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
.Insets
;
45 import java
.awt
.Rectangle
;
46 import java
.awt
.Point
;
47 import javax
.accessibility
.Accessible
;
48 import javax
.accessibility
.AccessibleContext
;
49 import javax
.accessibility
.AccessibleRole
;
50 import javax
.accessibility
.AccessibleStateSet
;
51 import javax
.accessibility
.AccessibleText
;
52 import javax
.swing
.Icon
;
53 import javax
.swing
.JComponent
;
54 import javax
.swing
.KeyStroke
;
55 import javax
.swing
.Scrollable
;
56 import javax
.swing
.UIManager
;
57 import javax
.swing
.event
.CaretEvent
;
58 import javax
.swing
.event
.CaretListener
;
59 import javax
.swing
.event
.DocumentEvent
;
60 import javax
.swing
.event
.DocumentListener
;
61 import javax
.swing
.plaf
.TextUI
;
63 public abstract class JTextComponent
extends JComponent
64 implements Scrollable
, Accessible
66 // public class AccessibleJTextComponent extends AccessibleJComponent
67 // implements AccessibleText, CaretListener, DocumentListener,
68 // AccessibleAction, AccessibleEditableText
70 // } // class AccessibleJTextComponent
73 * AccessibleJTextComponent
75 public class AccessibleJTextComponent
extends AccessibleJComponent
76 implements AccessibleText
, CaretListener
, DocumentListener
{
78 //-------------------------------------------------------------
79 // Variables --------------------------------------------------
80 //-------------------------------------------------------------
88 //-------------------------------------------------------------
89 // Initialization ---------------------------------------------
90 //-------------------------------------------------------------
93 * Constructor AccessibleJTextComponent
94 * @param component TODO
96 public AccessibleJTextComponent(JTextComponent component
) {
99 } // AccessibleJTextComponent()
102 //-------------------------------------------------------------
103 // Methods ----------------------------------------------------
104 //-------------------------------------------------------------
110 public int getCaretPosition() {
112 } // getCaretPosition()
118 public String
getSelectedText() {
120 } // getSelectedText()
126 public int getSelectionStart() {
128 } // getSelectionStart()
134 public int getSelectionEnd() {
136 } // getSelectionEnd()
142 public void caretUpdate(CaretEvent value0
) {
147 * getAccessibleStateSet
148 * @returns AccessibleStateSet
150 public AccessibleStateSet
getAccessibleStateSet() {
152 } // getAccessibleStateSet()
156 * @returns AccessibleRole
158 public AccessibleRole
getAccessibleRole() {
160 } // getAccessibleRole()
164 * @returns AccessibleText
166 public AccessibleText
getAccessibleText() {
168 } // getAccessibleText()
174 public void insertUpdate(DocumentEvent value0
) {
182 public void removeUpdate(DocumentEvent value0
) {
190 public void changedUpdate(DocumentEvent value0
) {
199 public int getIndexAtPoint(Point value0
) {
201 } // getIndexAtPoint()
207 Rectangle
getRootEditorRect() {
209 } // getRootEditorRect()
216 public Rectangle
getCharacterBounds(int value0
) {
218 } // getCharacterBounds()
224 public int getCharCount() {
229 * getCharacterAttribute
231 * @returns AttributeSet
233 public AttributeSet
getCharacterAttribute(int value0
) {
235 } // getCharacterAttribute()
243 public String
getAtIndex(int value0
, int value1
) {
253 public String
getAfterIndex(int value0
, int value1
) {
263 public String
getBeforeIndex(int value0
, int value1
) {
265 } // getBeforeIndex()
268 } // AccessibleJTextComponent
272 public static class KeyBinding
274 public KeyStroke key
;
275 public String actionName
;
276 public KeyBinding(KeyStroke key
, String actionName
)
279 this.actionName
= actionName
;
281 } // class KeyBinding
288 public JTextComponent()
293 public JTextComponent(Icon image
)
298 public JTextComponent(Icon image
, int horizontalAlignment
)
300 this("", image
, horizontalAlignment
);
303 public JTextComponent(String text
)
308 public JTextComponent(String text
, int horizontalAlignment
)
310 this(text
, null, horizontalAlignment
);
313 public JTextComponent(String text
, Icon icon
, int horizontalAlignment
)
315 setDocument(new PlainDocument());
320 this.align
= horizontalAlignment
;
322 // its an editor, so:
323 enableEvents(AWTEvent
.KEY_EVENT_MASK
);
327 public void setDocument(Document s
)
334 public Document
getDocument()
337 System
.out
.println("doc == null !!!");
341 protected int checkHorizontalKey(int key
, String message
)
343 // Verify that key is a legal value for the horizontalAlignment properties.
346 protected int checkVerticalKey(int key
, String message
)
348 // Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
351 public AccessibleContext
getAccessibleContext()
353 // Get the AccessibleContext of this object
356 public Icon
getDisabledIcon()
360 public int getDisplayedMnemonic()
362 // Return the keycode that indicates a mnemonic key.
365 public int getHorizontalAlignment()
367 // Returns the alignment of the label's contents along the X axis.
370 public int getHorizontalTextPosition()
372 // Returns the horizontal position of the label's text, relative to its image.
376 public Icon
getIcon()
378 public int getIconTextGap()
382 Component
getLabelFor()
384 // Get the component this is labelling.
388 public Insets
getMargin()
390 // FIXME: Not implemented.
394 public void setText(String text
)
396 getDocument().remove(0,doc
.getLength());
397 getDocument().insertString(0, text
, null);
400 public String
getText()
402 return getDocument().getText(0,
403 getDocument().getLength());
406 public String
getUIClassID()
408 // Returns a string that specifies the name of the l&f class that renders this component.
409 return "JTextComponent";
411 public int getVerticalAlignment()
413 // Returns the alignment of the label's contents along the Y axis.
416 public int getVerticalTextPosition()
418 // Returns the vertical position of the label's text, relative to its image.
422 public boolean imageUpdate(Image img
, int infoflags
, int x
, int y
, int w
, int h
)
424 // This is overriden to return false if the current Icon's Image is not equal to the passed in Image img.
425 return (img
== icon
);
427 protected String
paramString()
429 // Returns a string representation of this JTextComponent.
430 return "JTextComponent";
432 void setDisabledIcon(Icon disabledIcon
)
434 // Set the icon to be displayed if this JTextComponent is "disabled" (JTextComponent.setEnabled(false)).
436 void setDisplayedMnemonic(char aChar
)
438 // Specifies the displayedMnemonic as a char value.
440 void setDisplayedMnemonic(int key
)
442 // Specify a keycode that indicates a mnemonic key.
444 void setHorizontalAlignment(int alignment
)
446 // Sets the alignment of the label's contents along the X axis.
448 void setHorizontalTextPosition(int textPosition
)
450 // Sets the horizontal position of the label's text, relative to its image.
452 void setIcon(Icon icon
)
454 // Defines the icon this component will display.
456 public void setIconTextGap(int iconTextGap
)
458 // If both the icon and text properties are set, this property defines the space between them.
461 public void setLabelFor(Component c
)
463 // Set the component this is labelling.
466 public void setVerticalAlignment(int alignment
)
468 // Sets the alignment of the label's contents along the Y axis.
470 public void setVerticalTextPosition(int textPosition
)
472 // Sets the vertical position of the label's text, relative to its image.
475 public TextUI
getUI()
476 { return (TextUI
) ui
;
479 public void updateUI()
481 TextUI b
= (TextUI
)UIManager
.getUI(this);
485 public Dimension
getPreferredScrollableViewportSize()
489 public int getScrollableUnitIncrement(Rectangle visible
, int orientation
,
494 public int getScrollableBlockIncrement(Rectangle visible
, int orientation
,
499 } // class JTextComponent