/* * $Id: PanelHolder.java,v 1.4 2003/08/27 23:29:40 dwd Exp $ * * This software is provided by NOAA for full, free and open release. It is * understood by the recipient/user that NOAA assumes no liability for any * errors contained in the code. Although this software is released without * conditions or restrictions in its use, it is expected that appropriate * credit be given to its author and to the National Oceanic and Atmospheric * Administration should the software be included by the recipient as an * element in other product development. */ package sgtplot.beans; import java.awt.Rectangle; import java.awt.Color; import javax.swing.event.*; import javax.swing.border.Border; import javax.swing.border.LineBorder; import java.util.*; import java.io.*; import java.beans.*; /** * Object to hold all the objects necessary to describe aLabels. * @return Map */ public Map getLabels() { return labels_; } /** * SetPanel. * Associated objects includeLabel,DataGroup, and *Legend. * * @author Donald Denbo * @version $Revision: 1.4 $, $Date: 2003/08/27 23:29:40 $ * @since 3.0 * @see Label * @see Panel * @see PanelModel PanelModel for UML diagram * @see DataGroup * @see Legend **/ public class PanelHolder implements ChangeListener, Serializable { private String id = ""; private Rectangle bounds = new Rectangle(0, 0, 100, 50); /** @link aggregation * @supplierCardinality * * @label labels */ /*#Label lnkLabel; */ private Map labels_ = new HashMap(5); /** @link aggregation * @supplierCardinality 1..* * @label dataGroups */ /*#DataGroup lnkDataGroup; */ private Map dataGroups_ = new HashMap(2); /** @link aggregation * @supplierCardinality * * @label legends */ /*#Legend lnkLegend; */ private Map legends_ = new HashMap(1); /** * @label pModel */ transient private PanelModel pModel_ = null; transient private ChangeEvent changeEvent_ = new ChangeEvent(this); transient private Vector changeListeners; private boolean visible = true; transient private boolean instantiated = false; private Border border = new LineBorder(Color.gray, 2); private Color background = Color.white; private boolean usePageBackground = true; static { try { BeanInfo info = Introspector.getBeanInfo(PanelHolder.class); PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); for(int i=0; i < descriptors.length; i++) { PropertyDescriptor pd = descriptors[i]; if(pd.getName().equals("instantiated")) { pd.setValue("transient", Boolean.TRUE); } else if(pd.getName().equals("panelModel")) { pd.setValue("transient", Boolean.TRUE); } } } catch (IntrospectionException ie) { ie.printStackTrace(); } } /** * Default constructor. SetsPanelHolderidentifier and *PanelModelparent tonull. */ public PanelHolder() { this(null, null); } /** *PanelHolderconstructor. * @param id PanelHolder identifier * @param pModel PanelModel parent */ public PanelHolder(String id, PanelModel pModel) { this.id = id; pModel_ = pModel; } /** *PanelHolderconstructor. This constructor has arguments to * passMaps ofLabel,DataGroup, and *Legendobjects. TheMapkey is the objects identifier. * @param id PanelHolder identifier * @param pModel PanelModel parent * @param bounds bounds * @param labels Map containing Labels * @param dataGroups Map containing DataGroups * @param legends Map contiaining Legends */ public PanelHolder(String id, PanelModel pModel, Rectangle bounds, Map labels, Map dataGroups, Map legends) { this.id = id; pModel_ = pModel; this.bounds = bounds; if(labels != null) { labels_ = new HashMap(labels); } if(dataGroups != null) { dataGroups_ = new HashMap(dataGroups); } if(legends != null) { legends_ = new HashMap(legends); } } /** * Set thePanelModelparent. * @param pModel PanelModel */ public void setPanelModel(PanelModel pModel) { if(pModel_ != null) removeChangeListener(pModel_); pModel_ = pModel; addChangeListener(pModel_); } /** * Get thePanelModel. * @return PanelModel */ public PanelModel getPanelModel() { return pModel_; } /** * AddLabelto thePanelHolder. * @param label Label */ public void addLabel(Label label) { label.addChangeListener(this); label.setPanelHolder(this); labels_.put(label.getId(), label); fireStateChanged(); } /** * RemoveLabelfrom thePanelHolder. * @param label Label */ public void removeLabel(Label label) { label.removeAllChangeListeners(); labels_.remove(label.getId()); fireStateChanged(); } /** * AddDataGroupto thePanelHolder. * @param dataGroup DataGroup */ public void addDataGroup(DataGroup dataGroup) { dataGroup.addChangeListener(this); dataGroups_.put(dataGroup.getId(), dataGroup); fireStateChanged(); } /** * RemoveDataGroupfrom thePanelHolder. * @param dataGroup DataGroup */ public void removeDataGroup(DataGroup dataGroup) { dataGroup.removeAllChangeListeners(); dataGroup.getXAxisHolder().removeAllChangeListeners(); dataGroup.getYAxisHolder().removeAllChangeListeners(); dataGroups_.remove(dataGroup.getId()); fireStateChanged(); } /** * AddLegendto thePanelHolder. * @param legend Legend */ public void addLegend(Legend legend) { legend.addChangeListener(this); legend.setPanelHolder(this); legends_.put(legend.getId(), legend); fireStateChanged(); } /** * RemoveLegendfrom thePanelHolder. * @param legend Legend */ public void removeLegend(Legend legend) { legend.removeAllChangeListeners(); legends_.remove(legend.getId()); fireStateChanged(); } /** * SetPanelHolderidentifier. * @param id identifier */ public void setId(String id) { String old = this.id; this.id = id; if(old == null || !old.equals(this.id)) fireStateChanged(); } /** * GetPanelHolderidentifier * @return identifier */ public String getId() { return id; } /** * Get number ofLabelobjects inMap. * @return number of Labels */ public int getLabelSize() { return labels_.size(); } /** * Get number ofDataGroupobjects inMap. * @return number of DataGroups */ public int getDataGroupSize() { return dataGroups_.size(); } /** * Get number ofLegendobjects inMap. * @return number of Legends */ public int getLegendSize() { return legends_.size(); } /** * Get anIteratorofLabelobjects. * @return Iterator */ public Iterator labelIterator() { return labels_.values().iterator(); } /** * Get anIteratorofDataGroupobjects. * @return Iterator */ public Iterator dataGroupIterator() { return dataGroups_.values().iterator(); } /** * Get anIteratorofLegendobjects. * @return Iterator */ public Iterator legendIterator() { return legends_.values().iterator(); } /** * Set bounds ofPanel. * @param bounds bounds */ public void setBounds(Rectangle bounds) { Rectangle old = this.bounds; this.bounds = bounds; fireStateChanged(); } /** * Get bounds ofPanel. * @return bounds */ public Rectangle getBounds() { return bounds; /** @todo bounds isn't cloned should be see note */ // return (Rectangle)bounds.clone(); // the clone didn't work with XMLEncoder for some reason } /** * Remove allChangeListeners. */ public void removeAllChangeListeners() { changeListeners = null; } /** *ChangeListnercallback. * @param e ChangeEvent */ public void stateChanged(ChangeEvent e) { if (changeListeners != null) { Vector listeners = changeListeners; int count = listeners.size(); for (int i = 0; i < count; i++) { ((ChangeListener) listeners.elementAt(i)).stateChanged(e); } } } /** * Remove changelistener. * @param l changelistener */ public synchronized void removeChangeListener(ChangeListener l) { if (changeListeners != null && changeListeners.contains(l)) { Vector v = (Vector) changeListeners.clone(); v.removeElement(l); changeListeners = v; } } /** * Add changelistener * @param l changelistener */ public synchronized void addChangeListener(ChangeListener l) { Vector v = changeListeners == null ? new Vector(2) : (Vector) changeListeners.clone(); if (!v.contains(l)) { v.addElement(l); changeListeners = v; } } /** * Remove allChangeListeners that implement the *DesignListenerinterface. * * @see DesignListener */ public synchronized void removeDesignChangeListeners() { if(changeListeners != null) { Vector v = (Vector) changeListeners.clone(); Iterator iter = v.iterator(); while(iter.hasNext()) { Object obj = iter.next(); if(obj instanceof DesignListener) changeListeners.removeElement(obj); } } } protected void fireStateChanged() { if (changeListeners != null) { Vector listeners = changeListeners; int count = listeners.size(); for (int i = 0; i < count; i++) { ((ChangeListener) listeners.elementAt(i)).stateChanged(changeEvent_); } } } /** * SetPanelvisible. * @param visible true if visible */ public void setVisible(boolean visible) { boolean saved = this.visible; this.visible = visible; if(saved != this.visible) fireStateChanged(); } /** * IsPanelvisible? * @return true, if Panel is visible */ public boolean isVisible() { return visible; } /** * Set instantiated. Once associatedPanelobject has been created * this property is set true. Used internally. * @param instantiated true if instantiated */ public void setInstantiated(boolean instantiated) { this.instantiated = instantiated; } /** * Is panel instantiated? * @return true, if Panel instantiated */ public boolean isInstantiated() { return instantiated; } /** * Find aDataGroupby identifier. * @param id identifier * @return DataGroup */ public DataGroup findDataGroup(String id) { return (DataGroup)dataGroups_.get(id); } /** * FindLabelby identifier. * @param id identifier * @return Label */ public Label findLabel(String id) { return (Label)labels_.get(id); } /** * FindLegendby identifier. * @param id identifier * @return Legend */ public Legend findLegend(String id) { return (Legend)legends_.get(id); } /** * DoesPanelHoldercontainDataGroup? * @param id DataGroup identifier * @return true, if DataGroup exists */ public boolean hasDataGroup(String id) { return dataGroups_.containsKey(id); } /** * DoesPanelHoldercontainLabel? * @param id Label identifier * @return Label */ public boolean hasLabel(String id) { return labels_.containsKey(id); } /** * DoesPanelHoldercontainLegend? * @param id Legend identifier * @return Legend */ public boolean hasLegend(String id) { return legends_.containsKey(id); } /** * ReturnBorderforPanel. * @return Border */ public Border getBorder() { return border; } /** * SetBorderforPanel. Default = LineBorder(gray, 2) * @param border Border */ public void setBorder(Border border) { Border saved = this.border; this.border = border; if(saved == null || !saved.equals(this.border)) fireStateChanged(); } /** * GetMapofMapof Labels. Key inMapcontains *Labelidentifier. * @param labels Label Map */ public void setLabels(Map labels) { labels_ = labels; Iterator iter = labelIterator(); while(iter.hasNext()) { ((Label)iter.next()).addChangeListener(this); } fireStateChanged(); } /** * GetMapcontainingLegends. * @return Map */ public Map getLegends() { return legends_; } /** * SetMapof Legends. Key inMapcontains *Legendidentifier. * @param legends Legend Map */ public void setLegends(Map legends) { legends_ = legends; Iterator iter = legendIterator(); while(iter.hasNext()) { ((Legend)iter.next()).addChangeListener(this); } fireStateChanged(); } /** * GetMapcontainingDataGroups. * @return Map */ public Map getDataGroups() { return dataGroups_; } /** * SetMapof DataGroups. Key inMapcontains *DataGroupidentifier. * @param dataGroups DataGroup Map */ public void setDataGroups(Map dataGroups) { dataGroups_ = dataGroups; Iterator iter = dataGroupIterator(); while(iter.hasNext()) { ((DataGroup)iter.next()).addChangeListener(this); } fireStateChanged(); } /** * Get background color. Will use the page background if usePageBackground property * is true. * @return color */ public Color getBackground() { return background; } /** * Set thePanelbackground color. * @param background color */ public void setBackground(Color background) { Color saved = this.background; this.background = background; if(!saved.equals(this.background)) fireStateChanged(); } /** * Use the page background color? * @return true if using page background color */ public boolean isUsePageBackground() { return usePageBackground; } /** * Set thePanelto use thePagebackground color. * @param pageBackground true to use page background color */ public void setUsePageBackground(boolean pageBackground) { boolean saved = this.usePageBackground; this.usePageBackground = pageBackground; if(saved != this.usePageBackground) fireStateChanged(); } }
Ads help maintain this website.