Statistics
| Revision:

gvsig-webmap / org.gvsig.googlemaps / trunk / org.gvsig.googlemaps / org.gvsig.googlemaps.swing / org.gvsig.googlemaps.swing.impl / src / main / java / org / gvsig / googlemaps / swing / impl / DefaultGoogleMapsParametersPanelView.java @ 58

History | View | Annotate | Download (6.67 KB)

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

    
3
import com.jgoodies.forms.layout.CellConstraints;
4
import com.jgoodies.forms.layout.FormLayout;
5
import java.awt.BorderLayout;
6
import java.awt.Color;
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.JCheckBox;
13
import javax.swing.JComboBox;
14
import javax.swing.JEditorPane;
15
import javax.swing.JFrame;
16
import javax.swing.JLabel;
17
import javax.swing.JPanel;
18
import javax.swing.JTextField;
19
import javax.swing.border.EmptyBorder;
20

    
21

    
22
public class DefaultGoogleMapsParametersPanelView extends JPanel
23
{
24
   JLabel lblSelectMapType = new JLabel();
25
   JCheckBox chkboxUseAPIKey = new JCheckBox();
26
   JTextField txtAPIKey = new JTextField();
27
   JLabel lblZoomLvl = new JLabel();
28
   JComboBox cboMapTypes = new JComboBox();
29
   JTextField txtZoomLvl = new JTextField();
30
   JEditorPane txtDisclaimer = new JEditorPane();
31
   JEditorPane txtCrsWarning = new JEditorPane();
32

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

    
41
   /**
42
    * Adds fill components to empty cells in the first row and first column of the grid.
43
    * This ensures that the grid spacing will be the same as shown in the designer.
44
    * @param cols an array of column indices in the first row where fill components should be added.
45
    * @param rows an array of row indices in the first column where fill components should be added.
46
    */
47
   void addFillComponents( Container panel, int[] cols, int[] rows )
48
   {
49
      Dimension filler = new Dimension(10,10);
50

    
51
      boolean filled_cell_11 = false;
52
      CellConstraints cc = new CellConstraints();
53
      if ( cols.length > 0 && rows.length > 0 )
54
      {
55
         if ( cols[0] == 1 && rows[0] == 1 )
56
         {
57
            /** add a rigid area  */
58
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
59
            filled_cell_11 = true;
60
         }
61
      }
62

    
63
      for( int index = 0; index < cols.length; index++ )
64
      {
65
         if ( cols[index] == 1 && filled_cell_11 )
66
         {
67
            continue;
68
         }
69
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
70
      }
71

    
72
      for( int index = 0; index < rows.length; index++ )
73
      {
74
         if ( rows[index] == 1 && filled_cell_11 )
75
         {
76
            continue;
77
         }
78
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
79
      }
80

    
81
   }
82

    
83
   /**
84
    * Helper method to load an image file from the CLASSPATH
85
    * @param imageName the package and name of the file to load relative to the CLASSPATH
86
    * @return an ImageIcon instance with the specified image file
87
    * @throws IllegalArgumentException if the image resource cannot be loaded.
88
    */
89
   public ImageIcon loadImage( String imageName )
90
   {
91
      try
92
      {
93
         ClassLoader classloader = getClass().getClassLoader();
94
         java.net.URL url = classloader.getResource( imageName );
95
         if ( url != null )
96
         {
97
            ImageIcon icon = new ImageIcon( url );
98
            return icon;
99
         }
100
      }
101
      catch( Exception e )
102
      {
103
         e.printStackTrace();
104
      }
105
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
106
   }
107

    
108
   /**
109
    * Method for recalculating the component orientation for
110
    * right-to-left Locales.
111
    * @param orientation the component orientation to be applied
112
    */
113
   public void applyComponentOrientation( ComponentOrientation orientation )
114
   {
115
      // Not yet implemented...
116
      // I18NUtils.applyComponentOrientation(this, orientation);
117
      super.applyComponentOrientation(orientation);
118
   }
119

    
120
   public JPanel createPanel()
121
   {
122
      JPanel jpanel1 = new JPanel();
123
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:4DLU:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:4DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
124
      CellConstraints cc = new CellConstraints();
125
      jpanel1.setLayout(formlayout1);
126

    
127
      lblSelectMapType.setName("lblSelectMapType");
128
      lblSelectMapType.setText("_select_map_type");
129
      lblSelectMapType.setToolTipText("_select_map_type");
130
      jpanel1.add(lblSelectMapType,cc.xy(2,2));
131

    
132
      chkboxUseAPIKey.setActionCommand("use_api_key");
133
      chkboxUseAPIKey.setName("chkboxUseAPIKey");
134
      chkboxUseAPIKey.setText("_use_api_key");
135
      chkboxUseAPIKey.setToolTipText("_use_api_key_tooltip");
136
      jpanel1.add(chkboxUseAPIKey,cc.xy(2,4));
137

    
138
      txtAPIKey.setName("txtAPIKey");
139
      txtAPIKey.setToolTipText("_api_key");
140
      jpanel1.add(txtAPIKey,cc.xywh(2,6,5,1));
141

    
142
      lblZoomLvl.setName("lblZoomLvl");
143
      lblZoomLvl.setText("_zoom_lvl");
144
      lblZoomLvl.setToolTipText("_zoom_lvl_tooltip");
145
      jpanel1.add(lblZoomLvl,cc.xy(2,8));
146

    
147
      cboMapTypes.setName("cboMapTypes");
148
      cboMapTypes.setToolTipText("_map_type");
149
      jpanel1.add(cboMapTypes,cc.xy(4,2));
150

    
151
      txtZoomLvl.setName("txtZoomLvl");
152
      jpanel1.add(txtZoomLvl,cc.xy(4,8));
153

    
154
      txtDisclaimer.setAutoscrolls(false);
155
      txtDisclaimer.setContentType("text/html");
156
      txtDisclaimer.setEditable(false);
157
      txtDisclaimer.setName("txtDisclaimer");
158
      txtDisclaimer.setOpaque(false);
159
      txtDisclaimer.setSelectionEnd(24);
160
      txtDisclaimer.setSelectionStart(24);
161
      txtDisclaimer.setText("<html>\n  <head>\n    \n  </head>\n  <body>\n    _google_maps_disclaimer\n  </body>\n</html>\n");
162
      EmptyBorder emptyborder1 = new EmptyBorder(0,0,0,0);
163
      txtDisclaimer.setBorder(emptyborder1);
164
      jpanel1.add(txtDisclaimer,cc.xywh(2,10,5,1));
165

    
166
      txtCrsWarning.setAutoscrolls(false);
167
      txtCrsWarning.setContentType("text/html");
168
      txtCrsWarning.setEditable(false);
169
      txtCrsWarning.setForeground(new Color(255,0,0));
170
      txtCrsWarning.setName("txtCrsWarning");
171
      txtCrsWarning.setOpaque(false);
172
      txtCrsWarning.setSelectionEnd(13);
173
      txtCrsWarning.setSelectionStart(13);
174
      txtCrsWarning.setText("<html>\n  <head>\n    \n  </head>\n  <body>\n    <font color=\"red\">_crs_warning</font>\n  </body>\n</html>\n");
175
      EmptyBorder emptyborder2 = new EmptyBorder(0,0,0,0);
176
      txtCrsWarning.setBorder(emptyborder2);
177
      jpanel1.add(txtCrsWarning,cc.xywh(2,12,5,1));
178

    
179
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13 });
180
      return jpanel1;
181
   }
182

    
183
   /**
184
    * Initializer
185
    */
186
   protected void initializePanel()
187
   {
188
      setLayout(new BorderLayout());
189
      add(createPanel(), BorderLayout.CENTER);
190
   }
191

    
192

    
193
}