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 / selector / ColorTableSelectorPanelView.java @ 6899

History | View | Annotate | Download (5.39 KB)

1
package org.gvsig.raster.swing.legend.impl.colortable.selector;
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.JFrame;
14
import javax.swing.JPanel;
15
import javax.swing.JScrollPane;
16
import javax.swing.JTable;
17

    
18

    
19
public class ColorTableSelectorPanelView extends JPanel
20
{
21
   JTable tblColorTables = new JTable();
22
   JButton btnImport = new JButton();
23
   JButton btnNew = new JButton();
24
   JButton btnExport = new JButton();
25
   JButton btnRemove = new JButton();
26
   JButton btnEdit = new JButton();
27

    
28
   /**
29
    * Default constructor
30
    */
31
   public ColorTableSelectorPanelView()
32
   {
33
      initializePanel();
34
   }
35

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

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

    
58
      for( int index = 0; index < cols.length; index++ )
59
      {
60
         if ( cols[index] == 1 && filled_cell_11 )
61
         {
62
            continue;
63
         }
64
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
65
      }
66

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

    
76
   }
77

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

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

    
115
   public JPanel createPanel()
116
   {
117
      JPanel jpanel1 = new JPanel();
118
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,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,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");
119
      CellConstraints cc = new CellConstraints();
120
      jpanel1.setLayout(formlayout1);
121

    
122
      tblColorTables.setName("tblColorTables");
123
      JScrollPane jscrollpane1 = new JScrollPane();
124
      jscrollpane1.setViewportView(tblColorTables);
125
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
126
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
127
      jpanel1.add(jscrollpane1,new CellConstraints(2,2,10,1,CellConstraints.FILL,CellConstraints.FILL));
128

    
129
      btnImport.setActionCommand("JButton");
130
      btnImport.setName("btnImport");
131
      btnImport.setToolTipText("_import");
132
      jpanel1.add(btnImport,cc.xy(9,4));
133

    
134
      btnNew.setActionCommand("JButton");
135
      btnNew.setName("btnNew");
136
      btnNew.setToolTipText("_new_color_table");
137
      jpanel1.add(btnNew,cc.xy(3,4));
138

    
139
      btnExport.setActionCommand("JButton");
140
      btnExport.setName("btnExport");
141
      btnExport.setToolTipText("_export");
142
      jpanel1.add(btnExport,cc.xy(11,4));
143

    
144
      btnRemove.setActionCommand("JButton");
145
      btnRemove.setName("btnRemove");
146
      btnRemove.setToolTipText("_remove");
147
      jpanel1.add(btnRemove,cc.xy(7,4));
148

    
149
      btnEdit.setName("btnEdit");
150
      btnEdit.setToolTipText("_edit");
151
      jpanel1.add(btnEdit,cc.xy(5,4));
152

    
153
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12 },new int[]{ 1,2,3,4,5 });
154
      return jpanel1;
155
   }
156

    
157
   /**
158
    * Initializer
159
    */
160
   protected void initializePanel()
161
   {
162
      setLayout(new BorderLayout());
163
      add(createPanel(), BorderLayout.CENTER);
164
   }
165

    
166

    
167
}