svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.swing / org.gvsig.expressionevaluator.swing.impl / src / main / java / org / gvsig / expressionevaluator / swing / impl / DefaultHistoryPanelView.java @ 44263
History | View | Annotate | Download (4.59 KB)
1 |
package org.gvsig.expressionevaluator.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.JList; |
14 |
import javax.swing.JPanel; |
15 |
import javax.swing.JScrollPane; |
16 |
import javax.swing.JTextArea; |
17 |
|
18 |
|
19 |
public class DefaultHistoryPanelView extends JPanel |
20 |
{ |
21 |
JList lstHistory = new JList(); |
22 |
JTextArea txtFormula = new JTextArea(); |
23 |
|
24 |
/**
|
25 |
* Default constructor
|
26 |
*/
|
27 |
public DefaultHistoryPanelView()
|
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,FILL:DEFAULT:GROW(0.8),CENTER:DEFAULT:NONE,FILL:DEFAULT:GROW(0.2),CENTER:2DLU:NONE"); |
115 |
CellConstraints cc = new CellConstraints();
|
116 |
jpanel1.setLayout(formlayout1); |
117 |
|
118 |
lstHistory.setName("lstHistory");
|
119 |
JScrollPane jscrollpane1 = new JScrollPane(); |
120 |
jscrollpane1.setViewportView(lstHistory); |
121 |
jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
122 |
jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
123 |
jpanel1.add(jscrollpane1,cc.xy(2,2)); |
124 |
|
125 |
txtFormula.setName("txtFormula");
|
126 |
JScrollPane jscrollpane2 = new JScrollPane(); |
127 |
jscrollpane2.setViewportView(txtFormula); |
128 |
jscrollpane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
129 |
jscrollpane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
130 |
jpanel1.add(jscrollpane2,cc.xy(2,4)); |
131 |
|
132 |
addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5 }); |
133 |
return jpanel1;
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* Initializer
|
138 |
*/
|
139 |
protected void initializePanel() |
140 |
{ |
141 |
setLayout(new BorderLayout()); |
142 |
add(createPanel(), BorderLayout.CENTER);
|
143 |
} |
144 |
|
145 |
|
146 |
} |