001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package wingset;
014:
015: import org.wings.*;
016:
017: import java.awt.event.ActionEvent;
018: import java.awt.event.ActionListener;
019:
020: /**
021: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
022: */
023: public class OptionPaneExample extends WingSetPane {
024:
025: private ComponentControls controls;
026:
027: protected SComponent createControls() {
028: controls = new OptionPaneControls();
029: return controls;
030: }
031:
032: protected SComponent createExample() {
033: SDesktopPane desktopPane = new SDesktopPane();
034:
035: desktopPane.add(createPersonalDataFrame());
036: desktopPane.add(createBusinessDataFrame());
037:
038: return desktopPane;
039: }
040:
041: private SInternalFrame createPersonalDataFrame() {
042:
043: final SInternalFrame personalData = new SInternalFrame();
044: SContainer pane = personalData.getContentPane();
045: pane.setLayout(new SGridLayout(5, 2, 5, 5));
046:
047: pane.add(new SLabel("Firstname"));
048: pane.add(new STextField());
049: pane.add(new SLabel("Lastname"));
050: pane.add(new STextField());
051: pane.add(new SLabel("Street"));
052: pane.add(new STextField());
053: pane.add(new SLabel("Zip"));
054: pane.add(new STextField());
055: pane.add(new SLabel("City"));
056: pane.add(new STextField());
057: pane.add(new SLabel("E-Mail"));
058: pane.add(new STextField());
059:
060: SButton save = new SButton("Save");
061: save.addActionListener(new ActionListener() {
062: public void actionPerformed(ActionEvent e) {
063: SOptionPane
064: .showMessageDialog(
065: personalData,
066: "As for demo reasons the data isn't really persisted.",
067: "Data Saved");
068: }
069: });
070: pane.add(save);
071:
072: SButton cancel = new SButton("Cancel");
073: cancel.addActionListener(new ActionListener() {
074: public void actionPerformed(ActionEvent e) {
075: SOptionPane.showMessageDialog(personalData,
076: "No action defined.", "No Action");
077: }
078: });
079: pane.add(cancel);
080:
081: return personalData;
082: }
083:
084: private SInternalFrame createBusinessDataFrame() {
085:
086: final SInternalFrame businessData = new SInternalFrame();
087: SContainer pane = businessData.getContentPane();
088: pane.setLayout(new SGridLayout(5, 2, 5, 5));
089:
090: pane.add(new SLabel("Company"));
091: pane.add(new STextField());
092: pane.add(new SLabel("Street"));
093: pane.add(new STextField());
094: pane.add(new SLabel("Zip"));
095: pane.add(new STextField());
096: pane.add(new SLabel("City"));
097: pane.add(new STextField());
098: pane.add(new SLabel("Department"));
099: pane.add(new STextField());
100: pane.add(new SLabel("Profession"));
101: pane.add(new STextField());
102:
103: SButton save = new SButton("Save");
104: save.addActionListener(new ActionListener() {
105: public void actionPerformed(ActionEvent e) {
106: SOptionPane
107: .showMessageDialog(
108: businessData,
109: "As for demo reasons the data isn't really persisted.",
110: "Data Saved");
111: }
112: });
113: pane.add(save);
114:
115: SButton cancel = new SButton("Cancel");
116: cancel.addActionListener(new ActionListener() {
117: public void actionPerformed(ActionEvent e) {
118: SOptionPane.showMessageDialog(businessData,
119: "No action defined.", "No Action");
120: }
121: });
122: pane.add(cancel);
123:
124: return businessData;
125: }
126:
127: class OptionPaneControls extends ComponentControls {
128: public OptionPaneControls() {
129: globalControls.setVisible(false);
130:
131: SButton msg = new SButton("show Message");
132: msg.addActionListener(new java.awt.event.ActionListener() {
133: public void actionPerformed(ActionEvent e) {
134: SOptionPane.showPlainMessageDialog(null,
135: "This is a simple message", "A Message");
136: }
137: });
138: addControl(msg);
139:
140: SButton question = new SButton("show Question");
141: final ActionListener comment = new java.awt.event.ActionListener() {
142: public void actionPerformed(ActionEvent e) {
143: if (e.getActionCommand().equals(
144: SOptionPane.OK_ACTION)) {
145: SOptionPane.showPlainMessageDialog(null,
146: "Fine !");
147: } else {
148: SOptionPane
149: .showPlainMessageDialog(null,
150: "No Problem, just look at another site");
151: }
152: }
153: };
154:
155: question
156: .addActionListener(new java.awt.event.ActionListener() {
157: public void actionPerformed(ActionEvent e) {
158: SOptionPane.showQuestionDialog(null,
159: "Continue this example?",
160: "A Question", comment);
161: }
162: });
163: addControl(question);
164:
165: SButton yesno = new SButton("show Yes No");
166: final ActionListener feedback = new java.awt.event.ActionListener() {
167: public void actionPerformed(ActionEvent e) {
168: if (e.getActionCommand().equals(
169: SOptionPane.NO_ACTION)) {
170: SPanel p = new SPanel(new SFlowDownLayout());
171: p.add(new SLabel("That's sad!"));
172: SAnchor sendMail = new SAnchor(
173: "mailto:haaf@mercatis.de");
174: sendMail.add(new SLabel("Please send my why!"));
175: p.add(sendMail);
176: SOptionPane.showPlainMessageDialog(null, p);
177: } else {
178: SOptionPane.showPlainMessageDialog(null,
179: "Fine, so do we!");
180: }
181: }
182: };
183:
184: yesno
185: .addActionListener(new java.awt.event.ActionListener() {
186: public void actionPerformed(ActionEvent e) {
187: SOptionPane.showYesNoDialog(null,
188: "Do you like wingS",
189: "A Yes No Question", feedback);
190: }
191: });
192:
193: addControl(yesno);
194:
195: SButton information = new SButton("show Information");
196: information.addActionListener(new ActionListener() {
197: public void actionPerformed(ActionEvent e) {
198: SOptionPane.showMessageDialog(null,
199: "wingS2 WingSet", "Information");
200: }
201: });
202: addControl(information);
203:
204: final SLabel label = new SLabel();
205: final ActionListener inputListener = new java.awt.event.ActionListener() {
206: public void actionPerformed(ActionEvent e) {
207: if (e.getActionCommand().equals(
208: SOptionPane.OK_ACTION)) {
209: final SOptionPane optionPane = (SOptionPane) e
210: .getSource();
211: STextField inputValue = (STextField) optionPane
212: .getInputValue();
213:
214: if ("".equals(inputValue.getText().trim())) {
215: SOptionPane.showMessageDialog(null,
216: "The profession field is empty.",
217: "Empty profession field",
218: SOptionPane.ERROR_MESSAGE,
219: new ActionListener() {
220: public void actionPerformed(
221: ActionEvent e) {
222: optionPane.show(null);
223: }
224: });
225: } else {
226: label.setText("" + inputValue.getText());
227: }
228: }
229: }
230: };
231:
232: SButton input = new SButton("show Input");
233: input
234: .addActionListener(new java.awt.event.ActionListener() {
235: public void actionPerformed(ActionEvent e) {
236: SOptionPane.showInputDialog(null,
237: "What's your profession?",
238: "A Message", new STextField(),
239: inputListener);
240: }
241: });
242: addControl(input);
243: addControl(label);
244: }
245: }
246: }
|