|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--org.zaval.util.ValidationObject
|
+--org.zaval.lw.LwCanvas
|
+--org.zaval.lw.LwLabel
|
+--org.zaval.lw.LwTextField
This class is a text field component. The library provides several text renders implementations that can be used as a face view of the component:
...
LwTextFiled tf = new LwTextFiled("Password text");
tf.getViewMan(true).setView(new LwPasswordText(tf.getText()));
...
The list below describes some features of the component:
...
// Creates single line text field component, where it is possible to
// enter at most 10 characters.
LwTextFiled tf = new LwTextFiled("", 10);
...
setPSByRowsCols method to define preferred size of the component
basing on the number of rows and columns. The method calculates and sets preferred size of
the text field component according to row size and column size. Draw attention that
if the font has been redefined for the text render, than it is necessary to call
the method again to recalculate his preferred size.
setCursorView method.
setPosController
method to control text cursor position.
setEditable method to define if a text can be edited or not.
getSelectedText method to get selected text.
The component overrides the getOrigin method to organize scrolling of the
content. The scrolling mechanism works right if the component will be inserted
into a LwScrollPan component.
To listen when the cursor position has been changed use the pos controller as follow:
public class Sample
implements PosListener
{
...
public void init()
{
...
LwTextFiled tf = new LwTextFiled("Text");
tf.getPosController().addPosListener(this);
...
}
public void posChanged(PosEvent e) {
System.out.println("The old cursor location is - " + e.getPrevOffset());
}
}
| Fields inherited from class org.zaval.lw.LwCanvas |
bits, height, insets, parent, psHeight, psWidth, skins, width, x, y |
| Fields inherited from class org.zaval.util.ValidationObject |
isValidFlag |
| Constructor Summary | |
LwTextField()
Constructs a text filed component with no text. |
|
LwTextField(java.lang.String s)
Constructs a text field component with the specified text. |
|
LwTextField(java.lang.String s,
int maxCol)
Constructs a single line text field component with the specified text and the maximal number of columns. |
|
LwTextField(TextModel model)
Constructs a text field component with the specified text model. |
|
| Method Summary | |
boolean |
canHaveFocus()
Specifies if the component can have focus. |
protected void |
drawCursor(java.awt.Graphics g)
The method is used to paint the text cursor using the cursor view. |
void |
endDragged(LwMouseMotionEvent e)
Invoked when the mouse ends dragged. |
static java.awt.Point |
findNextWord(TextModel t,
int line,
int col,
int d)
Finds starting from the specified line and column next word in the given text model and returns the found word location. |
void |
focusGained(LwFocusEvent e)
Invoked when the light weight component gained focus. |
void |
focusLost(LwFocusEvent e)
Invoked when the light weight component lost focus. |
int |
getCursorType(LwComponent target,
int x,
int y)
Gets the cursor type for the specified location of the given component. |
LwView |
getCursorView()
Gets the cursor view that is used to paint the text cursor. |
java.awt.Point |
getEndSelection()
Returns the last selection row and column |
int |
getLines()
Gets the number of lines. |
int |
getLineSize(int i)
Gets the line size for the specified line number. |
int |
getMaxOffset()
Gets the maximal offset. |
java.awt.Point |
getOrigin()
Returns an origin of the component. |
PosController |
getPosController()
Gets the pos controller that manages the text cursor position. |
java.awt.Dimension |
getPreferredSize()
Gets the preferred size of this component. |
java.awt.Color |
getSelectColor()
Returns a color that is used to render selected text background. |
java.lang.String |
getSelectedText()
Returns the selected text. |
java.awt.Point |
getSelectionOffsets()
Gets the start and last selection offsets. |
java.awt.Point |
getSOLocation()
Gets the scroll object location. |
java.awt.Dimension |
getSOSize()
Gets the scroll object size. |
java.awt.Point |
getStartSelection()
Returns the start selection row and column |
static java.lang.String |
getSubString(TextModel t,
java.awt.Point start,
java.awt.Point end)
Returns a substring of the specified text model, at the given start and last position. |
static java.awt.Point |
getTextLocationAt(LwTextRender render,
PosController pos)
Calculates and gets a pixel location for the specified text render and the text cursor position. |
static java.awt.Point |
getTextRowColAt(LwTextRender render,
int x,
int y)
Calculates and gets a text position for the specified text render and the location. |
protected boolean |
handleKey(LwKeyEvent e)
Handles the specified key event. |
boolean |
hasSelection()
Tests if the a text part has been selected. |
boolean |
isEditable()
Checks if the text field component is editable. |
protected boolean |
isFiltered(LwKeyEvent e)
Returns true if the key event should be handle next, returns
false if the handling process has to be terminated. |
void |
keyPressed(LwKeyEvent e)
Invoked when a key has been pressed. |
void |
keyReleased(LwKeyEvent e)
Invoked when a key has been released. |
void |
keyTyped(LwKeyEvent e)
Invoked when a key has been typed. |
protected LwTextRender |
makeTextRender(TextModel t)
The method gets default text render that will be used to render the specified text model. |
void |
mouseClicked(LwMouseEvent e)
Invoked when the mouse button has been clicked on a light weight component. |
void |
mouseDragged(LwMouseMotionEvent e)
Invoked when a mouse button is pressed on a component and then dragged. |
void |
mouseEntered(LwMouseEvent e)
Invoked when the mouse enters a light weight component. |
void |
mouseExited(LwMouseEvent e)
Invoked when the mouse exits a light weight component. |
void |
mouseMoved(LwMouseMotionEvent e)
Invoked when the mouse pointer has been moved on a light weight component (with no buttons no down). |
void |
mousePressed(LwMouseEvent e)
Invoked when the mouse button has been pressed on a light weight component. |
void |
mouseReleased(LwMouseEvent e)
Invoked when the mouse button has been released on a light weight component. |
boolean |
moveContent()
Tests if the scroll component performs scrolling by changing it location or view. |
protected int |
pageSize()
Gets the page size. |
void |
paint(java.awt.Graphics g)
Paints this component. |
void |
posChanged(PosEvent e)
Invoked when a virtual position has been changed. |
protected void |
recalc()
Invoked with validate method only if the component is not valid. |
protected void |
remove(int pos,
int size)
Removes a part of the text starting from the given position and with the specified size. |
void |
select(int startOffset,
int endOffset)
Selects the specified by the start and end offsets the text part. |
void |
setCursorView(LwView v)
Sets the specified cursor view to render the text cursor. |
void |
setEditable(boolean b)
Sets the specified mode for the text field component. |
void |
setEnabled(boolean b)
Enables or disables this component. |
void |
setPosController(PosController p)
Sets the specified pos controller to manage the text cursor position. |
void |
setPSByRowsCols(int r,
int c)
Sets the preferred size for the text field component that conforms to the specified number of rows and columns. |
void |
setScrollMan(ScrollMan m)
Sets the specified scroll manager for the scroll object. |
void |
setSelectColor(java.awt.Color c)
Sets the specified color to render selected text. |
void |
setSOLocation(int x,
int y)
Sets the specified scroll object location. |
void |
setText(java.lang.String s)
Sets the specified string to be shown with the class. |
void |
startDragged(LwMouseMotionEvent e)
Invoked when the mouse starts dragged. |
protected void |
stopSelection()
Clear the current selection. |
protected void |
write(int pos,
java.lang.String s)
Inserts the specified text at the given position. |
| Methods inherited from class org.zaval.lw.LwLabel |
getForeground, getText, getTextModel, getTextRender, setForeground |
| Methods inherited from class org.zaval.lw.LwCanvas |
calcPreferredSize, getBackground, getBounds, getHeight, getInsets, getLocation, getLwComponentAt, getLwParent, getSize, getViewMan, getVisiblePart, getWidth, getX, getY, hasFocus, invalidate, isEnabled, isOpaque, isVisible, repaint, repaint, requestFocus, setBackground, setInsets, setLocation, setLwParent, setOpaque, setPSSize, setSize, setViewMan, setVisible, toString, update, validate, viewManChanged, vrp |
| Methods inherited from class org.zaval.util.ValidationObject |
isValid |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.zaval.util.Validationable |
isValid |
| Constructor Detail |
public LwTextField()
public LwTextField(java.lang.String s)
s - the specified text.
public LwTextField(java.lang.String s,
int maxCol)
s - the specified text.maxCol - the specified maximal number of columns.public LwTextField(TextModel model)
model - the specified text model.| Method Detail |
public boolean canHaveFocus()
LwComponentcanHaveFocus in class LwCanvasorg.zaval.lw.LwComponenttrue if the component can have the focus.public PosController getPosController()
public void setPosController(PosController p)
p - the specified pos controller.public LwView getCursorView()
public void setCursorView(LwView v)
v - the specified cursor view.
public void setPSByRowsCols(int r,
int c)
r - the specified number of rows.c - the specified number of columns.public void paint(java.awt.Graphics g)
drawCursor method.paint in class LwCanvasg - the graphics context to be used for painting.public void setEditable(boolean b)
b - the specified mode. If the mode is true than the component
is editable; otherwise not-editable.public boolean isEditable()
true if the text field is editable; false
otherwise.public void keyPressed(LwKeyEvent e)
LwKeyListenerkeyPressed in interface LwKeyListenerorg.zaval.lw.event.LwKeyListenere - the specified key event.public void keyTyped(LwKeyEvent e)
LwKeyListenerkeyTyped in interface LwKeyListenerorg.zaval.lw.event.LwKeyListenere - the specified key event.public void focusGained(LwFocusEvent e)
LwFocusListenerfocusGained in interface LwFocusListenerorg.zaval.lw.event.LwFocusListenere - the specified focus event.public void focusLost(LwFocusEvent e)
LwFocusListenerfocusLost in interface LwFocusListenerorg.zaval.lw.event.LwFocusListenere - the specified focus event.public void keyReleased(LwKeyEvent e)
LwKeyListenerkeyReleased in interface LwKeyListenerorg.zaval.lw.event.LwKeyListenere - the specified key event.public void mouseClicked(LwMouseEvent e)
LwMouseListenermouseClicked in interface LwMouseListenerorg.zaval.lw.event.LwMouseListenere - the specified mouse event.public void mouseEntered(LwMouseEvent e)
LwMouseListenermouseEntered in interface LwMouseListenerorg.zaval.lw.event.LwMouseListenere - the specified mouse event.public void mouseExited(LwMouseEvent e)
LwMouseListenermouseExited in interface LwMouseListenerorg.zaval.lw.event.LwMouseListenere - the specified mouse event.public void startDragged(LwMouseMotionEvent e)
LwMouseMotionListenerstartDragged in interface LwMouseMotionListenerorg.zaval.lw.event.LwMouseMotionListenere - the specified mouse motion event.public void endDragged(LwMouseMotionEvent e)
LwMouseMotionListenerendDragged in interface LwMouseMotionListenerorg.zaval.lw.event.LwMouseMotionListenere - the specified mouse motion event.public void mouseReleased(LwMouseEvent e)
LwMouseListenermouseReleased in interface LwMouseListenerorg.zaval.lw.event.LwMouseListenere - the specified mouse event.public void mouseMoved(LwMouseMotionEvent e)
LwMouseMotionListenermouseMoved in interface LwMouseMotionListenerorg.zaval.lw.event.LwMouseMotionListenere - the specified mouse motion event.public void mouseDragged(LwMouseMotionEvent e)
LwMouseMotionListenermouseDragged in interface LwMouseMotionListenerorg.zaval.lw.event.LwMouseMotionListenere - the specified mouse motion event.public void mousePressed(LwMouseEvent e)
LwMouseListenermousePressed in interface LwMouseListenerorg.zaval.lw.event.LwMouseListenere - the specified mouse event.
public int getCursorType(LwComponent target,
int x,
int y)
getCursorType in interface Cursorabletarget - the given component.x - the x coordinate.y - the y coordinate.public int getLineSize(int i)
PosInfogetLineSize in interface PosInfoorg.zaval.misc.PosInfoline - the specified line number.public int getLines()
PosInfogetLines in interface PosInfoorg.zaval.misc.PosInfopublic int getMaxOffset()
PosInfogetMaxOffset in interface PosInfoorg.zaval.misc.PosInfopublic void setText(java.lang.String s)
LwLabelsetText in class LwLabelorg.zaval.lw.LwLabels - the specified string.public void posChanged(PosEvent e)
PosListenerposChanged in interface PosListenerorg.zaval.misc.event.PosListenere - the specified pos event.public java.awt.Point getOrigin()
getOrigin in class LwCanvaspublic java.awt.Dimension getPreferredSize()
LwCanvasgetInsets method) and
a "pure" preferred size (returned with calcPreferredSize method).
You should not override the method, use calcPreferredSize method to
define the "pure" preferred size of this component.getPreferredSize in class LwCanvasorg.zaval.lw.LwCanvaspublic java.awt.Point getSOLocation()
ScrollObjgetSOLocation in interface ScrollObjorg.zaval.misc.ScrollObj
public void setSOLocation(int x,
int y)
ScrollObjsetSOLocation in interface ScrollObjorg.zaval.misc.ScrollObjx - the specified x coordinate.y - the specified y coordinate.public java.awt.Dimension getSOSize()
ScrollObjgetSOSize in interface ScrollObjorg.zaval.misc.ScrollObjpublic void setScrollMan(ScrollMan m)
ScrollObjsetScrollMan in interface ScrollObjorg.zaval.misc.ScrollObjm - the specified scroll manager.public boolean moveContent()
true.moveContent in interface ScrollObjtrue if the scroll component organizes scrolling by moving
its view; otherwise false.public java.awt.Point getStartSelection()
TxtSelectionInfogetStartSelection in interface TxtSelectionInfoorg.zaval.lw.TxtSelectionInfox field is selection row and y field is selection
column.public java.awt.Point getEndSelection()
TxtSelectionInfogetEndSelection in interface TxtSelectionInfoorg.zaval.lw.TxtSelectionInfox field is selection row and y field is selection
column.public boolean hasSelection()
true if the text part has been selected; false otherwise.public java.awt.Point getSelectionOffsets()
x field corresponds to start selection offset and
y field corresponds to last selection offset.public java.lang.String getSelectedText()
TxtSelectionInfogetSelectedText in interface TxtSelectionInfoorg.zaval.lw.TxtSelectionInfonull if there is not selected
text.public java.awt.Color getSelectColor()
TxtSelectionInfogetSelectColor in interface TxtSelectionInfoorg.zaval.lw.TxtSelectionInfopublic void setSelectColor(java.awt.Color c)
c - the specified color.public void setEnabled(boolean b)
LwCanvassetEnabled in class LwCanvasorg.zaval.lw.LwCanvasb - if true, this component is
enabled; otherwise this component is disabled.
public void select(int startOffset,
int endOffset)
startOffset - the specified start offset.endOffset - the specified end offset.protected void drawCursor(java.awt.Graphics g)
g - the graphics context to be used for painting.protected void recalc()
LwCanvasvalidate method only if the component is not valid.
The method shoud be overrided to calculate metrical characteristics of the component to
minimize computation time of the preferred size for the component. For example, you can
calculate a preferred size inside the method and just return it by
calcPreferredSize method.recalc in class LwCanvasprotected boolean handleKey(LwKeyEvent e)
e - the specified key event to be handle.true if the key event has been handled with the method; otherwise
false.protected boolean isFiltered(LwKeyEvent e)
true if the key event should be handle next, returns
false if the handling process has to be terminated. The method
is called before any other event handler will be executed.e - the specified key event.true if the key event should be handled.protected LwTextRender makeTextRender(TextModel t)
LwLabelmakeTextRender in class LwLabelorg.zaval.lw.LwLabelt - the specified text model.
protected void remove(int pos,
int size)
pos - the given position.size - the specified removed part size.
protected void write(int pos,
java.lang.String s)
pos - the given position.s - the specified text to be inserted.protected int pageSize()
protected void stopSelection()
public static java.awt.Point getTextLocationAt(LwTextRender render,
PosController pos)
render - the specified text render.pos - the pos controller that defines the text position.
public static java.awt.Point getTextRowColAt(LwTextRender render,
int x,
int y)
x field defines
a row and y field defines a column.render - the specified text render.x - the x coordinate of the location.y - the y coordinate of the location.
public static java.awt.Point findNextWord(TextModel t,
int line,
int col,
int d)
x field defines a row text position and y field defines a
column text position.t - the specified text model.line - the specified starting line.col - the specified starting column.d - the specified searching direction. If the value is 1
than the method looks for a next word location, if the value is
-1 than the method looks for a previous word location.
public static java.lang.String getSubString(TextModel t,
java.awt.Point start,
java.awt.Point end)
x field defines a row and y field defines a
column.t - the specified text model.start - the specified start position.end - the specified last position.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||