svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / export / swing / impl / panels / SelectOutputFilePanelView.java @ 44168
History | View | Annotate | Download (4.43 KB)
1 | 43925 | jjdelcerro | package org.gvsig.export.swing.impl.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.JButton; |
||
13 | import javax.swing.JFrame; |
||
14 | import javax.swing.JLabel; |
||
15 | import javax.swing.JPanel; |
||
16 | import javax.swing.JTextField; |
||
17 | import javax.swing.border.EmptyBorder; |
||
18 | |||
19 | |||
20 | public class SelectOutputFilePanelView extends JPanel |
||
21 | { |
||
22 | JLabel lblFile = new JLabel(); |
||
23 | JTextField txtFile = new JTextField(); |
||
24 | JButton btnSelectFile = new JButton(); |
||
25 | |||
26 | /**
|
||
27 | * Default constructor
|
||
28 | */
|
||
29 | public SelectOutputFilePanelView()
|
||
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:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE"); |
||
117 | CellConstraints cc = new CellConstraints();
|
||
118 | jpanel1.setLayout(formlayout1); |
||
119 | |||
120 | lblFile.setName("lblFile");
|
||
121 | lblFile.setText("_File");
|
||
122 | jpanel1.add(lblFile,cc.xy(2,2)); |
||
123 | |||
124 | txtFile.setName("txtFile");
|
||
125 | jpanel1.add(txtFile,cc.xy(4,2)); |
||
126 | |||
127 | btnSelectFile.setActionCommand("...");
|
||
128 | btnSelectFile.setName("btnSelectFile");
|
||
129 | btnSelectFile.setText("...");
|
||
130 | EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2); |
||
131 | btnSelectFile.setBorder(emptyborder1); |
||
132 | jpanel1.add(btnSelectFile,cc.xy(6,2)); |
||
133 | |||
134 | addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7 },new int[]{ 1,2,3 }); |
||
135 | return jpanel1;
|
||
136 | } |
||
137 | |||
138 | /**
|
||
139 | * Initializer
|
||
140 | */
|
||
141 | protected void initializePanel() |
||
142 | { |
||
143 | setLayout(new BorderLayout()); |
||
144 | add(createPanel(), BorderLayout.CENTER);
|
||
145 | } |
||
146 | |||
147 | |||
148 | } |