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