|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--org.artoflife.gui.population.PopulationView
Base class for JComponent-based views on a
Population
containing
Individual
s that have
org.artoflife.gp.paintable.PaintablePhenotype
s.
Individuals are represented in the view by
the image painted by their phenotype.
Fires ItemEvents when an Individual is clicked, and ActionEvents when an Individual is double-clicked. Maintains a list of selected Individuals, painting a border around when selected.
Manages addition, deletion, and changes of Individuals in the Population, repainting areas as necessary.
Dragging of Individuals within the view is also supported via
org.artoflife.gui.paintable.view.PopulationViewTransferHandler
and the JDK1.4 TransferHandler mechanism.
The positioning and painting
of Individuals is delegated to IndividualRecord
helpers that are used by an
org.artoflife.gui.paintable.view.IndividualRecordPositionPolicy
to manage pluggable positioning of Individuals within the view.
The default implementation uses VerticalFitnessPolicy
and
IndividualCachingRecord
.
Field Summary | |
protected java.awt.event.ActionListener |
actionListener
Support firing ActionEvents when double-click an Individual. |
static org.artoflife.gui.population.IndividualRecord |
currentDraggedIndividualRecord
Per VM reference to currently dragged IndividualRecord. |
static PopulationView |
currentDragSource
Per VM record of the current PopulationView that initiated a drag. |
static java.awt.Point |
dragOffset
Per VM record of the last offset of mouse press into Individual's image for drag tracking. |
protected java.awt.event.ItemListener |
itemListener
Support firing ItemEvents when click an Individual. |
protected Population |
population
View onto this population, may be null. |
protected java.util.ArrayList |
populationRecords
Ordered list of IndividualRecord s to describe the Individuals in
the population. |
protected RecordPositionPolicy |
positionPolicy
Helper to maintain IndividualRecord positions within the view. |
protected Individual[] |
selection
Array of length 1 if an Individual selected (only support single selection), or of length 0 if none selected, never null. |
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 | |
PopulationView()
Subclasses must call setPositionPolicy(RecordPositionPolicy) to
set a RecordPositionPolicy before letting this view run. |
Method Summary | |
void |
addActionListener(java.awt.event.ActionListener l)
|
void |
addItemListener(java.awt.event.ItemListener l)
|
void |
addNewIndividual(Individual individual,
java.awt.Point location)
Used by data transfer stuff to bring a new Individual into the population that this view manages. |
static void |
clearDragState()
Called at the end of a drag to reset the global (static) PopulationView drag state. |
protected org.artoflife.gui.population.IndividualRecord |
doIndividualAdded(Individual individual)
Add a new record for an Individual, working out its position and size using the position policy. |
protected org.artoflife.gui.population.IndividualRecord |
doIndividualChanged(Individual individual)
An individual changed so repaint over old position, update to new position etc. |
protected org.artoflife.gui.population.IndividualRecord |
doIndividualRemoved(Individual individual)
Remove the record for an Individual and clear the selection if it was just removed. |
protected int |
findEmptyRecordIndex(java.util.ArrayList records)
Utility for doIndividualAdded(Individual) . |
protected org.artoflife.gui.population.IndividualRecord |
findRecord(Individual individual)
|
protected int |
findRecordIndex(java.util.ArrayList records,
Individual individual)
Utility for doIndividualChanged(Individual)
and doIndividualRemoved(Individual) |
java.awt.Dimension |
getIndividualDimension(Individual individual)
For dragging images of individuals. |
Population |
getPopulation()
|
java.lang.Object[] |
getSelectedObjects()
|
void |
handleDragEnter()
Called when a drag enters the source PopulationView so that it can add back the selected Individual temporarily. |
void |
handleDragExit()
Called when a drag exits the source PopulationView so that it can remove the selected Individual temporarily. |
protected org.artoflife.gui.population.IndividualRecord |
individualRecordAt(java.util.ArrayList records,
int x,
int y)
|
protected org.artoflife.gui.population.IndividualRecord |
individualRecordAt(int x,
int y)
|
protected org.artoflife.gui.population.IndividualRecord |
makeRecordFor(Individual individual)
Default implementation returns an IndividualRecord but override
to change this. |
void |
mouseClicked(java.awt.event.MouseEvent e)
Fire ActionEvent when double-clicked an Individual. |
void |
mouseDragged(java.awt.event.MouseEvent e)
Recognise drags by looking for a MousePressed followed by MouseDrag for a certain time after the press. |
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)
Change selected and fire ItemEvent when pressed on an Individual. |
void |
mouseReleased(java.awt.event.MouseEvent e)
|
void |
paint(java.awt.Graphics graphics)
|
protected void |
paintIndividual(java.awt.Graphics2D g,
org.artoflife.gui.population.IndividualRecord record)
Paint the IndividualRecord if it falls within the graphics' clip region. |
void |
populationChanged(PopulationEvent event)
Repaint to reflect a change in population being viewed. |
protected void |
processActionEvent(java.awt.event.ActionEvent e)
|
protected void |
processItemEvent(java.awt.event.ItemEvent e)
|
void |
removeActionListener(java.awt.event.ActionListener l)
|
void |
removeItemListener(java.awt.event.ItemListener l)
|
protected void |
repositionForNewBounds(java.util.ArrayList records,
int x,
int y,
int width,
int height)
Utility. |
void |
select(Individual individual)
|
void |
setBounds(int x,
int y,
int width,
int height)
Override to calculate internal dimensions and reposition Individuals. |
void |
setPopulation(Population population)
|
void |
setPositionPolicy(RecordPositionPolicy policy)
|
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, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI |
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, setLayout, 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, 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 |
protected Population population
protected java.util.ArrayList populationRecords
IndividualRecord
s to describe the Individuals in
the population. Never null: if population is null this will be an empty
list.
protected Individual[] selection
protected transient java.awt.event.ItemListener itemListener
protected transient java.awt.event.ActionListener actionListener
protected RecordPositionPolicy positionPolicy
public static PopulationView currentDragSource
public static java.awt.Point dragOffset
public static org.artoflife.gui.population.IndividualRecord currentDraggedIndividualRecord
Constructor Detail |
public PopulationView()
setPositionPolicy(RecordPositionPolicy)
to
set a RecordPositionPolicy
before letting this view run.
Method Detail |
public void setPositionPolicy(RecordPositionPolicy policy)
policy
- a RecordPositionPolicy
for this view to use when positioning indiviuduals.public void setPopulation(Population population)
population
- that this view presents, may be nullpublic Population getPopulation()
public void populationChanged(PopulationEvent event)
populationChanged
in interface PopulationListener
event
- to respond toprotected org.artoflife.gui.population.IndividualRecord doIndividualAdded(Individual individual)
This calls makeRecordFor(Individual)
to create the record for
flexibility: the default uses an IndividualCachingRecord
.
individual
- whose record to be created and added
protected org.artoflife.gui.population.IndividualRecord makeRecordFor(Individual individual)
IndividualRecord
but override
to change this.
individual
- Individual to create a record for
* @return IndividualRecord a record for the Individualprotected org.artoflife.gui.population.IndividualRecord doIndividualRemoved(Individual individual)
individual
- whose record to be removed
protected org.artoflife.gui.population.IndividualRecord doIndividualChanged(Individual individual)
individual
- that changed
public void paint(java.awt.Graphics graphics)
paint
in class javax.swing.JComponent
JComponent.paint(java.awt.Graphics)
protected void paintIndividual(java.awt.Graphics2D g, org.artoflife.gui.population.IndividualRecord record)
public void setBounds(int x, int y, int width, int height)
setBounds
in class java.awt.Component
protected void repositionForNewBounds(java.util.ArrayList records, int x, int y, int width, int height)
protected int findEmptyRecordIndex(java.util.ArrayList records)
doIndividualAdded(Individual)
.
protected int findRecordIndex(java.util.ArrayList records, Individual individual)
doIndividualChanged(Individual)
and doIndividualRemoved(Individual)
individual
- the one to find (can be null)
protected org.artoflife.gui.population.IndividualRecord findRecord(Individual individual)
public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
public void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in interface java.awt.event.MouseMotionListener
public void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged
in interface java.awt.event.MouseMotionListener
public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
protected org.artoflife.gui.population.IndividualRecord individualRecordAt(int x, int y)
protected org.artoflife.gui.population.IndividualRecord individualRecordAt(java.util.ArrayList records, int x, int y)
public void addItemListener(java.awt.event.ItemListener l)
addItemListener
in interface java.awt.ItemSelectable
public void removeItemListener(java.awt.event.ItemListener l)
removeItemListener
in interface java.awt.ItemSelectable
protected void processItemEvent(java.awt.event.ItemEvent e)
public java.lang.Object[] getSelectedObjects()
getSelectedObjects
in interface java.awt.ItemSelectable
ItemSelectable.getSelectedObjects()
public void select(Individual individual)
public void addActionListener(java.awt.event.ActionListener l)
public void removeActionListener(java.awt.event.ActionListener l)
protected void processActionEvent(java.awt.event.ActionEvent e)
public static void clearDragState()
public void handleDragExit()
public void handleDragEnter()
public void addNewIndividual(Individual individual, java.awt.Point location) throws IncompatibleGenotypeException
individual
- the new individual to bring into the population
IncompatibleGenotypeException
public java.awt.Dimension getIndividualDimension(Individual individual)
|
artoflife pre0.1.0-dev | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |