root / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / preferences / general / IconThemePanelPage.java @ 38608
History | View | Annotate | Download (4.78 KB)
1 | 38564 | jjdelcerro | package org.gvsig.coreplugin.preferences.general; |
---|---|---|---|
2 | |||
3 | //import com.jeta.open.i18n.I18NUtils;
|
||
4 | import java.awt.BorderLayout; |
||
5 | import java.awt.ComponentOrientation; |
||
6 | import java.awt.Container; |
||
7 | import java.awt.Dimension; |
||
8 | |||
9 | import javax.swing.Box; |
||
10 | import javax.swing.ImageIcon; |
||
11 | import javax.swing.JButton; |
||
12 | import javax.swing.JComboBox; |
||
13 | import javax.swing.JLabel; |
||
14 | import javax.swing.JPanel; |
||
15 | |||
16 | import com.jgoodies.forms.layout.CellConstraints; |
||
17 | import com.jgoodies.forms.layout.FormLayout; |
||
18 | |||
19 | public class IconThemePanelPage extends JPanel { |
||
20 | /**
|
||
21 | *
|
||
22 | */
|
||
23 | private static final long serialVersionUID = 732724276675072878L; |
||
24 | |||
25 | JLabel label_title = new JLabel(); |
||
26 | JLabel label_selection = new JLabel(); |
||
27 | JLabel label_export = new JLabel(); |
||
28 | JComboBox combo_selection = new JComboBox(); |
||
29 | JButton button_export = new JButton(); |
||
30 | |||
31 | /**
|
||
32 | * Default constructor
|
||
33 | */
|
||
34 | public IconThemePanelPage() {
|
||
35 | initializePanel(); |
||
36 | } |
||
37 | |||
38 | /**
|
||
39 | * Adds fill components to empty cells in the first row and first column of
|
||
40 | * the grid. This ensures that the grid spacing will be the same as shown in
|
||
41 | * the designer.
|
||
42 | *
|
||
43 | * @param cols
|
||
44 | * an array of column indices in the first row where fill
|
||
45 | * components should be added.
|
||
46 | * @param rows
|
||
47 | * an array of row indices in the first column where fill
|
||
48 | * components should be added.
|
||
49 | */
|
||
50 | void addFillComponents(Container panel, int[] cols, int[] rows) { |
||
51 | Dimension filler = new Dimension(10, 10); |
||
52 | |||
53 | boolean filled_cell_11 = false; |
||
54 | CellConstraints cc = new CellConstraints();
|
||
55 | if (cols.length > 0 && rows.length > 0) { |
||
56 | if (cols[0] == 1 && rows[0] == 1) { |
||
57 | /** add a rigid area */
|
||
58 | panel.add(Box.createRigidArea(filler), cc.xy(1, 1)); |
||
59 | filled_cell_11 = true;
|
||
60 | } |
||
61 | } |
||
62 | |||
63 | for (int index = 0; index < cols.length; index++) { |
||
64 | if (cols[index] == 1 && filled_cell_11) { |
||
65 | continue;
|
||
66 | } |
||
67 | panel.add(Box.createRigidArea(filler), cc.xy(cols[index], 1)); |
||
68 | } |
||
69 | |||
70 | for (int index = 0; index < rows.length; index++) { |
||
71 | if (rows[index] == 1 && filled_cell_11) { |
||
72 | continue;
|
||
73 | } |
||
74 | panel.add(Box.createRigidArea(filler), cc.xy(1, rows[index])); |
||
75 | } |
||
76 | |||
77 | } |
||
78 | |||
79 | /**
|
||
80 | * Helper method to load an image file from the CLASSPATH
|
||
81 | *
|
||
82 | * @param imageName
|
||
83 | * the package and name of the file to load relative to the
|
||
84 | * CLASSPATH
|
||
85 | * @return an ImageIcon instance with the specified image file
|
||
86 | * @throws IllegalArgumentException
|
||
87 | * if the image resource cannot be loaded.
|
||
88 | */
|
||
89 | public ImageIcon loadImage(String imageName) { |
||
90 | try {
|
||
91 | ClassLoader classloader = getClass().getClassLoader();
|
||
92 | java.net.URL url = classloader.getResource(imageName); |
||
93 | if (url != null) { |
||
94 | ImageIcon icon = new ImageIcon(url); |
||
95 | return icon;
|
||
96 | } |
||
97 | } catch (Exception e) { |
||
98 | e.printStackTrace(); |
||
99 | } |
||
100 | throw new IllegalArgumentException("Unable to load image: " + imageName); |
||
101 | } |
||
102 | |||
103 | /**
|
||
104 | * Method for recalculating the component orientation for right-to-left
|
||
105 | * Locales.
|
||
106 | *
|
||
107 | * @param orientation
|
||
108 | * the component orientation to be applied
|
||
109 | */
|
||
110 | public void applyComponentOrientation(ComponentOrientation orientation) { |
||
111 | // Not yet implemented...
|
||
112 | // I18NUtils.applyComponentOrientation(this, orientation);
|
||
113 | super.applyComponentOrientation(orientation);
|
||
114 | } |
||
115 | |||
116 | public JPanel createPanel() { |
||
117 | JPanel jpanel1 = new JPanel(); |
||
118 | FormLayout formlayout1 = new FormLayout(
|
||
119 | "FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE",
|
||
120 | "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");
|
||
121 | CellConstraints cc = new CellConstraints();
|
||
122 | jpanel1.setLayout(formlayout1); |
||
123 | |||
124 | label_title.setName("label_title");
|
||
125 | label_title.setText("_Icon_themes_availables");
|
||
126 | jpanel1.add(label_title, cc.xywh(2, 2, 3, 1)); |
||
127 | |||
128 | label_selection.setName("label_selection");
|
||
129 | label_selection |
||
130 | .setText("_Select_an_icon_theme_as_default_for_use_in_the_application");
|
||
131 | jpanel1.add(label_selection, cc.xywh(2, 3, 3, 1)); |
||
132 | |||
133 | label_export.setName("label_export");
|
||
134 | label_export |
||
135 | .setText("_You_can_export_the_default_icon_theme_to_use_as_base_for_create_a_custom_icon_theme");
|
||
136 | jpanel1.add(label_export, cc.xywh(2, 6, 3, 1)); |
||
137 | |||
138 | combo_selection.setName("combo_selection");
|
||
139 | jpanel1.add(combo_selection, cc.xy(3, 4)); |
||
140 | |||
141 | button_export.setActionCommand("_Export_default_icon_theme");
|
||
142 | button_export.setName("button_export");
|
||
143 | button_export.setText("_Export_default_icon_theme");
|
||
144 | jpanel1.add(button_export, new CellConstraints(3, 8, 1, 1, |
||
145 | CellConstraints.LEFT, CellConstraints.DEFAULT)); |
||
146 | |||
147 | addFillComponents(jpanel1, new int[] { 1, 2, 3, 4 }, new int[] { 1, 2, |
||
148 | 3, 4, 5, 6, 7, 8, 9 }); |
||
149 | return jpanel1;
|
||
150 | } |
||
151 | |||
152 | /**
|
||
153 | * Initializer
|
||
154 | */
|
||
155 | protected void initializePanel() { |
||
156 | setLayout(new BorderLayout()); |
||
157 | add(createPanel(), BorderLayout.CENTER);
|
||
158 | } |
||
159 | |||
160 | } |