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