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