root / org.gvsig.legend.heatmap / trunk / org.gvsig.legend.heatmap.swing / org.gvsig.legend.heatmap.swing.impl / src / main / java / org / gvsig / legend / heatmap / swing / impl / DefaultHeatmapLegendEditorView.java @ 1717
History | View | Annotate | Download (4.07 KB)
1 |
package org.gvsig.legend.heatmap.swing.impl; |
---|---|
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.JFrame; |
13 |
import javax.swing.JLabel; |
14 |
import javax.swing.JPanel; |
15 |
import javax.swing.JTextField; |
16 |
|
17 |
|
18 |
public class DefaultHeatmapLegendEditorView extends JPanel |
19 |
{ |
20 |
JLabel lblDistance = new JLabel(); |
21 |
JTextField txtDistance = new JTextField(); |
22 |
|
23 |
/**
|
24 |
* Default constructor
|
25 |
*/
|
26 |
public DefaultHeatmapLegendEditorView()
|
27 |
{ |
28 |
initializePanel(); |
29 |
} |
30 |
|
31 |
/**
|
32 |
* Adds fill components to empty cells in the first row and first column of the grid.
|
33 |
* This ensures that the grid spacing will be the same as shown in the designer.
|
34 |
* @param cols an array of column indices in the first row where fill components should be added.
|
35 |
* @param rows an array of row indices in the first column where fill components should be added.
|
36 |
*/
|
37 |
void addFillComponents( Container panel, int[] cols, int[] rows ) |
38 |
{ |
39 |
Dimension filler = new Dimension(10,10); |
40 |
|
41 |
boolean filled_cell_11 = false; |
42 |
CellConstraints cc = new CellConstraints();
|
43 |
if ( cols.length > 0 && rows.length > 0 ) |
44 |
{ |
45 |
if ( cols[0] == 1 && rows[0] == 1 ) |
46 |
{ |
47 |
/** add a rigid area */
|
48 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); |
49 |
filled_cell_11 = true;
|
50 |
} |
51 |
} |
52 |
|
53 |
for( int index = 0; index < cols.length; index++ ) |
54 |
{ |
55 |
if ( cols[index] == 1 && filled_cell_11 ) |
56 |
{ |
57 |
continue;
|
58 |
} |
59 |
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); |
60 |
} |
61 |
|
62 |
for( int index = 0; index < rows.length; index++ ) |
63 |
{ |
64 |
if ( rows[index] == 1 && filled_cell_11 ) |
65 |
{ |
66 |
continue;
|
67 |
} |
68 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); |
69 |
} |
70 |
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Helper method to load an image file from the CLASSPATH
|
75 |
* @param imageName the package and name of the file to load relative to the CLASSPATH
|
76 |
* @return an ImageIcon instance with the specified image file
|
77 |
* @throws IllegalArgumentException if the image resource cannot be loaded.
|
78 |
*/
|
79 |
public ImageIcon loadImage( String imageName ) |
80 |
{ |
81 |
try
|
82 |
{ |
83 |
ClassLoader classloader = getClass().getClassLoader();
|
84 |
java.net.URL url = classloader.getResource( imageName ); |
85 |
if ( url != null ) |
86 |
{ |
87 |
ImageIcon icon = new ImageIcon( url ); |
88 |
return icon;
|
89 |
} |
90 |
} |
91 |
catch( Exception e ) |
92 |
{ |
93 |
e.printStackTrace(); |
94 |
} |
95 |
throw new IllegalArgumentException( "Unable to load image: " + imageName ); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Method for recalculating the component orientation for
|
100 |
* right-to-left Locales.
|
101 |
* @param orientation the component orientation to be applied
|
102 |
*/
|
103 |
public void applyComponentOrientation( ComponentOrientation orientation ) |
104 |
{ |
105 |
// Not yet implemented...
|
106 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
107 |
super.applyComponentOrientation(orientation);
|
108 |
} |
109 |
|
110 |
public JPanel createPanel() |
111 |
{ |
112 |
JPanel jpanel1 = new JPanel(); |
113 |
FormLayout formlayout1 = new FormLayout("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"); |
114 |
CellConstraints cc = new CellConstraints();
|
115 |
jpanel1.setLayout(formlayout1); |
116 |
|
117 |
lblDistance.setName("lblDistance");
|
118 |
lblDistance.setText("Distance");
|
119 |
jpanel1.add(lblDistance,cc.xy(2,2)); |
120 |
|
121 |
txtDistance.setName("txtDistance");
|
122 |
jpanel1.add(txtDistance,cc.xy(4,2)); |
123 |
|
124 |
addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3 }); |
125 |
return jpanel1;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* Initializer
|
130 |
*/
|
131 |
protected void initializePanel() |
132 |
{ |
133 |
setLayout(new BorderLayout()); |
134 |
add(createPanel(), BorderLayout.CENTER);
|
135 |
} |
136 |
|
137 |
|
138 |
} |