Package hec.gfx2d

Class G2dPanel

All Implemented Interfaces:
G2dPointerComponent, G2dToolbarListener, ObjectSelectionListener, ImageObserver, MenuContainer, Printable, Serializable, EventListener, Accessible, TimeZoneComponent, UnitsComponent
Direct Known Subclasses:
G2dBarPlot, HotPlotPanel

Copyright (C) 1997, 1998 Hydrologic Engineering Center, United States Army Corps of Engineers, All Rights Reserved HEC-Java NEXGEN Version 1.0beta The primary container for 2d graphic displays.
See Also:
  • Field Details

  • Constructor Details

    • G2dPanel

      public G2dPanel()
      Default Constructor
  • Method Details

    • registerPopupPlotCreator

      public static void registerPopupPlotCreator(PopupPlotCreator creator)
    • setPropertiesFactoryName

      public void setPropertiesFactoryName(String name)
    • getPopupPlotCreator

      public static PopupPlotCreator getPopupPlotCreator()
    • setDirty

      public void setDirty()
    • getAccessoryPanel

      public JComponent getAccessoryPanel()
    • setDeviceResolution

      public void setDeviceResolution(int dpi)
    • getDeviceResoultion

      public int getDeviceResoultion()
      Returns the resolution of the current device being drawn to. If
      Returns:
      int
    • createPopupPlot

      protected G2dDialog createPopupPlot()
      Opens the plot into a G2dDialog, if it is not already in one already.
      Returns:
    • addPopupWindow

      protected void addPopupWindow(G2dDialog dialog)
    • removeGlyph

      public void removeGlyph(G2dGlyph g)
    • showThumbnailPopupMenu

      public void showThumbnailPopupMenu(Component parent, int x, int y)
      Shows the popup menu for thumbnail plots that all the user to open the thumbnail plot into a full window plot.
      Parameters:
      parent -
      x - the x coordinate to show the menu
      y - the y coordinate to show the menu.
    • createThumbnailPopupMenu

      protected JPopupMenu createThumbnailPopupMenu()
    • addThumbnailMenuItems

      protected void addThumbnailMenuItems(Container c)
    • showPopupPlot

      public void showPopupPlot()
      Opens the plot into a G2dDialog, if it is not already in one already.
    • setIgnorePopupPlotEvents

      public void setIgnorePopupPlotEvents(boolean b)
    • ignorePopupPlotEvent

      public boolean ignorePopupPlotEvent()
    • getViewports

      public Viewport[] getViewports()
      Returns an array of viewports. If there are no viewports in the panel, and array of size 0 is returned.
      Returns:
      the array of viewports.
    • setTransferHandler

      public void setTransferHandler(TransferHandler transferHandler)
      Overrides:
      setTransferHandler in class JComponent
    • getViewportToolbar

      public ViewportToolbar getViewportToolbar()
    • isPaintEnabled

      public boolean isPaintEnabled()
      isPaintEnabled
      Returns:
      the returned boolean
    • setPaintEnabled

      public void setPaintEnabled(boolean b)
      setPaintEnabled
      Parameters:
      b - parameter for setPaintEnabled
    • addLegendToPosition

      protected void addLegendToPosition(LegendPanel legend, int position)
    • moveLegendToPosition

      public void moveLegendToPosition(int position)
      This method will move the legend from on position on the panel to another.
      Parameters:
      position - marks the legend position. The valid positions are G2dPanelProp.BOTTOM and G2dPanelProp.RIGHT. The LEFT and TOP values will positiong to RIGHT and BOTTOM respectively.
    • paintGfx

      public void paintGfx()
      paintGfx
    • print

      public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException
      Specified by:
      print in interface Printable
      Throws:
      PrinterException
    • print

      public int print(Graphics g, PageFormat pageFormat, int pageIndex, boolean useLocalPageFormat, PrintProperties printProperties) throws PrinterException
      Throws:
      PrinterException
    • getFontScl

      public double getFontScl()
    • resetFontScl

      public void resetFontScl()
    • setBounds

      public void setBounds(Rectangle rc)
      Overrides:
      setBounds in class Component
    • setBounds

      public void setBounds(int x, int y, int w, int h)
      Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height.
      Overrides:
      setBounds in class Component
      Parameters:
      x - the new x-coordinate of this component
      y - the new y-coordinate of this component
      w - the new width of this component
      h - the new height of this component
    • setSize

      public void setSize(Dimension dim)
      setSize
      Overrides:
      setSize in class Component
      Parameters:
      dim - parameter for setSize
    • setSize

      public void setSize(int w, int h)
      setSize
      Overrides:
      setSize in class Component
      Parameters:
      w - parameter for setSize
      h -
    • printStatus

      public void printStatus(String txt)
      printStatus
      Parameters:
      txt - parameter for printStatus
    • clearPanel

      public void clearPanel()
      Removes all scales, axis, and components
    • addScaleToTable

      public void addScaleToTable(String key, Scale scl)
      Simple assistant method that adds a scale to the table of existing scale. The scale can then be looked up via the key at any time.
      Parameters:
      key -
      scl -
    • getPlotLayout

      public PlotLayout getPlotLayout()
      Returns the plot layout used to construct this plot. If the plot was constructed using something other than PlotLayout than this will return null.
      Returns:
    • buildComponents

      public void buildComponents(PlotLayout plotLayout)
    • createScale

      protected Scale createScale(String scaleName)
    • buildDefaultComponents

      public void buildDefaultComponents()
      Creates a two pane 2D drawing area with axis tics and labels, scrollbars, title, and legend.
    • addLegendContainers

      public void addLegendContainers()
      Adds the legend containers to the panel.
    • getComponents

      public G2dComponent[] getComponents(Predicate<G2dComponent> p)
      Gets all the components in this container that satisfy the predicate

      Note: This method should be called under AWT tree lock.

      Parameters:
      p -
      Returns:
      an array of all the components in this container.
      See Also:
    • applyToAll

      public void applyToAll(Consumer<G2dComponent> c)
    • buildComponents

      public void buildComponents(List objvec)
      Creates a two pane 2D drawing area to display a set of G2dObjects with default colors
      Parameters:
      objvec -
    • buildComponents

      public void buildComponents(List objvec, boolean addToolbar, boolean addLegend)
    • buildComponents

      public void buildComponents(List objvec, List colorvec)
    • buildComponents

      public void buildComponents(List objvec, List colorvec, boolean addToolbar, boolean addLegend)
      Creates a two pane 2D drawing area to display a set of G2dObjects
      Parameters:
      addLegend -
    • createAxis

      protected Axis createAxis(int type, String name)
    • getPlotObjects

      public Vector getPlotObjects()
      Returns a vector of G2dObjects that are used in the plot by recursing over the viewports and querying them for their G2dObjects. If there are no objects then an empty vector is returned.
      Returns:
      a vector of G2dObjects.
    • getLinePropertyObjects

      public Vector getLinePropertyObjects()
      return a copy of the G2dLineProperties objects from all the viewports. This returns the G2dLineProperties object in the same order as getPlotObject() as long as the two methods are called with no changed to the plot layout between calls.
      Returns:
      a Vector of G2dLineProperties
    • getAllLinePropertyObjects

      public Vector getAllLinePropertyObjects()
    • getProperties

      public G2dPanelProp getProperties()
      getProperties
      Returns:
      the returned G2dPanelProp
    • getLegendLocation

      public int getLegendLocation()
      This returns an integer locations of the position of the legend
      Returns:
      and integer value, eiter G2dPanelProp.BOTTOM or G2dPanel.RIGHT.
    • resetProperties

      public void resetProperties(G2dPanelProp panelProperties)
      Resets the properties for the panel.It removes all currently visble glyphs, and all components and re-configures the panel according to the properties and then redraws the glyphs.
      Parameters:
      panelProperties -
    • configurePanel

      public void configurePanel(G2dPanelProp prop)
      configure the panel based on a G2dPanelProp object
      Parameters:
      prop -
    • getTitlePanel

      public G2dTitle getTitlePanel()
    • getTitle

      public String getTitle()
    • setTitle

      public void setTitle(String title)
    • setPlotObjects

      public void setPlotObjects(List plotvec)
      Set the plot objects with default line colors
      Parameters:
      plotvec -
    • setPlotObjects

      public void setPlotObjects(List plotvec, List colorvec)
      Set the plot objects with specific line colors
      Parameters:
      colorvec -
    • addPlotObject

      public void addPlotObject(G2dObject obj)
      addPlotObject
      Parameters:
      obj - parameter for addPlotObject
    • addPlotObject

      public void addPlotObject(G2dObject go, G2dLineProperties lineProp, boolean refreshComponents)
      addPlotObject
      Parameters:
      go - parameter for addPlotObject
      lineProp - line properties that describe the g2dobject passed in
      refreshComponents - if true the legend is refreshed.
    • plotTimeWindow

      public void plotTimeWindow(TimeWindowPlotData data)
    • zoomToAll

      public void zoomToAll()
      This method loops through all viewports zooming them so all data becomes visible.
    • buildPlotComponents

      public Viewport buildPlotComponents(int plotcol, int plotrow, double colwgt, double rowwgt, Axis[] x, Axis[] y, Scale[] vs, boolean[] showXtic, boolean[] showXlabel, boolean showXscroll, boolean[] showYtic, boolean[] showYlabel, boolean showYscroll)
      builds a viewport that is one row tall and one column long
      Returns:
    • createViewport

      protected Viewport createViewport()
    • buildPlotComponents

      public Viewport buildPlotComponents(int plotcol, int plotrow, double colwgt, double rowwgt, int colwth, int rowht, Axis[] x, Axis[] y, Scale[] vs, boolean[] showXtic, boolean[] showXlabel, boolean showXscroll, boolean[] showYtic, boolean[] showYlabel, boolean showYscroll)
      Constructs a viewport component and associated components
      Parameters:
      plotcol -
      plotrow -
      colwgt -
      rowwgt -
      colwth -
      rowht -
      x -
      y -
      vs -
      showXtic -
      showXlabel -
      showXscroll -
      showYtic -
      showYlabel -
      showYscroll -
      Returns:
    • getHorizontalViewportSpacing

      public int getHorizontalViewportSpacing()
      Returns the value used by the panels to determine the amount of space between the top and the bottom of viewports.If the value is -1 then the spacing is computed automatically based on font size.
      Returns:
    • setHorizontalViewportSpacing

      public void setHorizontalViewportSpacing(int pixelWidth)
      Sets the spacing in pixels between the top and bottom of viewports.If the value is -1 then the spacing is determined automatically by font size.
      Parameters:
      pixelWidth -
    • createDefaultMapTools

      public void createDefaultMapTools(ViewportToolbar tools)
      createDefaultMapTools
      Parameters:
      tools - parameter for createDefaultMapTools
    • addTool

      public JToggleButton addTool(ToolbarButtonProp bprop)
      public method for adding a plot tool and button
      Returns:
    • setViewportAxisLink

      public void setViewportAxisLink(Viewport view, Axis axis, int axisId)
    • getViewportAxis

      public Axis getViewportAxis(Viewport view, int axis)
      Returns the Axis for a given viewport.The axis can either be one of the master X-Y axis (X1 or Y1) or the slave axis (X2 or Y2). If the viewport does not exist or there is no label for the viewport then null is returned
      Returns:
    • getViewportAxisLabel

      public AxisLabel getViewportAxisLabel(Viewport view, int axisInt)
      Returns the Axis label for a given viewport.The axis label can either be one of the master X-Y axis (X1 or Y1) or the slave axis (X2 or Y2). If the viewport does not exist or there is no label for the viewport then null is returned
      Parameters:
      view -
      axisInt -
      Returns:
    • getViewportAxisLabelSpacer

      public G2dSpacer getViewportAxisLabelSpacer(Viewport view, int axis)
      Returns the Axis Label for a given viewport.The axis label can either be one of the master X-Y axis (X1 or Y1) or the slave axis (X2 or Y2).If the viewport does not exist or there is no label for the viewport then null is returned
      Parameters:
      view -
      Returns:
    • getViewportAxisTicsSpacer

      public G2dSpacer getViewportAxisTicsSpacer(Viewport view, int axis)
      Returns the Axis Spacer for a given viewport.The axis spacer can either be one of the master X-Y axis (X1 or Y1) or the slave axis (X2 or Y2).If the viewport does not exist or there is no label for the viewport then null is returned
      Parameters:
      view -
      Returns:
    • getViewportAxisTics

      public AxisTics getViewportAxisTics(Viewport view, int axis)
      Returns the Axis Tics for a given viewport.The axis tics can either be one of the master X-Y axis (X1 or Y1) or the slave axis (X2 or Y2). If the viewport does not exist or there is no label for the viewport then null is returned
      Returns:
    • getAxisLabel

      public AxisLabel getAxisLabel(int axis)
    • getAxisTics

      public AxisTics getAxisTics(int axis)
    • setLabelFontSizes

      public void setLabelFontSizes(int sz, int tiny, int min, int max)
      set the font sizes for the axis labels
      Parameters:
      max -
    • setTicFontSizes

      public void setTicFontSizes(int sz, int tiny, int min, int max)
      set the font sizes for the axis labels
      Parameters:
      max -
    • resetAllDataLimits

      public void resetAllDataLimits()
      reset scales on all viewports in panel
    • paintGfx

      public void paintGfx(Graphics g)
      Method that is repsonsible for paint the plot component on the panel. This is were all of the graphics drawing work is done, by looping over the components having them paint to there correct locations.
      Parameters:
      g - The graphics context to paint to
    • objectPopupMenu

      public boolean objectPopupMenu(LocalPt pt, int modifiers)
      Test to see if an object popupmenu can be handled at the given local point. If there is a popupmenu that can be shown then true is returned, otherwise false.
      Specified by:
      objectPopupMenu in interface G2dPointerComponent
      Parameters:
      pt - the point of where to put the popupMenu.
      modifiers - mouse modifiers that were recieved by the mouse adapter that may be usefull here.
      Returns:
      true if the popup menu is shown.
    • pointerOver

      public void pointerOver(LocalPt pt)
      pointerOver
      Specified by:
      pointerOver in interface G2dPointerComponent
      Parameters:
      pt - parameter for pointerOver
    • mouseDragged

      public boolean mouseDragged(LocalPt pt)
      Method called when the mouse is dragged.
      Parameters:
      pt - the new point of where the mouse was dragged to.
      Returns:
      true if the mouse dragged event was accepted and consumed otherwise false.
    • objectSelect

      public boolean objectSelect(LocalPt pt, int modifiers)
      objectSelect
      Specified by:
      objectSelect in interface G2dPointerComponent
      Parameters:
      pt - parameter for objectSelect
      modifiers - mouse modifiers that were recieved by the mouse adapter that may be usefull here.
      Returns:
      the returned boolean
    • objectSelectionChanged

      public void objectSelectionChanged(ObjectSelectionEvent e)
      Specified by:
      objectSelectionChanged in interface ObjectSelectionListener
    • addObjectSelectionListener

      public void addObjectSelectionListener(ObjectSelectionListener l)
    • removeObjectSelectionListener

      public void removeObjectSelectionListener(ObjectSelectionListener l)
    • fireObjectSelectionChanged

      protected void fireObjectSelectionChanged(ObjectSelectionEvent event)
      fireObjectSelectionChanged
      Parameters:
      event - parameter for fireObjectSelectionChanged
    • getMouseAdapter

      public G2dMouseAdapter getMouseAdapter()
      getMouseAdapter
      Specified by:
      getMouseAdapter in interface G2dToolbarListener
      Returns:
      the returned G2dMouseAdapter
    • setMouseAdapter

      public void setMouseAdapter(String className)
      Creates and makes current a mouse adapter according to the given class name.
      Specified by:
      setMouseAdapter in interface G2dToolbarListener
      Parameters:
      className -
    • createDefaultMouseAdapter

      protected G2dMouseAdapter createDefaultMouseAdapter()
      Returns:
    • setMouseAdapter

      public G2dMouseAdapter setMouseAdapter(G2dMouseAdapter adapter)
      Set the active mouse adapter for the canvas.
      Specified by:
      setMouseAdapter in interface G2dToolbarListener
      Returns:
    • setDisplayUnitsSystem

      public void setDisplayUnitsSystem(int units)
      Description copied from interface: UnitsComponent
      Sets the current Unit System for this object
      Specified by:
      setDisplayUnitsSystem in interface UnitsComponent
    • setDisplayScaleFactor

      public void setDisplayScaleFactor(int paramId, double scaleFactor)
      Sets a scaling factor for a particular id.If any of the data used that parameter id it will be scaled accordingly.
      Specified by:
      setDisplayScaleFactor in interface UnitsComponent
      Parameters:
      paramId -
      scaleFactor -
    • getDisplayUnitsString

      public String getDisplayUnitsString(int v)
      Description copied from interface: UnitsComponent
      This method allows the retrieves the units string for a given units system
      Specified by:
      getDisplayUnitsString in interface UnitsComponent
      See Also:
    • setTimeZone

      public void setTimeZone(TimeZone tz)
      Description copied from interface: TimeZoneComponent
      Sets the time zone that this component will use to display date and time.
      Specified by:
      setTimeZone in interface TimeZoneComponent
      Parameters:
      tz - The time zone to use for display purposes
    • getTimeZone

      public TimeZone getTimeZone()
      Description copied from interface: TimeZoneComponent
      Gets the Time Zone that this component is using to display a date and time.
      Specified by:
      getTimeZone in interface TimeZoneComponent
      Returns:
      java.util.TimeZone
    • getSelectedToolbarButton

      public int getSelectedToolbarButton()
      public access to toolbar button selection
      Returns:
    • setSelectedToolbarButton

      public void setSelectedToolbarButton(int selected)
    • addFocusListener

      public void addFocusListener(FocusListener fl)
      Overrides:
      addFocusListener in class Component
    • removeFocusListener

      public void removeFocusListener(FocusListener fl)
      Overrides:
      removeFocusListener in class Component
    • isFocusTraversable

      public boolean isFocusTraversable()
      Overrides:
      isFocusTraversable in class Component
    • useLineStyles

      public void useLineStyles(boolean useStyles)
    • getScales

      public Scale[] getScales()
    • getViewportVector

      public Vector getViewportVector()
      get the Vector of Viewports
      Returns:
      the Viewport Vector.
    • getLineColors

      public static Color[] getLineColors()
    • getFillColors

      public static Color[] getFillColors()
    • getLegendPanel

      public LegendPanel getLegendPanel()
    • setLegendVisible

      public void setLegendVisible(boolean b)
    • isLegendVisible

      public boolean isLegendVisible()
    • setLegendPanel

      public void setLegendPanel(LegendPanel panel)
    • createDefaultToolbarProperties

      public static ViewportToolbarProp createDefaultToolbarProperties()
    • showStatistics

      public void showStatistics(boolean stats)
    • isShowingStatistics

      public boolean isShowingStatistics()
    • hasStatistics

      public boolean hasStatistics()