Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.mapcontext.swing / org.gvsig.fmap.mapcontext.swing.impl / src / main / java / org / gvsig / fmap / mapcontext / raster / swing / impl / bands / BandsPanelView.java @ 44831

History | View | Annotate | Download (5.97 KB)

1
package org.gvsig.fmap.mapcontext.raster.swing.impl.bands;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.ComponentOrientation;
5
import java.awt.Container;
6
import java.awt.Dimension;
7

    
8
import javax.swing.Box;
9
import javax.swing.ImageIcon;
10
import javax.swing.JButton;
11
import javax.swing.JComboBox;
12
import javax.swing.JLabel;
13
import javax.swing.JPanel;
14
import javax.swing.JScrollPane;
15
import javax.swing.JTable;
16

    
17
import com.jeta.forms.components.separator.TitledSeparator;
18
import com.jgoodies.forms.layout.CellConstraints;
19
import com.jgoodies.forms.layout.FormLayout;
20

    
21

    
22
public class BandsPanelView extends JPanel
23
{
24
   TitledSeparator lblBands = new TitledSeparator();
25
   JButton btnAdd = new JButton();
26
   JButton btnRemove = new JButton();
27
   JTable tblBands = new JTable();
28
   JLabel lblColorSpace = new JLabel();
29
   JComboBox cboColorSpaces = new JComboBox();
30

    
31
   /**
32
    * Default constructor
33
    */
34
   public BandsPanelView()
35
   {
36
      initializePanel();
37
   }
38

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

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

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

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

    
79
   }
80

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

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

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

    
125
      lblBands.setName("lblBands");
126
      lblBands.setText("_bands");
127
      jpanel1.add(lblBands,cc.xywh(2,2,6,1));
128

    
129
      jpanel1.add(createPanel1(),new CellConstraints(7,6,1,1,CellConstraints.DEFAULT,CellConstraints.TOP));
130
      tblBands.setName("tblBands");
131
      JScrollPane jscrollpane1 = new JScrollPane();
132
      jscrollpane1.setViewportView(tblBands);
133
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
134
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
135
      jpanel1.add(jscrollpane1,new CellConstraints(2,6,4,1,CellConstraints.FILL,CellConstraints.FILL));
136

    
137
      lblColorSpace.setName("lblColorSpace");
138
      lblColorSpace.setText("_color_space");
139
      lblColorSpace.setToolTipText("_color_space");
140
      jpanel1.add(lblColorSpace,cc.xy(2,4));
141

    
142
      cboColorSpaces.setName("cboColorSpaces");
143
      cboColorSpaces.setToolTipText("_color_space");
144
      jpanel1.add(cboColorSpaces,cc.xy(4,4));
145

    
146
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8 },new int[]{ 1,2,3,4,5,6,7 });
147
      return jpanel1;
148
   }
149

    
150
   public JPanel createPanel1()
151
   {
152
      JPanel jpanel1 = new JPanel();
153
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE");
154
      CellConstraints cc = new CellConstraints();
155
      jpanel1.setLayout(formlayout1);
156

    
157
      btnAdd.setActionCommand("JButton");
158
      btnAdd.setName("btnAdd");
159
      btnAdd.setText("_add");
160
      btnAdd.setToolTipText("_add_foreign_band");
161
      jpanel1.add(btnAdd,cc.xy(1,1));
162

    
163
      btnRemove.setActionCommand("JButton");
164
      btnRemove.setEnabled(false);
165
      btnRemove.setName("btnRemove");
166
      btnRemove.setText("_remove");
167
      btnRemove.setToolTipText("_remove_foreign_band");
168
      jpanel1.add(btnRemove,cc.xy(1,3));
169

    
170
      addFillComponents(jpanel1,new int[0],new int[]{ 2 });
171
      return jpanel1;
172
   }
173

    
174
   /**
175
    * Initializer
176
    */
177
   protected void initializePanel()
178
   {
179
      setLayout(new BorderLayout());
180
      add(createPanel(), BorderLayout.CENTER);
181
   }
182

    
183

    
184
}