Statistics
| Revision:

gvsig-3d / 2.1 / branches / extrusion / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / properties / layer / VectorLayer3DPanel.java @ 657

History | View | Annotate | Download (5.2 KB)

1
package org.gvsig.view3d.swing.impl.properties.layer;
2

    
3
import com.jgoodies.forms.layout.CellConstraints;
4
import com.jgoodies.forms.layout.FormLayout;
5
import java.awt.BorderLayout;
6
import java.awt.ComponentOrientation;
7
import java.awt.Container;
8
import java.awt.Dimension;
9
import javax.swing.Box;
10
import javax.swing.ImageIcon;
11
import javax.swing.JButton;
12
import javax.swing.JComboBox;
13
import javax.swing.JFrame;
14
import javax.swing.JLabel;
15
import javax.swing.JPanel;
16
import javax.swing.JTextField;
17

    
18

    
19
public class VectorLayer3DPanel extends JPanel
20
{
21
   JLabel _elevationModeLabel = new JLabel();
22
   JLabel _defaultColorLabel = new JLabel();
23
   JComboBox _elevationModeCombo = new JComboBox();
24
   JButton _defaultColorButton = new JButton();
25
   JLabel _constantHeightLabel = new JLabel();
26
   JTextField _constantHeightTextField = new JTextField();
27

    
28
   /**
29
    * Default constructor
30
    */
31
   public VectorLayer3DPanel()
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:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(0.3),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL: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:GROW(1.0),CENTER:DEFAULT:NONE");
119
      CellConstraints cc = new CellConstraints();
120
      jpanel1.setLayout(formlayout1);
121

    
122
      _elevationModeLabel.setName("elevationModeLabel");
123
      _elevationModeLabel.setText("Elevation Mode");
124
      jpanel1.add(_elevationModeLabel,cc.xywh(2,2,2,1));
125

    
126
      _defaultColorLabel.setName("defaultColorLabel");
127
      _defaultColorLabel.setText("Default Color");
128
      jpanel1.add(_defaultColorLabel,cc.xywh(2,4,2,1));
129

    
130
      _elevationModeCombo.setName("elevationModeCombo");
131
      jpanel1.add(_elevationModeCombo,cc.xywh(5,2,3,1));
132

    
133
      _defaultColorButton.setActionCommand("...");
134
      _defaultColorButton.setName("defaultColorButton");
135
      _defaultColorButton.setText("...");
136
      jpanel1.add(_defaultColorButton,cc.xy(5,4));
137

    
138
      _constantHeightLabel.setName("constantHeightLabel");
139
      _constantHeightLabel.setText("Constant Height");
140
      jpanel1.add(_constantHeightLabel,cc.xywh(2,6,2,1));
141

    
142
      _constantHeightTextField.setName("constantHeightTextField");
143
      jpanel1.add(_constantHeightTextField,cc.xywh(5,6,3,1));
144

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

    
149
   /**
150
    * Initializer
151
    */
152
   protected void initializePanel()
153
   {
154
      setLayout(new BorderLayout());
155
      add(createPanel(), BorderLayout.CENTER);
156
   }
157

    
158

    
159
}