ptft
Class JPaintCellularAutomata

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byptft.JGrid
                      extended byptft.JCellularAutomata
                          extended byptft.JPtftCellularAutomata
                              extended byptft.JPaintCellularAutomata
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.lang.Runnable, java.io.Serializable

public class JPaintCellularAutomata
extends JPtftCellularAutomata
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

Adds the functionality of a simple paint program so that the user can paint cells a different strategy or ethnicity color.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  int m_activeEthnicity
           
protected  int m_activeStrategy
           
protected  java.awt.Cursor m_bucketCursor
           
protected  boolean[][] m_isFlooded
           
protected  boolean m_isMouseButtonPressed
           
protected  boolean m_isPaintModeEnabled
           
protected  boolean m_isPencil
           
protected  JPtftCell m_lastDrawnCell
           
protected  java.awt.Cursor m_pencilCursor
           
 
Fields inherited from class ptft.JPtftCellularAutomata
m_ethnicColors, m_isSegregated, m_isStrategyDisplayed, m_strategyColors
 
Fields inherited from class ptft.JCellularAutomata
m_payoffs, m_sleepDelay, m_thread
 
Fields inherited from class ptft.JGrid
innerPanel, m_cellPadding, m_cellWidth, m_columns, m_grid, m_rows, m_strategies
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
 
Constructor Summary
JPaintCellularAutomata()
          Creates new form JCellularAutomataPaint
 
Method Summary
protected  void drawCell(JPtftCell cell)
          Depending on whether we're viewing strategies or ethnicities, changes the cell's strategy or ethnicity to m_activeStrategy or m_activeEthnicity.
protected  void drawLine(JPtftCell c1, JPtftCell c2)
          Draws a line recursively connecting two cells
 void fillWithBucket(JPtftCell cell, int strategy, int ethnicity)
           
protected  void floodFill(JPtftCell cell, int fillColor, int oldColor, java.lang.String text)
          Fills regions of color "old" with the new color "fill" starting at the given coordinates
protected  JPtftCell getCell(java.awt.Point p)
          Returns the cell located at the pixel coordinate p.
 boolean isPaintModeEnabled()
           
 boolean isPencil()
           
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
protected  boolean sameColor(JPtftCell cell, int color)
           
 void setActiveEthnicity(int ethnicity)
          User-painting will be done with this ethnicity color
 void setActiveStrategy(int strategy)
          User-painting will be done with this strategy color
protected  void setCell(JPtftCell cell, int color)
           
 void setPaintMode(boolean isEnabled, boolean isPencil)
          enables paint mode
 
Methods inherited from class ptft.JPtftCellularAutomata
createCells, integrate, isSegregated, isStrategyDisplayed, playNeighbor, restart, segregate, setRandomEthnicities, setRandomEthnicities, toggleViews
 
Methods inherited from class ptft.JCellularAutomata
getWinningStrategy, isRunning, pause, playCell, playRound, playRound, run, setPayoffs, setSleepDelay, start
 
Methods inherited from class ptft.JGrid
createCells, getCell, getLeftColumn, getLowerRow, getNeighbor, getRightColumn, getTotalColumns, getTotalRows, getUpperRow, paintComponent, setBackground, setBorderColor, setGridColor, setLayout, setRandomStrategies, setRandomStrategies
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, transferFocusBackward, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_activeStrategy

protected int m_activeStrategy

m_activeEthnicity

protected int m_activeEthnicity

m_lastDrawnCell

protected JPtftCell m_lastDrawnCell

m_isPaintModeEnabled

protected boolean m_isPaintModeEnabled

m_isPencil

protected boolean m_isPencil

m_isMouseButtonPressed

protected boolean m_isMouseButtonPressed

m_pencilCursor

protected java.awt.Cursor m_pencilCursor

m_bucketCursor

protected java.awt.Cursor m_bucketCursor

m_isFlooded

protected boolean[][] m_isFlooded
Constructor Detail

JPaintCellularAutomata

public JPaintCellularAutomata()
Creates new form JCellularAutomataPaint

Method Detail

setPaintMode

public void setPaintMode(boolean isEnabled,
                         boolean isPencil)
enables paint mode


isPaintModeEnabled

public boolean isPaintModeEnabled()

isPencil

public boolean isPencil()

setActiveStrategy

public void setActiveStrategy(int strategy)
User-painting will be done with this strategy color


setActiveEthnicity

public void setActiveEthnicity(int ethnicity)
User-painting will be done with this ethnicity color


drawLine

protected void drawLine(JPtftCell c1,
                        JPtftCell c2)
Draws a line recursively connecting two cells

Parameters:
c1 - starting point of the line
c2 - ending point of the line

drawCell

protected void drawCell(JPtftCell cell)
Depending on whether we're viewing strategies or ethnicities, changes the cell's strategy or ethnicity to m_activeStrategy or m_activeEthnicity.

See Also:
setActiveStrategy(int), setActiveEthnicity(int), JPtftCellularAutomata.toggleViews()

getCell

protected JPtftCell getCell(java.awt.Point p)
Returns the cell located at the pixel coordinate p. This also helps us avoid missing mouse clicks that are in-between cells.


fillWithBucket

public void fillWithBucket(JPtftCell cell,
                           int strategy,
                           int ethnicity)

setCell

protected void setCell(JPtftCell cell,
                       int color)

sameColor

protected boolean sameColor(JPtftCell cell,
                            int color)

floodFill

protected void floodFill(JPtftCell cell,
                         int fillColor,
                         int oldColor,
                         java.lang.String text)
Fills regions of color "old" with the new color "fill" starting at the given coordinates

Parameters:
cell - starting cell for the flood fill
oldColor - color to paint with

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener