gvsig-projects-pool / org.gvsig.winmgr / trunk / org.gvsig.winmgr.app / org.gvsig.winmgr.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / general / IconThemePageLayout.java @ 682
History | View | Annotate | Download (4.43 KB)
1 |
package org.gvsig.coreplugin.preferences.general; |
---|---|
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.JComboBox; |
13 |
import javax.swing.JFrame; |
14 |
import javax.swing.JLabel; |
15 |
import javax.swing.JPanel; |
16 |
|
17 |
|
18 |
public class IconThemePageLayout extends JPanel |
19 |
{ |
20 |
JLabel label_title = new JLabel(); |
21 |
JLabel label_selection = new JLabel(); |
22 |
JComboBox combo_selection = new JComboBox(); |
23 |
|
24 |
/**
|
25 |
* Default constructor
|
26 |
*/
|
27 |
public IconThemePageLayout()
|
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:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL: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"); |
115 |
CellConstraints cc = new CellConstraints();
|
116 |
jpanel1.setLayout(formlayout1); |
117 |
|
118 |
label_title.setName("label_title");
|
119 |
label_title.setText("_Icon_themes_availables");
|
120 |
jpanel1.add(label_title,cc.xywh(2,2,3,1)); |
121 |
|
122 |
label_selection.setName("label_selection");
|
123 |
label_selection.setText("_Select_an_icon_theme_as_default_for_use_in_the_application");
|
124 |
jpanel1.add(label_selection,cc.xywh(2,3,3,1)); |
125 |
|
126 |
combo_selection.setName("combo_selection");
|
127 |
jpanel1.add(combo_selection,cc.xy(3,4)); |
128 |
|
129 |
addFillComponents(jpanel1,new int[]{ 1,2,3,4 },new int[]{ 1,2,3,4,5,6,7,8,9 }); |
130 |
return jpanel1;
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* Initializer
|
135 |
*/
|
136 |
protected void initializePanel() |
137 |
{ |
138 |
setLayout(new BorderLayout()); |
139 |
add(createPanel(), BorderLayout.CENTER);
|
140 |
} |
141 |
|
142 |
|
143 |
} |