Package doodlepad
Class Pad
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Iterable<Shape>
,Accessible
,RootPaneContainer
,WindowConstants
A class that implements a drawing surface and window for graphical shapes.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Interface for the dispatch method with a signature having no parametes.static interface
Interface used by methods that assign key event handlers given a method reference as a parameter.static interface
Interface used by methods that assign key typed event handlers given a method reference as a parameter.static interface
Interface used by methods that assign mouse event handlers given a method reference as a parameter.static interface
Interface used by methods that assign timer event handlers given a method reference as a parameter.Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.Type
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
-
Field Summary
Fields inherited from class javax.swing.JFrame
accessibleContext, rootPane, rootPaneCheckingEnabled
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
-
Constructor Summary
ConstructorDescriptionPad
(int width, int height) Simple Pad constructor taking only window dimensionsSimple Pad constructor taking only title and window dimensionsSimple Pad constructor taking only window dimensionsConstructor for objects of class PadConstructor for objects of class Pad -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add object to the list of items that are notified on Pad's key events.int
addLayer()
Create and add a new Layer to the Pad`s layersvoid
Add object to the list of items that are notified on Pad's mouse events.void
Add a shape to the shapes listvoid
Add object to the list of items that are notified on Pad's timer tick action.void
Broadcast a message to all open network connections.void
clear()
Remove all shapes from the Padvoid
close()
Close the Pad as if by clicking the [X] close button.void
Close all open network connections.void
closeConnection
(int id) Close the identified network connection.boolean
connectionExists
(int id) Returns true of a connection exists with the idstatic void
create()
Create a new Pad object, properly invoking on the event dispatch thread.static void
create
(int width, int height) Create a new Pad object, properly invoking on the event dispatch thread.static void
Create a new Pad object, properly invoking on the event dispatch thread.protected void
finalize()
Free all resources when Pad object is garbage collected.Return the current background color used to clear the PadReturn the set of current connection Ids.static Layer
Get the default layer for the Pad.boolean
Return the current value of the immediateMode flagCollect and return all IPv4 addresses for this computerCollect and return all IPv6 addresses for this computergetLayer
(int idx) Get the named Layer from the layers Mapint
Return the number of open network connections.static Pad
getPad()
A static method that creates a new Pad singleton object or returns the current Pad singleton object.int
Return the current height of the drawing areaint
Return the current width of the drawing areaReturn an ArrayList of Shape objects currently managed by the Pad instancefinal double
Return the current rate at which the timer tickslong
Return the milliseconds since midnight, January 1, 1970 UTC.Clone the Pad's default Layer AffineTransform.void
Invoke a method on the GUI event dispatch threadboolean
Determine if the timer is runningiterator()
Return an iterator for loop over Shapesvoid
onClientClosed
(int id) Invoked when a client connection is closedvoid
onClientError
(int id, String msg) Invoked when a connected client socket has has errorvoid
onClientInfo
(int id, String msg) Invoked when a connected client socket has some information to sharevoid
onClientOpened
(int id) Invoked when a new client connection opensvoid
onClientReceived
(int id, String msg) Invoked when a connected client socket receives a messagevoid
onKeyPressed
(String keyText, String keyModifiers) A method that can be overridden to handle key pressed eventsvoid
onKeyReleased
(String keyText, String keyModifiers) A method that can be overridden to handle key released eventsvoid
onKeyTyped
(char keyChar) A method that can be overridden to handle key typed eventsvoid
onMouseClicked
(double x, double y, int button) A method that can be overridden to handle mouse clicked events.void
onMouseDoubleClicked
(double x, double y, int button) A method that can be overridden to handle mouse double-clicked events.void
onMouseDragged
(double x, double y, int button) A method that can be overridden to handle mouse dragged events.void
onMouseEntered
(double x, double y, int button) A method that can be overridden to handle mouse entered eventsvoid
onMouseExited
(double x, double y, int button) A method that can be overridden to handle mouse exited eventsvoid
onMouseMoved
(double x, double y, int button) A method that can be overridden to handle mouse moved eventsvoid
onMousePressed
(double x, double y, int button) A method that can be overridden to handle mouse pressed eventsvoid
onMouseReleased
(double x, double y, int button) A method that can be overridden to handle mouse released eventsvoid
onServerError
(String msg) Invoked when the listening server has an errorvoid
onServerInfo
(String msg) Invoked when the listening server has some information to sharevoid
Invoked when the listening server startsvoid
Invoked when the listening server stops and all connections are closedvoid
onTick
(long when) A method that can be overridden to handle the Pad timer`s tick event.int
openConnection
(String host, int port) Open a connection with a listening socket server.void
redraw()
Force a redraw of all Shapesvoid
Remove object from Pad's key listener list.void
removeLayer
(int idx) Remove a Layer given the layer index.void
Remove object from Pad's mouse listener list.void
removeShape
(Shape s) Remove a shape from the shapes listvoid
Remove object from Pad's timer tick action listener list.void
repaint()
Override Component repaint methodvoid
reset()
Resets the Pad to have no transformation.void
rotate
(double angle) Add a rotation angle to Pad transform.void
rotate
(double angle, double cx, double cy) Add a rotation angle to Pad transform.void
scale
(double factor) Add a scale factor to Pad transform.void
scale
(double xFactor, double yFactor) Add a scale factor to Pad transform.void
scale
(double factor, double cx, double cy) Add a scale factor to Pad transform.void
scale
(double xFactor, double yFactor, double cx, double cy) Add a scale factor to Pad transform.void
Send a message to the client given a connection id.void
setBackground
(double gray) Set the background color for the Pad to a gray valuevoid
setBackground
(double red, double green, double blue) Set the background color for the Padvoid
setEventsEnabled
(boolean enabled) Enable or disable add Pad events.void
setImmediateMode
(boolean mode) Set the immediateMode flagvoid
Assign an onKeyPressed event handler using a method reference.void
Assign an onKeyReleased event handler using a method reference.void
Assign an onKeyTyped event handler using a method reference.void
Assign an onMouseClicked event handler using a method reference.void
Assign an onMouseDoubleClicked event handler using a method reference.void
Assign an onMouseDragged event handler using a method reference.void
Assign an onMouseEntered event handler using a method reference.void
Assign an onMouseExited event handler using a method reference.void
Assign an onMouseMoved event handler using a method reference.void
Assign an onMousePressed event handler using a method reference.void
Assign an onMouseReleased event handler using a method reference.void
setTickHandler
(Pad.PadTimerEventHandler handler) Assign an onTick event handler using a method reference.final void
setTickRate
(double tps) Set the rate at which to fire onTick eventsvoid
setTransform
(AffineTransform transform) Set a new AffineTransform for the Pad's default Layer.void
startListening
(int port) Start listening for new network connection requests.void
Start the timer firing onTick events.void
Stop listening for new network connection requests.void
Stop timervoid
Move shape to the back of diagramvoid
Move shape to the front of diagram.void
Toggle the state of the timer.double[]
toWindowCoords
(double x, double y) Convert transformed Pad coordinates to window coordinates returned as a new Point2D object.toWindowCoords
(Point pt) Convert transformed Pad coordinates in a Point2D object to window coordinates returned as a new Point2D object.void
translate
(double deltaX, double deltaY) Add a translate to Pad transform.Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFront
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
-
Constructor Details
-
Pad
public Pad(int width, int height) Simple Pad constructor taking only window dimensions- Parameters:
width
- The width of the windowheight
- The height of the window
-
Pad
Simple Pad constructor taking only title and window dimensions- Parameters:
title
- The Pad window titlewidth
- The width of the windowheight
- The height of the window
-
Pad
Simple Pad constructor taking only window dimensions- Parameters:
title
- The Pad window titlewidth
- The width of the windowheight
- The height of the windowsingleton
- True if this Pad object is to be set to the internal singleton
-
Pad
Constructor for objects of class Pad- Parameters:
title
- The Pad window titlewidth
- The width of the windowheight
- The height of the windowbackground
- The default color of the background
-
Pad
Constructor for objects of class Pad- Parameters:
title
- The Pad window titlewidth
- The width of the windowheight
- The height of the windowbackground
- The default color of the backgroundsingleton
- True if this Pad object is to be set to the internal singleton
-
-
Method Details
-
create
public static void create()Create a new Pad object, properly invoking on the event dispatch thread. -
create
public static void create(int width, int height) Create a new Pad object, properly invoking on the event dispatch thread.- Parameters:
width
- The width of the windowheight
- The height of the window
-
create
Create a new Pad object, properly invoking on the event dispatch thread.- Parameters:
title
- The Pad window titlewidth
- The width of the windowheight
- The height of the window
-
getPad
A static method that creates a new Pad singleton object or returns the current Pad singleton object. Ensures that only one singleton is created by synchronizing execution.- Returns:
- The current Pad singleton object
-
getDefaultLayer
Get the default layer for the Pad.- Returns:
- Default shape Layer.
-
addLayer
public int addLayer()Create and add a new Layer to the Pad`s layers- Returns:
- idx The new Layer`s index
-
removeLayer
public void removeLayer(int idx) Remove a Layer given the layer index. Do nothing when index of Layer is 0, the default Layer- Parameters:
idx
- Index of Layer to remove.
-
getLayer
Get the named Layer from the layers Map- Parameters:
idx
- The index of the Layer- Returns:
- Layer at index idx
-
close
public void close()Close the Pad as if by clicking the [X] close button. -
finalize
Free all resources when Pad object is garbage collected. -
getPadWidth
public int getPadWidth()Return the current width of the drawing area- Returns:
- Width of the drawing area
-
getPadHeight
public int getPadHeight()Return the current height of the drawing area- Returns:
- Height of the drawing area
-
setBackground
public void setBackground(double red, double green, double blue) Set the background color for the Pad- Parameters:
red
- The background color red componentgreen
- The background color green componentblue
- The background color blue component
-
setBackground
public void setBackground(double gray) Set the background color for the Pad to a gray value- Parameters:
gray
- The background gray scale
-
getBackground
Return the current background color used to clear the Pad- Overrides:
getBackground
in classWindow
- Returns:
- Color object used for the Pad background
-
getShapes
Return an ArrayList of Shape objects currently managed by the Pad instance- Returns:
- An ArrayList<Shape> of all Shapes being managed
-
iterator
Return an iterator for loop over Shapes -
repaint
public void repaint()Override Component repaint method -
redraw
public void redraw()Force a redraw of all Shapes -
addShape
Add a shape to the shapes list- Parameters:
s
- The Shape object to add to the Pad
-
removeShape
Remove a shape from the shapes list- Parameters:
s
- The Shape to remove
-
clear
public void clear()Remove all shapes from the Pad -
setEventsEnabled
public void setEventsEnabled(boolean enabled) Enable or disable add Pad events.- Parameters:
enabled
- True to enable. False to disable
-
setImmediateMode
public void setImmediateMode(boolean mode) Set the immediateMode flag- Parameters:
mode
- true or false
-
getImmediateMode
public boolean getImmediateMode()Return the current value of the immediateMode flag- Returns:
- Gets the Pad's immediate mode state. If true, all graphical updates will trigger and redraw. If false, not draw will happen until redraw() is called explicitly.
-
getTimeStamp
public long getTimeStamp()Return the milliseconds since midnight, January 1, 1970 UTC.- Returns:
- Milliseconds since midnight, January 1, 1970 UTC.
-
setTickRate
public final void setTickRate(double tps) Set the rate at which to fire onTick events- Parameters:
tps
- Ticks per second
-
getTickRate
public final double getTickRate()Return the current rate at which the timer ticks- Returns:
- A double indicating ticks per second.
-
addTickListener
Add object to the list of items that are notified on Pad's timer tick action.- Parameters:
o
- An object that implements the ActionListener interface.
-
removeTickListener
Remove object from Pad's timer tick action listener list.- Parameters:
o
- The ActionListener object to be removed.
-
startTimer
public void startTimer()Start the timer firing onTick events. -
stopTimer
public void stopTimer()Stop timer -
toggleTimer
public void toggleTimer()Toggle the state of the timer. Started/Stopped. -
isRunning
public boolean isRunning()Determine if the timer is running- Returns:
- True or false indicating if the timer is running.
-
addMouseListener
Add object to the list of items that are notified on Pad's mouse events.- Parameters:
o
- The PadMouseListener object to be added.
-
removeMouseListener
Remove object from Pad's mouse listener list.- Parameters:
o
- The PadMouseListener object to be removed.
-
addKeyListener
Add object to the list of items that are notified on Pad's key events.- Parameters:
o
- The PadKeyListener object to be added.
-
removeKeyListener
Remove object from Pad's key listener list.- Parameters:
o
- The PadKeyListener object to be removed.
-
setMouseClickedHandler
Assign an onMouseClicked event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setMouseDoubleClickedHandler
Assign an onMouseDoubleClicked event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setMouseDraggedHandler
Assign an onMouseDragged event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setMouseEnteredHandler
Assign an onMouseEntered event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setMouseExitedHandler
Assign an onMouseExited event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setMouseMovedHandler
Assign an onMouseMoved event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setMousePressedHandler
Assign an onMousePressed event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setMouseReleasedHandler
Assign an onMouseReleased event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setKeyPressedHandler
Assign an onKeyPressed event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setKeyReleasedHandler
Assign an onKeyReleased event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setKeyTypedHandler
Assign an onKeyTyped event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
setTickHandler
Assign an onTick event handler using a method reference.- Parameters:
handler
- Method reference to an event handler
-
toFront
Move shape to the front of diagram. Assumes Shape is on default layer 0.- Parameters:
s
- The Shape to bring to the front of the display list.
-
toBack
Move shape to the back of diagram- Parameters:
s
- The Shape to move to the back of the display list.
-
rotate
public void rotate(double angle) Add a rotation angle to Pad transform.- Parameters:
angle
- Adds the rotation angle to the current transform (degrees)
-
rotate
public void rotate(double angle, double cx, double cy) Add a rotation angle to Pad transform.- Parameters:
angle
- Adds the rotation angle to the current transform (degrees)cx
- x-coordinate of point about which rotation occurscy
- y-coordinate of point about which rotation occurs
-
translate
public void translate(double deltaX, double deltaY) Add a translate to Pad transform.- Parameters:
deltaX
- Translate shape in the x-direction by deltaXdeltaY
- Translate shape in the y-direction by deltaY
-
scale
public void scale(double factor) Add a scale factor to Pad transform.- Parameters:
factor
- Scale the shape by a scale factor
-
scale
public void scale(double factor, double cx, double cy) Add a scale factor to Pad transform.- Parameters:
factor
- Scale the shape by a scale factorcx
- x-coordinate of point about which scaling occurscy
- y-coordinate of point about which scaling occurs
-
scale
public void scale(double xFactor, double yFactor) Add a scale factor to Pad transform.- Parameters:
xFactor
- Scale the shape in the x-direction by a xFactoryFactor
- Scale the shape in the y-direction by a yFactor
-
scale
public void scale(double xFactor, double yFactor, double cx, double cy) Add a scale factor to Pad transform.- Parameters:
xFactor
- Scale the shape in the x-direction by a xFactoryFactor
- Scale the shape in the y-direction by a yFactorcx
- x-coordinate of point about which scaling occurscy
- y-coordinate of point about which scaling occurs
-
reset
public void reset()Resets the Pad to have no transformation. -
getTransform
Clone the Pad's default Layer AffineTransform.- Returns:
- The cloned AffineTransform.
-
setTransform
Set a new AffineTransform for the Pad's default Layer.- Parameters:
transform
- The new transform.
-
toWindowCoords
public double[] toWindowCoords(double x, double y) Convert transformed Pad coordinates to window coordinates returned as a new Point2D object. This method is useful for converting transformed coordinates received from a Pad mouse event method back to original window coordinates.- Parameters:
x
- Transformed x-coordinatey
- Transformed y-coordinate- Returns:
- A Point2D object containing the transformed coordinates
-
toWindowCoords
Convert transformed Pad coordinates in a Point2D object to window coordinates returned as a new Point2D object. This method is useful for converting transformed coordinates received from a Pad mouse event method back to original window coordinates.- Parameters:
pt
- A Point object- Returns:
- A new Point object containing the transformed coordinates
-
startListening
public void startListening(int port) Start listening for new network connection requests.- Parameters:
port
- The port on which to listen.
-
stopListening
public void stopListening()Stop listening for new network connection requests. -
openConnection
Open a connection with a listening socket server.- Parameters:
host
- The host name to connect with.port
- The port number on the host through which to connect.- Returns:
- id of the open socket
-
connectionExists
public boolean connectionExists(int id) Returns true of a connection exists with the id- Parameters:
id
- A unique integer id identifying the connection.- Returns:
- A boolean indicating whether or not the connection exists.
-
getConnectionIds
Return the set of current connection Ids.- Returns:
- A Set<Integer> holding all current connection Ids.
-
send
Send a message to the client given a connection id.- Parameters:
id
- The id of the connection.msg
- The message to send.
-
broadcast
Broadcast a message to all open network connections.- Parameters:
msg
- The message to broadcast.
-
closeConnection
public void closeConnection(int id) Close the identified network connection.- Parameters:
id
- ID of the connection to close.
-
closeAllConnections
public void closeAllConnections()Close all open network connections. -
getNumConnections
public int getNumConnections()Return the number of open network connections.- Returns:
- Number of open connections.
-
getIPv4Addresses
Collect and return all IPv4 addresses for this computer- Returns:
- List<String> of IPv4 addresses
- Throws:
SocketException
- May throw SocketExceptions
-
getIPv6Addresses
Collect and return all IPv6 addresses for this computer- Returns:
- List<String> of IPv6 addresses
- Throws:
SocketException
- May throw SocketExceptions
-
invokeOnDispatch
Invoke a method on the GUI event dispatch thread- Parameters:
meth
- A method implementing the DispatchMethodNoParameters interface, which is a method taking no parameters.
-
onServerStarted
public void onServerStarted()Invoked when the listening server starts -
onServerStopped
public void onServerStopped()Invoked when the listening server stops and all connections are closed -
onServerInfo
Invoked when the listening server has some information to share- Parameters:
msg
- A message containing information to share
-
onServerError
Invoked when the listening server has an error- Parameters:
msg
- A message containing the error message
-
onClientOpened
public void onClientOpened(int id) Invoked when a new client connection opens- Parameters:
id
- Unique id for the client connection
-
onClientClosed
public void onClientClosed(int id) Invoked when a client connection is closed- Parameters:
id
- Unique of the client id that is closed
-
onClientReceived
Invoked when a connected client socket receives a message- Parameters:
id
- Unique client idmsg
- Message String received
-
onClientInfo
Invoked when a connected client socket has some information to share- Parameters:
id
- Unique client idmsg
- Message from the client
-
onClientError
Invoked when a connected client socket has has error- Parameters:
id
- Unique client idmsg
- Error message from the client
-
onKeyTyped
public void onKeyTyped(char keyChar) A method that can be overridden to handle key typed events- Parameters:
keyChar
- The char of the key typed
-
onKeyPressed
A method that can be overridden to handle key pressed events- Parameters:
keyText
- Text of the key pressedkeyModifiers
- Special keys pressed
-
onKeyReleased
A method that can be overridden to handle key released events- Parameters:
keyText
- Text of the key pressedkeyModifiers
- Special keys pressed
-
onMousePressed
public void onMousePressed(double x, double y, int button) A method that can be overridden to handle mouse pressed events- Parameters:
x
- x-locationy
- y-locationbutton
- The button pressed
-
onMouseReleased
public void onMouseReleased(double x, double y, int button) A method that can be overridden to handle mouse released events- Parameters:
x
- x-locationy
- y-locationbutton
- The button pressed
-
onMouseClicked
public void onMouseClicked(double x, double y, int button) A method that can be overridden to handle mouse clicked events. A mouse clicked event is composed of a mouse pressed event followed by a mouse released event at the same mouse location.- Parameters:
x
- x-locationy
- y-locationbutton
- The button pressed
-
onMouseDoubleClicked
public void onMouseDoubleClicked(double x, double y, int button) A method that can be overridden to handle mouse double-clicked events.- Parameters:
x
- x-locationy
- y-locationbutton
- The button pressed
-
onMouseEntered
public void onMouseEntered(double x, double y, int button) A method that can be overridden to handle mouse entered events- Parameters:
x
- x-locationy
- y-locationbutton
- The button pressed
-
onMouseExited
public void onMouseExited(double x, double y, int button) A method that can be overridden to handle mouse exited events- Parameters:
x
- x-locationy
- y-locationbutton
- The button pressed
-
onMouseMoved
public void onMouseMoved(double x, double y, int button) A method that can be overridden to handle mouse moved events- Parameters:
x
- x-locationy
- y-locationbutton
- The button pressed
-
onMouseDragged
public void onMouseDragged(double x, double y, int button) A method that can be overridden to handle mouse dragged events. A mouse dragged event is the same as a mouse moved event while the mouse is pressed.- Parameters:
x
- x-locationy
- y-locationbutton
- The button pressed
-
onTick
public void onTick(long when) A method that can be overridden to handle the Pad timer`s tick event. The timer tick rate is set with the setTickRate() method. The timer is started by invoking the startTimer() method. The timer is stopped by invoking the stopTimer() method.- Parameters:
when
- The difference in milliseconds between the timestamp of when this event occurred and midnight, January 1, 1970 UTC.
-