1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package org.ericmignot.modeler.gui.layout; |
19 |
| |
20 |
| import java.awt.Component; |
21 |
| import java.awt.Container; |
22 |
| import java.awt.Dimension; |
23 |
| import java.awt.LayoutManager; |
24 |
| |
25 |
| import org.ericmignot.modeler.gui.StaticValues; |
26 |
| |
27 |
| |
28 |
| public class ZoomLayoutManager implements LayoutManager |
29 |
| { |
30 |
| |
31 |
| private double zoomRatio; |
32 |
| |
33 |
164
| public ZoomLayoutManager()
|
34 |
| { |
35 |
164
| this.setZoomRatio(1.0);
|
36 |
| } |
37 |
| |
38 |
0
| public Dimension preferredLayoutSize(Container c)
|
39 |
| { |
40 |
0
| return zoom(c.getPreferredSize());
|
41 |
| } |
42 |
| |
43 |
0
| public Dimension minimumLayoutSize(Container c)
|
44 |
| { |
45 |
0
| return zoom(c.getPreferredSize());
|
46 |
| } |
47 |
| |
48 |
0
| private Dimension zoom(Dimension dim)
|
49 |
| { |
50 |
0
| return new Dimension( (int)(dim.width * getZoomRatio()),
|
51 |
| (int)(dim.height * getZoomRatio()) ); |
52 |
| } |
53 |
| |
54 |
| |
55 |
0
| public void addLayoutComponent(String s, Component c)
|
56 |
| { |
57 |
| } |
58 |
| |
59 |
18
| public void removeLayoutComponent(Component c)
|
60 |
| { |
61 |
| } |
62 |
| |
63 |
1197
| public void zoomComponent(Component c)
|
64 |
| { |
65 |
1197
| if (c instanceof Zoomable)
|
66 |
| { |
67 |
1197
| Zoomable z = (Zoomable) c;
|
68 |
1197
| c.setSize(z.getZoomedSize(this.zoomRatio));
|
69 |
1197
| c.setLocation(z.getZoomedLocation(this.zoomRatio));
|
70 |
| } |
71 |
| } |
72 |
| |
73 |
531
| public void layoutContainer(java.awt.Container target)
|
74 |
| { |
75 |
531
| synchronized (target.getTreeLock())
|
76 |
| { |
77 |
531
| for (int i = 0; i < target.getComponentCount(); i++)
|
78 |
| { |
79 |
1194
| Component c = target.getComponent(i);
|
80 |
1194
| this.zoomComponent(c);
|
81 |
| } |
82 |
| } |
83 |
| } |
84 |
| |
85 |
| |
86 |
196
| public double getZoomRatio()
|
87 |
| { |
88 |
196
| return zoomRatio;
|
89 |
| } |
90 |
| |
91 |
| |
92 |
191
| public void setZoomRatio(double zoomRatio)
|
93 |
| { |
94 |
191
| if (zoomRatio > 0.0)
|
95 |
| { |
96 |
191
| this.zoomRatio = zoomRatio;
|
97 |
| } |
98 |
| } |
99 |
| |
100 |
1
| public void zoomIn()
|
101 |
| { |
102 |
1
| double increment = Double.parseDouble(StaticValues.getInstance().get("Design.Zoom.IncrementDecrement", "0.2"));
|
103 |
1
| this.setZoomRatio(this.getZoomRatio() + increment);
|
104 |
| } |
105 |
| |
106 |
1
| public void zoomOut()
|
107 |
| { |
108 |
1
| double decrement = Double.parseDouble(StaticValues.getInstance().get("Design.Zoom.IncrementDecrement", "0.2"));
|
109 |
1
| this.setZoomRatio(this.getZoomRatio() - decrement);
|
110 |
| } |
111 |
| |
112 |
| } |