1 | package de.ugoe.cs.eventbench.swing;
|
---|
2 |
|
---|
3 | import java.awt.EventQueue;
|
---|
4 | import javax.swing.JFrame;
|
---|
5 | import javax.swing.JList;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import javax.swing.JButton;
|
---|
9 | import javax.swing.event.ListSelectionListener;
|
---|
10 | import javax.swing.event.ListSelectionEvent;
|
---|
11 | import de.ugoe.cs.eventbench.data.Event;
|
---|
12 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
13 | import de.ugoe.cs.util.console.Console;
|
---|
14 |
|
---|
15 | import java.awt.event.MouseAdapter;
|
---|
16 | import java.awt.event.MouseEvent;
|
---|
17 | import javax.swing.JPanel;
|
---|
18 | import javax.swing.border.EtchedBorder;
|
---|
19 | import javax.swing.JScrollPane;
|
---|
20 | import java.awt.event.WindowAdapter;
|
---|
21 | import java.awt.event.WindowEvent;
|
---|
22 |
|
---|
23 | public class DlgSequences {
|
---|
24 |
|
---|
25 | private JFrame frmSequences;
|
---|
26 | private List<List<Event<?>>> containedSequences;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Launch the application.
|
---|
30 | */
|
---|
31 | public static void showDialog() {
|
---|
32 |
|
---|
33 | EventQueue.invokeLater(new Runnable() {
|
---|
34 | public void run() {
|
---|
35 | try {
|
---|
36 | DlgSequences window = new DlgSequences();
|
---|
37 | window.frmSequences.setVisible(true);
|
---|
38 | } catch (Exception e) {
|
---|
39 | e.printStackTrace();
|
---|
40 | }
|
---|
41 | }
|
---|
42 | });
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Create the application.
|
---|
47 | */
|
---|
48 | public DlgSequences() {
|
---|
49 | initialize();
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Initialize the contents of the frame.
|
---|
54 | */
|
---|
55 | @SuppressWarnings("unchecked")
|
---|
56 | private void initialize() {
|
---|
57 | frmSequences = new JFrame();
|
---|
58 | frmSequences.addWindowListener(new WindowAdapter() {
|
---|
59 | @Override
|
---|
60 | public void windowClosed(WindowEvent arg0) {
|
---|
61 |
|
---|
62 | synchronized (Console.getInstance()) {
|
---|
63 | Console.getInstance().notify();
|
---|
64 | }
|
---|
65 | }
|
---|
66 | });
|
---|
67 | final javax.swing.DefaultListModel modelListSequences = new javax.swing.DefaultListModel();
|
---|
68 | final JButton btnSequence = new JButton("Show details");
|
---|
69 | final JButton btnClose = new JButton("Close");
|
---|
70 | JPanel panel = new JPanel();
|
---|
71 |
|
---|
72 | // JFrame: frmSequence ***
|
---|
73 | frmSequences.setTitle("Sequences");
|
---|
74 | frmSequences.setResizable(false);
|
---|
75 | frmSequences.setBounds(100, 100, 270, 332);
|
---|
76 | frmSequences.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
---|
77 | frmSequences.getContentPane().setLayout(null);
|
---|
78 |
|
---|
79 | try {
|
---|
80 | containedSequences = (List<List<Event<?>>>) GlobalDataContainer
|
---|
81 | .getInstance().getData("sequences");
|
---|
82 | } catch (ClassCastException e) {
|
---|
83 | Console.println("Not able to cast Data in GlobalDataContainer to List of Sequences");
|
---|
84 | }
|
---|
85 |
|
---|
86 | try {
|
---|
87 | for (int i = 0; i < containedSequences.size(); i++) {
|
---|
88 | modelListSequences.addElement("Sequence " + (i + 1) + ": "
|
---|
89 | + containedSequences.get(i).size() + " Events");
|
---|
90 | }
|
---|
91 | } catch (NullPointerException e) {
|
---|
92 | Console.println("No sequences found.");
|
---|
93 | }
|
---|
94 |
|
---|
95 | panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
|
---|
96 | panel.setBounds(10, 11, 244, 218);
|
---|
97 | frmSequences.getContentPane().add(panel);
|
---|
98 | panel.setLayout(null);
|
---|
99 | // ***
|
---|
100 |
|
---|
101 | // JScrollPane: scrollPane
|
---|
102 | JScrollPane scrollPane = new JScrollPane();
|
---|
103 | scrollPane.setBounds(10, 11, 224, 196);
|
---|
104 | panel.add(scrollPane);
|
---|
105 | final JList listSequences = new JList(modelListSequences);
|
---|
106 | scrollPane.setViewportView(listSequences);
|
---|
107 | // ***
|
---|
108 |
|
---|
109 | // JList: listSequnces
|
---|
110 | listSequences.addListSelectionListener(new ListSelectionListener() {
|
---|
111 | public void valueChanged(ListSelectionEvent arg0) {
|
---|
112 | if (listSequences.getSelectedIndex() >= 0)
|
---|
113 | btnSequence.setEnabled(true);
|
---|
114 | else
|
---|
115 | btnSequence.setEnabled(false);
|
---|
116 | }
|
---|
117 | });
|
---|
118 |
|
---|
119 | JPanel panel_1 = new JPanel();
|
---|
120 | panel_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
|
---|
121 | panel_1.setBounds(10, 240, 244, 53);
|
---|
122 | frmSequences.getContentPane().add(panel_1);
|
---|
123 | panel_1.setLayout(null);
|
---|
124 | // ***
|
---|
125 |
|
---|
126 | // JButton: btnSequence ***
|
---|
127 | btnSequence.addMouseListener(new MouseAdapter() {
|
---|
128 | public void mouseClicked(MouseEvent arg0) {
|
---|
129 | if (btnSequence.isEnabled()) {
|
---|
130 | DlgSequenceDetails dlgSequences = new DlgSequenceDetails(
|
---|
131 | frmSequences, containedSequences.get(listSequences
|
---|
132 | .getSelectedIndex()));
|
---|
133 | dlgSequences.showDialog(frmSequences, containedSequences
|
---|
134 | .get(listSequences.getSelectedIndex()));
|
---|
135 | frmSequences.setVisible(false);
|
---|
136 | }
|
---|
137 | }
|
---|
138 | });
|
---|
139 | btnSequence.setBounds(124, 11, 110, 32);
|
---|
140 | panel_1.add(btnSequence);
|
---|
141 | btnSequence.setEnabled(false);
|
---|
142 | // ***
|
---|
143 |
|
---|
144 | // JButton: btnClose ***
|
---|
145 | btnClose.addMouseListener(new MouseAdapter() {
|
---|
146 | public void mouseClicked(MouseEvent arg0) {
|
---|
147 | frmSequences.dispose();
|
---|
148 | }
|
---|
149 | });
|
---|
150 | btnClose.setBounds(10, 11, 110, 32);
|
---|
151 | panel_1.add(btnClose);
|
---|
152 | // ***
|
---|
153 | }
|
---|
154 | }
|
---|