001: package com.xoetrope.carousel.survey;
002:
003: import com.xoetrope.survey.Question;
004: import com.xoetrope.survey.QuestionGroup;
005: import com.xoetrope.survey.Condition;
006: import com.xoetrope.survey.Survey;
007: import com.xoetrope.survey.SurveyManager;
008: import com.xoetrope.survey.Option;
009: import java.awt.BorderLayout;
010: import java.awt.Dimension;
011: import java.awt.FlowLayout;
012: import java.awt.GridBagConstraints;
013: import java.awt.GridBagLayout;
014: import java.awt.Insets;
015: import java.awt.Toolkit;
016: import java.awt.event.ActionEvent;
017: import java.awt.event.ActionListener;
018: import javax.swing.*;
019: import javax.swing.border.Border;
020: import javax.swing.border.TitledBorder;
021: import net.xoetrope.xui.XProject;
022: import net.xoetrope.xui.XProjectManager;
023:
024: /**
025: * Dialog for adding new condition.
026: *
027: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
028: * the GNU Public License (GPL), please see license.txt for more details. If
029: * you make commercial use of this software you must purchase a commercial
030: * license from Xoetrope.</p>
031: * <p> $Revision: 1.5 $</p>
032: */
033: public class NewConditionDialog extends JDialog {
034: public static final int LABEL_WIDTH = 280;
035: public static final int EDIT_WIDTH = 280;
036: public static final int ROW_HEIGHT = 24;
037: public static final int WIDTH = 320;
038: public static final int HEIGHT = 170;
039: public static final int BUTTON_WIDTH = 80;
040: public static final int BUTTON_HEIGHT = 24;
041:
042: protected XSurvey survey;
043:
044: protected JComboBox questionCombo;
045: protected boolean okPressed;
046:
047: /**
048: * Creates a new instance of NewConditionDialog
049: */
050: public NewConditionDialog() {
051: super ();
052: XProject project = XProjectManager.getCurrentProject();
053: survey = (XSurvey) project.getObject("Survey");
054: setModal(true);
055: okPressed = false;
056: init();
057: }
058:
059: /**
060: * Displays the dialog
061: * @param rule the rule which this dialog will
062: * visualise
063: */
064: public boolean showDialog(XRule rule) {
065: XQuestionGroup group = rule.getGroup();
066: questionCombo.setModel(new DefaultComboBoxModel(group
067: .getQuestions()));
068: okPressed = false;
069: setVisible(true);
070: return okPressed;
071: }
072:
073: /**
074: * Gets the selected question
075: * @return the selected question
076: */
077: public Question getQuestion() {
078: return (Question) questionCombo.getSelectedItem();
079: }
080:
081: /**
082: * Initializes the dialog
083: */
084: private void init() {
085: Dimension labelSize = new Dimension(LABEL_WIDTH, ROW_HEIGHT);
086: Dimension editSize = new Dimension(EDIT_WIDTH, ROW_HEIGHT);
087: Dimension buttonSize = new Dimension(BUTTON_WIDTH,
088: BUTTON_HEIGHT);
089: Dimension size = new Dimension(WIDTH, HEIGHT);
090: setSize(size);
091: setPreferredSize(size);
092:
093: Border titledBorder = BorderFactory
094: .createTitledBorder(" Add new condition");
095:
096: JPanel mainPanel = new JPanel();
097: mainPanel.setLayout(new BorderLayout());
098: JPanel editPanel = new JPanel();
099: editPanel.setLayout(new GridBagLayout());
100: JPanel bottomPanel = new JPanel();
101: bottomPanel.setLayout(new FlowLayout());
102:
103: JLabel questionLabel = new JLabel("Question: ");
104: questionLabel.setSize(labelSize);
105: questionLabel.setPreferredSize(labelSize);
106: questionLabel.setMinimumSize(labelSize);
107: questionLabel.setHorizontalAlignment(SwingConstants.LEFT);
108:
109: questionCombo = new JComboBox();
110: questionCombo.setSize(editSize);
111: questionCombo.setMinimumSize(editSize);
112: questionCombo.setPreferredSize(editSize);
113:
114: JButton buttonOk = new JButton("Ok");
115: buttonOk.setSize(buttonSize);
116: buttonOk.setPreferredSize(buttonSize);
117: buttonOk.setMinimumSize(buttonSize);
118: buttonOk.addActionListener(new ActionListener() {
119: public void actionPerformed(ActionEvent e) {
120: okPressed = true;
121: setVisible(false);
122: }
123: });
124:
125: JButton buttonCancel = new JButton("Cancel");
126: buttonCancel.setSize(buttonSize);
127: buttonCancel.setPreferredSize(buttonSize);
128: buttonCancel.setMinimumSize(buttonSize);
129: buttonCancel.addActionListener(new ActionListener() {
130: public void actionPerformed(ActionEvent e) {
131: okPressed = false;
132: setVisible(false);
133: }
134: });
135:
136: GridBagConstraints c = new GridBagConstraints();
137: c.insets = new Insets(1, 1, 1, 1);
138:
139: c.gridx = 0;
140: c.gridy = 0;
141: editPanel.add(questionLabel, c);
142: c.gridx = 0;
143: c.gridy = 1;
144: editPanel.add(questionCombo, c);
145:
146: bottomPanel.add(buttonOk);
147: bottomPanel.add(buttonCancel);
148: mainPanel.add(editPanel, BorderLayout.CENTER);
149: mainPanel.add(bottomPanel, BorderLayout.SOUTH);
150:
151: editPanel.setBorder(titledBorder);
152:
153: add(mainPanel);
154: pack();
155:
156: Dimension screenSize = Toolkit.getDefaultToolkit()
157: .getScreenSize();
158: Dimension dialogSize = getSize();
159: setLocation((screenSize.width - dialogSize.width) / 2,
160: (screenSize.height - dialogSize.height) / 2);
161:
162: }
163: }
|