jET
1.0beta1


org.jet.sce
Class JSceneryEditor

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--org.jet.sce.JSceneryEditor
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.Scrollable, java.io.Serializable

public class JSceneryEditor
extends javax.swing.JComponent
implements javax.swing.Scrollable

Scenery editor for jET application.

The goal of this component is separating data model and user interface. It should be developed in Model-View-Controller pattern and it should have generalized form, similar to Swing text components.

See Also:
Serialized Form

Field Summary
static java.lang.String BASEPOINT_PROPERTY
          Bound property name for base point.
static java.lang.String EDITABLE_PROPERTY
          Bound property name for editing.
static java.lang.String GRID_VISIBLE_PROPERTY
          Bound property name for grid.
static java.lang.String SCALE_PROPERTY
          Bound property name for scale.
protected  Scenery scenery
          Data model.
static java.lang.String SCENERY_MODEL_PROPERTY
          Bound property name for scenery.
static java.lang.String SCENERY_SELECTION_PROPERTY
          Bound property name for scenery selection model.
protected  ScenerySelectionModel selectionModel
          Selection model.
 
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
JSceneryEditor()
          Creates new scenery editor with blank scenery.
JSceneryEditor(Scenery scenery)
          Creates new scenery editor with given scenery.
 
Method Summary
 void addScenerySelectionListener(ScenerySelectionListener l)
          Adds selection listener.
 void centerViewAt(java.awt.geom.Point2D p)
          Scrolls the viewport which includes this scenery editor to show specified point at its center.
 void clearSelection()
          Clears selection.
protected  ScenerySelectionModel createSelectionModel()
          Creates default selection model for this editor.
 BasePoint getBasePoint()
          Gets base point.
 java.awt.Color getGridColor()
          Returns color of the grid.
 int getMaxUnitIncrement()
          Gets max unit incrementation when editor is in the scroll pane.
 java.awt.Dimension getPreferredScrollableViewportSize()
          Gets preferred viewport size for this component when it is inside scroll pane.
 double getScale()
          Gets scenery editor scale.
 Scenery getScenery()
          Gets scenery of this scenery editor.
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Gets pixels of block increment in scroll pane.
 boolean getScrollableTracksViewportHeight()
          Returns false.
 boolean getScrollableTracksViewportWidth()
          Returns false.
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Gets amount of pixels of unit incremeny in scroll pane.
 java.lang.Object getSelectedObject()
          Gets the current selection.
 ScenerySelectionModel getSelectionModel()
          Gets the selection model for this scenery editor.
 SceneryEditorUI getUI()
          Gets user insterface object for this component.
 java.lang.String getUIClassID()
          Gets user interface class name.
 boolean isEditable()
          Returns true when editor is editable.
 boolean isGridEnabled()
          Returns true if grid is enabled.
 boolean isSelectionEmpty()
          Determines if selection is empty.
 java.awt.geom.Point2D modelToView(javax.vecmath.Point3d p)
          Translates model coordinates to component cooridantes.
 void read(java.io.Reader in)
          Reads scenery from reader stream.
 void removeScenerySelectionListener(ScenerySelectionListener l)
          Removes selection listener.
 void setBasePoint(BasePoint bp)
          Sets base point.
 void setEditable(boolean b)
          Sets edit ability of scenery editor.
 void setGridColor(java.awt.Color color)
          Sets color for the grid.
 void setGridEnabled(boolean b)
          If set to true, the grid will is active.
 void setMaxUnitIncrement(int pixels)
          Sets max unit incrementation when editor is in the scroll pane.
 void setScale(double newScale)
          Sets new scale for scenery editor.
 void setScenery(Scenery newScenery)
          Sets a scenery for scenery editor.
 void setSelectedObject(java.lang.Object obj)
          Sets the selection.
 void setSelectionModel(ScenerySelectionModel sm)
          Sets the selection model for this scenery editor.
 void setUI(SceneryEditorUI ui)
          Sets user interface of this component to user interface manager.
 void updateUI()
          Updates user interface manager with a user interface of this component.
 javax.vecmath.Point3d viewToModel(java.awt.geom.Point2D p)
          Translates view coordinates to model coordinates.
 void write(java.io.Writer out)
          Writes scenery to file.
 
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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, 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
 
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, 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

SCALE_PROPERTY

public static final java.lang.String SCALE_PROPERTY
Bound property name for scale.

See Also:
Constant Field Values

GRID_VISIBLE_PROPERTY

public static final java.lang.String GRID_VISIBLE_PROPERTY
Bound property name for grid.

See Also:
Constant Field Values

EDITABLE_PROPERTY

public static final java.lang.String EDITABLE_PROPERTY
Bound property name for editing.

See Also:
Constant Field Values

SCENERY_MODEL_PROPERTY

public static final java.lang.String SCENERY_MODEL_PROPERTY
Bound property name for scenery.

See Also:
Constant Field Values

SCENERY_SELECTION_PROPERTY

public static final java.lang.String SCENERY_SELECTION_PROPERTY
Bound property name for scenery selection model.

See Also:
Constant Field Values

BASEPOINT_PROPERTY

public static final java.lang.String BASEPOINT_PROPERTY
Bound property name for base point.

See Also:
Constant Field Values

scenery

protected Scenery scenery
Data model.


selectionModel

protected ScenerySelectionModel selectionModel
Selection model.

Constructor Detail

JSceneryEditor

public JSceneryEditor()
Creates new scenery editor with blank scenery.


JSceneryEditor

public JSceneryEditor(Scenery scenery)
Creates new scenery editor with given scenery.

Parameters:
scenery - Scenery.
See Also:
Scenery
Method Detail

getUI

public SceneryEditorUI getUI()
Gets user insterface object for this component.

Returns:
User interface for scenery editor.

setUI

public void setUI(SceneryEditorUI ui)
Sets user interface of this component to user interface manager.

Parameters:
ui - User interface to set.

updateUI

public void updateUI()
Updates user interface manager with a user interface of this component.

Overrides:
updateUI in class javax.swing.JComponent

getUIClassID

public java.lang.String getUIClassID()
Gets user interface class name.

Overrides:
getUIClassID in class javax.swing.JComponent
Returns:
String containing user interface class name.

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Gets preferred viewport size for this component when it is inside scroll pane.

Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable
Returns:
Dimension of preferred viewport.

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Gets pixels of block increment in scroll pane.

Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Returns false.

Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Returns false.

Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Gets amount of pixels of unit incremeny in scroll pane.

Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable

setMaxUnitIncrement

public void setMaxUnitIncrement(int pixels)
Sets max unit incrementation when editor is in the scroll pane.

Parameters:
pixels - amount of pixels to scroll.

getMaxUnitIncrement

public int getMaxUnitIncrement()
Gets max unit incrementation when editor is in the scroll pane.

Returns:
Incrementation amount in pixels.

isEditable

public boolean isEditable()
Returns true when editor is editable.

Returns:
True if editable.

setEditable

public void setEditable(boolean b)
Sets edit ability of scenery editor.

Parameters:
b - If true, editor will be editable.

isGridEnabled

public boolean isGridEnabled()
Returns true if grid is enabled.


setGridEnabled

public void setGridEnabled(boolean b)
If set to true, the grid will is active.


getGridColor

public java.awt.Color getGridColor()
Returns color of the grid.


setGridColor

public void setGridColor(java.awt.Color color)
Sets color for the grid.


getScenery

public Scenery getScenery()
Gets scenery of this scenery editor.

Scenery is a data model for this component.

Returns:
A scenery of this editor.
See Also:
Scenery

setScenery

public void setScenery(Scenery newScenery)
Sets a scenery for scenery editor.

Scenery is a data model for this component.

Parameters:
newScenery - A new scenery for this editor.
See Also:
Scenery

createSelectionModel

protected ScenerySelectionModel createSelectionModel()
Creates default selection model for this editor.

Returns:
Selection model to use for this editor.

setSelectionModel

public void setSelectionModel(ScenerySelectionModel sm)
Sets the selection model for this scenery editor.

Parameters:
sm - Scenery selection model.

getSelectionModel

public ScenerySelectionModel getSelectionModel()
Gets the selection model for this scenery editor.

Returns:
Scenery selection model.

clearSelection

public void clearSelection()
Clears selection.


isSelectionEmpty

public boolean isSelectionEmpty()
Determines if selection is empty.

Returns:
True, if selection is empty.

getSelectedObject

public java.lang.Object getSelectedObject()
Gets the current selection.

Returns:
Selected object.

setSelectedObject

public void setSelectedObject(java.lang.Object obj)
Sets the selection.

Parameters:
obj - Object to select.

addScenerySelectionListener

public void addScenerySelectionListener(ScenerySelectionListener l)
Adds selection listener.

Parameters:
l - Scenery selection listener.

removeScenerySelectionListener

public void removeScenerySelectionListener(ScenerySelectionListener l)
Removes selection listener.

Parameters:
l - Scenery selection listener to remove.

getBasePoint

public BasePoint getBasePoint()
Gets base point.

Returns:
Base point or null when there is no base point.

setBasePoint

public void setBasePoint(BasePoint bp)
Sets base point. Note that this method notifies registered property listeners.

Parameters:
bp - New base point.
See Also:
BASEPOINT_PROPERTY

read

public void read(java.io.Reader in)
          throws java.io.IOException
Reads scenery from reader stream.

Parameters:
in - Reader to read.
Throws:
java.io.IOException - Thrown when some I/O errors occured.

write

public void write(java.io.Writer out)
           throws java.io.IOException
Writes scenery to file.

Parameters:
out - Output to write.
Throws:
java.io.IOException - Thrown when some I/O errors occured.

modelToView

public java.awt.geom.Point2D modelToView(javax.vecmath.Point3d p)
Translates model coordinates to component cooridantes.

Parameters:
p - 3D point.
Returns:
Point in component coordiantes.

viewToModel

public javax.vecmath.Point3d viewToModel(java.awt.geom.Point2D p)
Translates view coordinates to model coordinates.

Parameters:
p - Point in view.
Returns:
3D point in model coordinates.

centerViewAt

public void centerViewAt(java.awt.geom.Point2D p)
Scrolls the viewport which includes this scenery editor to show specified point at its center.

Parameters:
p - Point to be shown.

setScale

public void setScale(double newScale)
Sets new scale for scenery editor. Scale must be in range >= 0 and <= 1. Method fires a property change SCALE_PROPERTY.

Parameters:
newScale - New scale.

getScale

public double getScale()
Gets scenery editor scale.

Returns:
Scale of scenery editor. Scale is in range >=0 and <= 1.

jET
1.0beta1