org.diylc.presenter
Class Presenter

java.lang.Object
  extended by org.diylc.presenter.Presenter
All Implemented Interfaces:
IKeyProcessor, IMouseProcessor, IPlugInPort, ISelectionProcessor, ITemplateProcessor

public class Presenter
extends java.lang.Object
implements IPlugInPort

The main presenter class, contains core app logic and drawing routines.

Author:
Branislav Stojkovic

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.diylc.common.ITemplateProcessor
ITemplateProcessor.TemplateAlreadyExistsException
 
Field Summary
static org.diylc.appframework.update.VersionNumber CURRENT_VERSION
           
static java.lang.String DEFAULTS_KEY_PREFIX
           
static java.util.List<IDIYComponent<?>> EMPTY_SELECTION
           
static int ICON_SIZE
           
 
Fields inherited from interface org.diylc.common.IPlugInPort
ABNORMAL_EXIT_KEY, ANTI_ALIASING_KEY, AUTO_EDIT_KEY, BUTTON1, BUTTON2, BUTTON3, CONTINUOUS_CREATION_KEY, DND_TOGGLE_SNAP, DND_TOGGLE_STICKY, EXPORT_GRID_KEY, HI_QUALITY_RENDER_KEY, METRIC_KEY, NOBUTTON, OUTLINE_KEY, RECENT_COMPONENTS_KEY, SNAP_TO_GRID_KEY, STICKY_POINTS_KEY, THEME_KEY, WHEEL_ZOOM_KEY
 
Fields inherited from interface org.diylc.common.IKeyProcessor
VK_DOWN, VK_LEFT, VK_RIGHT, VK_UP
 
Fields inherited from interface org.diylc.common.ITemplateProcessor
TEMPLATES_KEY
 
Constructor Summary
Presenter(IView view)
           
 
Method Summary
 boolean allowFileAction()
          Shows a user dialog if there are changes to confirm that it's safe to proceed.
 void applyPropertiesToProject(java.util.List<PropertyWrapper> properties)
          Applies specified properties to the current project.
 void applyTemplateToSelection(Template template)
           
 void bringSelectionToFront()
          Brings each of the selected components one step to front.
 java.awt.geom.Point2D calculateSelectionDimension()
           
 void createNewProject()
          Creates a new project.
 void deleteSelectedComponents()
          Deletes all the selected components from the project.
 void deleteTemplate(java.lang.String categoryName, java.lang.String componentTypeName, java.lang.String templateName)
           
 void dispose()
           
 void dragActionChanged(int dragAction)
          Changes the current drag action during the dragging.
 void dragEnded(java.awt.Point point)
          Notification that drag has been ended in the specified point.
 boolean dragOver(java.awt.Point point)
          Checks if it's possible to drop over the specified point.
 void dragStarted(java.awt.Point point, int dragAction)
          Notification that drag has been started from the specified point.
 void draw(java.awt.Graphics2D g2d, java.util.Set<DrawOption> drawOptions, IComponentFiler filter)
          Draws project on the provided Graphics2D.
 void editSelection()
           
 void expandSelection(ExpansionMode expansionMode)
          Expands the current selection to include surrounding components.
 java.util.List<IDIYComponent<?>> findComponentsAt(java.awt.Point point)
          Finds all components at the specified location, sorted by z-index from top to bottom.
 java.util.List<IDIYComponent<?>> findComponentsAtScaled(java.awt.Point point)
          Finds all components whose areas include the specified Point.
 java.util.List<IAutoCreator> getAutoCreators()
           
 java.lang.Double[] getAvailableZoomLevels()
           
 java.awt.Dimension getCanvasDimensions(boolean useZoom)
          Returns size of the canvas that takes project dimensions into account as well as zoom level.
 java.util.Map<java.lang.String,java.util.List<ComponentType>> getComponentTypes()
          Returns all available ComponentTypes classified by category.
 java.lang.String getCurrentFileName()
           
 Project getCurrentProject()
          Returns an instance of currently loaded project.
 org.diylc.appframework.update.VersionNumber getCurrentVersionNumber()
          Returns current version number.
 java.awt.Cursor getCursorAt(java.awt.Point point)
          Returns an instance of Cursor that should be used at the specified location.
 java.util.List<PropertyWrapper> getMutualSelectionProperties()
           
 ComponentType getNewComponentTypeSlot()
          Gets the current new component slot.
 java.util.List<PropertyWrapper> getProjectProperties()
           
 java.util.List<IDIYComponent<?>> getSelectedComponents()
          Returns the current ComponentTransferable.
 Theme getSelectedTheme()
           
 java.util.List<Template> getTemplatesFor(java.lang.String categoryName, java.lang.String componentTypeName)
           
 java.util.List<Template> getTemplatesForSelection()
           
 double getZoomLevel()
          Returns current zoom level where zoomLevel = 1.0d means 100%.
 void groupSelectedComponents()
          Groups all selected components.
 void installPlugin(IPlugIn plugIn)
           
 boolean isProjectModified()
           
 boolean keyPressed(int key, boolean ctrlDown, boolean shiftDown, boolean altDown)
          Notifies the presenter that a key hes been pressed on the canvas.
 void loadProject(Project project, boolean freshStart)
          Loads specified Project.
 void loadProjectFromFile(java.lang.String fileName)
          Loads a project from the specified file.
 void mouseClicked(java.awt.Point point, int button, boolean ctrlDown, boolean shiftDown, boolean altDown, int clickCount)
          Notifies the presenter that mouse is clicked.
 void mouseMoved(java.awt.Point point, boolean ctrlDown, boolean shiftDown, boolean altDown)
          Notifies the presenter that mouse is moved.
 void pasteComponents(java.util.List<IDIYComponent<?>> components)
          Adds a list of components to the project.
 void refresh()
          Causes the display to refresh.
 void renumberSelectedComponents(boolean xAxisFirst)
          Renumbers all the selected components.
 void rotateSelection(int direction)
          Rotates selection for 90 degrees.
 void saveProjectToFile(java.lang.String fileName, boolean isBackup)
          Saves the current project into the specified file.
 void saveSelectedComponentAsTemplate(java.lang.String templateName)
           
 void selectAll(int layer)
          Selects all components in the project.
 void sendSelectionToBack()
          Sends each of the selected components one step back.
 void setLayerLocked(int layerZOrder, boolean locked)
          Locks or unlocks the specified layer.
 void setMetric(boolean isMetric)
          Changes default size notation, true for metric, false for imperial.
 void setNewComponentTypeSlot(ComponentType componentType, Template template)
          Sets the new component slot.
 void setProjectDefaultPropertyValue(java.lang.String propertyName, java.lang.Object value)
          Sets default value for the specified property name for projects.
 void setSelectedTheme(Theme theme)
          Changes the current theme.
 void setSelectionDefaultPropertyValue(java.lang.String propertyName, java.lang.Object value)
          Sets default value for the specified property name for currently selected component types.
 void setZoomLevel(double zoomLevel)
          Changes current zoom level where zoomLevel = 1.0d means 100%
 void ungroupSelectedComponents()
          Ungroups all selected components.
 void updateSelection(java.util.List<IDIYComponent<?>> newSelection)
          Updates the selection with the specified list of component.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CURRENT_VERSION

public static org.diylc.appframework.update.VersionNumber CURRENT_VERSION

DEFAULTS_KEY_PREFIX

public static final java.lang.String DEFAULTS_KEY_PREFIX
See Also:
Constant Field Values

EMPTY_SELECTION

public static final java.util.List<IDIYComponent<?>> EMPTY_SELECTION

ICON_SIZE

public static final int ICON_SIZE
See Also:
Constant Field Values
Constructor Detail

Presenter

public Presenter(IView view)
Method Detail

installPlugin

public void installPlugin(IPlugIn plugIn)

dispose

public void dispose()

getAvailableZoomLevels

public java.lang.Double[] getAvailableZoomLevels()
Specified by:
getAvailableZoomLevels in interface IPlugInPort

getZoomLevel

public double getZoomLevel()
Description copied from interface: IPlugInPort
Returns current zoom level where zoomLevel = 1.0d means 100%.

Specified by:
getZoomLevel in interface IPlugInPort
Returns:
current zoom level

setZoomLevel

public void setZoomLevel(double zoomLevel)
Description copied from interface: IPlugInPort
Changes current zoom level where zoomLevel = 1.0d means 100%

Specified by:
setZoomLevel in interface IPlugInPort
Parameters:
zoomLevel - new zoom leve

getCursorAt

public java.awt.Cursor getCursorAt(java.awt.Point point)
Description copied from interface: IPlugInPort
Returns an instance of Cursor that should be used at the specified location. Note: point coordinates are scaled for zoom factor.

Specified by:
getCursorAt in interface IPlugInPort
Returns:
cursor

getCanvasDimensions

public java.awt.Dimension getCanvasDimensions(boolean useZoom)
Description copied from interface: IPlugInPort
Returns size of the canvas that takes project dimensions into account as well as zoom level. Each dimension is calculated as the product of the actual size and the number of pixels per unit. If useZoom is set to true, the result is scaled by zoom factor.

Specified by:
getCanvasDimensions in interface IPlugInPort
Returns:
canvas dimensions

getCurrentProject

public Project getCurrentProject()
Description copied from interface: IPlugInPort
Returns an instance of currently loaded project.

Specified by:
getCurrentProject in interface IPlugInPort
Returns:

loadProject

public void loadProject(Project project,
                        boolean freshStart)
Description copied from interface: IPlugInPort
Loads specified Project.

Specified by:
loadProject in interface IPlugInPort

createNewProject

public void createNewProject()
Description copied from interface: IPlugInPort
Creates a new project.

Specified by:
createNewProject in interface IPlugInPort

loadProjectFromFile

public void loadProjectFromFile(java.lang.String fileName)
Description copied from interface: IPlugInPort
Loads a project from the specified file.

Specified by:
loadProjectFromFile in interface IPlugInPort

allowFileAction

public boolean allowFileAction()
Description copied from interface: IPlugInPort
Shows a user dialog if there are changes to confirm that it's safe to proceed.

Specified by:
allowFileAction in interface IPlugInPort
Returns:
true, if file actions (new, open, close) can be taken

saveProjectToFile

public void saveProjectToFile(java.lang.String fileName,
                              boolean isBackup)
Description copied from interface: IPlugInPort
Saves the current project into the specified file.

Specified by:
saveProjectToFile in interface IPlugInPort

getCurrentFileName

public java.lang.String getCurrentFileName()
Specified by:
getCurrentFileName in interface IPlugInPort
Returns:
the current file name.

isProjectModified

public boolean isProjectModified()
Specified by:
isProjectModified in interface IPlugInPort
Returns:
true if the current project is modified.

getComponentTypes

public java.util.Map<java.lang.String,java.util.List<ComponentType>> getComponentTypes()
Description copied from interface: IPlugInPort
Returns all available ComponentTypes classified by category. Result is a Map between category name to a List of all ComponentTypes that share that category name.

Specified by:
getComponentTypes in interface IPlugInPort
Returns:

getAutoCreators

public java.util.List<IAutoCreator> getAutoCreators()

draw

public void draw(java.awt.Graphics2D g2d,
                 java.util.Set<DrawOption> drawOptions,
                 IComponentFiler filter)
Description copied from interface: IPlugInPort
Draws project on the provided Graphics2D. If the provided filter is not null, it will be used to filter the components that are shown.

Specified by:
draw in interface IPlugInPort
drawOptions - specific drawing options

findComponentsAtScaled

public java.util.List<IDIYComponent<?>> findComponentsAtScaled(java.awt.Point point)
Finds all components whose areas include the specified Point. Point is not scaled by the zoom factor. Components that belong to locked layers are ignored.

Returns:

findComponentsAt

public java.util.List<IDIYComponent<?>> findComponentsAt(java.awt.Point point)
Description copied from interface: ISelectionProcessor
Finds all components at the specified location, sorted by z-index from top to bottom.

Specified by:
findComponentsAt in interface ISelectionProcessor
Returns:

mouseClicked

public void mouseClicked(java.awt.Point point,
                         int button,
                         boolean ctrlDown,
                         boolean shiftDown,
                         boolean altDown,
                         int clickCount)
Description copied from interface: IMouseProcessor
Notifies the presenter that mouse is clicked. Note: point coordinates are display based, i.e. scaled for zoom factor.

Specified by:
mouseClicked in interface IMouseProcessor

keyPressed

public boolean keyPressed(int key,
                          boolean ctrlDown,
                          boolean shiftDown,
                          boolean altDown)
Description copied from interface: IKeyProcessor
Notifies the presenter that a key hes been pressed on the canvas.

Specified by:
keyPressed in interface IKeyProcessor
Returns:
true if the event should be consumed

editSelection

public void editSelection()
Specified by:
editSelection in interface IPlugInPort

mouseMoved

public void mouseMoved(java.awt.Point point,
                       boolean ctrlDown,
                       boolean shiftDown,
                       boolean altDown)
Description copied from interface: IMouseProcessor
Notifies the presenter that mouse is moved. Note: point coordinates are display based, i.e. scaled for zoom factor.

Specified by:
mouseMoved in interface IMouseProcessor

getSelectedComponents

public java.util.List<IDIYComponent<?>> getSelectedComponents()
Description copied from interface: ISelectionProcessor
Returns the current ComponentTransferable.

Specified by:
getSelectedComponents in interface ISelectionProcessor
Returns:

selectAll

public void selectAll(int layer)
Description copied from interface: ISelectionProcessor
Selects all components in the project.

Specified by:
selectAll in interface ISelectionProcessor

getCurrentVersionNumber

public org.diylc.appframework.update.VersionNumber getCurrentVersionNumber()
Description copied from interface: IPlugInPort
Returns current version number.

Specified by:
getCurrentVersionNumber in interface IPlugInPort
Returns:

dragStarted

public void dragStarted(java.awt.Point point,
                        int dragAction)
Description copied from interface: IMouseProcessor
Notification that drag has been started from the specified point. Note: point coordinates are scaled for zoom factor.

Specified by:
dragStarted in interface IMouseProcessor

dragActionChanged

public void dragActionChanged(int dragAction)
Description copied from interface: IMouseProcessor
Changes the current drag action during the dragging.

Specified by:
dragActionChanged in interface IMouseProcessor

dragOver

public boolean dragOver(java.awt.Point point)
Description copied from interface: IMouseProcessor
Checks if it's possible to drop over the specified point. Note: point coordinates are scaled for zoom factor.

Specified by:
dragOver in interface IMouseProcessor
Returns:

rotateSelection

public void rotateSelection(int direction)
Description copied from interface: ISelectionProcessor
Rotates selection for 90 degrees.

Specified by:
rotateSelection in interface ISelectionProcessor
Parameters:
direction - 1 for clockwise, -1 for counter-clockwise

dragEnded

public void dragEnded(java.awt.Point point)
Description copied from interface: IMouseProcessor
Notification that drag has been ended in the specified point. Note: point coordinates are scaled for zoom factor.

Specified by:
dragEnded in interface IMouseProcessor

pasteComponents

public void pasteComponents(java.util.List<IDIYComponent<?>> components)
Description copied from interface: IPlugInPort
Adds a list of components to the project.

Specified by:
pasteComponents in interface IPlugInPort

deleteSelectedComponents

public void deleteSelectedComponents()
Description copied from interface: IPlugInPort
Deletes all the selected components from the project.

Specified by:
deleteSelectedComponents in interface IPlugInPort

setSelectionDefaultPropertyValue

public void setSelectionDefaultPropertyValue(java.lang.String propertyName,
                                             java.lang.Object value)
Description copied from interface: IPlugInPort
Sets default value for the specified property name for currently selected component types.

Specified by:
setSelectionDefaultPropertyValue in interface IPlugInPort
Parameters:
propertyName - display name for property
value - new default value, must not be null

setProjectDefaultPropertyValue

public void setProjectDefaultPropertyValue(java.lang.String propertyName,
                                           java.lang.Object value)
Description copied from interface: IPlugInPort
Sets default value for the specified property name for projects.

Specified by:
setProjectDefaultPropertyValue in interface IPlugInPort
Parameters:
propertyName - display name for property
value - new default value, must not be null

setMetric

public void setMetric(boolean isMetric)
Description copied from interface: IPlugInPort
Changes default size notation, true for metric, false for imperial.

Specified by:
setMetric in interface IPlugInPort

groupSelectedComponents

public void groupSelectedComponents()
Description copied from interface: IPlugInPort
Groups all selected components.

Specified by:
groupSelectedComponents in interface IPlugInPort

ungroupSelectedComponents

public void ungroupSelectedComponents()
Description copied from interface: IPlugInPort
Ungroups all selected components.

Specified by:
ungroupSelectedComponents in interface IPlugInPort

setLayerLocked

public void setLayerLocked(int layerZOrder,
                           boolean locked)
Description copied from interface: IPlugInPort
Locks or unlocks the specified layer. All components within +- 0.5 range will be affected by the change as well.

Specified by:
setLayerLocked in interface IPlugInPort

sendSelectionToBack

public void sendSelectionToBack()
Description copied from interface: IPlugInPort
Sends each of the selected components one step back.

Specified by:
sendSelectionToBack in interface IPlugInPort

bringSelectionToFront

public void bringSelectionToFront()
Description copied from interface: IPlugInPort
Brings each of the selected components one step to front.

Specified by:
bringSelectionToFront in interface IPlugInPort

refresh

public void refresh()
Description copied from interface: IPlugInPort
Causes the display to refresh.

Specified by:
refresh in interface IPlugInPort

getSelectedTheme

public Theme getSelectedTheme()
Specified by:
getSelectedTheme in interface IPlugInPort
Returns:
currently selected theme.

setSelectedTheme

public void setSelectedTheme(Theme theme)
Description copied from interface: IPlugInPort
Changes the current theme.

Specified by:
setSelectedTheme in interface IPlugInPort

renumberSelectedComponents

public void renumberSelectedComponents(boolean xAxisFirst)
Description copied from interface: IPlugInPort
Renumbers all the selected components.

Specified by:
renumberSelectedComponents in interface IPlugInPort

updateSelection

public void updateSelection(java.util.List<IDIYComponent<?>> newSelection)
Description copied from interface: ISelectionProcessor
Updates the selection with the specified list of component. Also, updates control point map with all components that are stuck to the newly selected components.

Specified by:
updateSelection in interface ISelectionProcessor

expandSelection

public void expandSelection(ExpansionMode expansionMode)
Description copied from interface: ISelectionProcessor
Expands the current selection to include surrounding components. Options are controlled with expansionMode flag.

Specified by:
expandSelection in interface ISelectionProcessor

calculateSelectionDimension

public java.awt.geom.Point2D calculateSelectionDimension()
Specified by:
calculateSelectionDimension in interface IPlugInPort
Returns:
selection size expressed in either inches or centimeters, based on the user preference.

getMutualSelectionProperties

public java.util.List<PropertyWrapper> getMutualSelectionProperties()
Specified by:
getMutualSelectionProperties in interface IPlugInPort
Returns:
a list of properties that are mutual for all the selected components. Resulting list may be empty if selected components do not have mutual properties or can be null if the selection is empty.

getProjectProperties

public java.util.List<PropertyWrapper> getProjectProperties()
Specified by:
getProjectProperties in interface IPlugInPort
Returns:
a list of editable properties of the current project.

applyPropertiesToProject

public void applyPropertiesToProject(java.util.List<PropertyWrapper> properties)
Description copied from interface: IPlugInPort
Applies specified properties to the current project.

Specified by:
applyPropertiesToProject in interface IPlugInPort

getNewComponentTypeSlot

public ComponentType getNewComponentTypeSlot()
Description copied from interface: IPlugInPort
Gets the current new component slot.

Specified by:
getNewComponentTypeSlot in interface IPlugInPort

setNewComponentTypeSlot

public void setNewComponentTypeSlot(ComponentType componentType,
                                    Template template)
Description copied from interface: IPlugInPort
Sets the new component slot. Specified component type will be used to instantiate new component.

Specified by:
setNewComponentTypeSlot in interface IPlugInPort

saveSelectedComponentAsTemplate

public void saveSelectedComponentAsTemplate(java.lang.String templateName)
Specified by:
saveSelectedComponentAsTemplate in interface ITemplateProcessor

getTemplatesFor

public java.util.List<Template> getTemplatesFor(java.lang.String categoryName,
                                                java.lang.String componentTypeName)
Specified by:
getTemplatesFor in interface ITemplateProcessor

getTemplatesForSelection

public java.util.List<Template> getTemplatesForSelection()
Specified by:
getTemplatesForSelection in interface ITemplateProcessor

applyTemplateToSelection

public void applyTemplateToSelection(Template template)
Specified by:
applyTemplateToSelection in interface ITemplateProcessor

deleteTemplate

public void deleteTemplate(java.lang.String categoryName,
                           java.lang.String componentTypeName,
                           java.lang.String templateName)
Specified by:
deleteTemplate in interface ITemplateProcessor