shady.common
Class Environment

java.lang.Object
  extended by shady.common.Environment
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MultiEnvironment

public class Environment
extends java.lang.Object
implements java.io.Serializable

An environment in which Shady can play.

An environment is a set of Segments.

Copyright (C) 2006 Marsette A. Vona, III

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Author:
Marsette (Marty) A. Vona, III
See Also:
Serialized Form

Field Summary
protected  boolean boundsDirty
          Whether we need to recomputeBounds().
protected  double centerX
          The center x coord in this environment, 0.0 if isEmpty().
protected  double centerY
          The center y coord in this environment, 0.0 if isEmpty().
private static java.lang.String cvsid
          CVS id.
static double DEFAULT_BAR_WIDTH
          The bar width, in meters, in Stata 34-376.
static double DEFAULT_COLUMN_WIDTH
          The pane column width, bar center to bar center, in meters, in Stata 34-376.
static double DEFAULT_MAX_LOWER_ROW_HEIGHT
          The max lower pane row height, midbar center to lower bar top, in meters, in Stata 34-376.
static double DEFAULT_MIN_LOWER_ROW_HEIGHT
          The min lower pane row height, midbar center to lower bar top, in meters, in Stata 34-376.
static int DEFAULT_NUM_PANE_COLUMNS
          The number of pane columns in Stata 34-376.
static double DEFAULT_UPPER_ROW_HEIGHT
          The upper pane row height, midbar center to ceiling, in meters, in Stata 34-376.
protected  double height
          The height of this environment, 0.0 if isEmpty().
protected  java.util.Vector listeners
          The currently registered EnvironmentListeners.
 boolean lockBounds
          Whether to lock the bounds variables at their current values.
protected  double maxX
          The maximum x coordinate in this environment, 0.0 if isEmpty().
protected  double maxY
          The maximum y coordinate in this environment, 0.0 if isEmpty().
protected  double minX
          The minimum x coordinate in this environment, 0.0 if isEmpty().
protected  double minY
          The minimum y coordinate in this environment, 0.0 if isEmpty().
protected  java.util.Vector segments
          The Segments in this Environment.
protected  double width
          The width of this environment, 0.0 if isEmpty().
 
Constructor Summary
Environment()
          Covers Environment(double), uses a default exclude.
Environment(double exclude)
          Makes a default environment that models the window in Stata 34-376.
Environment(Segment[] segment)
          Make a new Environment.
 
Method Summary
 void addListener(EnvironmentListener l)
          Add an EnvironmentListener.
 int addSegment(double startX, double startY, double endX, double endY)
          Add a new segment at the end of the list.
 void clearSegments()
          Remove all segments from this Environment.
 java.util.Enumeration enumerateSegments()
          Get an Enumeration over the segments.
protected  void fireEnvironmentChanged()
          Fire an EnvironmentListener.environmentChanged(shady.common.Environment) to all our listeners.
 double getCenterX()
          Get center x coord in this environment.
 double getCenterY()
          Get center y coord in this environment.
 double getHeight()
          Get the height of this environment.
 double getMaxX()
          Get the maximum x coordinate in this environment.
 double getMaxY()
          Get the maximum y coordinate in this environment.
 double getMinX()
          Get the minimum x coordinate in this environment.
 double getMinY()
          Get the minimum y coordinate in this environment.
 Segment getSegment(int index)
          Get a Segment.
 double getWidth()
          Get the width of this environment.
 boolean isEmpty()
          Check if there are no Segments in this envrionment.
protected  void makeDefaultEnvironment(double exclude)
          Makes a default environment to model the window in Stata 34-376.
 void moveSegment(int index, double startX, double startY, double endX, double endY)
          Move the Segment at index.
 int numSegments()
          Get the number of Segments in this Environment.
 int pick(Point p, double threshold)
          Covers pick(Point, double, Point.OnSegment), does not collect nearest point.
 int pick(Point p, double threshold, Point.OnSegment nearest)
          Covers pick(Point, double, Point.OnSegment, Vector), does not collect all points within threshold.
 int pick(Point p, double threshold, Point.OnSegment nearest, java.util.Vector all)
          Find one or more Point.OnSegments in this Environment closer than threshold to p.
 void recomputeBounds()
          Recompute the bounds of this Environment iff not lockBounds.
 Segment removeLastSegment()
          Remove the segment with the highest index.
 boolean removeListener(EnvironmentListener l)
          Remove an EnvironmentListener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cvsid

private static final java.lang.String cvsid

CVS id.

See Also:
Constant Field Values

DEFAULT_NUM_PANE_COLUMNS

public static final int DEFAULT_NUM_PANE_COLUMNS

The number of pane columns in Stata 34-376.

See Also:
Constant Field Values

DEFAULT_BAR_WIDTH

public static final double DEFAULT_BAR_WIDTH

The bar width, in meters, in Stata 34-376.

See Also:
Constant Field Values

DEFAULT_COLUMN_WIDTH

public static final double DEFAULT_COLUMN_WIDTH

The pane column width, bar center to bar center, in meters, in Stata 34-376.

See Also:
Constant Field Values

DEFAULT_UPPER_ROW_HEIGHT

public static final double DEFAULT_UPPER_ROW_HEIGHT

The upper pane row height, midbar center to ceiling, in meters, in Stata 34-376.

See Also:
Constant Field Values

DEFAULT_MIN_LOWER_ROW_HEIGHT

public static final double DEFAULT_MIN_LOWER_ROW_HEIGHT

The min lower pane row height, midbar center to lower bar top, in meters, in Stata 34-376.

See Also:
Constant Field Values

DEFAULT_MAX_LOWER_ROW_HEIGHT

public static final double DEFAULT_MAX_LOWER_ROW_HEIGHT

The max lower pane row height, midbar center to lower bar top, in meters, in Stata 34-376.

See Also:
Constant Field Values

segments

protected java.util.Vector segments

The Segments in this Environment.


listeners

protected java.util.Vector listeners

The currently registered EnvironmentListeners.


boundsDirty

protected boolean boundsDirty

Whether we need to recomputeBounds().


minX

protected double minX

The minimum x coordinate in this environment, 0.0 if isEmpty().


minY

protected double minY

The minimum y coordinate in this environment, 0.0 if isEmpty().


maxX

protected double maxX

The maximum x coordinate in this environment, 0.0 if isEmpty().


maxY

protected double maxY

The maximum y coordinate in this environment, 0.0 if isEmpty().


width

protected double width

The width of this environment, 0.0 if isEmpty().


height

protected double height

The height of this environment, 0.0 if isEmpty().


centerX

protected double centerX

The center x coord in this environment, 0.0 if isEmpty().


centerY

protected double centerY

The center y coord in this environment, 0.0 if isEmpty().


lockBounds

public boolean lockBounds

Whether to lock the bounds variables at their current values.

Constructor Detail

Environment

public Environment()

Covers Environment(double), uses a default exclude.


Environment

public Environment(double exclude)

Makes a default environment that models the window in Stata 34-376.

Parameters:
exclude - see makeDefaultEnvironment(double)

Environment

public Environment(Segment[] segment)

Make a new Environment.

Parameters:
segment - the set of Segments, not null, a copy is made
Method Detail

recomputeBounds

public void recomputeBounds()

Recompute the bounds of this Environment iff not lockBounds.


isEmpty

public boolean isEmpty()

Check if there are no Segments in this envrionment.

Returns:
true if there are no Segments in this envrionment

numSegments

public int numSegments()

Get the number of Segments in this Environment.

Returns:
the number of Segments in this Environment

getSegment

public Segment getSegment(int index)

Get a Segment.

Parameters:
index - the 0-based index of the segment in the range [0, numSegments())
Returns:
the indicated Segment

enumerateSegments

public java.util.Enumeration enumerateSegments()

Get an Enumeration over the segments.

Returns:
an Enumeration over the segments

getMinX

public double getMinX()

Get the minimum x coordinate in this environment.

Returns:
the minimum x coordinate in this environment, 0.0 if isEmpty()

getMinY

public double getMinY()

Get the minimum y coordinate in this environment.

Returns:
the minimum y coordinate in this environment, 0.0 if isEmpty()

getMaxX

public double getMaxX()

Get the maximum x coordinate in this environment.

Returns:
the maximum x coordinate in this environment, 0.0 if isEmpty()

getMaxY

public double getMaxY()

Get the maximum y coordinate in this environment.

Returns:
the maximum y coordinate in this environment, 0.0 if isEmpty()

getWidth

public double getWidth()

Get the width of this environment.

Returns:
the width of this environment, 0.0 if isEmpty()

getHeight

public double getHeight()

Get the height of this environment.

Returns:
the height of this environment, 0.0 if isEmpty()

getCenterX

public double getCenterX()

Get center x coord in this environment.

Returns:
the center x coord in this environment, 0.0 if isEmpty()

getCenterY

public double getCenterY()

Get center y coord in this environment.

Returns:
the center y coord in this environment, 0.0 if isEmpty()

pick

public int pick(Point p,
                double threshold,
                Point.OnSegment nearest,
                java.util.Vector all)

Find one or more Point.OnSegments in this Environment closer than threshold to p.

Parameters:
p - the pick point
threshold - the distance threshold in meters, negative for no threshold
nearest - if non-null the nearest point closer than threshold will be written here on return. If non-null and no points are within range, the segment of this Point.OnSegment will be null on return.
all - if non-null then all points closer than threshold are collected here
Returns:
the index of the nearest Segment in this Environment closer than threshold or negative if none

pick

public int pick(Point p,
                double threshold,
                Point.OnSegment nearest)

Covers pick(Point, double, Point.OnSegment, Vector), does not collect all points within threshold.


pick

public int pick(Point p,
                double threshold)

Covers pick(Point, double, Point.OnSegment), does not collect nearest point.


clearSegments

public void clearSegments()

Remove all segments from this Environment.

A EnvironmentListener.environmentChanged(shady.common.Environment) event will be fired to all registered listeners.


removeLastSegment

public Segment removeLastSegment()

Remove the segment with the highest index.

A EnvironmentListener.environmentChanged(shady.common.Environment) event will be fired to all registered listeners.

Returns:
the removed segment or null if none

addSegment

public int addSegment(double startX,
                      double startY,
                      double endX,
                      double endY)

Add a new segment at the end of the list.

A EnvironmentListener.environmentChanged(shady.common.Environment) event will be fired to all registered listeners.

Parameters:
startX - the start X coord of the segment in meters
startY - the start Y coord of the segment in meters
endX - the end X coord of the segment in meters
endY - the end Y coord of the segment in meters
Returns:
the new number of segments

moveSegment

public void moveSegment(int index,
                        double startX,
                        double startY,
                        double endX,
                        double endY)

Move the Segment at index.

A EnvironmentListener.environmentChanged(shady.common.Environment) event will be fired to all registered listeners.

Parameters:
index - the zero-based index of the segment to move
startX - the new start X coord of the segment in meters
startY - the new start Y coord of the segment in meters
endX - the new end X coord of the segment in meters
endY - the new end Y coord of the segment in meters

addListener

public void addListener(EnvironmentListener l)

Add an EnvironmentListener.

Parameters:
l - the listener to add

removeListener

public boolean removeListener(EnvironmentListener l)

Remove an EnvironmentListener.

Parameters:
l - the listener to remove
Returns:
true iff the listener existed

fireEnvironmentChanged

protected void fireEnvironmentChanged()

Fire an EnvironmentListener.environmentChanged(shady.common.Environment) to all our listeners.


makeDefaultEnvironment

protected void makeDefaultEnvironment(double exclude)

Makes a default environment to model the window in Stata 34-376.

Metrics are taken from the various DEFAULT_ constants.

Parameters:
exclude - the amount to exclude, in meters, at the end of segments