Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.coreplugin.app / org.gvsig.coreplugin.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / general / IconThemePageLayout.java @ 40558

History | View | Annotate | Download (5.72 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.coreplugin.preferences.general;
25

    
26
//import com.jeta.open.i18n.I18NUtils;
27
import java.awt.BorderLayout;
28
import java.awt.ComponentOrientation;
29
import java.awt.Container;
30
import java.awt.Dimension;
31

    
32
import javax.swing.Box;
33
import javax.swing.ImageIcon;
34
import javax.swing.JButton;
35
import javax.swing.JComboBox;
36
import javax.swing.JLabel;
37
import javax.swing.JPanel;
38

    
39
import com.jgoodies.forms.layout.CellConstraints;
40
import com.jgoodies.forms.layout.FormLayout;
41

    
42
public class IconThemePageLayout extends JPanel {
43
        /**
44
         * 
45
         */
46
        private static final long serialVersionUID = 732724276675072878L;
47

    
48
        JLabel label_title = new JLabel();
49
        JLabel label_selection = new JLabel();
50
        JLabel label_export = new JLabel();
51
        JComboBox combo_selection = new JComboBox();
52
        JButton button_export = new JButton();
53

    
54
        /**
55
         * Default constructor
56
         */
57
        public IconThemePageLayout() {
58
                initializePanel();
59
        }
60

    
61
        /**
62
         * Adds fill components to empty cells in the first row and first column of
63
         * the grid. This ensures that the grid spacing will be the same as shown in
64
         * the designer.
65
         * 
66
         * @param cols
67
         *            an array of column indices in the first row where fill
68
         *            components should be added.
69
         * @param rows
70
         *            an array of row indices in the first column where fill
71
         *            components should be added.
72
         */
73
        void addFillComponents(Container panel, int[] cols, int[] rows) {
74
                Dimension filler = new Dimension(10, 10);
75

    
76
                boolean filled_cell_11 = false;
77
                CellConstraints cc = new CellConstraints();
78
                if (cols.length > 0 && rows.length > 0) {
79
                        if (cols[0] == 1 && rows[0] == 1) {
80
                                /** add a rigid area */
81
                                panel.add(Box.createRigidArea(filler), cc.xy(1, 1));
82
                                filled_cell_11 = true;
83
                        }
84
                }
85

    
86
                for (int index = 0; index < cols.length; index++) {
87
                        if (cols[index] == 1 && filled_cell_11) {
88
                                continue;
89
                        }
90
                        panel.add(Box.createRigidArea(filler), cc.xy(cols[index], 1));
91
                }
92

    
93
                for (int index = 0; index < rows.length; index++) {
94
                        if (rows[index] == 1 && filled_cell_11) {
95
                                continue;
96
                        }
97
                        panel.add(Box.createRigidArea(filler), cc.xy(1, rows[index]));
98
                }
99

    
100
        }
101

    
102
        /**
103
         * Helper method to load an image file from the CLASSPATH
104
         * 
105
         * @param imageName
106
         *            the package and name of the file to load relative to the
107
         *            CLASSPATH
108
         * @return an ImageIcon instance with the specified image file
109
         * @throws IllegalArgumentException
110
         *             if the image resource cannot be loaded.
111
         */
112
        public ImageIcon loadImage(String imageName) {
113
                try {
114
                        ClassLoader classloader = getClass().getClassLoader();
115
                        java.net.URL url = classloader.getResource(imageName);
116
                        if (url != null) {
117
                                ImageIcon icon = new ImageIcon(url);
118
                                return icon;
119
                        }
120
                } catch (Exception e) {
121
                        e.printStackTrace();
122
                }
123
                throw new IllegalArgumentException("Unable to load image: " + imageName);
124
        }
125

    
126
        /**
127
         * Method for recalculating the component orientation for right-to-left
128
         * Locales.
129
         * 
130
         * @param orientation
131
         *            the component orientation to be applied
132
         */
133
        public void applyComponentOrientation(ComponentOrientation orientation) {
134
                // Not yet implemented...
135
                // I18NUtils.applyComponentOrientation(this, orientation);
136
                super.applyComponentOrientation(orientation);
137
        }
138

    
139
        public JPanel createPanel() {
140
                JPanel jpanel1 = new JPanel();
141
                FormLayout formlayout1 = new FormLayout(
142
                                "FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE",
143
                                "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");
144
                CellConstraints cc = new CellConstraints();
145
                jpanel1.setLayout(formlayout1);
146

    
147
                label_title.setName("label_title");
148
                label_title.setText("_Icon_themes_availables");
149
                jpanel1.add(label_title, cc.xywh(2, 2, 3, 1));
150

    
151
                label_selection.setName("label_selection");
152
                label_selection
153
                                .setText("_Select_an_icon_theme_as_default_for_use_in_the_application");
154
                jpanel1.add(label_selection, cc.xywh(2, 3, 3, 1));
155

    
156
                label_export.setName("label_export");
157
                label_export
158
                                .setText("_You_can_export_the_default_icon_theme_to_use_as_base_for_create_a_custom_icon_theme");
159
                jpanel1.add(label_export, cc.xywh(2, 6, 3, 1));
160

    
161
                combo_selection.setName("combo_selection");
162
                jpanel1.add(combo_selection, cc.xy(3, 4));
163

    
164
                button_export.setActionCommand("_Export_default_icon_theme");
165
                button_export.setName("button_export");
166
                button_export.setText("_Export_default_icon_theme");
167
                jpanel1.add(button_export, new CellConstraints(3, 8, 1, 1,
168
                                CellConstraints.LEFT, CellConstraints.DEFAULT));
169

    
170
                addFillComponents(jpanel1, new int[] { 1, 2, 3, 4 }, new int[] { 1, 2,
171
                                3, 4, 5, 6, 7, 8, 9 });
172
                return jpanel1;
173
        }
174

    
175
        /**
176
         * Initializer
177
         */
178
        protected void initializePanel() {
179
                setLayout(new BorderLayout());
180
                add(createPanel(), BorderLayout.CENTER);
181
        }
182

    
183
}