Kafenio.editor 0.8.5

de.xeinfach.kafenio.component
Class RelativeImageView

java.lang.Object
  extended byjavax.swing.text.View
      extended byde.xeinfach.kafenio.component.RelativeImageView
All Implemented Interfaces:
java.util.EventListener, java.awt.image.ImageObserver, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, javax.swing.SwingConstants

public class RelativeImageView
extends javax.swing.text.View
implements java.awt.image.ImageObserver, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

Description: creates a view on an image. This code was modeled after an article on JavaWorld by Bob Kenworthy.

Author:
Frits Jalvingh, Karsten Pawlik

Field Summary
static java.lang.String ABSMIDDLE
           
static java.lang.String BOTTOM
           
static java.lang.String CENTER
           
static java.lang.String IMAGE_CACHE_PROPERTY
           
static java.lang.String MIDDLE
           
static java.lang.String TEXTTOP
           
static java.lang.String TOP
           
 
Fields inherited from class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Fields inherited from interface javax.swing.SwingConstants
EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TRAILING, VERTICAL, WEST
 
Constructor Summary
RelativeImageView(javax.swing.text.Element elem)
          Constructor Creates a new view that represents an IMG element.
 
Method Summary
 void changedUpdate(javax.swing.event.DocumentEvent e, java.awt.Shape a, javax.swing.text.ViewFactory f)
          Attributes may have changed, so update.
 float getAlignment(int axis)
          Determines the desired alignment for this view along an axis.
 javax.swing.text.AttributeSet getAttributes()
          Fetches the attributes to use when rendering.
 int getBorder()
          Method returns the size of the border to use
 java.awt.Color getBorderColor()
          Method returns the border's color, or null if this is not a link
protected  java.awt.Color getHighlightColor()
           
 float getPreferredSpan(int axis)
          Determines the preferred span for this view along an axis.
protected  int getSelectionState()
          Determines whether the image is selected, and if it's the only thing selected.
 int getSpace(int axis)
          Method returns the amount of extra space to add along an axis
protected  javax.swing.text.html.StyleSheet getStyleSheet()
           
 float getVerticalAlignment()
          Method returns the image's vertical alignment
 boolean hasPixels(java.awt.image.ImageObserver obs)
          returns true if ImageObserver does have pixels, false if not.
 boolean imageUpdate(java.awt.Image img, int flags, int x, int y, int width, int height)
          updates the image.
protected  boolean isEditable()
           
 java.awt.Shape modelToView(int pos, java.awt.Shape a, javax.swing.text.Position.Bias b)
          Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.
 void mouseClicked(java.awt.event.MouseEvent me)
          On double-click, open image properties dialog.
 void mouseDragged(java.awt.event.MouseEvent e)
          Resize image if initial click was in grow-box:
 void mouseEntered(java.awt.event.MouseEvent me)
           
 void mouseExited(java.awt.event.MouseEvent me)
           
 void mouseMoved(java.awt.event.MouseEvent me)
           
 void mousePressed(java.awt.event.MouseEvent e)
          Select or grow image when clicked.
 void mouseReleased(java.awt.event.MouseEvent me)
          what to do when mouse is released.
 void paint(java.awt.Graphics g, java.awt.Shape a)
          Paints the image.
protected  void repaint(long delay)
          Request that this view be repainted.
protected  void resize(int width, int height)
          Change the size of this image.
 void setParent(javax.swing.text.View parent)
          Establishes the parent view for this view.
 int viewToModel(float x, float y, java.awt.Shape a, javax.swing.text.Position.Bias[] bias)
          Provides a mapping from the view coordinate space to the logical coordinate space of the model.
 
Methods inherited from class javax.swing.text.View
append, breakView, createFragment, forwardUpdate, forwardUpdateToView, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getMaximumSpan, getMinimumSpan, getNextVisualPositionFrom, getParent, getResizeWeight, getStartOffset, getToolTipText, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, insertUpdate, isVisible, modelToView, modelToView, preferenceChanged, remove, removeAll, removeUpdate, replace, setSize, updateChildren, updateLayout, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOP

public static final java.lang.String TOP
See Also:
Constant Field Values

TEXTTOP

public static final java.lang.String TEXTTOP
See Also:
Constant Field Values

MIDDLE

public static final java.lang.String MIDDLE
See Also:
Constant Field Values

ABSMIDDLE

public static final java.lang.String ABSMIDDLE
See Also:
Constant Field Values

CENTER

public static final java.lang.String CENTER
See Also:
Constant Field Values

BOTTOM

public static final java.lang.String BOTTOM
See Also:
Constant Field Values

IMAGE_CACHE_PROPERTY

public static final java.lang.String IMAGE_CACHE_PROPERTY
See Also:
Constant Field Values
Constructor Detail

RelativeImageView

public RelativeImageView(javax.swing.text.Element elem)
Constructor Creates a new view that represents an IMG element.

Parameters:
elem - the element to create a view for
Method Detail

getAttributes

public javax.swing.text.AttributeSet getAttributes()
Fetches the attributes to use when rendering. This is implemented to multiplex the attributes specified in the model with a StyleSheet.

Returns:
returns an AttributeSet containing the attributes.

getBorder

public int getBorder()
Method returns the size of the border to use

Returns:
returns the border width as int.

getSpace

public int getSpace(int axis)
Method returns the amount of extra space to add along an axis

Parameters:
axis - value of axis
Returns:
returns the space for the given axis value.

getBorderColor

public java.awt.Color getBorderColor()
Method returns the border's color, or null if this is not a link

Returns:
the border color.

getVerticalAlignment

public float getVerticalAlignment()
Method returns the image's vertical alignment

Returns:
vertical alignment as float

hasPixels

public boolean hasPixels(java.awt.image.ImageObserver obs)
returns true if ImageObserver does have pixels, false if not.

Parameters:
obs - an ImageObserver.
Returns:
returns true if ImageObserver does have pixels, false if not.

setParent

public void setParent(javax.swing.text.View parent)
Establishes the parent view for this view. Seize this moment to cache the AWT Container I'm in.

Parameters:
parent - the parent view

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent e,
                          java.awt.Shape a,
                          javax.swing.text.ViewFactory f)
Attributes may have changed, so update.

Parameters:
e - a DocumentEvent
a - a Shape
f - a ViewFactory

paint

public void paint(java.awt.Graphics g,
                  java.awt.Shape a)
Paints the image.

Parameters:
g - the rendering surface to use
a - the allocated region to render into
See Also:
View.paint(java.awt.Graphics, java.awt.Shape)

repaint

protected void repaint(long delay)
Request that this view be repainted. Assumes the view is still at its last-drawn location.

Parameters:
delay - delay before repainting.

getSelectionState

protected int getSelectionState()
Determines whether the image is selected, and if it's the only thing selected.

Returns:
0 if not selected, 1 if selected, 2 if exclusively selected. "Exclusive" selection is only returned when editable.

isEditable

protected boolean isEditable()
Returns:
returns true if container is editable, false otherwise.

getHighlightColor

protected java.awt.Color getHighlightColor()
Returns:
returns the text editor's highlight color.

imageUpdate

public boolean imageUpdate(java.awt.Image img,
                           int flags,
                           int x,
                           int y,
                           int width,
                           int height)
updates the image.

Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Parameters:
img - the image to update to
flags - flags to set
x - y-coordinate
y - y-coordinate
width - image width
height - image height
Returns:
returns true if update was successful, false otherwise.

getPreferredSpan

public float getPreferredSpan(int axis)
Determines the preferred span for this view along an axis.

Parameters:
axis - may be either X_AXIS or Y_AXIS
Returns:
the span the view would like to be rendered into. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.

getAlignment

public float getAlignment(int axis)
Determines the desired alignment for this view along an axis. This is implemented to give the alignment to the bottom of the icon along the y axis, and the default along the x axis.

Parameters:
axis - may be either X_AXIS or Y_AXIS
Returns:
the desired alignment. This should be a value between 0.0 and 1.0 where 0 indicates alignment at the origin and 1.0 indicates alignment to the full span away from the origin. An alignment of 0.5 would be the center of the view.

modelToView

public java.awt.Shape modelToView(int pos,
                                  java.awt.Shape a,
                                  javax.swing.text.Position.Bias b)
                           throws javax.swing.text.BadLocationException
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.

Parameters:
pos - the position to convert
a - the allocated region to render into
b - Position Bias
Returns:
the bounding box of the given position
Throws:
javax.swing.text.BadLocationException - if the given position does not represent a valid location in the associated document
See Also:
View.modelToView(int, java.awt.Shape)

viewToModel

public int viewToModel(float x,
                       float y,
                       java.awt.Shape a,
                       javax.swing.text.Position.Bias[] bias)
Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Parameters:
x - the X coordinate
y - the Y coordinate
a - the allocated region to render into
bias - Position Bias[]
Returns:
the location within the model that best represents the given point of view
See Also:
View.viewToModel(float, float, java.awt.Shape)

resize

protected void resize(int width,
                      int height)
Change the size of this image. This alters the HEIGHT and WIDTH attributes of the Element and causes a re-layout.


mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Select or grow image when clicked.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent to handle

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Resize image if initial click was in grow-box:

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - MouseEvent to handle

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent me)
what to do when mouse is released.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
me - MouseEvent to handle

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent me)
On double-click, open image properties dialog.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
me - MouseEvent to handle

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent me)
Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
me - MouseEvent to handle

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent me)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
me - MouseEvent to handle

mouseExited

public void mouseExited(java.awt.event.MouseEvent me)
Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
me - MouseEvent to handle

getStyleSheet

protected javax.swing.text.html.StyleSheet getStyleSheet()
Returns:
returns the stylesheet for this document

Kafenio.editor 0.8.5

Copyright © 2003-2004 by Karsten Pawlik. All Rights Reserved. Published under the Lesser General Public License (LGPL)