1 | package de.ugoe.cs.eventbench.swing;
|
---|
2 | import java.awt.EventQueue;
|
---|
3 |
|
---|
4 | import javax.swing.JFrame;
|
---|
5 | import javax.swing.JButton;
|
---|
6 | import java.awt.event.MouseAdapter;
|
---|
7 | import java.awt.event.MouseEvent;
|
---|
8 | import javax.swing.JList;
|
---|
9 | import java.awt.event.ActionListener;
|
---|
10 | import java.awt.event.ActionEvent;
|
---|
11 | import java.util.Vector;
|
---|
12 | import java.util.List;
|
---|
13 |
|
---|
14 | import javax.swing.AbstractListModel;
|
---|
15 | import javax.swing.ListSelectionModel;
|
---|
16 | import javax.swing.border.CompoundBorder;
|
---|
17 | import javax.swing.border.LineBorder;
|
---|
18 | import java.awt.Color;
|
---|
19 | import javax.swing.border.SoftBevelBorder;
|
---|
20 | import javax.swing.border.BevelBorder;
|
---|
21 | import javax.swing.border.TitledBorder;
|
---|
22 | import javax.swing.UIManager;
|
---|
23 | import javax.swing.event.ListSelectionListener;
|
---|
24 | import javax.swing.event.ListSelectionEvent;
|
---|
25 |
|
---|
26 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
27 | import de.ugoe.cs.eventbench.data.IReplayable;
|
---|
28 | import de.ugoe.cs.util.console.Console;
|
---|
29 | import de.ugoe.cs.eventbench.data.Event;
|
---|
30 | import de.ugoe.cs.eventbench.windows.WindowsEvent;
|
---|
31 |
|
---|
32 | import javax.swing.JLabel;
|
---|
33 | import java.awt.event.WindowAdapter;
|
---|
34 | import java.awt.event.WindowEvent;
|
---|
35 | import javax.swing.JScrollBar;
|
---|
36 | import javax.swing.JScrollPane;
|
---|
37 | import javax.swing.JPanel;
|
---|
38 | import javax.swing.border.EtchedBorder;
|
---|
39 |
|
---|
40 |
|
---|
41 | public class DlgSequenceDetails {
|
---|
42 |
|
---|
43 | private JFrame frmEvents;
|
---|
44 | private JFrame frmParent;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Launch the application, the index of the sequence to work on is stored in sequenceIndex
|
---|
48 | */
|
---|
49 | public void ShowDialog(JFrame parent, final List<Event<?>> events) {
|
---|
50 | frmParent = parent;
|
---|
51 |
|
---|
52 | EventQueue.invokeLater(new Runnable() {
|
---|
53 | public void run() {
|
---|
54 | try {
|
---|
55 | DlgSequenceDetails window = new DlgSequenceDetails(frmParent, events);
|
---|
56 | window.frmEvents.setVisible(true);
|
---|
57 | } catch (Exception e) {
|
---|
58 | e.printStackTrace();
|
---|
59 | }
|
---|
60 | }
|
---|
61 | });
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Create the application.
|
---|
66 | */
|
---|
67 | public DlgSequenceDetails(JFrame parent, final List<Event<?>> events) {
|
---|
68 | frmParent = parent;
|
---|
69 | initialize(events);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Initialize the contents of the frame.
|
---|
74 | */
|
---|
75 | private void initialize(final List<Event<?>> events) {
|
---|
76 |
|
---|
77 |
|
---|
78 | final javax.swing.DefaultListModel modelListEvents = new javax.swing.DefaultListModel();
|
---|
79 | final javax.swing.DefaultListModel modelListTargets = new javax.swing.DefaultListModel();
|
---|
80 | final JList listSequences = new JList(modelListEvents);
|
---|
81 | final JList listTargets = new JList(modelListTargets);
|
---|
82 | // ***
|
---|
83 |
|
---|
84 |
|
---|
85 | // JFrame: frmEvents
|
---|
86 | frmEvents = new JFrame();
|
---|
87 | frmEvents.setResizable(false);
|
---|
88 | frmEvents.setTitle("Sequence details");
|
---|
89 | frmEvents.setBounds(100, 100, 666, 492);
|
---|
90 | frmEvents.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
---|
91 | frmEvents.getContentPane().setLayout(null);
|
---|
92 |
|
---|
93 | frmEvents.addWindowListener(new WindowAdapter() {
|
---|
94 | public void windowClosing(WindowEvent arg0) {
|
---|
95 | frmParent.setVisible(true);
|
---|
96 | frmEvents.dispose();
|
---|
97 | }
|
---|
98 | });
|
---|
99 |
|
---|
100 | updateLists(events, modelListEvents, modelListTargets);
|
---|
101 |
|
---|
102 | JPanel panel = new JPanel();
|
---|
103 | panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
|
---|
104 | panel.setBounds(10, 402, 639, 52);
|
---|
105 | frmEvents.getContentPane().add(panel);
|
---|
106 | panel.setLayout(null);
|
---|
107 | final JButton btnInsertBefore = new JButton("Insert before");
|
---|
108 | btnInsertBefore.setBounds(10, 11, 124, 31);
|
---|
109 | panel.add(btnInsertBefore);
|
---|
110 | // ***
|
---|
111 |
|
---|
112 |
|
---|
113 | // JButton: btnInsertBefore ***
|
---|
114 | btnInsertBefore.addMouseListener(new MouseAdapter() {
|
---|
115 | public void mouseClicked(MouseEvent arg0) {
|
---|
116 | if(!btnInsertBefore.isEnabled()) return;
|
---|
117 |
|
---|
118 | int selectedIndex = listSequences.getSelectedIndex();
|
---|
119 | DlgInsert dlgInsert = new DlgInsert(events, selectedIndex, true);
|
---|
120 | dlgInsert.ShowDialog(events, selectedIndex, true);
|
---|
121 |
|
---|
122 | updateLists(events, modelListEvents, modelListTargets);
|
---|
123 | listSequences.setSelectedIndex(selectedIndex);
|
---|
124 | }
|
---|
125 | });
|
---|
126 |
|
---|
127 | btnInsertBefore.setEnabled(false);
|
---|
128 | final JButton btnInsertAfter = new JButton("Insert after");
|
---|
129 | btnInsertAfter.setBounds(144, 11, 124, 31);
|
---|
130 | panel.add(btnInsertAfter);
|
---|
131 | // ***
|
---|
132 |
|
---|
133 |
|
---|
134 | // JButton: btnInsertAfter
|
---|
135 | btnInsertAfter.addMouseListener(new MouseAdapter() {
|
---|
136 | public void mouseClicked(MouseEvent arg0) {
|
---|
137 | if(!btnInsertAfter.isEnabled()) return;
|
---|
138 |
|
---|
139 | int selectedIndex = listSequences.getSelectedIndex();
|
---|
140 | DlgInsert dlgInsert = new DlgInsert(events, selectedIndex, false);
|
---|
141 | dlgInsert.ShowDialog(events, selectedIndex, false);
|
---|
142 |
|
---|
143 | updateLists(events, modelListEvents, modelListTargets);
|
---|
144 | listSequences.setSelectedIndex(selectedIndex+1);
|
---|
145 | }
|
---|
146 | });
|
---|
147 |
|
---|
148 | btnInsertAfter.setEnabled(false);
|
---|
149 |
|
---|
150 | final JButton btnClose = new JButton("Back to sequences");
|
---|
151 | btnClose.setBounds(505, 11, 124, 31);
|
---|
152 | panel.add(btnClose);
|
---|
153 |
|
---|
154 | JPanel panel_1 = new JPanel();
|
---|
155 | panel_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
|
---|
156 | panel_1.setBounds(10, 11, 639, 380);
|
---|
157 | frmEvents.getContentPane().add(panel_1);
|
---|
158 | panel_1.setLayout(null);
|
---|
159 |
|
---|
160 | JScrollPane scrollPane_1 = new JScrollPane();
|
---|
161 | scrollPane_1.setBounds(10, 29, 309, 339);
|
---|
162 | panel_1.add(scrollPane_1);
|
---|
163 | scrollPane_1.setViewportView(listSequences);
|
---|
164 | // ***
|
---|
165 |
|
---|
166 |
|
---|
167 | // JList: listSequences ***
|
---|
168 | listSequences.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
|
---|
169 | listSequences.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
170 |
|
---|
171 |
|
---|
172 | // JScrollPane: scrollPane
|
---|
173 | JScrollPane scrollPane = new JScrollPane();
|
---|
174 | scrollPane.setBounds(329, 29, 298, 339);
|
---|
175 | panel_1.add(scrollPane);
|
---|
176 |
|
---|
177 | listTargets.addListSelectionListener(new ListSelectionListener() {
|
---|
178 | public void valueChanged(ListSelectionEvent arg0) {
|
---|
179 | if(listTargets.getSelectedIndex() > -1) {
|
---|
180 | listSequences.setSelectedIndex(listTargets.getSelectedIndex());
|
---|
181 | btnInsertAfter.setEnabled(true);
|
---|
182 |
|
---|
183 | if(listTargets.getSelectedIndex() == 0) {
|
---|
184 | btnInsertBefore.setEnabled(false);
|
---|
185 | }
|
---|
186 | else {
|
---|
187 | btnInsertBefore.setEnabled(true);
|
---|
188 | }
|
---|
189 | }
|
---|
190 | }
|
---|
191 | });
|
---|
192 | scrollPane.setViewportView(listTargets);
|
---|
193 | // ***
|
---|
194 |
|
---|
195 |
|
---|
196 | // JList for targets ***
|
---|
197 | listTargets.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
|
---|
198 | listTargets.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
199 |
|
---|
200 | JLabel lblEvents = new JLabel("Events:");
|
---|
201 | lblEvents.setBounds(10, 11, 46, 14);
|
---|
202 | panel_1.add(lblEvents);
|
---|
203 |
|
---|
204 | JLabel lblTargets = new JLabel("Targets:");
|
---|
205 | lblTargets.setBounds(329, 11, 58, 14);
|
---|
206 | panel_1.add(lblTargets);
|
---|
207 |
|
---|
208 | listSequences.addListSelectionListener(new ListSelectionListener() {
|
---|
209 | public void valueChanged(ListSelectionEvent arg0) {
|
---|
210 | if(listSequences.getSelectedIndex() > -1) {
|
---|
211 | listTargets.setSelectedIndex(listSequences.getSelectedIndex());
|
---|
212 |
|
---|
213 | if(listSequences.getSelectedIndex() == 0) {
|
---|
214 | btnInsertBefore.setEnabled(false);
|
---|
215 | btnInsertAfter.setEnabled(true);
|
---|
216 | }
|
---|
217 | else {
|
---|
218 | btnInsertBefore.setEnabled(true);
|
---|
219 | btnInsertAfter.setEnabled(true);
|
---|
220 | }
|
---|
221 | }
|
---|
222 | }
|
---|
223 | });
|
---|
224 | // ***
|
---|
225 |
|
---|
226 |
|
---|
227 | // JButton: btnClose ***
|
---|
228 | btnClose.addMouseListener(new MouseAdapter() {
|
---|
229 | public void mouseClicked(MouseEvent arg0) {
|
---|
230 | frmParent.setVisible(true);
|
---|
231 | frmEvents.dispose();
|
---|
232 | }
|
---|
233 | });
|
---|
234 | // ***
|
---|
235 | }
|
---|
236 |
|
---|
237 | private void updateLists(final List<Event<?>> events,
|
---|
238 | final javax.swing.DefaultListModel modelListEvents,
|
---|
239 | final javax.swing.DefaultListModel modelListTargets) {
|
---|
240 |
|
---|
241 | modelListEvents.clear();
|
---|
242 | modelListTargets.clear();
|
---|
243 | for(int i=0; i<events.size(); i++) {
|
---|
244 | modelListEvents.addElement(events.get(i).getType());
|
---|
245 | modelListTargets.addElement(events.get(i).getTarget());
|
---|
246 | }
|
---|
247 | }
|
---|
248 | }
|
---|