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