Revision 43068 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

View differences:

IconThemePageLayout.java
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 1
package org.gvsig.coreplugin.preferences.general;
25 2

  
26
//import com.jeta.open.i18n.I18NUtils;
3
import com.jeta.open.i18n.I18NUtils;
4
import com.jgoodies.forms.layout.CellConstraints;
5
import com.jgoodies.forms.layout.FormLayout;
27 6
import java.awt.BorderLayout;
28 7
import java.awt.ComponentOrientation;
29 8
import java.awt.Container;
30 9
import java.awt.Dimension;
31
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
33
import java.awt.Insets;
34

  
35 10
import javax.swing.Box;
36 11
import javax.swing.ImageIcon;
37
import javax.swing.JButton;
38 12
import javax.swing.JComboBox;
13
import javax.swing.JFrame;
39 14
import javax.swing.JLabel;
40 15
import javax.swing.JPanel;
41
import javax.swing.JTextArea;
42 16

  
43
import org.gvsig.i18n.Messages;
44 17

  
45
import com.jgoodies.forms.layout.CellConstraints;
46
import com.jgoodies.forms.layout.FormLayout;
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();
47 23

  
48
public class IconThemePageLayout extends JPanel {
49
	/**
50
	 * 
51
	 */
52
	private static final long serialVersionUID = 732724276675072878L;
24
   /**
25
    * Default constructor
26
    */
27
   public IconThemePageLayout()
28
   {
29
      initializePanel();
30
   }
53 31

  
54
	JLabel label_title = new JLabel();
55
	JLabel label_selection = new JLabel();
56
	JTextArea label_export = new JTextArea();
57
	JComboBox combo_selection = new JComboBox();
58
	JButton button_export = new JButton();
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);
59 41

  
60
	/**
61
	 * Default constructor
62
	 */
63
	public IconThemePageLayout() {
64
		initializePanel();
65
	}
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
      }
66 53

  
67
	/**
68
	 * Adds fill components to empty cells in the first row and first column of
69
	 * the grid. This ensures that the grid spacing will be the same as shown in
70
	 * the designer.
71
	 * 
72
	 * @param cols
73
	 *            an array of column indices in the first row where fill
74
	 *            components should be added.
75
	 * @param rows
76
	 *            an array of row indices in the first column where fill
77
	 *            components should be added.
78
	 */
79
	void addFillComponents(Container panel, int[] cols, int[] rows) {
80
		Dimension filler = new Dimension(10, 10);
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
      }
81 62

  
82
		boolean filled_cell_11 = false;
83
		CellConstraints cc = new CellConstraints();
84
		if (cols.length > 0 && rows.length > 0) {
85
			if (cols[0] == 1 && rows[0] == 1) {
86
				/** add a rigid area */
87
				panel.add(Box.createRigidArea(filler), cc.xy(1, 1));
88
				filled_cell_11 = true;
89
			}
90
		}
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
      }
91 71

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

  
99
		for (int index = 0; index < rows.length; index++) {
100
			if (rows[index] == 1 && filled_cell_11) {
101
				continue;
102
			}
103
			panel.add(Box.createRigidArea(filler), cc.xy(1, rows[index]));
104
		}
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
   }
105 98

  
106
	}
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
   }
107 110

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

  
132
	/**
133
	 * Method for recalculating the component orientation for right-to-left
134
	 * Locales.
135
	 * 
136
	 * @param orientation
137
	 *            the component orientation to be applied
138
	 */
139
	public void applyComponentOrientation(ComponentOrientation orientation) {
140
		// Not yet implemented...
141
		// I18NUtils.applyComponentOrientation(this, orientation);
142
		super.applyComponentOrientation(orientation);
143
	}
118
      label_title.setName("label_title");
119
      label_title.setText("_Icon_themes_availables");
120
      jpanel1.add(label_title,cc.xywh(2,2,3,1));
144 121

  
145
	public JPanel createPanel() {
146
		
147
		GridBagLayout gbl = new GridBagLayout();
148
		JPanel resp = new JPanel(gbl);
149
		GridBagConstraints gbc = new GridBagConstraints();
150
		
151
		gbc.insets = new Insets(2, 30, 0, 30);
152
		gbc.anchor = GridBagConstraints.NORTHWEST;
153
		gbc.fill = GridBagConstraints.BOTH;
154
		gbc.gridx = 0;
155
		// ==============================
156
		gbc.gridy = 0;
157
		label_title.setName("label_title");
158
		label_title.setText(Messages.getText("_Icon_themes_availables"));
159
		resp.add(label_title, gbc);
160
		// ==============================
161
		gbc.gridy = 1;
162
		label_selection.setName("label_selection");
163
		label_selection.setText(Messages.getText(
164
				"_Select_an_icon_theme_as_default_for_use_in_the_application"));
165
		resp.add(label_selection, gbc);
166
		// ==============================
167
		gbc.gridy = 2;
168
		combo_selection.setName("combo_selection");
169
		resp.add(combo_selection, gbc);
170
		// ==============================
171
		gbc.gridy = 3;
172
		resp.add(new JLabel(" "), gbc);
173
		// ==============================
174
		gbc.gridy = 4;
175
		label_export.setName("label_export");
176
		label_export.setWrapStyleWord(true);
177
		label_export.setLineWrap(true);
178
		label_export.setFont(new JLabel().getFont());
179
		label_export.setBackground(resp.getBackground());
180
		label_export.setText(Messages.getText(
181
				"_You_can_export_the_default_icon_theme_to_use_as_base_for_create_a_custom_icon_theme"));
182
		resp.add(label_export, gbc);
183
		// ==============================
184
		gbc.gridy = 5;
185
		gbc.fill = GridBagConstraints.NONE;
186
		gbc.anchor = GridBagConstraints.NORTH;
187
		button_export.setActionCommand("_Export_default_icon_theme");
188
		button_export.setName("button_export");
189
		button_export.setText(Messages.getText(
190
				"_Export_default_icon_theme"));
191
		resp.add(button_export, gbc);
192
		// ==============================
193
		return resp;
194
	}
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));
195 125

  
196
	/**
197
	 * Initializer
198
	 */
199
	protected void initializePanel() {
200
		setLayout(new BorderLayout());
201
		add(createPanel(), BorderLayout.CENTER);
202
	}
126
      combo_selection.setName("combo_selection");
127
      jpanel1.add(combo_selection,cc.xy(3,4));
203 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

  
204 143
}

Also available in: Unified diff