gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.swing / org.gvsig.scripting.swing.impl / src / main / java / org / gvsig / scripting / swing / impl / composer / JNewScriptPanelLayout.java @ 457
History | View | Annotate | Download (6.93 KB)
1 |
package org.gvsig.scripting.swing.impl.composer; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.ComponentOrientation; |
5 |
import java.awt.Container; |
6 |
import java.awt.Dimension; |
7 |
|
8 |
import javax.swing.Box; |
9 |
import javax.swing.ImageIcon; |
10 |
import javax.swing.JComboBox; |
11 |
import javax.swing.JLabel; |
12 |
import javax.swing.JPanel; |
13 |
import javax.swing.JScrollPane; |
14 |
import javax.swing.JTextArea; |
15 |
import javax.swing.JTextField; |
16 |
|
17 |
import org.gvsig.scripting.swing.api.ScriptingSwingLocator; |
18 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
19 |
|
20 |
import com.jgoodies.forms.layout.CellConstraints; |
21 |
import com.jgoodies.forms.layout.FormLayout; |
22 |
|
23 |
|
24 |
public class JNewScriptPanelLayout extends JPanel |
25 |
{ |
26 |
JLabel Name_ = new JLabel(); |
27 |
JTextField name = new JTextField(); |
28 |
JTextArea description = new JTextArea(); |
29 |
JComboBox units = new JComboBox(); |
30 |
JComboBox languages = new JComboBox(); |
31 |
JTextField saveTo = new JTextField(); |
32 |
JPanel saveToPanel = new JPanel(); |
33 |
JTextField createdBy = new JTextField(); |
34 |
JTextField version = new JTextField(); |
35 |
private ScriptingUIManager uimanager;
|
36 |
|
37 |
/**
|
38 |
* Default constructor
|
39 |
*/
|
40 |
public JNewScriptPanelLayout()
|
41 |
{ |
42 |
this.uimanager = ScriptingSwingLocator.getUIManager();
|
43 |
initializePanel(); |
44 |
} |
45 |
|
46 |
/**
|
47 |
* Adds fill components to empty cells in the first row and first column of the grid.
|
48 |
* This ensures that the grid spacing will be the same as shown in the designer.
|
49 |
* @param cols an array of column indices in the first row where fill components should be added.
|
50 |
* @param rows an array of row indices in the first column where fill components should be added.
|
51 |
*/
|
52 |
void addFillComponents( Container panel, int[] cols, int[] rows ) |
53 |
{ |
54 |
Dimension filler = new Dimension(10,10); |
55 |
|
56 |
boolean filled_cell_11 = false; |
57 |
CellConstraints cc = new CellConstraints();
|
58 |
if ( cols.length > 0 && rows.length > 0 ) |
59 |
{ |
60 |
if ( cols[0] == 1 && rows[0] == 1 ) |
61 |
{ |
62 |
/** add a rigid area */
|
63 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); |
64 |
filled_cell_11 = true;
|
65 |
} |
66 |
} |
67 |
|
68 |
for( int index = 0; index < cols.length; index++ ) |
69 |
{ |
70 |
if ( cols[index] == 1 && filled_cell_11 ) |
71 |
{ |
72 |
continue;
|
73 |
} |
74 |
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); |
75 |
} |
76 |
|
77 |
for( int index = 0; index < rows.length; index++ ) |
78 |
{ |
79 |
if ( rows[index] == 1 && filled_cell_11 ) |
80 |
{ |
81 |
continue;
|
82 |
} |
83 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); |
84 |
} |
85 |
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* Helper method to load an image file from the CLASSPATH
|
90 |
* @param imageName the package and name of the file to load relative to the CLASSPATH
|
91 |
* @return an ImageIcon instance with the specified image file
|
92 |
* @throws IllegalArgumentException if the image resource cannot be loaded.
|
93 |
*/
|
94 |
public ImageIcon loadImage( String imageName ) |
95 |
{ |
96 |
try
|
97 |
{ |
98 |
ClassLoader classloader = getClass().getClassLoader();
|
99 |
java.net.URL url = classloader.getResource( imageName ); |
100 |
if ( url != null ) |
101 |
{ |
102 |
ImageIcon icon = new ImageIcon( url ); |
103 |
return icon;
|
104 |
} |
105 |
} |
106 |
catch( Exception e ) |
107 |
{ |
108 |
e.printStackTrace(); |
109 |
} |
110 |
throw new IllegalArgumentException( "Unable to load image: " + imageName ); |
111 |
} |
112 |
|
113 |
/**
|
114 |
* Method for recalculating the component orientation for
|
115 |
* right-to-left Locales.
|
116 |
* @param orientation the component orientation to be applied
|
117 |
*/
|
118 |
public void applyComponentOrientation( ComponentOrientation orientation ) |
119 |
{ |
120 |
// Not yet implemented...
|
121 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
122 |
super.applyComponentOrientation(orientation);
|
123 |
} |
124 |
|
125 |
public JPanel createPanel() |
126 |
{ |
127 |
JPanel jpanel1 = new JPanel(); |
128 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:MIN(12DLU;DEFAULT):GROW(1.0),FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:GROW(1.0),CENTER: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:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE"); |
129 |
CellConstraints cc = new CellConstraints();
|
130 |
jpanel1.setLayout(formlayout1); |
131 |
|
132 |
Name_.setName("Name:");
|
133 |
Name_.setText(this.uimanager.getTranslation("Name")+":"); |
134 |
jpanel1.add(Name_,cc.xy(2,2)); |
135 |
|
136 |
JLabel jlabel1 = new JLabel(); |
137 |
jlabel1.setText(this.uimanager.getTranslation("Description")+":"); |
138 |
jpanel1.add(jlabel1,new CellConstraints(2,4,1,1,CellConstraints.DEFAULT,CellConstraints.TOP)); |
139 |
|
140 |
JLabel jlabel2 = new JLabel(); |
141 |
jlabel2.setText(this.uimanager.getTranslation("Type")+":"); |
142 |
jpanel1.add(jlabel2,cc.xy(2,6)); |
143 |
|
144 |
JLabel jlabel3 = new JLabel(); |
145 |
jlabel3.setText(this.uimanager.getTranslation("Language")+":"); |
146 |
jpanel1.add(jlabel3,cc.xy(2,8)); |
147 |
|
148 |
JLabel jlabel4 = new JLabel(); |
149 |
jlabel4.setText(this.uimanager.getTranslation("Save")+":"); |
150 |
jpanel1.add(jlabel4,cc.xy(2,10)); |
151 |
|
152 |
JLabel jlabel5 = new JLabel(); |
153 |
jlabel5.setText(this.uimanager.getTranslation("Author")+":"); |
154 |
jpanel1.add(jlabel5,cc.xy(2,13)); |
155 |
|
156 |
JLabel jlabel6 = new JLabel(); |
157 |
jlabel6.setText(this.uimanager.getTranslation("Version")+":"); |
158 |
jpanel1.add(jlabel6,cc.xy(2,15)); |
159 |
|
160 |
name.setName("name");
|
161 |
jpanel1.add(name,cc.xy(3,2)); |
162 |
|
163 |
description.setName("description");
|
164 |
JScrollPane jscrollpane1 = new JScrollPane(); |
165 |
jscrollpane1.setViewportView(description); |
166 |
jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
167 |
jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
168 |
jpanel1.add(jscrollpane1,new CellConstraints(3,4,1,1,CellConstraints.FILL,CellConstraints.FILL)); |
169 |
|
170 |
units.setName("units");
|
171 |
jpanel1.add(units,cc.xy(3,6)); |
172 |
|
173 |
languages.setName("languages");
|
174 |
jpanel1.add(languages,cc.xy(3,8)); |
175 |
|
176 |
saveTo.setEditable(false);
|
177 |
saveTo.setName("saveTo");
|
178 |
saveTo.setScrollOffset(300);
|
179 |
saveTo.setSelectionEnd(85);
|
180 |
saveTo.setSelectionStart(85);
|
181 |
saveTo.setText("esto es una pruaba a ver que pasa con un texto grande a ver si me deja editarlo o no.");
|
182 |
jpanel1.add(saveTo,new CellConstraints(3,10,1,1,CellConstraints.LEFT,CellConstraints.DEFAULT)); |
183 |
|
184 |
saveToPanel.setName("saveToPanel");
|
185 |
jpanel1.add(saveToPanel,cc.xy(3,11)); |
186 |
|
187 |
createdBy.setName("createdBy");
|
188 |
jpanel1.add(createdBy,cc.xy(3,13)); |
189 |
|
190 |
version.setName("version");
|
191 |
jpanel1.add(version,cc.xy(3,15)); |
192 |
|
193 |
addFillComponents(jpanel1,new int[]{ 1,2,3,4 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }); |
194 |
return jpanel1;
|
195 |
} |
196 |
|
197 |
/**
|
198 |
* Initializer
|
199 |
*/
|
200 |
protected void initializePanel() |
201 |
{ |
202 |
setLayout(new BorderLayout()); |
203 |
add(createPanel(), BorderLayout.CENTER);
|
204 |
} |
205 |
|
206 |
|
207 |
} |