Class DrawingController
- java.lang.Object
-
- controller.DrawingController
-
public class DrawingController extends java.lang.ObjectClass that represent controller in MVC architectural pattern.
Called by theDrawingViewwhen user click something and act depending on the command (usually updateDrawingModel).
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.ColorchoosenEdgeColorprivate java.awt.ColorchoosenInteriorColorprivate java.util.Stack<Command>commandsprivate intcounterOfSelectedShapesprivate java.awt.ColoredgeColorprivate FileManagerfileManagerprivate DrawingFrameframeprivate PointinitialPointOfLineprivate java.awt.ColorinteriorColorprivate javax.swing.DefaultListModel<java.lang.String>logprivate DrawingModelmodelprivate java.beans.PropertyChangeSupportpropertyChangeSupportprivate java.util.Stack<Command>undoCommandsprivate java.util.Stack<java.lang.String>undoCommandsLog
-
Constructor Summary
Constructors Constructor Description DrawingController(DrawingModel model, DrawingFrame frame)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangedListener(java.beans.PropertyChangeListener propertyChangeListener)Add listener that will listen (observe) to the changes in this class.voidbringToBack()Method that call commandCmdBringToBackwhich bring some shape at the beginnig of the list of shapes if shape is not already at first position.voidbringToFront()Method that call commandCmdBringToFrontwhich bring some shape at the end of the list of shapes if shape is not already at last position.voidbtnAddCircleClicked(java.awt.event.MouseEvent click)Called when user click to add newCircle.voidbtnAddHexagonClicked(java.awt.event.MouseEvent click)Called when user click to add newHexagon.voidbtnAddLineClicked(java.awt.event.MouseEvent click)Called when user click to add newLine.voidbtnAddPointClicked(java.awt.event.MouseEvent click)Called when user click to add newPoint.voidbtnAddRectangleClicked(java.awt.event.MouseEvent click)Called when user click to add newRectangle.voidbtnAddSquareClicked(java.awt.event.MouseEvent click)Called when user click to add newSquare.voidbtnDeleteShapeClicked()Method is called when user want to delete some shape(s).java.awt.ColorbtnEdgeColorClicked()User clicked to choose edge color, show {@inheritDoc JColorChooser}.java.awt.ColorbtnInteriorColorClicked()User clicked to choose area color, show {@inheritDoc JColorChooser}.voidbtnSelectShapeClicked(java.awt.event.MouseEvent click)Called when user select some shape on a draw.voidbtnUpdateCircleClicked(Circle oldCircle)Method is called when user want to update some existingCircleon a draw.voidbtnUpdateHexagonClicked(HexagonAdapter oldHexagon)Method is called when user want to update some existingHexagonAdapteron a draw.voidbtnUpdateLineClicked(Line oldLine)Method is called when user want to update some existingLineon draw.voidbtnUpdatePointClicked(Point oldPoint)Method is called when user want to update some existingPointon draw.voidbtnUpdateRectangleClicked(Rectangle oldRectangle)Method is called when user want to update some existingRectangleon draw.voidbtnUpdateSquareClicked(Square oldSquare)Method is called when user want to update some existingSquareon draw.voidexecuteCommand(Command command)Method that execute some command.ShapegetSelectedShape()Method that returns currently selected shape.voidhandleSelect(java.lang.String s, java.lang.String command)Count how many shapes are selected.voidhandleSelectButtons()Handle buttons state depend on number of selected shapes.voidnewDraw()Method that create new draw if draw is not already empty removing all executed shapes and comands.voidopen()Method that is obligate for displaying {@ JFileChooser} for user to choose file to open.voidredo()Method that execute previously unexecuted command.voidsave()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.voidtoBack()Method that call commandCmdToBackwhich move some shape one position backward in the list of shapes if shape is not already at first position.voidtoFront()Method that call commandCmdToFrontwhich move some shape one position forward in the list of shapes if shape is not already at last position.voidundo()Method that unexecute (undo) some command.voidupdateShapeClicked()Method that is called when user choose to update some shape.
-
-
-
Field Detail
-
model
private DrawingModel model
-
frame
private DrawingFrame frame
-
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
-
fileManager
private FileManager fileManager
-
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
-
-
Constructor Detail
-
DrawingController
public DrawingController(DrawingModel model, DrawingFrame frame)
-
-
Method Detail
-
addPropertyChangedListener
public void addPropertyChangedListener(java.beans.PropertyChangeListener propertyChangeListener)
Add listener that will listen (observe) to the changes in this class.
- Parameters:
propertyChangeListener- RepresentDrawingObserverthat 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, addPointto that command and execute it. Fire change that now shape exist, repaintDrawingViewand 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, addLineto that command and execute it. Fire change that now shape exist, repaintDrawingViewand 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, addSquareto that command and execute it, ensuring thatSquaredon't go out of draw. Fire change that now shape exist, repaintDrawingViewand 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, addRectangleto that command and execute it, ensuring thatRectangledon't go out of draw. Fire change that now shape exist, repaintDrawingViewand 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, addCircleto that command and execute it, ensuring thatCircledon't go out of draw. Fire change that now shape exist, repaintDrawingViewand 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, addHexagonto that command and execute it, ensuring thatHexagondon't go out of draw. Fire change that now shape exist, repaintDrawingViewand 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,CmdToBackandCmdToFront). 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
Pointon draw.DlgPointis presented for user to enter new values for point. ThenCmdUpdatePointis 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
Lineon draw.DlgLineis presented for user to enter new values for line. ThenCmdUpdateLineis 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
Rectangleon draw.DlgRectangleis presented for user to enter new values for rectangle. ThenCmdUpdateRectangleis 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
Squareon draw.DlgSquareis presented for user to enter new values for square. ThenCmdUpdateSquareis 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
Circleon a draw.DlgCircleis presented for user to enter new values for circle. ThenCmdUpdateCircleis 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
HexagonAdapteron a draw.DlgHexagonis presented for user to enter new values for hexagon. ThenCmdUpdateHexagonis executed if user confirm input.- Parameters:
hexagon- Hexagon that user want to update.
-
toFront
public void toFront()
Method that call command
CmdToFrontwhich 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
CmdBringToFrontwhich 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
CmdToBackwhich 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
CmdBringToBackwhich 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).
CmdRemoveShapeis executed.
-
executeCommand
public void executeCommand(Command command)
Method that execute some command.
Fire changes fromDrawingModelto ObserverDrawingFramethat updates buttons.- Parameters:
command- Command that need to be executed.
-
undo
public void undo()
Method that unexecute (undo) some command.
Fire changes fromDrawingModelto ObserverDrawingFramethat updates buttons.- Parameters:
command- Command that need to be unexecuted.
-
redo
public void redo()
Method that execute previously unexecuted command.
Fire changes fromDrawingModelto ObserverDrawingFramethat 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 appropriateFileManagerto 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 appropriateFileManagerto open {@docRoot File}.
-
newDraw
public void newDraw()
Method that create new draw if draw is not already empty removing all executed shapes and comands.
-
-