File Source: ActionConditionsPanel.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionConditionsPanel__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.addons.ui_swing.dialogs.actioneditor;
24
25 import com.dmdirc.actions.ActionCondition;
26 import com.dmdirc.actions.ConditionTree;
27 import com.dmdirc.actions.ConditionTreeFactory.ConditionTreeFactoryType;
28 import com.dmdirc.actions.interfaces.ActionType;
29
30 import java.awt.event.ActionEvent;
31 import java.awt.event.ActionListener;
32 import java.beans.PropertyChangeEvent;
33 import java.beans.PropertyChangeListener;
34 import java.util.List;
35
36 import javax.swing.BorderFactory;
37 import javax.swing.JButton;
38 import javax.swing.JPanel;
39 import javax.swing.JScrollPane;
40 import javax.swing.JSeparator;
41
42 import net.miginfocom.swing.MigLayout;
43
44 /**
45 * Action conditions panel.
46 */
47 public class ActionConditionsPanel extends JPanel implements ActionListener,
48 PropertyChangeListener {
49
50 /**
51 * A version number for this class. It should be changed whenever the class
52 * structure is changed (or anything else that would prevent serialized
53 * objects being unserialized with the new class).
54 */
55 private static final long serialVersionUID = 1;
56 /** Action trigger. */
57 private ActionType trigger;
58 /** Tree panel. */
59 private ActionConditionsTreePanel tree;
60 /** List Panel. */
61 private ActionConditionsListPanel list;
62 /** Add button. */
63 private JButton add;
64 /** tree validates? */
65 private boolean treeValidates = true;
66 /** list validates? */
67 private boolean listValidates = true;
68
69 /** Instantiates the panel. */
70 public ActionConditionsPanel() {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionConditionsPanel()
*
* Presumptions:
* this.list != null
* this.tree != null
*
* Postconditions:
* init'ed(this.add)
* this.list != null
* this.listValidates == 1
* this.treeValidates == 1
* this.tree != null
* this.trigger == null
*/
71 this(null);
72 }
73
74 /**
75 * Instantiates the panel.
76 *
77 * @param trigger Action trigger
78 */
79 public ActionConditionsPanel(final ActionType trigger) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionConditionsPanel(ActionType)
*
* Presumptions:
* this.add != null
* this.add@89 != null
* this.list != null
* this.list.conditions != null
* this.tree != null
* ...
*
* Postconditions:
* init'ed(this.add)
* this.list != null
* this.listValidates == 1
* this.treeValidates == 1
* this.tree != null
* this.trigger == trigger
* init'ed(this.trigger)
*
* Test Vectors:
* trigger: Inverse{null}, Addr_Set{null}
*/
80 super();
81
82 this.trigger = trigger;
83
84 initComponents();
85 addListeners();
86 layoutComponents();
87
88 if (trigger == null) {
89 setEnabled(false);
90 add.setEnabled(false);
91 }
92 }
93
94 /** Validates the conditions. */
95 public void validateConditions() {
/*
P/P * Method: void validateConditions()
*
* Preconditions:
* init'ed(this.tree.treeFactory)
* this.tree != null
* this.tree.group != null
* this.tree.rule != null
* this.tree.rule.errorIcon != null
* this.tree.rule.textField != null
* (soft) init'ed(com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionConditionsTreePanel$1__static_init.new int[](ActionConditionsTreePanel$1__static_init#1)[...])
* (soft) init'ed(this.tree.validates)
* (soft) this.tree.allButton != null
* (soft) init'ed(this.tree.conditionCount)
* ...
*
* Presumptions:
* com.dmdirc.actions.ConditionTreeFactory$ConditionTreeFactoryType:values(...).length >= 1
*
* Postconditions:
* this.tree.treeFactory == One-of{&new ConditionTreeFactory$ConjunctionFactory(sortTreeFactory#1), &new ConditionTreeFactory$DisjunctionFactory(sortTreeFactory#2), &new ConditionTreeFactory$CustomFactory(sortTreeFactory#3)}
* this.tree.treeFactory in Addr_Set{&new ConditionTreeFactory$ConjunctionFactory(sortTreeFactory#1),&new ConditionTreeFactory$DisjunctionFactory(sortTreeFactory#2),&new ConditionTreeFactory$CustomFactory(sortTreeFactory#3)}
* init'ed(this.tree.validates)
* new ConditionTreeFactory$ConjunctionFactory(sortTreeFactory#1) num objects <= 1
* new ConditionTreeFactory$CustomFactory(sortTreeFactory#3) num objects <= 1
* new ConditionTreeFactory$DisjunctionFactory(sortTreeFactory#2) num objects <= 1
*/
96 tree.validateConditions();
97 }
98
99 /** Initialises the components. */
100 private void initComponents() {
/*
P/P * Method: void initComponents()
*
* Preconditions:
* (soft) init'ed(com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionConditionsTreePanel$1__static_init.new int[](ActionConditionsTreePanel$1__static_init#1)[...])
*
* Presumptions:
* com.dmdirc.actions.ConditionTreeFactory$ConditionTreeFactoryType:values(...).length >= 1
*
* Postconditions:
* this.add == &new JButton(initComponents#3)
* this.list == &new ActionConditionsListPanel(initComponents#2)
* this.tree == &new ActionConditionsTreePanel(initComponents#1)
* this.list.treePanel == &new ActionConditionsTreePanel(initComponents#1)
* new ActionConditionsListPanel(initComponents#2) num objects == 1
* this.list.validates == 1
* new ActionConditionsTreePanel(initComponents#1) num objects == 1
* this.tree.validates == 1
* new ArrayList(ActionConditionsListPanel#2) num objects == 1
* new ButtonGroup(initComponents#1) num objects == 1
* ...
*/
101 tree = new ActionConditionsTreePanel();
102 list = new ActionConditionsListPanel(tree);
103 add = new JButton("Add");
104 }
105
106 /** Adds the listeners. */
107 private void addListeners() {
/*
P/P * Method: void addListeners()
*
* Preconditions:
* this.add != null
* this.list != null
* this.tree != null
*/
108 add.addActionListener(this);
109 tree.addPropertyChangeListener("validationResult", this);
110 list.addPropertyChangeListener("validationResult", this);
111 }
112
113 /** Lays out the components. */
114 private void layoutComponents() {
/*
P/P * Method: void layoutComponents()
*
* Preconditions:
* init'ed(this.add)
* init'ed(this.list)
* init'ed(this.tree)
*
* Presumptions:
* javax.swing.JScrollPane:getVerticalScrollBar(...)@121 != null
*/
115 setLayout(new MigLayout("fill, wrap 1, pack"));
116
117 setBorder(BorderFactory.createTitledBorder(getBorder(), "Conditions"));
118
119 final JScrollPane sp = new JScrollPane(list);
120 sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
121 sp.getVerticalScrollBar().setUnitIncrement(10);
122
123 add(tree, "growx, pushx");
124 add(new JSeparator(JSeparator.HORIZONTAL), "growx, pushx");
125 add(sp, "grow, push");
126 add(add, "right, gaptop push");
127 }
128
129 /**
130 * Sets the trigger for this conditions panel.
131 *
132 * @param trigger Action trigger.
133 */
134 public void setActionTrigger(final ActionType trigger) {
/*
P/P * Method: void setActionTrigger(ActionType)
*
* Preconditions:
* init'ed(this.list.trigger)
* this.add != null
* this.list != null
* this.list.conditions != null
*
* Presumptions:
* com.dmdirc.actions.interfaces.ActionMetaType:getArgNames(...)@138 != null
* com.dmdirc.actions.interfaces.ActionType:getType(...)@138 != null
*
* Postconditions:
* this.list.trigger == trigger
* init'ed(this.list.trigger)
* this.trigger == this.list.trigger
*/
135 this.trigger = trigger;
136 list.setTrigger(trigger);
137 add.setEnabled(trigger != null);
138 add.setEnabled(trigger != null && trigger.getType().getArgNames().length != 0);
139 }
140
141 /** {@inheritDoc} */
142 @Override
143 public void setEnabled(final boolean enabled) {
/*
P/P * Method: void setEnabled(bool)
*
* Preconditions:
* this.list != null
* this.list.conditions != null
* this.tree != null
* this.tree.allButton != null
* this.tree.customButton != null
* this.tree.oneButton != null
*/
144 tree.setEnabled(enabled);
145 list.setEnabled(enabled);
146 }
147
148 /**
149 * {@inheritDoc}
150 *
151 * @param e Action event
152 */
153 @Override
154 public void actionPerformed(final ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Preconditions:
* this.list != null
*/
155 list.addCondition(new ActionCondition(-1, null, null, ""));
156 }
157
158 /**
159 * Sets the conditions.
160 *
161 * @param conditions conditions list
162 */
163 public void setConditions(final List<ActionCondition> conditions) {
/*
P/P * Method: void setConditions(List)
*
* Preconditions:
* conditions != null
* this.list != null
* this.list.conditions != null
* (soft) init'ed(this.list.validates)
* (soft) this.list.treePanel != null
* (soft) this.list.treePanel.rule != null
* (soft) this.list.treePanel.rule.errorIcon != null
* (soft) this.list.treePanel.rule.textField != null
* (soft) this.list.treePanel.rule.validator != null
* (soft) this.list.treePanel.treeValidator != null
* ...
*
* Postconditions:
* possibly_updated(this.list.treePanel.conditionCount)
* init'ed(this.list.validates)
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@166: {0}, {1}
*/
164 list.clearConditions();
165
166 for (ActionCondition condition : conditions) {
167 list.addCondition(condition);
168 }
169 }
170
171 /**
172 * Sets the condition tree.
173 *
174 * @param conditionTree new condition tree
175 */
176 public void setConditionTree(final ConditionTree conditionTree) {
/*
P/P * Method: void setConditionTree(ConditionTree)
*
* Preconditions:
* this.list != null
* this.list.conditions != null
* this.tree != null
* (soft) init'ed(com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionConditionsTreePanel$1__static_init.new int[](ActionConditionsTreePanel$1__static_init#1)[...])
* (soft) init'ed(this.tree.validates)
* (soft) this.tree.allButton != null
* (soft) this.tree.customButton != null
* (soft) this.tree.group != null
* (soft) this.tree.oneButton != null
* (soft) this.tree.rule != null
* ...
*
* Presumptions:
* com.dmdirc.actions.ConditionTreeFactory$ConditionTreeFactoryType:values(...).length >= 1
*
* Postconditions:
* possibly_updated(this.tree.conditionCount)
* this.tree.treeFactory == One-of{old this.tree.treeFactory, &new ConditionTreeFactory$ConjunctionFactory(sortTreeFactory#1), &new ConditionTreeFactory$DisjunctionFactory(sortTreeFactory#2), &new ConditionTreeFactory$CustomFactory(sortTreeFactory#3)}
* init'ed(this.tree.validates)
* new ConditionTreeFactory$ConjunctionFactory(sortTreeFactory#1) num objects <= 1
* new ConditionTreeFactory$CustomFactory(sortTreeFactory#3) num objects <= 1
* new ConditionTreeFactory$DisjunctionFactory(sortTreeFactory#2) num objects <= 1
*/
177 tree.setRule(list.getConditions().size(), conditionTree);
178 }
179
180 /**
181 * Gets the condition type.
182 *
183 * @return condition type
184 */
185 public ConditionTreeFactoryType getConditionTreeType() {
/*
P/P * Method: ConditionTreeFactory$ConditionTreeFactoryType getConditionTreeType()
*
* Preconditions:
* this.list != null
* this.list.conditions != null
* this.tree != null
* (soft) this.tree.treeFactory != null
*
* Postconditions:
* init'ed(return_value)
*/
186 return tree.getRuleType(list.getConditions().size());
187 }
188
189 /**
190 * Gets the condition tree.
191 *
192 * @return condition tree
193 */
194 public ConditionTree getConditionTree() {
/*
P/P * Method: ConditionTree getConditionTree()
*
* Preconditions:
* this.list != null
* this.list.conditions != null
* this.tree != null
* this.tree.treeFactory != null
*
* Postconditions:
* init'ed(return_value)
*/
195 return tree.getRule(list.getConditions().size());
196 }
197
198 /**
199 * Returns the condition list.
200 *
201 * @return condition list
202 */
203 public List<ActionCondition> getConditions() {
/*
P/P * Method: List getConditions()
*
* Preconditions:
* this.list != null
* this.list.conditions != null
*
* Postconditions:
* return_value == &new ArrayList(getConditions#1*)
* new ArrayList(getConditions#1*) num objects == 1
*/
204 return list.getConditions();
205 }
206
207 /** {@inheritDoc} */
208 @Override
209 public void propertyChange(final PropertyChangeEvent evt) {
/*
P/P * Method: void propertyChange(PropertyChangeEvent)
*
* Preconditions:
* evt != null
* init'ed(this.listValidates)
* init'ed(this.list)
* (soft) init'ed(this.treeValidates)
*
* Presumptions:
* java.beans.PropertyChangeEvent:getNewValue(...)@212 != null
* java.beans.PropertyChangeEvent:getNewValue(...)@214 != null
*
* Postconditions:
* init'ed(this.listValidates)
* init'ed(this.treeValidates)
*/
210 final boolean currentlyValidates = listValidates && treeValidates;
211 if (evt.getSource() == list) {
212 listValidates = (Boolean) evt.getNewValue();
213 } else {
214 treeValidates = (Boolean) evt.getNewValue();
215 }
216
217 firePropertyChange("validationResult", currentlyValidates,
218 listValidates && treeValidates);
219 }
220 }
SofCheck Inspector Build Version : 2.17854
| ActionConditionsPanel.java |
2009-Jun-25 01:54:24 |
| ActionConditionsPanel.class |
2009-Sep-02 17:04:15 |