source: ether_statistics/service/implementation/gov/noaa/pmel/sgt/beans/PanelHolderDragBox.java @ 569

Last change on this file since 569 was 569, checked in by vmipsl, 12 years ago

Nouveau projet

File size: 6.2 KB
Line 
1/*
2 * $Id: PanelHolderDragBox.java,v 1.4 2003/09/16 22:02:14 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
13package gov.noaa.pmel.sgt.beans;
14
15import java.awt.Component;
16import java.awt.Graphics;
17import java.awt.Rectangle;
18import java.awt.Point;
19import java.awt.Color;
20import java.awt.Insets;
21
22import java.util.Iterator;
23import java.util.List;
24import java.util.Vector;
25
26import gov.noaa.pmel.sgt.SGLabel;
27import javax.swing.event.ChangeEvent;
28import javax.swing.event.ChangeListener;
29
30/**
31 * @author Donald Denbo
32 * @version $Revision: 1.4 $, $Date: 2003/09/16 22:02:14 $
33 * @since 3.0
34 **/
35class PanelHolderDragBox extends DragBox implements ChangeListener {
36  private List dragBox_ = new Vector();
37  private boolean ignoreStateChange_ = false;
38
39  public PanelHolderDragBox(PanelHolder ph) {
40    super(ph);
41//    ph.setPanelDragBox(this);
42    ignoreStateChange_ = true;
43    pHolder_.addChangeListener(this);
44    Iterator iter = pHolder_.dataGroupIterator();
45    while(iter.hasNext()) {
46      DataGroup dg = (DataGroup)iter.next();
47      DataGroupDragBox agdb = new DataGroupDragBox(dg, pHolder_);
48      AxisHolderDragBox xAxdb = new AxisHolderDragBox(dg.getXAxisHolder(), dg, pHolder_);
49      AxisHolderDragBox yAxdb = new AxisHolderDragBox(dg.getYAxisHolder(), dg, pHolder_);
50      dragBox_.add(xAxdb);
51      dragBox_.add(yAxdb);
52      dragBox_.add(agdb);
53    }
54    iter = pHolder_.labelIterator();
55    while(iter.hasNext()) {
56      LabelDragBox ldb = new LabelDragBox((Label)iter.next(),  pHolder_);
57      dragBox_.add(ldb);
58    }
59    iter = pHolder_.legendIterator();
60    while(iter.hasNext()) {
61      LegendDragBox lgdb = new LegendDragBox((Legend)iter.next(), pHolder_);
62      dragBox_.add(lgdb);
63    }
64
65    for(int i=0; i < handles_.length;  i++) {
66      handles_[i] = new Rectangle(0,0,0,0);
67    }
68    ignoreStateChange_ = false;
69    computeHandles();
70  }
71
72  public PanelHolder getPanelHolder() {
73    return pHolder_;
74  }
75
76  public DragBox[] getDragBoxArray() {
77    DragBox[] dba = new DragBox[1];
78    return (DragBox[])dragBox_.toArray(dba);
79  }
80
81  public Iterator getDragBoxIterator() {
82    return dragBox_.iterator();
83  }
84
85  public void setSelected(boolean sel) {
86    super.setSelected(sel);
87    if(!selected_) {
88      Iterator iter = dragBox_.iterator();
89      while(iter.hasNext()) {
90        ((DragBox)iter.next()).setSelected(sel);
91      }
92    }
93  }
94
95  public void update(String message) {
96//    if(Page.DEBUG) System.out.println("PanelDragBox.update(" + message + ")");
97    computeHandles();
98    Iterator iter = dragBox_.iterator();
99    while(iter.hasNext()) {
100      ((DragBox)iter.next()).update(message);
101    }
102  }
103
104  public void draw(Graphics g) {
105    Color saved = g.getColor();
106    Rectangle bounds = pHolder_.getBounds();
107    if(!pHolder_.isUsePageBackground()) {
108      g.setColor(pHolder_.getBackground());
109      g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
110    }
111    g.setColor(Color.darkGray);
112    g.drawString(pHolder_.getId(), bounds.x + 10, bounds.y + 12);
113    g.drawString("["+bounds.width+"x"+bounds.height+"]",
114                 bounds.x + 10, bounds.y + 22);
115    g.setColor(color_);
116    if(pHolder_.isVisible()) g.drawRect(bounds.x, bounds.y, bounds.width-1, bounds.height-1);
117    if(selected_) {
118      for(int i=0; i < handles_.length; i++) {
119        Rectangle r = handles_[i];
120        g.fillRect(r.x, r.y, r.width-1, r.height-1);
121      }
122    }
123
124    if(pHolder_.isVisible()) {
125      Iterator iter = dragBox_.iterator();
126      while(iter.hasNext()) {
127        ((DragBox)iter.next()).draw(g);
128      }
129    }
130
131    g.setColor(saved);
132  }
133
134  public String getId() {
135    return pHolder_.getId();
136  }
137
138  public void setId(String id) {
139    pHolder_.setId(id);
140  }
141
142  public void setBounds(Rectangle bounds) {
143    ignoreStateChange_ = true;
144    pHolder_.setBounds(bounds);
145    update("PanelDragBox.setBounds()");
146    ignoreStateChange_ = false;
147  }
148
149  public Rectangle getBounds() {
150    return pHolder_.getBounds();
151  }
152
153  public void setLocation(Point pt) {
154    setLocation(pt.x, pt.y);
155  }
156
157  public void setLocation(int x, int y) {
158    Rectangle bounds = pHolder_.getBounds();
159    bounds.x = x;
160    bounds.y = y;
161    ignoreStateChange_ = true;
162    pHolder_.setBounds(bounds);
163    update("PanelDragBox.setLocation()");
164    ignoreStateChange_ = false;
165  }
166
167  public Point getLocation() {
168    Rectangle bounds = pHolder_.getBounds();
169    return new Point(bounds.x, bounds.y);
170  }
171
172  public void addDragBox(DataGroup ag) {
173    DataGroupDragBox agdb = new DataGroupDragBox(ag, pHolder_);
174    AxisHolderDragBox xAxdb = new AxisHolderDragBox(ag.getXAxisHolder(), ag, pHolder_);
175    AxisHolderDragBox yAxdb = new AxisHolderDragBox(ag.getYAxisHolder(), ag, pHolder_);
176    agdb.setAxisHolderDB(xAxdb, yAxdb);
177    dragBox_.add(xAxdb);
178    dragBox_.add(yAxdb);
179    dragBox_.add(agdb);
180  }
181
182  public void addDragBox(Legend legend) {
183    LegendDragBox ldb = new LegendDragBox(legend, pHolder_);
184    dragBox_.add(ldb);
185  }
186
187  public void addDragBox(Label label) {
188    LabelDragBox lbdb = new LabelDragBox(label, pHolder_);
189    dragBox_.add(lbdb);
190  }
191
192  public void removeDragBox(DataGroupDragBox ag) {
193    dragBox_.remove(ag.getXAxisHolderDB());
194    dragBox_.remove(ag.getYAxisHolderDB());
195    dragBox_.remove(ag);
196    update("PanelDragBox.removeDragBox(DataGroupDragBox)");
197  }
198
199  public void removeDragBox(LegendDragBox legend) {
200    dragBox_.remove(legend);
201    update("PanelDragBox.removeDragBox(LegendDragBox)");
202  }
203
204  public void removeDragBox(LabelDragBox label) {
205    dragBox_.remove(label);
206    update("PanelDragBox.removeDragBox(LabelDragBox)");
207  }
208
209  public void stateChanged(ChangeEvent e) {
210    if(ignoreStateChange_) return;
211    update("PanelDragBox.stateChanged");
212/*    System.out.println("PanelDragBox.stateChanged(" +
213                       e.getSource().getClass().getName() + ")"); */
214  }
215}
Note: See TracBrowser for help on using the repository browser.