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