Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.raster.swing / org.gvsig.raster.swing.legend / org.gvsig.raster.swing.legend.impl / src / main / java / org / gvsig / raster / swing / legend / impl / colortable / editor / ColorTableEditorPanelView.java @ 6899

History | View | Annotate | Download (7.39 KB)

1
package org.gvsig.raster.swing.legend.impl.colortable.editor;
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.JCheckBox;
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.JTable;
20
import javax.swing.JTextField;
21

    
22

    
23
public class ColorTableEditorPanelView extends JPanel
24
{
25
   JCheckBox chkInterpolated = new JCheckBox();
26
   JLabel lblName = new JLabel();
27
   JTextField txtName = new JTextField();
28
   JTabbedPane tabColorTable = new JTabbedPane();
29
   JTable tblColorTableClasses = new JTable();
30
   JButton btnAdd = new JButton();
31
   JButton btnRemove = new JButton();
32
   JButton btnRemoveAll = new JButton();
33

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

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

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

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

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

    
82
   }
83

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

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

    
121
   public JPanel createPanel()
122
   {
123
      JPanel jpanel1 = new JPanel();
124
      FormLayout formlayout1 = new FormLayout("FILL:4DLU: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:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
125
      CellConstraints cc = new CellConstraints();
126
      jpanel1.setLayout(formlayout1);
127

    
128
      chkInterpolated.setActionCommand("_interpolated");
129
      chkInterpolated.setName("chkInterpolated");
130
      chkInterpolated.setText("_interpolated");
131
      jpanel1.add(chkInterpolated,cc.xy(6,6));
132

    
133
      lblName.setName("lblName");
134
      lblName.setText("_name");
135
      jpanel1.add(lblName,cc.xy(2,6));
136

    
137
      txtName.setName("txtName");
138
      jpanel1.add(txtName,cc.xy(4,6));
139

    
140
      jpanel1.add(createPanel1(),new CellConstraints(2,2,7,1,CellConstraints.FILL,CellConstraints.FILL));
141
      jpanel1.add(createPanel3(),new CellConstraints(2,4,7,1,CellConstraints.RIGHT,CellConstraints.DEFAULT));
142
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8,9 },new int[]{ 1,2,3,4,5,6,7 });
143
      return jpanel1;
144
   }
145

    
146
   public JPanel createPanel1()
147
   {
148
      JPanel jpanel1 = new JPanel();
149
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:GROW(1.0)");
150
      CellConstraints cc = new CellConstraints();
151
      jpanel1.setLayout(formlayout1);
152

    
153
      tabColorTable.setName("tabColorTable");
154
      tabColorTable.addTab("table",null,createPanel2());
155
      jpanel1.add(tabColorTable,new CellConstraints(1,1,1,1,CellConstraints.FILL,CellConstraints.FILL));
156

    
157
      addFillComponents(jpanel1,new int[0],new int[0]);
158
      return jpanel1;
159
   }
160

    
161
   public JPanel createPanel2()
162
   {
163
      JPanel jpanel1 = new JPanel();
164
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:2DLU:NONE");
165
      CellConstraints cc = new CellConstraints();
166
      jpanel1.setLayout(formlayout1);
167

    
168
      tblColorTableClasses.setName("tblColorTableClasses");
169
      JScrollPane jscrollpane1 = new JScrollPane();
170
      jscrollpane1.setViewportView(tblColorTableClasses);
171
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
172
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
173
      jpanel1.add(jscrollpane1,new CellConstraints(2,2,1,1,CellConstraints.DEFAULT,CellConstraints.TOP));
174

    
175
      addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3 });
176
      return jpanel1;
177
   }
178

    
179
   public JPanel createPanel3()
180
   {
181
      JPanel jpanel1 = new JPanel();
182
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
183
      CellConstraints cc = new CellConstraints();
184
      jpanel1.setLayout(formlayout1);
185

    
186
      btnAdd.setActionCommand("_add");
187
      btnAdd.setName("btnAdd");
188
      btnAdd.setText("_add");
189
      btnAdd.setToolTipText("_add");
190
      jpanel1.add(btnAdd,cc.xy(1,1));
191

    
192
      btnRemove.setActionCommand("_remove");
193
      btnRemove.setName("btnRemove");
194
      btnRemove.setText("_remove");
195
      btnRemove.setToolTipText("_remove");
196
      jpanel1.add(btnRemove,cc.xy(3,1));
197

    
198
      btnRemoveAll.setActionCommand("_remove_all");
199
      btnRemoveAll.setName("btnRemoveAll");
200
      btnRemoveAll.setText("_remove_all");
201
      btnRemoveAll.setToolTipText("_remove_all");
202
      jpanel1.add(btnRemoveAll,cc.xy(5,1));
203

    
204
      addFillComponents(jpanel1,new int[]{ 2,4 },new int[0]);
205
      return jpanel1;
206
   }
207

    
208
   /**
209
    * Initializer
210
    */
211
   protected void initializePanel()
212
   {
213
      setLayout(new BorderLayout());
214
      add(createPanel(), BorderLayout.CENTER);
215
   }
216

    
217

    
218
}