Class TLcyPrintableComponentFactory


public class TLcyPrintableComponentFactory extends ALcyPrintableComponentFactory
Factory for the creation of printable java.awt.Components. This factory was designed so that it is easy to modify small parts of the creation process. This can be done by subclassing this class and overriding certain methods.

The main create function createPrintableComponent( ILcyMapComponent, TLcyProperties ) will first create all usable parts, eg. the map view, the header text, the scale icon,... using the functions createGXYView(id) and createComponent(id). Then it calls createPrintableComponentContent(), which will create the content of the printable component using the created objects by calling getGXYView(id) and getComponent(id). And finally it will create the actual TLcyGXYViewPrintableComponent.

Note however that we use ID's. This is because there are different types of components that can be created: the legend, the scale icon, the footer/header text,... All possible ID's that can be passed to the createComponent method all end with the same suffix "component". The same thing goes for "gxyview" (createGXYView, getGXYView).

As an example, imagine you want to change the behaviour of the footer text. Browsing this class learns there is a FOOTER_TEXT_COMPONENT constant. Because it ends with "component", this constant can only be passed to the createComponent method. Therefore we can override the method createComponent, check if the ID is FOOTER_TEXT_COMPONENT and return a custom component instance. Or use super.createComponent and change some settings before returning it. If you want to remove the component completely, you can simply return null.

The method createPrintableComponent(ILcyMapComponent, TLcyProperties) should not be overridden without using the super function. Changing the layout of the TLcyGXYViewPrintableComponent can be done by overriding createPrintableComponentContent(). The internal elements are already created and should be retrieved by calling getGXYView(id) and getComponent(id).

  • Field Details

    • MAIN_GXYVIEW

      public static final int MAIN_GXYVIEW
      The id for creating the gxyview of the current map component. For this ID, it is not allowed to return null.
      See Also:
    • OVERVIEW_GXYVIEW

      public static final int OVERVIEW_GXYVIEW
      The id for creating the gxyview of the current map overview component.
      See Also:
    • LEGEND_COMPONENT

      public static final int LEGEND_COMPONENT
      The id for creating the legend component.

      When creating custom legends, it might be useful to use TLcyPrintAddOn.getPrintAreaGXYLayerFilter()

      See Also:
    • SCALE_ICON_COMPONENT

      public static final int SCALE_ICON_COMPONENT
      The id for creating the scale icon component.
      See Also:
    • SCALE_LABEL_COMPONENT

      public static final int SCALE_LABEL_COMPONENT
      The id for creating the scale indication component.
      See Also:
    • HEADER_TEXT_COMPONENT

      public static final int HEADER_TEXT_COMPONENT
      The id for creating the header text component.
      See Also:
    • TITLE_TEXT_COMPONENT

      public static final int TITLE_TEXT_COMPONENT
      The id for creating the title text component.
      See Also:
    • MODIFIABLE_HEADER_TEXT_COMPONENT

      public static final int MODIFIABLE_HEADER_TEXT_COMPONENT
      The id for creating the header text component which can be altered by the user in the UI.
      Since:
      2016.1.1
      See Also:
    • CLASSIFICATION_COMPONENT

      public static final int CLASSIFICATION_COMPONENT
      The id for creating the classification component
      Since:
      2016.1.1
      See Also:
  • Constructor Details

    • TLcyPrintableComponentFactory

      public TLcyPrintableComponentFactory()
      Default constructor. Creates a new TLcyPrintableComponentFactory. Note that you will have to set an ILcyLucyEnv before this instance can be used.
    • TLcyPrintableComponentFactory

      public TLcyPrintableComponentFactory(ILcyLucyEnv aLucyEnv)
      Creates a new TLcyPrintableComponentFactory.
      Parameters:
      aLucyEnv - The lucy environment, contextual information.
  • Method Details

    • getLucyEnv

      public ILcyLucyEnv getLucyEnv()
      Description copied from class: ALcyPrintableMapComponentFactory
      Returns the associated lucy environment.
      Specified by:
      getLucyEnv in class ALcyPrintableMapComponentFactory<ILcyMapComponent>
      Returns:
      the associated lucy environment.
      See Also:
    • setLucyEnv

      public void setLucyEnv(ILcyLucyEnv aLucyEnv)
      Description copied from class: ALcyPrintableMapComponentFactory
      Sets the associated lucy environment.
      Specified by:
      setLucyEnv in class ALcyPrintableMapComponentFactory<ILcyMapComponent>
      Parameters:
      aLucyEnv - The lucy environment.
      See Also:
    • createPrintableComponent

      public TLcyGXYViewPrintableComponent createPrintableComponent(ILcyMapComponent aMapComponent, TLcyProperties aProperties)
      This function will first create all internal components using createGXYView and createComponent. Then it calls createPrintableComponentContent, which will create the content of the printable component using the internal components by calling getGXYView and getComponent. And finally it will create the actual TLcyGXYViewPrintableComponent.

      Warning: Should not be overridden without calling the super function.

      Specified by:
      createPrintableComponent in class ALcyPrintableComponentFactory
      Parameters:
      aMapComponent - The map component to use.
      aProperties - The property node to use.
      Returns:
      the created printable component.
    • createPrintableComponentContent

      protected Component createPrintableComponentContent(ILcyMapComponent aMapComponent, TLcyProperties aProperties)
      Creates the content of the TLcyGXYViewPrintableComponent. The methods getGXYView(id) and getComponent(id) are used to safely retrieve the previously created objects. The retrieved components are layed out in for example a javax.swing.JPanel. This function should be overridden when you want to change the layout of the TLcyGXYViewPrintableComponent.

      If you would like to put components on the map (for example a legend), a JLayeredPane can be useful to overlay them.

      Parameters:
      aMapComponent - The map component to use.
      aProperties - The property node to use.
      Returns:
      the created content.
    • createGXYView

      protected ILcdGXYView createGXYView(int aID, ILcyMapComponent aMapComponent, TLcyProperties aProperties)
      Creates an ILcdGXYView for the given ID. This ILcdGXYView is assumed to be an instance of java.awt.Component (or one of its subclasses).

      The return value for the MAIN_GXYVIEW constant must not be null.

      By default, it returns a view for the MAIN_GXYVIEW constant where the invisible layers are no longer part of (so that they, for example, don't appear in the legend). Subclasses can overwrite this method and for example do add the invisible layers or add extra layers.

      Note: it is important that the returned ILcdGXYView instance is not part of any existing user interface, because its properties (scale, size, ...) might be modified during the print (preview) process. It is also important that the returned ILcdGXYView has correct initial values for scale, size, ... as these could for example be used to find the initial visible area.

      Parameters:
      aID - The id describing which gxyview to create. This is a constant that ends in GXYVIEW.
      aMapComponent - The map component to use.
      aProperties - The property node to use.
      Returns:
      The newly created ILcdGXYView, or null. Null is however not returned for the MAIN_GXYVIEW constant.
    • getGXYView

      protected ILcdGXYView getGXYView(int aID)
      Returns the ILcdGXYView for the given ID.
      Parameters:
      aID - The id describing which gxyview to create. This is a constant that ends in GXYVIEW.
      Returns:
      the ILcdGXYView for the given ID.
    • createComponent

      protected Component createComponent(int aID, ILcyMapComponent aMapComponent, TLcyProperties aProperties)
      Creates a java.awt.Component for the given ID.

      The map component is provided as contextual information, and could for example be used to build a legend.

      The properties can be used to tweak the component creation. For example when the legend is created (see LEGEND_COMPONENT), null is returned if the value of TLcyPrintAddOn.LEGEND_VISIBLE_KEY is false. If the value of TLcyPrintAddOn.LEGEND_SELECTED_KEY changes (even after the component is returned), the legend will toggle its visibility. One can detect changes in the given aProperties by using ALcyProperties.addPropertyChangeListener(java.beans.PropertyChangeListener).

      Parameters:
      aID - The id describing which component to create. This is a constant that ends in COMPONENT.
      aMapComponent - The map component, provided as contextual information.
      aProperties - The property node.
      Returns:
      The newly created java.awt.Component, or null.
    • getComponent

      protected Component getComponent(int aID)
      Returns the java.awt.Component for the given ID.
      Parameters:
      aID - The id describing which component to create. This is a constant that ends in COMPONENT.
      Returns:
      the java.awt.Component for the given ID.