Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / export / swing / impl / panels / SelectAttributesPanelView.java @ 44860

History | View | Annotate | Download (7.83 KB)

1
package org.gvsig.export.swing.impl.panels;
2
import com.jeta.open.i18n.I18NUtils;
3
import com.jgoodies.forms.layout.CellConstraints;
4
import com.jgoodies.forms.layout.FormLayout;
5
import java.awt.BorderLayout;
6
import java.awt.ComponentOrientation;
7
import java.awt.Container;
8
import java.awt.Dimension;
9
import java.awt.event.WindowAdapter;
10
import java.awt.event.WindowEvent;
11
import javax.swing.Box;
12
import javax.swing.ImageIcon;
13
import javax.swing.JButton;
14
import javax.swing.JFrame;
15
import javax.swing.JLabel;
16
import javax.swing.JPanel;
17
import javax.swing.JScrollPane;
18
import javax.swing.JTable;
19
import javax.swing.JTextField;
20
import javax.swing.border.EmptyBorder;
21

    
22

    
23
public class SelectAttributesPanelView extends JPanel
24
{
25
   JLabel lblHeader = new JLabel();
26
   JPanel jplAttributes = new JPanel();
27
   JTable tblAttributes = new JTable();
28
   JButton btnFilter = new JButton();
29
   JTextField txtFilter = new JTextField();
30
   JButton btnUncheckAll = new JButton();
31
   JButton btnCheckAll = new JButton();
32
   JLabel lblMessage = new JLabel();
33

    
34
   /**
35
    * Default constructor
36
    */
37
   public SelectAttributesPanelView()
38
   {
39
      initializePanel();
40
   }
41

    
42
   /**
43
    * Main method for panel
44
    */
45
   public static void main(String[] args)
46
   {
47
      JFrame frame = new JFrame();
48
      frame.setSize(600, 400);
49
      frame.setLocation(100, 100);
50
      frame.getContentPane().add(new SelectAttributesPanelView());
51
      frame.setVisible(true);
52

    
53
      frame.addWindowListener( new WindowAdapter()
54
      {
55
         public void windowClosing( WindowEvent evt )
56
         {
57
            System.exit(0);
58
         }
59
      });
60
   }
61

    
62
   /**
63
    * Adds fill components to empty cells in the first row and first column of the grid.
64
    * This ensures that the grid spacing will be the same as shown in the designer.
65
    * @param cols an array of column indices in the first row where fill components should be added.
66
    * @param rows an array of row indices in the first column where fill components should be added.
67
    */
68
   void addFillComponents( Container panel, int[] cols, int[] rows )
69
   {
70
      Dimension filler = new Dimension(10,10);
71

    
72
      boolean filled_cell_11 = false;
73
      CellConstraints cc = new CellConstraints();
74
      if ( cols.length > 0 && rows.length > 0 )
75
      {
76
         if ( cols[0] == 1 && rows[0] == 1 )
77
         {
78
            /** add a rigid area  */
79
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
80
            filled_cell_11 = true;
81
         }
82
      }
83

    
84
      for( int index = 0; index < cols.length; index++ )
85
      {
86
         if ( cols[index] == 1 && filled_cell_11 )
87
         {
88
            continue;
89
         }
90
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
91
      }
92

    
93
      for( int index = 0; index < rows.length; index++ )
94
      {
95
         if ( rows[index] == 1 && filled_cell_11 )
96
         {
97
            continue;
98
         }
99
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
100
      }
101

    
102
   }
103

    
104
   /**
105
    * Helper method to load an image file from the CLASSPATH
106
    * @param imageName the package and name of the file to load relative to the CLASSPATH
107
    * @return an ImageIcon instance with the specified image file
108
    * @throws IllegalArgumentException if the image resource cannot be loaded.
109
    */
110
   public ImageIcon loadImage( String imageName )
111
   {
112
      try
113
      {
114
         ClassLoader classloader = getClass().getClassLoader();
115
         java.net.URL url = classloader.getResource( imageName );
116
         if ( url != null )
117
         {
118
            ImageIcon icon = new ImageIcon( url );
119
            return icon;
120
         }
121
      }
122
      catch( Exception e )
123
      {
124
         e.printStackTrace();
125
      }
126
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
127
   }
128

    
129
   /**
130
    * Method for recalculating the component orientation for 
131
    * right-to-left Locales.
132
    * @param orientation the component orientation to be applied
133
    */
134
   public void applyComponentOrientation( ComponentOrientation orientation )
135
   {
136
      // Not yet implemented...
137
      // I18NUtils.applyComponentOrientation(this, orientation);
138
      super.applyComponentOrientation(orientation);
139
   }
140

    
141
   public JPanel createPanel()
142
   {
143
      JPanel jpanel1 = new JPanel();
144
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:8DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:4DLU:NONE,FILL:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:20DLU:NONE,CENTER:2DLU:NONE");
145
      CellConstraints cc = new CellConstraints();
146
      jpanel1.setLayout(formlayout1);
147

    
148
      lblHeader.setName("lblHeader");
149
      lblHeader.setText("_Select_name_type_size_and_attributes_to_export");
150
      jpanel1.add(lblHeader,cc.xywh(2,2,2,1));
151

    
152
      jplAttributes.setAutoscrolls(true);
153
      jplAttributes.setName("jplAttributes");
154
      jpanel1.add(jplAttributes,cc.xy(3,9));
155

    
156
      tblAttributes.setName("tblAttributes");
157
      tblAttributes.setShowVerticalLines(false);
158
      JScrollPane jscrollpane1 = new JScrollPane();
159
      jscrollpane1.setViewportView(tblAttributes);
160
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
161
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
162
      jpanel1.add(jscrollpane1,cc.xy(3,6));
163

    
164
      jpanel1.add(createPanel1(),cc.xy(3,4));
165
      jpanel1.add(createPanel2(),cc.xy(3,8));
166
      addFillComponents(jpanel1,new int[]{ 1,2,3,4 },new int[]{ 1,2,3,4,5,6,7,8,9,10 });
167
      return jpanel1;
168
   }
169

    
170
   public JPanel createPanel1()
171
   {
172
      JPanel jpanel1 = new JPanel();
173
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
174
      CellConstraints cc = new CellConstraints();
175
      jpanel1.setLayout(formlayout1);
176

    
177
      btnFilter.setActionCommand("JButton");
178
      btnFilter.setIcon(loadImage("org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.impl/src/main/resources/images/export-to/common-filter.png"));
179
      btnFilter.setName("btnFilter");
180
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
181
      btnFilter.setBorder(emptyborder1);
182
      jpanel1.add(btnFilter,cc.xy(3,1));
183

    
184
      txtFilter.setName("txtFilter");
185
      jpanel1.add(txtFilter,cc.xy(1,1));
186

    
187
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
188
      return jpanel1;
189
   }
190

    
191
   public JPanel createPanel2()
192
   {
193
      JPanel jpanel1 = new JPanel();
194
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:NONE,CENTER:69PX:NONE");
195
      CellConstraints cc = new CellConstraints();
196
      jpanel1.setLayout(formlayout1);
197

    
198
      btnUncheckAll.setActionCommand("JButton");
199
      btnUncheckAll.setIcon(loadImage("org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.impl/src/main/resources/images/export-to/common-check-off.png"));
200
      btnUncheckAll.setName("btnUncheckAll");
201
      EmptyBorder emptyborder1 = new EmptyBorder(0,0,0,0);
202
      btnUncheckAll.setBorder(emptyborder1);
203
      jpanel1.add(btnUncheckAll,cc.xy(2,1));
204

    
205
      btnCheckAll.setActionCommand("JButton");
206
      btnCheckAll.setIcon(loadImage("org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.impl/src/main/resources/images/export-to/common-check-on.png"));
207
      btnCheckAll.setName("btnCheckAll");
208
      EmptyBorder emptyborder2 = new EmptyBorder(0,0,0,0);
209
      btnCheckAll.setBorder(emptyborder2);
210
      jpanel1.add(btnCheckAll,cc.xy(1,1));
211

    
212
      lblMessage.setName("lblMessage");
213
      jpanel1.add(lblMessage,cc.xywh(1,2,4,1));
214

    
215
      addFillComponents(jpanel1,new int[]{ 3,4 },new int[0]);
216
      return jpanel1;
217
   }
218

    
219
   /**
220
    * Initializer
221
    */
222
   protected void initializePanel()
223
   {
224
      setLayout(new BorderLayout());
225
      add(createPanel(), BorderLayout.CENTER);
226
   }
227

    
228

    
229
}