jET
1.0beta1


org.jet.sce
Class BasicSceneryEditorUI

java.lang.Object
  |
  +--javax.swing.plaf.ComponentUI
        |
        +--org.jet.sce.SceneryEditorUI
              |
              +--org.jet.sce.BasicSceneryEditorUI
All Implemented Interfaces:
SceneryConstants

public class BasicSceneryEditorUI
extends SceneryEditorUI
implements SceneryConstants

This class defines basic behaviour for scenery editor.


Nested Class Summary
 class BasicSceneryEditorUI.HighlighterHandler
          Handles mouse events.
 class BasicSceneryEditorUI.KeyHandler
          Key listener.
 class BasicSceneryEditorUI.PropertyChangeHandler
          Property change listener listens component property changes.
 class BasicSceneryEditorUI.SceneryChangeHandler
          Scenery listener.
 class BasicSceneryEditorUI.SelectionHandler
          Scenery selection listener.
 class BasicSceneryEditorUI.ZoomInAction
          Zooming in action.
 class BasicSceneryEditorUI.ZoomOutAction
          Zooming out action.
 
Field Summary
static int NORMAL_MODE
          Normal mouse work mode.
protected  java.awt.Dimension preferredSize
          Dimension.
protected  JSceneryEditor sce
          Component.
static java.lang.String UI_CLASS_ID
          Class text represenataion.
static int ZOOM_MODE
          Zoom mouse work mode.
 
Fields inherited from interface org.jet.sce.SceneryConstants
PIXELS_PER_METER
 
Constructor Summary
BasicSceneryEditorUI()
          Default constructor.
 
Method Summary
protected  void completeUninstall()
          Last stage of uninstalling process.
protected  BasicSceneryEditorUI.HighlighterHandler createHighlighterListener()
          Creates object highlight listener.
protected  BasicSceneryEditorUI.KeyHandler createKeyListener()
          Creates key listener to listen to key.
protected  BasicSceneryEditorUI.PropertyChangeHandler createPropertyChangeListener()
          Creates property handler to handle property changes in the component.
protected  BasicSceneryEditorUI.SceneryChangeHandler createSceneryListener()
          Creates scenery listener to handle changes in the scenery.
protected  BasicSceneryEditorUI.SelectionHandler createScenerySelectionListener()
          Creates scenery selection listener.
static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
          Creates component UI for the component.
 EditorKit getEditorKit(JSceneryEditor sc)
          Gets an editor kit for component.
 java.awt.Dimension getMinimumSize(javax.swing.JComponent c)
          Gets the minimum size of the scenery editor.
 int getMouseMode()
          Returns mouse work mode.
 java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
          Gets a preferred size of component.
 java.awt.Color getSwitchColor()
          Gets the switch color.
 java.awt.Color getTrackColor()
          Gets the track color.
 java.awt.Color getTrackNamesColor()
          Gets track names color.
 boolean getTrackNamesVisibility()
          Gets track names visibility flag.
protected  void installCursors()
          Installs zoom cursor.
protected  void installDefaults()
          Installs defaults for the component (e.g. colors).
protected  void installImages()
          Installs images.
protected  void installKeyboardActions()
          Installs keyboard action for the scenery editor.
protected  void installListeners()
          Installs listeners for the component.
 void installUI(javax.swing.JComponent c)
          Installs defaults, listeners for component.
 java.awt.geom.Point2D modelToView(JSceneryEditor editor, javax.vecmath.Point3d p)
          Translates model coordinates to view coordinates for specfied scenery editor.
 void paint(java.awt.Graphics g, javax.swing.JComponent c)
          Paints a component c with graphic context g.
protected  void paintBackground(java.awt.Graphics g)
          Paints background for component.
protected  void paintForeground(java.awt.Graphics g)
          Draws tracks.
protected  void paintGrid(java.awt.Graphics g)
          Paints a grid for scenery editor.
protected  void paintHandles(java.awt.Graphics2D g2)
          Paints selection handlers if there is selection.
protected  void paintSelection(java.awt.Graphics2D g2)
          Paints selection.
protected  void paintSwitches(java.awt.Graphics2D g2)
          Paints switches.
protected  void paintTrackNames(java.awt.Graphics2D g2)
          Paints track names.
protected  void paintTracks(java.awt.Graphics2D g2)
          Paints tracks.
protected  void prepareToInstall()
          First stage of component installation.
 java.awt.geom.Rectangle2D queryMinMax()
          Returns rectangle that contains minimum X, maximum X, minimum Y, maximum Y values in model coordinates' layout, but the axes have view meaning.
protected  void setModel(Scenery s)
          Sets the model for this scenery editor user interface.
 void setMouseMode(int mode)
          Sets mouse work mode.
protected  void setSelectionModel(ScenerySelectionModel newSSM)
          Resets the selection model.
 void setSwitchColor(java.awt.Color c)
          Sets the switch color.
 void setTrackColor(java.awt.Color c)
          Sets the track color.
 void setTrackNamesColor(java.awt.Color c)
          Sets track names color.
 void setTrackNamesVisibility(boolean b)
          Sets the visibility of track names.
protected  boolean shouldDraw(java.awt.Rectangle rect, java.awt.Shape a)
          Determines if the shape should be drawn in clipping rectangle.
protected  TextBox transformNamedTrack(Track t)
          Computes text boxes for named tracks.
protected  java.awt.geom.CubicCurve2D[] transformSwitchToView(Switch sw)
          Transforms switch to two cubic curves.
protected  java.awt.geom.CubicCurve2D transformTrackToView(Track track)
          Transforms track to cubic curve.
protected  void uninstallKeyboardActions()
          Uninstalls keyboard actions.
protected  void uninstallListeners()
          Uninstalls listeners.
 void uninstallUI(javax.swing.JComponent c)
          Uninstalls user interface for a component.
protected  void updateCachedDisplay()
          Updates cached display, but it does not help much.
protected  void updateMinMaxInfo()
          Updates when necessary min-max information.
protected  void updatePreferredSize()
          Updates size for the component when data or scale changes.
 javax.vecmath.Point3d viewToModel(JSceneryEditor editor, java.awt.geom.Point2D p)
          Translates view coordinates (coordinates within GUI component) to model coordinates in three dimensonal space.
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UI_CLASS_ID

public static final java.lang.String UI_CLASS_ID
Class text represenataion.

See Also:
Constant Field Values

NORMAL_MODE

public static final int NORMAL_MODE
Normal mouse work mode. In this mode mouse operates to selected for track.

See Also:
Constant Field Values

ZOOM_MODE

public static final int ZOOM_MODE
Zoom mouse work mode. In this mode mouse operates to zoom in / zoom out scenery. It deos not select tracks.

See Also:
Constant Field Values

sce

protected JSceneryEditor sce
Component.


preferredSize

protected java.awt.Dimension preferredSize
Dimension.

Constructor Detail

BasicSceneryEditorUI

public BasicSceneryEditorUI()
Default constructor.

Method Detail

createUI

public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
Creates component UI for the component.

Parameters:
c - Component to create user interface object for.
Returns:
New BasicSceneryEditorUI.

installUI

public void installUI(javax.swing.JComponent c)
Installs defaults, listeners for component.

Overrides:
installUI in class javax.swing.plaf.ComponentUI
Parameters:
c - A component.

prepareToInstall

protected void prepareToInstall()
First stage of component installation.


installDefaults

protected void installDefaults()
Installs defaults for the component (e.g. colors).


installCursors

protected void installCursors()
Installs zoom cursor.


installImages

protected void installImages()
Installs images.


installListeners

protected void installListeners()
Installs listeners for the component.


createPropertyChangeListener

protected BasicSceneryEditorUI.PropertyChangeHandler createPropertyChangeListener()
Creates property handler to handle property changes in the component.


createSceneryListener

protected BasicSceneryEditorUI.SceneryChangeHandler createSceneryListener()
Creates scenery listener to handle changes in the scenery.


createHighlighterListener

protected BasicSceneryEditorUI.HighlighterHandler createHighlighterListener()
Creates object highlight listener.


createKeyListener

protected BasicSceneryEditorUI.KeyHandler createKeyListener()
Creates key listener to listen to key.


createScenerySelectionListener

protected BasicSceneryEditorUI.SelectionHandler createScenerySelectionListener()
Creates scenery selection listener.


installKeyboardActions

protected void installKeyboardActions()
Installs keyboard action for the scenery editor.


uninstallUI

public void uninstallUI(javax.swing.JComponent c)
Uninstalls user interface for a component.

Overrides:
uninstallUI in class javax.swing.plaf.ComponentUI
Parameters:
c - Component to uninstall (the same as in install).

completeUninstall

protected void completeUninstall()
Last stage of uninstalling process. It nullize all members.


uninstallListeners

protected void uninstallListeners()
Uninstalls listeners.


uninstallKeyboardActions

protected void uninstallKeyboardActions()
Uninstalls keyboard actions.


setModel

protected void setModel(Scenery s)
Sets the model for this scenery editor user interface.

Parameters:
s - The new scenery.

setSelectionModel

protected void setSelectionModel(ScenerySelectionModel newSSM)
Resets the selection model. The appropriate listeners are installed on the model.


getMouseMode

public int getMouseMode()
Returns mouse work mode.

Returns:
Code of mouse mode.
See Also:
NORMAL_MODE, ZOOM_MODE

setMouseMode

public void setMouseMode(int mode)
Sets mouse work mode.

Parameters:
mode - Code of mouse mode.

paint

public void paint(java.awt.Graphics g,
                  javax.swing.JComponent c)
Paints a component c with graphic context g.

Overrides:
paint in class javax.swing.plaf.ComponentUI
Parameters:
g - Graphic context.
c - The component to paint.

paintBackground

protected void paintBackground(java.awt.Graphics g)
Paints background for component. This method is invoken from paint function.

Parameters:
g - Graphic context.

paintGrid

protected void paintGrid(java.awt.Graphics g)
Paints a grid for scenery editor.

Parameters:
g - Graphic context.

paintForeground

protected void paintForeground(java.awt.Graphics g)
Draws tracks.

This method is not good. It isn't optimised at now.


paintTracks

protected void paintTracks(java.awt.Graphics2D g2)
Paints tracks. Separated for readability reason.


paintSwitches

protected void paintSwitches(java.awt.Graphics2D g2)
Paints switches. Separated for readability reason.


paintTrackNames

protected void paintTrackNames(java.awt.Graphics2D g2)
Paints track names.


paintSelection

protected void paintSelection(java.awt.Graphics2D g2)
Paints selection.


paintHandles

protected void paintHandles(java.awt.Graphics2D g2)
Paints selection handlers if there is selection. It paints also a base point.


updateCachedDisplay

protected void updateCachedDisplay()
Updates cached display, but it does not help much.


transformTrackToView

protected java.awt.geom.CubicCurve2D transformTrackToView(Track track)
Transforms track to cubic curve.

Parameters:
track - Original track from scenery.
Returns:
Cubic curve in component space.

transformSwitchToView

protected java.awt.geom.CubicCurve2D[] transformSwitchToView(Switch sw)
Transforms switch to two cubic curves.

Parameters:
sw - Original switch from scenery.
Returns:
Array of two cubic curves.

transformNamedTrack

protected TextBox transformNamedTrack(Track t)
Computes text boxes for named tracks.

Parameters:
t - Named track.
Returns:
Text box.

shouldDraw

protected boolean shouldDraw(java.awt.Rectangle rect,
                             java.awt.Shape a)
Determines if the shape should be drawn in clipping rectangle.


getPreferredSize

public java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
Gets a preferred size of component.

Overrides:
getPreferredSize in class javax.swing.plaf.ComponentUI
Parameters:
c - Component.
Returns:
Preferred size.

getMinimumSize

public java.awt.Dimension getMinimumSize(javax.swing.JComponent c)
Gets the minimum size of the scenery editor.

Default is (1200, 1200).

Overrides:
getMinimumSize in class javax.swing.plaf.ComponentUI
Returns:
Minimum size.

updatePreferredSize

protected void updatePreferredSize()
Updates size for the component when data or scale changes.


updateMinMaxInfo

protected void updateMinMaxInfo()
Updates when necessary min-max information.


getEditorKit

public EditorKit getEditorKit(JSceneryEditor sc)
Gets an editor kit for component.

Specified by:
getEditorKit in class SceneryEditorUI
Parameters:
sc - Scenery editor component.
Returns:
Editor kit.
See Also:
EditorKit

modelToView

public java.awt.geom.Point2D modelToView(JSceneryEditor editor,
                                         javax.vecmath.Point3d p)
Translates model coordinates to view coordinates for specfied scenery editor.

Specified by:
modelToView in class SceneryEditorUI
Parameters:
p - Point in model coordinates.
editor - Scenery editor.
Returns:
Point in component coordinates.

viewToModel

public javax.vecmath.Point3d viewToModel(JSceneryEditor editor,
                                         java.awt.geom.Point2D p)
Translates view coordinates (coordinates within GUI component) to model coordinates in three dimensonal space.

Specified by:
viewToModel in class SceneryEditorUI
Parameters:
editor - Editor.
p - Point in view coordinates.
Returns:
Point in model corrdinates.

queryMinMax

public java.awt.geom.Rectangle2D queryMinMax()
Returns rectangle that contains minimum X, maximum X, minimum Y, maximum Y values in model coordinates' layout, but the axes have view meaning.

Returned rectangle bounds scenery.

X variable of rectangle means maximum X, y variable means maximum Y. Width (negative value) of rectangle is a distance, between maxmium X and minimum X, so x + width equals minimum Y. Height (negative value) variable in rectangle is a distance between the maximum Y and the minimum Y, so y + height equals the minimum Y. You can easly obtain minimums and maximums using getMinX(), getMaxX(), getMinY() and getMaxY() rectangle's methods.

Returns:
Rectangle bound scenery.

setTrackColor

public void setTrackColor(java.awt.Color c)
Sets the track color.

Parameters:
c - New color of the track.

getTrackColor

public java.awt.Color getTrackColor()
Gets the track color.

Returns:
Current track color.

setSwitchColor

public void setSwitchColor(java.awt.Color c)
Sets the switch color.

Parameters:
c - New color of the switch.

getSwitchColor

public java.awt.Color getSwitchColor()
Gets the switch color.

Returns:
Current color of the switch.

setTrackNamesColor

public void setTrackNamesColor(java.awt.Color c)
Sets track names color.

Parameters:
c - The new color.

getTrackNamesColor

public java.awt.Color getTrackNamesColor()
Gets track names color.

Returns:
Current color of the track names.

setTrackNamesVisibility

public void setTrackNamesVisibility(boolean b)
Sets the visibility of track names.

Parameters:
b - If true, track names will be visible.

getTrackNamesVisibility

public boolean getTrackNamesVisibility()
Gets track names visibility flag.

Returns:
True, if track names are visible.

jET
1.0beta1