01: /* SwingML
02: * Copyright (C) 2002 SwingML Team
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: *
19: * Authors:
20: * Ezequiel Cuellar <ecuellar@crosslogic.com>
21: * Alessandro Dibella <alessandro.dibella@fuurou.org>
22: */
23:
24: package org.swingml.component;
25:
26: import java.awt.Container;
27:
28: import javax.swing.JComponent;
29: import javax.swing.JOptionPane;
30:
31: import org.swingml.Constants;
32: import org.swingml.SwingMLModel;
33: import org.swingml.event.EventHandler;
34: import org.swingml.model.JOptionPaneModel;
35:
36: public class JOptionPaneComponent extends Container {
37:
38: private EventHandler eventHandler = EventHandler.getInstance();
39:
40: public JOptionPaneComponent(JOptionPaneModel aModel,
41: Container aParent) {
42: String theMessage = aModel.getText();
43: String theType = aModel.getType();
44: String theComponent = aModel.getComponent();
45: if (theComponent != null) {
46: aParent = (Container) this .eventHandler.findActionTarget(
47: aParent, theComponent);
48: }
49: this .eventHandler.handleEvent((SwingMLModel) aModel,
50: Constants.WINDOW_OPENED, (JComponent) aParent);
51: if (theType.equalsIgnoreCase(Constants.CONFIRM)) {
52: int theOption = JOptionPane.showConfirmDialog(aParent,
53: theMessage);
54: if (theOption == JOptionPane.YES_OPTION) {
55: this .eventHandler.handleEvent((SwingMLModel) aModel,
56: Constants.ACTION_PERFORMED_YES,
57: (JComponent) aParent);
58: }
59: if (theOption == JOptionPane.NO_OPTION) {
60: this .eventHandler.handleEvent((SwingMLModel) aModel,
61: Constants.ACTION_PERFORMED_NO,
62: (JComponent) aParent);
63: }
64: if (theOption == JOptionPane.CANCEL_OPTION) {
65: this .eventHandler.handleEvent((SwingMLModel) aModel,
66: Constants.ACTION_PERFORMED_CANCEL,
67: (JComponent) aParent);
68: }
69: }
70: if (theType.equalsIgnoreCase(Constants.MESSAGE)) {
71: JOptionPane.showMessageDialog(aParent, theMessage);
72: this .eventHandler.handleEvent((SwingMLModel) aModel,
73: Constants.ACTION_PERFORMED, (JComponent) aParent);
74: }
75: if (theType.equalsIgnoreCase(Constants.INPUT)) {
76: JOptionPane.showInputDialog(theMessage);
77: }
78: }
79: }
|