1 | /* |
---|
2 | * $Id: DataGroupDragBox.java,v 1.2 2003/08/22 23:02:33 dwd Exp $ |
---|
3 | * |
---|
4 | * This software is provided by NOAA for full, free and open release. It is |
---|
5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
6 | * errors contained in the code. Although this software is released without |
---|
7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
9 | * Administration should the software be included by the recipient as an |
---|
10 | * element in other product development. |
---|
11 | */ |
---|
12 | |
---|
13 | package gov.noaa.pmel.sgt.beans; |
---|
14 | |
---|
15 | import java.awt.*; |
---|
16 | //import gov.noaa.pmel.util.Rectangle2D; |
---|
17 | import javax.swing.event.ChangeEvent; |
---|
18 | import javax.swing.event.ChangeListener; |
---|
19 | import java.awt.geom.Rectangle2D; |
---|
20 | |
---|
21 | /** |
---|
22 | * @author Donald Denbo |
---|
23 | * @version $Revision: 1.2 $, $Date: 2003/08/22 23:02:33 $ |
---|
24 | * @since 3.0 |
---|
25 | **/ |
---|
26 | class DataGroupDragBox extends DragBox implements ChangeListener { |
---|
27 | private Rectangle boundsD_ = new Rectangle(); |
---|
28 | private DataGroup dg_ = null; |
---|
29 | private AxisHolderDragBox xAxDB_ = null; |
---|
30 | private AxisHolderDragBox yAxDB_ = null; |
---|
31 | |
---|
32 | public DataGroupDragBox(DataGroup dg, PanelHolder pHolder) { |
---|
33 | super(pHolder); |
---|
34 | dg_ = dg; |
---|
35 | dg_.addChangeListener(this); |
---|
36 | for(int i=0; i < handles_.length; i++) { |
---|
37 | handles_[i] = new Rectangle(0,0,0,0); |
---|
38 | } |
---|
39 | update("DataGroupDragBox.new()"); |
---|
40 | } |
---|
41 | |
---|
42 | public DataGroup getDataGroup() { |
---|
43 | return dg_; |
---|
44 | } |
---|
45 | |
---|
46 | public void setBounds(Rectangle bounds) { |
---|
47 | boundsD_ = bounds; |
---|
48 | dg_.setMargin(computeMargin()); |
---|
49 | computeHandles(); |
---|
50 | } |
---|
51 | |
---|
52 | private Margin computeMargin() { |
---|
53 | Rectangle panel = pHolder_.getBounds(); |
---|
54 | float dpi = pHolder_.getPanelModel().getDpi(); |
---|
55 | float top = ((float)(boundsD_.y - panel.y))/dpi; |
---|
56 | float bottom = ((float)((panel.y + panel.height) - (boundsD_.y + boundsD_.height)))/dpi; |
---|
57 | float left = ((float)(boundsD_.x - panel.x))/dpi; |
---|
58 | float right = ((float)((panel.x + panel.width) - (boundsD_.x + boundsD_.width)))/dpi; |
---|
59 | return new Margin(top, left, bottom, right); |
---|
60 | } |
---|
61 | |
---|
62 | public void draw(Graphics g) { |
---|
63 | Rectangle bounds = getBounds(); |
---|
64 | Color savedColor = g.getColor(); |
---|
65 | if(selected_) { |
---|
66 | g.setColor(Color.red); |
---|
67 | } else { |
---|
68 | g.setColor(Color.green); |
---|
69 | } |
---|
70 | // draw AxisHolder |
---|
71 | |
---|
72 | // draw rectangle dashed |
---|
73 | Rectangle2D rect = new Rectangle2D.Float(bounds.x, bounds.y, |
---|
74 | bounds.width, bounds.height); |
---|
75 | Graphics2D g2 = (Graphics2D)g; |
---|
76 | Stroke saved = g2.getStroke(); |
---|
77 | float[] dashes = {4.0f, 4.0f}; |
---|
78 | BasicStroke stroke = new BasicStroke(1.0f, |
---|
79 | BasicStroke.CAP_SQUARE, |
---|
80 | BasicStroke.JOIN_MITER, |
---|
81 | 10.0f, |
---|
82 | dashes, |
---|
83 | 0.0f); |
---|
84 | g2.setStroke(stroke); |
---|
85 | g2.draw(rect); |
---|
86 | g2.setStroke(saved); |
---|
87 | // Name |
---|
88 | /* if(dg_.getXPosition() == DataGroup.BOTTOM) { |
---|
89 | yString += BOX_HEIGHT - 2; |
---|
90 | } else { |
---|
91 | yString += BOX_HEIGHT - TIC_LENGTH - 2; |
---|
92 | } |
---|
93 | g.drawString(dg_.getId(), xBoundsD_.x + 5, yString); */ |
---|
94 | |
---|
95 | if(selected_) { |
---|
96 | for(int i=0; i < handles_.length; i++) { |
---|
97 | Rectangle r = handles_[i]; |
---|
98 | g.fillRect(r.x, r.y, r.width-1, r.height-1); |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | g.setColor(savedColor); |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | public void update(String message) { |
---|
107 | // if(Page.DEBUG) System.out.println("DataGroupDragBox.update(" + message + ")"); |
---|
108 | Rectangle panel = pHolder_.getBounds(); |
---|
109 | Margin margin = dg_.getMargin(); |
---|
110 | float dpi = pHolder_.getPanelModel().getDpi(); |
---|
111 | int left = (int)(margin.left*dpi); |
---|
112 | int right = (int)(margin.right*dpi); |
---|
113 | int top = (int)(margin.top*dpi); |
---|
114 | int bottom = (int)(margin.bottom*dpi); |
---|
115 | boundsD_.x = panel.x + left; |
---|
116 | boundsD_.y = panel.y + top; |
---|
117 | boundsD_.width = panel.width - (left + right); |
---|
118 | boundsD_.height = panel.height - (top + bottom); |
---|
119 | computeHandles(); |
---|
120 | } |
---|
121 | |
---|
122 | public void setLocation(Point pt) { |
---|
123 | boundsD_.x = pt.x; |
---|
124 | boundsD_.y = pt.y; |
---|
125 | dg_.setMargin(computeMargin()); |
---|
126 | computeHandles(); |
---|
127 | } |
---|
128 | |
---|
129 | public Point getLocation() { |
---|
130 | return new Point(boundsD_.x, boundsD_.y); |
---|
131 | } |
---|
132 | |
---|
133 | public Rectangle getBounds() { |
---|
134 | return boundsD_; |
---|
135 | } |
---|
136 | |
---|
137 | public String getId() { |
---|
138 | return dg_.getId(); |
---|
139 | } |
---|
140 | |
---|
141 | public void setId(String id) { |
---|
142 | dg_.setId(id); |
---|
143 | } |
---|
144 | |
---|
145 | public void setAxisHolderDB(AxisHolderDragBox x, AxisHolderDragBox y) { |
---|
146 | xAxDB_ = x; |
---|
147 | yAxDB_ = y; |
---|
148 | } |
---|
149 | |
---|
150 | public AxisHolderDragBox getXAxisHolderDB() { |
---|
151 | return xAxDB_; |
---|
152 | } |
---|
153 | |
---|
154 | public AxisHolderDragBox getYAxisHolderDB() { |
---|
155 | return yAxDB_; |
---|
156 | } |
---|
157 | |
---|
158 | public void stateChanged(ChangeEvent e) { |
---|
159 | update("DataGroupDragBox.stateChanged()"); |
---|
160 | } |
---|
161 | } |
---|