root / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / NotificationDialogNew.java @ 38564
History | View | Annotate | Download (7.64 KB)
1 | 29630 | jpiera | package org.gvsig.coreplugin; |
---|---|---|---|
2 | 2917 | caballero | |
3 | 33398 | jjdelcerro | import java.awt.BorderLayout; |
4 | import java.awt.Dimension; |
||
5 | import java.awt.FlowLayout; |
||
6 | import java.awt.GridBagConstraints; |
||
7 | import java.awt.GridBagLayout; |
||
8 | import java.awt.LayoutManager; |
||
9 | import java.awt.event.ActionEvent; |
||
10 | import java.awt.event.ActionListener; |
||
11 | |||
12 | import javax.swing.BorderFactory; |
||
13 | 26449 | jmvivo | import javax.swing.JButton; |
14 | 33398 | jjdelcerro | import javax.swing.JComponent; |
15 | import javax.swing.JLabel; |
||
16 | 26449 | jmvivo | import javax.swing.JPanel; |
17 | import javax.swing.JScrollPane; |
||
18 | import javax.swing.JTextArea; |
||
19 | import javax.swing.SwingUtilities; |
||
20 | 33398 | jjdelcerro | import javax.swing.border.Border; |
21 | import javax.swing.border.TitledBorder; |
||
22 | 26449 | jmvivo | |
23 | 38564 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
24 | 29630 | jpiera | import org.gvsig.andami.PluginServices; |
25 | import org.gvsig.andami.messages.MessageEvent; |
||
26 | import org.gvsig.andami.messages.NotificationListener; |
||
27 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
28 | import org.gvsig.andami.ui.mdiManager.SingletonWindow; |
||
29 | import org.gvsig.andami.ui.mdiManager.WindowInfo; |
||
30 | 2917 | caballero | |
31 | 33398 | jjdelcerro | public class NotificationDialogNew extends JPanel implements IWindow, |
32 | SingletonWindow, NotificationListener {
|
||
33 | 2917 | caballero | |
34 | 33398 | jjdelcerro | /**
|
35 | *
|
||
36 | */
|
||
37 | private static final long serialVersionUID = 4363640321917006480L; |
||
38 | 29630 | jpiera | |
39 | 33398 | jjdelcerro | JPanelConsole console; |
40 | JPanelButtons buttons; |
||
41 | JPanelDescription description; |
||
42 | 2917 | caballero | |
43 | 33398 | jjdelcerro | public NotificationDialogNew() {
|
44 | super();
|
||
45 | this.setLayout(new GridBagLayout()); |
||
46 | 2917 | caballero | |
47 | 33398 | jjdelcerro | description = new JPanelDescription();
|
48 | console = new JPanelConsole();
|
||
49 | buttons = new JPanelButtons(console);
|
||
50 | 2917 | caballero | |
51 | 33398 | jjdelcerro | addComppnent(this, description, 0, 0, 3, 1, 1.0, 1.0, |
52 | GridBagConstraints.BOTH, GridBagConstraints.CENTER); |
||
53 | addComppnent(this, buttons, 0, 1, 3, 1, 0, 0, GridBagConstraints.NONE, |
||
54 | GridBagConstraints.NORTHEAST);
|
||
55 | addComppnent(this, console, 0, 2, 3, 1, 1.0, 2.0, |
||
56 | GridBagConstraints.BOTH, GridBagConstraints.CENTER); |
||
57 | this.setVisible(true); |
||
58 | this.hideConsole();
|
||
59 | } |
||
60 | 2917 | caballero | |
61 | 33398 | jjdelcerro | void addComppnent(JPanel panel, JComponent component, int gridx, int gridy, |
62 | int width, int height, double weightx, double weighty, int fill, |
||
63 | int anchor) {
|
||
64 | GridBagConstraints constraints = new GridBagConstraints(); |
||
65 | constraints.gridx = gridx; |
||
66 | constraints.gridy = gridy; |
||
67 | constraints.gridwidth = width; |
||
68 | constraints.gridheight = height; |
||
69 | constraints.weightx = weightx; // 1.0 se estira, 0 no.
|
||
70 | constraints.weighty = weighty; // 1.0 se estira, 0 no.
|
||
71 | constraints.fill = fill; |
||
72 | constraints.anchor = anchor; |
||
73 | constraints.ipadx = 2;
|
||
74 | constraints.ipady = 2;
|
||
75 | 2917 | caballero | |
76 | 33398 | jjdelcerro | panel.add(component, constraints); |
77 | component.setVisible(true);
|
||
78 | } |
||
79 | 2917 | caballero | |
80 | 33398 | jjdelcerro | public void setDescription(String description) { |
81 | this.description.setDescription(description);
|
||
82 | } |
||
83 | 2917 | caballero | |
84 | 33398 | jjdelcerro | public void closeWindow() { |
85 | PluginServices.getMDIManager().closeWindow(this);
|
||
86 | } |
||
87 | 2917 | caballero | |
88 | 33398 | jjdelcerro | public void hideConsole() { |
89 | this.buttons.hideConsole();
|
||
90 | } |
||
91 | 2917 | caballero | |
92 | 33398 | jjdelcerro | public void showConsole() { |
93 | this.buttons.showConsole();
|
||
94 | } |
||
95 | 2917 | caballero | |
96 | 33398 | jjdelcerro | class JPanelDescription extends JPanel { |
97 | /**
|
||
98 | *
|
||
99 | */
|
||
100 | private static final long serialVersionUID = 1529755877776747074L; |
||
101 | JTextArea description = null; |
||
102 | JLabel image;
|
||
103 | 2917 | caballero | |
104 | 33398 | jjdelcerro | JPanelDescription() { |
105 | LayoutManager layout;
|
||
106 | Border border;
|
||
107 | 2917 | caballero | |
108 | 33398 | jjdelcerro | layout = new GridBagLayout(); |
109 | this.setLayout(layout);
|
||
110 | 2917 | caballero | |
111 | 33398 | jjdelcerro | // border = BorderFactory.createTitledBorder("Description");
|
112 | border = BorderFactory.createEmptyBorder();
|
||
113 | this.setBorder(border);
|
||
114 | 26449 | jmvivo | |
115 | 33398 | jjdelcerro | this.image = new JLabel(); |
116 | 38564 | jjdelcerro | this.image.setIcon(IconThemeHelper.getImageIcon("show-console") ); |
117 | 33398 | jjdelcerro | addComppnent(this, this.image, 0, 0, 1, 1, 0, 0, |
118 | GridBagConstraints.NONE, GridBagConstraints.CENTER); |
||
119 | 2917 | caballero | |
120 | 33398 | jjdelcerro | this.description = new JTextArea(); |
121 | this.description.setEditable(false); |
||
122 | this.description.setOpaque(false); |
||
123 | this.description.setText(""); |
||
124 | JScrollPane scrollPanel = new JScrollPane(this.description); |
||
125 | scrollPanel.setBorder(BorderFactory.createEmptyBorder());
|
||
126 | scrollPanel.setPreferredSize(new Dimension(600, 200)); |
||
127 | addComppnent(this, scrollPanel, 1, 0, 1, 1, 1, 1, |
||
128 | GridBagConstraints.BOTH, GridBagConstraints.CENTER); |
||
129 | } |
||
130 | 2917 | caballero | |
131 | 33398 | jjdelcerro | public String getDescription() { |
132 | return this.description.getText(); |
||
133 | } |
||
134 | 2917 | caballero | |
135 | 33398 | jjdelcerro | public void setDescription(String description) { |
136 | this.description.setText(description);
|
||
137 | } |
||
138 | } |
||
139 | 2917 | caballero | |
140 | 33398 | jjdelcerro | class JPanelButtons extends JPanel { |
141 | /**
|
||
142 | *
|
||
143 | */
|
||
144 | private static final long serialVersionUID = 1529755877776747074L; |
||
145 | JButton close = null; |
||
146 | JButton showDetails = null; |
||
147 | JButton hideDetails = null; |
||
148 | JPanel console = null; |
||
149 | 2917 | caballero | |
150 | 33398 | jjdelcerro | JPanelButtons(JPanel console) {
|
151 | this.console = console;
|
||
152 | this.setLayout(new FlowLayout()); |
||
153 | this.close = getCloseButton();
|
||
154 | this.showDetails = getShowDetailsButton();
|
||
155 | this.hideDetails = getHideDetailsButton();
|
||
156 | this.add(this.close); |
||
157 | this.add(this.showDetails); |
||
158 | this.add(this.hideDetails); |
||
159 | hideConsole(); |
||
160 | } |
||
161 | 2917 | caballero | |
162 | 33398 | jjdelcerro | private JButton getCloseButton() { |
163 | JButton button = new JButton( |
||
164 | PluginServices.getText(this, "aceptar")); |
||
165 | button.addActionListener(new ActionListener() { |
||
166 | public void actionPerformed(ActionEvent e) { |
||
167 | closeWindow(); |
||
168 | } |
||
169 | }); |
||
170 | return button;
|
||
171 | } |
||
172 | 2917 | caballero | |
173 | 33398 | jjdelcerro | private JButton getShowDetailsButton() { |
174 | JButton button = new JButton(PluginServices.getText(this, |
||
175 | "detalles") + " >>>"); |
||
176 | button.addActionListener(new ActionListener() { |
||
177 | public void actionPerformed(ActionEvent e) { |
||
178 | showConsole(); |
||
179 | } |
||
180 | }); |
||
181 | return button;
|
||
182 | } |
||
183 | 2917 | caballero | |
184 | 33398 | jjdelcerro | private JButton getHideDetailsButton() { |
185 | JButton button = new JButton(PluginServices.getText(this, |
||
186 | "detalles") + " <<<"); |
||
187 | button.addActionListener(new ActionListener() { |
||
188 | public void actionPerformed(ActionEvent e) { |
||
189 | hideConsole(); |
||
190 | } |
||
191 | }); |
||
192 | return button;
|
||
193 | } |
||
194 | |||
195 | public void hideConsole() { |
||
196 | this.showDetails.setVisible(true); |
||
197 | this.hideDetails.setVisible(false); |
||
198 | this.console.setVisible(false); |
||
199 | } |
||
200 | |||
201 | public void showConsole() { |
||
202 | this.showDetails.setVisible(false); |
||
203 | this.hideDetails.setVisible(true); |
||
204 | this.console.setVisible(true); |
||
205 | } |
||
206 | } |
||
207 | |||
208 | class JPanelConsole extends JPanel { |
||
209 | |||
210 | /**
|
||
211 | *
|
||
212 | */
|
||
213 | private static final long serialVersionUID = -6651900105647107644L; |
||
214 | |||
215 | JPanelConsole() { |
||
216 | BorderLayout layout = new BorderLayout(); |
||
217 | this.setLayout(new BorderLayout()); |
||
218 | TitledBorder border = BorderFactory.createTitledBorder("Console"); |
||
219 | this.setBorder(border);
|
||
220 | this.setLayout(layout);
|
||
221 | this.add(Consola.consolaFrame, BorderLayout.CENTER); |
||
222 | } |
||
223 | } |
||
224 | |||
225 | public Object getWindowModel() { |
||
226 | return "notification-dialog"; |
||
227 | } |
||
228 | |||
229 | public WindowInfo getWindowInfo() {
|
||
230 | WindowInfo info = new WindowInfo(WindowInfo.MODELESSDIALOG
|
||
231 | 33618 | jjdelcerro | | WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE); |
232 | 33398 | jjdelcerro | info.setTitle(PluginServices.getText(this, "Warning")); |
233 | info.setHeight(this.getPreferredSize().height);
|
||
234 | info.setWidth(this.getPreferredSize().width);
|
||
235 | return info;
|
||
236 | } |
||
237 | |||
238 | 26449 | jmvivo | public Object getWindowProfile() { |
239 | return WindowInfo.PROPERTIES_PROFILE;
|
||
240 | } |
||
241 | |||
242 | 33398 | jjdelcerro | public void errorEvent(MessageEvent e) { |
243 | if (e.getMessages() != null) { |
||
244 | for (int i = 0; i < e.getMessages().length; i++) { |
||
245 | this.setDescription(e.getMessages()[i]);
|
||
246 | } |
||
247 | } |
||
248 | |||
249 | PluginServices.getMDIManager().restoreCursor(); |
||
250 | if (SwingUtilities.isEventDispatchThread()) { |
||
251 | PluginServices.getMDIManager().addCentredWindow(this);
|
||
252 | } else {
|
||
253 | final IWindow win = this; |
||
254 | SwingUtilities.invokeLater(new Runnable() { |
||
255 | public void run() { |
||
256 | PluginServices.getMDIManager().addCentredWindow(win); |
||
257 | } |
||
258 | }); |
||
259 | } |
||
260 | } |
||
261 | |||
262 | public void warningEvent(MessageEvent e) { |
||
263 | if (e.getMessages() != null) { |
||
264 | for (int i = 0; i < e.getMessages().length; i++) { |
||
265 | this.setDescription(e.getMessages()[i]);
|
||
266 | } |
||
267 | } |
||
268 | |||
269 | PluginServices.getMDIManager().restoreCursor(); |
||
270 | if (SwingUtilities.isEventDispatchThread()) { |
||
271 | PluginServices.getMDIManager().addCentredWindow(this);
|
||
272 | } else {
|
||
273 | final IWindow win = this; |
||
274 | SwingUtilities.invokeLater(new Runnable() { |
||
275 | public void run() { |
||
276 | PluginServices.getMDIManager().addCentredWindow(win); |
||
277 | } |
||
278 | }); |
||
279 | } |
||
280 | } |
||
281 | |||
282 | public void infoEvent(MessageEvent e) { |
||
283 | // Do nothing, ignore info events
|
||
284 | } |
||
285 | |||
286 | } |