1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package us.paulevans.basicxslt; |
17 | |
|
18 | |
import java.awt.BorderLayout; |
19 | |
import java.awt.Color; |
20 | |
import java.awt.Component; |
21 | |
import java.awt.FlowLayout; |
22 | |
import java.awt.Font; |
23 | |
import java.awt.GridBagConstraints; |
24 | |
import java.awt.GridBagLayout; |
25 | |
import java.awt.event.ActionEvent; |
26 | |
import java.awt.event.ActionListener; |
27 | |
import java.awt.event.WindowAdapter; |
28 | |
import java.awt.event.WindowEvent; |
29 | |
|
30 | |
import javax.swing.BorderFactory; |
31 | |
import javax.swing.JButton; |
32 | |
import javax.swing.JLabel; |
33 | |
import javax.swing.JMenu; |
34 | |
import javax.swing.JMenuBar; |
35 | |
import javax.swing.JMenuItem; |
36 | |
import javax.swing.JPanel; |
37 | |
import javax.swing.JScrollPane; |
38 | |
import javax.swing.JSeparator; |
39 | |
import javax.swing.JTextArea; |
40 | |
|
41 | |
import net.blueslate.commons.gui.GUIUtils; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | 0 | public class ValidationErrorFrame extends DisposableFrame |
49 | |
implements ActionListener { |
50 | |
|
51 | |
|
52 | |
|
53 | |
private static final String DEFAULT_FRAME_WIDTH = "590"; |
54 | |
private static final String DEFAULT_FRAME_HEIGHT = "350"; |
55 | |
|
56 | |
|
57 | |
private static final String PROPERTY_NAME_PREFIX = "validationerror_"; |
58 | |
|
59 | |
|
60 | 0 | private static final LabelStringFactory stringFactory = |
61 | |
LabelStringFactory.getInstance(); |
62 | |
|
63 | |
|
64 | |
private JButton closeBtn; |
65 | |
private JMenuItem close; |
66 | |
private UserPreferences userPrefs; |
67 | |
private String propertyNamePrefix; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public ValidationErrorFrame(BasicXSLTFrame aParent, String aTitle, |
82 | |
String aHeaderLabel, String aErrHeader, int aErrColumn, int aErrLine, |
83 | 0 | String aErrText, String aFileName, XSLRow aXSLRows[]) { |
84 | |
|
85 | |
Component panel; |
86 | |
|
87 | 0 | buildMenuBar(); |
88 | 0 | JPanel southPanel = new JPanel(new FlowLayout()); |
89 | 0 | southPanel.add(closeBtn = new JButton("Close")); |
90 | 0 | panel = buildMainPanel(aHeaderLabel, aErrHeader, aErrColumn, |
91 | |
aErrLine, aErrText, aFileName); |
92 | 0 | closeBtn.addActionListener(this); |
93 | 0 | getContentPane().setLayout(new BorderLayout()); |
94 | 0 | getContentPane().add(panel, BorderLayout.CENTER); |
95 | 0 | getContentPane().add(southPanel, BorderLayout.SOUTH); |
96 | 0 | setTitle(aTitle); |
97 | 0 | setWindowCloseListener(); |
98 | 0 | setSize(); |
99 | 0 | GUIUtils.center(this, aParent); |
100 | 0 | setVisible(true); |
101 | 0 | } |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
private void setWindowCloseListener() { |
108 | 0 | addWindowListener(new WindowAdapter() { |
109 | 0 | public void windowClosing(WindowEvent evt) { |
110 | 0 | dispose(userPrefs, PROPERTY_NAME_PREFIX); |
111 | 0 | } |
112 | |
}); |
113 | 0 | } |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
private void setSize() { |
120 | |
|
121 | |
int width, height; |
122 | |
|
123 | 0 | userPrefs = Utils.getUserPrefs(); |
124 | 0 | width = Integer.parseInt(userPrefs.getProperty(propertyNamePrefix + |
125 | |
AppConstants.FRAME_WIDTH_PROP, DEFAULT_FRAME_WIDTH)); |
126 | 0 | height = Integer.parseInt(userPrefs.getProperty(propertyNamePrefix + |
127 | |
AppConstants.FRAME_HEIGHT_PROP, DEFAULT_FRAME_HEIGHT)); |
128 | 0 | setSize(width, height); |
129 | 0 | } |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
private static JScrollPane buildMainPanel(String aHeaderLabel, |
142 | |
String aErrHeader, int aErrColumn, int aErrLine, String aErrText, |
143 | |
String aFileName) { |
144 | |
|
145 | |
GridBagLayout layout; |
146 | |
GridBagConstraints constraints; |
147 | |
JPanel panel; |
148 | |
JScrollPane scrollPane; |
149 | |
int row; |
150 | |
int col; |
151 | |
JLabel headerLabel; |
152 | |
JLabel fileLabel; |
153 | |
JLabel errLineLabel; |
154 | |
JLabel errLine; |
155 | |
JLabel errColLabel; |
156 | |
JLabel errCol; |
157 | |
JLabel errTextLabel; |
158 | |
JTextArea errText; |
159 | |
|
160 | 0 | layout = new GridBagLayout(); |
161 | 0 | constraints = new GridBagConstraints(); |
162 | 0 | panel = new JPanel(layout); |
163 | 0 | scrollPane = new JScrollPane(panel, |
164 | |
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, |
165 | |
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
166 | 0 | row = 0; |
167 | 0 | col = 0; |
168 | 0 | headerLabel = new JLabel("!" + aErrHeader + " (" + aHeaderLabel + ")"); |
169 | 0 | headerLabel.setForeground(Color.RED); |
170 | 0 | headerLabel.setFont(new Font("arial", Font.PLAIN, 18)); |
171 | 0 | fileLabel = new JLabel(stringFactory.getString( |
172 | |
LabelStringFactory.VALIDATIONERR_FRAME_FILE) + aFileName); |
173 | 0 | fileLabel.setFont(new Font("arial", Font.PLAIN, 12)); |
174 | 0 | errLineLabel = new JLabel(stringFactory.getString( |
175 | |
LabelStringFactory.VALIDATIONERR_FRAME_LINE_NUM)); |
176 | 0 | errLine = new JLabel(aErrLine == -1 ? stringFactory.getString( |
177 | |
LabelStringFactory.VALIDATIONERR_FRAME_NOT_AVAILABLE) : |
178 | |
Integer.toString(aErrLine)); |
179 | 0 | errColLabel = new JLabel(stringFactory.getString( |
180 | |
LabelStringFactory.VALIDATIONERR_FRAME_COLUMN_NUM)); |
181 | 0 | errCol = new JLabel(aErrColumn == -1 ? stringFactory.getString( |
182 | |
LabelStringFactory.VALIDATIONERR_FRAME_NOT_AVAILABLE) : |
183 | |
Integer.toString(aErrColumn)); |
184 | 0 | errTextLabel = new JLabel(stringFactory.getString( |
185 | |
LabelStringFactory.VALIDATIONERR_FRAME_MSG)); |
186 | 0 | errText = new JTextArea(7, 30); |
187 | 0 | errText.setBorder(BorderFactory.createLoweredBevelBorder()); |
188 | 0 | errText.setText(aErrText); |
189 | 0 | errText.setEditable(false); |
190 | 0 | errText.setLineWrap(true); |
191 | 0 | errText.setWrapStyleWord(true); |
192 | 0 | GUIUtils.add(panel, headerLabel, layout, constraints, row++, col, |
193 | |
1, 2, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH, |
194 | |
GUIUtils.MED_LARGE_INSETS); |
195 | 0 | GUIUtils.add(panel, new JSeparator(), layout, constraints, row++, col, |
196 | |
1, 2, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH, |
197 | |
GUIUtils.MED_LARGE_INSETS); |
198 | 0 | GUIUtils.add(panel, fileLabel, layout, constraints, row++, col, |
199 | |
1, 2, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH, |
200 | |
GUIUtils.MED_LARGE_INSETS); |
201 | 0 | GUIUtils.add(panel, new JSeparator(), layout, constraints, row++, col, |
202 | |
1, 2, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH, |
203 | |
GUIUtils.MED_LARGE_INSETS); |
204 | 0 | GUIUtils.add(panel, errLineLabel, layout, constraints, row, col++, |
205 | |
1, 1, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, |
206 | |
GUIUtils.SMALL_INSETS); |
207 | 0 | GUIUtils.add(panel, errLine, layout, constraints, row++, col, |
208 | |
1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, |
209 | |
GUIUtils.SMALL_INSETS); |
210 | 0 | GUIUtils.add(panel, errColLabel, layout, constraints, row, col=0, |
211 | |
1, 1, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, |
212 | |
GUIUtils.SMALL_INSETS); |
213 | 0 | GUIUtils.add(panel, errCol, layout, constraints, row++, ++col, |
214 | |
1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, |
215 | |
GUIUtils.SMALL_INSETS); |
216 | 0 | GUIUtils.add(panel, errTextLabel, layout, constraints, row, col=0, |
217 | |
1, 1, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, |
218 | |
GUIUtils.SMALL_INSETS); |
219 | 0 | GUIUtils.add(panel, new JScrollPane(errText, |
220 | |
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, |
221 | |
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), layout, |
222 | |
constraints, row++, 1, 1, 1, GridBagConstraints.WEST, |
223 | |
GridBagConstraints.BOTH, GUIUtils.SMALL_INSETS); |
224 | 0 | return scrollPane; |
225 | |
} |
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
private void buildMenuBar() { |
231 | |
|
232 | |
JMenu file; |
233 | |
JMenuBar menuBar; |
234 | |
|
235 | 0 | menuBar = new JMenuBar(); |
236 | 0 | file = new JMenu(stringFactory.getString( |
237 | |
LabelStringFactory.VF_FILE_MENU)); |
238 | 0 | file.setMnemonic(stringFactory.getMnemonic( |
239 | |
LabelStringFactory.VF_FILE_MENU)); |
240 | 0 | close = new JMenuItem(stringFactory.getString( |
241 | |
LabelStringFactory.VF_FILE_CLOSE_MI)); |
242 | 0 | close.setMnemonic(stringFactory.getMnemonic( |
243 | |
LabelStringFactory.VF_FILE_CLOSE_MI)); |
244 | 0 | close.addActionListener(this); |
245 | 0 | file.add(close); |
246 | 0 | menuBar.add(file); |
247 | 0 | setJMenuBar(menuBar); |
248 | 0 | } |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
public void actionPerformed(ActionEvent aEvt) { |
255 | 0 | if (aEvt.getSource() == closeBtn || aEvt.getSource() == close) { |
256 | 0 | dispose(userPrefs, PROPERTY_NAME_PREFIX); |
257 | |
} |
258 | 0 | } |
259 | |
} |