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 | public class DlgSequenceDetails {
|
---|
31 |
|
---|
32 | private JFrame frmEvents;
|
---|
33 | private JFrame frmParent;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Launch the application, the index of the sequence to work on is stored in
|
---|
37 | * sequenceIndex
|
---|
38 | */
|
---|
39 | public void showDialog(JFrame parent, final List<Event<?>> events) {
|
---|
40 | frmParent = parent;
|
---|
41 |
|
---|
42 | EventQueue.invokeLater(new Runnable() {
|
---|
43 | public void run() {
|
---|
44 | try {
|
---|
45 | DlgSequenceDetails window = new DlgSequenceDetails(
|
---|
46 | frmParent, events);
|
---|
47 | window.frmEvents.setVisible(true);
|
---|
48 | } catch (Exception e) {
|
---|
49 | e.printStackTrace();
|
---|
50 | }
|
---|
51 | }
|
---|
52 | });
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Create the application.
|
---|
57 | */
|
---|
58 | public DlgSequenceDetails(JFrame parent, final List<Event<?>> events) {
|
---|
59 | frmParent = parent;
|
---|
60 | initialize(events);
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Initialize the contents of the frame.
|
---|
65 | */
|
---|
66 | private void initialize(final List<Event<?>> events) {
|
---|
67 |
|
---|
68 | final DefaultListModel modelListEvents = new DefaultListModel();
|
---|
69 | final DefaultListModel modelListTargets = new DefaultListModel();
|
---|
70 | final JList listEvents = new JList(modelListEvents);
|
---|
71 | final JList listTargets = new JList(modelListTargets);
|
---|
72 | // ***
|
---|
73 |
|
---|
74 | // JFrame: frmEvents
|
---|
75 | frmEvents = new JFrame();
|
---|
76 | frmEvents.setResizable(false);
|
---|
77 | frmEvents.setTitle("Sequence details");
|
---|
78 | frmEvents.setBounds(100, 100, 731, 589);
|
---|
79 | frmEvents.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
---|
80 | frmEvents.getContentPane().setLayout(null);
|
---|
81 |
|
---|
82 | frmEvents.addWindowListener(new WindowAdapter() {
|
---|
83 | public void windowClosing(WindowEvent arg0) {
|
---|
84 | frmParent.setVisible(true);
|
---|
85 | frmEvents.dispose();
|
---|
86 | }
|
---|
87 | });
|
---|
88 |
|
---|
89 | updateLists(events, modelListEvents, modelListTargets);
|
---|
90 |
|
---|
91 | JPanel panel = new JPanel();
|
---|
92 | panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
|
---|
93 | panel.setBounds(10, 498, 705, 52);
|
---|
94 | frmEvents.getContentPane().add(panel);
|
---|
95 | panel.setLayout(null);
|
---|
96 | final JButton btnInsertBefore = new JButton("Insert before");
|
---|
97 | btnInsertBefore.setBounds(10, 11, 135, 31);
|
---|
98 | panel.add(btnInsertBefore);
|
---|
99 | // ***
|
---|
100 |
|
---|
101 | // JButton: btnInsertBefore ***
|
---|
102 | btnInsertBefore.addMouseListener(new MouseAdapter() {
|
---|
103 | public void mouseClicked(MouseEvent arg0) {
|
---|
104 | if (!btnInsertBefore.isEnabled())
|
---|
105 | return;
|
---|
106 |
|
---|
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
|
---|
122 | btnInsertAfter.addMouseListener(new MouseAdapter() {
|
---|
123 | public void mouseClicked(MouseEvent arg0) {
|
---|
124 | if (!btnInsertAfter.isEnabled())
|
---|
125 | return;
|
---|
126 |
|
---|
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);
|
---|
136 |
|
---|
137 | final JButton btnClose = new JButton("Back to sequences");
|
---|
138 | btnClose.setBounds(544, 11, 150, 31);
|
---|
139 | panel.add(btnClose);
|
---|
140 |
|
---|
141 | JPanel panel_1 = new JPanel();
|
---|
142 | panel_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
|
---|
143 | panel_1.setBounds(10, 11, 705, 476);
|
---|
144 | frmEvents.getContentPane().add(panel_1);
|
---|
145 | panel_1.setLayout(null);
|
---|
146 |
|
---|
147 | final JScrollPane scrollPaneEvents = new JScrollPane();
|
---|
148 | scrollPaneEvents.setBounds(10, 29, 209, 436);
|
---|
149 | panel_1.add(scrollPaneEvents);
|
---|
150 | scrollPaneEvents.setViewportView(listEvents);
|
---|
151 | // ***
|
---|
152 |
|
---|
153 | // JList: listEvents ***
|
---|
154 | listEvents.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null,
|
---|
155 | null, null, null));
|
---|
156 | listEvents.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
157 |
|
---|
158 | // JScrollPane: scrollPane
|
---|
159 | final JScrollPane scrollPaneTargets = new JScrollPane();
|
---|
160 | scrollPaneTargets.setBounds(229, 29, 466, 436);
|
---|
161 | panel_1.add(scrollPaneTargets);
|
---|
162 |
|
---|
163 | Rectangle r = scrollPaneEvents.getBounds();
|
---|
164 | r.height -= 18;
|
---|
165 | if(scrollPaneEvents.getVerticalScrollBar().isVisible()) scrollPaneEvents.setBounds(r);
|
---|
166 |
|
---|
167 | listTargets.addListSelectionListener(new ListSelectionListener() {
|
---|
168 | public void valueChanged(ListSelectionEvent arg0) {
|
---|
169 | 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 | }
|
---|
184 | }
|
---|
185 | }
|
---|
186 | });
|
---|
187 | scrollPaneTargets.setViewportView(listTargets);
|
---|
188 | // ***
|
---|
189 |
|
---|
190 | // JList for targets ***
|
---|
191 | listTargets.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null,
|
---|
192 | null, null, null));
|
---|
193 | listTargets.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
194 |
|
---|
195 | JLabel lblEvents = new JLabel("Events:");
|
---|
196 | lblEvents.setBounds(10, 11, 46, 14);
|
---|
197 | panel_1.add(lblEvents);
|
---|
198 |
|
---|
199 | JLabel lblTargets = new JLabel("Targets:");
|
---|
200 | lblTargets.setBounds(229, 11, 58, 14);
|
---|
201 | panel_1.add(lblTargets);
|
---|
202 |
|
---|
203 | listEvents.addListSelectionListener(new ListSelectionListener() {
|
---|
204 | public void valueChanged(ListSelectionEvent arg0) {
|
---|
205 | 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 | }
|
---|
221 | }
|
---|
222 | }
|
---|
223 | });
|
---|
224 | // ***
|
---|
225 |
|
---|
226 | // JButton: btnClose ***
|
---|
227 | btnClose.addMouseListener(new MouseAdapter() {
|
---|
228 | public void mouseClicked(MouseEvent arg0) {
|
---|
229 | frmParent.setVisible(true);
|
---|
230 | frmEvents.dispose();
|
---|
231 | }
|
---|
232 | });
|
---|
233 | // ***
|
---|
234 | }
|
---|
235 |
|
---|
236 | private void updateLists(final List<Event<?>> events,
|
---|
237 | final javax.swing.DefaultListModel modelListEvents,
|
---|
238 | final javax.swing.DefaultListModel modelListTargets) {
|
---|
239 |
|
---|
240 | modelListEvents.clear();
|
---|
241 | modelListTargets.clear();
|
---|
242 | for (int i = 0; i < events.size(); i++) {
|
---|
243 | modelListEvents.addElement(events.get(i).getType());
|
---|
244 | modelListTargets.addElement(events.get(i).getTarget());
|
---|
245 | }
|
---|
246 | }
|
---|
247 | }
|
---|