diff options
Diffstat (limited to 'libjava/javax/swing/text')
22 files changed, 1409 insertions, 720 deletions
diff --git a/libjava/javax/swing/text/AbstractDocument.java b/libjava/javax/swing/text/AbstractDocument.java index 5612fc94bc5..c1ea098c0a9 100644 --- a/libjava/javax/swing/text/AbstractDocument.java +++ b/libjava/javax/swing/text/AbstractDocument.java @@ -42,7 +42,6 @@ import java.util.Dictionary; import java.util.Enumeration; import java.util.EventListener; import java.util.Vector; - import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.event.EventListenerList; @@ -57,232 +56,15 @@ import javax.swing.undo.UndoableEdit; public abstract class AbstractDocument implements Document, Serializable { - public abstract class AbstractElement - implements Element, TreeNode, Serializable - { - private static final long serialVersionUID = 1265312733007397733L; - - int count; - int offset; - AttributeSet attr; - Vector elts = new Vector(); - String name; - Element parent; - Vector kids = new Vector(); - TreeNode tree_parent; - - public AbstractElement(Element p, AttributeSet s) - { - parent = p; - attr = s; - } - - public Enumeration children() - { - return kids.elements(); - } - - public boolean getAllowsChildren() - { - return true; - } - - public TreeNode getChildAt(int index) - { - return (TreeNode) kids.elementAt(index); - } - - public int getChildCount() - { - return kids.size(); - } - - public int getIndex(TreeNode node) - { - return kids.indexOf(node); - } - - public TreeNode getParent() - { - return tree_parent; - } - - public AttributeSet getAttributes() - { - return attr; - } - - public Document getDocument() - { - return AbstractDocument.this; - } - - public Element getElement(int index) - { - return (Element) elts.elementAt(index); - } - - public String getName() - { - return name; - } - - public Element getParentElement() - { - return parent; - } - - public abstract boolean isLeaf(); - - public abstract int getEndOffset(); - - public abstract int getElementCount(); - - public abstract int getElementIndex(int offset); - - public abstract int getStartOffset(); - } - - public interface AttributeContext - { - } - - public class BranchElement extends AbstractElement - { - private static final long serialVersionUID = -8595176318868717313L; - - public BranchElement(Element e, AttributeSet a, int s, int end) - { - super(e, a); - } - - public boolean isLeaf() - { - return false; - } - - public int getEndOffset() - { - return 0; - } - - public int getElementCount() - { - return 0; - } - - public int getElementIndex(int offset) - { - return 0; - } - - public int getStartOffset() - { - return 0; - } - } - - public interface Content - { - Position createPosition(int offset) throws BadLocationException; - - int length(); - - UndoableEdit insertString(int where, String str) - throws BadLocationException; - - UndoableEdit remove(int where, int nitems) throws BadLocationException; - - String getString(int where, int len) throws BadLocationException; - - void getChars(int where, int len, Segment txt) throws BadLocationException; - } - - public class DefaultDocumentEvent extends CompoundEdit - implements DocumentEvent - { - private static final long serialVersionUID = -7406103236022413522L; - - public int len; - public int off; - - public Document getDocument() - { - return AbstractDocument.this; - } - - public int getLength() - { - return len; - } - - public int getOffset() - { - return off; - } - - public DocumentEvent.EventType getType() - { - return null; - } - - public DocumentEvent.ElementChange getChange(Element elem) - { - return null; - } - } - - public static class ElementEdit extends AbstractUndoableEdit - { - private static final long serialVersionUID = -1216620962142928304L; - } - - public class LeafElement extends AbstractElement - { - private static final long serialVersionUID = 5115368706941283802L; - - public LeafElement(Element e, AttributeSet a, int s, int end) - { - super(e, a); - } - - public boolean isLeaf() - { - return true; - } - - public int getEndOffset() - { - return 0; - } - - public int getElementCount() - { - return 0; - } - - public int getElementIndex(int offset) - { - return 0; - } - - public int getStartOffset() - { - return 0; - } - } - private static final long serialVersionUID = -116069779446114664L; - protected static final String BAD_LOCATION = "document location failure"; - public static final String BidiElementName = "bidi level"; public static final String ContentElementName = "content"; public static final String ParagraphElementName = "paragraph"; public static final String SectionElementName = "section"; public static final String ElementNameAttribute = "$ename"; - Content content; + protected EventListenerList listenerList = new EventListenerList(); protected AbstractDocument(Content doc) { @@ -294,8 +76,6 @@ public abstract class AbstractDocument content = doc; } - protected EventListenerList listenerList = new EventListenerList(); - // these still need to be implemented by a derived class: public abstract Element getParagraphElement(int pos); @@ -312,14 +92,16 @@ public abstract class AbstractDocument return new LeafElement(parent, a, p0, p1 - p0); } - public Position createPosition(int offs) + public Position createPosition(final int offset) throws BadLocationException { - final int a = offs; + if (offset < 0 || offset > getLength()) + throw new BadLocationException(getText(0, getLength()), offset); + return new Position() { public int getOffset() { - return a; + return offset; } }; } @@ -416,21 +198,13 @@ public abstract class AbstractDocument return null; } - public String getText(int offset, int length) - { - try + public String getText(int offset, int length) throws BadLocationException { return content.getString(offset, length); } - catch (Exception e) - { - System.out.println("Hmmm, fail to getText: " + offset + " -> " - + length); - return null; - } - } public void getText(int offset, int length, Segment txt) + throws BadLocationException { String a = getText(offset, length); @@ -439,6 +213,7 @@ public abstract class AbstractDocument txt.offset = 0; txt.count = 0; txt.array = new char[0]; + return; } @@ -478,7 +253,7 @@ public abstract class AbstractDocument { } - public void remove(int offs, int len) + public void remove(int offset, int length) throws BadLocationException { } @@ -565,4 +340,316 @@ public abstract class AbstractDocument protected void writeUnlock() { } + + public interface AttributeContext + { + AttributeSet addAttribute(AttributeSet old, Object name, Object value); + + AttributeSet addAttributes(AttributeSet old, AttributeSet attributes); + + AttributeSet getEmptySet(); + + void reclaim(AttributeSet attributes); + + AttributeSet removeAttribute(AttributeSet old, Object name); + + AttributeSet removeAttributes(AttributeSet old, AttributeSet attributes); + + AttributeSet removeAttributes(AttributeSet old, Enumeration names); + } + + public interface Content + { + Position createPosition(int offset) throws BadLocationException; + + int length(); + + UndoableEdit insertString(int where, String str) + throws BadLocationException; + + UndoableEdit remove(int where, int nitems) throws BadLocationException; + + String getString(int where, int len) throws BadLocationException; + + void getChars(int where, int len, Segment txt) throws BadLocationException; + } + + public abstract class AbstractElement + implements Element, TreeNode, Serializable + { + private static final long serialVersionUID = 1265312733007397733L; + int count; + int offset; + AttributeSet attr; + Vector elts = new Vector(); + String name; + Element parent; + Vector kids = new Vector(); + TreeNode tree_parent; + + public AbstractElement(Element p, AttributeSet s) + { + parent = p; + attr = s; + } + + public Enumeration children() + { + return kids.elements(); + } + + public boolean getAllowsChildren() + { + return true; + } + + public TreeNode getChildAt(int index) + { + return (TreeNode) kids.elementAt(index); + } + + public int getChildCount() + { + return kids.size(); + } + + public int getIndex(TreeNode node) + { + return kids.indexOf(node); + } + + public TreeNode getParent() + { + return tree_parent; + } + + public AttributeSet getAttributes() + { + return attr; + } + + public Document getDocument() + { + return AbstractDocument.this; + } + + public Element getElement(int index) + { + return (Element) elts.elementAt(index); + } + + public String getName() + { + return name; + } + + public Element getParentElement() + { + return parent; + } + + public abstract boolean isLeaf(); + + public abstract int getEndOffset(); + + public abstract int getElementCount(); + + public abstract int getElementIndex(int offset); + + public abstract int getStartOffset(); + } + + public class BranchElement extends AbstractElement + { + private static final long serialVersionUID = -8595176318868717313L; + private int start; + private int end; + private Vector children = new Vector(); + + public BranchElement(Element parent, AttributeSet attributes, int start, + int end) + { + super(parent, attributes); + this.start = start; + this.end = end; + } + + public Enumeration children() + { + return children.elements(); + } + + public boolean getAllowsChildren() + { + return true; + } + + public Element getElement(int index) + { + return (Element) children.get(index); + } + + public int getElementCount() + { + return children.size(); + } + + public int getElementIndex(int offset) + { + return children.indexOf(positionToElement(offset)); + } + + public int getEndOffset() + { + return end; + } + + public String getName() + { + return "AbstractDocument.BranchElement"; + } + + public int getStartOffset() + { + return start; + } + + public boolean isLeaf() + { + return false; + } + + public Element positionToElement(int position) + { + // XXX: There is surely a better algorithm + // as beginning from first element each time. + for (int index = 0; index < children.size(); ++index) + { + Element elem = (Element) children.get(index); + + if ((elem.getStartOffset() <= position) + && (position < elem.getEndOffset())) + return elem; + } + + return null; + } + + public void replace(int offset, int length, Element[] elems) + { + for (int index = 0; index < length; ++index) + children.removeElementAt(offset); + + for (int index = 0; index < elems.length; ++index) + children.add(offset + index, elems[index]); + } + + public String toString() + { + return getName() + ": " + "content"; + } + } + + public class DefaultDocumentEvent extends CompoundEdit + implements DocumentEvent + { + private static final long serialVersionUID = -7406103236022413522L; + public int len; + public int off; + + public Document getDocument() + { + return AbstractDocument.this; + } + + public int getLength() + { + return len; + } + + public int getOffset() + { + return off; + } + + public DocumentEvent.EventType getType() + { + return null; + } + + public DocumentEvent.ElementChange getChange(Element elem) + { + return null; + } + } + + public static class ElementEdit extends AbstractUndoableEdit + { + private static final long serialVersionUID = -1216620962142928304L; + } + + public class LeafElement extends AbstractElement + { + private static final long serialVersionUID = 5115368706941283802L; + private int start; + private int end; + + public LeafElement(Element parent, AttributeSet attributes, int start, + int end) + { + super(parent, attributes); + this.start = start; + this.end = end; + } + + public Enumeration children() + { + return null; + } + + public boolean getAllowsChildren() + { + return false; + } + + public Element getElement() + { + return null; + } + + public int getElementCount() + { + return 0; + } + + public int getElementIndex(int offset) + { + return -1; + } + + public int getEndOffset() + { + return end; + } + + public String getName() + { + return "AbstractDocument.LeafElement"; + } + + public int getStartOffset() + { + return start; + } + + public boolean isLeaf() + { + return true; + } + + public String toString() + { + return getName() + ": " + "content"; + } + } } diff --git a/libjava/javax/swing/text/AttributeSet.java b/libjava/javax/swing/text/AttributeSet.java index 5c08a04f013..3c31767cf3a 100644 --- a/libjava/javax/swing/text/AttributeSet.java +++ b/libjava/javax/swing/text/AttributeSet.java @@ -41,6 +41,22 @@ import java.util.Enumeration; public interface AttributeSet { + static interface CharacterAttribute + { + } + + static interface ColorAttribute + { + } + + static interface FontAttribute + { + } + + static interface ParagraphAttribute + { + } + boolean containsAttribute(Object name, Object value); boolean containsAttributes(AttributeSet attributes); AttributeSet copyAttributes(); diff --git a/libjava/javax/swing/text/ComponentView.java b/libjava/javax/swing/text/ComponentView.java index bd509b8dbcb..0305a717462 100644 --- a/libjava/javax/swing/text/ComponentView.java +++ b/libjava/javax/swing/text/ComponentView.java @@ -79,6 +79,7 @@ public class ComponentView extends View } public Shape modelToView(int pos, Shape a, Position.Bias b) + throws BadLocationException { return null; } diff --git a/libjava/javax/swing/text/DefaultCaret.java b/libjava/javax/swing/text/DefaultCaret.java index 8a17a369ba5..968bf1ffdf6 100644 --- a/libjava/javax/swing/text/DefaultCaret.java +++ b/libjava/javax/swing/text/DefaultCaret.java @@ -41,7 +41,9 @@ import java.awt.Color; import java.awt.Graphics; import java.awt.Point; import java.awt.Rectangle; +import java.awt.event.FocusEvent; import java.awt.event.FocusListener; +import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.util.EventListener; @@ -54,6 +56,8 @@ import javax.swing.event.EventListenerList; public class DefaultCaret extends Rectangle implements Caret, FocusListener, MouseListener, MouseMotionListener { + private static final long serialVersionUID = 228155774675466193L; + protected ChangeEvent changeEvent = new ChangeEvent(this); protected EventListenerList listenerList = new EventListenerList(); @@ -67,39 +71,47 @@ public class DefaultCaret extends Rectangle boolean vis = true; - public void mouseDragged(java.awt.event.MouseEvent evt) + public void mouseDragged(MouseEvent event) + { + } + + public void mouseMoved(MouseEvent event) + { + } + + public void mouseClicked(MouseEvent event) { } - public void mouseMoved(java.awt.event.MouseEvent evt) + public void mouseEntered(MouseEvent event) { } - public void mouseClicked(java.awt.event.MouseEvent evt) + public void mouseExited(MouseEvent event) { } - public void mouseEntered(java.awt.event.MouseEvent evt) + public void mousePressed(MouseEvent event) { } - public void mouseExited(java.awt.event.MouseEvent evt) + public void mouseReleased(MouseEvent event) { } - public void mousePressed(java.awt.event.MouseEvent evt) + public void focusGained(FocusEvent event) { } - public void mouseReleased(java.awt.event.MouseEvent evt) + public void focusLost(FocusEvent event) { } - public void focusGained(java.awt.event.FocusEvent evt) + protected void moveCaret(MouseEvent event) { } - public void focusLost(java.awt.event.FocusEvent evt) + protected void positionCaret(MouseEvent event) { } @@ -144,7 +156,7 @@ public class DefaultCaret extends Rectangle return vis_sel; } - private void repaint() + protected final void repaint() { if (parent != null) parent.repaint(); diff --git a/libjava/javax/swing/text/DefaultEditorKit.java b/libjava/javax/swing/text/DefaultEditorKit.java index 037ca9166f9..8611de5a0eb 100644 --- a/libjava/javax/swing/text/DefaultEditorKit.java +++ b/libjava/javax/swing/text/DefaultEditorKit.java @@ -38,14 +38,17 @@ exception statement from your version. */ package javax.swing.text; import java.io.InputStream; +import java.io.IOException; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; import javax.swing.Action; import javax.swing.JEditorPane; + public class DefaultEditorKit extends EditorKit { + private static final long serialVersionUID = 9017245433028523428L; public static final String backwardAction = "caret-backward"; public static final String beepAction = "beep"; public static final String beginAction = "caret-begin"; @@ -60,7 +63,7 @@ public class DefaultEditorKit extends EditorKit public static final String downAction = "caret-down"; public static final String endAction = "caret-end"; public static final String endLineAction = "caret-end-line"; - public static final String endOfLineStringProperty = "__EndOfLine__"; + public static final String EndOfLineStringProperty = "__EndOfLine__"; public static final String endParagraphAction = "caret-end-paragraph"; public static final String endWordAction = "caret-end-word"; public static final String forwardAction = "caret-forward"; @@ -77,16 +80,19 @@ public class DefaultEditorKit extends EditorKit public static final String selectionBackwardAction = "selection-backward"; public static final String selectionBeginAction = "selection-begin"; public static final String selectionBeginLineAction = "selection-begin-line"; - public static final String selectionBeginParagraphAction = "selection-begin-paragraph"; + public static final String selectionBeginParagraphAction = + "selection-begin-paragraph"; public static final String selectionBeginWordAction = "selection-begin-word"; public static final String selectionDownAction = "selection-down"; public static final String selectionEndAction = "selection-end"; public static final String selectionEndLineAction = "selection-end-line"; - public static final String selectionEndParagraphAction = "selection-end-paragraph"; + public static final String selectionEndParagraphAction = + "selection-end-paragraph"; public static final String selectionEndWordAction = "selection-end-word"; public static final String selectionForwardAction = "selection-forward"; public static final String selectionNextWordAction = "selection-next-word"; - public static final String selectionPreviousWordAction = "selection-previous-word"; + public static final String selectionPreviousWordAction = + "selection-previous-word"; public static final String selectionUpAction = "selection-up"; public static final String selectLineAction = "select-line"; public static final String selectParagraphAction = "select-paragraph"; @@ -94,48 +100,63 @@ public class DefaultEditorKit extends EditorKit public static final String upAction = "caret-up"; public static final String writableAction = "set-writable"; - void deinstall(JEditorPane c) + public DefaultEditorKit() + { + } + + /** + * Called when the kit is being removed from the JEditorPane. + */ + public void deinstall(JEditorPane c) { - // Called when the kit is being removed from the JEditorPane. } - void install(JEditorPane c) + + public void install(JEditorPane c) { } - Caret createCaret() + public Caret createCaret() { return null; } - Document createDefaultDocument() + + public Document createDefaultDocument() { return new PlainDocument(); } - Action[] getActions() + public Action[] getActions() { return null; } - String getContentType() + public String getContentType() { return "text/plain"; } - ViewFactory getViewFactory() + public ViewFactory getViewFactory() { return null; } - void read(InputStream in, Document doc, int pos) + + public void read(InputStream in, Document doc, int pos) + throws BadLocationException, IOException { } - void read(Reader in, Document doc, int pos) + + public void read(Reader in, Document doc, int pos) + throws BadLocationException, IOException { } - void write(OutputStream out, Document doc, int pos, int len) + + public void write(OutputStream out, Document doc, int pos, int len) + throws BadLocationException, IOException { } - void write(Writer out, Document doc, int pos, int len) + + public void write(Writer out, Document doc, int pos, int len) + throws BadLocationException, IOException { } } - diff --git a/libjava/javax/swing/text/DefaultHighlighter.java b/libjava/javax/swing/text/DefaultHighlighter.java new file mode 100644 index 00000000000..003d17d1a8e --- /dev/null +++ b/libjava/javax/swing/text/DefaultHighlighter.java @@ -0,0 +1,150 @@ +/* DefaultHighlighter.java -- + Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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. */ + + +package javax.swing.text; + +import java.awt.Graphics; +import java.awt.Shape; +import java.util.Vector; + +import javax.swing.text.JTextComponent; +import javax.swing.text.View; + + +public class DefaultHighlighter extends LayeredHighlighter +{ + private class HighlightEntry + { + int p0; + int p1; + Highlighter.HighlightPainter painter; + + public HighlightEntry(int p0, int p1, Highlighter.HighlightPainter painter) + { + this.p0 = p0; + this.p1 = p1; + this.painter = painter; + } + + public int getStartPosition() + { + return p0; + } + + public int getEndPosition() + { + return p1; + } + + public Highlighter.HighlightPainter getPainter() + { + return painter; + } + } + + private JTextComponent textComponent; + private Vector highlights = new Vector(); + + public DefaultHighlighter() + { + } + + private void checkPositions(int p0, int p1) + throws BadLocationException + { + if (p0 < 0) + throw new BadLocationException("DefaultHighlighter", p0); + + if (p1 < p0) + throw new BadLocationException("DefaultHighlighter", p1); + } + + public void install(JTextComponent c) + { + textComponent = c; + removeAllHighlights(); + } + + public void deinstall(JTextComponent c) + { + textComponent = null; + } + + public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter painter) + throws BadLocationException + { + checkPositions(p0, p1); + HighlightEntry entry = new HighlightEntry(p0, p1, painter); + highlights.add(entry); + return entry; + } + + public void removeHighlight(Object tag) + { + highlights.remove(tag); + } + + public void removeAllHighlights() + { + highlights.clear(); + } + + public Highlighter.Highlight[] getHighlights() + { + return null; + } + + public void changeHighlight(Object tag, int p0, int p1) + throws BadLocationException + { + checkPositions(p0, p1); + HighlightEntry entry = (HighlightEntry) tag; + entry.p0 = p0; + entry.p1 = p1; + } + + public void paintLayeredHighlights(Graphics g, int p0, int p1, + Shape viewBounds, JTextComponent editor, + View view) + { + } + + public void paint(Graphics g) + { + } +} diff --git a/libjava/javax/swing/text/Document.java b/libjava/javax/swing/text/Document.java index 6ecb7ca21db..d197924bdf9 100644 --- a/libjava/javax/swing/text/Document.java +++ b/libjava/javax/swing/text/Document.java @@ -50,7 +50,8 @@ public interface Document void addUndoableEditListener(UndoableEditListener listener); - Position createPosition(int offs); + Position createPosition(int offs) + throws BadLocationException; Element getDefaultRootElement(); @@ -64,16 +65,19 @@ public interface Document Position getStartPosition(); - String getText(int offset, int length); + String getText(int offset, int length) + throws BadLocationException; - void getText(int offset, int length, Segment txt); + void getText(int offset, int length, Segment txt) + throws BadLocationException; void insertString(int offset, String str, AttributeSet a) throws BadLocationException; void putProperty(Object key, Object value); - void remove(int offs, int len); + void remove(int offs, int len) + throws BadLocationException; void removeDocumentListener(DocumentListener listener); diff --git a/libjava/javax/swing/text/EditorKit.java b/libjava/javax/swing/text/EditorKit.java index acc21c114c1..0609332f0b8 100644 --- a/libjava/javax/swing/text/EditorKit.java +++ b/libjava/javax/swing/text/EditorKit.java @@ -38,38 +38,58 @@ exception statement from your version. */ package javax.swing.text; import java.io.InputStream; +import java.io.IOException; import java.io.OutputStream; import java.io.Reader; +import java.io.Serializable; import java.io.Writer; import javax.swing.Action; import javax.swing.JEditorPane; -public abstract class EditorKit implements Cloneable + +public abstract class EditorKit + implements Cloneable, Serializable { - EditorKit() + private static final long serialVersionUID = -5044124649345887822L; + + public EditorKit() { } - EditorKit(EditorKit kit) + public Object clone() { + try + { + return super.clone(); } - - void deinstall(JEditorPane c) + catch (CloneNotSupportedException e) { - // Called when the kit is being removed from the JEditorPane. + return null; } - void install(JEditorPane c) + } + + /** + * Called when the kit is being removed from the JEditorPane. + */ + public void deinstall(JEditorPane c) { } - abstract Caret createCaret(); - abstract Document createDefaultDocument(); - abstract Action[] getActions(); - abstract String getContentType(); - abstract ViewFactory getViewFactory(); - abstract void read(InputStream in, Document doc, int pos); - abstract void read(Reader in, Document doc, int pos); - abstract void write(OutputStream out, Document doc, int pos, int len); - abstract void write(Writer out, Document doc, int pos, int len); + public void install(JEditorPane c) + { } + public abstract Caret createCaret(); + public abstract Document createDefaultDocument(); + public abstract Action[] getActions(); + public abstract String getContentType(); + public abstract ViewFactory getViewFactory(); + public abstract void read(InputStream in, Document doc, int pos) + throws BadLocationException, IOException; + public abstract void read(Reader in, Document doc, int pos) + throws BadLocationException, IOException; + public abstract void write(OutputStream out, Document doc, int pos, int len) + throws BadLocationException, IOException; + public abstract void write(Writer out, Document doc, int pos, int len) + throws BadLocationException, IOException; +} diff --git a/libjava/javax/swing/text/PlainEditorKit.java b/libjava/javax/swing/text/FieldView.java index 1c8c5de8b96..29a00acfa3c 100644 --- a/libjava/javax/swing/text/PlainEditorKit.java +++ b/libjava/javax/swing/text/FieldView.java @@ -1,5 +1,5 @@ -/* PlainEditorKit.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. +/* FieldView.java -- + Copyright (C) 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,69 +35,63 @@ 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. */ + package javax.swing.text; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; -import javax.swing.Action; -import javax.swing.JEditorPane; +import java.awt.Component; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Shape; + -public class PlainEditorKit extends EditorKit +public class FieldView extends PlainView { - public PlainEditorKit() - { - } - - public PlainEditorKit(PlainEditorKit kit) - { - super(kit); - } - - protected Object clone() - { - return new PlainEditorKit(this); - } - void deinstall(JEditorPane c) - { - // Called when the kit is being removed from the JEditorPane. - } - void install(JEditorPane c) - { - } - - Caret createCaret() - { - return null; - } - Document createDefaultDocument() - { - return null; - } - Action[] getActions() - { - return null; - } - String getContentType() - { - return null; - } - ViewFactory getViewFactory() - { - return null; - } - void read(InputStream in, Document doc, int pos) - { - } - void read(Reader in, Document doc, int pos) - { - } - void write(OutputStream out, Document doc, int pos, int len) - { - } - void write(Writer out, Document doc, int pos, int len) - { - } -} + public FieldView(Element elem) + { + super(elem); + } + + protected FontMetrics getFontMetrics() + { + Component container = getContainer(); + return container.getFontMetrics(container.getFont()); + } + + public float getPreferredSpan(int axis) + { + if (axis != X_AXIS && axis != Y_AXIS) + throw new IllegalArgumentException(); + FontMetrics fm = getFontMetrics(); + + if (axis == Y_AXIS) + return fm.getHeight(); + + String text; + Element elem = getElement(); + + try + { + text = elem.getDocument().getText(elem.getStartOffset(), + elem.getEndOffset()); + } + catch (BadLocationException e) + { + // This should never happen. + text = ""; + System.out.println("Michael: FieldView.getPreferredSpan: Error"); + } + + return fm.stringWidth(text); + } + + public int getResizeWeight(int axis) + { + return axis = axis == X_AXIS ? 1 : 0; + } + + public void paint(Graphics g, Shape s) + { + drawLine(0, g, 0, 0); + } +} diff --git a/libjava/javax/swing/text/Highlighter.java b/libjava/javax/swing/text/Highlighter.java new file mode 100644 index 00000000000..77471d17768 --- /dev/null +++ b/libjava/javax/swing/text/Highlighter.java @@ -0,0 +1,80 @@ +/* Highlighter.java -- + Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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. */ + + +package javax.swing.text; + +import java.awt.Graphics; +import java.awt.Shape; + + +public interface Highlighter +{ + public interface Highlight + { + int getEndOffset(); + + int getStartOffset(); + + HighlightPainter getPainter(); + } + + public interface HighlightPainter + { + public void paint(Graphics g, int p0, int p1, Shape bounds, + JTextComponent c); + } + + void install(JTextComponent c); + + void deinstall(JTextComponent c); + + Object addHighlight(int p0, int p1, HighlightPainter p) + throws BadLocationException; + + void removeAllHighlights(); + + void removeHighlight(Object tag); + + void changeHighlight(Object tag, int p0, int p1) + throws BadLocationException; + + Highlight[] getHighlights(); + + void paint(Graphics g); +} + diff --git a/libjava/javax/swing/text/JTextComponent.java b/libjava/javax/swing/text/JTextComponent.java index d5227d03e08..e44c5296d86 100644 --- a/libjava/javax/swing/text/JTextComponent.java +++ b/libjava/javax/swing/text/JTextComponent.java @@ -38,6 +38,7 @@ exception statement from your version. */ package javax.swing.text; import java.awt.AWTEvent; +import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Image; @@ -67,12 +68,6 @@ import javax.swing.plaf.TextUI; public abstract class JTextComponent extends JComponent implements Scrollable, Accessible { -// public class AccessibleJTextComponent extends AccessibleJComponent -// implements AccessibleText, CaretListener, DocumentListener, -// AccessibleAction, AccessibleEditableText -// { -// } - /** * AccessibleJTextComponent */ @@ -82,11 +77,6 @@ public abstract class JTextComponent extends JComponent private static final long serialVersionUID = 7664188944091413696L; /** - * caretPos - */ - int caretPos; - - /** * Constructor AccessibleJTextComponent * @param component TODO */ @@ -280,6 +270,12 @@ public abstract class JTextComponent extends JComponent public KeyStroke key; public String actionName; + /** + * Creates a new <code>KeyBinding</code> instance. + * + * @param key a <code>KeyStroke</code> value + * @param actionName a <code>String</code> value + */ public KeyBinding(KeyStroke key, String actionName) { this.key = key; @@ -294,8 +290,16 @@ public abstract class JTextComponent extends JComponent private Document doc; private Caret caret; + private Highlighter highlighter; + private Color caretColor; + private Color disabledTextColor; + private Color selectedTextColor; + private Color selectionColor; private boolean editable; + /** + * Creates a new <code>JTextComponent</code> instance. + */ public JTextComponent() { enableEvents(AWTEvent.KEY_EVENT_MASK); @@ -311,13 +315,13 @@ public abstract class JTextComponent extends JComponent public Document getDocument() { - if (doc == null) - System.out.println("doc == null !!!"); return doc; } /** - * Get the AccessibleContext of this object + * Get the <code>AccessibleContext<code> of this object. + * + * @return an <code>AccessibleContext</code> object */ public AccessibleContext getAccessibleContext() { @@ -351,7 +355,18 @@ public abstract class JTextComponent extends JComponent */ public String getText() { - return getDocument().getText(0, getDocument().getLength()); + if (doc == null) + return null; + + try + { + return doc.getText(0, doc.getLength()); + } + catch (BadLocationException e) + { + // This should never happen. + return ""; + } } /** @@ -389,14 +404,33 @@ public abstract class JTextComponent extends JComponent return "JTextComponent"; } + /** + * This method returns the label's UI delegate. + * + * @return The label's UI delegate. + */ public TextUI getUI() { - return (TextUI) UIManager.getUI(this); + return (TextUI) ui; + } + + /** + * This method sets the label's UI delegate. + * + * @param ui The label's UI delegate. + */ + public void setUI(TextUI newUI) + { + super.setUI(newUI); } + /** + * This method resets the label's UI delegate to the default UI for the + * current look and feel. + */ public void updateUI() { - setUI(getUI()); + setUI((TextUI) UIManager.getUI(this)); } public Dimension getPreferredScrollableViewportSize() @@ -448,6 +482,61 @@ public abstract class JTextComponent extends JComponent } /** + * Sets a new <code>Caret</code> for this text component. + * + * @param newCaret the new <code>Caret</code> to set + */ + public void setCaret(Caret newCaret) + { + firePropertyChange("caret", caret, newCaret); + caret = newCaret; + } + + public Color getCaretColor() + { + return caretColor; + } + + public void setCaretColor(Color newColor) + { + firePropertyChange("caretColor", caretColor, newColor); + caretColor = newColor; + } + + public Color getDisabledTextColor() + { + return disabledTextColor; + } + + public void setDisabledTextColor(Color newColor) + { + firePropertyChange("disabledTextColor", caretColor, newColor); + disabledTextColor = newColor; + } + + public Color getSelectedTextColor() + { + return selectedTextColor; + } + + public void setSelectedTextColor(Color newColor) + { + firePropertyChange("selectedTextColor", caretColor, newColor); + selectedTextColor = newColor; + } + + public Color getSelectionColor() + { + return selectionColor; + } + + public void setSelectionColor(Color newColor) + { + firePropertyChange("selectionColor", caretColor, newColor); + selectionColor = newColor; + } + + /** * Retrisves the current caret position. * * @return the current position @@ -488,6 +577,17 @@ public abstract class JTextComponent extends JComponent caret.moveDot(position); } + public Highlighter getHighlighter() + { + return highlighter; + } + + public void setHighlighter(Highlighter newHighlighter) + { + firePropertyChange("highlighter", highlighter, newHighlighter); + highlighter = newHighlighter; + } + /** * Returns the start postion of the currently selected text. * @@ -556,6 +656,34 @@ public abstract class JTextComponent extends JComponent select(0, doc.getLength()); } + public synchronized void replaceSelection(String content) + { + int dot = caret.getDot(); + int mark = caret.getMark(); + + // If content is empty delete selection. + if (content == null) + { + caret.setDot(dot); + return; + } + + try + { + // Remove selected text. + if (dot != mark) + doc.remove(Math.min(dot, mark), Math.max(dot, mark)); + + // Insert new text. + doc.insertString(Math.min(dot, mark), content, null); + } + catch (BadLocationException e) + { + // This should never happen. + System.out.println("Michael: JTextComponent.replaceSelection: Error"); + } + } + public boolean getScrollableTracksViewportHeight() { if (getParent() instanceof JViewport) diff --git a/libjava/javax/swing/text/LayeredHighlighter.java b/libjava/javax/swing/text/LayeredHighlighter.java new file mode 100644 index 00000000000..45932217a02 --- /dev/null +++ b/libjava/javax/swing/text/LayeredHighlighter.java @@ -0,0 +1,61 @@ +/* LayeredHighlighter.java -- + Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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. */ + +package javax.swing.text; + +import java.awt.Graphics; +import java.awt.Shape; + +import javax.swing.text.JTextComponent; +import javax.swing.text.View; + + +public abstract class LayeredHighlighter + implements Highlighter +{ + public abstract static class LayerPainter + implements Highlighter.HighlightPainter + { + public abstract Shape paintLayer(Graphics g, int p0, int p1, + Shape viewBounds, JTextComponent editor, + View view); + } + + public abstract void paintLayeredHighlights(Graphics g, int p0, int p1, + Shape viewBounds, + JTextComponent editor, View view); +} diff --git a/libjava/javax/swing/text/PlainDocument.java b/libjava/javax/swing/text/PlainDocument.java index 930e5d3cb56..4a8adfca54d 100644 --- a/libjava/javax/swing/text/PlainDocument.java +++ b/libjava/javax/swing/text/PlainDocument.java @@ -44,6 +44,7 @@ public class PlainDocument extends AbstractDocument public static final String lineLimitAttribute = "lineLimit"; public static final String tabSizeAttribute = "tabSize"; + private Element rootElement; private int tabSize; public PlainDocument() @@ -55,11 +56,22 @@ public class PlainDocument extends AbstractDocument { super(content); tabSize = 8; + rootElement = createDefaultRoot(); + } + + protected AbstractDocument.AbstractElement createDefaultRoot() + { + BranchElement rootElement = + (BranchElement) createBranchElement(null, null); + Element[] lines = new Element[1]; + lines[0] = createLeafElement(rootElement, null, 0, 1); + rootElement.replace(0, 0, lines); + return rootElement; } public Element getDefaultRootElement() { - return null; + return rootElement; } public Element getParagraphElement(int pos) diff --git a/libjava/javax/swing/text/PlainView.java b/libjava/javax/swing/text/PlainView.java new file mode 100644 index 00000000000..229c7e193b0 --- /dev/null +++ b/libjava/javax/swing/text/PlainView.java @@ -0,0 +1,122 @@ +/* PlainView.java -- + Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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. */ + + +package javax.swing.text; + +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.awt.Shape; + + +public class PlainView extends View + implements TabExpander +{ + protected FontMetrics metrics; + + public PlainView(Element elem) + { + super(elem); + } + + public void drawLine(int lineIndex, Graphics g, int x, int y) + { + try + { + metrics = g.getFontMetrics(); + // FIXME: Selected text are not drawn yet. + drawUnselectedText(g, x, y, 0, getDocument().getLength()); + //drawSelectedText(g, , , , ); + } + catch (BadLocationException e) + { + // This should never happen. + } + } + + public int drawSelectedText(Graphics g, int x, int y, int p0, int p1) + throws BadLocationException + { + String text = getDocument().getText(p0, p1); + g.setColor(Color.WHITE); + g.drawString(text, x, y); + return metrics.stringWidth(text); + } + + public int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) + throws BadLocationException + { + String text = getDocument().getText(p0, p1); + g.setColor(Color.BLACK); + g.drawString(text, x, y); + return metrics.stringWidth(text); + } + + public void paint(Graphics g, Shape s) + { + System.out.println("Michael: PlainView.paint"); + + Rectangle rect = s.getBounds(); + + g.setColor(Color.WHITE); + g.fillRect(rect.x, rect.y, rect.width, rect.height); + + // FIXME: Text may be scrolled. + drawLine(0, g, rect.x, rect.y); + } + + public int getTabSize() + { + return 8; + } + + public float nextTabStop(float x, int tabStop) + { + System.out.println("Michael: PlainView.nextTabpStop: missing implementation"); + return x; + } + + public float getPreferredSpan(int axis) + { + if (axis != X_AXIS && axis != Y_AXIS) + throw new IllegalArgumentException(); + + return 10; + } +}
\ No newline at end of file diff --git a/libjava/javax/swing/text/Position.java b/libjava/javax/swing/text/Position.java index be5406043f2..64a91f2e1a4 100644 --- a/libjava/javax/swing/text/Position.java +++ b/libjava/javax/swing/text/Position.java @@ -1,5 +1,5 @@ /* Position.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,6 +42,20 @@ public interface Position { static class Bias { + public static final Bias Backward = new Bias("backward"); + public static final Bias Forward = new Bias("forward"); + + private String name; + + private Bias(String n) + { + name = n; + } + + public String toString() + { + return name; + } } int getOffset(); diff --git a/libjava/javax/swing/text/Segment.java b/libjava/javax/swing/text/Segment.java index 8934b453210..69e2fecfc38 100644 --- a/libjava/javax/swing/text/Segment.java +++ b/libjava/javax/swing/text/Segment.java @@ -37,22 +37,38 @@ exception statement from your version. */ package javax.swing.text; -public class Segment implements Cloneable, CharacterIterator +import java.text.CharacterIterator; + + +public class Segment + implements Cloneable, CharacterIterator { - char[] array; - int count; - int offset; + public char[] array; + public int count; + public int offset; + + public Segment() + { + } + + public Segment(char[] array, int offset, int count) + { + this.array = array; + this.offset = offset; + this.count = count; + } public Object clone() { - try { + try + { return super.clone(); - } catch (Exception e) { - System.err.println("Huuuhhh, this class implements cloneable !!!!!!"); - System.err.println("I think there is a bug in this JVM somewhere"); } + catch (CloneNotSupportedException e) + { return null; } + } public char current() { @@ -74,25 +90,30 @@ public class Segment implements Cloneable, CharacterIterator { return offset + count; } + public int getIndex() { return offset; } + public char last() { offset = getEndIndex() - 1; return array[offset]; } + public char next() { offset++; return array[offset]; } + public char previous() { offset--; return array[offset]; } + public char setIndex(int position) { offset = position; @@ -104,4 +125,3 @@ public class Segment implements Cloneable, CharacterIterator return new String(array, offset, count); } } - diff --git a/libjava/javax/swing/text/StyledEditorKit.java b/libjava/javax/swing/text/StyledEditorKit.java index f237247a01f..d3db03e208d 100644 --- a/libjava/javax/swing/text/StyledEditorKit.java +++ b/libjava/javax/swing/text/StyledEditorKit.java @@ -42,335 +42,241 @@ import java.awt.event.ActionEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Serializable; - import javax.swing.Action; import javax.swing.JEditorPane; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; + /** * StyledEditorKit + * * @author Andrew Selkirk - * @version 1.0 */ public class StyledEditorKit extends DefaultEditorKit { - static final long serialVersionUID = 7002391892985555948L; - - //------------------------------------------------------------- - // Classes ---------------------------------------------------- - //------------------------------------------------------------- + private static final long serialVersionUID = 7002391892985555948L; /** * UnderlineAction */ - public static class UnderlineAction extends StyledEditorKit.StyledTextAction { - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - + public static class UnderlineAction extends StyledEditorKit.StyledTextAction + { /** * Constructor UnderlineAction */ - public UnderlineAction() { + public UnderlineAction() + { super("TODO"); // TODO - } // UnderlineAction() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * actionPerformed * @param event TODO */ - public void actionPerformed(ActionEvent event) { + public void actionPerformed(ActionEvent event) + { // TODO - } // actionPerformed() - - - } // UnderlineAction + } + } /** * ItalicAction */ - public static class ItalicAction extends StyledEditorKit.StyledTextAction { - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - + public static class ItalicAction extends StyledEditorKit.StyledTextAction + { /** * Constructor ItalicAction */ - public ItalicAction() { + public ItalicAction() + { super("TODO"); // TODO - } // ItalicAction() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * actionPerformed * @param event TODO */ - public void actionPerformed(ActionEvent event) { + public void actionPerformed(ActionEvent event) + { // TODO - } // actionPerformed() - - - } // ItalicAction + } + } /** * BoldAction */ - public static class BoldAction extends StyledEditorKit.StyledTextAction { - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - + public static class BoldAction extends StyledEditorKit.StyledTextAction + { /** * Constructor BoldAction */ - public BoldAction() { + public BoldAction() + { super("TODO"); // TODO - } // BoldAction() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * actionPerformed * @param event TODO */ - public void actionPerformed(ActionEvent event) { + public void actionPerformed(ActionEvent event) + { // TODO - } // actionPerformed() - - - } // BoldAction + } + } /** * AlignmentAction */ - public static class AlignmentAction extends StyledEditorKit.StyledTextAction { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - + public static class AlignmentAction extends StyledEditorKit.StyledTextAction + { /** * a */ private int a; - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - /** * Constructor AlignmentAction * @param nm TODO * @param a TODO */ - public AlignmentAction(String nm, int a) { + public AlignmentAction(String nm, int a) + { super("TODO"); // TODO - } // AlignmentAction() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * actionPerformed * @param event TODO */ - public void actionPerformed(ActionEvent event) { + public void actionPerformed(ActionEvent event) + { // TODO - } // actionPerformed() - - - } // AlignmentAction + } + } /** * ForegroundAction */ - public static class ForegroundAction extends StyledEditorKit.StyledTextAction { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - + public static class ForegroundAction extends StyledEditorKit.StyledTextAction + { /** * fg */ private Color fg; - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - /** * Constructor ForegroundAction * @param nm TODO * @param fg TODO */ - public ForegroundAction(String nm, Color fg) { + public ForegroundAction(String nm, Color fg) + { super("TODO"); // TODO - } // ForegroundAction() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * actionPerformed * @param event TODO */ - public void actionPerformed(ActionEvent event) { + public void actionPerformed(ActionEvent event) + { // TODO - } // actionPerformed() - - - } // ForegroundAction + } + } /** * FontSizeAction */ - public static class FontSizeAction extends StyledEditorKit.StyledTextAction { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - + public static class FontSizeAction extends StyledEditorKit.StyledTextAction + { /** * size */ private int size; - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - /** * Constructor FontSizeAction * @param nm TODO * @param size TODO */ - public FontSizeAction(String nm, int size) { + public FontSizeAction(String nm, int size) + { super("TODO"); // TODO - } // FontSizeAction() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * actionPerformed * @param event TODO */ - public void actionPerformed(ActionEvent event) { + public void actionPerformed(ActionEvent event) + { // TODO - } // actionPerformed() - - - } // FontSizeAction + } + } /** * FontFamilyAction */ - public static class FontFamilyAction extends StyledEditorKit.StyledTextAction { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - + public static class FontFamilyAction extends StyledEditorKit.StyledTextAction + { /** * family */ private String family; - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - /** * Constructor FontFamilyAction * @param nm TODO * @param family TODO */ - public FontFamilyAction(String nm, String family) { + public FontFamilyAction(String nm, String family) + { super("TODO"); // TODO - } // FontFamilyAction() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * actionPerformed * @param event TODO */ - public void actionPerformed(ActionEvent event) { + public void actionPerformed(ActionEvent event) + { // TODO - } // actionPerformed() - - - } // FontFamilyAction + } + } /** * StyledTextAction */ - public abstract static class StyledTextAction extends TextAction { - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - + public abstract static class StyledTextAction extends TextAction + { /** * Constructor StyledTextAction * @param nm TODO */ - public StyledTextAction(String nm) { + public StyledTextAction(String nm) + { super(nm); // TODO - } // StyledTextAction() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * getEditor * @param event TODO * @returns JEditorPane */ - protected final JEditorPane getEditor(ActionEvent event) { + protected final JEditorPane getEditor(ActionEvent event) + { return null; // TODO - } // getEditor() + } /** * setCharacterAttributes @@ -378,27 +284,32 @@ public class StyledEditorKit extends DefaultEditorKit * @param value1 TODO * @param value2 TODO */ - protected final void setCharacterAttributes(JEditorPane value0, AttributeSet value1, boolean value2) { + protected final void setCharacterAttributes(JEditorPane value0, + AttributeSet value1, + boolean value2) + { // TODO - } // setCharacterAttributes() + } /** * getStyledDocument * @param value0 TODO * @returns StyledDocument */ - protected final StyledDocument getStyledDocument(JEditorPane value0) { + protected final StyledDocument getStyledDocument(JEditorPane value0) + { return null; // TODO - } // getStyledDocument() + } /** * getStyledEditorKit * @param value0 TODO * @returns StyledEditorKit */ - protected final StyledEditorKit getStyledEditorKit(JEditorPane value0) { + protected final StyledEditorKit getStyledEditorKit(JEditorPane value0) + { return null; // TODO - } // getStyledEditorKit() + } /** * setParagraphAttributes @@ -406,72 +317,53 @@ public class StyledEditorKit extends DefaultEditorKit * @param value1 TODO * @param value2 TODO */ - protected final void setParagraphAttributes(JEditorPane value0, AttributeSet value1, boolean value2) { + protected final void setParagraphAttributes(JEditorPane value0, + AttributeSet value1, + boolean value2) + { // TODO - } // setParagraphAttributes() - - - } // StyledTextAction + } + } /** * StyledViewFactory */ - static class StyledViewFactory implements ViewFactory { - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - + static class StyledViewFactory + implements ViewFactory + { /** * Constructor StyledViewFactory */ - StyledViewFactory() { + StyledViewFactory() + { // TODO - } // StyledViewFactory() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * create * @param value0 TODO * @returns View */ - public View create(Element value0) { + public View create(Element value0) + { return null; // TODO - } // create() - - - } // StyledViewFactory + } + } /** * AttributeTracker */ - class AttributeTracker implements CaretListener, PropertyChangeListener, Serializable { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - + class AttributeTracker + implements CaretListener, PropertyChangeListener, Serializable + { /** * Constructor AttributeTracker * @param value0 TODO */ - AttributeTracker(StyledEditorKit value0) { + AttributeTracker(StyledEditorKit value0) + { // TODO - } // AttributeTracker() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * updateInputAttributes @@ -479,33 +371,29 @@ public class StyledEditorKit extends DefaultEditorKit * @param value1 TODO * @param value2 TODO */ - void updateInputAttributes(int value0, int value1, JTextComponent value2) { + void updateInputAttributes(int value0, int value1, JTextComponent value2) + { // TODO - } // updateInputAttributes() + } /** * propertyChange * @param value0 TODO */ - public void propertyChange(PropertyChangeEvent value0) { + public void propertyChange(PropertyChangeEvent value0) + { // TODO - } // propertyChange() + } /** * caretUpdate * @param value0 TODO */ - public void caretUpdate(CaretEvent value0) { + public void caretUpdate(CaretEvent value0) + { // TODO - } // caretUpdate() - - - } // AttributeTracker - - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- + } + } /** * currentRun @@ -522,96 +410,93 @@ public class StyledEditorKit extends DefaultEditorKit */ MutableAttributeSet inputAttributes; - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - /** * Constructor StyledEditorKit */ - public StyledEditorKit() { + public StyledEditorKit() + { // TODO - } // StyledEditorKit() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * clone * @returns Object */ - public Object clone() { + public Object clone() + { return null; // TODO - } // clone() + } /** * getActions * @returns Action[] */ - public Action[] getActions() { + public Action[] getActions() + { return null; // TODO - } // getActions() + } /** * getInputAttributes * @returns MutableAttributeSet */ - public MutableAttributeSet getInputAttributes() { + public MutableAttributeSet getInputAttributes() + { return null; // TODO - } // getInputAttributes() + } /** * getCharacterAttributeRun * @returns Element */ - public Element getCharacterAttributeRun() { + public Element getCharacterAttributeRun() + { return null; // TODO - } // getCharacterAttributeRun() + } /** * createDefaultDocument * @returns Document */ - public Document createDefaultDocument() { + public Document createDefaultDocument() + { return null; // TODO - } // createDefaultDocument() + } /** * install * @param component TODO */ - public void install(JEditorPane component) { + public void install(JEditorPane component) + { // TODO - } // install() + } /** * deinstall * @param component TODO */ - public void deinstall(JEditorPane component) { + public void deinstall(JEditorPane component) + { // TODO - } // deinstall() + } /** * getViewFactory * @returns ViewFactory */ - public ViewFactory getViewFactory() { + public ViewFactory getViewFactory() + { return null; // TODO - } // getViewFactory() + } /** * createInputAttributes * @param element TODO * @param set TODO */ - protected void createInputAttributes(Element element, - MutableAttributeSet set) { + protected void createInputAttributes(Element element, MutableAttributeSet set) + { // TODO - } // createInputAttributes() - - -} // StyledEditorKit + } +} diff --git a/libjava/javax/swing/text/TabExpander.java b/libjava/javax/swing/text/TabExpander.java new file mode 100644 index 00000000000..56940f552a5 --- /dev/null +++ b/libjava/javax/swing/text/TabExpander.java @@ -0,0 +1,43 @@ +/* TabExpander.java -- + Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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. */ + +package javax.swing.text; + +public interface TabExpander +{ + float nextTabStop(float x, int tabOffset); +}
\ No newline at end of file diff --git a/libjava/javax/swing/text/CharacterIterator.java b/libjava/javax/swing/text/TabableView.java index 71c8d660e4f..9d244be19c7 100644 --- a/libjava/javax/swing/text/CharacterIterator.java +++ b/libjava/javax/swing/text/TabableView.java @@ -1,5 +1,5 @@ -/* CharacterIterator.java -- - Copyright (C) 2002 Free Software Foundation, Inc. +/* TabableView.java -- + Copyright (C) 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,17 +37,8 @@ exception statement from your version. */ package javax.swing.text; - -public interface CharacterIterator extends Cloneable +public interface TabableView { - Object clone(); - char current(); - char first(); - int getBeginIndex(); - int getEndIndex(); - int getIndex(); - char last(); - char next(); - char previous(); - char setIndex(int position); + float getPartialSpan(int p0, int p1); + float getTabbedSpan(float x, TabExpander expander); } diff --git a/libjava/javax/swing/text/TextAction.java b/libjava/javax/swing/text/TextAction.java index 55c04c1cd44..5fee0e8640d 100644 --- a/libjava/javax/swing/text/TextAction.java +++ b/libjava/javax/swing/text/TextAction.java @@ -41,56 +41,49 @@ import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.Action; + /** * TextAction * @author Andrew Selkirk - * @version 1.0 */ -public abstract class TextAction extends AbstractAction { - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - +public abstract class TextAction extends AbstractAction +{ /** * Constructor TextAction * @param name TODO */ - public TextAction(String name) { + public TextAction(String name) + { // TODO - } // TextAction() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + } /** * getTextComponent * @param event TODO - * @returns JTextComponent + * @return JTextComponent */ - protected final JTextComponent getTextComponent(ActionEvent event) { + protected final JTextComponent getTextComponent(ActionEvent event) + { return null; // TODO - } // getTextComponent() + } /** * augmentList * @param list1 TODO * @param list2 TODO - * @returns Action[] + * @return Action[] */ - public static final Action[] augmentList(Action[] list1, Action[] list2) { + public static final Action[] augmentList(Action[] list1, Action[] list2) + { return null; // TODO - } // augmentList() + } /** * getFocusedComponent - * @returns JTextComponent + * @return JTextComponent */ - protected final JTextComponent getFocusedComponent() { + protected final JTextComponent getFocusedComponent() + { return null; // TODO - } // getFocusedComponent() - - -} // TextAction + } +} diff --git a/libjava/javax/swing/text/View.java b/libjava/javax/swing/text/View.java index 46d2b35e9c3..6c5a9c296dd 100644 --- a/libjava/javax/swing/text/View.java +++ b/libjava/javax/swing/text/View.java @@ -37,6 +37,7 @@ exception statement from your version. */ package javax.swing.text; +import java.awt.Container; import java.awt.Graphics; import java.awt.Shape; import java.util.Vector; @@ -44,97 +45,124 @@ import javax.swing.SwingConstants; public abstract class View implements SwingConstants { - static int BadBreakWeight; - static int ExcellentBreakWeight; - static int ForcedBreakWeight; - static int GoodBreakWeight; + public static final int BadBreakWeight = 0; + public static final int ExcellentBreakWeight = 2000; + public static final int ForcedBreakWeight = 3000; + public static final int GoodBreakWeight = 1000; - public final static int X_AXIS = 0; - public final static int Y_AXIS = 1; + public static final int X_AXIS = 0; + public static final int Y_AXIS = 1; - float width, height; - Element elt; - View parent; + private float width, height; + private Element elt; + private View parent; /** - * this vector contains the views ordered at offsets... + * Creates a new <code>View</code> instance. + * + * @param elem an <code>Element</code> value */ - Vector v = new Vector(); - - public View(Element elem) { elt = elem; } - public int getViewCount() + public abstract void paint(Graphics g, Shape s); + + public void setParent(View a) { - return v.size(); + parent = a; } - public View getView(int a) + public View getParent() { - return (View) v.get(a); + return parent; } - public void remove(int i) + public void setSize(int w, int h) { - v.removeElementAt(i); + width = w; + height = h; } - public void insert(int off, View view) + public Container getContainer() { - v.insertElementAt(view, off); + return parent != null ? parent.getContainer() : null; } - public void append(View view) + public Document getDocument() { - v.addElement(view); + return getElement().getDocument(); } - public void paint(Graphics g, Shape allocation) + public Element getElement() { - System.out.println("view.paint() !!!!"); + return elt; } - public void setParent(View a) + public abstract float getPreferredSpan(int axis); + + public float getAlignment(int axis) { - parent = a; + return 0.5f; } - public View getParent() + public AttributeSet getAttributes() { - return parent; + return elt.getAttributes(); } - public void setSize(int w, int h) + public boolean isVisible() { - width = w; - height = h; + return true; } - public Document getDocument() + public int getViewCount() { - return getElement().getDocument(); + return 0; } - public Element getElement() + public View getView(int index) { - return elt; + return null; } - public float getPreferredSpan(int a) + public ViewFactory getViewFactory() { - switch (a) + return parent != null ? parent.getViewFactory() : null; + } + + public void replace(int offset, int length, View[] views) { - case X_AXIS: return width; - case Y_AXIS: return height; - default: + // Default implementation does nothing. + } + + public void insert(int offset, View view) { - System.err.println("I sure wish Java had enums !!! "); - return 0; + View[] array = { view }; + replace(offset, 1, array); } + + public void append(View view) + { + View[] array = { view }; + replace(getViewCount(), 1, array); + } + + public void removeAll() + { + replace(0, getViewCount(), null); } + + public void remove(int index) + { + replace(index, 1, null); + } + + public View createFragment(int p0, int p1) + { + // The default implementation doesnt support fragmentation. + return this; } } diff --git a/libjava/javax/swing/text/ViewFactory.java b/libjava/javax/swing/text/ViewFactory.java index 1fef6bceb96..52be67ba557 100644 --- a/libjava/javax/swing/text/ViewFactory.java +++ b/libjava/javax/swing/text/ViewFactory.java @@ -1,5 +1,5 @@ /* ViewFactory.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,5 +39,12 @@ package javax.swing.text; public interface ViewFactory { + /** + * Creates a view for a given element. + * + * @param elem them element to create view for + * + * @return a new created view + */ View create (Element elem); } |