Statistics
| Revision:

root / org.gvsig.proj / branches / refactor2018 / org.gvsig.proj / org.gvsig.proj.swing / org.gvsig.proj.swing.impl / src / main / java / org / gvsig / proj / swing / impl / CrsSelectorView.java @ 866

History | View | Annotate | Download (12.4 KB)

1
package org.gvsig.proj.swing.impl;
2

    
3
import com.jeta.open.i18n.I18NUtils;
4
import com.jgoodies.forms.layout.CellConstraints;
5
import com.jgoodies.forms.layout.FormLayout;
6
import java.awt.BorderLayout;
7
import java.awt.ComponentOrientation;
8
import java.awt.Container;
9
import java.awt.Dimension;
10
import javax.swing.Box;
11
import javax.swing.ImageIcon;
12
import javax.swing.JButton;
13
import javax.swing.JComboBox;
14
import javax.swing.JFrame;
15
import javax.swing.JLabel;
16
import javax.swing.JPanel;
17
import javax.swing.JScrollPane;
18
import javax.swing.JTabbedPane;
19
import javax.swing.JTextArea;
20
import javax.swing.JTree;
21
import javax.swing.border.EmptyBorder;
22

    
23

    
24
public class CrsSelectorView extends JPanel
25
{
26
   JPanel mainPanel = new JPanel();
27
   JLabel lblCurrentCrs = new JLabel();
28
   JTree treeResults = new JTree();
29
   JTabbedPane pnlDetails = new JTabbedPane();
30
   JPanel DescriptionTab = new JPanel();
31
   JTextArea txtDescription = new JTextArea();
32
   JPanel WktTab = new JPanel();
33
   JTextArea txtCrsWkt = new JTextArea();
34
   JPanel pnl_filter = new JPanel();
35
   JButton btnSearch = new JButton();
36
   JButton btnSearchRemove = new JButton();
37
   JButton btnFilterDropdown = new JButton();
38
   JPanel pnl_filterBar = new JPanel();
39
   JComboBox cboFilterAlpha = new JComboBox();
40
   JComboBox cboFilterSpatial = new JComboBox();
41
   JPanel pnl_filterType = new JPanel();
42
   JLabel lblFilterAlpha = new JLabel();
43
   JLabel lblFilterSpatial = new JLabel();
44
   JPanel grd_buttonBar = new JPanel();
45
   JButton btnFavoritesAdd = new JButton();
46
   JButton btnFavoritesRemove = new JButton();
47
   JButton btnCrsAdd = new JButton();
48
   JButton btnRecentCrsRemove = new JButton();
49

    
50
   /**
51
    * Default constructor
52
    */
53
   public CrsSelectorView()
54
   {
55
      initializePanel();
56
   }
57

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

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

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

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

    
98
   }
99

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

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

    
137
   public JPanel createmainPanel()
138
   {
139
      mainPanel.setName("mainPanel");
140
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,FILL:DEFAULT:GROW(0.8),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,FILL:MIN(60DLU;DEFAULT):GROW(0.2),CENTER:2DLU:NONE");
141
      CellConstraints cc = new CellConstraints();
142
      mainPanel.setLayout(formlayout1);
143

    
144
      lblCurrentCrs.setName("lblCurrentCrs");
145
      lblCurrentCrs.setText("Current coordinate system:");
146
      mainPanel.add(lblCurrentCrs,cc.xy(2,8));
147

    
148
      treeResults.setLargeModel(true);
149
      treeResults.setName("treeResults");
150
      treeResults.setRootVisible(false);
151
      treeResults.setShowsRootHandles(true);
152
      JScrollPane jscrollpane1 = new JScrollPane();
153
      jscrollpane1.setViewportView(treeResults);
154
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
155
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
156
      mainPanel.add(jscrollpane1,cc.xy(2,4));
157

    
158
      pnlDetails.setName("pnlDetails");
159
      pnlDetails.setTabPlacement(JTabbedPane.BOTTOM);
160
      pnlDetails.addTab("Description",null,createDescriptionTab());
161
      pnlDetails.addTab("WKT",null,createWktTab());
162
      mainPanel.add(pnlDetails,cc.xy(2,10));
163

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

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

    
177
      txtDescription.setName("txtDescription");
178
      txtDescription.setRows(4);
179
      txtDescription.setSelectionEnd(74);
180
      txtDescription.setSelectionStart(74);
181
      txtDescription.setText("Aqui vendria la informacion que tiene la descripcion del CRS del catalogo.");
182
      JScrollPane jscrollpane1 = new JScrollPane();
183
      jscrollpane1.setViewportView(txtDescription);
184
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
185
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
186
      DescriptionTab.add(jscrollpane1,cc.xy(2,2));
187

    
188
      addFillComponents(DescriptionTab,new int[]{ 1,2,3 },new int[]{ 1,2,3 });
189
      return DescriptionTab;
190
   }
191

    
192
   public JPanel createWktTab()
193
   {
194
      WktTab.setName("WktTab");
195
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:2DLU:NONE");
196
      CellConstraints cc = new CellConstraints();
197
      WktTab.setLayout(formlayout1);
198

    
199
      txtCrsWkt.setLineWrap(true);
200
      txtCrsWkt.setName("txtCrsWkt");
201
      txtCrsWkt.setRows(4);
202
      JScrollPane jscrollpane1 = new JScrollPane();
203
      jscrollpane1.setViewportView(txtCrsWkt);
204
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
205
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
206
      WktTab.add(jscrollpane1,cc.xy(2,2));
207

    
208
      addFillComponents(WktTab,new int[]{ 1,2,3 },new int[]{ 1,2,3 });
209
      return WktTab;
210
   }
211

    
212
   public JPanel createpnl_filter()
213
   {
214
      pnl_filter.setName("pnl_filter");
215
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","FILL:DEFAULT:NONE");
216
      CellConstraints cc = new CellConstraints();
217
      pnl_filter.setLayout(formlayout1);
218

    
219
      btnSearch.setName("btnSearch");
220
      btnSearch.setToolTipText("Search");
221
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
222
      btnSearch.setBorder(emptyborder1);
223
      pnl_filter.add(btnSearch,cc.xy(6,1));
224

    
225
      btnSearchRemove.setName("btnSearchRemove");
226
      btnSearchRemove.setToolTipText("Clear search");
227
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
228
      btnSearchRemove.setBorder(emptyborder2);
229
      pnl_filter.add(btnSearchRemove,cc.xy(8,1));
230

    
231
      btnFilterDropdown.setName("btnFilterDropdown");
232
      EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2);
233
      btnFilterDropdown.setBorder(emptyborder3);
234
      pnl_filter.add(btnFilterDropdown,cc.xy(2,1));
235

    
236
      pnl_filter.add(createpnl_filterBar(),cc.xy(4,1));
237
      pnl_filter.add(createpnl_filterType(),cc.xy(1,1));
238
      addFillComponents(pnl_filter,new int[]{ 1,3,4,5,7 },new int[]{ 1 });
239
      return pnl_filter;
240
   }
241

    
242
   public JPanel createpnl_filterBar()
243
   {
244
      pnl_filterBar.setName("pnl_filterBar");
245
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
246
      CellConstraints cc = new CellConstraints();
247
      pnl_filterBar.setLayout(formlayout1);
248

    
249
      cboFilterAlpha.setEditable(true);
250
      cboFilterAlpha.setName("cboFilterAlpha");
251
      cboFilterAlpha.setRequestFocusEnabled(false);
252
      pnl_filterBar.add(cboFilterAlpha,cc.xy(1,1));
253

    
254
      cboFilterSpatial.setName("cboFilterSpatial");
255
      cboFilterSpatial.addItem("Current Visible Extent");
256
      cboFilterSpatial.addItem("Outline of Features");
257
      cboFilterSpatial.addItem("Outline of Selected Graphics");
258
      cboFilterSpatial.addItem("Custom Extent");
259
      pnl_filterBar.add(cboFilterSpatial,cc.xy(1,2));
260

    
261
      addFillComponents(pnl_filterBar,new int[0],new int[0]);
262
      return pnl_filterBar;
263
   }
264

    
265
   public JPanel createpnl_filterType()
266
   {
267
      pnl_filterType.setName("pnl_filterType");
268
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
269
      CellConstraints cc = new CellConstraints();
270
      pnl_filterType.setLayout(formlayout1);
271

    
272
      lblFilterAlpha.setName("lblFilterAlpha");
273
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
274
      lblFilterAlpha.setBorder(emptyborder1);
275
      pnl_filterType.add(lblFilterAlpha,cc.xy(1,1));
276

    
277
      lblFilterSpatial.setName("lblFilterSpatial");
278
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
279
      lblFilterSpatial.setBorder(emptyborder2);
280
      pnl_filterType.add(lblFilterSpatial,cc.xy(1,2));
281

    
282
      addFillComponents(pnl_filterType,new int[0],new int[0]);
283
      return pnl_filterType;
284
   }
285

    
286
   public JPanel creategrd_buttonBar()
287
   {
288
      grd_buttonBar.setName("grd_buttonBar");
289
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
290
      CellConstraints cc = new CellConstraints();
291
      grd_buttonBar.setLayout(formlayout1);
292

    
293
      btnFavoritesAdd.setName("btnFavoritesAdd");
294
      btnFavoritesAdd.setToolTipText("Add selected CRS to favorites");
295
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
296
      btnFavoritesAdd.setBorder(emptyborder1);
297
      grd_buttonBar.add(btnFavoritesAdd,cc.xy(8,1));
298

    
299
      btnFavoritesRemove.setName("btnFavoritesRemove");
300
      btnFavoritesRemove.setToolTipText("Remove selected CRS from favorites");
301
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
302
      btnFavoritesRemove.setBorder(emptyborder2);
303
      grd_buttonBar.add(btnFavoritesRemove,cc.xy(6,1));
304

    
305
      btnCrsAdd.setName("btnCrsAdd");
306
      btnCrsAdd.setToolTipText("Create a new CRS");
307
      EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2);
308
      btnCrsAdd.setBorder(emptyborder3);
309
      grd_buttonBar.add(btnCrsAdd,cc.xy(2,1));
310

    
311
      btnRecentCrsRemove.setName("btnRecentCrsRemove");
312
      btnRecentCrsRemove.setToolTipText("Remove selected CRS from recents");
313
      EmptyBorder emptyborder4 = new EmptyBorder(2,2,2,2);
314
      btnRecentCrsRemove.setBorder(emptyborder4);
315
      grd_buttonBar.add(btnRecentCrsRemove,cc.xy(4,1));
316

    
317
      addFillComponents(grd_buttonBar,new int[]{ 1,3,5,7 },new int[]{ 1 });
318
      return grd_buttonBar;
319
   }
320

    
321
   /**
322
    * Initializer
323
    */
324
   protected void initializePanel()
325
   {
326
      setLayout(new BorderLayout());
327
      add(createmainPanel(), BorderLayout.CENTER);
328
   }
329

    
330

    
331
}