File: ObjectSelector.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 (95 lines) | stat: -rw-r--r-- 2,358 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
package ThePEG;

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

public class ObjectSelector extends JDialog
                           implements MouseListener,
				      ActionListener {
  ObjectRef selectedObject;
  boolean done = false;
  BrowserTree tree;
  JButton cancelButton = new JButton("Cancel");
  JButton okButton = new JButton("Select");
  SetupThePEG thepeg;

  public ObjectSelector(SetupThePEG thepeg, String dir,
		       String selclass, JDialog owner) {
    super(owner, "Choose an object", true);
    init(thepeg, dir, selclass);
  }

  public ObjectSelector(SetupThePEG thepeg, String dir, String selclass) {
    super(thepeg, "Choose an object", true);
    init(thepeg, dir, selclass);
  }

  public void init(SetupThePEG thepeg, String dir, String selclass) {
    this.thepeg = thepeg;
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    tree = new BrowserTree(thepeg, selclass, true, dir);
    tree.addMouseListener(this);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(tree, 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,400);

    thepeg.setLocation(this);

    setVisible(true);

  }

  public ObjectRef selected() {
    if ( !done ) return null;
    return selectedObject;
  }

  public void actionPerformed(ActionEvent e) {
    if ( e.getSource() == cancelButton ) {
      selectedObject = null;
      dispose();
    }
    if ( e.getSource() == okButton ) {
      if ( selectedObject != null ) {
	done = true;
	dispose();
      } else if ( tree.getSelectedObject() != null ) {
	selectedObject = tree.getSelectedObject();
	done = true;
	dispose();
      }
    }
  }

  public void mouseClicked(MouseEvent e) {
    if ( e.getClickCount() >= 2 ) {
      selectedObject = tree.getSelectedObject();
      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() {}

}