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