1 | /* |
---|
2 | * $Id: LegendDragBox.java,v 1.2 2003/08/22 23:02:35 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 | |
---|
17 | import gov.noaa.pmel.util.Rectangle2D; |
---|
18 | import javax.swing.event.ChangeEvent; |
---|
19 | import javax.swing.event.ChangeListener; |
---|
20 | |
---|
21 | /** |
---|
22 | * @author Donald Denbo |
---|
23 | * @version $Revision: 1.2 $, $Date: 2003/08/22 23:02:35 $ |
---|
24 | * @since 3.0 |
---|
25 | **/ |
---|
26 | class LegendDragBox extends DragBox implements ChangeListener { |
---|
27 | private Legend legend_ = null; |
---|
28 | private Rectangle boundsD_ = null; |
---|
29 | |
---|
30 | public LegendDragBox(Legend legend, PanelHolder pHolder) { |
---|
31 | super(pHolder); |
---|
32 | legend_ = legend; |
---|
33 | legend_.addChangeListener(this); |
---|
34 | boundsD_ = toRectangle(legend_.getBoundsP()); |
---|
35 | for(int i=0; i < handles_.length; i++) { |
---|
36 | handles_[i] = new Rectangle(0,0,0,0); |
---|
37 | } |
---|
38 | computeHandles(); |
---|
39 | } |
---|
40 | |
---|
41 | public Legend getLegend() { |
---|
42 | return legend_; |
---|
43 | } |
---|
44 | |
---|
45 | public void setBounds(Rectangle bounds) { |
---|
46 | boundsD_ = bounds; |
---|
47 | legend_.setBoundsP(toRectangle(boundsD_)); |
---|
48 | computeHandles(); |
---|
49 | } |
---|
50 | |
---|
51 | public void draw(Graphics g) { |
---|
52 | Rectangle bounds = getBounds(); |
---|
53 | Color saved = g.getColor(); |
---|
54 | g.setColor(Color.darkGray); |
---|
55 | g.drawString(getId(), bounds.x + 5, bounds.y + 12); |
---|
56 | g.setColor(color_); |
---|
57 | if(legend_.isVisible()) |
---|
58 | g.drawRect(bounds.x, bounds.y, bounds.width-1, bounds.height-1); |
---|
59 | if(selected_) { |
---|
60 | for(int i=0; i < handles_.length; i++) { |
---|
61 | Rectangle r = handles_[i]; |
---|
62 | g.fillRect(r.x, r.y, r.width-1, r.height-1); |
---|
63 | } |
---|
64 | } |
---|
65 | g.setColor(saved); |
---|
66 | } |
---|
67 | |
---|
68 | public void setLocation(Point pt) { |
---|
69 | boundsD_.x = pt.x; |
---|
70 | boundsD_.y = pt.y; |
---|
71 | legend_.setBoundsP(toRectangle(boundsD_)); |
---|
72 | computeHandles(); |
---|
73 | } |
---|
74 | |
---|
75 | public Point getLocation() { |
---|
76 | return new Point(boundsD_.x, boundsD_.y); |
---|
77 | } |
---|
78 | |
---|
79 | public Rectangle getBounds() { |
---|
80 | return boundsD_; |
---|
81 | } |
---|
82 | |
---|
83 | public String getId() { |
---|
84 | return legend_.getId(); |
---|
85 | } |
---|
86 | |
---|
87 | public void update(String message) { |
---|
88 | // if(Page.DEBUG) System.out.println("LegendDragBox.update(" + message + ")"); |
---|
89 | boundsD_ = toRectangle(legend_.getBoundsP()); |
---|
90 | computeHandles(); |
---|
91 | } |
---|
92 | |
---|
93 | public void setId(String id) { |
---|
94 | legend_.setId(id); |
---|
95 | } |
---|
96 | |
---|
97 | public void stateChanged(ChangeEvent e) { |
---|
98 | update("LegendDragBox.stateChanged()"); |
---|
99 | } |
---|
100 | } |
---|