-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopup.java
More file actions
90 lines (80 loc) · 2.78 KB
/
Copy pathPopup.java
File metadata and controls
90 lines (80 loc) · 2.78 KB
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
import javax.swing.JPopupMenu;
import javax.swing.JMenuItem;
import java.awt.Point;
import javax.swing.border.BevelBorder;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
public class Popup extends JPopupMenu
{
Object obj;
Point p;
public Popup(Object obj, ArrayList<Variable> variables, String[] options, Point p)
{
Container.appendPopup(this);
this.obj = obj;
this.p = p;
ActionListener menuListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {
setVisible(false);
}
};
if(variables != null)
{
// ADD VARIABLES
for(Variable v : variables)
{
if((v.isConstant() && !v.isEnvironmental()))
{
if(v.getAngle() != null)
add(new PopupOption(this, obj, v.getName().toString() + " : " + v.getValue().toString() + " " + v.getUnits() + ", " + v.getAngle() + "°", menuListener, p));
else
add(new PopupOption(this, obj, v.getName().toString() + " : " + v.getValue().toString() + " " + v.getUnits(), menuListener, p));
}
}
addSeparator();
}
for(String str : options)
{
if(!str.equals(""))
add(new PopupOption(this, obj, str, menuListener, p));
}
setLocation((int)p.getX(), (int)p.getY());
setBorder(new BevelBorder(BevelBorder.RAISED));
setVisible(true);
}
public class PopupOption extends JMenuItem implements MouseListener
{
String str = "";
Object obj;
Point p;
Popup popup;
public PopupOption(Popup popup, Object obj, String str, ActionListener al, Point p)
{
super(str);
this.p = p;
this.popup = popup;
this.str = str;
this.obj = obj;
setHorizontalTextPosition(JMenuItem.RIGHT);
addActionListener(al);
addMouseListener(this);
}
public void mouseExited(MouseEvent e){setArmed(false);}
public void mouseEntered(MouseEvent e){setArmed(true);}
public void mouseReleased(MouseEvent e)
{
popup.setVisible(false);
if(obj instanceof Snap)
Snap.parseSnap(obj).run(str);
else if(obj instanceof Figure)
Figure.parseFigure(obj).run(str);
else
Container.run(str);
}
public void mouseClicked(MouseEvent e){}
public void mousePressed(MouseEvent e){}
}
}