001: package com.xoetrope.carousel.survey;
002:
003: import com.xoetrope.survey.Condition;
004: import com.xoetrope.survey.Question;
005: import com.xoetrope.survey.QuestionGroup;
006: import com.xoetrope.survey.Survey;
007: import com.xoetrope.survey.SurveyManager;
008: import java.awt.BorderLayout;
009: import java.awt.CardLayout;
010: import java.awt.Container;
011: import java.awt.Dimension;
012: import java.util.Enumeration;
013: import java.util.Observable;
014: import java.util.Observer;
015: import java.util.Vector;
016: import javax.swing.BorderFactory;
017: import javax.swing.ImageIcon;
018: import javax.swing.JButton;
019: import javax.swing.JLabel;
020: import javax.swing.JPanel;
021: import javax.swing.JScrollPane;
022: import javax.swing.JSplitPane;
023: import javax.swing.JTable;
024: import javax.swing.JToolBar;
025: import javax.swing.border.EmptyBorder;
026: import javax.swing.border.TitledBorder;
027: import net.xoetrope.xui.XProject;
028: import net.xoetrope.xui.XProjectManager;
029:
030: /**
031: * A panel that contains conditions table and answers table.
032: *
033: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
034: * the GNU Public License (GPL), please see license.txt for more details. If
035: * you make commercial use of this software you must purchase a commercial
036: * license from Xoetrope.</p>
037: * <p> $Revision: 1.5 $</p>
038: */
039: public class XConditionsPanel extends JPanel {
040: protected JButton addConditionB, deleteConditionB;
041: protected XSurveyEditorFrame editorFrame;
042: protected XConditionsTableModel conditionsTableModel;
043: protected XAnswersTableModel answersTableModel;
044: protected XAnswersTableModelFree answersTableModelFree;
045: protected JPanel answersPanel;
046: protected CardLayout answersPanelLayout;
047:
048: public XConditionsPanel() {
049: super ();
050: XProject project = XProjectManager.getCurrentProject();
051: editorFrame = (XSurveyEditorFrame) project
052: .getObject("EditorFrame");
053: init();
054: }
055:
056: protected void init() {
057: setLayout(new BorderLayout());
058:
059: XTable conditionsTable = new XTable();
060: conditionsTable.setBorder(new EmptyBorder(0, 0, 0, 0));
061: conditionsTableModel = new XConditionsTableModel(
062: conditionsTable);
063: JScrollPane scrollPaneResponses = new JScrollPane(
064: conditionsTable);
065: TitledBorder responsesBorder = BorderFactory
066: .createTitledBorder("Conditions");
067: scrollPaneResponses.setBorder(responsesBorder);
068:
069: XTable answersTable = new XTable();
070: XTable answersTableFree = new XTable();
071: answersTable.setBorder(new EmptyBorder(0, 0, 0, 0));
072: answersTableModel = new XAnswersTableModel(answersTable);
073: answersTableModelFree = new XAnswersTableModelFree(
074: answersTableFree);
075: JScrollPane scrollPaneAnswers = new JScrollPane(answersTable);
076: JScrollPane scrollPaneAnswersFree = new JScrollPane(
077: answersTableFree);
078: TitledBorder answersBorder = BorderFactory
079: .createTitledBorder("Answers");
080: scrollPaneAnswers.setBorder(answersBorder);
081: scrollPaneAnswersFree.setBorder(answersBorder);
082:
083: answersPanel = new JPanel();
084: answersPanelLayout = new CardLayout();
085: answersPanel.setLayout(answersPanelLayout);
086: answersPanel.add(scrollPaneAnswers, "MultiExclusive");
087: answersPanel.add(scrollPaneAnswersFree, "FreeText");
088:
089: JToolBar toolBar = new JToolBar();
090: addConditionB = editorFrame.addButton("addCondition.png",
091: "add condition", toolBar);
092: deleteConditionB = editorFrame.addButton("deleteCondition.png",
093: "delete condition", toolBar);
094: addConditionB.setEnabled(false);
095: deleteConditionB.setEnabled(false);
096:
097: JSplitPane splitPane = new JSplitPane(
098: JSplitPane.HORIZONTAL_SPLIT, scrollPaneResponses,
099: answersPanel);
100: splitPane.setDividerLocation(700);
101:
102: add(toolBar, BorderLayout.NORTH);
103: add(splitPane, BorderLayout.CENTER);
104:
105: addConditionB.addActionListener(conditionsTableModel
106: .getAddResponse());
107: deleteConditionB.addActionListener(conditionsTableModel
108: .getDeleteResponse());
109:
110: conditionsTableModel.getNotifier().addObserver(new Observer() {
111: public void update(Observable o, Object arg) {
112: deleteConditionB.setEnabled(arg != null);
113: }
114: });
115: conditionsTableModel.getNotifier().addObserver(new Observer() {
116: public void update(Observable o, Object arg) {
117: Condition condition = (Condition) arg;
118: if (condition != null) {
119: Question question = condition.getQuestion();
120: if (question.getQuestionType() == Question.FREE_TEXT) {
121: answersTableModelFree.setCondition(condition);
122: answersPanelLayout.show(answersPanel,
123: "FreeText");
124: } else {
125: answersTableModel.setCondition(condition);
126: answersPanelLayout.show(answersPanel,
127: "MultiExclusive");
128: }
129: } else {
130: answersTableModel.setCondition(null);
131: answersTableModelFree.setCondition(null);
132: }
133: }
134: });
135: }
136:
137: public void showCondition(Condition condition) {
138: conditionsTableModel.selectCondition(condition);
139: }
140:
141: public XConditionsTableModel getResponsesTableModel() {
142: return conditionsTableModel;
143: }
144:
145: public JButton getAddConditionB() {
146: return addConditionB;
147: }
148:
149: public JButton getDeleteConditionB() {
150: return deleteConditionB;
151: }
152:
153: }
|