File Source: ActionsGroupPanel.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsGroupPanel__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.actionsmanager;
24
25 import com.dmdirc.actions.Action;
26 import com.dmdirc.actions.ActionGroup;
27 import com.dmdirc.actions.ActionManager;
28 import com.dmdirc.addons.ui_swing.components.PackingTable;
29 import com.dmdirc.addons.ui_swing.components.renderers.ActionTypeTableCellRenderer;
30 import com.dmdirc.addons.ui_swing.components.renderers.ArrayCellRenderer;
31 import com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionEditorDialog;
32
33 import java.awt.Window;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.MouseAdapter;
37 import java.awt.event.MouseEvent;
38 import java.util.ArrayList;
39
40 import javax.swing.JButton;
41 import javax.swing.JOptionPane;
42 import javax.swing.JPanel;
43 import javax.swing.JScrollPane;
44 import javax.swing.ListSelectionModel;
45 import javax.swing.event.ListSelectionEvent;
46 import javax.swing.event.ListSelectionListener;
47 import javax.swing.table.TableCellRenderer;
48
49 import net.miginfocom.swing.MigLayout;
50
51 /**
52 * The actions group panel is the control displayed within the tabbed control
53 * of the actions manager dialog. It shows the user all actions belonging to
54 * a particular group.
55 */
/*
P/P * Method: JButton access$000(ActionsGroupPanel)
*
* Preconditions:
* x0 != null
* init'ed(x0.edit)
*
* Postconditions:
* return_value == x0.edit
* init'ed(return_value)
*/
56 public final class ActionsGroupPanel extends JPanel implements ActionListener,
57 ListSelectionListener {
58
59 /**
60 * A version number for this class. It should be changed whenever the class
61 * structure is changed (or anything else that would prevent serialized
62 * objects being unserialized with the new class).
63 */
64 private static final long serialVersionUID = 1;
65 /** Parent dialog. */
66 private Window parent;
67 /** Table scrollpane. */
68 private JScrollPane scrollPane;
69 /** Actions table. */
70 private PackingTable table;
71 /** Table mode. */
72 private ActionTableModel model;
73 /** Add button. */
74 private JButton add;
75 /** Edit button. */
76 private JButton edit;
77 /** Delete button. */
78 private JButton delete;
79 /** Action group. */
80 private ActionGroup group;
81
82 /**
83 * Creates a new instance of ActionsManagerDialog.
84 *
85 * @param group Action group to display
86 */
87 public ActionsGroupPanel(final Window parent, final ActionGroup group) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsGroupPanel(Window, ActionGroup)
*
* Postconditions:
* this.add == &new JButton(initComponents#6)
* this.delete == &new JButton(initComponents#8)
* this.edit == &new JButton(initComponents#7)
* this.group == group
* init'ed(this.group)
* this.model == &new ActionTableModel(initComponents#2)
* this.parent == parent
* init'ed(this.parent)
* this.scrollPane == &new JScrollPane(initComponents#1)
* this.table == &new ActionsGroupPanel$1(initComponents#4)
* ...
*/
88 super();
89
90 this.parent = parent;
91 this.group = group;
92
93 initComponents();
94 addListeners();
95 layoutComponents();
96 }
97
98 /**
99 * Updates or creates the new action.
100 *
101 * @param action Action changed or created
102 */
103 public void actionChanged(final Action action) {
/*
P/P * Method: void actionChanged(Action)
*
* Preconditions:
* this.model != null
* this.model.actions != null
*
* Test Vectors:
* java.util.List:contains(...)@226: {0}, {1}
*/
104 if (model.contains(action)) {
105 final int row = model.getAction(action);
106 model.fireTableCellUpdated(row, 0);
107 model.fireTableCellUpdated(row, 1);
108 model.fireTableCellUpdated(row, 2);
109 } else {
110 model.add(action);
111 }
112 }
113
114 /**
115 * Deletes an action from the group.
116 *
117 * @param name Name of the action
118 */
119 public void actionDeleted(final String name) {
/*
P/P * Method: void actionDeleted(String)
*
* Preconditions:
* this.model != null
* this.model.actions != null
*/
120 final int location = model.findAction(name);
121 if (location != -1) {
122 model.remove(location);
123 }
124 }
125
126 /**
127 * Initialises the components.
128 */
129 private void initComponents() {
/*
P/P * Method: void initComponents()
*
* Preconditions:
* init'ed(this.group)
*
* Presumptions:
* com.dmdirc.addons.ui_swing.components.PackingTable:getRowSorter(...)@183 != null
*
* Postconditions:
* this.add == &new JButton(initComponents#6)
* this.delete == &new JButton(initComponents#8)
* this.edit == &new JButton(initComponents#7)
* this.model == &new ActionTableModel(initComponents#2)
* this.scrollPane == &new JScrollPane(initComponents#1)
* this.table == &new ActionsGroupPanel$1(initComponents#4)
* new ActionTableModel(initComponents#2) num objects == 1
* new ActionTypeTableCellRenderer(ActionsGroupPanel$1#1) num objects == 1
* new ActionsGroupPanel$1(initComponents#4) num objects == 1
* new ArrayCellRenderer(ActionsGroupPanel$1#2) num objects == 1
* ...
*
* Test Vectors:
* this.group: Inverse{null}, Addr_Set{null}
*/
130 scrollPane = new JScrollPane();
131 model = new ActionTableModel(group == null ? new ArrayList<Action>() : group.getActions());
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsGroupPanel$1(ActionsGroupPanel, TableModel, bool, JScrollPane, bool)
*
* Postconditions:
* this.arrayRenderer == &new ArrayCellRenderer(ActionsGroupPanel$1#2)
* this.typeRenderer == &new ActionTypeTableCellRenderer(ActionsGroupPanel$1#1)
* new ActionTypeTableCellRenderer(ActionsGroupPanel$1#1) num objects == 1
* new ArrayCellRenderer(ActionsGroupPanel$1#2) num objects == 1
*/
132 table = new PackingTable(model, false, scrollPane, false) {
133
134 /**
135 * A version number for this class. It should be changed whenever the class
136 * structure is changed (or anything else that would prevent serialized
137 * objects being unserialized with the new class).
138 */
139 private static final long serialVersionUID = 1;
140 /** Action type renderer. */
141 private final ActionTypeTableCellRenderer typeRenderer =
142 new ActionTypeTableCellRenderer();
143 /** Action response renrderer. */
144 private final ArrayCellRenderer arrayRenderer =
145 new ArrayCellRenderer();
146
147 /** {@inheritDoc} */
148 @Override
149 public TableCellRenderer getCellRenderer(int row, int column) {
/*
P/P * Method: TableCellRenderer getCellRenderer(int, int)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* column: {1}, {2}, {-231..0, 3..232-1}
*/
150 switch (column) {
151 case 1:
152 return typeRenderer;
153 case 2:
154 return arrayRenderer;
155 default:
156 return super.getCellRenderer(row, column);
157 }
158 }
159 };
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsGroupPanel$2(ActionsGroupPanel)
*/
160 table.addMouseListener(new MouseAdapter() {
161
162 /** {@inheritDoc} */
163 @Override
164 public void mouseClicked(final MouseEvent e) {
/*
P/P * Method: void mouseClicked(MouseEvent)
*
* Preconditions:
* e != null
* (soft) this.edit != null
*
* Test Vectors:
* java.awt.event.MouseEvent:getClickCount(...)@165: {-231..1, 3..232-1}, {2}
*/
165 if (e.getClickCount() == 2) {
166 edit.doClick();
167 }
168 }
169 });
170 add = new JButton("Add");
171 edit = new JButton("Edit");
172 delete = new JButton("Delete");
173
174 scrollPane.setViewportView(table);
175
176 table.setAutoCreateRowSorter(true);
177 table.setAutoCreateColumnsFromModel(true);
178 table.setColumnSelectionAllowed(false);
179 table.setCellSelectionEnabled(false);
180 table.setFillsViewportHeight(false);
181 table.setRowSelectionAllowed(true);
182 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
183 table.getRowSorter().toggleSortOrder(0);
184
185 edit.setEnabled(false);
186 delete.setEnabled(false);
187 add.setEnabled(group != null);
188 }
189
190 /**
191 * Adds listeners.
192 */
193 private void addListeners() {
/*
P/P * Method: void addListeners()
*
* Preconditions:
* this.add != null
* this.delete != null
* this.edit != null
* this.table != null
*
* Presumptions:
* com.dmdirc.addons.ui_swing.components.PackingTable:getSelectionModel(...)@197 != null
*/
194 add.addActionListener(this);
195 edit.addActionListener(this);
196 delete.addActionListener(this);
197 table.getSelectionModel().addListSelectionListener(this);
198 }
199
200 /**
201 * Lays out the components.
202 */
203 private void layoutComponents() {
/*
P/P * Method: void layoutComponents()
*
* Preconditions:
* init'ed(this.add)
* init'ed(this.delete)
* init'ed(this.edit)
* init'ed(this.scrollPane)
*/
204 setLayout(new MigLayout("fill"));
205
206 add(scrollPane, "grow, push, span 3, wrap");
207 add(add, "right, sgx button");
208 add(edit, "right, sgx button");
209 add(delete, "right, sgx button");
210 }
211
212 /**
213 * Sets the action group for the panel.
214 *
215 * @param group New action group
216 */
217 public void setActionGroup(final ActionGroup group) {
/*
P/P * Method: void setActionGroup(ActionGroup)
*
* Preconditions:
* init'ed(this.model.actions)
* this.add != null
* this.model != null
*
* Postconditions:
* this.group == group
* init'ed(this.group)
* init'ed(this.model.actions)
* new ArrayList(setActionGroup#1*) num objects <= 1
*/
218 this.group = group;
219
220 model.setActionGroup(group);
221 add.setEnabled(group != null);
222 }
223
224 /**
225 * {@inheritDoc}
226 *
227 * @param e Action event
228 */
229 @Override
230 public void actionPerformed(final ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Preconditions:
* e != null
* init'ed(this.add)
* (soft) init'ed(com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.me)
* (soft) init'ed(this.delete)
* (soft) init'ed(this.edit)
* (soft) this.group != null
* (soft) this.model != null
* (soft) this.model.actions != null
* (soft) init'ed(this.parent)
* (soft) this.table != null
*
* Presumptions:
* com.dmdirc.addons.ui_swing.components.PackingTable:getRowSorter(...)@234 != null
* com.dmdirc.addons.ui_swing.components.PackingTable:getRowSorter(...)@238 != null
* java.util.List:get(...)@143 != null
*
* Postconditions:
* com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.me == One-of{old com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.me, &new ActionEditorDialog(getActionEditorDialog#1)}
* init'ed(com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.me)
* new ActionEditorDialog(getActionEditorDialog#1) num objects <= 1
* init'ed(new ActionEditorDialog(getActionEditorDialog#1).action)
* init'ed(new ActionEditorDialog(getActionEditorDialog#1).conditions)
* init'ed(new ActionEditorDialog(getActionEditorDialog#1).conditionsValid)
* init'ed(new ActionEditorDialog(getActionEditorDialog#1).group)
* init'ed(new ActionEditorDialog(getActionEditorDialog#1).name)
* init'ed(new ActionEditorDialog(getActionEditorDialog#1).nameValid)
* init'ed(new ActionEditorDialog(getActionEditorDialog#1).response)
* ...
*
* Test Vectors:
* javax.swing.JOptionPane:showConfirmDialog(...)@241: {-231..-1, 1..232-1}, {0}
*/
231 if (e.getSource() == add) {
232 ActionEditorDialog.showActionEditorDialog(parent, group.getName());
233 } else if (e.getSource() == edit) {
234 ActionEditorDialog.showActionEditorDialog(parent, group.getName(),
235 model.getAction(
236 table.getRowSorter().convertRowIndexToModel(table.getSelectedRow())));
237 } else if (e.getSource() == delete) {
238 final Action action =
239 model.getAction(
240 table.getRowSorter().convertRowIndexToModel(table.getSelectedRow()));
241 final int response = JOptionPane.showConfirmDialog(this,
242 "Are you sure you wish to delete the action '" +
243 action.getName() + "'?",
244 "Confirm deletion", JOptionPane.YES_NO_OPTION);
245 if (response == JOptionPane.YES_OPTION) {
246 ActionManager.deleteAction(action);
247 }
248 }
249 }
250
251 /** {@inheritDoc} */
252 @Override
253 public void valueChanged(final ListSelectionEvent e) {
/*
P/P * Method: void valueChanged(ListSelectionEvent)
*
* Preconditions:
* e != null
* (soft) this.delete != null
* (soft) this.edit != null
* (soft) this.table != null
*
* Test Vectors:
* com.dmdirc.addons.ui_swing.components.PackingTable:getSelectedRow(...)@258: {-231..-2, 0..232-1}, {-1}
* javax.swing.event.ListSelectionEvent:getValueIsAdjusting(...)@254: {0}, {1}
*/
254 if (e.getValueIsAdjusting()) {
255 return;
256 }
257
258 if (table.getSelectedRow() == -1) {
259 edit.setEnabled(false);
260 delete.setEnabled(false);
261 } else {
262 edit.setEnabled(true);
263 delete.setEnabled(true);
264 }
265 }
266 }
SofCheck Inspector Build Version : 2.17854
| ActionsGroupPanel.java |
2009-Jun-25 01:54:24 |
| ActionsGroupPanel.class |
2009-Sep-02 17:04:16 |
| ActionsGroupPanel$1.class |
2009-Sep-02 17:04:16 |
| ActionsGroupPanel$2.class |
2009-Sep-02 17:04:16 |