-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSizeBox.java
91 lines (77 loc) · 1.83 KB
/
JSizeBox.java
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
package mindmapApplication;
import java.awt.Color;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
public class JSizeBox extends JLabel
{
private JNode node;
private int i;
private int j;
public JSizeBox(JNode node, int i, int j, int x, int y, int size)
{
this.node = node;
this.i = i;
this.j = j;
setBounds(x, y, size, size);
setBorder(BorderFactory.createLineBorder(Color.BLACK));
setBackground(Color.WHITE);
setOpaque(true);
MyMouseListener listener = new MyMouseListener();
addMouseListener(listener);
addMouseMotionListener(listener);
}
private class MyMouseListener extends MouseAdapter implements MouseListener, MouseMotionListener
{
private Point start;
private int x;
private int y;
private int width;
private int height;
public MyMouseListener()
{
start = new Point();
}
@Override
public void mousePressed(MouseEvent e)
{
start.move(e.getXOnScreen(), e.getYOnScreen());
x = node.getX();
y = node.getY();
width = node.getWidth();
height = node.getHeight();
AttributePanel.setMainPanel(node);
}
@Override
public void mouseDragged(MouseEvent e)
{
int mx = e.getXOnScreen();
int my = e.getYOnScreen();
int toX = x;
int toY = y;
int toWidth = width;
int toHeight = height;
if(i == 0)
{
toX = x+mx-start.x;
toWidth = width-mx+start.x;
}
else if(i == 2)
toWidth = width+mx-start.x;
if(j == 0)
{
toY = y+my-start.y;
toHeight = height-my+start.y;
}
else if(j == 2)
toHeight = height+my-start.y;
node.setLocation(toX, toY);
node.setSize(toWidth, toHeight);
AttributePanel.setMainPanel(node);
}
}
}