Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.symbology.app / org.gvsig.symbology.app.importsymbols / src / main / java / org / gvsig / symbology / app / importsymbols / ImportPictureMarkerSymbolsPanelLayout.java @ 44920

History | View | Annotate | Download (7.65 KB)

1
package org.gvsig.symbology.app.importsymbols;
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.JList;
17
import javax.swing.JPanel;
18
import javax.swing.JScrollPane;
19
import javax.swing.JSpinner;
20
import javax.swing.JTextField;
21

    
22

    
23
public class ImportPictureMarkerSymbolsPanelLayout extends JPanel
24
{
25
   JLabel labelTitle = new JLabel();
26
   JLabel labelImagesToImport = new JLabel();
27
   JLabel labelFolderName = new JLabel();
28
   JTextField ctrltFolderName = new JTextField();
29
   JList ctrlExistingFolders = new JList();
30
   JLabel labelSize = new JLabel();
31
   JSpinner ctrlDefaultSize = new JSpinner();
32
   JButton ctrlCancel = new JButton();
33
   JButton ctrlImport = new JButton();
34
   JLabel labelOverwriteOptions = new JLabel();
35
   JComboBox ctrlOverwriteOptions = new JComboBox();
36
   JList ctrlImagesToImport = new JList();
37
   JButton ctrlBrowseImagesToImport = new JButton();
38

    
39
   /**
40
    * Default constructor
41
    */
42
   public ImportPictureMarkerSymbolsPanelLayout()
43
   {
44
      initializePanel();
45
   }
46

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

    
57
      boolean filled_cell_11 = false;
58
      CellConstraints cc = new CellConstraints();
59
      if ( cols.length > 0 && rows.length > 0 )
60
      {
61
         if ( cols[0] == 1 && rows[0] == 1 )
62
         {
63
            /** add a rigid area  */
64
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
65
            filled_cell_11 = true;
66
         }
67
      }
68

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

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

    
87
   }
88

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

    
114
   /**
115
    * Method for recalculating the component orientation for 
116
    * right-to-left Locales.
117
    * @param orientation the component orientation to be applied
118
    */
119
   public void applyComponentOrientation( ComponentOrientation orientation )
120
   {
121
      // Not yet implemented...
122
      // I18NUtils.applyComponentOrientation(this, orientation);
123
      super.applyComponentOrientation(orientation);
124
   }
125

    
126
   public JPanel createPanel()
127
   {
128
      JPanel jpanel1 = new JPanel();
129
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,FILL:PREF:GROW(1.0),CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
130
      CellConstraints cc = new CellConstraints();
131
      jpanel1.setLayout(formlayout1);
132

    
133
      labelTitle.setName("labelTitle");
134
      labelTitle.setText("_Import_images_as_symbols");
135
      jpanel1.add(labelTitle,cc.xywh(2,2,6,1));
136

    
137
      labelImagesToImport.setName("labelImagesToImport");
138
      labelImagesToImport.setText("_Images_to_import");
139
      jpanel1.add(labelImagesToImport,cc.xywh(2,4,6,1));
140

    
141
      labelFolderName.setName("labelFolderName");
142
      labelFolderName.setText("_Folder_for_the_symbols");
143
      jpanel1.add(labelFolderName,cc.xywh(2,7,6,1));
144

    
145
      ctrltFolderName.setName("ctrltFolderName");
146
      jpanel1.add(ctrltFolderName,cc.xywh(3,8,5,1));
147

    
148
      ctrlExistingFolders.setName("ctrlExistingFolders");
149
      JScrollPane jscrollpane1 = new JScrollPane();
150
      jscrollpane1.setViewportView(ctrlExistingFolders);
151
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
152
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
153
      jpanel1.add(jscrollpane1,new CellConstraints(3,9,5,1,CellConstraints.FILL,CellConstraints.TOP));
154

    
155
      labelSize.setName("labelSize");
156
      labelSize.setText("_Default_size");
157
      jpanel1.add(labelSize,cc.xywh(2,11,6,1));
158

    
159
      ctrlDefaultSize.setName("ctrlDefaultSize");
160
      jpanel1.add(ctrlDefaultSize,cc.xywh(3,12,5,1));
161

    
162
      ctrlCancel.setActionCommand("_Cancel");
163
      ctrlCancel.setName("ctrlCancel");
164
      ctrlCancel.setText("_Cancel");
165
      jpanel1.add(ctrlCancel,cc.xy(5,17));
166

    
167
      ctrlImport.setActionCommand("_import");
168
      ctrlImport.setName("ctrlImport");
169
      ctrlImport.setText("_import");
170
      jpanel1.add(ctrlImport,cc.xy(7,17));
171

    
172
      labelOverwriteOptions.setName("labelOverwriteOptions");
173
      labelOverwriteOptions.setText("_Overwrite_options");
174
      jpanel1.add(labelOverwriteOptions,cc.xywh(2,14,6,1));
175

    
176
      ctrlOverwriteOptions.setName("ctrlOverwriteOptions");
177
      ctrlOverwriteOptions.addItem("_Ask_to_user");
178
      ctrlOverwriteOptions.addItem("_Dont_overwrite");
179
      ctrlOverwriteOptions.addItem("_Overwrite_always");
180
      jpanel1.add(ctrlOverwriteOptions,cc.xywh(3,15,5,1));
181

    
182
      ctrlImagesToImport.setName("ctrlImagesToImport");
183
      JScrollPane jscrollpane2 = new JScrollPane();
184
      jscrollpane2.setViewportView(ctrlImagesToImport);
185
      jscrollpane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
186
      jscrollpane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
187
      jpanel1.add(jscrollpane2,new CellConstraints(3,5,5,1,CellConstraints.DEFAULT,CellConstraints.TOP));
188

    
189
      ctrlBrowseImagesToImport.setActionCommand("_Browse");
190
      ctrlBrowseImagesToImport.setName("ctrlBrowseImagesToImport");
191
      ctrlBrowseImagesToImport.setText("_Select_images");
192
      jpanel1.add(ctrlBrowseImagesToImport,new CellConstraints(3,6,5,1,CellConstraints.RIGHT,CellConstraints.DEFAULT));
193

    
194
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 });
195
      return jpanel1;
196
   }
197

    
198
   /**
199
    * Initializer
200
    */
201
   protected void initializePanel()
202
   {
203
      setLayout(new BorderLayout());
204
      add(createPanel(), BorderLayout.CENTER);
205
   }
206

    
207

    
208
}