File: ClassSelector.java

package info (click to toggle)
thepeg 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 9,312 kB
  • ctags: 11,509
  • sloc: cpp: 57,129; sh: 11,315; java: 3,212; lisp: 1,402; makefile: 830; ansic: 58; perl: 3
file content (107 lines) | stat: -rw-r--r-- 2,823 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package ThePEG;

import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;

public class ClassSelector extends JDialog
                           implements MouseListener,
				      ActionListener {
  String selectedClass;
  boolean done = false;
  JList classList = new JList();
  JButton cancelButton = new JButton("Cancel");
  JButton okButton = new JButton("Select");
  SetupThePEG thepeg;

  public ClassSelector(SetupThePEG thepeg) {
    super(thepeg, "Choose a class", true);
    init(thepeg, "ThePEG::Interfaced", null);
  }

  public ClassSelector(SetupThePEG thepeg, String cl) {
    super(thepeg, "Choose a class", true);
    init(thepeg, cl, null);
  }

  public ClassSelector(SetupThePEG thepeg, JDialog owner, String cl) {
    super(owner, "Choose a class", true);
    init(thepeg, cl, owner);
  }

  public void init(SetupThePEG thepeg, String cl, JDialog owner) {
    this.thepeg = thepeg;
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    LinkedList ret = thepeg.exec("lsclass " + cl);
    if ( ret.size() <= 0 ) {
      JOptionPane.showMessageDialog(this, "No classes found.", "Error",
				    JOptionPane.ERROR_MESSAGE);
      dispose();
      return;
    }

    classList.setListData(ret.toArray());
    classList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    classList.addMouseListener(this);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(new JScrollPane(classList), BorderLayout.CENTER);

    JPanel panel = new JPanel();
    cancelButton.addActionListener(this);
    okButton.addActionListener(this);
    panel.add(cancelButton);
    panel.add(okButton);
    getContentPane().add(panel, BorderLayout.SOUTH);

    setSize(300,300);
    thepeg.setLocation(this);

    setVisible(true);

  }

  public String selected() {
    if ( selectedClass == null || !done ) return null;
    return selectedClass;
  }

  public void actionPerformed(ActionEvent e) {
    if ( e.getSource() == cancelButton ) {
      selectedClass = null;
      dispose();
    }
    if ( e.getSource() == okButton ) {
      if ( selectedClass != null ) {
	done = true;
	dispose();
      } else if ( classList.getSelectedValue() != null ) {
	selectedClass = (String)classList.getSelectedValue();
	done = true;
	dispose();
      }
    }
  }

  public void mouseClicked(MouseEvent e) {
    if ( e.getSource() == classList && e.getClickCount() >= 2 ) {
      selectedClass = (String)classList.getSelectedValue();
      done = true;
      dispose();
    }
  }

  public void mouseEntered(MouseEvent e) {}
  public void mouseExited(MouseEvent e) {}
  public void mousePressed(MouseEvent e) {}
  public void mouseReleased(MouseEvent e) {}

  public void dispose() {
    thepeg.removeLocation(this);
    super.dispose();
  }

  public static void classcheck() {}

}