|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.visuals.LabelView
public class LabelView
LabelView is a class that displays lines of text. The text can be
single or multiline. The text can also be horizontally or vertically
aligned.
Notes:
//use default constructor
LabelView labelView1 = new LabelView();
labelView1.setText("labelView");
//or set text in constructor
LabelView labelView2 = new LabelView("labelView");
//Intialize layout manager
//This labelView component will be the specified Preferred size of 150 x 200 with word wrapping.
//The true in the AutoSizingGridLayout specifies FillCell.
Container container1 = new Container();
container1.setLayout( new AutoSizingGridLayout( 0, 1, 10 ,10 , true, false, false) );
LabelView label1 = new LabelView();
label1.initialize();
label1.setPreferredSize( new java.awt.Dimension( 150, 200 ));
label1.setText("This is a LabelView with long text and with wordWrapping on!");
label1.setWordWrap( true );
label1.setResizeToFit( true );
//This sample code demonstrates a label view component that will fill the cell
//in a layout manager with word wrapping on.
Container container2 = new Container();
container2.setLayout( new AutoSizingGridLayout( 0, 1, 10 ,10 , true, false, false) );
LabelView label2 = new LabelView();
label2.initialize();
//The set Size is arbitrary but nesseccary for the the Label to size correctly.
//See **below for LabelView behaviour when neither setSize nor setPreferredSize is set.
label2.setSize( new java.awt.Dimension( 150, 200 ) );
label2.setText("This labelView will fill a cell in a layout manager using word wrapping!");
//NOTE* SetFont is neccessary in this case or the label will not size itself correctly.
label2.setFont( new java.awt.Font( "Dialog", java.awt.Font.PLAIN, 12 ) );
label2.setWordWrap( true );
label2.setResizetoFit( false );
Setting the Width of the LabelView to a Fixed Value
//NOTE* Referring to the previous example, if setResizeToFit is set to true, the
//label will appear as wide as specified in setSize but the height will be
//computed to fit the wrapped text. This is a particularly useful option
//when displaying text that will be translated.
**When neither size nor preferredSize is set, the LabelView has a different
behaviour if placed in the sample code above. The behaviour varies whether
the Font is set or not. If the Font is set, and resizeToFit is set to True, the
LabelView will size itself to have the width of the widest single word and with
the height of the wrapped text.
Field Summary | |
---|---|
static int |
BOTTOM
BOTTOM vertical alignment |
static int |
CENTER_LEFT
CENTER LEFT horizontal alignment. |
static int |
CENTER_RIGHT
CENTER RIGHT horizontal alignment. |
static int |
LEFT
LEFT horizontal alignment |
static int |
RIGHT
RIGHT horizontal alignment |
static int |
TOP
TOP vertical alignment |
Fields inherited from interface com.sas.visuals.Alignment |
---|
BEGIN, CENTER, END |
Constructor Summary | |
---|---|
LabelView()
Default constructor. |
|
LabelView(java.lang.String text)
Constructor that sets the text to be displayed. |
Method Summary | |
---|---|
void |
addNotify()
Makes this Component displayable by connecting it to a native screen resource. |
void |
attachModel(com.sas.ModelInterface model)
Attaches a model to the LabelView. |
protected java.awt.Dimension |
calculateTextDisplay()
Calculates the location and size of the text to display. |
java.lang.Object |
clone()
Returns an object that is a clone of this LabelView. |
java.awt.Dimension |
computePreferredSize()
Returns the minimum size in pixels. |
void |
detachModel(com.sas.ModelInterface model)
Detach the specified model from the LabelView. |
static int |
getDefaultHeight()
Returns default height in pixels. |
static int |
getDefaultWidth()
Returns default width in pixels. |
static com.sas.beans.ExtendedBeanInfo |
getExtendedBeanInfo()
Returns information used by the com.sas.beans.Introspector to
augment the automatically introspected information about a LabelView. |
int |
getHorizontalAlignment()
Returns the horizontal alignment of the text. |
java.awt.Insets |
getInsets()
Returns the insets in pixels for the LabelView. |
java.awt.Dimension |
getMinimumSize()
Returns the minimum size in pixels necessary to display the text. |
java.util.Vector |
getRequiredInterfaces()
Returns the required interfaces Vector for this component. |
int |
getTabSpace()
Returns the number of spaces a tab or a \t will contribute
to the text string in this LabelView |
java.lang.String |
getText()
Returns the text to be displayed. |
int |
getVerticalAlignment()
Returns the vertical alignment of the text. |
boolean |
isDefaultModelAttached()
Returns whether the default model is attached. |
boolean |
isResizeToFit()
Returns whether or not the resize to fit property is set. |
boolean |
isWordWrap()
Returns whether or not word wrapping is set on the LabelView. |
void |
paint(java.awt.Component component,
java.awt.Graphics g,
int x,
int y,
int width,
int height)
Paint of the text on the component. |
void |
paint(java.awt.Graphics g)
Paint this LabelView |
protected void |
parseText()
Parses the text returned from getText() into the appropriate elements for display. |
void |
print(java.awt.Graphics g)
|
void |
print(java.awt.Graphics g,
int pageNumber,
int pageWidth,
int pageHeight)
Prints the requested page. |
void |
propertyChange(java.beans.PropertyChangeEvent event)
Handle PropertyChangeEvent from the model. |
void |
refresh()
Refreshes this LabelView . |
void |
refresh(com.sas.ModelInterface model)
Refresh the displayed text based on the model changing. |
void |
resizeToFit()
Resets the size of the LabelView to the preferred size of this component. |
void |
setBounds(int x,
int y,
int width,
int height)
Calls the super setBounds and then repaints the entire component. |
static void |
setDefaultHeight(int newHeight)
Sets the default height in pixels. |
void |
setDefaultValues()
Sets the default internal values for the LabelView. |
static void |
setDefaultWidth(int newWidth)
Sets the default width in pixels. |
void |
setEnabled(boolean enabled)
Calls the super setEnabled to repaint the LabelView when this enabled
property is changed. |
void |
setFont(java.awt.Font newFont)
Sets the font of the LabelView. |
void |
setHorizontalAlignment(int align)
Sets the horizontal alignment of the text. |
void |
setInsets(java.awt.Insets margins)
Sets the inset margins for the LabelView object. |
void |
setResizeToFit(boolean resize)
Sets the value of the resizeToFit property |
void |
setTabSpace(int space)
Sets the number of spaces in a tab to be displayed in the LabelView. |
void |
setText(java.lang.String label)
Sets the text to be displayed. |
void |
setVerticalAlignment(int align)
Sets the vertical alignment of the text. |
void |
setWordWrap(boolean wrap)
Sets the value of wordWrap. |
protected void |
wordWrap(java.lang.String string)
Wraps text to the beginning of next line if the current text size is greater than the width of the LabelView. |
Methods inherited from interface com.sas.visuals.IconInterface |
---|
getPreferredSize |
Field Detail |
---|
public static final int TOP
Orientations.TOP
,
Constant Field Valuespublic static final int BOTTOM
Orientations.BOTTOM
,
Constant Field Valuespublic static final int LEFT
Orientations.LEFT
,
Constant Field Valuespublic static final int RIGHT
Orientations.RIGHT
,
Constant Field Valuespublic static final int CENTER_LEFT
public static final int CENTER_RIGHT
Constructor Detail |
---|
public LabelView()
public LabelView(java.lang.String text)
text
- the string that is to be set in the LabelViewMethod Detail |
---|
public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
com.sas.beans.Introspector
to
augment the automatically introspected information about a LabelView.
public static int getDefaultHeight()
public static int getDefaultWidth()
public static void setDefaultHeight(int newHeight)
newHeight
- the new default height in pixelspublic static void setDefaultWidth(int newWidth)
newWidth
- the new default width in pixelspublic void attachModel(com.sas.ModelInterface model)
PropertyChangeEvent
from the model.
attachModel
in interface com.sas.ViewInterface
attachModel
in class ComponentVisualComponent
model
- Model to attach toViewInterface.attachModel(com.sas.ModelInterface)
public void detachModel(com.sas.ModelInterface model)
defaultModel
will be attached if the model is set to null.
detachModel
in interface com.sas.ViewInterface
detachModel
in class ComponentVisualComponent
model
- the ModelInterface
to be detachedViewInterface.detachModel(com.sas.ModelInterface)
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in interface com.sas.PublicClonable
clone
in class ComponentVisualComponent
java.lang.CloneNotSupportedException
- if clone creation failspublic void addNotify()
addNotify
in class java.awt.Component
public int getHorizontalAlignment()
setHorizontalAlignment(int)
,
Orientations
public java.awt.Insets getInsets()
getInsets
in interface com.sas.visuals.PainterInterface
setInsets(java.awt.Insets)
public java.awt.Dimension getMinimumSize()
getMinimumSize
in interface VisualInterface
getMinimumSize
in class Component
computePreferredSize()
public java.util.Vector getRequiredInterfaces()
getRequiredInterfaces
in interface com.sas.ViewInterface
getRequiredInterfaces
in class ComponentVisualComponent
ViewInterface.getRequiredInterfaces()
public java.awt.Dimension computePreferredSize()
computePreferredSize
in interface VisualInterface
computePreferredSize
in class ComponentVisualComponent
getMinimumSize()
public int getTabSpace()
\t
will contribute
to the text string in this LabelView
setTabSpace(int)
public java.lang.String getText()
getText
in interface com.sas.lang.StringDataInterface
StringDataInterface
,
setText(java.lang.String)
public int getVerticalAlignment()
setVerticalAlignment(int)
,
Orientations
public boolean isDefaultModelAttached()
(getDefaultModel() == getModelInterface() &&
(getDefaultModel() != null)
isDefaultModelAttached
in interface com.sas.ViewDefaultModelInterface
true
if the component is using the default
model, and false
otherwise.ViewInterface.getModelInterface()
public boolean isResizeToFit()
true
, then the
LabelView will size itself to just fit all the text in the component,
which is the same size as the minimum size.
isResizeToFit
in interface ResizeToFitInterface
true
if the resize to fit property is set on,
else returns false
setResizeToFit(boolean)
,
resizeToFit
public boolean isWordWrap()
true
if word wrapping is on, else false
if word wrapping is off.setWordWrap(boolean)
,
wordWrap
public void paint(java.awt.Component component, java.awt.Graphics g, int x, int y, int width, int height)
paint
in interface com.sas.visuals.PainterInterface
comp
- the Component to paint the IconInterface with.g
- Graphics contextx
- the x coordinatey
- the y coordinatewidth
- the width to be painted.height
- the height to be painted.public void paint(java.awt.Graphics g)
paint
in class ComponentVisualComponent
g
- the specified Graphics contextVisualInterfaceSupport.paint(com.sas.ComponentInterface, com.sas.awt.VisualInterface, java.awt.Component, java.awt.Graphics)
public void propertyChange(java.beans.PropertyChangeEvent event)
PropertyChangeEvent
from the model.
propertyChange
in interface java.beans.PropertyChangeListener
propertyChange
in class ComponentVisualComponent
event
- the event from the model indicating what property changed.PropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)
public void refresh(com.sas.ModelInterface model)
refresh
in interface com.sas.ViewInterface
refresh
in class ComponentVisualComponent
model
- the current model refresh to refresh fromViewInterface.refresh(com.sas.ModelInterface)
public void refresh()
LabelView
. LabelView will reread the data from
its model and discard any previous data
protected void parseText()
getText()
into the appropriate elements for display.
protected void wordWrap(java.lang.String string)
string
- text of the label, usually returned from getText()
isWordWrap()
,
setWordWrap(boolean)
protected java.awt.Dimension calculateTextDisplay()
Dimension
.public void resizeToFit()
isResizeToFit()
returns true
, the LabelView
will be resized.
setResizeToFit(boolean)
,
isResizeToFit()
public void setBounds(int x, int y, int width, int height)
setBounds
and then repaints the entire component.
setBounds
in interface VisualInterface
setBounds
in class ComponentVisualComponent
x
- the desired x position relative to the frame or panel the LabelView is in.y
- the desired y position relative to the frame or panel the LabelView is in.width
- the desired width in pixels of the LabelView.height
- the desired height in pixels of the LabelView.VisualInterface.setBounds(int, int, int, int)
public void setDefaultValues()
setDefaultValues
in interface VisualInterface
setDefaultValues
in interface com.sas.ComponentInterface
setDefaultValues
in class Component
ComponentInterface.setDefaultValues()
public void setEnabled(boolean enabled)
setEnabled
to repaint the LabelView when this enabled
property is changed.
setEnabled
in interface VisualInterface
setEnabled
in class ComponentVisualComponent
enabled
- true
to enable the LabelView for interaction. Set to
false
to disable this LabelView component.VisualInterface.setEnabled(boolean)
public void setFont(java.awt.Font newFont)
setFont
in interface VisualInterface
setFont
in class ComponentVisualComponent
newFont
- the font to be used when displaying text in this LabelViewVisualInterface.setFont(java.awt.Font)
public void setHorizontalAlignment(int align)
align
- the horizontal alignment values: LEFT, RIGHT, or CENTER.getHorizontalAlignment()
,
Orientations
public void setInsets(java.awt.Insets margins)
margin
- the new inset values to be used as the margin of this LabelViewgetInsets()
public void setResizeToFit(boolean resize)
resizeToFit
property
setResizeToFit
in interface ResizeToFitInterface
resize
- true
to automatically set the size of the LabelView object based
on the dimensions of the text being displayed.isResizeToFit()
public void setTabSpace(int space)
space
- the number of spaces desired in a tabgetTabSpace()
public void setVerticalAlignment(int align)
align
- an alignment value: TOP, BOTTOM, or CENTER.getVerticalAlignment()
,
Orientations
public void setWordWrap(boolean wrap)
wordWrap
- boolean valueisWordWrap()
,
wordWrap
public void setText(java.lang.String label)
setText
in interface com.sas.lang.StringDataInterface
label
- the text string that is to be displayed in the LabelView objectpublic void print(java.awt.Graphics g)
print
in class java.awt.Component
public void print(java.awt.Graphics g, int pageNumber, int pageWidth, int pageHeight) throws com.sas.awt.print.PrintException
ComponentVisualComponent
This implementation temporarily resizes the component via
setSize(pageWidth, pageHeight)
and calls the standard print method, print(g)
.
Therefore, subclasses should make sure that their paint method, which
is called by the default implementation of standard print, is
synchronized, as print is here, to guard against an independent call to
paint, due to a window refresh for example, inadvertently using this
size change.
Subclasses with multiple pages will have to override
pageExists()
since it returns false
for
page numbers other than one which will cause the implementation of this
method to throw an IndexOutOfBoundsException. Such subclasses will
also need to override this method in order to change pages.
print
in interface com.sas.awt.print.PrintableInterface
print
in class ComponentVisualComponent
g
- The graphics context to use for printing.pageNumber
- The one-based index of the page to be printed.pageWidth
- The width of the page (in pixels) being printed to.pageHeight
- The height of the page (in pixels) being printed to.
com.sas.awt.print.PrintException
- Thrown if a failure occurred while printing.PrintableInterface.print(java.awt.Graphics, int, int, int)
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |