Statistics
| Revision:

root / org.gvsig.complexlegend / trunk / org.gvsig.complexlegend / org.gvsig.complexlegend.swing / org.gvsig.complexlegend.swing.impl / src / main / java / org / gvsig / complexlegend / swing / impl / DefaultComplexLegendPanelView.java @ 3574

History | View | Annotate | Download (6.48 KB)

1
package org.gvsig.complexlegend.swing.impl;
2

    
3
import com.jeta.forms.components.separator.TitledSeparator;
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.JComboBox;
15
import javax.swing.JFrame;
16
import javax.swing.JPanel;
17

    
18

    
19
public class DefaultComplexLegendPanelView extends JPanel
20
{
21
   JPanel fieldsPanel = new JPanel();
22
   JComboBox cmbValue = new JComboBox();
23
   JButton addButton = new JButton();
24
   JButton removeButton = new JButton();
25
   JCheckBox chkAllowOverlap = new JCheckBox();
26
   TitledSeparator legendPanelTitle = new TitledSeparator();
27
   JPanel symbolPanel = new JPanel();
28
   TitledSeparator symbolPanelTitle = new TitledSeparator();
29

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

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

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

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

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

    
78
   }
79

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

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

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

    
124
      jpanel1.add(createfieldsPanel(),cc.xy(2,2));
125
      jpanel1.add(createsymbolPanel(),cc.xy(2,4));
126
      symbolPanelTitle.setName("symbolPanelTitle");
127
      symbolPanelTitle.setText("legend_definition");
128
      jpanel1.add(symbolPanelTitle,cc.xy(2,3));
129

    
130
      addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5 });
131
      return jpanel1;
132
   }
133

    
134
   public JPanel createfieldsPanel()
135
   {
136
      fieldsPanel.setName("fieldsPanel");
137
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
138
      CellConstraints cc = new CellConstraints();
139
      fieldsPanel.setLayout(formlayout1);
140

    
141
      fieldsPanel.add(createPanel1(),cc.xy(1,2));
142
      legendPanelTitle.setName("legendPanelTitle");
143
      legendPanelTitle.setText("select_scale");
144
      fieldsPanel.add(legendPanelTitle,cc.xy(1,1));
145

    
146
      addFillComponents(fieldsPanel,new int[0],new int[]{ 2,3 });
147
      return fieldsPanel;
148
   }
149

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

    
157
      cmbValue.setName("cmbValue");
158
      jpanel1.add(cmbValue,cc.xy(2,1));
159

    
160
      addButton.setName("addButton");
161
      addButton.setToolTipText("legend-add");
162
      jpanel1.add(addButton,cc.xy(4,1));
163

    
164
      removeButton.setName("removeButton");
165
      jpanel1.add(removeButton,cc.xy(6,1));
166

    
167
      chkAllowOverlap.setActionCommand("_Allow_overlap_drawing_legends");
168
      chkAllowOverlap.setName("chkAllowOverlap");
169
      chkAllowOverlap.setText("_Allow_overlap_drawing_legends");
170
      chkAllowOverlap.setToolTipText("_Allow_overlap_drawing_legends");
171
      jpanel1.add(chkAllowOverlap,cc.xy(8,1));
172

    
173
      addFillComponents(jpanel1,new int[]{ 1,3,5,7,9 },new int[]{ 1 });
174
      return jpanel1;
175
   }
176

    
177
   public JPanel createsymbolPanel()
178
   {
179
      symbolPanel.setName("symbolPanel");
180
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0)","FILL:DEFAULT:GROW(1.0)");
181
      CellConstraints cc = new CellConstraints();
182
      symbolPanel.setLayout(formlayout1);
183

    
184
      addFillComponents(symbolPanel,new int[]{ 1 },new int[]{ 1 });
185
      return symbolPanel;
186
   }
187

    
188
   /**
189
    * Initializer
190
    */
191
   protected void initializePanel()
192
   {
193
      setLayout(new BorderLayout());
194
      add(createPanel(), BorderLayout.CENTER);
195
   }
196

    
197

    
198
}