| 1 | package de.ugoe.cs.eventbench.swing;
|
|---|
| 2 |
|
|---|
| 3 | import java.awt.EventQueue;
|
|---|
| 4 | import java.awt.Rectangle;
|
|---|
| 5 |
|
|---|
| 6 | import javax.swing.DefaultListModel;
|
|---|
| 7 | import javax.swing.JFrame;
|
|---|
| 8 | import javax.swing.JButton;
|
|---|
| 9 | import javax.swing.JScrollBar;
|
|---|
| 10 |
|
|---|
| 11 | import java.awt.event.MouseAdapter;
|
|---|
| 12 | import java.awt.event.MouseEvent;
|
|---|
| 13 | import javax.swing.JList;
|
|---|
| 14 | import java.util.List;
|
|---|
| 15 | import javax.swing.ListSelectionModel;
|
|---|
| 16 | import javax.swing.border.SoftBevelBorder;
|
|---|
| 17 | import javax.swing.border.BevelBorder;
|
|---|
| 18 | import javax.swing.event.ListSelectionListener;
|
|---|
| 19 | import javax.swing.event.ListSelectionEvent;
|
|---|
| 20 |
|
|---|
| 21 | import de.ugoe.cs.eventbench.data.Event;
|
|---|
| 22 |
|
|---|
| 23 | import javax.swing.JLabel;
|
|---|
| 24 | import java.awt.event.WindowAdapter;
|
|---|
| 25 | import java.awt.event.WindowEvent;
|
|---|
| 26 | import javax.swing.JScrollPane;
|
|---|
| 27 | import javax.swing.JPanel;
|
|---|
| 28 | import javax.swing.border.EtchedBorder;
|
|---|
| 29 |
|
|---|
| 30 | /**
|
|---|
| 31 | * <p>
|
|---|
| 32 | * This class provides a dialog to have a look on the events of the sequence,
|
|---|
| 33 | * that was selected in {@link DlgSequences}. Furthermore, assertions can be
|
|---|
| 34 | * added.
|
|---|
| 35 | * </p>
|
|---|
| 36 | *
|
|---|
| 37 | * @author Jeffrey Hall
|
|---|
| 38 | * @version 1.0
|
|---|
| 39 | * @deprecated Use SWT-GUI for modifying sequences.
|
|---|
| 40 | */
|
|---|
| 41 | public class DlgSequenceDetails {
|
|---|
| 42 |
|
|---|
| 43 | private JFrame frmEvents;
|
|---|
| 44 | private JFrame frmParent;
|
|---|
| 45 |
|
|---|
| 46 | /**
|
|---|
| 47 | * <p>
|
|---|
| 48 | * Create the dialog.
|
|---|
| 49 | * </p>
|
|---|
| 50 | *
|
|---|
| 51 | * @param parent
|
|---|
| 52 | * the parent window of type {@link DlgSequences}.
|
|---|
| 53 | * @param events
|
|---|
| 54 | * list of events that is to be displayed.
|
|---|
| 55 | */
|
|---|
| 56 | public DlgSequenceDetails(JFrame parent, final List<Event<?>> events) {
|
|---|
| 57 | frmParent = parent;
|
|---|
| 58 | initialize(events);
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | /**
|
|---|
| 62 | * <p>
|
|---|
| 63 | * Launch the dialog.
|
|---|
| 64 | * </p>
|
|---|
| 65 | *
|
|---|
| 66 | * @param parent
|
|---|
| 67 | * the parent window of type {@link DlgSequences}.
|
|---|
| 68 | * @param events
|
|---|
| 69 | * list of events that is to be displayed.
|
|---|
| 70 | */
|
|---|
| 71 | public void showDialog(JFrame parent, final List<Event<?>> events) {
|
|---|
| 72 | frmParent = parent;
|
|---|
| 73 |
|
|---|
| 74 | EventQueue.invokeLater(new Runnable() {
|
|---|
| 75 | public void run() {
|
|---|
| 76 | try {
|
|---|
| 77 | DlgSequenceDetails window = new DlgSequenceDetails(
|
|---|
| 78 | frmParent, events);
|
|---|
| 79 | window.frmEvents.setVisible(true);
|
|---|
| 80 | } catch (Exception e) {
|
|---|
| 81 | e.printStackTrace();
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
| 84 | });
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | /**
|
|---|
| 88 | * <p>
|
|---|
| 89 | * Initialize the contents of the frame.
|
|---|
| 90 | * </p>
|
|---|
| 91 | *
|
|---|
| 92 | * @param events
|
|---|
| 93 | * list of events that is to be displayed.
|
|---|
| 94 | */
|
|---|
| 95 | private void initialize(final List<Event<?>> events) {
|
|---|
| 96 |
|
|---|
| 97 | final DefaultListModel modelListEvents = new DefaultListModel();
|
|---|
| 98 | final DefaultListModel modelListTargets = new DefaultListModel();
|
|---|
| 99 | final JList listEvents = new JList(modelListEvents);
|
|---|
| 100 | final JList listTargets = new JList(modelListTargets);
|
|---|
| 101 |
|
|---|
| 102 | frmEvents = new JFrame();
|
|---|
| 103 | frmEvents.setTitle("Sequence details");
|
|---|
| 104 | frmEvents.setBounds(100, 100, 738, 597);
|
|---|
| 105 | frmEvents.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
|---|
| 106 | frmEvents.getContentPane().setLayout(null);
|
|---|
| 107 |
|
|---|
| 108 | // before closing the window, set parent to visible
|
|---|
| 109 | frmEvents.addWindowListener(new WindowAdapter() {
|
|---|
| 110 | public void windowClosing(WindowEvent arg0) {
|
|---|
| 111 | frmParent.setVisible(true);
|
|---|
| 112 | frmEvents.dispose();
|
|---|
| 113 | }
|
|---|
| 114 | });
|
|---|
| 115 |
|
|---|
| 116 | JPanel panel = new JPanel();
|
|---|
| 117 | panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
|
|---|
| 118 | panel.setBounds(10, 498, 705, 52);
|
|---|
| 119 | frmEvents.getContentPane().add(panel);
|
|---|
| 120 | panel.setLayout(null);
|
|---|
| 121 |
|
|---|
| 122 | final JButton btnInsertBefore = new JButton("Insert before");
|
|---|
| 123 | btnInsertBefore.setEnabled(false);
|
|---|
| 124 | btnInsertBefore.setBounds(10, 11, 135, 31);
|
|---|
| 125 | panel.add(btnInsertBefore);
|
|---|
| 126 |
|
|---|
| 127 | final JButton btnInsertAfter = new JButton("Insert after");
|
|---|
| 128 | btnInsertAfter.setEnabled(false);
|
|---|
| 129 | btnInsertAfter.setBounds(155, 11, 135, 31);
|
|---|
| 130 | panel.add(btnInsertAfter);
|
|---|
| 131 |
|
|---|
| 132 | updateLists(events, modelListEvents, modelListTargets, listEvents,
|
|---|
| 133 | listTargets);
|
|---|
| 134 |
|
|---|
| 135 | // listener for clicking the "Insert before" button
|
|---|
| 136 | btnInsertBefore.addMouseListener(new MouseAdapter() {
|
|---|
| 137 | public void mouseClicked(MouseEvent arg0) {
|
|---|
| 138 | if (!btnInsertBefore.isEnabled())
|
|---|
| 139 | return;
|
|---|
| 140 |
|
|---|
| 141 | addAssertion(events, modelListEvents, modelListTargets,
|
|---|
| 142 | listEvents, listTargets, true);
|
|---|
| 143 | }
|
|---|
| 144 | });
|
|---|
| 145 |
|
|---|
| 146 | // listener for clicking the "Insert after" button
|
|---|
| 147 | btnInsertAfter.addMouseListener(new MouseAdapter() {
|
|---|
| 148 | public void mouseClicked(MouseEvent arg0) {
|
|---|
| 149 | if (!btnInsertAfter.isEnabled())
|
|---|
| 150 | return;
|
|---|
| 151 |
|
|---|
| 152 | addAssertion(events, modelListEvents, modelListTargets,
|
|---|
| 153 | listEvents, listTargets, false);
|
|---|
| 154 | }
|
|---|
| 155 | });
|
|---|
| 156 |
|
|---|
| 157 | final JButton btnClose = new JButton("Back to sequences");
|
|---|
| 158 | btnClose.setBounds(544, 11, 150, 31);
|
|---|
| 159 | panel.add(btnClose);
|
|---|
| 160 |
|
|---|
| 161 | JPanel panel_1 = new JPanel();
|
|---|
| 162 | panel_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
|
|---|
| 163 | panel_1.setBounds(10, 11, 705, 476);
|
|---|
| 164 | frmEvents.getContentPane().add(panel_1);
|
|---|
| 165 | panel_1.setLayout(null);
|
|---|
| 166 |
|
|---|
| 167 | final JScrollPane scrollPaneEvents = new JScrollPane();
|
|---|
| 168 | scrollPaneEvents.setBounds(10, 29, 209, 436);
|
|---|
| 169 | panel_1.add(scrollPaneEvents);
|
|---|
| 170 | scrollPaneEvents.setViewportView(listEvents);
|
|---|
| 171 |
|
|---|
| 172 | listEvents.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null,
|
|---|
| 173 | null, null, null));
|
|---|
| 174 | listEvents.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|---|
| 175 |
|
|---|
| 176 | final JScrollPane scrollPaneTargets = new JScrollPane();
|
|---|
| 177 | scrollPaneTargets.setBounds(229, 29, 466, 436);
|
|---|
| 178 | panel_1.add(scrollPaneTargets);
|
|---|
| 179 |
|
|---|
| 180 | // if there are more events than the list is able to display without
|
|---|
| 181 | // vertical scrollbar, the event list has to be resized to fit to the
|
|---|
| 182 | // target list
|
|---|
| 183 | Rectangle r = scrollPaneEvents.getBounds();
|
|---|
| 184 | r.height -= 18;
|
|---|
| 185 | if (scrollPaneEvents.getVerticalScrollBar().isVisible()) {
|
|---|
| 186 | scrollPaneEvents.setBounds(r);
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | // listener for selecting a target: select the fitting event
|
|---|
| 190 | listTargets.addListSelectionListener(new ListSelectionListener() {
|
|---|
| 191 | public void valueChanged(ListSelectionEvent arg0) {
|
|---|
| 192 | if (listTargets.getSelectedIndex() > -1) {
|
|---|
| 193 |
|
|---|
| 194 | changeSelection(listEvents, listTargets, btnInsertBefore,
|
|---|
| 195 | btnInsertAfter, scrollPaneEvents, scrollPaneTargets);
|
|---|
| 196 | }
|
|---|
| 197 | }
|
|---|
| 198 | });
|
|---|
| 199 | scrollPaneTargets.setViewportView(listTargets);
|
|---|
| 200 |
|
|---|
| 201 | listTargets.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null,
|
|---|
| 202 | null, null, null));
|
|---|
| 203 | listTargets.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|---|
| 204 |
|
|---|
| 205 | JLabel lblEvents = new JLabel("Events:");
|
|---|
| 206 | lblEvents.setBounds(10, 11, 46, 14);
|
|---|
| 207 | panel_1.add(lblEvents);
|
|---|
| 208 |
|
|---|
| 209 | JLabel lblTargets = new JLabel("Targets:");
|
|---|
| 210 | lblTargets.setBounds(229, 11, 58, 14);
|
|---|
| 211 | panel_1.add(lblTargets);
|
|---|
| 212 |
|
|---|
| 213 | // listener for selecting an event: select the fitting target
|
|---|
| 214 | listEvents.addListSelectionListener(new ListSelectionListener() {
|
|---|
| 215 | public void valueChanged(ListSelectionEvent arg0) {
|
|---|
| 216 | if (listEvents.getSelectedIndex() > -1) {
|
|---|
| 217 |
|
|---|
| 218 | changeSelection(listTargets, listEvents, btnInsertBefore,
|
|---|
| 219 | btnInsertAfter, scrollPaneTargets, scrollPaneEvents);
|
|---|
| 220 | }
|
|---|
| 221 | }
|
|---|
| 222 | });
|
|---|
| 223 |
|
|---|
| 224 | // before closing the window, set parent to visible
|
|---|
| 225 | btnClose.addMouseListener(new MouseAdapter() {
|
|---|
| 226 | public void mouseClicked(MouseEvent arg0) {
|
|---|
| 227 | frmParent.setVisible(true);
|
|---|
| 228 | frmEvents.dispose();
|
|---|
| 229 | }
|
|---|
| 230 | });
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | /**
|
|---|
| 234 | * <p>
|
|---|
| 235 | * the value of one of the lists changed so the other has to be set to the
|
|---|
| 236 | * fitting selection.
|
|---|
| 237 | * </p>
|
|---|
| 238 | *
|
|---|
| 239 | * @param listValueHasToBeChanged
|
|---|
| 240 | * the selection of this list has to be corrected.
|
|---|
| 241 | * @param listValueHasBeenChanged
|
|---|
| 242 | * the selection of this list is already correct.
|
|---|
| 243 | * @param btnInsertBefore
|
|---|
| 244 | * to enable the "Insert before" button.
|
|---|
| 245 | * @param btnInsertAfter
|
|---|
| 246 | * to enable the "Insert after" button.
|
|---|
| 247 | * @param scrollPaneValueHasToBeChanged
|
|---|
| 248 | * the position of the scrollBar of this scrollPane has to be
|
|---|
| 249 | * corrected.
|
|---|
| 250 | * @param scrollPaneValueHasBeenChanged
|
|---|
| 251 | * the position of the scrollBar of this scrollPane is already
|
|---|
| 252 | * correct.
|
|---|
| 253 | */
|
|---|
| 254 | private void changeSelection(final JList listValueHasToBeChanged,
|
|---|
| 255 | final JList listValueHasBeenChanged, final JButton btnInsertBefore,
|
|---|
| 256 | final JButton btnInsertAfter,
|
|---|
| 257 | final JScrollPane scrollPaneValueHasToBeChanged,
|
|---|
| 258 | final JScrollPane scrollPaneValueHasBeenChanged) {
|
|---|
| 259 |
|
|---|
| 260 | JScrollBar bar1 = scrollPaneValueHasBeenChanged.getVerticalScrollBar();
|
|---|
| 261 | JScrollBar bar2 = scrollPaneValueHasToBeChanged.getVerticalScrollBar();
|
|---|
| 262 | bar2.setValue(bar1.getValue());
|
|---|
| 263 |
|
|---|
| 264 | listValueHasToBeChanged.setSelectedIndex(listValueHasBeenChanged
|
|---|
| 265 | .getSelectedIndex());
|
|---|
| 266 |
|
|---|
| 267 | btnInsertBefore.setEnabled(true);
|
|---|
| 268 | btnInsertAfter.setEnabled(true);
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | /**
|
|---|
| 272 | * <p>
|
|---|
| 273 | * updates both lists, eventList and targetList to display the current
|
|---|
| 274 | * status.
|
|---|
| 275 | * </p>
|
|---|
| 276 | *
|
|---|
| 277 | * @param events
|
|---|
| 278 | * list of the current events that has to be displayed.
|
|---|
| 279 | * @param modelListEvents
|
|---|
| 280 | * DefaultListModel to display the events.
|
|---|
| 281 | * @param modelListTargets
|
|---|
| 282 | * DefaultListModel to display the targets.
|
|---|
| 283 | * @param listEvents
|
|---|
| 284 | * the listEvents to store and reset the selection.
|
|---|
| 285 | * @param listTargets
|
|---|
| 286 | * the listTargets to reset the selection after updating.
|
|---|
| 287 | */
|
|---|
| 288 | private void updateLists(final List<Event<?>> events,
|
|---|
| 289 | final javax.swing.DefaultListModel modelListEvents,
|
|---|
| 290 | final javax.swing.DefaultListModel modelListTargets,
|
|---|
| 291 | JList listEvents, JList listTargets) {
|
|---|
| 292 |
|
|---|
| 293 | int selectedIndex = listEvents.getSelectedIndex();
|
|---|
| 294 |
|
|---|
| 295 | modelListEvents.clear();
|
|---|
| 296 | modelListTargets.clear();
|
|---|
| 297 | for (int i = 0; i < events.size(); i++) {
|
|---|
| 298 | modelListEvents.addElement(events.get(i).getType());
|
|---|
| 299 | modelListTargets.addElement(events.get(i).getTarget());
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | if (selectedIndex > -1) {
|
|---|
| 303 | listEvents.setSelectedIndex(selectedIndex);
|
|---|
| 304 | listTargets.setSelectedIndex(selectedIndex);
|
|---|
| 305 | }
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | /**
|
|---|
| 309 | * <p>
|
|---|
| 310 | * opens {@link DlgInsert} dialog to insert an assertion and updates the
|
|---|
| 311 | * lists.
|
|---|
| 312 | * </p>
|
|---|
| 313 | *
|
|---|
| 314 | * @param events
|
|---|
| 315 | * list of the current events.
|
|---|
| 316 | * @param modelListEvents
|
|---|
| 317 | * needed to call updateList.
|
|---|
| 318 | * @param modelListTargets
|
|---|
| 319 | * needed to call updateList.
|
|---|
| 320 | * @param listEvents
|
|---|
| 321 | * needed to get the currently selected index and to update the
|
|---|
| 322 | * lists.
|
|---|
| 323 | * @param listTargets
|
|---|
| 324 | * needed to update the lists.
|
|---|
| 325 | * @param insertBefore
|
|---|
| 326 | * to decide if the assertions has to be inserted before or after
|
|---|
| 327 | * the current selection.
|
|---|
| 328 | */
|
|---|
| 329 | private void addAssertion(final List<Event<?>> events,
|
|---|
| 330 | final DefaultListModel modelListEvents,
|
|---|
| 331 | final DefaultListModel modelListTargets, final JList listEvents,
|
|---|
| 332 | final JList listTargets, boolean insertBefore) {
|
|---|
| 333 |
|
|---|
| 334 | int selectedIndex = listEvents.getSelectedIndex();
|
|---|
| 335 | DlgInsert.showDialog(events, selectedIndex, insertBefore);
|
|---|
| 336 | updateLists(events, modelListEvents, modelListTargets, listEvents,
|
|---|
| 337 | listTargets);
|
|---|
| 338 | }
|
|---|
| 339 | }
|
|---|