1 /* JTextComponent.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax
.swing
.text
;
40 import java
.awt
.AWTEvent
;
41 import java
.awt
.Component
;
42 import java
.awt
.Dimension
;
43 import java
.awt
.Image
;
44 import java
.awt
.Rectangle
;
45 import java
.awt
.Point
;
46 import javax
.accessibility
.*;
47 import javax
.swing
.Icon
;
48 import javax
.swing
.JComponent
;
49 import javax
.swing
.KeyStroke
;
50 import javax
.swing
.Scrollable
;
51 import javax
.swing
.UIManager
;
52 import javax
.swing
.event
.*;
53 import javax
.swing
.plaf
.TextUI
;
55 public abstract class JTextComponent
extends JComponent
56 implements Scrollable
, Accessible
58 // public class AccessibleJTextComponent extends AccessibleJComponent
59 // implements AccessibleText, CaretListener, DocumentListener,
60 // AccessibleAction, AccessibleEditableText
62 // } // class AccessibleJTextComponent
65 * AccessibleJTextComponent
67 public class AccessibleJTextComponent
extends AccessibleJComponent
68 implements AccessibleText
, CaretListener
, DocumentListener
{
70 //-------------------------------------------------------------
71 // Variables --------------------------------------------------
72 //-------------------------------------------------------------
80 //-------------------------------------------------------------
81 // Initialization ---------------------------------------------
82 //-------------------------------------------------------------
85 * Constructor AccessibleJTextComponent
86 * @param component TODO
88 public AccessibleJTextComponent(JTextComponent component
) {
91 } // AccessibleJTextComponent()
94 //-------------------------------------------------------------
95 // Methods ----------------------------------------------------
96 //-------------------------------------------------------------
102 public int getCaretPosition() {
104 } // getCaretPosition()
110 public String
getSelectedText() {
112 } // getSelectedText()
118 public int getSelectionStart() {
120 } // getSelectionStart()
126 public int getSelectionEnd() {
128 } // getSelectionEnd()
134 public void caretUpdate(CaretEvent value0
) {
139 * getAccessibleStateSet
140 * @returns AccessibleStateSet
142 public AccessibleStateSet
getAccessibleStateSet() {
144 } // getAccessibleStateSet()
148 * @returns AccessibleRole
150 public AccessibleRole
getAccessibleRole() {
152 } // getAccessibleRole()
156 * @returns AccessibleText
158 public AccessibleText
getAccessibleText() {
160 } // getAccessibleText()
166 public void insertUpdate(DocumentEvent value0
) {
174 public void removeUpdate(DocumentEvent value0
) {
182 public void changedUpdate(DocumentEvent value0
) {
191 public int getIndexAtPoint(Point value0
) {
193 } // getIndexAtPoint()
199 Rectangle
getRootEditorRect() {
201 } // getRootEditorRect()
208 public Rectangle
getCharacterBounds(int value0
) {
210 } // getCharacterBounds()
216 public int getCharCount() {
221 * getCharacterAttribute
223 * @returns AttributeSet
225 public AttributeSet
getCharacterAttribute(int value0
) {
227 } // getCharacterAttribute()
235 public String
getAtIndex(int value0
, int value1
) {
245 public String
getAfterIndex(int value0
, int value1
) {
255 public String
getBeforeIndex(int value0
, int value1
) {
257 } // getBeforeIndex()
260 } // AccessibleJTextComponent
264 public static class KeyBinding
266 public KeyStroke key
;
267 public String actionName
;
268 public KeyBinding(KeyStroke key
, String actionName
)
271 this.actionName
= actionName
;
273 } // class KeyBinding
280 public JTextComponent()
285 public JTextComponent(Icon image
)
290 public JTextComponent(Icon image
, int horizontalAlignment
)
292 this("", image
, horizontalAlignment
);
295 public JTextComponent(String text
)
300 public JTextComponent(String text
, int horizontalAlignment
)
302 this(text
, null, horizontalAlignment
);
305 public JTextComponent(String text
, Icon icon
, int horizontalAlignment
)
307 setDocument(new PlainDocument());
312 this.align
= horizontalAlignment
;
314 // its an editor, so:
315 enableEvents(AWTEvent
.KEY_EVENT_MASK
);
319 public void setDocument(Document s
)
326 public Document
getDocument()
329 System
.out
.println("doc == null !!!");
333 protected int checkHorizontalKey(int key
, String message
)
335 // Verify that key is a legal value for the horizontalAlignment properties.
338 protected int checkVerticalKey(int key
, String message
)
340 // Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
343 public AccessibleContext
getAccessibleContext()
345 // Get the AccessibleContext of this object
348 public Icon
getDisabledIcon()
352 public int getDisplayedMnemonic()
354 // Return the keycode that indicates a mnemonic key.
357 public int getHorizontalAlignment()
359 // Returns the alignment of the label's contents along the X axis.
362 public int getHorizontalTextPosition()
364 // Returns the horizontal position of the label's text, relative to its image.
368 public Icon
getIcon()
370 public int getIconTextGap()
374 Component
getLabelFor()
376 // Get the component this is labelling.
380 public void setText(String text
)
382 getDocument().remove(0,doc
.getLength());
383 getDocument().insertString(0, text
, null);
386 public String
getText()
388 return getDocument().getText(0,
389 getDocument().getLength());
392 public String
getUIClassID()
394 // Returns a string that specifies the name of the l&f class that renders this component.
395 return "JTextComponent";
397 public int getVerticalAlignment()
399 // Returns the alignment of the label's contents along the Y axis.
402 public int getVerticalTextPosition()
404 // Returns the vertical position of the label's text, relative to its image.
408 public boolean imageUpdate(Image img
, int infoflags
, int x
, int y
, int w
, int h
)
410 // This is overriden to return false if the current Icon's Image is not equal to the passed in Image img.
411 return (img
== icon
);
413 protected String
paramString()
415 // Returns a string representation of this JTextComponent.
416 return "JTextComponent";
418 void setDisabledIcon(Icon disabledIcon
)
420 // Set the icon to be displayed if this JTextComponent is "disabled" (JTextComponent.setEnabled(false)).
422 void setDisplayedMnemonic(char aChar
)
424 // Specifies the displayedMnemonic as a char value.
426 void setDisplayedMnemonic(int key
)
428 // Specify a keycode that indicates a mnemonic key.
430 void setHorizontalAlignment(int alignment
)
432 // Sets the alignment of the label's contents along the X axis.
434 void setHorizontalTextPosition(int textPosition
)
436 // Sets the horizontal position of the label's text, relative to its image.
438 void setIcon(Icon icon
)
440 // Defines the icon this component will display.
442 public void setIconTextGap(int iconTextGap
)
444 // If both the icon and text properties are set, this property defines the space between them.
447 public void setLabelFor(Component c
)
449 // Set the component this is labelling.
452 public void setVerticalAlignment(int alignment
)
454 // Sets the alignment of the label's contents along the Y axis.
456 public void setVerticalTextPosition(int textPosition
)
458 // Sets the vertical position of the label's text, relative to its image.
461 public TextUI
getUI()
462 { return (TextUI
) ui
;
465 public void updateUI()
467 TextUI b
= (TextUI
)UIManager
.getUI(this);
471 public Dimension
getPreferredScrollableViewportSize()
475 public int getScrollableUnitIncrement(Rectangle visible
, int orientation
,
480 public int getScrollableBlockIncrement(Rectangle visible
, int orientation
,
485 } // class JTextComponent