source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swing/DlgSequences.java @ 229

Last change on this file since 229 was 229, checked in by sherbold, 13 years ago
  • Property svn:mime-type set to text/plain
File size: 4.8 KB
Line 
1package de.ugoe.cs.eventbench.swing;
2
3import java.awt.EventQueue;
4import javax.swing.JFrame;
5import javax.swing.JList;
6import java.util.List;
7
8import javax.swing.JButton;
9import javax.swing.event.ListSelectionListener;
10import javax.swing.event.ListSelectionEvent;
11import de.ugoe.cs.eventbench.data.Event;
12import de.ugoe.cs.eventbench.data.GlobalDataContainer;
13import de.ugoe.cs.util.console.Console;
14
15import java.awt.event.MouseAdapter;
16import java.awt.event.MouseEvent;
17import javax.swing.JPanel;
18import javax.swing.border.EtchedBorder;
19import javax.swing.JScrollPane;
20import java.awt.event.WindowAdapter;
21import java.awt.event.WindowEvent;
22
23/**
24 * <p>
25 * This class provides the dialog to choose one of the available sequences after
26 * parsing a log
27 * </p>
28 *
29 * @author Jeffrey Hall
30 * @version 1.0
31 * @deprecated Use SWT-GUI for modifying sequences.
32 */
33public class DlgSequences {
34
35        /**
36         * <p>
37         * All the sequences that are found in the parsed log
38         * </p>
39         */
40        private List<List<Event<?>>> containedSequences;
41
42        private JFrame frmSequences;
43
44        /**
45         * <p>
46         * Launch the dialog
47         * </p>
48         */
49        public static void showDialog() {
50
51                EventQueue.invokeLater(new Runnable() {
52                        public void run() {
53                                try {
54                                        DlgSequences window = new DlgSequences();
55                                        window.frmSequences.setVisible(true);
56                                } catch (Exception e) {
57                                        e.printStackTrace();
58                                }
59                        }
60                });
61        }
62
63        /**
64         * <p>
65         * Create the dialog
66         * </p>
67         */
68        public DlgSequences() {
69                initialize();
70        }
71
72        /**
73         * <p>
74         * Initialize the contents of the frame.
75         * </p>
76         */
77        @SuppressWarnings("unchecked")
78        private void initialize() {
79                frmSequences = new JFrame();
80                frmSequences.addWindowListener(new WindowAdapter() {
81                        @Override
82                        public void windowClosed(WindowEvent arg0) {
83
84                                synchronized (Console.getInstance()) {
85                                        Console.getInstance().notify();
86                                }
87                        }
88                });
89
90                frmSequences.setTitle("Sequences");
91                frmSequences.setResizable(false);
92                frmSequences.setBounds(100, 100, 270, 332);
93                frmSequences.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
94                frmSequences.getContentPane().setLayout(null);
95
96                final javax.swing.DefaultListModel modelListSequences = new javax.swing.DefaultListModel();
97                final JButton btnSequence = new JButton("Show details");
98                final JButton btnClose = new JButton("Close");
99
100                JPanel panel = new JPanel();
101                panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
102                panel.setBounds(10, 11, 244, 218);
103                frmSequences.getContentPane().add(panel);
104                panel.setLayout(null);
105
106                JScrollPane scrollPane = new JScrollPane();
107                scrollPane.setBounds(10, 11, 224, 196);
108                panel.add(scrollPane);
109                final JList listSequences = new JList(modelListSequences);
110                scrollPane.setViewportView(listSequences);
111
112                JPanel panel_1 = new JPanel();
113                panel_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
114                panel_1.setBounds(10, 240, 244, 53);
115                frmSequences.getContentPane().add(panel_1);
116                panel_1.setLayout(null);
117
118                // get the available sequences out of globalDataContainer
119                try {
120                        containedSequences = (List<List<Event<?>>>) GlobalDataContainer
121                                        .getInstance().getData("sequences");
122                } catch (ClassCastException e) {
123                        Console.println("Not able to cast data in globalDataContainer to list of sequences");
124                }
125
126                // display sequences in the dialog
127                try {
128                        for (int i = 0; i < containedSequences.size(); i++) {
129                                modelListSequences.addElement("Sequence " + (i + 1) + ": "
130                                                + containedSequences.get(i).size() + " Events");
131                        }
132                } catch (NullPointerException e) {
133                        Console.println("No sequences found.");
134                }
135
136                // enable/disable the "Show details" button by selecting/deselecting a
137                // sequence
138                listSequences.addListSelectionListener(new ListSelectionListener() {
139                        public void valueChanged(ListSelectionEvent arg0) {
140                                if (listSequences.getSelectedIndex() >= 0)
141                                        btnSequence.setEnabled(true);
142                                else
143                                        btnSequence.setEnabled(false);
144                        }
145                });
146
147                // listener for clicking the "Show details" button
148                btnSequence.addMouseListener(new MouseAdapter() {
149                        public void mouseClicked(MouseEvent arg0) {
150                                if (btnSequence.isEnabled()) {
151                                        DlgSequenceDetails dlgSequences = new DlgSequenceDetails(
152                                                        frmSequences, containedSequences.get(listSequences
153                                                                        .getSelectedIndex()));
154                                        dlgSequences.showDialog(frmSequences, containedSequences
155                                                        .get(listSequences.getSelectedIndex()));
156                                        frmSequences.setVisible(false);
157                                }
158                        }
159                });
160                btnSequence.setBounds(124, 11, 110, 32);
161                panel_1.add(btnSequence);
162                btnSequence.setEnabled(false);
163
164                // listener for clicking the "Close" button
165                btnClose.addMouseListener(new MouseAdapter() {
166                        public void mouseClicked(MouseEvent arg0) {
167                                frmSequences.dispose();
168                        }
169                });
170                btnClose.setBounds(10, 11, 110, 32);
171                panel_1.add(btnClose);
172        }
173}
Note: See TracBrowser for help on using the repository browser.