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