Class RMViewer

All Implemented Interfaces:
RMDocument.DocListener, ImageObserver, MenuContainer, Serializable
Direct Known Subclasses:
Gallery.GViewer, RMEditor, RMTrackballControl, Scene3DTool.Scene3DControl

public class RMViewer extends JComponent implements RMDocument.DocListener
The RMViewer class is a JComponent subclass that can be used in Swing applications to display and/or print an RMDocument.

You might use it like this to simply print a document:

 new RMViewer(aDocument).print();
 

Or you might want to allocate one and add it to a Swing component hierarchy:

 RMViewer viewer = new RMViewer();
 JScrollPane scrollPane = new JScrollPane(viewer);
 myFrame.getContentPane().add(scrollPane, Border.CENTER);
 viewer.setDocument(new RMDocument(aSource));
 

See Also:
  • Field Details

    • GridColor

      public static Color GridColor
    • MarginColor

      public static Color MarginColor
  • Constructor Details

    • RMViewer

      public RMViewer()
      Creates a new RMViewer with an empty document in it.
    • RMViewer

      public RMViewer(Object aSource)
      Creates a new RMViewer from the given source. aSource is used to get an RMDocument and can be many different things: String file path, File object, InputStream, byte array, URL or even an RMDocument.
  • Method Details

    • getPrintingMode

      public int getPrintingMode()
    • setPrintingMode

      public void setPrintingMode(int printingMode)
    • getPrintingDPI

      public int getPrintingDPI()
    • setPrintingDPI

      public void setPrintingDPI(int printingDPI)
    • getDocument

      public RMDocument getDocument()
      Returns the RMDocument associated with this viewer.
    • setDocument

      public void setDocument(RMDocument aDoc)
      Sets the RMDocument associated with this viewer.
    • getSelectedPage

      public RMShape getSelectedPage()
      Returns the currently selected page shape.
    • getFilename

      public String getFilename()
      Returns filename associated with viewer's document (or null if the document didn't come from a file).
    • getPageLayout

      public byte getPageLayout()
      Returns the page layout of the viewer's document.
    • getSelectedPageIndex

      public int getSelectedPageIndex()
      Returns the index of the current visiable document page.
    • setSelectedPageIndex

      public void setSelectedPageIndex(int anIndex)
      Sets the page of viewer's document that is visible (by index).
    • pageForward

      public void pageForward()
      Selects the next page.
    • pageBack

      public void pageBack()
      Selects the previous page.
    • getDocumentBounds

      public RMRect getDocumentBounds()
      Returns the bounds of the viewer document.
    • getPageBounds

      public RMRect getPageBounds()
      Returns the bounds of the viewer document's selected page.
    • getShapeAtPoint

      public RMShape getShapeAtPoint(Point2D aPoint, boolean goDeep)
      Returns the first shape hit by the given point.
    • getZoomFactor

      public float getZoomFactor()
      Returns the viewer's zoom factor (1 by default).
    • setZoomFactor

      public void setZoomFactor(float aFactor)
      Sets the viewer's zoom factor (1 for 100%).
    • setZoomForScreenResolution

      public void setZoomForScreenResolution()
      Sets the viewer's zoom to match the current screen resolution
    • zoomToggleLast

      public void zoomToggleLast()
      Sets the viewer's zoom to its previous value.
    • runZoomPanel

      public void runZoomPanel()
      Runs a dialog panel to request a percentage zoom (which is then set with setZoomFactor).
    • convertPointFromShape

      public RMPoint convertPointFromShape(RMPoint aPoint, RMShape aShape)
      Returns a point converted from the coordinate space of the given shape to viewer coords.
    • convertPointToShape

      public RMPoint convertPointToShape(Point2D aPoint, RMShape aShape)
      Returns a point converted from viewer coords to the coordinate space of the given shape.
    • convertRectFromShape

      public RMRect convertRectFromShape(RMRect aRect, RMShape aShape)
      Returns a rect converted from the coordinate space of the given shape to viewer coords.
    • convertRectToShape

      public RMRect convertRectToShape(RMRect aRect, RMShape aShape)
      Returns a rect converted from viewer coords to the coordinate space of the given shape.
    • getTransformFromShape

      public AffineTransform getTransformFromShape(RMShape aShape)
      Returns the transform from given shape to viewer.
    • repaint

      public void repaint(RMRect aRect)
      Requests a repaint for the area represented by the given rect.
    • getShapePainter

      public RMShapePainter getShapePainter()
      Returns the object that is actually responsible for paining shapes in the viewer.
    • setShapePainter

      public void setShapePainter(RMShapePainter aPainter)
      Sets the object that is actually responsible for paining shapes in the viewer.
    • getRenderingHints

      public RenderingHints getRenderingHints()
      Returns the rendering hings used to paint the view.
    • drawsBackground

      public boolean drawsBackground()
      Returns whether or not the gutter, page background & dropshadow get drawn.
    • paintComponent

      public void paintComponent(Graphics g)
      Overrides JComponent implementation to paint viewer shapes and page, margin, grid, etc.
      Overrides:
      paintComponent in class JComponent
    • paintComponentAbove

      public void paintComponentAbove(Graphics2D g)
      Provides a hook for subclasses to paint above standard viewer drawing.
    • processMouseEvent

      protected void processMouseEvent(MouseEvent anEvent)
      Handle mouse events.
      Overrides:
      processMouseEvent in class JComponent
    • processMouseMotionEvent

      protected void processMouseMotionEvent(MouseEvent anEvent)
      Overrides:
      processMouseMotionEvent in class JComponent
    • mousePressed

      public void mousePressed(MouseEvent anEvent)
      Handle mouse pressed event.
    • mouseDragged

      public void mouseDragged(MouseEvent anEvent)
      Handle mouse dragged event.
    • mouseReleased

      public void mouseReleased(MouseEvent anEvent)
      Handle mouse released event.
    • mouseMoved

      public void mouseMoved(MouseEvent anEvent)
      Handle mouse moved event.
    • updateShapeUnderStack

      protected void updateShapeUnderStack(RMShape aShape, MouseEvent anEvent)
      The shape under stack should always be a stack of descendants that acceptEvents.
    • performActionURLClick

      public void performActionURLClick(String aURL)
      Viewer callback - called when shape with URL is clicked (opens URL).
    • getMinimumSize

      public Dimension getMinimumSize()
      Standard minimum size method.
      Overrides:
      getMinimumSize in class JComponent
    • getPreferredSize

      public Dimension getPreferredSize()
      Returns the optimal size of the viewer.
      Overrides:
      getPreferredSize in class JComponent
    • getUndoer

      public RMUndoer getUndoer()
      Returns the undoer associated with the viewer's document.
    • undoerSetUndoTitle

      public void undoerSetUndoTitle(String aTitle)
      Sets the title of the next registered undo in the viewer's documents's undoer (convenience).
    • undoerDisable

      public void undoerDisable()
      Disable's undo in the viewer's documents's undoer (convenience).
    • undoerEnable

      public void undoerEnable()
      Enable's undo in the viewer's documents's undoer (convenience).
    • undoerSetCoalesce

      public void undoerSetCoalesce(boolean aFlag)
      Turns on undo coalescing in the viewer's documents's undoer (convenience).
    • undoerHasUndos

      public boolean undoerHasUndos()
      Returns whether undos exist in the viewer's documents's undoer (convenience).
    • undoerAddChildToShape

      public void undoerAddChildToShape(RMShape aShape, RMShape aParent)
      Adds a child with undo registration in the viewer's documents's undoer (convenience).
    • getShapeRepaintEnabled

      public boolean getShapeRepaintEnabled()
      Returns whether changes to shapes cause repaints.
    • setShapeRepaintEnabled

      public void setShapeRepaintEnabled(boolean aFlag)
      Sets whether changes to shapes cause repaints.
    • docShapeNeedsRepaint

      public void docShapeNeedsRepaint(RMDocument aDoc, RMShape aShape)
      Doc listener method - called before a shape makes a visual change. Provides a mechanism to efficiently repaint the portion of the viewer that currently displays a shape. Registers the area covered by the shape now and at event end, to efficiently repaint shapes in transition as well.
      Specified by:
      docShapeNeedsRepaint in interface RMDocument.DocListener
    • docShapeBoundsChanged

      public void docShapeBoundsChanged(RMDocument aDoc, RMShape aShape)
      Doc listener method - called by editor when making bounds changes.
      Specified by:
      docShapeBoundsChanged in interface RMDocument.DocListener
    • docUndoerAddDirtyObject

      public void docUndoerAddDirtyObject(RMDocument aDoc, RMObject anObj)
      Doc listener method - RMViewer ignores it, but RMEditor calls setUndoSelectedObjects.
      Specified by:
      docUndoerAddDirtyObject in interface RMDocument.DocListener
    • flushGraphics

      public void flushGraphics()
      This method repaints the total bounds of shapes that have previously been registered by shapeNeedsRepaint. This should only be used internally.
    • getDirtyRect

      public RMRect getDirtyRect()
      Returns the dirty rect of shapes currently registered with shapeNeedsRepaint (and clears _dirtyShapes).
    • print

      public void print()
      This method tells the RMViewer to print by running the print dialog (configured to the default printer).
    • print

      public void print(String aPrinterName, boolean runPanel)
      This method tells the RMViewer to print to the printer with the given printer name (use null for default printer). It also offers an option to run the printer dialog.
    • print2

      public void print2()
    • print2

      public void print2(String aPrinterName, boolean runPanel)
    • getBook

      public Book getBook(int orientation, Paper paper)
      Returns a java.awt.print.Book, suitable for AWT printing.