Package controller

Class DrawingController


  • public class DrawingController
    extends java.lang.Object

    Class that represent controller in MVC architectural pattern.

    Called by the DrawingView when user click something and act depending on the command (usually update DrawingModel).
    • Field Detail

      • initialPointOfLine

        private Point initialPointOfLine
      • edgeColor

        private java.awt.Color edgeColor
      • interiorColor

        private java.awt.Color interiorColor
      • choosenEdgeColor

        private java.awt.Color choosenEdgeColor
      • choosenInteriorColor

        private java.awt.Color choosenInteriorColor
      • propertyChangeSupport

        private java.beans.PropertyChangeSupport propertyChangeSupport
      • counterOfSelectedShapes

        private int counterOfSelectedShapes
      • log

        private javax.swing.DefaultListModel<java.lang.String> log
      • undoCommandsLog

        private java.util.Stack<java.lang.String> undoCommandsLog
      • commands

        private java.util.Stack<Command> commands
      • undoCommands

        private java.util.Stack<Command> undoCommands
    • Method Detail

      • addPropertyChangedListener

        public void addPropertyChangedListener​(java.beans.PropertyChangeListener propertyChangeListener)

        Add listener that will listen (observe) to the changes in this class.

        Parameters:
        propertyChangeListener - Represent DrawingObserver that listen to the changes.
      • btnEdgeColorClicked

        public java.awt.Color btnEdgeColorClicked()
        User clicked to choose edge color, show {@inheritDoc JColorChooser}.
        Returns:
        Color that user choose.
      • btnInteriorColorClicked

        public java.awt.Color btnInteriorColorClicked()

        User clicked to choose area color, show {@inheritDoc JColorChooser}.

        Returns:
        Color that user choose.
      • btnAddPointClicked

        public void btnAddPointClicked​(java.awt.event.MouseEvent click)

        Called when user click to add new Point.

        Create CmdAddShape, add Point to that command and execute it.
        Fire change that now shape exist, repaint DrawingView and add command to the list of commands.

        Parameters:
        click - Represent place where user clicked.
      • btnAddLineClicked

        public void btnAddLineClicked​(java.awt.event.MouseEvent click)

        Called when user click to add new Line.

        Create CmdAddShape, add Line to that command and execute it.
        Fire change that now shape exist, repaint DrawingView and add command to the list of commands.

        Parameters:
        click - Represent place where user clicked.
      • btnAddSquareClicked

        public void btnAddSquareClicked​(java.awt.event.MouseEvent click)

        Called when user click to add new Square.

        Create CmdAddShape, add Square to that command and execute it, ensuring that Square don't go out of draw.
        Fire change that now shape exist, repaint DrawingView and add command to the list of commands.

        Parameters:
        click - Represent place where user clicked.
      • btnAddRectangleClicked

        public void btnAddRectangleClicked​(java.awt.event.MouseEvent click)

        Called when user click to add new Rectangle.

        Create CmdAddShape, add Rectangle to that command and execute it, ensuring that Rectangle don't go out of draw.
        Fire change that now shape exist, repaint DrawingView and add command to the list of commands.

        Parameters:
        click - Represent place where user clicked.
      • btnAddCircleClicked

        public void btnAddCircleClicked​(java.awt.event.MouseEvent click)

        Called when user click to add new Circle.

        Create CmdAddShape, add Circle to that command and execute it, ensuring that Circle don't go out of draw.
        Fire change that now shape exist, repaint DrawingView and add command to the list of commands.

        Parameters:
        click - Represent place where user clicked.
      • btnAddHexagonClicked

        public void btnAddHexagonClicked​(java.awt.event.MouseEvent click)

        Called when user click to add new Hexagon.

        Create CmdAddShape, add Hexagon to that command and execute it, ensuring that Hexagon don't go out of draw.

        Fire change that now shape exist, repaint DrawingView and add command to the list of commands.

        Parameters:
        click - Represent place where user clicked.
      • btnSelectShapeClicked

        public void btnSelectShapeClicked​(java.awt.event.MouseEvent click)

        Called when user select some shape on a draw.

        Multiple shapes can be selected and deleted.
        One selected shape can be modified, deleted, and moved by Z coordinate (CmdBringToBack, CmdBringToFront, CmdToBack and CmdToFront).
        When user click on some part on draw where no shape, all selected shapes are unselected.
        When user click on some selected shape only that shape is unselected.

        Parameters:
        click - Represent place where user click.
      • handleSelect

        public void handleSelect​(java.lang.String s,
                                 java.lang.String command)
        Count how many shapes are selected. This method is called by undo command, redo command and log parser.
        Parameters:
        s - Undo or redo command.
        command - Selection or unselection.
      • handleSelectButtons

        public void handleSelectButtons()
        Handle buttons state depend on number of selected shapes.
      • updateShapeClicked

        public void updateShapeClicked()

        Method that is called when user choose to update some shape.

        Determines instance of selected shape and call appropriate method forwarding casted type of shape.
      • btnUpdatePointClicked

        public void btnUpdatePointClicked​(Point oldPoint)

        Method is called when user want to update some existing Point on draw.

        DlgPoint is presented for user to enter new values for point.
        Then CmdUpdatePoint is executed if user confirm input.

        Parameters:
        point - Point that user want to update.
      • btnUpdateLineClicked

        public void btnUpdateLineClicked​(Line oldLine)

        Method is called when user want to update some existing Line on draw.

        DlgLine is presented for user to enter new values for line. Then CmdUpdateLine is executed if user confirm input.

        Parameters:
        line - Line that user want to update.
      • btnUpdateRectangleClicked

        public void btnUpdateRectangleClicked​(Rectangle oldRectangle)

        Method is called when user want to update some existing Rectangle on draw.

        DlgRectangle is presented for user to enter new values for rectangle.
        Then CmdUpdateRectangle is executed if user confirm input.

        Parameters:
        rectangle - Rectangle that user want to update.
      • btnUpdateSquareClicked

        public void btnUpdateSquareClicked​(Square oldSquare)

        Method is called when user want to update some existing Square on draw.

        DlgSquare is presented for user to enter new values for square.
        Then CmdUpdateSquare is executed if user confirm input.

        Parameters:
        square - Square that user want to update.
      • btnUpdateCircleClicked

        public void btnUpdateCircleClicked​(Circle oldCircle)

        Method is called when user want to update some existing Circle on a draw.

        DlgCircle is presented for user to enter new values for circle.
        Then CmdUpdateCircle is executed if user confirm input.

        Parameters:
        circle - Circle that user want to update.
      • btnUpdateHexagonClicked

        public void btnUpdateHexagonClicked​(HexagonAdapter oldHexagon)

        Method is called when user want to update some existing HexagonAdapter on a draw.

        DlgHexagon is presented for user to enter new values for hexagon.
        Then CmdUpdateHexagon is executed if user confirm input.

        Parameters:
        hexagon - Hexagon that user want to update.
      • toFront

        public void toFront()

        Method that call command CmdToFront which move some shape one position forward in the list of shapes if shape is not already at last position.

      • bringToFront

        public void bringToFront()

        Method that call command CmdBringToFront which bring some shape at the end of the list of shapes if shape is not already at last position.

      • toBack

        public void toBack()

        Method that call command CmdToBack which move some shape one position backward in the list of shapes if shape is not already at first position.

      • bringToBack

        public void bringToBack()

        Method that call command CmdBringToBack which bring some shape at the beginnig of the list of shapes if shape is not already at first position.

      • getSelectedShape

        public Shape getSelectedShape()

        Method that returns currently selected shape.

        Returns:
        Shape that is selected.
      • btnDeleteShapeClicked

        public void btnDeleteShapeClicked()

        Method is called when user want to delete some shape(s).

        CmdRemoveShape is executed.
      • executeCommand

        public void executeCommand​(Command command)

        Method that execute some command.

        Fire changes from DrawingModel to Observer DrawingFrame that updates buttons.
        Parameters:
        command - Command that need to be executed.
      • undo

        public void undo()

        Method that unexecute (undo) some command.

        Fire changes from DrawingModel to Observer DrawingFrame that updates buttons.
        Parameters:
        command - Command that need to be unexecuted.
      • redo

        public void redo()

        Method that execute previously unexecuted command.

        Fire changes from DrawingModel to Observer DrawingFrame that updates buttons.
        Parameters:
        command - Command that need to be executed again.
      • save

        public void save()

        Method that is obligate for displaying {@ JFileChooser} for user to choose where to save draw as serialized file, log file with executed commands or picture (screenshot) of draw.

        Then called appropriate FileManager to save {@docRoot File}.
      • open

        public void open()

        Method that is obligate for displaying {@ JFileChooser} for user to choose file to open.

        Supported formats are serialized file and log file with executed commands. Then called appropriate FileManager to open {@docRoot File}.
      • newDraw

        public void newDraw()

        Method that create new draw if draw is not already empty removing all executed shapes and comands.