| 1 | /* JTextComponent.java --
|
|---|
| 2 | Copyright (C) 2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 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)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 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
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 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
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 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. */
|
|---|
| 37 |
|
|---|
| 38 | package javax.swing.text;
|
|---|
| 39 |
|
|---|
| 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;
|
|---|
| 54 |
|
|---|
| 55 | public abstract class JTextComponent extends JComponent
|
|---|
| 56 | implements Scrollable, Accessible
|
|---|
| 57 | {
|
|---|
| 58 | // public class AccessibleJTextComponent extends AccessibleJComponent
|
|---|
| 59 | // implements AccessibleText, CaretListener, DocumentListener,
|
|---|
| 60 | // AccessibleAction, AccessibleEditableText
|
|---|
| 61 | // {
|
|---|
| 62 | // } // class AccessibleJTextComponent
|
|---|
| 63 |
|
|---|
| 64 | /**
|
|---|
| 65 | * AccessibleJTextComponent
|
|---|
| 66 | */
|
|---|
| 67 | public class AccessibleJTextComponent extends AccessibleJComponent
|
|---|
| 68 | implements AccessibleText, CaretListener, DocumentListener {
|
|---|
| 69 |
|
|---|
| 70 | //-------------------------------------------------------------
|
|---|
| 71 | // Variables --------------------------------------------------
|
|---|
| 72 | //-------------------------------------------------------------
|
|---|
| 73 |
|
|---|
| 74 | /**
|
|---|
| 75 | * caretPos
|
|---|
| 76 | */
|
|---|
| 77 | int caretPos;
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | //-------------------------------------------------------------
|
|---|
| 81 | // Initialization ---------------------------------------------
|
|---|
| 82 | //-------------------------------------------------------------
|
|---|
| 83 |
|
|---|
| 84 | /**
|
|---|
| 85 | * Constructor AccessibleJTextComponent
|
|---|
| 86 | * @param component TODO
|
|---|
| 87 | */
|
|---|
| 88 | public AccessibleJTextComponent(JTextComponent component) {
|
|---|
| 89 | super(component);
|
|---|
| 90 | // TODO
|
|---|
| 91 | } // AccessibleJTextComponent()
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 | //-------------------------------------------------------------
|
|---|
| 95 | // Methods ----------------------------------------------------
|
|---|
| 96 | //-------------------------------------------------------------
|
|---|
| 97 |
|
|---|
| 98 | /**
|
|---|
| 99 | * getCaretPosition
|
|---|
| 100 | * @returns int
|
|---|
| 101 | */
|
|---|
| 102 | public int getCaretPosition() {
|
|---|
| 103 | return 0; // TODO
|
|---|
| 104 | } // getCaretPosition()
|
|---|
| 105 |
|
|---|
| 106 | /**
|
|---|
| 107 | * getSelectedText
|
|---|
| 108 | * @returns String
|
|---|
| 109 | */
|
|---|
| 110 | public String getSelectedText() {
|
|---|
| 111 | return null; // TODO
|
|---|
| 112 | } // getSelectedText()
|
|---|
| 113 |
|
|---|
| 114 | /**
|
|---|
| 115 | * getSelectionStart
|
|---|
| 116 | * @returns int
|
|---|
| 117 | */
|
|---|
| 118 | public int getSelectionStart() {
|
|---|
| 119 | return 0; // TODO
|
|---|
| 120 | } // getSelectionStart()
|
|---|
| 121 |
|
|---|
| 122 | /**
|
|---|
| 123 | * getSelectionEnd
|
|---|
| 124 | * @returns int
|
|---|
| 125 | */
|
|---|
| 126 | public int getSelectionEnd() {
|
|---|
| 127 | return 0; // TODO
|
|---|
| 128 | } // getSelectionEnd()
|
|---|
| 129 |
|
|---|
| 130 | /**
|
|---|
| 131 | * caretUpdate
|
|---|
| 132 | * @param value0 TODO
|
|---|
| 133 | */
|
|---|
| 134 | public void caretUpdate(CaretEvent value0) {
|
|---|
| 135 | // TODO
|
|---|
| 136 | } // caretUpdate()
|
|---|
| 137 |
|
|---|
| 138 | /**
|
|---|
| 139 | * getAccessibleStateSet
|
|---|
| 140 | * @returns AccessibleStateSet
|
|---|
| 141 | */
|
|---|
| 142 | public AccessibleStateSet getAccessibleStateSet() {
|
|---|
| 143 | return null; // TODO
|
|---|
| 144 | } // getAccessibleStateSet()
|
|---|
| 145 |
|
|---|
| 146 | /**
|
|---|
| 147 | * getAccessibleRole
|
|---|
| 148 | * @returns AccessibleRole
|
|---|
| 149 | */
|
|---|
| 150 | public AccessibleRole getAccessibleRole() {
|
|---|
| 151 | return null; // TODO
|
|---|
| 152 | } // getAccessibleRole()
|
|---|
| 153 |
|
|---|
| 154 | /**
|
|---|
| 155 | * getAccessibleText
|
|---|
| 156 | * @returns AccessibleText
|
|---|
| 157 | */
|
|---|
| 158 | public AccessibleText getAccessibleText() {
|
|---|
| 159 | return null; // TODO
|
|---|
| 160 | } // getAccessibleText()
|
|---|
| 161 |
|
|---|
| 162 | /**
|
|---|
| 163 | * insertUpdate
|
|---|
| 164 | * @param value0 TODO
|
|---|
| 165 | */
|
|---|
| 166 | public void insertUpdate(DocumentEvent value0) {
|
|---|
| 167 | // TODO
|
|---|
| 168 | } // insertUpdate()
|
|---|
| 169 |
|
|---|
| 170 | /**
|
|---|
| 171 | * removeUpdate
|
|---|
| 172 | * @param value0 TODO
|
|---|
| 173 | */
|
|---|
| 174 | public void removeUpdate(DocumentEvent value0) {
|
|---|
| 175 | // TODO
|
|---|
| 176 | } // removeUpdate()
|
|---|
| 177 |
|
|---|
| 178 | /**
|
|---|
| 179 | * changedUpdate
|
|---|
| 180 | * @param value0 TODO
|
|---|
| 181 | */
|
|---|
| 182 | public void changedUpdate(DocumentEvent value0) {
|
|---|
| 183 | // TODO
|
|---|
| 184 | } // changedUpdate()
|
|---|
| 185 |
|
|---|
| 186 | /**
|
|---|
| 187 | * getIndexAtPoint
|
|---|
| 188 | * @param value0 TODO
|
|---|
| 189 | * @returns int
|
|---|
| 190 | */
|
|---|
| 191 | public int getIndexAtPoint(Point value0) {
|
|---|
| 192 | return 0; // TODO
|
|---|
| 193 | } // getIndexAtPoint()
|
|---|
| 194 |
|
|---|
| 195 | /**
|
|---|
| 196 | * getRootEditorRect
|
|---|
| 197 | * @returns Rectangle
|
|---|
| 198 | */
|
|---|
| 199 | Rectangle getRootEditorRect() {
|
|---|
| 200 | return null; // TODO
|
|---|
| 201 | } // getRootEditorRect()
|
|---|
| 202 |
|
|---|
| 203 | /**
|
|---|
| 204 | * getCharacterBounds
|
|---|
| 205 | * @param value0 TODO
|
|---|
| 206 | * @returns Rectangle
|
|---|
| 207 | */
|
|---|
| 208 | public Rectangle getCharacterBounds(int value0) {
|
|---|
| 209 | return null; // TODO
|
|---|
| 210 | } // getCharacterBounds()
|
|---|
| 211 |
|
|---|
| 212 | /**
|
|---|
| 213 | * getCharCount
|
|---|
| 214 | * @returns int
|
|---|
| 215 | */
|
|---|
| 216 | public int getCharCount() {
|
|---|
| 217 | return 0; // TODO
|
|---|
| 218 | } // getCharCount()
|
|---|
| 219 |
|
|---|
| 220 | /**
|
|---|
| 221 | * getCharacterAttribute
|
|---|
| 222 | * @param value0 TODO
|
|---|
| 223 | * @returns AttributeSet
|
|---|
| 224 | */
|
|---|
| 225 | public AttributeSet getCharacterAttribute(int value0) {
|
|---|
| 226 | return null; // TODO
|
|---|
| 227 | } // getCharacterAttribute()
|
|---|
| 228 |
|
|---|
| 229 | /**
|
|---|
| 230 | * getAtIndex
|
|---|
| 231 | * @param value0 TODO
|
|---|
| 232 | * @param value1 TODO
|
|---|
| 233 | * @returns String
|
|---|
| 234 | */
|
|---|
| 235 | public String getAtIndex(int value0, int value1) {
|
|---|
| 236 | return null; // TODO
|
|---|
| 237 | } // getAtIndex()
|
|---|
| 238 |
|
|---|
| 239 | /**
|
|---|
| 240 | * getAfterIndex
|
|---|
| 241 | * @param value0 TODO
|
|---|
| 242 | * @param value1 TODO
|
|---|
| 243 | * @returns String
|
|---|
| 244 | */
|
|---|
| 245 | public String getAfterIndex(int value0, int value1) {
|
|---|
| 246 | return null; // TODO
|
|---|
| 247 | } // getAfterIndex()
|
|---|
| 248 |
|
|---|
| 249 | /**
|
|---|
| 250 | * getBeforeIndex
|
|---|
| 251 | * @param value0 TODO
|
|---|
| 252 | * @param value1 TODO
|
|---|
| 253 | * @returns String
|
|---|
| 254 | */
|
|---|
| 255 | public String getBeforeIndex(int value0, int value1) {
|
|---|
| 256 | return null; // TODO
|
|---|
| 257 | } // getBeforeIndex()
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 | } // AccessibleJTextComponent
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 | public static class KeyBinding
|
|---|
| 265 | {
|
|---|
| 266 | public KeyStroke key;
|
|---|
| 267 | public String actionName;
|
|---|
| 268 | public KeyBinding(KeyStroke key, String actionName)
|
|---|
| 269 | {
|
|---|
| 270 | this.key = key;
|
|---|
| 271 | this.actionName = actionName;
|
|---|
| 272 | }
|
|---|
| 273 | } // class KeyBinding
|
|---|
| 274 |
|
|---|
| 275 | int icon_gap;
|
|---|
| 276 | Icon icon;
|
|---|
| 277 | int align;
|
|---|
| 278 | Document doc;
|
|---|
| 279 |
|
|---|
| 280 | public JTextComponent()
|
|---|
| 281 | {
|
|---|
| 282 | this("", null, 0);
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | public JTextComponent(Icon image)
|
|---|
| 286 | {
|
|---|
| 287 | this("", image, 0);
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | public JTextComponent(Icon image, int horizontalAlignment)
|
|---|
| 291 | {
|
|---|
| 292 | this("", image, horizontalAlignment);
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | public JTextComponent(String text)
|
|---|
| 296 | {
|
|---|
| 297 | this(text, null, 0);
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | public JTextComponent(String text, int horizontalAlignment)
|
|---|
| 301 | {
|
|---|
| 302 | this(text, null, horizontalAlignment);
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | public JTextComponent(String text, Icon icon, int horizontalAlignment)
|
|---|
| 306 | {
|
|---|
| 307 | setDocument(new PlainDocument());
|
|---|
| 308 |
|
|---|
| 309 | // do the work.....
|
|---|
| 310 | setText(text);
|
|---|
| 311 | this.icon = icon;
|
|---|
| 312 | this.align = horizontalAlignment;
|
|---|
| 313 |
|
|---|
| 314 | // its an editor, so:
|
|---|
| 315 | enableEvents(AWTEvent.KEY_EVENT_MASK);
|
|---|
| 316 | updateUI();
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | public void setDocument(Document s)
|
|---|
| 320 | {
|
|---|
| 321 | doc = s;
|
|---|
| 322 | revalidate();
|
|---|
| 323 | repaint();
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | public Document getDocument()
|
|---|
| 327 | {
|
|---|
| 328 | if (doc == null)
|
|---|
| 329 | System.out.println("doc == null !!!");
|
|---|
| 330 | return doc;
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | protected int checkHorizontalKey(int key, String message)
|
|---|
| 334 | {
|
|---|
| 335 | // Verify that key is a legal value for the horizontalAlignment properties.
|
|---|
| 336 | return 0;
|
|---|
| 337 | }
|
|---|
| 338 | protected int checkVerticalKey(int key, String message)
|
|---|
| 339 | {
|
|---|
| 340 | // Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
|
|---|
| 341 | return 0;
|
|---|
| 342 | }
|
|---|
| 343 | public AccessibleContext getAccessibleContext()
|
|---|
| 344 | {
|
|---|
| 345 | // Get the AccessibleContext of this object
|
|---|
| 346 | return null;
|
|---|
| 347 | }
|
|---|
| 348 | public Icon getDisabledIcon()
|
|---|
| 349 | {
|
|---|
| 350 | return null;
|
|---|
| 351 | }
|
|---|
| 352 | public int getDisplayedMnemonic()
|
|---|
| 353 | {
|
|---|
| 354 | // Return the keycode that indicates a mnemonic key.
|
|---|
| 355 | return 0;
|
|---|
| 356 | }
|
|---|
| 357 | public int getHorizontalAlignment()
|
|---|
| 358 | {
|
|---|
| 359 | // Returns the alignment of the label's contents along the X axis.
|
|---|
| 360 | return 0;
|
|---|
| 361 | }
|
|---|
| 362 | public int getHorizontalTextPosition()
|
|---|
| 363 | {
|
|---|
| 364 | // Returns the horizontal position of the label's text, relative to its image.
|
|---|
| 365 | return 0;
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | public Icon getIcon()
|
|---|
| 369 | { return icon; }
|
|---|
| 370 | public int getIconTextGap()
|
|---|
| 371 | { return icon_gap; }
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 | Component getLabelFor()
|
|---|
| 375 | {
|
|---|
| 376 | // Get the component this is labelling.
|
|---|
| 377 | return null;
|
|---|
| 378 | }
|
|---|
| 379 |
|
|---|
| 380 | public void setText(String text)
|
|---|
| 381 | {
|
|---|
| 382 | getDocument().remove(0,doc.getLength());
|
|---|
| 383 | getDocument().insertString(0, text, null);
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | public String getText()
|
|---|
| 387 | {
|
|---|
| 388 | return getDocument().getText(0,
|
|---|
| 389 | getDocument().getLength());
|
|---|
| 390 | }
|
|---|
| 391 |
|
|---|
| 392 | public String getUIClassID()
|
|---|
| 393 | {
|
|---|
| 394 | // Returns a string that specifies the name of the l&f class that renders this component.
|
|---|
| 395 | return "JTextComponent";
|
|---|
| 396 | }
|
|---|
| 397 | public int getVerticalAlignment()
|
|---|
| 398 | {
|
|---|
| 399 | // Returns the alignment of the label's contents along the Y axis.
|
|---|
| 400 | return 0;
|
|---|
| 401 | }
|
|---|
| 402 | public int getVerticalTextPosition()
|
|---|
| 403 | {
|
|---|
| 404 | // Returns the vertical position of the label's text, relative to its image.
|
|---|
| 405 | return 0;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
|
|---|
| 409 | {
|
|---|
| 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);
|
|---|
| 412 | }
|
|---|
| 413 | protected String paramString()
|
|---|
| 414 | {
|
|---|
| 415 | // Returns a string representation of this JTextComponent.
|
|---|
| 416 | return "JTextComponent";
|
|---|
| 417 | }
|
|---|
| 418 | void setDisabledIcon(Icon disabledIcon)
|
|---|
| 419 | {
|
|---|
| 420 | // Set the icon to be displayed if this JTextComponent is "disabled" (JTextComponent.setEnabled(false)).
|
|---|
| 421 | }
|
|---|
| 422 | void setDisplayedMnemonic(char aChar)
|
|---|
| 423 | {
|
|---|
| 424 | // Specifies the displayedMnemonic as a char value.
|
|---|
| 425 | }
|
|---|
| 426 | void setDisplayedMnemonic(int key)
|
|---|
| 427 | {
|
|---|
| 428 | // Specify a keycode that indicates a mnemonic key.
|
|---|
| 429 | }
|
|---|
| 430 | void setHorizontalAlignment(int alignment)
|
|---|
| 431 | {
|
|---|
| 432 | // Sets the alignment of the label's contents along the X axis.
|
|---|
| 433 | }
|
|---|
| 434 | void setHorizontalTextPosition(int textPosition)
|
|---|
| 435 | {
|
|---|
| 436 | // Sets the horizontal position of the label's text, relative to its image.
|
|---|
| 437 | }
|
|---|
| 438 | void setIcon(Icon icon)
|
|---|
| 439 | {
|
|---|
| 440 | // Defines the icon this component will display.
|
|---|
| 441 | }
|
|---|
| 442 | public void setIconTextGap(int iconTextGap)
|
|---|
| 443 | {
|
|---|
| 444 | // If both the icon and text properties are set, this property defines the space between them.
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | public void setLabelFor(Component c)
|
|---|
| 448 | {
|
|---|
| 449 | // Set the component this is labelling.
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | public void setVerticalAlignment(int alignment)
|
|---|
| 453 | {
|
|---|
| 454 | // Sets the alignment of the label's contents along the Y axis.
|
|---|
| 455 | }
|
|---|
| 456 | public void setVerticalTextPosition(int textPosition)
|
|---|
| 457 | {
|
|---|
| 458 | // Sets the vertical position of the label's text, relative to its image.
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | public TextUI getUI()
|
|---|
| 462 | { return (TextUI) ui;
|
|---|
| 463 | }
|
|---|
| 464 |
|
|---|
| 465 | public void updateUI()
|
|---|
| 466 | {
|
|---|
| 467 | TextUI b = (TextUI)UIManager.getUI(this);
|
|---|
| 468 | setUI(b);
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | public Dimension getPreferredScrollableViewportSize()
|
|---|
| 472 | {
|
|---|
| 473 | return null;
|
|---|
| 474 | }
|
|---|
| 475 | public int getScrollableUnitIncrement(Rectangle visible, int orientation,
|
|---|
| 476 | int direction)
|
|---|
| 477 | {
|
|---|
| 478 | return 0;
|
|---|
| 479 | }
|
|---|
| 480 | public int getScrollableBlockIncrement(Rectangle visible, int orientation,
|
|---|
| 481 | int direction)
|
|---|
| 482 | {
|
|---|
| 483 | return 0;
|
|---|
| 484 | }
|
|---|
| 485 | } // class JTextComponent
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|