Region Class Reference

Inheritance diagram for Region:

ButtonRegion CompoundRegion GraphicsRegion ImageRegion PolygonalRegion TextRegion XMLRegion List of all members.

Public Member Functions

 Region (String name, double xInches, double yInches, double wInches, double hInches)
 For our American friends.
 Region (String theName, Shape s, Units u)
 Region (String name, Units x, Units y, Units w, Units h)
 We will convert all the units to x's type.
void addEventHandler (EventHandler handler)
 Keeps track of this event handler.
List< EventHandlergetEventHandlers ()
Color getFillColor ()
Units getHeight ()
String getIsActiveString ()
String getName ()
double getOpacity ()
Units getOriginX ()
Units getOriginY ()
Sheet getParentSheet ()
RegionRenderer getRenderer ()
 Subclasses should override this, to customize rendering.
double getScaleX ()
double getScaleY ()
Shape getShape ()
 Subclasses can modify the internal shape object.
Color getStrokeColor ()
Units getUnits ()
 TODO: We should make sure that Units objects immutable if possible.
Rectangle2D getUnscaledBounds2D ()
Units getUnscaledBoundsHeight ()
Units getUnscaledBoundsWidth ()
Shape getUnscaledShapeCopy ()
Units getWidth ()
boolean isActive ()
boolean isVisible ()
void resetScale ()
 Resets to the default scaling factors.
void scaleRegion (double sX, double sY)
 Scales the points in the current region by a horizontal and vertical multiplier.
void scaleRegionUniformly (double scale)
 Resizes the region uniformly in x and y.
void setActive (boolean isRegionActive)
void setFillColor (Color theFillColor)
void setName (String theName)
void setOpacity (double theOpacityFrom0To1)
void setParentSheet (Sheet sheet)
 For traversing up the UI hierarchy, in Event Visualizations.
void setScale (double newScaleX, double newScaleY)
 Replaces the scaling factors.
void setStrokeColor (Color strokeCol)
void setVisible (boolean v)
String toString ()
 Please override for more interesting output.

Protected Member Functions

 Region (String theName, Units u)
 A protected constructor so subclasses can assign the shape whichever way they please.
void setShape (Shape s)
 Subclasses can use this method to set the shape after constructing the object.

Protected Attributes

Units referenceUnits
 This is used only to interpret the shape's true physical size.
double scaleX = 1.0
 Internal horizontal scale of the region.
double scaleY = 1.0
 Internal vertical scale of the region.

Detailed Description

A region is defined by a Shape that outlines the region. Internally, the region remembers the Units that it is represented in. Thus, you may use whatever units pleases you.

Also, a region can be INPUT(REALTIME|BATCH), OUTPUT(REALTIME|INTERMITTENT), or STATIC. This is entirely determined by the type(s) of attachments (input event handlers, input filters, realtime outputs, print output) you add to a region. If you do not add anything, it is by default a STATIC region. For example, if you add an input event handler for a streaming pen, it becomes an INPUT(REALTIME) region. Regions that handle interactive input will automatically be overlaid with pattern when rendered to PDF or to a printer.

Regardless of whether the Shape is closed or not, we assume that all regions are closed Shapes. A rectangular region is represented using this class's Region(4 args) constructors.

This software is distributed under the BSD License.

Author:
Ron B Yeh (ronyeh(AT)cs.stanford.edu)

Definition at line 42 of file Region.java.


Constructor & Destructor Documentation

Region ( String  name,
double  xInches,
double  yInches,
double  wInches,
double  hInches 
)

For our American friends.

Parameters:
xInches 
yInches 
wInches 
hInches 

Definition at line 139 of file Region.java.

Region ( String  theName,
Shape  s,
Units  u 
)

Parameters:
name 
s the shape that defines this region.
u the reference unit for interpreting the shape's coordinates

Definition at line 151 of file Region.java.

References Region.referenceUnits.

Region ( String  theName,
Units  u 
) [protected]

A protected constructor so subclasses can assign the shape whichever way they please.

A Region doesn't really make sense without a shape, so use this constructor carefully (i.e., make sure to assign a sensible shape).

Parameters:
u 

Definition at line 164 of file Region.java.

References Region.referenceUnits.

Region ( String  name,
Units  x,
Units  y,
Units  w,
Units  h 
)

We will convert all the units to x's type.

Thus, if you pass in an Inch, Centimeter, Foot, Points, we will convert everything to Inches. It's OK to keep the x object around, because we only use it to interpret the shape object.

Parameters:
x 
y 
w 
h 

Definition at line 179 of file Region.java.

References Units.getValue(), and Units.getValueIn().


Member Function Documentation

void addEventHandler ( EventHandler  handler  ) 

Keeps track of this event handler.

The PaperToolkit will dispatch events to these, whenever the event deals with this region.

A particular kind of event handler can be thought of as a "content filter," which will grab input and "change" the meaning of the input in some way. The canonical example is the HandwritingRecognizer, as it will collect ink and then change it into ASCII text.

Parameters:
handler 

Definition at line 194 of file Region.java.

References EventHandler.addParentRegion().

Referenced by ButtonRegion.ButtonRegion(), and RegionComponent.RegionComponent().

List<EventHandler> getEventHandlers (  ) 

Returns:
the event engine will access the event handlers, to invoke events.

Definition at line 208 of file Region.java.

Referenced by EventEngine.handlePenEvent(), and SheetFrame.SheetFrame().

Color getFillColor (  ) 

Returns:

Definition at line 215 of file Region.java.

Referenced by RegionRenderer.renderToG2D().

Units getHeight (  ) 

Returns:
the height of the region (or its rectangular bounding box)

Definition at line 222 of file Region.java.

References Units.getUnitsObjectOfSameTypeWithValue(), Region.referenceUnits, and Region.scaleY.

Referenced by FlexiblePatternCoordinateConverter.FlexiblePatternCoordinateConverter(), RegionID.RegionID(), TextRenderer.renderToG2D(), SheetFrame.SheetFrame(), and SketchToPaperUI.translate().

String getIsActiveString (  ) 

Returns:

Definition at line 230 of file Region.java.

References Region.isActive().

Referenced by Region.toString().

String getName (  ) 

Returns:

Definition at line 237 of file Region.java.

Referenced by Sheet.addRegion(), PatternLocationToSheetLocationMapping.getPatternBoundsOfRegion(), FlexiblePatternCoordinateConverter.getRegionName(), RegionID.RegionID(), PatternLocationToSheetLocationMapping.setPatternInformationOfRegion(), SheetFrame.SheetFrame(), Region.toString(), and DebuggingEnvironment.visualize().

double getOpacity (  ) 

Returns:
how opaque this region's background will be. If it's 0, we will not render the background fillColor at all.

Definition at line 245 of file Region.java.

Referenced by RegionRenderer.renderToG2D().

Units getOriginX (  ) 

Returns:

Definition at line 252 of file Region.java.

References Units.getUnitsObjectOfSameTypeWithValue(), and Region.referenceUnits.

Referenced by RegionID.RegionID(), CompoundRenderer.renderToG2D(), SheetFrame.SheetFrame(), and CompoundRegion.toString().

Units getOriginY (  ) 

Returns:

Definition at line 259 of file Region.java.

References Units.getUnitsObjectOfSameTypeWithValue(), and Region.referenceUnits.

Referenced by RegionID.RegionID(), CompoundRenderer.renderToG2D(), SheetFrame.SheetFrame(), and CompoundRegion.toString().

RegionRenderer getRenderer (  ) 

Subclasses should override this, to customize rendering.

Otherwise, you'll just get gray boxes, which is what RegionRenderer does.

Returns:
the renderer for this region

Reimplemented in CompoundRegion, ImageRegion, PolygonalRegion, and TextRegion.

Definition at line 273 of file Region.java.

double getScaleX (  ) 

Returns:

Definition at line 285 of file Region.java.

References Region.scaleX.

Referenced by CompoundRegion.addChild(), RegionGroup.addRegion(), RegionRenderer.renderToG2D(), PolygonRenderer.renderToG2D(), ImageRenderer.renderToG2D(), and PolygonalRegion.toString().

double getScaleY (  ) 

Returns:

Definition at line 292 of file Region.java.

References Region.scaleY.

Referenced by CompoundRegion.addChild(), RegionGroup.addRegion(), RegionRenderer.renderToG2D(), PolygonRenderer.renderToG2D(), ImageRenderer.renderToG2D(), and PolygonalRegion.toString().

Shape getShape (  ) 

Subclasses can modify the internal shape object.

Returns:
the internal shape, at your peril.

Definition at line 301 of file Region.java.

Referenced by CompoundRegion.addChild(), RegionGroup.addRegion(), PolygonalRegion.getPolygonReference(), PolygonRenderer.renderToG2D(), and CompoundRegion.toString().

Units getUnits (  ) 

TODO: We should make sure that Units objects immutable if possible.

Returns:
a pointer to the actual units object.

Definition at line 314 of file Region.java.

References Region.referenceUnits.

Referenced by CompoundRegion.addChild(), RegionGroup.addRegion(), ImageRegion.ImageRegion(), RegionRenderer.renderToG2D(), PolygonRenderer.renderToG2D(), ImageRenderer.renderToG2D(), PolygonalRegion.toString(), and ImageRegion.toString().

Rectangle2D getUnscaledBounds2D (  ) 

Returns:
a bounds object that represents the UNSCALED internal shape.

Definition at line 321 of file Region.java.

Referenced by RegionRenderer.renderToG2D().

Units getUnscaledBoundsHeight (  ) 

Returns:

Definition at line 328 of file Region.java.

References Units.getUnitsObjectOfSameTypeWithValue(), and Region.referenceUnits.

Units getUnscaledBoundsWidth (  ) 

Returns:

Definition at line 335 of file Region.java.

References Units.getUnitsObjectOfSameTypeWithValue(), and Region.referenceUnits.

Shape getUnscaledShapeCopy (  ) 

Returns:
a copy of the internal shape as a Java2D GeneralPath. You should use this with getScaleX/Y to determine the true shape. Alternatively, use getScaledShapeCopy()

Definition at line 343 of file Region.java.

Units getWidth (  ) 

Returns:
the width of the region (or its rectangular bounding box).

Definition at line 350 of file Region.java.

References Units.getUnitsObjectOfSameTypeWithValue(), Region.referenceUnits, and Region.scaleX.

Referenced by FlexiblePatternCoordinateConverter.FlexiblePatternCoordinateConverter(), RegionID.RegionID(), TextRenderer.renderToG2D(), SheetFrame.SheetFrame(), and SketchToPaperUI.translate().

boolean isActive (  ) 

Returns:
if this region is an active (NON-STATIC) region. This means that upon rendering to PDF/Printer, pattern will be displayed over this region.

Definition at line 359 of file Region.java.

Referenced by Region.getIsActiveString().

boolean isVisible (  ) 

Returns:
whether the region will be visible. TODO: The renderer SHOULD respect this flag.

Definition at line 366 of file Region.java.

void scaleRegion ( double  sX,
double  sY 
)

Scales the points in the current region by a horizontal and vertical multiplier.

Parameters:
sX 
sY 

Definition at line 403 of file Region.java.

References Region.scaleX, and Region.scaleY.

Referenced by Region.scaleRegionUniformly().

void scaleRegionUniformly ( double  scale  ) 

Resizes the region uniformly in x and y.

We actually just store the number and scale it whenever we need to render the final region. The Lazy Approach. =) This is nice because we can scale the region multiple times without getting aliasing effects.

Parameters:
scale 

Definition at line 415 of file Region.java.

References Region.scaleRegion().

void setActive ( boolean  isRegionActive  ) 

Parameters:
isRegionActive determines whether this will be an active region or not

Definition at line 423 of file Region.java.

void setFillColor ( Color  theFillColor  ) 

Parameters:
theFillColor 

Definition at line 430 of file Region.java.

void setName ( String  theName  ) 

Parameters:
theName the name of the region. Name it something useful, like "Blue Button for Changing Pen Colors"

Definition at line 439 of file Region.java.

Referenced by ImageRegion.ImageRegion().

void setOpacity ( double  theOpacityFrom0To1  ) 

Parameters:
theOpacityFrom0To1 bounds checked from 0.0 to 1.0

Definition at line 447 of file Region.java.

void setParentSheet ( Sheet  sheet  ) 

For traversing up the UI hierarchy, in Event Visualizations.

Parameters:
sheet 

Definition at line 461 of file Region.java.

Referenced by Sheet.addRegion().

void setScale ( double  newScaleX,
double  newScaleY 
)

Replaces the scaling factors.

Parameters:
newScaleX 
newScaleY 

Definition at line 471 of file Region.java.

References Region.scaleX, and Region.scaleY.

Referenced by Region.resetScale().

void setShape ( Shape  s  )  [protected]

Subclasses can use this method to set the shape after constructing the object.

Parameters:
s 

Definition at line 481 of file Region.java.

Referenced by CompoundRegion.addChild(), ImageRegion.ImageRegion(), and TextRegion.TextRegion().

void setVisible ( boolean  v  ) 

Parameters:
v whether the region will be visible

Definition at line 493 of file Region.java.

String toString (  ) 

Please override for more interesting output.

This will print the name of the class along with all the segments of the shape.

See also:
java.lang.Object.toString()
Returns:
the String representation of this Region

Reimplemented in CompoundRegion, ImageRegion, PolygonalRegion, and TextRegion.

Definition at line 504 of file Region.java.

References Region.getIsActiveString(), Region.getName(), Units.getUnitName(), Region.referenceUnits, Region.scaleX, and Region.scaleY.

Referenced by RegionRenderer.renderToG2D().


Member Data Documentation

Units referenceUnits [protected]

This is used only to interpret the shape's true physical size.

The value of the units object doesn't matter. Only the type of the unit matters.

Definition at line 97 of file Region.java.

Referenced by Region.getHeight(), Region.getOriginX(), Region.getOriginY(), Region.getUnits(), Region.getUnscaledBoundsHeight(), Region.getUnscaledBoundsWidth(), Region.getWidth(), Region.Region(), TextRegion.TextRegion(), TextRegion.toString(), Region.toString(), and CompoundRegion.toString().

double scaleX = 1.0 [protected]

Internal horizontal scale of the region.

When rendering, we will multiply the shape by this scale. This is only a RECOMMENDATION and not a requirement of the renderer, however, as some regions may not make sense if scaled after the fact. However, we will try to make sure most of our calculations respect this scaling factor.

Definition at line 105 of file Region.java.

Referenced by Region.getScaleX(), Region.getWidth(), ImageRegion.getWidthVal(), Region.scaleRegion(), Region.setScale(), and Region.toString().

double scaleY = 1.0 [protected]

Internal vertical scale of the region.

When rendering, we will multiply the shape by this scale.

Definition at line 111 of file Region.java.

Referenced by Region.getHeight(), ImageRegion.getHeightVal(), Region.getScaleY(), Region.scaleRegion(), Region.setScale(), and Region.toString().


The documentation for this class was generated from the following file:
Generated on Sat Apr 14 18:21:42 2007 for R3 Paper Toolkit by  doxygen 1.4.7