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