addCaretListener
public void addCaretListener(CaretListener listener)
Adds a CaretListener
object to this text component.
listener
- the listener to add
addKeymap
public static Keymap addKeymap(String n,
Keymap parent)
Create a new Keymap with a specific name and parent, and add the new
Keymap to the global keymap table. The name may be null
,
in which case the new Keymap will not be added to the global
Keymap table. The parent may also be null
, which is
harmless.
n
- The name of the new Keymap, or null
parent
- The parent of the new Keymap, or null
fireCaretUpdate
protected void fireCaretUpdate(CaretEvent event)
Notifies all registered CaretListener
objects that the caret
was updated.
event
- the event to send
getCaret
public Caret getCaret()
The Caret
object used in this text component.
getCaretPosition
public int getCaretPosition()
Retrisves the current caret position.
getKeymap
public Keymap getKeymap()
Get the current Keymap of this component.
- The component's current Keymap
getKeymap
public static Keymap getKeymap(String n)
Get a Keymap from the global keymap table, by name.
n
- The name of the Keymap to look up
- A Keymap associated with the provided name, or
null
if no such Keymap exists
getScrollableBlockIncrement
public int getScrollableBlockIncrement(Rectangle visible,
int orientation,
int direction)
Return the preferred scrolling amount (in pixels) for the given
scrolling direction and orientation when scrolling in large amounts
(pages).
- getScrollableBlockIncrement in interface Scrollable
orientation
- the scrolling orientationdirection
- the scrolling direction (negative - up, positive -down).
The values greater than one means that more mouse wheel or similar
events were generated, and hence it is better to scroll the longer
distance.
- the preferred scrolling distance, negative if up or left.
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()
Return true if the width of the scrollable is always equal to the
view, where it is displayed, width (for instance, the text area with
the word wrap). In such case, the horizontal scrolling should not be
performed.
- getScrollableTracksViewportWidth in interface Scrollable
- true is no horizontal scrolling is assumed, faster otherwise.
getScrollableUnitIncrement
public int getScrollableUnitIncrement(Rectangle visible,
int orientation,
int direction)
Return the preferred scrolling amount (in pixels) for the given
scrolling direction and orientation when scrolling in small amounts
like table lines.
- getScrollableUnitIncrement in interface Scrollable
orientation
- the scrolling orientationdirection
- the scrolling direction (negative - up, positive -down).
The values greater than one means that more mouse wheel or similar
events were generated, and hence it is better to scroll the longer
distance.
- the preferred scrolling distance, negative if up or left.
getSelectedText
public String getSelectedText()
Retrieves the currently selected text in this text document.
getSelectionEnd
public int getSelectionEnd()
Returns the end postion of the currently selected text.
getSelectionStart
public int getSelectionStart()
Returns the start postion of the currently selected text.
getText
public String getText()
Retrieves the current text in this text document.
getText
public String getText(int offset,
int length)
throws BadLocationException
Retrieves a part of the current text in this document.
offset
- the postion of the first characterlength
- the length of the text to retrieve
getUI
public TextUI getUI()
This method returns the label's UI delegate.
getUIClassID
public String getUIClassID()
Returns a string that specifies the name of the Look and Feel class
that renders this component.
- getUIClassID in interface JComponent
- the string "TextComponentUI"
isEditable
public boolean isEditable()
Checks whether this text component it editable.
- true if editable, false otherwise
loadKeymap
public static void loadKeymap(Keymap map,
JTextComponent.KeyBinding[] bindings,
Action[] actions)
Resolves a set of bindings against a set of actions and inserts the
results into a
Keymap
. Specifically, for each provided binding
b
, if there exists a provided action
a
such
that
a.getValue(Action.NAME) == b.ActionName
then an
entry is added to the Keymap mapping
b
to
a
.
map
- The Keymap to add new mappings tobindings
- The set of bindings to add to the Keymapactions
- The set of actions to resolve binding names against
moveCaretPosition
public void moveCaretPosition(int position)
Moves the caret to a given position. This selects the text between
the old and the new position of the caret.
read
public void read(Reader input,
Object streamDescription)
throws IOException
Read and set the content this component. If not overridden, the
method reads the component content as a plain text.
The second parameter of this method describes the input stream. It can
be String, URL, File and so on. If not null, this object is added to
the properties of the associated document under the key
Document.StreamDescriptionProperty
.
input
- an input stream to read from.streamDescription
- an object, describing the stream.
removeCaretListener
public void removeCaretListener(CaretListener listener)
Removed a CaretListener
object from this text component.
listener
- the listener to remove
removeKeymap
public static Keymap removeKeymap(String n)
Remove a Keymap from the global Keymap table, by name.
n
- The name of the Keymap to remove
- The keymap removed from the global table
select
public void select(int start,
int end)
Selects a part of the content of the text component.
start
- the start position of the selected textend
- the end position of the selected text
selectAll
public void selectAll()
Selects the whole content of the text component.
setCaret
public void setCaret(Caret newCaret)
Sets a new Caret
for this text component.
newCaret
- the new Caret
to set
setCaretPosition
public void setCaretPosition(int position)
Sets the caret to a new position.
position
- the new position
setEditable
public void setEditable(boolean newValue)
Enables/disabled this text component's editability.
newValue
- true to make it editable, false otherwise.
setKeymap
public void setKeymap(Keymap k)
Set the current Keymap of this component, installing appropriate
KeymapWrapper
and
KeymapActionMap
objects in the
InputMap
and
ActionMap
parent chains, respectively,
and fire a property change event with name
"keymap"
.
setSelectionEnd
public void setSelectionEnd(int end)
Selects the text from the selection start postion to the given position.
end
- the end positon of the selected text.
setSelectionStart
public void setSelectionStart(int start)
Selects the text from the given postion to the selection end position.
start
- the start positon of the selected text.
setUI
public void setUI(TextUI newUI)
This method sets the label's UI delegate.
newUI
- The label's UI delegate.
updateUI
public void updateUI()
This method resets the label's UI delegate to the default UI for the
current look and feel.
- updateUI in interface JComponent
write
public void write(Writer output)
throws IOException
Write the content of this component to the given stream. If not
overridden, the method writes the component content as a plain text.
output
- the writer to write into.
JTextComponent.java --
Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath 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, or (at your option)
any later version.
GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.