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 java.awt.BorderLayout;
007: import java.awt.CardLayout;
008: import java.awt.Dimension;
009: import java.util.Enumeration;
010: import java.util.Observable;
011: import java.util.Observer;
012: import javax.swing.JButton;
013: import javax.swing.JPanel;
014: import javax.swing.JScrollPane;
015: import javax.swing.JToolBar;
016: import javax.swing.JSplitPane;
017: import javax.swing.border.EmptyBorder;
018: import net.xoetrope.xui.XProject;
019: import net.xoetrope.xui.XProjectManager;
020: import net.xoetrope.xui.data.XModel;
021:
022: /**
023: * A panel containing graphic editor and four tables.
024: *
025: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
026: * the GNU Public License (GPL), please see license.txt for more details. If
027: * you make commercial use of this software you must purchase a commercial
028: * license from Xoetrope.</p>
029: * <p> $Revision: 1.5 $</p>
030: */
031: public class XRulesEditorPanel extends JPanel {
032: protected XRulesEditorPane rulesEditorPane;
033: protected JScrollPane rulesEditorScroll;
034: protected XRulesPanel rulesPanel;
035: protected XConditionsPanel conditionsPanel;
036: protected XGroupsPanel groupsPanel;
037: protected XQuestionsPanel questionsPanel;
038: protected XSurveyEditorFrame editorFrame;
039: protected Observer deleteGroupObserver, deleteRuleObserver;
040: protected Observer addRuleObserver;
041: protected JPanel bottomPanel, rightPanel;
042: protected CardLayout bottomLayout, rightLayout;
043: protected XGroupsTableModel groupsTableModel;
044: protected XQuestionsTableModel questionsTableModel;
045: protected XRulesTableModel rulesTableModel;
046: protected XConditionsTableModel conditionsTableModel;
047:
048: public XRulesEditorPanel() {
049: super ();
050:
051: XProject currentProject = XProjectManager.getCurrentProject();
052: editorFrame = (XSurveyEditorFrame) currentProject
053: .getObject("EditorFrame");
054: init();
055: createObservers();
056: }
057:
058: protected void init() {
059: setBorder(new EmptyBorder(5, 5, 5, 5));
060: setLayout(new BorderLayout());
061:
062: rulesPanel = new XRulesPanel();
063: rulesTableModel = rulesPanel.getRulesTableModel();
064: rulesTableModel.validate();
065: conditionsPanel = new XConditionsPanel();
066: rulesTableModel = rulesPanel.getRulesTableModel();
067: conditionsTableModel = conditionsPanel.getResponsesTableModel();
068: rulesTableModel.getNotifier().addObserver(conditionsTableModel);
069:
070: groupsPanel = new XGroupsPanel();
071: questionsPanel = new XQuestionsPanel();
072: questionsPanel.getComboBoxLabel().setVisible(false);
073: questionsPanel.getGroupComboBox().setVisible(false);
074: groupsTableModel = groupsPanel.getGroupsTableModel();
075: questionsTableModel = questionsPanel.getQuestionsTableModel();
076: groupsTableModel.getNotifier().addObserver(questionsTableModel);
077:
078: rulesEditorPane = new XRulesEditorPane(this );
079: rulesEditorScroll = new JScrollPane(rulesEditorPane);
080:
081: rightPanel = new JPanel();
082: rightLayout = new CardLayout();
083: rightPanel.setLayout(rightLayout);
084: rightPanel.add(groupsPanel, "Groups");
085: rightPanel.add(rulesPanel, "Rules");
086:
087: Dimension dim = new Dimension(100, 10);
088: rightPanel.setSize(dim);
089: rightPanel.setPreferredSize(dim);
090:
091: bottomPanel = new JPanel();
092: bottomLayout = new CardLayout();
093: bottomPanel.setLayout(bottomLayout);
094: bottomPanel.add(questionsPanel, "Questions");
095: bottomPanel.add(conditionsPanel, "Conditions");
096:
097: JSplitPane splitPane1 = new JSplitPane(
098: JSplitPane.HORIZONTAL_SPLIT, rulesEditorScroll,
099: rightPanel);
100: splitPane1.setDividerLocation(750);
101:
102: splitPane1.setDividerSize(5);
103:
104: JSplitPane splitPane2 = new JSplitPane(
105: JSplitPane.VERTICAL_SPLIT, splitPane1, bottomPanel);
106: splitPane2.setDividerLocation(500);
107: splitPane2.setDividerSize(5);
108: add(splitPane2, BorderLayout.CENTER);
109: rulesEditorPane.createView();
110: }
111:
112: public void refreshTables() {
113: groupsTableModel.getTable().revalidate();
114: groupsTableModel.getTable().repaint();
115: questionsTableModel.getTable().revalidate();
116: questionsTableModel.getTable().repaint();
117: rulesTableModel.getTable().revalidate();
118: rulesTableModel.getTable().repaint();
119: conditionsTableModel.getTable().revalidate();
120: conditionsTableModel.getTable().repaint();
121: }
122:
123: protected void createObservers() {
124: groupsTableModel.getNotifier().addObserver(new Observer() {
125: public void update(Observable o, Object arg) {
126: XQuestionGroup group = (XQuestionGroup) arg;
127: rulesEditorPane.selectGroup(group);
128: }
129: });
130: questionsTableModel.getNotifier().addObserver(new Observer() {
131: public void update(Observable o, Object arg) {
132: Question question = (Question) arg;
133: rulesEditorPane.selectQuestion(question);
134: }
135: });
136: rulesTableModel.getNotifier().addObserver(new Observer() {
137: public void update(Observable o, Object arg) {
138: XRule rule = (XRule) arg;
139: rulesEditorPane.selectRule(rule);
140: }
141: });
142: conditionsTableModel.getNotifier().addObserver(new Observer() {
143: public void update(Observable o, Object arg) {
144: XRule rule = rulesTableModel.getSelectedRule();
145: Condition condition = (Condition) arg;
146: rulesEditorPane.selectCondition(rule, condition);
147: }
148: });
149: }
150:
151: public void showQuestionView(XQuestionView questionView) {
152: questionsPanel.showQuestion(questionView.getQuestion());
153: bottomLayout.show(bottomPanel, "Questions");
154: }
155:
156: public void showGroupView(XGroupView groupView) {
157: groupsPanel.getGroupsTableModel().selectGroup(
158: groupView.getGroup());
159: rightLayout.show(rightPanel, "Groups");
160: bottomLayout.show(bottomPanel, "Questions");
161: }
162:
163: public void showConditionView(XConditionView conditionView) {
164: conditionsPanel.showCondition(conditionView.getCondition());
165: bottomLayout.show(bottomPanel, "Conditions");
166: }
167:
168: public void showRuleView(XRuleView ruleView) {
169: rulesPanel.showRule(ruleView.getRule());
170: rightLayout.show(rightPanel, "Rules");
171: bottomLayout.show(bottomPanel, "Conditions");
172: }
173:
174: public XRulesEditorPane getEditorPane() {
175: return rulesEditorPane;
176: }
177:
178: public Observer getDeleteGroupObserver() {
179: return deleteGroupObserver;
180: }
181:
182: public Observer getAddRuleObserver() {
183: return addRuleObserver;
184: }
185:
186: public Observer getDeleteRuleObserver() {
187: return deleteRuleObserver;
188: }
189:
190: public XRulesEditorPane getRulesEditorPane() {
191: return rulesEditorPane;
192: }
193:
194: public JScrollPane getRulesEditorScroll() {
195: return rulesEditorScroll;
196: }
197:
198: }
|