Sweet Home 3D 4.0

com.eteks.sweethome3d.swing
Class PlanComponent

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.eteks.sweethome3d.swing.PlanComponent
All Implemented Interfaces:
PlanView, View, ImageObserver, MenuContainer, Printable, Serializable, Scrollable

public class PlanComponent
extends JComponent
implements PlanView, Scrollable, Printable

A component displaying the plan of a home.

Author:
Emmanuel Puybaret
See Also:
Serialized Form

Nested Class Summary
protected static class PlanComponent.PaintMode
          The circumstances under which the home items displayed by this component will be painted.
 class PlanComponent.PlanRulerComponent
          A component displaying the plan horizontal or vertical ruler associated to this plan.
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Nested classes/interfaces inherited from interface com.eteks.sweethome3d.viewcontroller.PlanView
PlanView.CursorType
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PlanComponent(Home home, UserPreferences preferences, PlanController controller)
          Creates a new plan that displays home.
 
Method Summary
 boolean canImportDraggedItems(List<Selectable> items, int x, int y)
          Returns true.
 int convertXModelToScreen(float x)
          Returns x converted in screen coordinates space.
 float convertXPixelToModel(int x)
          Returns x converted in model coordinates space.
 int convertYModelToScreen(float y)
          Returns y converted in screen coordinates space.
 float convertYPixelToModel(int y)
          Returns y converted in model coordinates space.
protected  Cursor createCustomCursor(URL smallCursorImageUrl, URL largeCursorImageUrl, float xCursorHotSpot, float yCursorHotSpot, String cursorName, Cursor defaultCursor)
          Returns a custom cursor created from images in parameters.
 void deleteFeedback()
          Deletes all elements shown as feedback.
 void deleteToolTipFeedback()
          Deletes tool tip text from screen.
 void exportToSVG(OutputStream outputStream)
          Writes this plan in the given output stream at SVG (Scalable Vector Graphics) format.
protected  Color getBackgroundColor(PlanComponent.PaintMode mode)
          Returns the background color used to draw content.
 BufferedImage getClipboardImage()
          Returns an image of the selected items displayed by this component (camera excepted) with no outline at scale 1/1 (1 pixel = 1cm).
protected  Font getFont(Font defaultFont, TextStyle textStyle)
          Returns the AWT font matching a given text style.
protected  FontMetrics getFontMetrics(Font defaultFont, TextStyle textStyle)
          Returns the font metrics matching a given text style.
protected  Color getForegroundColor(PlanComponent.PaintMode mode)
          Returns the foreground color used to draw content.
protected  Color getFurnitureOutlineColor()
          Returns the color used to draw furniture outline of the shape where a user can click to select a piece of furniture.
 View getHorizontalRuler()
          Returns the component used as an horizontal ruler for this plan.
protected  Rectangle2D getItemBounds(Graphics g, Selectable item)
          Returns the bounds of the given item.
protected  List<Selectable> getPaintedItems()
          Returns the collection of walls, furniture, rooms and dimension lines of the home painted by this component wherever the level they belong to is selected or not.
 float getPixelLength()
          Returns the length in centimeters of a pixel with the current scale.
 Dimension getPreferredScrollableViewportSize()
           
 Dimension getPreferredSize()
          Returns the preferred size of this component.
 float getPrintPreferredScale(Graphics g, PageFormat pageFormat)
          Returns the print preferred scale of the plan drawn in this component to make it fill pageFormat imageable size.
 float getScale()
          Returns the scale used to display the plan.
 int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
           
 boolean getScrollableTracksViewportHeight()
           
 boolean getScrollableTracksViewportWidth()
           
 int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
           
protected  Color getSelectionColor()
          Returns the color used to draw selection outlines.
 float[][] getTextBounds(String text, TextStyle style, float x, float y, float angle)
          Returns the coordinates of the bounding rectangle of the text centered at the point (x,y).
 View getVerticalRuler()
          Returns the component used as a vertical ruler for this plan.
 boolean isBackgroundPainted()
          Returns true if plan's background should be painted.
 boolean isSelectedItemsOutlinePainted()
          Returns true if the outline of home selected items should be painted.
 void makePointVisible(float x, float y)
          Ensures the point at (x, y) is visible, moving scroll bars if needed.
 void makeSelectionVisible()
          Ensures selected items are visible at screen and moves scroll bars if needed.
 void moveView(float dx, float dy)
          Moves the view from (dx, dy) unit in the scrolling zone it belongs to.
protected  void paintComponent(Graphics g)
          Paints this component.
protected  void paintHomeItems(Graphics g, float planScale, Color backgroundColor, Color foregroundColor, PlanComponent.PaintMode paintMode)
          Paints home items at the given scale, and with background and foreground colors.
 int print(Graphics g, PageFormat pageFormat, int pageIndex)
          Prints this component plan at the scale given in the home print attributes or at a scale that makes it fill pageFormat imageable size if this attribute is null.
 void revalidate()
          Revalidates and repaints this component and its rulers.
 void setAlignmentFeedback(Class<? extends Selectable> alignedObjectClass, Selectable alignedObject, float x, float y, boolean showPointFeedback)
          Sets the location point for alignment feedback.
 void setAngleFeedback(float xCenter, float yCenter, float x1, float y1, float x2, float y2)
          Sets the points used to draw an angle in plan view.
 void setBackgroundPainted(boolean backgroundPainted)
          Sets whether plan's background should be painted or not.
 void setCursor(PlanView.CursorType cursorType)
          Sets the cursor of this component as rotation cursor.
 void setDimensionLinesFeedback(List<DimensionLine> dimensionLines)
          Sets the given dimension lines to be drawn as feedback.
 void setDraggedItemsFeedback(List<Selectable> draggedItems)
          Sets the feedback of dragged items drawn during a drag and drop operation, initiated from outside of plan view.
 void setRectangleFeedback(float x0, float y0, float x1, float y1)
          Sets rectangle selection feedback coordinates.
 void setResizeIndicatorVisible(boolean resizeIndicatorVisible)
          Sets whether the resize indicator of selected wall or piece of furniture should be visible or not.
 void setScale(float scale)
          Sets the scale used to display the plan.
 void setSelectedItemsOutlinePainted(boolean selectedItemsOutlinePainted)
          Sets whether the outline of home selected items should be painted or not.
 void setToolTipEditedProperties(PlanController.EditableProperty[] toolTipEditedProperties, Object[] toolTipPropertyValues, float x, float y)
          Set tool tip edition.
 void setToolTipFeedback(String toolTipFeedback, float x, float y)
          Sets tool tip text displayed as feedback.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PlanComponent

public PlanComponent(Home home,
                     UserPreferences preferences,
                     PlanController controller)
Creates a new plan that displays home.

Method Detail

revalidate

public void revalidate()
Revalidates and repaints this component and its rulers.

Overrides:
revalidate in class JComponent

createCustomCursor

protected Cursor createCustomCursor(URL smallCursorImageUrl,
                                    URL largeCursorImageUrl,
                                    float xCursorHotSpot,
                                    float yCursorHotSpot,
                                    String cursorName,
                                    Cursor defaultCursor)
Returns a custom cursor created from images in parameters.


getPreferredSize

public Dimension getPreferredSize()
Returns the preferred size of this component.

Overrides:
getPreferredSize in class JComponent

getPaintedItems

protected List<Selectable> getPaintedItems()
Returns the collection of walls, furniture, rooms and dimension lines of the home painted by this component wherever the level they belong to is selected or not.


getItemBounds

protected Rectangle2D getItemBounds(Graphics g,
                                    Selectable item)
Returns the bounds of the given item.


getTextBounds

public float[][] getTextBounds(String text,
                               TextStyle style,
                               float x,
                               float y,
                               float angle)
Returns the coordinates of the bounding rectangle of the text centered at the point (x,y).

Specified by:
getTextBounds in interface PlanView

getFont

protected Font getFont(Font defaultFont,
                       TextStyle textStyle)
Returns the AWT font matching a given text style.


getFontMetrics

protected FontMetrics getFontMetrics(Font defaultFont,
                                     TextStyle textStyle)
Returns the font metrics matching a given text style.


setBackgroundPainted

public void setBackgroundPainted(boolean backgroundPainted)
Sets whether plan's background should be painted or not. Background may include grid and an image.


isBackgroundPainted

public boolean isBackgroundPainted()
Returns true if plan's background should be painted.


setSelectedItemsOutlinePainted

public void setSelectedItemsOutlinePainted(boolean selectedItemsOutlinePainted)
Sets whether the outline of home selected items should be painted or not.


isSelectedItemsOutlinePainted

public boolean isSelectedItemsOutlinePainted()
Returns true if the outline of home selected items should be painted.


paintComponent

protected void paintComponent(Graphics g)
Paints this component.

Overrides:
paintComponent in class JComponent

getPrintPreferredScale

public float getPrintPreferredScale(Graphics g,
                                    PageFormat pageFormat)
Returns the print preferred scale of the plan drawn in this component to make it fill pageFormat imageable size.


print

public int print(Graphics g,
                 PageFormat pageFormat,
                 int pageIndex)
Prints this component plan at the scale given in the home print attributes or at a scale that makes it fill pageFormat imageable size if this attribute is null.

Specified by:
print in interface Printable

getClipboardImage

public BufferedImage getClipboardImage()
Returns an image of the selected items displayed by this component (camera excepted) with no outline at scale 1/1 (1 pixel = 1cm).


exportToSVG

public void exportToSVG(OutputStream outputStream)
                 throws IOException
Writes this plan in the given output stream at SVG (Scalable Vector Graphics) format.

Throws:
IOException

getForegroundColor

protected Color getForegroundColor(PlanComponent.PaintMode mode)
Returns the foreground color used to draw content.


getBackgroundColor

protected Color getBackgroundColor(PlanComponent.PaintMode mode)
Returns the background color used to draw content.


paintHomeItems

protected void paintHomeItems(Graphics g,
                              float planScale,
                              Color backgroundColor,
                              Color foregroundColor,
                              PlanComponent.PaintMode paintMode)
                       throws InterruptedIOException
Paints home items at the given scale, and with background and foreground colors. Outline around selected items will be painted only under PAINT mode.

Throws:
InterruptedIOException

getSelectionColor

protected Color getSelectionColor()
Returns the color used to draw selection outlines.


getFurnitureOutlineColor

protected Color getFurnitureOutlineColor()
Returns the color used to draw furniture outline of the shape where a user can click to select a piece of furniture.


setRectangleFeedback

public void setRectangleFeedback(float x0,
                                 float y0,
                                 float x1,
                                 float y1)
Sets rectangle selection feedback coordinates.

Specified by:
setRectangleFeedback in interface PlanView

makeSelectionVisible

public void makeSelectionVisible()
Ensures selected items are visible at screen and moves scroll bars if needed.

Specified by:
makeSelectionVisible in interface PlanView

makePointVisible

public void makePointVisible(float x,
                             float y)
Ensures the point at (x, y) is visible, moving scroll bars if needed.

Specified by:
makePointVisible in interface PlanView

moveView

public void moveView(float dx,
                     float dy)
Moves the view from (dx, dy) unit in the scrolling zone it belongs to.

Specified by:
moveView in interface PlanView

getScale

public float getScale()
Returns the scale used to display the plan.

Specified by:
getScale in interface PlanView

setScale

public void setScale(float scale)
Sets the scale used to display the plan. If this component is displayed in a viewport the view position is updated to ensure the center's view will remain the same after the scale change.

Specified by:
setScale in interface PlanView

convertXPixelToModel

public float convertXPixelToModel(int x)
Returns x converted in model coordinates space.

Specified by:
convertXPixelToModel in interface PlanView

convertYPixelToModel

public float convertYPixelToModel(int y)
Returns y converted in model coordinates space.

Specified by:
convertYPixelToModel in interface PlanView

convertXModelToScreen

public int convertXModelToScreen(float x)
Returns x converted in screen coordinates space.

Specified by:
convertXModelToScreen in interface PlanView

convertYModelToScreen

public int convertYModelToScreen(float y)
Returns y converted in screen coordinates space.

Specified by:
convertYModelToScreen in interface PlanView

getPixelLength

public float getPixelLength()
Returns the length in centimeters of a pixel with the current scale.

Specified by:
getPixelLength in interface PlanView

setCursor

public void setCursor(PlanView.CursorType cursorType)
Sets the cursor of this component as rotation cursor.

Specified by:
setCursor in interface PlanView

setToolTipFeedback

public void setToolTipFeedback(String toolTipFeedback,
                               float x,
                               float y)
Sets tool tip text displayed as feedback.

Specified by:
setToolTipFeedback in interface PlanView
Parameters:
toolTipFeedback - the text displayed in the tool tip or null to make tool tip disappear.

setToolTipEditedProperties

public void setToolTipEditedProperties(PlanController.EditableProperty[] toolTipEditedProperties,
                                       Object[] toolTipPropertyValues,
                                       float x,
                                       float y)
Set tool tip edition.

Specified by:
setToolTipEditedProperties in interface PlanView

deleteToolTipFeedback

public void deleteToolTipFeedback()
Deletes tool tip text from screen.

Specified by:
deleteToolTipFeedback in interface PlanView

setResizeIndicatorVisible

public void setResizeIndicatorVisible(boolean resizeIndicatorVisible)
Sets whether the resize indicator of selected wall or piece of furniture should be visible or not.

Specified by:
setResizeIndicatorVisible in interface PlanView

setAlignmentFeedback

public void setAlignmentFeedback(Class<? extends Selectable> alignedObjectClass,
                                 Selectable alignedObject,
                                 float x,
                                 float y,
                                 boolean showPointFeedback)
Sets the location point for alignment feedback.

Specified by:
setAlignmentFeedback in interface PlanView

setAngleFeedback

public void setAngleFeedback(float xCenter,
                             float yCenter,
                             float x1,
                             float y1,
                             float x2,
                             float y2)
Sets the points used to draw an angle in plan view.

Specified by:
setAngleFeedback in interface PlanView

setDraggedItemsFeedback

public void setDraggedItemsFeedback(List<Selectable> draggedItems)
Sets the feedback of dragged items drawn during a drag and drop operation, initiated from outside of plan view.

Specified by:
setDraggedItemsFeedback in interface PlanView

setDimensionLinesFeedback

public void setDimensionLinesFeedback(List<DimensionLine> dimensionLines)
Sets the given dimension lines to be drawn as feedback.

Specified by:
setDimensionLinesFeedback in interface PlanView

deleteFeedback

public void deleteFeedback()
Deletes all elements shown as feedback.

Specified by:
deleteFeedback in interface PlanView

canImportDraggedItems

public boolean canImportDraggedItems(List<Selectable> items,
                                     int x,
                                     int y)
Returns true.

Specified by:
canImportDraggedItems in interface PlanView

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface Scrollable

getScrollableBlockIncrement

public int getScrollableBlockIncrement(Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Specified by:
getScrollableBlockIncrement in interface Scrollable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Specified by:
getScrollableTracksViewportHeight in interface Scrollable

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Specified by:
getScrollableTracksViewportWidth in interface Scrollable

getScrollableUnitIncrement

public int getScrollableUnitIncrement(Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Specified by:
getScrollableUnitIncrement in interface Scrollable

getHorizontalRuler

public View getHorizontalRuler()
Returns the component used as an horizontal ruler for this plan.

Specified by:
getHorizontalRuler in interface PlanView

getVerticalRuler

public View getVerticalRuler()
Returns the component used as a vertical ruler for this plan.

Specified by:
getVerticalRuler in interface PlanView

Sweet Home 3D 4.0

© Copyrights 2006-2013 eTeks - All rights reserved
Distributed under GNU General Public License