Class DrawingController
- java.lang.Object
-
- controller.DrawingController
-
public class DrawingController extends java.lang.Object
Class that represent controller in MVC architectural pattern.
Called by theDrawingView
when user click something and act depending on the command (usually updateDrawingModel
).
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.Color
choosenEdgeColor
private java.awt.Color
choosenInteriorColor
private java.util.Stack<Command>
commands
private int
counterOfSelectedShapes
private java.awt.Color
edgeColor
private FileManager
fileManager
private DrawingFrame
frame
private Point
initialPointOfLine
private java.awt.Color
interiorColor
private javax.swing.DefaultListModel<java.lang.String>
log
private DrawingModel
model
private java.beans.PropertyChangeSupport
propertyChangeSupport
private java.util.Stack<Command>
undoCommands
private 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 void
addPropertyChangedListener(java.beans.PropertyChangeListener propertyChangeListener)
Add listener that will listen (observe) to the changes in this class.void
bringToBack()
Method that call commandCmdBringToBack
which bring some shape at the beginnig of the list of shapes if shape is not already at first position.void
bringToFront()
Method that call commandCmdBringToFront
which bring some shape at the end of the list of shapes if shape is not already at last position.void
btnAddCircleClicked(java.awt.event.MouseEvent click)
Called when user click to add newCircle
.void
btnAddHexagonClicked(java.awt.event.MouseEvent click)
Called when user click to add newHexagon
.void
btnAddLineClicked(java.awt.event.MouseEvent click)
Called when user click to add newLine
.void
btnAddPointClicked(java.awt.event.MouseEvent click)
Called when user click to add newPoint
.void
btnAddRectangleClicked(java.awt.event.MouseEvent click)
Called when user click to add newRectangle
.void
btnAddSquareClicked(java.awt.event.MouseEvent click)
Called when user click to add newSquare
.void
btnDeleteShapeClicked()
Method is called when user want to delete some shape(s).java.awt.Color
btnEdgeColorClicked()
User clicked to choose edge color, show {@inheritDoc JColorChooser}.java.awt.Color
btnInteriorColorClicked()
User clicked to choose area color, show {@inheritDoc JColorChooser}.void
btnSelectShapeClicked(java.awt.event.MouseEvent click)
Called when user select some shape on a draw.void
btnUpdateCircleClicked(Circle oldCircle)
Method is called when user want to update some existingCircle
on a draw.void
btnUpdateHexagonClicked(HexagonAdapter oldHexagon)
Method is called when user want to update some existingHexagonAdapter
on a draw.void
btnUpdateLineClicked(Line oldLine)
Method is called when user want to update some existingLine
on draw.void
btnUpdatePointClicked(Point oldPoint)
Method is called when user want to update some existingPoint
on draw.void
btnUpdateRectangleClicked(Rectangle oldRectangle)
Method is called when user want to update some existingRectangle
on draw.void
btnUpdateSquareClicked(Square oldSquare)
Method is called when user want to update some existingSquare
on draw.void
executeCommand(Command command)
Method that execute some command.Shape
getSelectedShape()
Method that returns currently selected shape.void
handleSelect(java.lang.String s, java.lang.String command)
Count how many shapes are selected.void
handleSelectButtons()
Handle buttons state depend on number of selected shapes.void
newDraw()
Method that create new draw if draw is not already empty removing all executed shapes and comands.void
open()
Method that is obligate for displaying {@ JFileChooser} for user to choose file to open.void
redo()
Method that execute previously unexecuted command.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.void
toBack()
Method that call commandCmdToBack
which move some shape one position backward in the list of shapes if shape is not already at first position.void
toFront()
Method that call commandCmdToFront
which move some shape one position forward in the list of shapes if shape is not already at last position.void
undo()
Method that unexecute (undo) some command.void
updateShapeClicked()
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
- RepresentDrawingObserver
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
, addPoint
to that command and execute it. Fire change that now shape exist, repaintDrawingView
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
, addLine
to that command and execute it. Fire change that now shape exist, repaintDrawingView
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
, addSquare
to that command and execute it, ensuring thatSquare
don't go out of draw. Fire change that now shape exist, repaintDrawingView
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
, addRectangle
to that command and execute it, ensuring thatRectangle
don't go out of draw. Fire change that now shape exist, repaintDrawingView
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
, addCircle
to that command and execute it, ensuring thatCircle
don't go out of draw. Fire change that now shape exist, repaintDrawingView
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
, addHexagon
to that command and execute it, ensuring thatHexagon
don't go out of draw. Fire change that now shape exist, repaintDrawingView
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
andCmdToFront
). 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. ThenCmdUpdatePoint
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. ThenCmdUpdateLine
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. ThenCmdUpdateRectangle
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. ThenCmdUpdateSquare
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. ThenCmdUpdateCircle
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. ThenCmdUpdateHexagon
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 fromDrawingModel
to ObserverDrawingFrame
that updates buttons.- Parameters:
command
- Command that need to be executed.
-
undo
public void undo()
Method that unexecute (undo) some command.
Fire changes fromDrawingModel
to ObserverDrawingFrame
that updates buttons.- Parameters:
command
- Command that need to be unexecuted.
-
redo
public void redo()
Method that execute previously unexecuted command.
Fire changes fromDrawingModel
to ObserverDrawingFrame
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 appropriateFileManager
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 appropriateFileManager
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.
-
-