Statistics
| Revision:

root / tags / v2_0_0_Build_2050 / libraries / libCorePlugin / src / org / gvsig / coreplugin / NotificationDialogNew.java @ 38668

History | View | Annotate | Download (7.64 KB)

1
package org.gvsig.coreplugin;
2

    
3
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
import javax.swing.JButton;
14
import javax.swing.JComponent;
15
import javax.swing.JLabel;
16
import javax.swing.JPanel;
17
import javax.swing.JScrollPane;
18
import javax.swing.JTextArea;
19
import javax.swing.SwingUtilities;
20
import javax.swing.border.Border;
21
import javax.swing.border.TitledBorder;
22

    
23
import org.gvsig.andami.IconThemeHelper;
24
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

    
31
public class NotificationDialogNew extends JPanel implements IWindow,
32
                SingletonWindow, NotificationListener {
33

    
34
        /**
35
         * 
36
         */
37
        private static final long serialVersionUID = 4363640321917006480L;
38

    
39
        JPanelConsole console;
40
        JPanelButtons buttons;
41
        JPanelDescription description;
42

    
43
        public NotificationDialogNew() {
44
                super();
45
                this.setLayout(new GridBagLayout());
46

    
47
                description = new JPanelDescription();
48
                console = new JPanelConsole();
49
                buttons = new JPanelButtons(console);
50

    
51
                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

    
61
        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

    
76
                panel.add(component, constraints);
77
                component.setVisible(true);
78
        }
79

    
80
        public void setDescription(String description) {
81
                this.description.setDescription(description);
82
        }
83

    
84
        public void closeWindow() {
85
                PluginServices.getMDIManager().closeWindow(this);
86
        }
87

    
88
        public void hideConsole() {
89
                this.buttons.hideConsole();
90
        }
91

    
92
        public void showConsole() {
93
                this.buttons.showConsole();
94
        }
95

    
96
        class JPanelDescription extends JPanel {
97
                /**
98
                         * 
99
                         */
100
                private static final long serialVersionUID = 1529755877776747074L;
101
                JTextArea description = null;
102
                JLabel image;
103

    
104
                JPanelDescription() {
105
                        LayoutManager layout;
106
                        Border border;
107

    
108
                        layout = new GridBagLayout();
109
                        this.setLayout(layout);
110

    
111
                        // border = BorderFactory.createTitledBorder("Description");
112
                        border = BorderFactory.createEmptyBorder();
113
                        this.setBorder(border);
114

    
115
                        this.image = new JLabel();
116
                        this.image.setIcon(IconThemeHelper.getImageIcon("show-console") );
117
                        addComppnent(this, this.image, 0, 0, 1, 1, 0, 0,
118
                                        GridBagConstraints.NONE, GridBagConstraints.CENTER);
119

    
120
                        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

    
131
                public String getDescription() {
132
                        return this.description.getText();
133
                }
134

    
135
                public void setDescription(String description) {
136
                        this.description.setText(description);
137
                }
138
        }
139

    
140
        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

    
150
                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

    
162
                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

    
173
                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

    
184
                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
                                | WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
232
                info.setTitle(PluginServices.getText(this, "Warning"));
233
                info.setHeight(this.getPreferredSize().height);
234
                info.setWidth(this.getPreferredSize().width);
235
                return info;
236
        }
237

    
238
        public Object getWindowProfile() {
239
                return WindowInfo.PROPERTIES_PROFILE;
240
        }
241

    
242
        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
}