| 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 | /**
|
|---|
| 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 | */
|
|---|
| 32 | public class DlgSequences {
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * <p>
|
|---|
| 36 | * All the sequences that are found in the parsed log
|
|---|
| 37 | * </p>
|
|---|
| 38 | */
|
|---|
| 39 | private List<List<Event<?>>> containedSequences;
|
|---|
| 40 |
|
|---|
| 41 | private JFrame frmSequences;
|
|---|
| 42 |
|
|---|
| 43 | /**
|
|---|
| 44 | * <p>
|
|---|
| 45 | * Launch the dialog
|
|---|
| 46 | * </p>
|
|---|
| 47 | */
|
|---|
| 48 | public static void showDialog() {
|
|---|
| 49 |
|
|---|
| 50 | EventQueue.invokeLater(new Runnable() {
|
|---|
| 51 | public void run() {
|
|---|
| 52 | try {
|
|---|
| 53 | DlgSequences window = new DlgSequences();
|
|---|
| 54 | window.frmSequences.setVisible(true);
|
|---|
| 55 | } catch (Exception e) {
|
|---|
| 56 | e.printStackTrace();
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 | });
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | /**
|
|---|
| 63 | * <p>
|
|---|
| 64 | * Create the dialog
|
|---|
| 65 | * </p>
|
|---|
| 66 | */
|
|---|
| 67 | public DlgSequences() {
|
|---|
| 68 | initialize();
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | /**
|
|---|
| 72 | * <p>
|
|---|
| 73 | * Initialize the contents of the frame.
|
|---|
| 74 | * </p>
|
|---|
| 75 | */
|
|---|
| 76 | @SuppressWarnings("unchecked")
|
|---|
| 77 | private void initialize() {
|
|---|
| 78 | frmSequences = new JFrame();
|
|---|
| 79 | frmSequences.addWindowListener(new WindowAdapter() {
|
|---|
| 80 | @Override
|
|---|
| 81 | public void windowClosed(WindowEvent arg0) {
|
|---|
| 82 |
|
|---|
| 83 | synchronized (Console.getInstance()) {
|
|---|
| 84 | Console.getInstance().notify();
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 | });
|
|---|
| 88 |
|
|---|
| 89 | frmSequences.setTitle("Sequences");
|
|---|
| 90 | frmSequences.setResizable(false);
|
|---|
| 91 | frmSequences.setBounds(100, 100, 270, 332);
|
|---|
| 92 | frmSequences.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|---|
| 93 | frmSequences.getContentPane().setLayout(null);
|
|---|
| 94 |
|
|---|
| 95 | final javax.swing.DefaultListModel modelListSequences = new javax.swing.DefaultListModel();
|
|---|
| 96 | final JButton btnSequence = new JButton("Show details");
|
|---|
| 97 | final JButton btnClose = new JButton("Close");
|
|---|
| 98 |
|
|---|
| 99 | JPanel panel = new JPanel();
|
|---|
| 100 | panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
|
|---|
| 101 | panel.setBounds(10, 11, 244, 218);
|
|---|
| 102 | frmSequences.getContentPane().add(panel);
|
|---|
| 103 | panel.setLayout(null);
|
|---|
| 104 |
|
|---|
| 105 | JScrollPane scrollPane = new JScrollPane();
|
|---|
| 106 | scrollPane.setBounds(10, 11, 224, 196);
|
|---|
| 107 | panel.add(scrollPane);
|
|---|
| 108 | final JList listSequences = new JList(modelListSequences);
|
|---|
| 109 | scrollPane.setViewportView(listSequences);
|
|---|
| 110 |
|
|---|
| 111 | JPanel panel_1 = new JPanel();
|
|---|
| 112 | panel_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
|
|---|
| 113 | panel_1.setBounds(10, 240, 244, 53);
|
|---|
| 114 | frmSequences.getContentPane().add(panel_1);
|
|---|
| 115 | panel_1.setLayout(null);
|
|---|
| 116 |
|
|---|
| 117 | // get the available sequences out of globalDataContainer
|
|---|
| 118 | try {
|
|---|
| 119 | containedSequences = (List<List<Event<?>>>) GlobalDataContainer
|
|---|
| 120 | .getInstance().getData("sequences");
|
|---|
| 121 | } catch (ClassCastException e) {
|
|---|
| 122 | Console.println("Not able to cast data in globalDataContainer to list of sequences");
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | // display sequences in the dialog
|
|---|
| 126 | try {
|
|---|
| 127 | for (int i = 0; i < containedSequences.size(); i++) {
|
|---|
| 128 | modelListSequences.addElement("Sequence " + (i + 1) + ": "
|
|---|
| 129 | + containedSequences.get(i).size() + " Events");
|
|---|
| 130 | }
|
|---|
| 131 | } catch (NullPointerException e) {
|
|---|
| 132 | Console.println("No sequences found.");
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | // enable/disable the "Show details" button by selecting/deselecting a
|
|---|
| 136 | // sequence
|
|---|
| 137 | listSequences.addListSelectionListener(new ListSelectionListener() {
|
|---|
| 138 | public void valueChanged(ListSelectionEvent arg0) {
|
|---|
| 139 | if (listSequences.getSelectedIndex() >= 0)
|
|---|
| 140 | btnSequence.setEnabled(true);
|
|---|
| 141 | else
|
|---|
| 142 | btnSequence.setEnabled(false);
|
|---|
| 143 | }
|
|---|
| 144 | });
|
|---|
| 145 |
|
|---|
| 146 | // listener for clicking the "Show details" button
|
|---|
| 147 | btnSequence.addMouseListener(new MouseAdapter() {
|
|---|
| 148 | public void mouseClicked(MouseEvent arg0) {
|
|---|
| 149 | if (btnSequence.isEnabled()) {
|
|---|
| 150 | DlgSequenceDetails dlgSequences = new DlgSequenceDetails(
|
|---|
| 151 | frmSequences, containedSequences.get(listSequences
|
|---|
| 152 | .getSelectedIndex()));
|
|---|
| 153 | dlgSequences.showDialog(frmSequences, containedSequences
|
|---|
| 154 | .get(listSequences.getSelectedIndex()));
|
|---|
| 155 | frmSequences.setVisible(false);
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 | });
|
|---|
| 159 | btnSequence.setBounds(124, 11, 110, 32);
|
|---|
| 160 | panel_1.add(btnSequence);
|
|---|
| 161 | btnSequence.setEnabled(false);
|
|---|
| 162 |
|
|---|
| 163 | // listener for clicking the "Close" button
|
|---|
| 164 | btnClose.addMouseListener(new MouseAdapter() {
|
|---|
| 165 | public void mouseClicked(MouseEvent arg0) {
|
|---|
| 166 | frmSequences.dispose();
|
|---|
| 167 | }
|
|---|
| 168 | });
|
|---|
| 169 | btnClose.setBounds(10, 11, 110, 32);
|
|---|
| 170 | panel_1.add(btnClose);
|
|---|
| 171 | }
|
|---|
| 172 | }
|
|---|