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.ActionListener;
018: import java.awt.event.ActionEvent;
019:
020: /**
021: * <code>DialogExample</code>.
022: * <p/>
023: * User: raedler
024: * Date: Oct 11, 2007
025: * Time: 12:42:05 PM
026: *
027: * @author raedler
028: * @version $Id
029: */
030: public class DialogExample extends WingSetPane {
031:
032: protected static final Boolean[] TRUE_FALSE = new Boolean[] {
033: Boolean.TRUE, Boolean.FALSE };
034:
035: private ComponentControls controls;
036:
037: protected SComponent createControls() {
038: controls = new DialogControls();
039: return controls;
040: }
041:
042: protected SComponent createExample() {
043: return new SPanel();
044: }
045:
046: class DialogControls extends ComponentControls {
047:
048: private STextField firstname;
049: private STextField lastname;
050: private STextField email;
051:
052: DialogControls() {
053: globalControls.setVisible(false);
054:
055: final SComboBox modality = new SComboBox(TRUE_FALSE);
056: addControl(new SLabel("Modal:"));
057: addControl(modality);
058:
059: final SComboBox draggability = new SComboBox(TRUE_FALSE);
060: addControl(new SLabel("Draggable"));
061: addControl(draggability);
062:
063: SButton createDialog = new SButton("Create Dialog");
064: addControl(createDialog);
065:
066: createDialog.addActionListener(new ActionListener() {
067: public void actionPerformed(ActionEvent e) {
068:
069: Boolean modal = (Boolean) modality
070: .getSelectedItem();
071: Boolean draggable = (Boolean) draggability
072: .getSelectedItem();
073:
074: final SDialog dialog = new SDialog(
075: getParentFrame(), "Contact Dialog", modal);
076: dialog.setLayout(new SFlowDownLayout());
077: dialog.setDraggable(draggable);
078: dialog.add(createContent());
079:
080: SPanel buttonPanel = new SPanel(new SGridLayout(1,
081: 2, 5, 5));
082: SButton okButton = new SButton("OK");
083: buttonPanel.add(okButton);
084: okButton.addActionListener(new ActionListener() {
085: public void actionPerformed(ActionEvent e) {
086:
087: if (!"".equals(firstname.getText())
088: && firstname.getText() != null
089: && !"".equals(lastname.getText())
090: && lastname.getText() != null
091: && !"".equals(email.getText())
092: && email.getText() != null) {
093: SOptionPane
094: .showMessageDialog(
095: DialogExample.this ,
096: "Hi "
097: + firstname
098: .getText()
099: + " "
100: + lastname
101: .getText()
102: + ", your email address is "
103: + email
104: .getText()
105: + ".",
106: "Your Information",
107: SOptionPane.INFORMATION_MESSAGE);
108: dialog.setVisible(false);
109: } else {
110: SOptionPane.showMessageDialog(
111: DialogExample.this ,
112: "Please fill out the form.",
113: "Information incomplete",
114: SOptionPane.ERROR_MESSAGE);
115: }
116: }
117: });
118:
119: SButton cancelButton = new SButton("Cancel");
120: buttonPanel.add(cancelButton);
121: cancelButton
122: .addActionListener(new ActionListener() {
123: public void actionPerformed(
124: ActionEvent e) {
125: dialog.setVisible(false);
126: }
127: });
128:
129: dialog.add(buttonPanel);
130:
131: dialog.setVisible(true);
132: }
133: });
134: }
135:
136: private SPanel createContent() {
137:
138: firstname = new STextField();
139: lastname = new STextField();
140: email = new STextField();
141: SLabel image = new SLabel(new SURLIcon(
142: "../icons/cowSmall.gif"));
143:
144: SPanel content = new SPanel(new SGridLayout(4, 2, 5, 5));
145: content.add(new SLabel("Firstname:"));
146: content.add(firstname);
147: content.add(new SLabel("Lastname:"));
148: content.add(lastname);
149: content.add(new SLabel("E-Mail:"));
150: content.add(email);
151: content.add(new SLabel("Image:"));
152: content.add(image);
153:
154: return content;
155: }
156: }
157: }
|