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
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for the dispatch method with a signature having no parametes.static interfaceInterface used by methods that assign key event handlers given a method reference as a parameter.static interfaceInterface used by methods that assign key typed event handlers given a method reference as a parameter.static interfaceInterface used by methods that assign mouse event handlers given a method reference as a parameter.static interfaceInterface 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.AccessibleJFrameNested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrameNested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.TypeNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested 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, rootPaneCheckingEnabledFields 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_CURSORFields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE -
Constructor Summary
ConstructorsConstructorDescriptionPad(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 TypeMethodDescriptionvoidAdd object to the list of items that are notified on Pad's key events.intaddLayer()Create and add a new Layer to the Pad`s layersvoidAdd object to the list of items that are notified on Pad's mouse events.voidAdd a shape to the shapes listvoidAdd object to the list of items that are notified on Pad's timer tick action.voidBroadcast a message to all open network connections.voidclear()Remove all shapes from the Padvoidclose()Close the Pad as if by clicking the [X] close button.voidClose all open network connections.voidcloseConnection(int id) Close the identified network connection.booleanconnectionExists(int id) Returns true of a connection exists with the idstatic voidcreate()Create a new Pad object, properly invoking on the event dispatch thread.static voidcreate(int width, int height) Create a new Pad object, properly invoking on the event dispatch thread.static voidCreate a new Pad object, properly invoking on the event dispatch thread.protected voidfinalize()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 LayerGet the default layer for the Pad.booleanReturn 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 MapintReturn the number of open network connections.static PadgetPad()A static method that creates a new Pad singleton object or returns the current Pad singleton object.intReturn the current height of the drawing areaintReturn the current width of the drawing areaReturn an ArrayList of Shape objects currently managed by the Pad instancefinal doubleReturn the current rate at which the timer tickslongReturn the milliseconds since midnight, January 1, 1970 UTC.Clone the Pad's default Layer AffineTransform.voidInvoke a method on the GUI event dispatch threadbooleanDetermine if the timer is runningiterator()Return an iterator for loop over ShapesvoidonClientClosed(int id) Invoked when a client connection is closedvoidonClientError(int id, String msg) Invoked when a connected client socket has has errorvoidonClientInfo(int id, String msg) Invoked when a connected client socket has some information to sharevoidonClientOpened(int id) Invoked when a new client connection opensvoidonClientReceived(int id, String msg) Invoked when a connected client socket receives a messagevoidonKeyPressed(String keyText, String keyModifiers) A method that can be overridden to handle key pressed eventsvoidonKeyReleased(String keyText, String keyModifiers) A method that can be overridden to handle key released eventsvoidonKeyTyped(char keyChar) A method that can be overridden to handle key typed eventsvoidonMouseClicked(double x, double y, int button) A method that can be overridden to handle mouse clicked events.voidonMouseDoubleClicked(double x, double y, int button) A method that can be overridden to handle mouse double-clicked events.voidonMouseDragged(double x, double y, int button) A method that can be overridden to handle mouse dragged events.voidonMouseEntered(double x, double y, int button) A method that can be overridden to handle mouse entered eventsvoidonMouseExited(double x, double y, int button) A method that can be overridden to handle mouse exited eventsvoidonMouseMoved(double x, double y, int button) A method that can be overridden to handle mouse moved eventsvoidonMousePressed(double x, double y, int button) A method that can be overridden to handle mouse pressed eventsvoidonMouseReleased(double x, double y, int button) A method that can be overridden to handle mouse released eventsvoidonServerError(String msg) Invoked when the listening server has an errorvoidonServerInfo(String msg) Invoked when the listening server has some information to sharevoidInvoked when the listening server startsvoidInvoked when the listening server stops and all connections are closedvoidonTick(long when) A method that can be overridden to handle the Pad timer`s tick event.intopenConnection(String host, int port) Open a connection with a listening socket server.voidredraw()Force a redraw of all ShapesvoidRemove object from Pad's key listener list.voidremoveLayer(int idx) Remove a Layer given the layer index.voidRemove object from Pad's mouse listener list.voidremoveShape(Shape s) Remove a shape from the shapes listvoidRemove object from Pad's timer tick action listener list.voidrepaint()Override Component repaint methodvoidreset()Resets the Pad to have no transformation.voidrotate(double angle) Add a rotation angle to Pad transform.voidrotate(double angle, double cx, double cy) Add a rotation angle to Pad transform.voidscale(double factor) Add a scale factor to Pad transform.voidscale(double xFactor, double yFactor) Add a scale factor to Pad transform.voidscale(double factor, double cx, double cy) Add a scale factor to Pad transform.voidscale(double xFactor, double yFactor, double cx, double cy) Add a scale factor to Pad transform.voidSend a message to the client given a connection id.voidsetBackground(double gray) Set the background color for the Pad to a gray valuevoidsetBackground(double red, double green, double blue) Set the background color for the PadvoidsetEventsEnabled(boolean enabled) Enable or disable add Pad events.voidsetImmediateMode(boolean mode) Set the immediateMode flagvoidAssign an onKeyPressed event handler using a method reference.voidAssign an onKeyReleased event handler using a method reference.voidAssign an onKeyTyped event handler using a method reference.voidAssign an onMouseClicked event handler using a method reference.voidAssign an onMouseDoubleClicked event handler using a method reference.voidAssign an onMouseDragged event handler using a method reference.voidAssign an onMouseEntered event handler using a method reference.voidAssign an onMouseExited event handler using a method reference.voidAssign an onMouseMoved event handler using a method reference.voidAssign an onMousePressed event handler using a method reference.voidAssign an onMouseReleased event handler using a method reference.voidsetTickHandler(Pad.PadTimerEventHandler handler) Assign an onTick event handler using a method reference.final voidsetTickRate(double tps) Set the rate at which to fire onTick eventsvoidsetTransform(AffineTransform transform) Set a new AffineTransform for the Pad's default Layer.voidstartListening(int port) Start listening for new network connection requests.voidStart the timer firing onTick events.voidStop listening for new network connection requests.voidStop timervoidMove shape to the back of diagramvoidMove shape to the front of diagram.voidToggle 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.voidtranslate(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, updateMethods 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, setUndecoratedMethods 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, toFrontMethods 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, validateTreeMethods 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, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods 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:
getBackgroundin 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.
-