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