[llvm-commits] [llvm-gcc-4.2] r43913 [55/80] - in /llvm-gcc-4.2/trunk: boehm-gc/ boehm-gc/Mac_files/ boehm-gc/cord/ boehm-gc/doc/ boehm-gc/include/ boehm-gc/include/private/ boehm-gc/tests/ libffi/ libffi/include/ libffi/src/ libffi/src/alpha/ libffi/src/arm/ libffi/src/cris/ libffi/src/frv/ libffi/src/ia64/ libffi/src/m32r/ libffi/src/m68k/ libffi/src/mips/ libffi/src/pa/ libffi/src/powerpc/ libffi/src/s390/ libffi/src/sh/ libffi/src/sh64/ libffi/src/sparc/ libffi/src/x86/ libffi/testsuite/ libffi/testsuite/config/ li...
Bill Wendling
isanbard at gmail.com
Thu Nov 8 14:57:11 PST 2007
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TabableView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TabableView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TabableView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TabableView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,44 @@
+/* TabableView.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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.text;
+
+public interface TabableView
+{
+ float getPartialSpan(int p0, int p1);
+ float getTabbedSpan(float x, TabExpander expander);
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TableView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TableView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TableView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TableView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,491 @@
+/* TableView.java -- A view impl for tables inside styled text
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text;
+
+import java.awt.Rectangle;
+import java.awt.Shape;
+
+import javax.swing.SizeRequirements;
+import javax.swing.event.DocumentEvent;
+
+/**
+ * A {@link View} implementation for rendering tables inside styled text.
+ * Tables are rendered as vertical boxes (see {@link BoxView}). These boxes
+ * have a number of child views, which are the rows of the table. These are
+ * horizontal boxes containing the actuall cells of the table. These cells
+ * can be arbitrary view implementations and are fetched via the
+ * {@link ViewFactory} returned by {@link View#getViewFactory}.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+public abstract class TableView
+ extends BoxView
+{
+
+ /**
+ * A view implementation that renders a row of a <code>TableView</code>.
+ * This is implemented as a horizontal box that contains the actual cells
+ * of the table.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+ public class TableRow
+ extends BoxView
+ {
+ /**
+ * Creates a new instance of <code>TableRow</code>.
+ *
+ * @param el the element for which to create a row view
+ */
+ public TableRow(Element el)
+ {
+ super(el, X_AXIS);
+ }
+
+ /**
+ * Replaces some child views with a new set of child views. This is
+ * implemented to call the superclass behaviour and invalidates the row
+ * grid so that rows and columns will be recalculated.
+ *
+ * @param offset the start offset at which to replace views
+ * @param length the number of views to remove
+ * @param views the new set of views
+ */
+ public void replace(int offset, int length, View[] views)
+ {
+ super.replace(offset, length, views);
+ int viewCount = getViewCount();
+ if (columnRequirements == null
+ || viewCount > columnRequirements.length)
+ {
+ columnRequirements = new SizeRequirements[viewCount];
+ for (int i = 0; i < columnRequirements.length; i++)
+ columnRequirements[i] = new SizeRequirements();
+ }
+ if (columnOffsets == null || columnOffsets.length < viewCount)
+ columnOffsets = new int[viewCount];
+ if (columnSpans == null || columnSpans.length < viewCount)
+ columnSpans = new int[viewCount];
+ layoutChanged(X_AXIS);
+ }
+
+ /**
+ * Lays out the box's child views along the major axis. This is
+ * reimplemented so that the child views all have the width of their
+ * column.
+ *
+ * @param targetSpan the total span of the view
+ * @param axis the axis that is laid out
+ * @param offsets an array that holds the offsets of the child views after
+ * this method returned
+ * @param spans an array that holds the spans of the child views after this
+ * method returned
+ */
+ protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets,
+ int[] spans)
+ {
+ // Some sanity checks. If these preconditions are not met, then the
+ // following code will not work. Also, there must be something
+ // seriously wrong then.
+ assert(offsets.length == columnOffsets.length);
+ assert(spans.length == columnSpans.length);
+ assert(offsets.length == spans.length);
+ for (int i = 0; i < offsets.length; ++i)
+ {
+ offsets[i] = columnOffsets[i];
+ spans[i] = columnSpans[i];
+ }
+ }
+
+ /**
+ * Lays out the box's child views along the minor axis (the orthogonal axis
+ * to the major axis). This is reimplemented to call the super behaviour
+ * and then adjust the span of the child views that span multiple rows.
+ *
+ * @param targetSpan the total span of the view
+ * @param axis the axis that is laid out
+ * @param offsets an array that holds the offsets of the child views after
+ * this method returned
+ * @param spans an array that holds the spans of the child views after this
+ * method returned
+ */
+ protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets,
+ int[] spans)
+ {
+ // FIXME: Figure out how to fetch the row heights from the TableView's
+ // element.
+ super.layoutMinorAxis(targetSpan, axis, offsets, spans);
+ }
+
+ /**
+ * Determines the resizeability of this view along the specified axis.
+ *
+ * @param axis the axis of which to fetch the resizability
+ *
+ * @return the resize weight or <= 0 if this view is not resizable
+ *
+ * @throws IllegalArgumentException when an illegal axis is specified
+ */
+ public int getResizeWeight(int axis)
+ {
+ // TODO: Figure out if this is ok. I would think so, but better test
+ // this.
+ return 0;
+ }
+
+ /**
+ * Returns the child view that represents the specified position in the
+ * model. This is reimplemented because in this view we do not necessarily
+ * have a one to one mapping of child elements to child views.
+ *
+ * @param pos the model position for which to query the view
+ * @param a the allocation of this view
+ *
+ * @return the view that corresponds to the specified model position or
+ * <code>null</code> if there is none
+ */
+ protected View getViewAtPosition(int pos, Rectangle a)
+ {
+ // FIXME: Do not call super here. Instead walk through the child views
+ // and look for a range that contains the given position.
+ return super.getViewAtPosition(pos, a);
+ }
+ }
+
+ /**
+ * This class is deprecated and not used anymore. Table cells are
+ * rendered by an arbitrary <code>View</code> implementation.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ *
+ * @deprecated Table cells are now rendered by an arbitrary <code>View</code>
+ * implementation.
+ */
+ public class TableCell
+ extends BoxView
+ {
+
+ /**
+ * The row number of this cell.
+ */
+ private int row;
+
+ /**
+ * The column number of this cell.
+ */
+ private int column;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param el the element
+ *
+ * @deprecated Table cells are now rendered by an arbitrary
+ * <code>View</code> implementation.
+ */
+ public TableCell(Element el)
+ {
+ super(el, X_AXIS);
+ }
+
+ /**
+ * Returns the number of columns that this cell spans.
+ *
+ * @return the number of columns that this cell spans
+ *
+ * @deprecated Table cells are now rendered by an arbitrary
+ * <code>View</code> implementation.
+ */
+ public int getColumnCount()
+ {
+ // TODO: Figure out if this is right. However, this is not so important
+ // since this class isn't used anyway (except maybe be application code
+ // that still uses this deprecated class).
+ return 1;
+ }
+
+ /**
+ * Returns the number of rows that this cell spans.
+ *
+ * @return the number of rows that this cell spans
+ *
+ * @deprecated Table cells are now rendered by an arbitrary
+ * <code>View</code> implementation.
+ */
+ public int getRowCount()
+ {
+ // TODO: Figure out if this is right. However, this is not so important
+ // since this class isn't used anyway (except maybe be application code
+ // that still uses this deprecated class).
+ return 1;
+ }
+
+ /**
+ * Sets the grid location of this table cell.
+ *
+ * @param r the row of this cell
+ * @param c the column of this cell
+ *
+ * @deprecated Table cells are now rendered by an arbitrary
+ * <code>View</code> implementation.
+ */
+ public void setGridLocation(int r, int c)
+ {
+ row = r;
+ column = c;
+ }
+
+ /**
+ * Returns the row number of this cell.
+ *
+ * @return the row number of this cell
+ *
+ * @deprecated Table cells are now rendered by an arbitrary
+ * <code>View</code> implementation.
+ */
+ public int getGridRow()
+ {
+ return row;
+ }
+
+ /**
+ * Returns the column number of this cell.
+ *
+ * @return the column number of this cell
+ *
+ * @deprecated Table cells are now rendered by an arbitrary
+ * <code>View</code> implementation.
+ */
+ public int getGridColumn()
+ {
+ return column;
+ }
+ }
+
+ /**
+ * The offsets of the columns of this table. Package private to avoid
+ * synthetic accessor methods.
+ */
+ int[] columnOffsets;
+
+ /**
+ * The spans of the columns of this table. Package private to avoid
+ * synthetic accessor methods.
+ */
+ int[] columnSpans;
+
+ /**
+ * The size requirements of the columns.
+ */
+ SizeRequirements[] columnRequirements = new SizeRequirements[0];
+
+ /**
+ * Creates a new instance of <code>TableView</code>.
+ *
+ * @param el the element for which to create a table view
+ */
+ public TableView(Element el)
+ {
+ super(el, Y_AXIS);
+ }
+
+ /**
+ * Replaces a number of child views with a set of new child views. This is
+ * implemented to call the superclass behaviour and invalidate the layout.
+ *
+ * @param offset the offset at which to replace child views
+ * @param length the number of child views to remove
+ * @param views the new set of views
+ */
+ public void replace(int offset, int length, View[] views)
+ {
+ super.replace(offset, length, views);
+ layoutChanged(Y_AXIS);
+ }
+
+ /**
+ * Creates a view for a table row.
+ *
+ * @param el the element that represents the table row
+ *
+ * @return a view for rendering the table row
+ */
+ protected TableRow createTableRow(Element el)
+ {
+ return new TableRow(el);
+ }
+
+ /**
+ * Creates a view for a table cell. This method is deprecated and not used
+ * anymore.
+ *
+ * @param el the element that represents the table cell
+ *
+ * @return a view for rendering the table cell
+ *
+ * @deprecated Table cells are now rendered by an arbitrary
+ * <code>View</code> implementation.
+ */
+ protected TableCell createTableCell(Element el)
+ {
+ return new TableCell(el);
+ }
+
+ protected void forwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent e,
+ Shape a, ViewFactory vf)
+ {
+ // TODO: Figure out what to do here.
+ }
+
+ /**
+ * Lays out the columns to fit within the specified target span.
+ *
+ * @param targetSpan the total span for the columns
+ * @param offsets an array that holds the offsets of the columns when this
+ * method returns
+ * @param spans an array that holds the spans of the columns when this method
+ * returns
+ * @param reqs the size requirements for each column
+ */
+ protected void layoutColumns(int targetSpan, int[] offsets, int spans[],
+ SizeRequirements[] reqs)
+ {
+ updateColumnRequirements();
+ SizeRequirements r = calculateMinorAxisRequirements(X_AXIS, null);
+ SizeRequirements.calculateTiledPositions(targetSpan, r, columnRequirements,
+ offsets, spans);
+ }
+
+ /**
+ * Lays out the child views along the minor axis of the table (that is the
+ * horizontal axis). This is implemented to call {@link #layoutColumns} to
+ * layout the column layout of this table, and then forward to the superclass
+ * to actually lay out the rows.
+ *
+ * @param targetSpan the available span along the minor (horizontal) axis
+ * @param axis the axis
+ * @param offsets an array that holds the offsets of the columns when this
+ * method returns
+ * @param spans an array that holds the spans of the columns when this method
+ * returns
+ */
+ protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets,
+ int[] spans)
+ {
+ // TODO: Prepare size requirements for the columns.
+ layoutColumns(targetSpan, columnOffsets, columnSpans, columnRequirements);
+ super.layoutMinorAxis(targetSpan, axis, offsets, spans);
+ }
+
+ /**
+ * Calculates the requirements of this view for the minor (== horizontal)
+ * axis.
+ *
+ * This is reimplemented to calculate the requirements as the sum of the
+ * size requirements of the columns.
+ *
+ * @param axis the axis
+ * @param req the size requirements object to use, if <code>null</code> a new
+ * one will be created
+ */
+ protected SizeRequirements calculateMinorAxisRequirements(int axis,
+ SizeRequirements req)
+ {
+ // TODO: Maybe prepare columnRequirements.
+ SizeRequirements res = req;
+ if (res == null)
+ res = new SizeRequirements();
+ else
+ {
+ res.alignment = 0.5f;
+ res.maximum = 0;
+ res.minimum = 0;
+ res.preferred = 0;
+ }
+
+ for (int i = 0; i < columnRequirements.length; ++i)
+ {
+ res.minimum += columnRequirements[i].minimum;
+ res.preferred += columnRequirements[i].preferred;
+ res.maximum += columnRequirements[i].maximum;
+ // TODO: Do we have to handle alignment somehow?
+ }
+ return res;
+ }
+
+ /**
+ * Returns the child view that represents the specified position in the
+ * model. This is reimplemented because in this view we do not necessarily
+ * have a one to one mapping of child elements to child views.
+ *
+ * @param pos the model position for which to query the view
+ * @param a the allocation of this view
+ *
+ * @return the view that corresponds to the specified model position or
+ * <code>null</code> if there is none
+ */
+ protected View getViewAtPosition(int pos, Rectangle a)
+ {
+ // FIXME: Do not call super here. Instead walk through the child views
+ // and look for a range that contains the given position.
+ return super.getViewAtPosition(pos, a);
+ }
+
+ /**
+ * Updates the column requirements.
+ */
+ private void updateColumnRequirements()
+ {
+ int rowCount = getViewCount();
+ for (int r = 0; r < rowCount; ++r)
+ {
+ TableRow row = (TableRow) getView(r);
+ int columnCount = row.getViewCount();
+ for (int c = 0; c < columnCount; ++c)
+ {
+ View cell = row.getView(c);
+ SizeRequirements cr = columnRequirements[c];
+ cr.minimum = Math.max(cr.minimum, (int) cell.getMinimumSpan(X_AXIS));
+ cr.preferred = Math.max(cr.preferred,
+ (int) cell.getPreferredSpan(X_AXIS));
+ cr.maximum = Math.max(cr.maximum, (int) cell.getMaximumSpan(X_AXIS));
+ }
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TextAction.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TextAction.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TextAction.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/TextAction.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,215 @@
+/* TextAction.java --
+ Copyright (C) 2002, 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text;
+
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.HashSet;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.SwingConstants;
+
+/**
+ * TextAction
+ * @author Andrew Selkirk
+ */
+public abstract class TextAction extends AbstractAction
+{
+ /**
+ * Constructor TextAction
+ * @param name TODO
+ */
+ public TextAction(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Returns the <code>JTextComponent</code> object associated with the given
+ * <code>ActionEvent</code>. If the source of the event is not a
+ * <code>JTextComponent</code> the currently focused text component is returned.
+ *
+ * @param event the action event
+ *
+ * @return the <code>JTextComponent</code>
+ */
+ protected final JTextComponent getTextComponent(ActionEvent event)
+ {
+ if (event.getSource() instanceof JTextComponent)
+ return (JTextComponent) event.getSource();
+
+ return getFocusedComponent();
+ }
+
+ /**
+ * Creates a new array of <code>Action</code> containing both given arrays.
+ *
+ * @param list1 the first action array
+ * @param list2 the second action array
+ *
+ * @return the augmented array of actions
+ */
+ public static final Action[] augmentList(Action[] list1, Action[] list2)
+ {
+ HashSet actionSet = new HashSet();
+
+ for (int i = 0; i < list1.length; ++i)
+ actionSet.add(list1[i]);
+
+ for (int i = 0; i < list2.length; ++i)
+ actionSet.add(list2[i]);
+
+ ArrayList list = new ArrayList(actionSet);
+ return (Action[]) list.toArray(new Action[actionSet.size()]);
+ }
+
+ /**
+ * Returns the current focused <code>JTextComponent</code> object.
+ *
+ * @return the <code>JTextComponent</code>
+ */
+ protected final JTextComponent getFocusedComponent()
+ {
+ return null; // TODO
+ }
+
+ /** Abstract helper class which implements everything needed for an
+ * Action implementation in <code>DefaultEditorKit</code> which
+ * does horizontal movement (and selection).
+ */
+ abstract static class HorizontalMovementAction extends TextAction
+ {
+ int dir;
+
+ HorizontalMovementAction(String name, int direction)
+ {
+ super(name);
+ dir = direction;
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ JTextComponent t = getTextComponent(event);
+ try
+ {
+ if (t != null)
+ {
+ int offs
+ = Utilities.getNextVisualPositionFrom(t,
+ t.getCaretPosition(),
+ dir);
+
+ Caret c = t.getCaret();
+
+ actionPerformedImpl(c, offs);
+
+ c.setMagicCaretPosition(t.modelToView(offs).getLocation());
+ }
+ }
+ catch(BadLocationException ble)
+ {
+ throw
+ (InternalError) new InternalError("Illegal offset").initCause(ble);
+ }
+
+ }
+
+ protected abstract void actionPerformedImpl(Caret c, int offs)
+ throws BadLocationException;
+ }
+
+ /** Abstract helper class which implements everything needed for an
+ * Action implementation in <code>DefaultEditorKit</code> which
+ * does vertical movement (and selection).
+ */
+ abstract static class VerticalMovementAction extends TextAction
+ {
+ int dir;
+
+ VerticalMovementAction(String name, int direction)
+ {
+ super(name);
+ dir = direction;
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ JTextComponent t = getTextComponent(event);
+ try
+ {
+ if (t != null)
+ {
+ Caret c = t.getCaret();
+ // The magic caret position may be null when the caret
+ // has not moved yet.
+ Point mcp = c.getMagicCaretPosition();
+
+ int pos;
+ if (mcp != null)
+ {
+ mcp.y = t.modelToView(c.getDot()).y;
+ pos = t.viewToModel(mcp);
+ }
+ else
+ pos = c.getDot();
+
+ pos = Utilities.getNextVisualPositionFrom(t,
+ t.getCaretPosition(),
+ dir);
+
+ if (pos > -1)
+ actionPerformedImpl(c, pos);
+ }
+ }
+ catch(BadLocationException ble)
+ {
+ throw
+ (InternalError) new InternalError("Illegal offset").initCause(ble);
+ }
+ }
+
+ protected abstract void actionPerformedImpl(Caret c, int offs)
+ throws BadLocationException;
+
+ }
+
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/Utilities.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/Utilities.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/Utilities.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/Utilities.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,729 @@
+/* Utilities.java --
+ Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text;
+
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.text.BreakIterator;
+
+import javax.swing.SwingConstants;
+import javax.swing.text.Position.Bias;
+
+/**
+ * A set of utilities to deal with text. This is used by several other classes
+ * inside this package.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ * @author Robert Schuster (robertschuster at fsfe.org)
+ */
+public class Utilities
+{
+ /**
+ * The length of the char buffer that holds the characters to be drawn.
+ */
+ private static final int BUF_LENGTH = 64;
+
+ /**
+ * Creates a new <code>Utilities</code> object.
+ */
+ public Utilities()
+ {
+ // Nothing to be done here.
+ }
+
+ /**
+ * Draws the given text segment. Contained tabs and newline characters
+ * are taken into account. Tabs are expanded using the
+ * specified {@link TabExpander}.
+ *
+ *
+ * The X and Y coordinates denote the start of the <em>baseline</em> where
+ * the text should be drawn.
+ *
+ * @param s the text fragment to be drawn.
+ * @param x the x position for drawing.
+ * @param y the y position for drawing.
+ * @param g the {@link Graphics} context for drawing.
+ * @param e the {@link TabExpander} which specifies the Tab-expanding
+ * technique.
+ * @param startOffset starting offset in the text.
+ * @return the x coordinate at the end of the drawn text.
+ */
+ public static final int drawTabbedText(Segment s, int x, int y, Graphics g,
+ TabExpander e, int startOffset)
+ {
+ // This buffers the chars to be drawn.
+ char[] buffer = s.array;
+
+ // The font metrics of the current selected font.
+ FontMetrics metrics = g.getFontMetrics();
+ int ascent = metrics.getAscent();
+
+ // The current x and y pixel coordinates.
+ int pixelX = x;
+ int pixelY = y - ascent;
+
+ int pixelWidth = 0;
+ int pos = s.offset;
+ int len = 0;
+
+ int end = s.offset + s.count;
+
+ for (int offset = s.offset; offset < end; ++offset)
+ {
+ char c = buffer[offset];
+ if (c == '\t' || c == '\n')
+ {
+ if (len > 0) {
+ g.drawChars(buffer, pos, len, pixelX, pixelY + ascent);
+ pixelX += pixelWidth;
+ pixelWidth = 0;
+ }
+ pos = offset+1;
+ len = 0;
+ }
+
+ switch (c)
+ {
+ case '\t':
+ // In case we have a tab, we just 'jump' over the tab.
+ // When we have no tab expander we just use the width of ' '.
+ if (e != null)
+ pixelX = (int) e.nextTabStop((float) pixelX,
+ startOffset + offset - s.offset);
+ else
+ pixelX += metrics.charWidth(' ');
+ break;
+ case '\n':
+ // In case we have a newline, we must jump to the next line.
+ pixelY += metrics.getHeight();
+ pixelX = x;
+ break;
+ default:
+ ++len;
+ pixelWidth += metrics.charWidth(buffer[offset]);
+ break;
+ }
+ }
+
+ if (len > 0)
+ g.drawChars(buffer, pos, len, pixelX, pixelY + ascent);
+
+ return pixelX + pixelWidth;
+ }
+
+ /**
+ * Determines the width, that the given text <code>s</code> would take
+ * if it was printed with the given {@link java.awt.FontMetrics} on the
+ * specified screen position.
+ * @param s the text fragment
+ * @param metrics the font metrics of the font to be used
+ * @param x the x coordinate of the point at which drawing should be done
+ * @param e the {@link TabExpander} to be used
+ * @param startOffset the index in <code>s</code> where to start
+ * @returns the width of the given text s. This takes tabs and newlines
+ * into account.
+ */
+ public static final int getTabbedTextWidth(Segment s, FontMetrics metrics,
+ int x, TabExpander e,
+ int startOffset)
+ {
+ // This buffers the chars to be drawn.
+ char[] buffer = s.array;
+
+ // The current x coordinate.
+ int pixelX = x;
+
+ // The current maximum width.
+ int maxWidth = 0;
+
+ for (int offset = s.offset; offset < (s.offset + s.count); ++offset)
+ {
+ switch (buffer[offset])
+ {
+ case '\t':
+ // In case we have a tab, we just 'jump' over the tab.
+ // When we have no tab expander we just use the width of 'm'.
+ if (e != null)
+ pixelX = (int) e.nextTabStop((float) pixelX,
+ startOffset + offset - s.offset);
+ else
+ pixelX += metrics.charWidth(' ');
+ break;
+ case '\n':
+ // In case we have a newline, we must 'draw'
+ // the buffer and jump on the next line.
+ pixelX += metrics.charWidth(buffer[offset]);
+ maxWidth = Math.max(maxWidth, pixelX - x);
+ pixelX = x;
+ break;
+ default:
+ // Here we draw the char.
+ pixelX += metrics.charWidth(buffer[offset]);
+ break;
+ }
+ }
+
+ // Take the last line into account.
+ maxWidth = Math.max(maxWidth, pixelX - x);
+
+ return maxWidth;
+ }
+
+ /**
+ * Provides a facility to map screen coordinates into a model location. For a
+ * given text fragment and start location within this fragment, this method
+ * determines the model location so that the resulting fragment fits best
+ * into the span <code>[x0, x]</code>.
+ *
+ * The parameter <code>round</code> controls which model location is returned
+ * if the view coordinates are on a character: If <code>round</code> is
+ * <code>true</code>, then the result is rounded up to the next character, so
+ * that the resulting fragment is the smallest fragment that is larger than
+ * the specified span. If <code>round</code> is <code>false</code>, then the
+ * resulting fragment is the largest fragment that is smaller than the
+ * specified span.
+ *
+ * @param s the text segment
+ * @param fm the font metrics to use
+ * @param x0 the starting screen location
+ * @param x the target screen location at which the requested fragment should
+ * end
+ * @param te the tab expander to use; if this is <code>null</code>, TABs are
+ * expanded to one space character
+ * @param p0 the starting model location
+ * @param round if <code>true</code> round up to the next location, otherwise
+ * round down to the current location
+ *
+ * @return the model location, so that the resulting fragment fits within the
+ * specified span
+ */
+ public static final int getTabbedTextOffset(Segment s, FontMetrics fm, int x0,
+ int x, TabExpander te, int p0,
+ boolean round)
+ {
+ // At the end of the for loop, this holds the requested model location
+ int pos;
+ int currentX = x0;
+ int width = 0;
+
+ for (pos = 0; pos < s.count; pos++)
+ {
+ char nextChar = s.array[s.offset+pos];
+
+ if (nextChar == 0)
+ break;
+
+ if (nextChar != '\t')
+ width = fm.charWidth(nextChar);
+ else
+ {
+ if (te == null)
+ width = fm.charWidth(' ');
+ else
+ width = ((int) te.nextTabStop(currentX, pos)) - currentX;
+ }
+
+ if (round)
+ {
+ if (currentX + (width>>1) > x)
+ break;
+ }
+ else
+ {
+ if (currentX + width > x)
+ break;
+ }
+
+ currentX += width;
+ }
+
+ return pos + p0;
+ }
+
+ /**
+ * Provides a facility to map screen coordinates into a model location. For a
+ * given text fragment and start location within this fragment, this method
+ * determines the model location so that the resulting fragment fits best
+ * into the span <code>[x0, x]</code>.
+ *
+ * This method rounds up to the next location, so that the resulting fragment
+ * will be the smallest fragment of the text, that is greater than the
+ * specified span.
+ *
+ * @param s the text segment
+ * @param fm the font metrics to use
+ * @param x0 the starting screen location
+ * @param x the target screen location at which the requested fragment should
+ * end
+ * @param te the tab expander to use; if this is <code>null</code>, TABs are
+ * expanded to one space character
+ * @param p0 the starting model location
+ *
+ * @return the model location, so that the resulting fragment fits within the
+ * specified span
+ */
+ public static final int getTabbedTextOffset(Segment s, FontMetrics fm, int x0,
+ int x, TabExpander te, int p0)
+ {
+ return getTabbedTextOffset(s, fm, x0, x, te, p0, true);
+ }
+
+ /**
+ * Finds the start of the next word for the given offset.
+ *
+ * @param c
+ * the text component
+ * @param offs
+ * the offset in the document
+ * @return the location in the model of the start of the next word.
+ * @throws BadLocationException
+ * if the offset is invalid.
+ */
+ public static final int getNextWord(JTextComponent c, int offs)
+ throws BadLocationException
+ {
+ if (offs < 0 || offs > (c.getText().length() - 1))
+ throw new BadLocationException("invalid offset specified", offs);
+ String text = c.getText();
+ BreakIterator wb = BreakIterator.getWordInstance();
+ wb.setText(text);
+
+ int last = wb.following(offs);
+ int current = wb.next();
+ int cp;
+
+ while (current != BreakIterator.DONE)
+ {
+ for (int i = last; i < current; i++)
+ {
+ cp = text.codePointAt(i);
+
+ // Return the last found bound if there is a letter at the current
+ // location or is not whitespace (meaning it is a number or
+ // punctuation). The first case means that 'last' denotes the
+ // beginning of a word while the second case means it is the start
+ // of something else.
+ if (Character.isLetter(cp)
+ || !Character.isWhitespace(cp))
+ return last;
+ }
+ last = current;
+ current = wb.next();
+ }
+
+ throw new BadLocationException("no more words", offs);
+ }
+
+ /**
+ * Finds the start of the previous word for the given offset.
+ *
+ * @param c
+ * the text component
+ * @param offs
+ * the offset in the document
+ * @return the location in the model of the start of the previous word.
+ * @throws BadLocationException
+ * if the offset is invalid.
+ */
+ public static final int getPreviousWord(JTextComponent c, int offs)
+ throws BadLocationException
+ {
+ String text = c.getText();
+
+ if (offs <= 0 || offs > text.length())
+ throw new BadLocationException("invalid offset specified", offs);
+
+ BreakIterator wb = BreakIterator.getWordInstance();
+ wb.setText(text);
+ int last = wb.preceding(offs);
+ int current = wb.previous();
+ int cp;
+
+ while (current != BreakIterator.DONE)
+ {
+ for (int i = last; i < offs; i++)
+ {
+ cp = text.codePointAt(i);
+
+ // Return the last found bound if there is a letter at the current
+ // location or is not whitespace (meaning it is a number or
+ // punctuation). The first case means that 'last' denotes the
+ // beginning of a word while the second case means it is the start
+ // of some else.
+ if (Character.isLetter(cp)
+ || !Character.isWhitespace(cp))
+ return last;
+ }
+ last = current;
+ current = wb.previous();
+ }
+
+ return 0;
+ }
+
+ /**
+ * Finds the start of a word for the given location.
+ * @param c the text component
+ * @param offs the offset location
+ * @return the location of the word beginning
+ * @throws BadLocationException if the offset location is invalid
+ */
+ public static final int getWordStart(JTextComponent c, int offs)
+ throws BadLocationException
+ {
+ String text = c.getText();
+
+ if (offs < 0 || offs > text.length())
+ throw new BadLocationException("invalid offset specified", offs);
+
+ BreakIterator wb = BreakIterator.getWordInstance();
+ wb.setText(text);
+
+ if (wb.isBoundary(offs))
+ return offs;
+
+ return wb.preceding(offs);
+ }
+
+ /**
+ * Finds the end of a word for the given location.
+ * @param c the text component
+ * @param offs the offset location
+ * @return the location of the word end
+ * @throws BadLocationException if the offset location is invalid
+ */
+ public static final int getWordEnd(JTextComponent c, int offs)
+ throws BadLocationException
+ {
+ if (offs < 0 || offs >= c.getText().length())
+ throw new BadLocationException("invalid offset specified", offs);
+
+ String text = c.getText();
+ BreakIterator wb = BreakIterator.getWordInstance();
+ wb.setText(text);
+ return wb.following(offs);
+ }
+
+ /**
+ * Get the model position of the end of the row that contains the
+ * specified model position. Return null if the given JTextComponent
+ * does not have a size.
+ * @param c the JTextComponent
+ * @param offs the model position
+ * @return the model position of the end of the row containing the given
+ * offset
+ * @throws BadLocationException if the offset is invalid
+ */
+ public static final int getRowEnd(JTextComponent c, int offs)
+ throws BadLocationException
+ {
+ String text = c.getText();
+ if (text == null)
+ return -1;
+
+ // Do a binary search for the smallest position X > offs
+ // such that that character at positino X is not on the same
+ // line as the character at position offs
+ int high = offs + ((text.length() - 1 - offs) / 2);
+ int low = offs;
+ int oldHigh = text.length() + 1;
+ while (true)
+ {
+ if (c.modelToView(high).y != c.modelToView(offs).y)
+ {
+ oldHigh = high;
+ high = low + ((high + 1 - low) / 2);
+ if (oldHigh == high)
+ return high - 1;
+ }
+ else
+ {
+ low = high;
+ high += ((oldHigh - high) / 2);
+ if (low == high)
+ return low;
+ }
+ }
+ }
+
+ /**
+ * Get the model position of the start of the row that contains the specified
+ * model position. Return null if the given JTextComponent does not have a
+ * size.
+ *
+ * @param c the JTextComponent
+ * @param offs the model position
+ * @return the model position of the start of the row containing the given
+ * offset
+ * @throws BadLocationException if the offset is invalid
+ */
+ public static final int getRowStart(JTextComponent c, int offs)
+ throws BadLocationException
+ {
+ String text = c.getText();
+ if (text == null)
+ return -1;
+
+ // Do a binary search for the greatest position X < offs
+ // such that the character at position X is not on the same
+ // row as the character at position offs
+ int high = offs;
+ int low = 0;
+ int oldLow = 0;
+ while (true)
+ {
+ if (c.modelToView(low).y != c.modelToView(offs).y)
+ {
+ oldLow = low;
+ low = high - ((high + 1 - low) / 2);
+ if (oldLow == low)
+ return low + 1;
+ }
+ else
+ {
+ high = low;
+ low -= ((low - oldLow) / 2);
+ if (low == high)
+ return low;
+ }
+ }
+ }
+
+ /**
+ * Determine where to break the text in the given Segment, attempting to find
+ * a word boundary.
+ * @param s the Segment that holds the text
+ * @param metrics the font metrics used for calculating the break point
+ * @param x0 starting view location representing the start of the text
+ * @param x the target view location
+ * @param e the TabExpander used for expanding tabs (if this is null tabs
+ * are expanded to 1 space)
+ * @param startOffset the offset in the Document of the start of the text
+ * @return the offset at which we should break the text
+ */
+ public static final int getBreakLocation(Segment s, FontMetrics metrics,
+ int x0, int x, TabExpander e,
+ int startOffset)
+ {
+ int mark = Utilities.getTabbedTextOffset(s, metrics, x0, x, e, startOffset, false);
+ BreakIterator breaker = BreakIterator.getWordInstance();
+ breaker.setText(s);
+
+ // If startOffset and s.offset differ then we need to use
+ // that difference two convert the offset between the two metrics.
+ int shift = startOffset - s.offset;
+
+ // If mark is equal to the end of the string, just use that position.
+ if (mark >= shift + s.count)
+ return mark;
+
+ // Try to find a word boundary previous to the mark at which we
+ // can break the text.
+ int preceding = breaker.preceding(mark + 1 - shift);
+
+ if (preceding != 0)
+ return preceding + shift;
+
+ // If preceding is 0 we couldn't find a suitable word-boundary so
+ // just break it on the character boundary
+ return mark;
+ }
+
+ /**
+ * Returns the paragraph element in the text component <code>c</code> at
+ * the specified location <code>offset</code>.
+ *
+ * @param c the text component
+ * @param offset the offset of the paragraph element to return
+ *
+ * @return the paragraph element at <code>offset</code>
+ */
+ public static final Element getParagraphElement(JTextComponent c, int offset)
+ {
+ Document doc = c.getDocument();
+ Element par = null;
+ if (doc instanceof StyledDocument)
+ {
+ StyledDocument styledDoc = (StyledDocument) doc;
+ par = styledDoc.getParagraphElement(offset);
+ }
+ else
+ {
+ Element root = c.getDocument().getDefaultRootElement();
+ int parIndex = root.getElementIndex(offset);
+ par = root.getElement(parIndex);
+ }
+ return par;
+ }
+
+ /**
+ * Returns the document position that is closest above to the specified x
+ * coordinate in the row containing <code>offset</code>.
+ *
+ * @param c the text component
+ * @param offset the offset
+ * @param x the x coordinate
+ *
+ * @return the document position that is closest above to the specified x
+ * coordinate in the row containing <code>offset</code>
+ *
+ * @throws BadLocationException if <code>offset</code> is not a valid offset
+ */
+ public static final int getPositionAbove(JTextComponent c, int offset, int x)
+ throws BadLocationException
+ {
+ int offs = getRowStart(c, offset);
+
+ if(offs == -1)
+ return -1;
+
+ // Effectively calculates the y value of the previous line.
+ Point pt = c.modelToView(offs-1).getLocation();
+
+ pt.x = x;
+
+ // Calculate a simple fitting offset.
+ offs = c.viewToModel(pt);
+
+ // Find out the real x positions of the calculated character and its
+ // neighbour.
+ int offsX = c.modelToView(offs).getLocation().x;
+ int offsXNext = c.modelToView(offs+1).getLocation().x;
+
+ // Chose the one which is nearer to us and return its offset.
+ if (Math.abs(offsX-x) <= Math.abs(offsXNext-x))
+ return offs;
+ else
+ return offs+1;
+ }
+
+ /**
+ * Returns the document position that is closest below to the specified x
+ * coordinate in the row containing <code>offset</code>.
+ *
+ * @param c the text component
+ * @param offset the offset
+ * @param x the x coordinate
+ *
+ * @return the document position that is closest above to the specified x
+ * coordinate in the row containing <code>offset</code>
+ *
+ * @throws BadLocationException if <code>offset</code> is not a valid offset
+ */
+ public static final int getPositionBelow(JTextComponent c, int offset, int x)
+ throws BadLocationException
+ {
+ int offs = getRowEnd(c, offset);
+
+ if(offs == -1)
+ return -1;
+
+ Point pt = null;
+
+ // Note: Some views represent the position after the last
+ // typed character others do not. Converting offset 3 in "a\nb"
+ // in a PlainView will return a valid rectangle while in a
+ // WrappedPlainView this will throw a BadLocationException.
+ // This behavior has been observed in the RI.
+ try
+ {
+ // Effectively calculates the y value of the next line.
+ pt = c.modelToView(offs+1).getLocation();
+ }
+ catch(BadLocationException ble)
+ {
+ return offset;
+ }
+
+ pt.x = x;
+
+ // Calculate a simple fitting offset.
+ offs = c.viewToModel(pt);
+
+ if (offs == c.getDocument().getLength())
+ return offs;
+
+ // Find out the real x positions of the calculated character and its
+ // neighbour.
+ int offsX = c.modelToView(offs).getLocation().x;
+ int offsXNext = c.modelToView(offs+1).getLocation().x;
+
+ // Chose the one which is nearer to us and return its offset.
+ if (Math.abs(offsX-x) <= Math.abs(offsXNext-x))
+ return offs;
+ else
+ return offs+1;
+ }
+
+ /** This is an internal helper method which is used by the
+ * <code>javax.swing.text</code> package. It simply delegates the
+ * call to a method with the same name on the <code>NavigationFilter</code>
+ * of the provided <code>JTextComponent</code> (if it has one) or its UI.
+ *
+ * If the underlying method throws a <code>BadLocationException</code> it
+ * will be swallowed and the initial offset is returned.
+ */
+ static int getNextVisualPositionFrom(JTextComponent t, int offset, int direction)
+ {
+ NavigationFilter nf = t.getNavigationFilter();
+
+ try
+ {
+ return (nf != null)
+ ? nf.getNextVisualPositionFrom(t,
+ offset,
+ Bias.Forward,
+ direction,
+ null)
+ : t.getUI().getNextVisualPositionFrom(t,
+ offset,
+ Bias.Forward,
+ direction,
+ null);
+ }
+ catch (BadLocationException ble)
+ {
+ return offset;
+ }
+
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/View.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/View.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/View.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/View.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,849 @@
+/* View.java --
+ Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text;
+
+import java.awt.Container;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.Shape;
+
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
+import javax.swing.event.DocumentEvent;
+
+public abstract class View implements SwingConstants
+{
+ 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 static final int X_AXIS = 0;
+ public static final int Y_AXIS = 1;
+
+ private float width, height;
+ private Element elt;
+ private View parent;
+
+ /**
+ * Creates a new <code>View</code> instance.
+ *
+ * @param elem an <code>Element</code> value
+ */
+ public View(Element elem)
+ {
+ elt = elem;
+ }
+
+ public abstract void paint(Graphics g, Shape s);
+
+ /**
+ * Sets the parent for this view. This is the first method that is beeing
+ * called on a view to setup the view hierarchy. This is also the last method
+ * beeing called when the view is disconnected from the view hierarchy, in
+ * this case <code>parent</code> is null.
+ *
+ * If <code>parent</code> is <code>null</code>, a call to this method also
+ * calls <code>setParent</code> on the children, thus disconnecting them from
+ * the view hierarchy. That means that super must be called when this method
+ * is overridden.
+ *
+ * @param parent the parent to set, <code>null</code> when this view is
+ * beeing disconnected from the view hierarchy
+ */
+ public void setParent(View parent)
+ {
+ if (parent == null)
+ {
+ int numChildren = getViewCount();
+ for (int i = 0; i < numChildren; i++)
+ getView(i).setParent(null);
+ }
+
+ this.parent = parent;
+ }
+
+ public View getParent()
+ {
+ return parent;
+ }
+
+ public Container getContainer()
+ {
+ View parent = getParent();
+ if (parent == null)
+ return null;
+ else
+ return parent.getContainer();
+ }
+
+ public Document getDocument()
+ {
+ return getElement().getDocument();
+ }
+
+ public Element getElement()
+ {
+ return elt;
+ }
+
+ /**
+ * Returns the preferred span along the specified axis. Normally the view is
+ * rendered with the span returned here if that is possible.
+ *
+ * @param axis the axis
+ *
+ * @return the preferred span along the specified axis
+ */
+ public abstract float getPreferredSpan(int axis);
+
+ /**
+ * Returns the resize weight of this view. A value of <code>0</code> or less
+ * means this view is not resizeable. Positive values make the view
+ * resizeable. The default implementation returns <code>0</code>
+ * unconditionally.
+ *
+ * @param axis the axis
+ *
+ * @return the resizability of this view along the specified axis
+ */
+ public int getResizeWeight(int axis)
+ {
+ return 0;
+ }
+
+ /**
+ * Returns the maximum span along the specified axis. The default
+ * implementation will forward to
+ * {@link #getPreferredSpan(int)} unless {@link #getResizeWeight(int)}
+ * returns a value > 0, in which case this returns {@link Integer#MIN_VALUE}.
+ *
+ * @param axis the axis
+ *
+ * @return the maximum span along the specified axis
+ */
+ public float getMaximumSpan(int axis)
+ {
+ float max = Integer.MAX_VALUE;
+ if (getResizeWeight(axis) <= 0)
+ max = getPreferredSpan(axis);
+ return max;
+ }
+
+ /**
+ * Returns the minimum span along the specified axis. The default
+ * implementation will forward to
+ * {@link #getPreferredSpan(int)} unless {@link #getResizeWeight(int)}
+ * returns a value > 0, in which case this returns <code>0</code>.
+ *
+ * @param axis the axis
+ *
+ * @return the minimum span along the specified axis
+ */
+ public float getMinimumSpan(int axis)
+ {
+ float min = 0;
+ if (getResizeWeight(axis) <= 0)
+ min = getPreferredSpan(axis);
+ return min;
+ }
+
+ public void setSize(float width, float height)
+ {
+ // The default implementation does nothing.
+ }
+
+ /**
+ * Returns the alignment of this view along the baseline of the parent view.
+ * An alignment of <code>0.0</code> will align this view with the left edge
+ * along the baseline, an alignment of <code>0.5</code> will align it
+ * centered to the baseline, an alignment of <code>1.0</code> will align
+ * the right edge along the baseline.
+ *
+ * The default implementation returns 0.5 unconditionally.
+ *
+ * @param axis the axis
+ *
+ * @return the alignment of this view along the parents baseline for the
+ * specified axis
+ */
+ public float getAlignment(int axis)
+ {
+ return 0.5f;
+ }
+
+ public AttributeSet getAttributes()
+ {
+ return getElement().getAttributes();
+ }
+
+ public boolean isVisible()
+ {
+ return true;
+ }
+
+ public int getViewCount()
+ {
+ return 0;
+ }
+
+ public View getView(int index)
+ {
+ return null;
+ }
+
+ public ViewFactory getViewFactory()
+ {
+ View parent = getParent();
+ return parent != null ? parent.getViewFactory() : null;
+ }
+
+ /**
+ * Replaces a couple of child views with new child views. If
+ * <code>length == 0</code> then this is a simple insertion, if
+ * <code>views == null</code> this only removes some child views.
+ *
+ * @param offset the offset at which to replace
+ * @param length the number of child views to be removed
+ * @param views the new views to be inserted, may be <code>null</code>
+ */
+ public void replace(int offset, int length, View[] views)
+ {
+ // Default implementation does nothing.
+ }
+
+ public void insert(int offset, View view)
+ {
+ View[] array = { view };
+ replace(offset, 1, array);
+ }
+
+ public void append(View view)
+ {
+ View[] array = { view };
+ int offset = getViewCount();
+ replace(offset, 0, array);
+ }
+
+ public void removeAll()
+ {
+ replace(0, getViewCount(), new View[0]);
+ }
+
+ public void remove(int index)
+ {
+ replace(index, 1, null);
+ }
+
+ public View createFragment(int p0, int p1)
+ {
+ // The default implementation doesn't support fragmentation.
+ return this;
+ }
+
+ public int getStartOffset()
+ {
+ return getElement().getStartOffset();
+ }
+
+ public int getEndOffset()
+ {
+ return getElement().getEndOffset();
+ }
+
+ public Shape getChildAllocation(int index, Shape a)
+ {
+ return null;
+ }
+
+ /**
+ * @since 1.4
+ */
+ public int getViewIndex(float x, float y, Shape allocation)
+ {
+ return -1;
+ }
+
+ /**
+ * @since 1.4
+ */
+ public String getToolTipText(float x, float y, Shape allocation)
+ {
+ int index = getViewIndex(x, y, allocation);
+
+ if (index < -1)
+ return null;
+
+ Shape childAllocation = getChildAllocation(index, allocation);
+
+ if (childAllocation.getBounds().contains(x, y))
+ return getView(index).getToolTipText(x, y, childAllocation);
+
+ return null;
+ }
+
+ /**
+ * @since 1.3
+ */
+ public Graphics getGraphics()
+ {
+ return getContainer().getGraphics();
+ }
+
+ public void preferenceChanged(View child, boolean width, boolean height)
+ {
+ if (parent != null)
+ parent.preferenceChanged(this, width, height);
+ }
+
+ public int getBreakWeight(int axis, float pos, float len)
+ {
+ return BadBreakWeight;
+ }
+
+ public View breakView(int axis, int offset, float pos, float len)
+ {
+ return this;
+ }
+
+ /**
+ * @since 1.3
+ */
+ public int getViewIndex(int pos, Position.Bias b)
+ {
+ return -1;
+ }
+
+ /**
+ * Receive notification about an insert update to the text model.
+ *
+ * The default implementation of this method does the following:
+ * <ul>
+ * <li>Call {@link #updateChildren} if the element that this view is
+ * responsible for has changed. This makes sure that the children can
+ * correctly represent the model.<li>
+ * <li>Call {@link #forwardUpdate}. This forwards the DocumentEvent to
+ * the child views.<li>
+ * <li>Call {@link #updateLayout}. Gives the view a chance to either
+ * repair its layout, reschedule layout or do nothing at all.</li>
+ * </ul>
+ *
+ * @param ev the DocumentEvent that describes the change
+ * @param shape the shape of the view
+ * @param vf the ViewFactory for creating child views
+ */
+ public void insertUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
+ {
+ Element el = getElement();
+ DocumentEvent.ElementChange ec = ev.getChange(el);
+ if (ec != null)
+ updateChildren(ec, ev, vf);
+ forwardUpdate(ec, ev, shape, vf);
+ updateLayout(ec, ev, shape);
+ }
+
+ /**
+ * Receive notification about a remove update to the text model.
+ *
+ * The default implementation of this method does the following:
+ * <ul>
+ * <li>Call {@link #updateChildren} if the element that this view is
+ * responsible for has changed. This makes sure that the children can
+ * correctly represent the model.<li>
+ * <li>Call {@link #forwardUpdate}. This forwards the DocumentEvent to
+ * the child views.<li>
+ * <li>Call {@link #updateLayout}. Gives the view a chance to either
+ * repair its layout, reschedule layout or do nothing at all.</li>
+ * </ul>
+ *
+ * @param ev the DocumentEvent that describes the change
+ * @param shape the shape of the view
+ * @param vf the ViewFactory for creating child views
+ */
+ public void removeUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
+ {
+ Element el = getElement();
+ DocumentEvent.ElementChange ec = ev.getChange(el);
+ if (ec != null)
+ {
+ if (! updateChildren(ec, ev, vf))
+ ec = null;
+ }
+ forwardUpdate(ec, ev, shape, vf);
+ updateLayout(ec, ev, shape);
+ }
+
+ /**
+ * Receive notification about a change update to the text model.
+ *
+ * The default implementation of this method does the following:
+ * <ul>
+ * <li>Call {@link #updateChildren} if the element that this view is
+ * responsible for has changed. This makes sure that the children can
+ * correctly represent the model.<li>
+ * <li>Call {@link #forwardUpdate}. This forwards the DocumentEvent to
+ * the child views.<li>
+ * <li>Call {@link #updateLayout}. Gives the view a chance to either
+ * repair its layout, reschedule layout or do nothing at all.</li>
+ * </ul>
+ *
+ * @param ev the DocumentEvent that describes the change
+ * @param shape the shape of the view
+ * @param vf the ViewFactory for creating child views
+ */
+ public void changedUpdate(DocumentEvent ev, Shape shape, ViewFactory vf)
+ {
+ Element el = getElement();
+ DocumentEvent.ElementChange ec = ev.getChange(el);
+ if (ec != null)
+ updateChildren(ec, ev, vf);
+ forwardUpdate(ec, ev, shape, vf);
+ updateLayout(ec, ev, shape);
+ }
+
+ /**
+ * Updates the list of children that is returned by {@link #getView}
+ * and {@link #getViewCount}.
+ *
+ * Element that are specified as beeing added in the ElementChange record are
+ * assigned a view for using the ViewFactory. Views of Elements that
+ * are specified as beeing removed are removed from the list.
+ *
+ * @param ec the ElementChange record that describes the change of the
+ * element
+ * @param ev the DocumentEvent describing the change of the document model
+ * @param vf the ViewFactory to use for creating new views
+ *
+ * @return whether or not the child views represent the child elements of
+ * the element that this view is responsible for. Some views may
+ * create views that are responsible only for parts of the element
+ * that they are responsible for and should then return false.
+ *
+ * @since 1.3
+ */
+ protected boolean updateChildren(DocumentEvent.ElementChange ec,
+ DocumentEvent ev,
+ ViewFactory vf)
+ {
+ Element[] added = ec.getChildrenAdded();
+ Element[] removed = ec.getChildrenRemoved();
+ int index = ec.getIndex();
+
+ View[] newChildren = new View[added.length];
+ for (int i = 0; i < added.length; ++i)
+ newChildren[i] = vf.create(added[i]);
+ replace(index, removed.length, newChildren);
+
+ return true;
+ }
+
+ /**
+ * Forwards the DocumentEvent to child views that need to get notified
+ * of the change to the model. This calles {@link #forwardUpdateToView}
+ * for each View that must be forwarded to.
+ *
+ * If <code>ec</code> is not <code>null</code> (this means there have been
+ * structural changes to the element that this view is responsible for) this
+ * method should recognize this and don't notify newly added child views.
+ *
+ * @param ec the ElementChange describing the element changes (may be
+ * <code>null</code> if there were no changes)
+ * @param ev the DocumentEvent describing the changes to the model
+ * @param shape the current allocation of the view
+ * @param vf the ViewFactory used to create new Views
+ *
+ * @since 1.3
+ */
+ protected void forwardUpdate(DocumentEvent.ElementChange ec,
+ DocumentEvent ev, Shape shape, ViewFactory vf)
+ {
+ int count = getViewCount();
+ if (count > 0)
+ {
+ // Determine start index.
+ int startOffset = ev.getOffset();
+ int startIndex = getViewIndex(startOffset, Position.Bias.Backward);
+
+ // For REMOVE events we have to forward the event to the last element,
+ // for the case that an Element has been removed that represente
+ // the offset.
+ if (startIndex == -1 && ev.getType() == DocumentEvent.EventType.REMOVE
+ && startOffset >= getEndOffset())
+ {
+ startIndex = getViewCount() - 1;
+ }
+
+ // When startIndex is on a view boundary, forward event to the
+ // previous view too.
+ if (startIndex >= 0)
+ {
+ View v = getView(startIndex);
+ if (v != null)
+ {
+ if (v.getStartOffset() == startOffset && startOffset > 0)
+ startIndex = Math.max(0, startIndex - 1);
+ }
+ }
+ startIndex = Math.max(0, startIndex);
+
+ // Determine end index.
+ int endIndex = startIndex;
+ if (ev.getType() != DocumentEvent.EventType.REMOVE)
+ {
+ endIndex = getViewIndex(startOffset + ev.getLength(),
+ Position.Bias.Forward);
+ if (endIndex < 0)
+ endIndex = getViewCount() - 1;
+ }
+
+ // Determine hole that comes from added elements (we don't forward
+ // the event to newly added views.
+ int startAdded = endIndex + 1;
+ int endAdded = startAdded;
+ Element[] added = (ec != null) ? ec.getChildrenAdded() : null;
+ if (added != null && added.length > 0)
+ {
+ startAdded = ec.getIndex();
+ endAdded = startAdded + added.length - 1;
+ }
+
+ // Forward event to all views between startIndex and endIndex,
+ // and leave out all views in the hole.
+ for (int i = startIndex; i <= endIndex; i++)
+ {
+ // Skip newly added child views.
+ if (! (i >= startAdded && i <= endAdded))
+ {
+ View child = getView(i);
+ if (child != null)
+ {
+ Shape childAlloc = getChildAllocation(i, shape);
+ forwardUpdateToView(child, ev, childAlloc, vf);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Forwards an update event to the given child view. This calls
+ * {@link #insertUpdate}, {@link #removeUpdate} or {@link #changedUpdate},
+ * depending on the type of document event.
+ *
+ * @param view the View to forward the event to
+ * @param ev the DocumentEvent to forward
+ * @param shape the current allocation of the View
+ * @param vf the ViewFactory used to create new Views
+ *
+ * @since 1.3
+ */
+ protected void forwardUpdateToView(View view, DocumentEvent ev, Shape shape,
+ ViewFactory vf)
+ {
+ DocumentEvent.EventType type = ev.getType();
+ if (type == DocumentEvent.EventType.INSERT)
+ view.insertUpdate(ev, shape, vf);
+ else if (type == DocumentEvent.EventType.REMOVE)
+ view.removeUpdate(ev, shape, vf);
+ else if (type == DocumentEvent.EventType.CHANGE)
+ view.changedUpdate(ev, shape, vf);
+ }
+
+ /**
+ * Updates the layout.
+ *
+ * @param ec the ElementChange that describes the changes to the element
+ * @param ev the DocumentEvent that describes the changes to the model
+ * @param shape the current allocation for this view
+ *
+ * @since 1.3
+ */
+ protected void updateLayout(DocumentEvent.ElementChange ec,
+ DocumentEvent ev, Shape shape)
+ {
+ if (ec != null && shape != null)
+ preferenceChanged(null, true, true);
+ Container c = getContainer();
+ if (c != null)
+ c.repaint();
+ }
+
+ /**
+ * Maps a position in the document into the coordinate space of the View.
+ * The output rectangle usually reflects the font height but has a width
+ * of zero.
+ *
+ * @param pos the position of the character in the model
+ * @param a the area that is occupied by the view
+ * @param b either {@link Position.Bias#Forward} or
+ * {@link Position.Bias#Backward} depending on the preferred
+ * direction bias. If <code>null</code> this defaults to
+ * <code>Position.Bias.Forward</code>
+ *
+ * @return a rectangle that gives the location of the document position
+ * inside the view coordinate space
+ *
+ * @throws BadLocationException if <code>pos</code> is invalid
+ * @throws IllegalArgumentException if b is not one of the above listed
+ * valid values
+ */
+ public abstract Shape modelToView(int pos, Shape a, Position.Bias b)
+ throws BadLocationException;
+
+ /**
+ * Maps a region in the document into the coordinate space of the View.
+ *
+ * @param p1 the beginning position inside the document
+ * @param b1 the direction bias for the beginning position
+ * @param p2 the end position inside the document
+ * @param b2 the direction bias for the end position
+ * @param a the area that is occupied by the view
+ *
+ * @return a rectangle that gives the span of the document region
+ * inside the view coordinate space
+ *
+ * @throws BadLocationException if <code>p1</code> or <code>p2</code> are
+ * invalid
+ * @throws IllegalArgumentException if b1 or b2 is not one of the above
+ * listed valid values
+ */
+ public Shape modelToView(int p1, Position.Bias b1,
+ int p2, Position.Bias b2, Shape a)
+ throws BadLocationException
+ {
+ if (b1 != Position.Bias.Forward && b1 != Position.Bias.Backward)
+ throw new IllegalArgumentException
+ ("b1 must be either Position.Bias.Forward or Position.Bias.Backward");
+ if (b2 != Position.Bias.Forward && b2 != Position.Bias.Backward)
+ throw new IllegalArgumentException
+ ("b2 must be either Position.Bias.Forward or Position.Bias.Backward");
+
+ Shape s1 = modelToView(p1, a, b1);
+ // Special case for p2 == end index.
+ Shape s2;
+ if (p2 != getEndOffset())
+ {
+ s2 = modelToView(p2, a, b2);
+ }
+ else
+ {
+ try
+ {
+ s2 = modelToView(p2, a, b2);
+ }
+ catch (BadLocationException ex)
+ {
+ // Assume the end rectangle to be at the right edge of the
+ // view.
+ Rectangle aRect = a instanceof Rectangle ? (Rectangle) a
+ : a.getBounds();
+ s2 = new Rectangle(aRect.x + aRect.width - 1, aRect.y, 1,
+ aRect.height);
+ }
+ }
+
+ // Need to modify the rectangle, so we create a copy in all cases.
+ Rectangle r1 = s1.getBounds();
+ Rectangle r2 = s2 instanceof Rectangle ? (Rectangle) s2
+ : s2.getBounds();
+
+ // For multiline view, let the resulting rectangle span the whole view.
+ if (r1.y != r2.y)
+ {
+ Rectangle aRect = a instanceof Rectangle ? (Rectangle) a
+ : a.getBounds();
+ r1.x = aRect.x;
+ r1.width = aRect.width;
+ }
+
+ return SwingUtilities.computeUnion(r2.x, r2.y, r2.width, r2.height, r1);
+ }
+
+ /**
+ * Maps a position in the document into the coordinate space of the View.
+ * The output rectangle usually reflects the font height but has a width
+ * of zero.
+ *
+ * This method is deprecated and calls
+ * {@link #modelToView(int, Position.Bias, int, Position.Bias, Shape)} with
+ * a bias of {@link Position.Bias#Forward}.
+ *
+ * @param pos the position of the character in the model
+ * @param a the area that is occupied by the view
+ *
+ * @return a rectangle that gives the location of the document position
+ * inside the view coordinate space
+ *
+ * @throws BadLocationException if <code>pos</code> is invalid
+ *
+ * @deprecated Use {@link #modelToView(int, Shape, Position.Bias)} instead.
+ */
+ public Shape modelToView(int pos, Shape a) throws BadLocationException
+ {
+ return modelToView(pos, a, Position.Bias.Forward);
+ }
+
+ /**
+ * Maps coordinates from the <code>View</code>'s space into a position
+ * in the document model.
+ *
+ * @param x the x coordinate in the view space
+ * @param y the y coordinate in the view space
+ * @param a the allocation of this <code>View</code>
+ * @param b the bias to use
+ *
+ * @return the position in the document that corresponds to the screen
+ * coordinates <code>x, y</code>
+ */
+ public abstract int viewToModel(float x, float y, Shape a, Position.Bias[] b);
+
+ /**
+ * Maps coordinates from the <code>View</code>'s space into a position
+ * in the document model. This method is deprecated and only there for
+ * compatibility.
+ *
+ * @param x the x coordinate in the view space
+ * @param y the y coordinate in the view space
+ * @param a the allocation of this <code>View</code>
+ *
+ * @return the position in the document that corresponds to the screen
+ * coordinates <code>x, y</code>
+ *
+ * @deprecated Use {@link #viewToModel(float, float, Shape, Position.Bias[])}
+ * instead.
+ */
+ public int viewToModel(float x, float y, Shape a)
+ {
+ return viewToModel(x, y, a, new Position.Bias[0]);
+ }
+
+ /**
+ * Dumps the complete View hierarchy. This method can be used for debugging
+ * purposes.
+ */
+ protected void dump()
+ {
+ // Climb up the hierarchy to the parent.
+ View parent = getParent();
+ if (parent != null)
+ parent.dump();
+ else
+ dump(0);
+ }
+
+ /**
+ * Dumps the view hierarchy below this View with the specified indentation
+ * level.
+ *
+ * @param indent the indentation level to be used for this view
+ */
+ void dump(int indent)
+ {
+ for (int i = 0; i < indent; ++i)
+ System.out.print('.');
+ System.out.println(this + "(" + getStartOffset() + "," + getEndOffset() + ": " + getElement());
+
+ int count = getViewCount();
+ for (int i = 0; i < count; ++i)
+ getView(i).dump(indent + 1);
+ }
+
+ /**
+ * Returns the document position that is (visually) nearest to the given
+ * document position <code>pos</code> in the given direction <code>d</code>.
+ *
+ * @param pos the document position
+ * @param b the bias for <code>pos</code>
+ * @param a the allocation for this view
+ * @param d the direction, must be either {@link SwingConstants#NORTH},
+ * {@link SwingConstants#SOUTH}, {@link SwingConstants#WEST} or
+ * {@link SwingConstants#EAST}
+ * @param biasRet an array of {@link Position.Bias} that can hold at least
+ * one element, which is filled with the bias of the return position
+ * on method exit
+ *
+ * @return the document position that is (visually) nearest to the given
+ * document position <code>pos</code> in the given direction
+ * <code>d</code>
+ *
+ * @throws BadLocationException if <code>pos</code> is not a valid offset in
+ * the document model
+ * @throws IllegalArgumentException if <code>d</code> is not a valid direction
+ */
+ public int getNextVisualPositionFrom(int pos, Position.Bias b,
+ Shape a, int d,
+ Position.Bias[] biasRet)
+ throws BadLocationException
+ {
+ int ret = pos;
+ Rectangle r;
+ View parent;
+
+ switch (d)
+ {
+ case EAST:
+ // TODO: take component orientation into account?
+ // Note: If pos is below zero the implementation will return
+ // pos + 1 regardless of whether that value is a correct offset
+ // in the document model. However this is what the RI does.
+ ret = Math.min(pos + 1, getEndOffset());
+ break;
+ case WEST:
+ // TODO: take component orientation into account?
+ ret = Math.max(pos - 1, getStartOffset());
+ break;
+ case NORTH:
+ // Try to find a suitable offset by examining the area above.
+ parent = getParent();
+ r = parent.modelToView(pos, a, b).getBounds();
+ ret = parent.viewToModel(r.x, r.y - 1, a, biasRet);
+ break;
+ case SOUTH:
+ // Try to find a suitable offset by examining the area below.
+ parent = getParent();
+ r = parent.modelToView(pos, a, b).getBounds();
+ ret = parent.viewToModel(r.x + r.width, r.y + r.height, a, biasRet);
+ break;
+ default:
+ throw new IllegalArgumentException("Illegal value for d");
+ }
+
+ return ret;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/ViewFactory.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/ViewFactory.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/ViewFactory.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/ViewFactory.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,50 @@
+/* ViewFactory.java --
+ Copyright (C) 2002, 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+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);
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/WrappedPlainView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/WrappedPlainView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/WrappedPlainView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/WrappedPlainView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,742 @@
+/* WrappedPlainView.java --
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text;
+
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.Shape;
+
+import javax.swing.event.DocumentEvent;
+import javax.swing.text.Position.Bias;
+
+/**
+ * @author Anthony Balkissoon abalkiss at redhat dot com
+ *
+ */
+public class WrappedPlainView extends BoxView implements TabExpander
+{
+ /** The color for selected text **/
+ Color selectedColor;
+
+ /** The color for unselected text **/
+ Color unselectedColor;
+
+ /** The color for disabled components **/
+ Color disabledColor;
+
+ /**
+ * Stores the font metrics. This is package private to avoid synthetic
+ * accessor method.
+ */
+ FontMetrics metrics;
+
+ /** Whether or not to wrap on word boundaries **/
+ boolean wordWrap;
+
+ /** A ViewFactory that creates WrappedLines **/
+ ViewFactory viewFactory = new WrappedLineCreator();
+
+ /** The start of the selected text **/
+ int selectionStart;
+
+ /** The end of the selected text **/
+ int selectionEnd;
+
+ /** The height of the line (used while painting) **/
+ int lineHeight;
+
+ /**
+ * The instance returned by {@link #getLineBuffer()}.
+ */
+ private transient Segment lineBuffer;
+
+ public WrappedPlainView (Element elem)
+ {
+ this (elem, false);
+ }
+
+ public WrappedPlainView (Element elem, boolean wordWrap)
+ {
+ super (elem, Y_AXIS);
+ this.wordWrap = wordWrap;
+ }
+
+ /**
+ * Provides access to the Segment used for retrievals from the Document.
+ * @return the Segment.
+ */
+ protected final Segment getLineBuffer()
+ {
+ if (lineBuffer == null)
+ lineBuffer = new Segment();
+ return lineBuffer;
+ }
+
+ /**
+ * Returns the next tab stop position after a given reference position.
+ *
+ * This implementation ignores the <code>tabStop</code> argument.
+ *
+ * @param x the current x position in pixels
+ * @param tabStop the position within the text stream that the tab occured at
+ */
+ public float nextTabStop(float x, int tabStop)
+ {
+ JTextComponent host = (JTextComponent)getContainer();
+ float tabSizePixels = getTabSize()
+ * host.getFontMetrics(host.getFont()).charWidth('m');
+ return (float) (Math.floor(x / tabSizePixels) + 1) * tabSizePixels;
+ }
+
+ /**
+ * Returns the tab size for the Document based on
+ * PlainDocument.tabSizeAttribute, defaulting to 8 if this property is
+ * not defined
+ *
+ * @return the tab size.
+ */
+ protected int getTabSize()
+ {
+ Object tabSize = getDocument().getProperty(PlainDocument.tabSizeAttribute);
+ if (tabSize == null)
+ return 8;
+ return ((Integer)tabSize).intValue();
+ }
+
+ /**
+ * Draws a line of text, suppressing white space at the end and expanding
+ * tabs. Calls drawSelectedText and drawUnselectedText.
+ * @param p0 starting document position to use
+ * @param p1 ending document position to use
+ * @param g graphics context
+ * @param x starting x position
+ * @param y starting y position
+ */
+ protected void drawLine(int p0, int p1, Graphics g, int x, int y)
+ {
+ try
+ {
+ // We have to draw both selected and unselected text. There are
+ // several cases:
+ // - entire range is unselected
+ // - entire range is selected
+ // - start of range is selected, end of range is unselected
+ // - start of range is unselected, end of range is selected
+ // - middle of range is selected, start and end of range is unselected
+
+ // entire range unselected:
+ if ((selectionStart == selectionEnd) ||
+ (p0 > selectionEnd || p1 < selectionStart))
+ drawUnselectedText(g, x, y, p0, p1);
+
+ // entire range selected
+ else if (p0 >= selectionStart && p1 <= selectionEnd)
+ drawSelectedText(g, x, y, p0, p1);
+
+ // start of range selected, end of range unselected
+ else if (p0 >= selectionStart)
+ {
+ x = drawSelectedText(g, x, y, p0, selectionEnd);
+ drawUnselectedText(g, x, y, selectionEnd, p1);
+ }
+
+ // start of range unselected, end of range selected
+ else if (selectionStart > p0 && selectionEnd > p1)
+ {
+ x = drawUnselectedText(g, x, y, p0, selectionStart);
+ drawSelectedText(g, x, y, selectionStart, p1);
+ }
+
+ // middle of range selected
+ else if (selectionStart > p0)
+ {
+ x = drawUnselectedText(g, x, y, p0, selectionStart);
+ x = drawSelectedText(g, x, y, selectionStart, selectionEnd);
+ drawUnselectedText(g, x, y, selectionEnd, p1);
+ }
+ }
+ catch (BadLocationException ble)
+ {
+ // shouldn't happen
+ }
+ }
+
+ /**
+ * Renders the range of text as selected text. Just paints the text
+ * in the color specified by the host component. Assumes the highlighter
+ * will render the selected background.
+ * @param g the graphics context
+ * @param x the starting X coordinate
+ * @param y the starting Y coordinate
+ * @param p0 the starting model location
+ * @param p1 the ending model location
+ * @return the X coordinate of the end of the text
+ * @throws BadLocationException if the given range is invalid
+ */
+ protected int drawSelectedText(Graphics g, int x, int y, int p0, int p1)
+ throws BadLocationException
+ {
+ g.setColor(selectedColor);
+ Segment segment = getLineBuffer();
+ getDocument().getText(p0, p1 - p0, segment);
+ return Utilities.drawTabbedText(segment, x, y, g, this, p0);
+ }
+
+ /**
+ * Renders the range of text as normal unhighlighted text.
+ * @param g the graphics context
+ * @param x the starting X coordinate
+ * @param y the starting Y coordinate
+ * @param p0 the starting model location
+ * @param p1 the end model location
+ * @return the X location of the end off the range
+ * @throws BadLocationException if the range given is invalid
+ */
+ protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1)
+ throws BadLocationException
+ {
+ JTextComponent textComponent = (JTextComponent) getContainer();
+ if (textComponent.isEnabled())
+ g.setColor(unselectedColor);
+ else
+ g.setColor(disabledColor);
+
+ Segment segment = getLineBuffer();
+ getDocument().getText(p0, p1 - p0, segment);
+ return Utilities.drawTabbedText(segment, x, y, g, this, p0);
+ }
+
+ /**
+ * Loads the children to initiate the view. Called by setParent.
+ * Creates a WrappedLine for each child Element.
+ */
+ protected void loadChildren (ViewFactory f)
+ {
+ Element root = getElement();
+ int numChildren = root.getElementCount();
+ if (numChildren == 0)
+ return;
+
+ View[] children = new View[numChildren];
+ for (int i = 0; i < numChildren; i++)
+ children[i] = new WrappedLine(root.getElement(i));
+ replace(0, 0, children);
+ }
+
+ /**
+ * Calculates the break position for the text between model positions
+ * p0 and p1. Will break on word boundaries or character boundaries
+ * depending on the break argument given in construction of this
+ * WrappedPlainView. Used by the nested WrappedLine class to determine
+ * when to start the next logical line.
+ * @param p0 the start model position
+ * @param p1 the end model position
+ * @return the model position at which to break the text
+ */
+ protected int calculateBreakPosition(int p0, int p1)
+ {
+ Container c = getContainer();
+
+ int li = getLeftInset();
+ int ti = getTopInset();
+
+ Rectangle alloc = new Rectangle(li, ti,
+ getWidth()-getRightInset()-li,
+ getHeight()-getBottomInset()-ti);
+
+ // Mimic a behavior observed in the RI.
+ if (alloc.isEmpty())
+ return 0;
+
+ updateMetrics();
+
+ try
+ {
+ getDocument().getText(p0, p1 - p0, getLineBuffer());
+ }
+ catch (BadLocationException ble)
+ {
+ // this shouldn't happen
+ throw new InternalError("Invalid offsets p0: " + p0 + " - p1: " + p1);
+ }
+
+ if (wordWrap)
+ return Utilities.getBreakLocation(lineBuffer, metrics, alloc.x,
+ alloc.x + alloc.width, this, p0);
+ else
+ return p0 + Utilities.getTabbedTextOffset(lineBuffer, metrics, alloc.x,
+ alloc.x + alloc.width, this, 0,
+ true);
+ }
+
+ void updateMetrics()
+ {
+ Container component = getContainer();
+ metrics = component.getFontMetrics(component.getFont());
+ }
+
+ /**
+ * Determines the preferred span along the given axis. Implemented to
+ * cache the font metrics and then call the super classes method.
+ */
+ public float getPreferredSpan (int axis)
+ {
+ updateMetrics();
+ return super.getPreferredSpan(axis);
+ }
+
+ /**
+ * Determines the minimum span along the given axis. Implemented to
+ * cache the font metrics and then call the super classes method.
+ */
+ public float getMinimumSpan (int axis)
+ {
+ updateMetrics();
+ return super.getMinimumSpan(axis);
+ }
+
+ /**
+ * Determines the maximum span along the given axis. Implemented to
+ * cache the font metrics and then call the super classes method.
+ */
+ public float getMaximumSpan (int axis)
+ {
+ updateMetrics();
+ return super.getMaximumSpan(axis);
+ }
+
+ /**
+ * Called when something was inserted. Overridden so that
+ * the view factory creates WrappedLine views.
+ */
+ public void insertUpdate (DocumentEvent e, Shape a, ViewFactory f)
+ {
+ super.insertUpdate(e, a, viewFactory);
+
+ // No repaint needed, as this is done by the WrappedLine instances.
+ }
+
+ /**
+ * Called when something is removed. Overridden so that
+ * the view factory creates WrappedLine views.
+ */
+ public void removeUpdate (DocumentEvent e, Shape a, ViewFactory f)
+ {
+ super.removeUpdate(e, a, viewFactory);
+
+ // No repaint needed, as this is done by the WrappedLine instances.
+ }
+
+ /**
+ * Called when the portion of the Document that this View is responsible
+ * for changes. Overridden so that the view factory creates
+ * WrappedLine views.
+ */
+ public void changedUpdate (DocumentEvent e, Shape a, ViewFactory f)
+ {
+ super.changedUpdate(e, a, viewFactory);
+
+ // No repaint needed, as this is done by the WrappedLine instances.
+ }
+
+ class WrappedLineCreator implements ViewFactory
+ {
+ // Creates a new WrappedLine
+ public View create(Element elem)
+ {
+ return new WrappedLine(elem);
+ }
+ }
+
+ /**
+ * Renders the <code>Element</code> that is associated with this
+ * <code>View</code>. Caches the metrics and then calls
+ * super.paint to paint all the child views.
+ *
+ * @param g the <code>Graphics</code> context to render to
+ * @param a the allocated region for the <code>Element</code>
+ */
+ public void paint(Graphics g, Shape a)
+ {
+ JTextComponent comp = (JTextComponent)getContainer();
+ // Ensure metrics are up-to-date.
+ updateMetrics();
+
+ selectionStart = comp.getSelectionStart();
+ selectionEnd = comp.getSelectionEnd();
+
+ selectedColor = comp.getSelectedTextColor();
+ unselectedColor = comp.getForeground();
+ disabledColor = comp.getDisabledTextColor();
+ selectedColor = comp.getSelectedTextColor();
+ lineHeight = metrics.getHeight();
+ g.setFont(comp.getFont());
+
+ super.paint(g, a);
+ }
+
+ /**
+ * Sets the size of the View. Implemented to update the metrics
+ * and then call super method.
+ */
+ public void setSize (float width, float height)
+ {
+ updateMetrics();
+ if (width != getWidth())
+ preferenceChanged(null, true, true);
+ super.setSize(width, height);
+ }
+
+ class WrappedLine extends View
+ {
+ /** Used to cache the number of lines for this View **/
+ int numLines = 1;
+
+ public WrappedLine(Element elem)
+ {
+ super(elem);
+ determineNumLines();
+ }
+
+ /**
+ * Renders this (possibly wrapped) line using the given Graphics object
+ * and on the given rendering surface.
+ */
+ public void paint(Graphics g, Shape s)
+ {
+ Rectangle rect = s.getBounds();
+
+ int end = getEndOffset();
+ int currStart = getStartOffset();
+ int currEnd;
+ int count = 0;
+ while (currStart < end)
+ {
+ currEnd = calculateBreakPosition(currStart, end);
+
+ drawLine(currStart, currEnd, g, rect.x, rect.y + metrics.getAscent());
+
+ rect.y += lineHeight;
+ if (currEnd == currStart)
+ currStart ++;
+ else
+ currStart = currEnd;
+
+ count++;
+
+ }
+
+ if (count != numLines)
+ {
+ numLines = count;
+ preferenceChanged(this, false, true);
+ }
+
+ }
+
+ /**
+ * Calculates the number of logical lines that the Element
+ * needs to be displayed and updates the variable numLines
+ * accordingly.
+ */
+ void determineNumLines()
+ {
+ numLines = 0;
+ int end = getEndOffset();
+ if (end == 0)
+ return;
+
+ int breakPoint;
+ for (int i = getStartOffset(); i < end;)
+ {
+ numLines ++;
+ // careful: check that there's no off-by-one problem here
+ // depending on which position calculateBreakPosition returns
+ breakPoint = calculateBreakPosition(i, end);
+
+ if (breakPoint == 0)
+ return;
+
+ // If breakPoint is equal to the current index no further
+ // line is needed and we can end the loop.
+ if (breakPoint == i)
+ break;
+ else
+ i = breakPoint;
+ }
+ }
+
+ /**
+ * Determines the preferred span for this view along the given axis.
+ *
+ * @param axis the axis (either X_AXIS or Y_AXIS)
+ *
+ * @return the preferred span along the given axis.
+ * @throws IllegalArgumentException if axis is not X_AXIS or Y_AXIS
+ */
+ public float getPreferredSpan(int axis)
+ {
+ if (axis == X_AXIS)
+ return getWidth();
+ else if (axis == Y_AXIS)
+ {
+ if (metrics == null)
+ updateMetrics();
+ return numLines * metrics.getHeight();
+ }
+
+ throw new IllegalArgumentException("Invalid axis for getPreferredSpan: "
+ + axis);
+ }
+
+ /**
+ * Provides a mapping from model space to view space.
+ *
+ * @param pos the position in the model
+ * @param a the region into which the view is rendered
+ * @param b the position bias (forward or backward)
+ *
+ * @return a box in view space that represents the given position
+ * in model space
+ * @throws BadLocationException if the given model position is invalid
+ */
+ public Shape modelToView(int pos, Shape a, Bias b)
+ throws BadLocationException
+ {
+ Rectangle rect = a.getBounds();
+
+ // Throwing a BadLocationException is an observed behavior of the RI.
+ if (rect.isEmpty())
+ throw new BadLocationException("Unable to calculate view coordinates "
+ + "when allocation area is empty.", 5);
+
+ Segment s = getLineBuffer();
+ int lineHeight = metrics.getHeight();
+
+ // Return a rectangle with width 1 and height equal to the height
+ // of the text
+ rect.height = lineHeight;
+ rect.width = 1;
+
+ int currLineStart = getStartOffset();
+ int end = getEndOffset();
+
+ if (pos < currLineStart || pos >= end)
+ throw new BadLocationException("invalid offset", pos);
+
+ while (true)
+ {
+ int currLineEnd = calculateBreakPosition(currLineStart, end);
+ // If pos is between currLineStart and currLineEnd then just find
+ // the width of the text from currLineStart to pos and add that
+ // to rect.x
+ if (pos >= currLineStart && pos < currLineEnd)
+ {
+ try
+ {
+ getDocument().getText(currLineStart, pos - currLineStart, s);
+ }
+ catch (BadLocationException ble)
+ {
+ // Shouldn't happen
+ }
+ rect.x += Utilities.getTabbedTextWidth(s, metrics, rect.x,
+ WrappedPlainView.this,
+ currLineStart);
+ return rect;
+ }
+ // Increment rect.y so we're checking the next logical line
+ rect.y += lineHeight;
+
+ // Increment currLineStart to the model position of the start
+ // of the next logical line
+ if (currLineEnd == currLineStart)
+ currLineStart = end;
+ else
+ currLineStart = currLineEnd;
+ }
+
+ }
+
+ /**
+ * Provides a mapping from view space to model space.
+ *
+ * @param x the x coordinate in view space
+ * @param y the y coordinate in view space
+ * @param a the region into which the view is rendered
+ * @param b the position bias (forward or backward)
+ *
+ * @return the location in the model that best represents the
+ * given point in view space
+ */
+ public int viewToModel(float x, float y, Shape a, Bias[] b)
+ {
+ Segment s = getLineBuffer();
+ Rectangle rect = a.getBounds();
+ int currLineStart = getStartOffset();
+
+ // Although calling modelToView with the last possible offset will
+ // cause a BadLocationException in CompositeView it is allowed
+ // to return that offset in viewToModel.
+ int end = getEndOffset();
+
+ int lineHeight = metrics.getHeight();
+ if (y < rect.y)
+ return currLineStart;
+
+ if (y > rect.y + rect.height)
+ return end;
+
+ // Note: rect.x and rect.width do not represent the width of painted
+ // text but the area where text *may* be painted. This means the width
+ // is most of the time identical to the component's width.
+
+ while (currLineStart != end)
+ {
+ int currLineEnd = calculateBreakPosition(currLineStart, end);
+
+ // If we're at the right y-position that means we're on the right
+ // logical line and we should look for the character
+ if (y >= rect.y && y < rect.y + lineHeight)
+ {
+ try
+ {
+ getDocument().getText(currLineStart, currLineEnd - currLineStart, s);
+ }
+ catch (BadLocationException ble)
+ {
+ // Shouldn't happen
+ }
+
+ int offset = Utilities.getTabbedTextOffset(s, metrics, rect.x,
+ (int) x,
+ WrappedPlainView.this,
+ currLineStart);
+ // If the calculated offset is the end of the line (in the
+ // document (= start of the next line) return the preceding
+ // offset instead. This makes sure that clicking right besides
+ // the last character in a line positions the cursor after the
+ // last character and not in the beginning of the next line.
+ return (offset == currLineEnd) ? offset - 1 : offset;
+ }
+ // Increment rect.y so we're checking the next logical line
+ rect.y += lineHeight;
+
+ // Increment currLineStart to the model position of the start
+ // of the next logical line.
+ currLineStart = currLineEnd;
+
+ }
+
+ return end;
+ }
+
+ /**
+ * <p>This method is called from insertUpdate and removeUpdate.</p>
+ *
+ * <p>If the number of lines in the document has changed, just repaint
+ * the whole thing (note, could improve performance by not repainting
+ * anything above the changes). If the number of lines hasn't changed,
+ * just repaint the given Rectangle.</p>
+ *
+ * <p>Note that the <code>Rectangle</code> argument may be <code>null</code>
+ * when the allocation area is empty.</code>
+ *
+ * @param a the Rectangle to repaint if the number of lines hasn't changed
+ */
+ void updateDamage (Rectangle a)
+ {
+ // If the allocation area is empty we can't do anything useful.
+ // As determining the number of lines is impossible in that state we
+ // reset it to an invalid value which can then be recalculated at a
+ // later point.
+ if (a == null || a.isEmpty())
+ {
+ numLines = 1;
+ return;
+ }
+
+ int oldNumLines = numLines;
+ determineNumLines();
+
+ if (numLines != oldNumLines)
+ preferenceChanged(this, false, true);
+ else
+ getContainer().repaint(a.x, a.y, a.width, a.height);
+ }
+
+ /**
+ * This method is called when something is inserted into the Document
+ * that this View is displaying.
+ *
+ * @param changes the DocumentEvent for the changes.
+ * @param a the allocation of the View
+ * @param f the ViewFactory used to rebuild
+ */
+ public void insertUpdate (DocumentEvent changes, Shape a, ViewFactory f)
+ {
+ updateDamage((Rectangle)a);
+ }
+
+ /**
+ * This method is called when something is removed from the Document
+ * that this View is displaying.
+ *
+ * @param changes the DocumentEvent for the changes.
+ * @param a the allocation of the View
+ * @param f the ViewFactory used to rebuild
+ */
+ public void removeUpdate (DocumentEvent changes, Shape a, ViewFactory f)
+ {
+ // Note: This method is not called when characters from the
+ // end of the document are removed. The reason for this
+ // can be found in the implementation of View.forwardUpdate:
+ // The document event will denote offsets which do not exist
+ // any more, getViewIndex() will therefore return -1 and this
+ // makes View.forwardUpdate() skip this method call.
+ // However this seems to cause no trouble and as it reduces the
+ // number of method calls it can stay this way.
+
+ updateDamage((Rectangle)a);
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/BRView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/BRView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/BRView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/BRView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,71 @@
+/* BRView.java -- HTML BR tag view
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import javax.swing.text.Element;
+
+/**
+ * Handled the HTML BR tag.
+ */
+class BRView
+ extends NullView
+
+{
+ /**
+ * Creates the new BR view.
+ *
+ * @param elem the HTML element, representing the view.
+ */
+ public BRView(Element elem)
+ {
+ super(elem);
+ }
+
+ /**
+ * Always return ForcedBreakWeight for the X_AXIS, BadBreakWeight for the
+ * Y_AXIS.
+ */
+ public int getBreakWeight(int axis, float pos, float len)
+ {
+ if (axis == X_AXIS)
+ return ForcedBreakWeight;
+ else
+ return BadBreakWeight;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/BlockView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/BlockView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/BlockView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/BlockView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,301 @@
+/* BlockView.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.Shape;
+
+import javax.swing.SizeRequirements;
+import javax.swing.event.DocumentEvent;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BoxView;
+import javax.swing.text.Element;
+import javax.swing.text.View;
+import javax.swing.text.ViewFactory;
+
+/**
+ * @author Lillian Angel <langel at redhat.com>
+ */
+public class BlockView extends BoxView
+{
+
+ /**
+ * Creates a new view that represents an html box.
+ * This can be used for a number of elements.
+ *
+ * @param elem - the element to create a view for
+ * @param axis - either View.X_AXIS or View.Y_AXIS
+ */
+ public BlockView(Element elem, int axis)
+ {
+ super(elem, axis);
+ }
+
+ /**
+ * Creates the parent view for this. It is called before
+ * any other methods, if the parent view is working properly.
+ * Implemented to forward to the superclass and call
+ * setPropertiesFromAttributes to set the paragraph
+ * properties.
+ *
+ * @param parent - the new parent, or null if the view
+ * is being removed from a parent it was added to.
+ */
+ public void setParent(View parent)
+ {
+ super.setParent(parent);
+
+ if (parent != null)
+ setPropertiesFromAttributes();
+ }
+
+ /**
+ * Calculates the requirements along the major axis.
+ * This is implemented to call the superclass and then
+ * adjust it if the CSS width or height attribute is specified
+ * and applicable.
+ *
+ * @param axis - the axis to check the requirements for.
+ * @param r - the SizeRequirements. If null, one is created.
+ * @return the new SizeRequirements object.
+ */
+ protected SizeRequirements calculateMajorAxisRequirements(int axis,
+ SizeRequirements r)
+ {
+ SizeRequirements sr = super.calculateMajorAxisRequirements(axis, r);
+ // FIXME: adjust it if the CSS width or height attribute is specified
+ // and applicable
+ return sr;
+ }
+
+ /**
+ * Calculates the requirements along the minor axis.
+ * This is implemented to call the superclass and then
+ * adjust it if the CSS width or height attribute is specified
+ * and applicable.
+ *
+ * @param axis - the axis to check the requirements for.
+ * @param r - the SizeRequirements. If null, one is created.
+ * @return the new SizeRequirements object.
+ */
+ protected SizeRequirements calculateMinorAxisRequirements(int axis,
+ SizeRequirements r)
+ {
+ SizeRequirements sr = super.calculateMinorAxisRequirements(axis, r);
+ // FIXME: adjust it if the CSS width or height attribute is specified
+ // and applicable.
+ return sr;
+ }
+
+ /**
+ * Lays out the box along the minor axis (the axis that is
+ * perpendicular to the axis that it represents). The results
+ * of the layout are placed in the given arrays which are
+ * the allocations to the children along the minor axis.
+ *
+ * @param targetSpan - the total span given to the view, also
+ * used to layout the children.
+ * @param axis - the minor axis
+ * @param offsets - the offsets from the origin of the view for
+ * all the child views. This is a return value and is filled in by this
+ * function.
+ * @param spans - the span of each child view. This is a return value and is
+ * filled in by this function.
+ */
+ protected void layoutMinorAxis(int targetSpan, int axis,
+ int[] offsets, int[] spans)
+ {
+ // FIXME: Not implemented.
+ super.layoutMinorAxis(targetSpan, axis, offsets, spans);
+ }
+
+ /**
+ * Paints using the given graphics configuration and shape.
+ * This delegates to the css box painter to paint the
+ * border and background prior to the interior.
+ *
+ * @param g - Graphics configuration
+ * @param a - the Shape to render into.
+ */
+ public void paint(Graphics g, Shape a)
+ {
+ Rectangle rect = (Rectangle) a;
+ // FIXME: not fully implemented
+ getStyleSheet().getBoxPainter(getAttributes()).paint(g, rect.x, rect.y,
+ rect.width,
+ rect.height, this);
+ super.paint(g, a);
+ }
+
+ /**
+ * Fetches the attributes to use when painting.
+ *
+ * @return the attributes of this model.
+ */
+ public AttributeSet getAttributes()
+ {
+ return getStyleSheet().getViewAttributes(this);
+ }
+
+ /**
+ * Gets the resize weight.
+ *
+ * @param axis - the axis to get the resize weight for.
+ * @return the resize weight.
+ * @throws IllegalArgumentException - for an invalid axis
+ */
+ public int getResizeWeight(int axis) throws IllegalArgumentException
+ {
+ // Can't resize the Y_AXIS
+ if (axis == Y_AXIS)
+ return 0;
+ if (axis == X_AXIS)
+ return 1;
+ throw new IllegalArgumentException("Invalid Axis");
+ }
+
+ /**
+ * Gets the alignment.
+ *
+ * @param axis - the axis to get the alignment for.
+ * @return the alignment.
+ */
+ public float getAlignment(int axis)
+ {
+ if (axis == X_AXIS)
+ return 0.0F;
+ if (axis == Y_AXIS)
+ {
+ if (getViewCount() == 0)
+ return 0.0F;
+ float prefHeight = getPreferredSpan(Y_AXIS);
+ float firstRowHeight = getView(0).getPreferredSpan(Y_AXIS);
+ return (firstRowHeight / 2.F) / prefHeight;
+ }
+ throw new IllegalArgumentException("Invalid Axis");
+ }
+
+ /**
+ * Gives notification from the document that attributes were
+ * changed in a location that this view is responsible for.
+ *
+ * @param ev - the change information
+ * @param a - the current shape of the view
+ * @param f - the factory to use to rebuild if the view has children.
+ */
+ public void changedUpdate(DocumentEvent ev,
+ Shape a, ViewFactory f)
+ {
+ super.changedUpdate(ev, a, f);
+
+ // If more elements were added, then need to set the properties for them
+ int currPos = ev.getOffset();
+ if (currPos <= getStartOffset() && (currPos + ev.getLength()) >= getEndOffset())
+ setPropertiesFromAttributes();
+ }
+
+ /**
+ * Determines the preferred span along the axis.
+ *
+ * @param axis - the view to get the preferred span for.
+ * @return the span the view would like to be painted into >=0/
+ * The view is usually told to paint into the span that is returned,
+ * although the parent may choose to resize or break the view.
+ * @throws IllegalArgumentException - for an invalid axis
+ */
+ public float getPreferredSpan(int axis) throws IllegalArgumentException
+ {
+ if (axis == X_AXIS || axis == Y_AXIS)
+ return super.getPreferredSpan(axis);
+ throw new IllegalArgumentException("Invalid Axis");
+ }
+
+ /**
+ * Determines the minimum span along the axis.
+ *
+ * @param axis - the axis to get the minimum span for.
+ * @return the span the view would like to be painted into >=0/
+ * The view is usually told to paint into the span that is returned,
+ * although the parent may choose to resize or break the view.
+ * @throws IllegalArgumentException - for an invalid axis
+ */
+ public float getMinimumSpan(int axis) throws IllegalArgumentException
+ {
+ if (axis == X_AXIS || axis == Y_AXIS)
+ return super.getMinimumSpan(axis);
+ throw new IllegalArgumentException("Invalid Axis");
+ }
+
+ /**
+ * Determines the maximum span along the axis.
+ *
+ * @param axis - the axis to get the maximum span for.
+ * @return the span the view would like to be painted into >=0/
+ * The view is usually told to paint into the span that is returned,
+ * although the parent may choose to resize or break the view.
+ * @throws IllegalArgumentException - for an invalid axis
+ */
+ public float getMaximumSpan(int axis) throws IllegalArgumentException
+ {
+ if (axis == X_AXIS || axis == Y_AXIS)
+ return super.getMaximumSpan(axis);
+ throw new IllegalArgumentException("Invalid Axis");
+ }
+
+ /**
+ * Updates any cached values that come from attributes.
+ */
+ protected void setPropertiesFromAttributes()
+ {
+ // FIXME: Not implemented (need to use StyleSheet).
+ }
+
+ /**
+ * Gets the default style sheet.
+ *
+ * @return the style sheet
+ */
+ protected StyleSheet getStyleSheet()
+ {
+ StyleSheet styleSheet = new StyleSheet();
+ styleSheet.importStyleSheet(getClass().getResource(HTMLEditorKit.DEFAULT_CSS));
+ return styleSheet;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/CSS.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/CSS.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/CSS.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/CSS.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,462 @@
+/* CSS.java -- Provides CSS attributes
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.text.html;
+
+import java.io.Serializable;
+import java.util.HashMap;
+
+/**
+ * Provides CSS attributes to be used by the HTML view classes. The constants
+ * defined here are used as keys for text attributes for use in
+ * {@link javax.swing.text.AttributeSet}s of {@link javax.swing.text.Element}s.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+public class CSS implements Serializable
+{
+ /**
+ * Returns an array of all CSS attributes.
+ *
+ * @return All available CSS.Attribute objects.
+ */
+ public static CSS.Attribute[] getAllAttributeKeys()
+ {
+ Object[] src = Attribute.attributeMap.values().toArray();
+ CSS.Attribute[] dst = new CSS.Attribute[ src.length ];
+ System.arraycopy(src, 0, dst, 0, src.length);
+ return dst;
+ }
+
+ /**
+ * Returns an a given CSS attribute.
+ *
+ * @param name - The name of the attribute.
+ * @return The CSS attribute with the given name, or <code>null</code> if
+ * no attribute with that name exists.
+ */
+ public static CSS.Attribute getAttribute(String name)
+ {
+ return (CSS.Attribute)Attribute.attributeMap.get( name );
+ }
+
+ public static final class Attribute
+ {
+ /**
+ * The CSS attribute 'background'.
+ */
+ public static final Attribute BACKGROUND =
+ new Attribute("background", false, null);
+
+ /**
+ * The CSS attribute 'background-attachment'.
+ */
+ public static final Attribute BACKGROUND_ATTACHMENT =
+ new Attribute("background-attachment", false, "scroll");
+
+ /**
+ * The CSS attribute 'background-color'.
+ */
+ public static final Attribute BACKGROUND_COLOR =
+ new Attribute("background-color", false, "transparent");
+
+ /**
+ * The CSS attribute 'background-image'.
+ */
+ public static final Attribute BACKGROUND_IMAGE =
+ new Attribute("background-image", false, "none");
+
+ /**
+ * The CSS attribute 'background-position'.
+ */
+ public static final Attribute BACKGROUND_POSITION =
+ new Attribute("background-position", false, null);
+
+ /**
+ * The CSS attribute 'background-repeat'.
+ */
+ public static final Attribute BACKGROUND_REPEAT =
+ new Attribute("background-repeat", false, "repeat");
+
+ /**
+ * The CSS attribute 'border'.
+ */
+ public static final Attribute BORDER = new Attribute("border", false, null);
+
+ /**
+ * The CSS attribute 'border-bottom'.
+ */
+ public static final Attribute BORDER_BOTTOM =
+ new Attribute("border-bottom", false, null);
+
+ /**
+ * The CSS attribute 'border-bottom-width'.
+ */
+ public static final Attribute BORDER_BOTTOM_WIDTH =
+ new Attribute("border-bottom-width", false, "medium");
+
+ /**
+ * The CSS attribute 'border-color'.
+ */
+ public static final Attribute BORDER_COLOR =
+ new Attribute("border-color", false, "black");
+
+ /**
+ * The CSS attribute 'border-left'.
+ */
+ public static final Attribute BORDER_LEFT =
+ new Attribute("border-left", false, null);
+
+ /**
+ * The CSS attribute 'border-left-width'.
+ */
+ public static final Attribute BORDER_LEFT_WIDTH =
+ new Attribute("border-left-width", false, "medium");
+
+ /**
+ * The CSS attribute 'border-right'.
+ */
+ public static final Attribute BORDER_RIGHT =
+ new Attribute("border-right", false, null);
+
+ /**
+ * The CSS attribute 'border-right-width'.
+ */
+ public static final Attribute BORDER_RIGHT_WIDTH =
+ new Attribute("border-right-width", false, "medium");
+
+ /**
+ * The CSS attribute 'border-style'.
+ */
+ public static final Attribute BORDER_STYLE =
+ new Attribute("border-style", false, "none");
+
+ /**
+ * The CSS attribute 'border-top'.
+ */
+ public static final Attribute BORDER_TOP =
+ new Attribute("border-top", false, null);
+
+ /**
+ * The CSS attribute 'border-top-width'.
+ */
+ public static final Attribute BORDER_TOP_WIDTH =
+ new Attribute("border-top-width", false, "medium");
+
+ /**
+ * The CSS attribute 'border-width'.
+ */
+ public static final Attribute BORDER_WIDTH =
+ new Attribute("border-width", false, "medium");
+
+ /**
+ * The CSS attribute 'clear'.
+ */
+ public static final Attribute CLEAR = new Attribute("clear", false, "none");
+
+ /**
+ * The CSS attribute 'color'.
+ */
+ public static final Attribute COLOR = new Attribute("color", true, "black");
+
+ /**
+ * The CSS attribute 'display'.
+ */
+ public static final Attribute DISPLAY =
+ new Attribute("display", false, "block");
+
+ /**
+ * The CSS attribute 'float'.
+ */
+ public static final Attribute FLOAT = new Attribute("float", false, "none");
+
+ /**
+ * The CSS attribute 'font'.
+ */
+ public static final Attribute FONT = new Attribute("font", true, null);
+
+ /**
+ * The CSS attribute 'font-family'.
+ */
+ public static final Attribute FONT_FAMILY =
+ new Attribute("font-family", true, null);
+
+ /**
+ * The CSS attribute 'font-size'.
+ */
+ public static final Attribute FONT_SIZE =
+ new Attribute("font-size", true, "medium");
+
+ /**
+ * The CSS attribute 'font-style'.
+ */
+ public static final Attribute FONT_STYLE =
+ new Attribute("font-style", true, "normal");
+
+ /**
+ * The CSS attribute 'font-variant'.
+ */
+ public static final Attribute FONT_VARIANT =
+ new Attribute("font-variant", true, "normal");
+
+ /**
+ * The CSS attribute 'font-weight'.
+ */
+ public static final Attribute FONT_WEIGHT =
+ new Attribute("font-weight", true, "normal");
+
+ /**
+ * The CSS attribute 'height'.
+ */
+ public static final Attribute HEIGHT =
+ new Attribute("height", false, "auto");
+
+ /**
+ * The CSS attribute 'letter-spacing'.
+ */
+ public static final Attribute LETTER_SPACING =
+ new Attribute("letter-spacing", true, "normal");
+
+ /**
+ * The CSS attribute 'line-height'.
+ */
+ public static final Attribute LINE_HEIGHT =
+ new Attribute("line-height", true, "normal");
+
+ /**
+ * The CSS attribute 'list-style'.
+ */
+ public static final Attribute LIST_STYLE =
+ new Attribute("list-style", true, null);
+
+ /**
+ * The CSS attribute 'list-style-image'.
+ */
+ public static final Attribute LIST_STYLE_IMAGE =
+ new Attribute("list-style-image", true, "none");
+
+ /**
+ * The CSS attribute 'list-style-position'.
+ */
+ public static final Attribute LIST_STYLE_POSITION =
+ new Attribute("list-style-position", true, "outside");
+
+ /**
+ * The CSS attribute 'list-style-type'.
+ */
+ public static final Attribute LIST_STYLE_TYPE =
+ new Attribute("list-style-type", true, "disc");
+
+ /**
+ * The CSS attribute 'margin'.
+ */
+ public static final Attribute MARGIN = new Attribute("margin", false, null);
+
+ /**
+ * The CSS attribute 'margin-bottom'.
+ */
+ public static final Attribute MARGIN_BOTTOM =
+ new Attribute("margin-bottom", false, "0");
+
+ /**
+ * The CSS attribute 'margin-left'.
+ */
+ public static final Attribute MARGIN_LEFT =
+ new Attribute("margin-left", false, "0");
+
+ /**
+ * The CSS attribute 'margin-right'.
+ */
+ public static final Attribute MARGIN_RIGHT =
+ new Attribute("margin-right", false, "0");
+
+ /**
+ * The CSS attribute 'margin-top'.
+ */
+ public static final Attribute MARGIN_TOP =
+ new Attribute("margin-top", false, "0");
+
+ /**
+ * The CSS attribute 'padding'.
+ */
+ public static final Attribute PADDING =
+ new Attribute("padding", false, null);
+
+ /**
+ * The CSS attribute 'padding-bottom'.
+ */
+ public static final Attribute PADDING_BOTTOM =
+ new Attribute("padding-bottom", false, "0");
+
+ /**
+ * The CSS attribute 'padding-left'.
+ */
+ public static final Attribute PADDING_LEFT =
+ new Attribute("padding-left", false, "0");
+
+ /**
+ * The CSS attribute 'padding-right'.
+ */
+ public static final Attribute PADDING_RIGHT =
+ new Attribute("padding-right", false, "0");
+
+ /**
+ * The CSS attribute 'padding-top'.
+ */
+ public static final Attribute PADDING_TOP =
+ new Attribute("padding-top", false, "0");
+
+ /**
+ * The CSS attribute 'text-align'.
+ */
+ public static final Attribute TEXT_ALIGN =
+ new Attribute("text-align", true, null);
+
+ /**
+ * The CSS attribute 'text-decoration'.
+ */
+ public static final Attribute TEXT_DECORATION =
+ new Attribute("text-decoration", true, "none");
+
+ /**
+ * The CSS attribute 'text-indent'.
+ */
+ public static final Attribute TEXT_INDENT =
+ new Attribute("text-indent", true, "0");
+
+ /**
+ * The CSS attribute 'text-transform'.
+ */
+ public static final Attribute TEXT_TRANSFORM =
+ new Attribute("text-transform", true, "none");
+
+ /**
+ * The CSS attribute 'vertical-align'.
+ */
+ public static final Attribute VERTICAL_ALIGN =
+ new Attribute("vertical-align", false, "baseline");
+
+ /**
+ * The CSS attribute 'white-space'.
+ */
+ public static final Attribute WHITE_SPACE =
+ new Attribute("white-space", true, "normal");
+
+ /**
+ * The CSS attribute 'width'.
+ */
+ public static final Attribute WIDTH =
+ new Attribute("width", false, "auto");
+
+ /**
+ * The CSS attribute 'word-spacing'.
+ */
+ public static final Attribute WORD_SPACING =
+ new Attribute("word-spacing", true, "normal");
+
+ /**
+ * The attribute string.
+ */
+ String attStr;
+
+ /**
+ * Indicates if this attribute should be inherited from it's parent or
+ * not.
+ */
+ boolean isInherited;
+
+ /**
+ * A default value for this attribute if one exists, otherwise null.
+ */
+ String defaultValue;
+
+ /**
+ * A HashMap of all attributes.
+ */
+ static HashMap attributeMap;
+
+ /**
+ * Creates a new Attribute instance with the specified values.
+ *
+ * @param attr the attribute string
+ * @param inherited if the attribute should be inherited or not
+ * @param def a default value; may be <code>null</code>
+ */
+ Attribute(String attr, boolean inherited, String def)
+ {
+ attStr = attr;
+ isInherited = inherited;
+ defaultValue = def;
+ if( attributeMap == null)
+ attributeMap = new HashMap();
+ attributeMap.put( attr, this );
+ }
+
+ /**
+ * Returns the string representation of this attribute as specified
+ * in the CSS specification.
+ */
+ public String toString()
+ {
+ return attStr;
+ }
+
+ /**
+ * Returns <code>true</code> if the attribute should be inherited from
+ * the parent, <code>false</code> otherwise.
+ *
+ * @return <code>true</code> if the attribute should be inherited from
+ * the parent, <code>false</code> otherwise
+ */
+ public boolean isInherited()
+ {
+ return isInherited;
+ }
+
+ /**
+ * Returns the default value of this attribute if one exists,
+ * <code>null</code> otherwise.
+ *
+ * @return the default value of this attribute if one exists,
+ * <code>null</code> otherwise
+ */
+ public String getDefaultValue()
+ {
+ return defaultValue;
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/CSSParser.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/CSSParser.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/CSSParser.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/CSSParser.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,568 @@
+/* CSSParser.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import java.io.*;
+
+/**
+ * Parses a CSS document. This works by way of a delegate that implements the
+ * CSSParserCallback interface. The delegate is notified of the following
+ * events:
+ * - Import statement: handleImport
+ * - Selectors handleSelector. This is invoked for each string. For example if
+ * the Reader contained p, bar , a {}, the delegate would be notified 4 times,
+ * for 'p,' 'bar' ',' and 'a'.
+ * - When a rule starts, startRule
+ * - Properties in the rule via the handleProperty. This
+ * is invoked one per property/value key, eg font size: foo;, would cause the
+ * delegate to be notified once with a value of 'font size'.
+ * - Values in the rule via the handleValue, this is notified for the total value.
+ * - When a rule ends, endRule
+ *
+ * @author Lillian Angel (langel at redhat.com)
+ */
+class CSSParser
+{
+
+ /**
+ * Receives all information about the CSS document structure while parsing it.
+ * The methods are invoked by parser.
+ */
+ static interface CSSParserCallback
+ {
+ /**
+ * Handles the import statment in the document.
+ *
+ * @param imp - the import string
+ */
+ public abstract void handleImport(String imp);
+
+ /**
+ * Called when the start of a rule is encountered.
+ */
+ public abstract void startRule();
+
+ /**
+ * Called when the end of a rule is encountered.
+ */
+ public abstract void endRule();
+
+ /**
+ * Handles the selector of a rule.
+ *
+ * @param selector - the selector in the rule
+ */
+ public abstract void handleSelector(String selector);
+
+ /**
+ * Handles the properties in the document.
+ *
+ * @param property - the property in the document.
+ */
+ public abstract void handleProperty(String property);
+
+ /**
+ * Handles the values in the document.
+ *
+ * @param value - the value to handle.
+ */
+ public abstract void handleValue(String value);
+
+ }
+
+ /**
+ * The identifier of the rule.
+ */
+ private static final int IDENTIFIER = 1;
+
+ /**
+ * The open bracket.
+ */
+ private static final int BRACKET_OPEN = 2;
+
+ /**
+ * The close bracket.
+ */
+ private static final int BRACKET_CLOSE = 3;
+
+ /**
+ * The open brace.
+ */
+ private static final int BRACE_OPEN = 4;
+
+ /**
+ * The close brace.
+ */
+ private static final int BRACE_CLOSE = 5;
+
+ /**
+ * The open parentheses.
+ */
+ private static final int PAREN_OPEN = 6;
+
+ /**
+ * The close parentheses.
+ */
+ private static final int PAREN_CLOSE = 7;
+
+ /**
+ * The end of the document.
+ */
+ private static final int END = -1;
+
+ /**
+ * The character mapping in the document.
+ */
+ // FIXME: What is this used for?
+ private static final char[] charMapping = null;
+
+ /**
+ * Set to true if one character has been read ahead.
+ */
+ private boolean didPushChar;
+
+ /**
+ * The read ahead character.
+ */
+ private int pushedChar;
+
+ /**
+ * Temporary place to hold identifiers.
+ */
+ private StringBuffer unitBuffer;
+
+ /**
+ * Used to indicate blocks.
+ */
+ private int[] unitStack;
+
+ /**
+ * Number of valid blocks.
+ */
+ private int stackCount;
+
+ /**
+ * Holds the incoming CSS rules.
+ */
+ private Reader reader;
+
+ /**
+ * Set to true when the first non @ rule is encountered.
+ */
+ private boolean encounteredRuleSet;
+
+ /**
+ * The call back used to parse.
+ */
+ private CSSParser.CSSParserCallback callback;
+
+ /**
+ * nextToken() inserts the string here.
+ */
+ private char[] tokenBuffer;
+
+ /**
+ * Current number of chars in tokenBufferLength.
+ */
+ private int tokenBufferLength;
+
+ /**
+ * Set to true if any whitespace is read.
+ */
+ private boolean readWS;
+
+ /**
+ * Constructor
+ */
+ CSSParser()
+ {
+ unitBuffer = new StringBuffer();
+ tokenBuffer = new char[10];
+ }
+
+ /**
+ * Appends a character to the token buffer.
+ *
+ * @param c - the character to append
+ */
+ private void append(char c)
+ {
+ if (tokenBuffer.length >= tokenBufferLength)
+ {
+ char[] temp = new char[tokenBufferLength * 2];
+ if (tokenBuffer != null)
+ System.arraycopy(tokenBuffer, 0, temp, 0, tokenBufferLength);
+
+ temp[tokenBufferLength] = c;
+ tokenBuffer = temp;
+ }
+ else
+ tokenBuffer[tokenBufferLength] = c;
+ tokenBufferLength++;
+ }
+
+ /**
+ * Fetches the next token.
+ *
+ * @param c - the character to fetch.
+ * @return the location
+ * @throws IOException - any i/o error encountered while reading
+ */
+ private int nextToken(char c) throws IOException
+ {
+ readWS = false;
+ int next = readWS();
+
+ switch (next)
+ {
+ case '\"':
+ if (tokenBufferLength > 0)
+ tokenBufferLength--;
+ return IDENTIFIER;
+ case '\'':
+ if (tokenBufferLength > 0)
+ tokenBufferLength--;
+ return IDENTIFIER;
+ case '(':
+ return PAREN_OPEN;
+ case ')':
+ return PAREN_CLOSE;
+ case '{':
+ return BRACE_OPEN;
+ case '}':
+ return BRACE_CLOSE;
+ case '[':
+ return BRACKET_OPEN;
+ case ']':
+ return BRACKET_CLOSE;
+ case -1:
+ return END;
+ default:
+ pushChar(next);
+ getIdentifier(c);
+ return IDENTIFIER;
+ }
+ }
+
+ /**
+ * Reads a character from the stream.
+ *
+ * @return the number of characters read or -1 if end of stream is reached.
+ * @throws IOException - any i/o encountered while reading
+ */
+ private int readChar() throws IOException
+ {
+ if (didPushChar)
+ {
+ didPushChar = false;
+ return pushedChar;
+ }
+ return reader.read();
+ }
+
+ /**
+ * Parses the the contents of the reader using the
+ * callback.
+ *
+ * @param reader - the reader to read from
+ * @param callback - the callback instance
+ * @param parsingDeclaration - true if parsing a declaration
+ * @throws IOException - any i/o error from the reader
+ */
+ void parse(Reader reader, CSSParser.CSSParserCallback callback,
+ boolean parsingDeclaration)
+ throws IOException
+ {
+ this.reader = reader;
+ this.callback = callback;
+
+ try
+ {
+ if (!parsingDeclaration)
+ while(getNextStatement());
+ else
+ parseDeclarationBlock();
+ }
+ catch (IOException ioe)
+ {
+ // Nothing to do here.
+ }
+ }
+
+ /**
+ * Skips any white space, returning the character after the white space.
+ *
+ * @return the character after the whitespace
+ * @throws IOException - any i/o error from the reader
+ */
+ private int readWS() throws IOException
+ {
+ int next = readChar();
+ while (Character.isWhitespace((char) next))
+ {
+ readWS = true;
+ int tempNext = readChar();
+ if (tempNext == END)
+ return next;
+ next = tempNext;
+ }
+
+ // Its all whitespace
+ return END;
+ }
+
+ /**
+ * Gets the next statement, returning false if the end is reached.
+ * A statement is either an At-rule, or a ruleset.
+ *
+ * @return false if the end is reached
+ * @throws IOException - any i/o error from the reader
+ */
+ private boolean getNextStatement() throws IOException
+ {
+ int c = nextToken((char) 0);
+ switch (c)
+ {
+ case PAREN_OPEN:
+ case BRACE_OPEN:
+ case BRACKET_OPEN:
+ parseTillClosed(c);
+ break;
+ case BRACKET_CLOSE:
+ case BRACE_CLOSE:
+ case PAREN_CLOSE:
+ throw new IOException("Not a proper statement.");
+ case IDENTIFIER:
+ if (tokenBuffer[0] == ('@'))
+ parseAtRule();
+ else
+ parseRuleSet();
+ break;
+ case END:
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Parses an @ rule, stopping at a matching brace pair, or ;.
+ *
+ * @throws IOException - any i/o error from the reader
+ */
+ private void parseAtRule() throws IOException
+ {
+ // An At-Rule begins with the "@" character followed immediately by a keyword.
+ // Following the keyword separated by a space is an At-rule statement appropriate
+ // to the At-keyword used. If the At-Rule is a simple declarative statement
+ // (charset, import, fontdef), it is terminated by a semi-colon (";".)
+ // If the At-Rule is a conditional or informative statement (media, page, font-face),
+ // it is followed by optional arguments and then a style declaration block inside matching
+ // curly braces ("{", "}".) At-Rules are sometimes nestable, depending on the context.
+ // If any part of an At-Rule is not understood, it should be ignored.
+
+ // FIXME: Not Implemented
+ // call handleimport
+ }
+
+ /**
+ * Parses the next rule set, which is a selector followed by a declaration
+ * block.
+ *
+ * @throws IOException - any i/o error from the reader
+ */
+ private void parseRuleSet() throws IOException
+ {
+ // call parseDeclarationBlock
+ // call parse selectors
+ // call parse identifiers
+ // call startrule/endrule
+ // FIXME: Not Implemented
+ }
+
+ /**
+ * Parses a set of selectors, returning false if the end of the stream is
+ * reached.
+ *
+ * @return false if the end of stream is reached
+ * @throws IOException - any i/o error from the reader
+ */
+ private boolean parseSelectors() throws IOException
+ {
+ // FIXME: Not Implemented
+ // call handleselector
+ return false;
+ }
+
+ /**
+ * Parses a declaration block. Which a number of declarations followed by a
+ * })].
+ *
+ * @throws IOException - any i/o error from the reader
+ */
+ private void parseDeclarationBlock() throws IOException
+ {
+ // call parseDeclaration
+ // FIXME: Not Implemented
+ }
+
+ /**
+ * Parses a single declaration, which is an identifier a : and another identifier.
+ * This returns the last token seen.
+ *
+ * @returns the last token
+ * @throws IOException - any i/o error from the reader
+ */
+ private int parseDeclaration() throws IOException
+ {
+ // call handleValue
+ // FIXME: Not Implemented
+ return 0;
+ }
+
+ /**
+ * Parses identifiers until c is encountered, returning the ending token,
+ * which will be IDENTIFIER if c is found.
+ *
+ * @param c - the stop character
+ * @param wantsBlocks - true if blocks are wanted
+ * @return the ending token
+ * @throws IOException - any i/o error from the reader
+ */
+ private int parseIdentifiers(char c, boolean wantsBlocks) throws IOException
+ {
+ // FIXME: Not implemented
+ // call handleproperty?
+ return 0;
+ }
+
+ /**
+ * Parses till a matching block close is encountered. This is only appropriate
+ * to be called at the top level (no nesting).
+ *
+ * @param i - FIXME
+ * @throws IOException - any i/o error from the reader
+ */
+ private void parseTillClosed(int i) throws IOException
+ {
+ // FIXME: Not Implemented
+ }
+
+ /**
+ * Gets an identifier, returning true if the length of the string is greater
+ * than 0, stopping when c, whitespace, or one of {}()[] is hit.
+ *
+ * @param c - the stop character
+ * @return returns true if the length of the string > 0
+ * @throws IOException - any i/o error from the reader
+ */
+ private boolean getIdentifier(char c) throws IOException
+ {
+ // FIXME: Not Implemented
+ return false;
+ }
+
+ /**
+ * Reads till c is encountered, escaping characters as necessary.
+ *
+ * @param c - the stop character
+ * @throws IOException - any i/o error from the reader
+ */
+ private void readTill(char c) throws IOException
+ {
+ // FIXME: Not Implemented
+ }
+
+ /**
+ * Parses a comment block.
+ *
+ * @throws IOException - any i/o error from the reader
+ */
+ private void readComment() throws IOException
+ {
+ // Should ignore comments. Read until end of comment.
+ // FIXME: Not implemented
+ }
+
+ /**
+ * Called when a block start is encountered ({[.
+ *
+ * @param start of block
+ */
+ private void startBlock(int start)
+ {
+ // FIXME: Not Implemented
+ }
+
+ /**
+ * Called when an end block is encountered )]}
+ *
+ * @param end of block
+ */
+ private void endBlock(int end)
+ {
+ // FIXME: Not Implemented
+ }
+
+ /**
+ * Checks if currently in a block.
+ *
+ * @return true if currently in a block.
+ */
+ private boolean inBlock()
+ {
+ // FIXME: Not Implemented
+ return false;
+ }
+
+ /**
+ * Supports one character look ahead, this will throw if called twice in a row.
+ *
+ * @param c - the character to push.
+ * @throws IOException - if called twice in a row
+ */
+ private void pushChar(int c) throws IOException
+ {
+ if (didPushChar)
+ throw new IOException("pushChar called twice.");
+ didPushChar = true;
+ pushedChar = c;
+ }
+}
+
+
\ No newline at end of file
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/FormView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/FormView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/FormView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/FormView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,275 @@
+/* FormView.java -- A view for a variety of HTML form elements
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import java.awt.Component;
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JPasswordField;
+import javax.swing.JRadioButton;
+import javax.swing.JTextField;
+import javax.swing.UIManager;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.ComponentView;
+import javax.swing.text.Element;
+import javax.swing.text.StyleConstants;
+
+/**
+ * A View that renders HTML form elements like buttons and input fields.
+ * This is implemented as a {@link ComponentView} that creates different Swing
+ * component depending on the type and setting of the different form elements.
+ *
+ * Namely, this view creates the following components:
+ * <table>
+ * <tr><th>Element type</th><th>Swing component</th></tr>
+ * <tr><td>input, button</td><td>JButton</td></tr>
+ * <tr><td>input, checkbox</td><td>JButton</td></tr>
+ * <tr><td>input, image</td><td>JButton</td></tr>
+ * <tr><td>input, password</td><td>JButton</td></tr>
+ * <tr><td>input, radio</td><td>JButton</td></tr>
+ * <tr><td>input, reset</td><td>JButton</td></tr>
+ * <tr><td>input, submit</td><td>JButton</td></tr>
+ * <tr><td>input, text</td><td>JButton</td></tr>
+ * <tr><td>select, size > 1 or with multiple attribute</td>
+ * <td>JList in JScrollPane</td></tr>
+ * <tr><td>select, size unspecified or == 1</td><td>JComboBox</td></tr>
+ * <tr><td>textarea, text</td><td>JTextArea in JScrollPane</td></tr>
+ * <tr><td>input, file</td><td>JTextField</td></tr>
+ * </table>
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+public class FormView
+ extends ComponentView
+ implements ActionListener
+{
+
+ protected class MouseEventListener
+ extends MouseAdapter
+ {
+ /**
+ * Creates a new <code>MouseEventListener</code>.
+ */
+ protected MouseEventListener()
+ {
+ // Nothing to do here.
+ }
+
+ public void mouseReleased(MouseEvent ev)
+ {
+ String data = getImageData(ev.getPoint());
+ imageSubmit(data);
+ }
+ }
+
+ /**
+ * If the value attribute of an <code><input type="submit">>
+ * tag is not specified, then this string is used.
+ *
+ * @deprecated As of JDK1.3 the value is fetched from the UIManager property
+ * <code>FormView.submitButtonText</code>.
+ */
+ public static final String SUBMIT =
+ UIManager.getString("FormView.submitButtonText");
+
+ /**
+ * If the value attribute of an <code><input type="reset">>
+ * tag is not specified, then this string is used.
+ *
+ * @deprecated As of JDK1.3 the value is fetched from the UIManager property
+ * <code>FormView.resetButtonText</code>.
+ */
+ public static final String RESET =
+ UIManager.getString("FormView.resetButtonText");
+
+ /**
+ * Creates a new <code>FormView</code>.
+ *
+ * @param el the element that is displayed by this view.
+ */
+ public FormView(Element el)
+ {
+ super(el);
+ }
+
+ /**
+ * Creates the correct AWT component for rendering the form element.
+ */
+ protected Component createComponent()
+ {
+ Component comp = null;
+ Element el = getElement();
+ Object tag = el.getAttributes().getAttribute(StyleConstants.NameAttribute);
+ if (tag.equals(HTML.Tag.INPUT))
+ {
+ AttributeSet atts = el.getAttributes();
+ String type = (String) atts.getAttribute(HTML.Attribute.TYPE);
+ String value = (String) atts.getAttribute(HTML.Attribute.VALUE);
+ if (type.equals("button"))
+ comp = new JButton(value);
+ else if (type.equals("checkbox"))
+ comp = new JCheckBox(value);
+ else if (type.equals("image"))
+ comp = new JButton(value); // FIXME: Find out how to fetch the image.
+ else if (type.equals("password"))
+ comp = new JPasswordField(value);
+ else if (type.equals("radio"))
+ comp = new JRadioButton(value);
+ else if (type.equals("reset"))
+ {
+ if (value == null || value.equals(""))
+ value = RESET;
+ comp = new JButton(value);
+ }
+ else if (type.equals("submit"))
+ {
+ if (value == null || value.equals(""))
+ value = SUBMIT;
+ comp = new JButton(value);
+ }
+ else if (type.equals("text"))
+ comp = new JTextField(value);
+
+ }
+ // FIXME: Implement the remaining components.
+ return comp;
+ }
+
+ /**
+ * Determines the maximum span for this view on the specified axis.
+ *
+ * @param axis the axis along which to determine the span
+ *
+ * @return the maximum span for this view on the specified axis
+ *
+ * @throws IllegalArgumentException if the axis is invalid
+ */
+ public float getMaximumSpan(int axis)
+ {
+ // FIXME: The specs say that for some components the maximum span == the
+ // preferred span of the component. This should be figured out and
+ // implemented accordingly.
+ float span;
+ if (axis == X_AXIS)
+ span = getComponent().getMaximumSize().width;
+ else if (axis == Y_AXIS)
+ span = getComponent().getMaximumSize().height;
+ else
+ throw new IllegalArgumentException("Invalid axis parameter");
+ return span;
+ }
+
+ /**
+ * Processes an action from the Swing component.
+ *
+ * If the action comes from a submit button, the form is submitted by calling
+ * {@link #submitData}. In the case of a reset button, the form is reset to
+ * the original state. If the action comes from a password or text field,
+ * then the input focus is transferred to the next input element in the form,
+ * unless this text/password field is the last one, in which case the form
+ * is submitted.
+ *
+ * @param ev the action event
+ */
+ public void actionPerformed(ActionEvent ev)
+ {
+ Element el = getElement();
+ Object tag = el.getAttributes().getAttribute(StyleConstants.NameAttribute);
+ if (tag.equals(HTML.Tag.INPUT))
+ {
+ AttributeSet atts = el.getAttributes();
+ String type = (String) atts.getAttribute(HTML.Attribute.TYPE);
+ if (type.equals("submit"))
+ submitData(""); // FIXME: How to fetch the actual form data?
+ }
+ // FIXME: Implement the remaining actions.
+ }
+
+ /**
+ * Submits the form data. A separate thread is created to do the
+ * transmission.
+ *
+ * @param data the form data
+ */
+ protected void submitData(String data)
+ {
+ // FIXME: Implement this.
+ }
+
+ /**
+ * Submits the form data in response to a click on a
+ * <code><input type="image"></code> element.
+ *
+ * @param imageData the mouse click coordinates
+ */
+ protected void imageSubmit(String imageData)
+ {
+ // FIXME: Implement this.
+ }
+
+ /**
+ * Determines the image data that should be submitted in response to a
+ * mouse click on a image. This is either 'x=<p.x>&y=<p.y>' if the name
+ * attribute of the element is null or '' or
+ * <name>.x=<p.x>&<name>.y=<p.y>' when the name attribute is not empty.
+ *
+ * @param p the coordinates of the mouseclick
+ */
+ String getImageData(Point p)
+ {
+ String name = (String) getElement().getAttributes()
+ .getAttribute(HTML.Attribute.NAME);
+ String data;
+ if (name == null || name.equals(""))
+ {
+ data = "x=" + p.x + "&y=" + p.y;
+ }
+ else
+ {
+ data = name + ".x=" + p.x + "&" + name + ".y=" + p.y;
+ }
+ return data;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HRuleView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HRuleView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HRuleView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HRuleView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,189 @@
+/* HRuleView.java -- Horizontal dash in HTML documents.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.Shape;
+
+import javax.swing.text.Element;
+import javax.swing.text.View;
+
+/**
+ * Represents the long horizontal separating dash that can be inserted into the
+ * HTML documents with HR tag.
+ */
+class HRuleView extends InlineView
+{
+ /**
+ * The null view, indicating, that nothing should be painted ahead the
+ * breaking point.
+ */
+ View nullView;
+
+ /**
+ * The height of the horizontal dash area.
+ */
+ static int HEIGHT = 4;
+
+ /**
+ * The imaginary invisible view that stays after end of line after the
+ * breaking procedure. It occupies on character.
+ */
+ class Beginning extends NullView
+ {
+ /**
+ * The break offset that becomes the views start offset.
+ */
+ int breakOffset;
+
+ /**
+ * Return the end offset that is always one char after the break offset.
+ */
+ public int getEndOffset()
+ {
+ return breakOffset + 1;
+ }
+
+ /**
+ * Return the start offset that has been passed in a constructor.
+ */
+ public int getStartOffset()
+ {
+ return breakOffset;
+ }
+
+ /**
+ * Create the new instance of this view.
+ *
+ * @param element the element (inherited from the HR view)
+ * @param offset the position where the HR view has been broken
+ */
+ public Beginning(Element element, int offset)
+ {
+ super(element);
+ breakOffset = offset;
+ }
+ }
+
+ /**
+ * Creates the new HR view.
+ */
+ public HRuleView(Element element)
+ {
+ super(element);
+ }
+
+ /**
+ * Returns the ForcedBreakWeight for the vertical axis, indicating, the the
+ * view must be broken to be displayed correctly. The horizontal dash is
+ * not breakeable along the Y axis.
+ */
+ public int getBreakWeight(int axis, float pos, float len)
+ {
+ if (axis == X_AXIS && ((getEndOffset() - getStartOffset()) > 1))
+ return ForcedBreakWeight;
+ else
+ return BadBreakWeight;
+ }
+
+ /**
+ * Draws the double line, upped black and the lower light gray.
+ */
+ public void paint(Graphics g, Shape a)
+ {
+ Rectangle bounds = a.getBounds();
+
+ int x = bounds.x;
+ int y = bounds.y;
+
+ int w = bounds.x + bounds.width;
+
+ // We move "half pixel up" from the actual horizontal position -
+ // this will be rounded to the closest actual int co-ordinate.
+ int h = bounds.y + (int) Math.round(bounds.height * 0.5 - 0.5);
+
+ g.setColor(Color.black);
+ g.drawLine(x, y++, w, h++);
+ g.setColor(Color.lightGray);
+ g.drawLine(x, y, w, h);
+ }
+
+ /**
+ * Break the view into this view and the invisible imaginary view that
+ * stays on the end of line that is broken by HR dash. The view is broken
+ * only if its length is longer than one (the two characters are expected
+ * in the initial length).
+ */
+ public View breakView(int axis, int offset, float pos, float len)
+ {
+ if (getEndOffset() - getStartOffset() > 1)
+ return new Beginning(getElement(), offset);
+ else
+ return this;
+ }
+
+ /**
+ * Returns the width of the container for the horizontal axis and the
+ * thickness of the dash area for the vertical axis.
+ */
+ public float getMaximumSpan(int axis)
+ {
+ if (axis == X_AXIS)
+ {
+ Component container = getContainer();
+ if (container != null)
+ return getContainer().getWidth();
+ else
+ return 640;
+ }
+ else
+ return HEIGHT;
+ }
+
+ /**
+ * Returns the same values as {@link #getMaximumSpan(int)}
+ */
+ public float getPreferredSpan(int axis)
+ {
+ return getMaximumSpan(axis);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTML.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTML.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTML.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTML.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1243 @@
+/* HTML.java -- HTML document tag constants
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import java.io.Serializable;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.swing.text.AttributeSet;
+
+/**
+ * HTML attribute and tag definitions.
+ * @author Audrius Meskauskas (AudriusA at Bioinformatics.org)
+ */
+public class HTML
+{
+ /**
+ * Represents a HTML attribute.
+ */
+ public static final class Attribute
+ {
+ /**
+ * The action attribute
+ */
+ public static final Attribute ACTION = new Attribute("action");
+
+ /**
+ * The align attribute
+ */
+ public static final Attribute ALIGN = new Attribute("align");
+
+ /**
+ * The alink attribute
+ */
+ public static final Attribute ALINK = new Attribute("alink");
+
+ /**
+ * The alt attribute
+ */
+ public static final Attribute ALT = new Attribute("alt");
+
+ /**
+ * The archive attribute
+ */
+ public static final Attribute ARCHIVE = new Attribute("archive");
+
+ /**
+ * The background attribute
+ */
+ public static final Attribute BACKGROUND = new Attribute("background");
+
+ /**
+ * The bgcolor attribute
+ */
+ public static final Attribute BGCOLOR = new Attribute("bgcolor");
+
+ /**
+ * The border attribute
+ */
+ public static final Attribute BORDER = new Attribute("border");
+
+ /**
+ * The cellpadding attribute
+ */
+ public static final Attribute CELLPADDING = new Attribute("cellpadding");
+
+ /**
+ * The cellspacing attribute
+ */
+ public static final Attribute CELLSPACING = new Attribute("cellspacing");
+
+ /**
+ * The checked attribute
+ */
+ public static final Attribute CHECKED = new Attribute("checked");
+
+ /**
+ * The class attribute
+ */
+ public static final Attribute CLASS = new Attribute("class");
+
+ /**
+ * The classid attribute
+ */
+ public static final Attribute CLASSID = new Attribute("classid");
+
+ /**
+ * The clear attribute
+ */
+ public static final Attribute CLEAR = new Attribute("clear");
+
+ /**
+ * The code attribute
+ */
+ public static final Attribute CODE = new Attribute("code");
+
+ /**
+ * The codebase attribute
+ */
+ public static final Attribute CODEBASE = new Attribute("codebase");
+
+ /**
+ * The codetype attribute
+ */
+ public static final Attribute CODETYPE = new Attribute("codetype");
+
+ /**
+ * The color attribute
+ */
+ public static final Attribute COLOR = new Attribute("color");
+
+ /**
+ * The cols attribute
+ */
+ public static final Attribute COLS = new Attribute("cols");
+
+ /**
+ * The colspan attribute
+ */
+ public static final Attribute COLSPAN = new Attribute("colspan");
+
+ /**
+ * The comment attribute
+ */
+ public static final Attribute COMMENT = new Attribute("comment");
+
+ /**
+ * The compact attribute
+ */
+ public static final Attribute COMPACT = new Attribute("compact");
+
+ /**
+ * The content attribute
+ */
+ public static final Attribute CONTENT = new Attribute("content");
+
+ /**
+ * The coords attribute
+ */
+ public static final Attribute COORDS = new Attribute("coords");
+
+ /**
+ * The data attribute
+ */
+ public static final Attribute DATA = new Attribute("data");
+
+ /**
+ * The declare attribute
+ */
+ public static final Attribute DECLARE = new Attribute("declare");
+
+ /**
+ * The dir attribute
+ */
+ public static final Attribute DIR = new Attribute("dir");
+
+ /**
+ * The dummy attribute
+ */
+ public static final Attribute DUMMY = new Attribute("dummy");
+
+ /**
+ * The enctype attribute
+ */
+ public static final Attribute ENCTYPE = new Attribute("enctype");
+
+ /**
+ * The endtag attribute
+ */
+ public static final Attribute ENDTAG = new Attribute("endtag");
+
+ /**
+ * The face attribute
+ */
+ public static final Attribute FACE = new Attribute("face");
+
+ /**
+ * The frameborder attribute
+ */
+ public static final Attribute FRAMEBORDER = new Attribute("frameborder");
+
+ /**
+ * The halign attribute
+ */
+ public static final Attribute HALIGN = new Attribute("halign");
+
+ /**
+ * The height attribute
+ */
+ public static final Attribute HEIGHT = new Attribute("height");
+
+ /**
+ * The href attribute
+ */
+ public static final Attribute HREF = new Attribute("href");
+
+ /**
+ * The hspace attribute
+ */
+ public static final Attribute HSPACE = new Attribute("hspace");
+
+ /**
+ * The http-equiv attribute
+ */
+ public static final Attribute HTTPEQUIV = new Attribute("http-equiv");
+
+ /**
+ * The id attribute
+ */
+ public static final Attribute ID = new Attribute("id");
+
+ /**
+ * The ismap attribute
+ */
+ public static final Attribute ISMAP = new Attribute("ismap");
+
+ /**
+ * The lang attribute
+ */
+ public static final Attribute LANG = new Attribute("lang");
+
+ /**
+ * The language attribute
+ */
+ public static final Attribute LANGUAGE = new Attribute("language");
+
+ /**
+ * The link attribute
+ */
+ public static final Attribute LINK = new Attribute("link");
+
+ /**
+ * The lowsrc attribute
+ */
+ public static final Attribute LOWSRC = new Attribute("lowsrc");
+
+ /**
+ * The marginheight attribute
+ */
+ public static final Attribute MARGINHEIGHT = new Attribute("marginheight");
+
+ /**
+ * The marginwidth attribute
+ */
+ public static final Attribute MARGINWIDTH = new Attribute("marginwidth");
+
+ /**
+ * The maxlength attribute
+ */
+ public static final Attribute MAXLENGTH = new Attribute("maxlength");
+
+ /**
+ * The media attribute
+ */
+ static final Attribute MEDIA = new Attribute("media");
+
+ /**
+ * The method attribute
+ */
+ public static final Attribute METHOD = new Attribute("method");
+
+ /**
+ * The multiple attribute
+ */
+ public static final Attribute MULTIPLE = new Attribute("multiple");
+
+ /**
+ * The n attribute
+ */
+ public static final Attribute N = new Attribute("n");
+
+ /**
+ * The name attribute
+ */
+ public static final Attribute NAME = new Attribute("name");
+
+ /**
+ * The nohref attribute
+ */
+ public static final Attribute NOHREF = new Attribute("nohref");
+
+ /**
+ * The noresize attribute
+ */
+ public static final Attribute NORESIZE = new Attribute("noresize");
+
+ /**
+ * The noshade attribute
+ */
+ public static final Attribute NOSHADE = new Attribute("noshade");
+
+ /**
+ * The nowrap attribute
+ */
+ public static final Attribute NOWRAP = new Attribute("nowrap");
+
+ /**
+ * The prompt attribute
+ */
+ public static final Attribute PROMPT = new Attribute("prompt");
+
+ /**
+ * The rel attribute
+ */
+ public static final Attribute REL = new Attribute("rel");
+
+ /**
+ * The rev attribute
+ */
+ public static final Attribute REV = new Attribute("rev");
+
+ /**
+ * The rows attribute
+ */
+ public static final Attribute ROWS = new Attribute("rows");
+
+ /**
+ * The rowspan attribute
+ */
+ public static final Attribute ROWSPAN = new Attribute("rowspan");
+
+ /**
+ * The scrolling attribute
+ */
+ public static final Attribute SCROLLING = new Attribute("scrolling");
+
+ /**
+ * The selected attribute
+ */
+ public static final Attribute SELECTED = new Attribute("selected");
+
+ /**
+ * The shape attribute
+ */
+ public static final Attribute SHAPE = new Attribute("shape");
+
+ /**
+ * The shapes attribute
+ */
+ public static final Attribute SHAPES = new Attribute("shapes");
+
+ /**
+ * The size attribute
+ */
+ public static final Attribute SIZE = new Attribute("size");
+
+ /**
+ * The src attribute
+ */
+ public static final Attribute SRC = new Attribute("src");
+
+ /**
+ * The standby attribute
+ */
+ public static final Attribute STANDBY = new Attribute("standby");
+
+ /**
+ * The start attribute
+ */
+ public static final Attribute START = new Attribute("start");
+
+ /**
+ * The style attribute
+ */
+ public static final Attribute STYLE = new Attribute("style");
+
+ /**
+ * The target attribute
+ */
+ public static final Attribute TARGET = new Attribute("target");
+
+ /**
+ * The text attribute
+ */
+ public static final Attribute TEXT = new Attribute("text");
+
+ /**
+ * The title attribute
+ */
+ public static final Attribute TITLE = new Attribute("title");
+
+ /**
+ * The type attribute
+ */
+ public static final Attribute TYPE = new Attribute("type");
+
+ /**
+ * The usemap attribute
+ */
+ public static final Attribute USEMAP = new Attribute("usemap");
+
+ /**
+ * The valign attribute
+ */
+ public static final Attribute VALIGN = new Attribute("valign");
+
+ /**
+ * The value attribute
+ */
+ public static final Attribute VALUE = new Attribute("value");
+
+ /**
+ * The valuetype attribute
+ */
+ public static final Attribute VALUETYPE = new Attribute("valuetype");
+
+ /**
+ * The version attribute
+ */
+ public static final Attribute VERSION = new Attribute("version");
+
+ /**
+ * The vlink attribute
+ */
+ public static final Attribute VLINK = new Attribute("vlink");
+
+ /**
+ * The vspace attribute
+ */
+ public static final Attribute VSPACE = new Attribute("vspace");
+
+ /**
+ * The width attribute
+ */
+ public static final Attribute WIDTH = new Attribute("width");
+
+ /**
+ * The attribute name.
+ */
+ private final String name;
+
+ /**
+ * Creates the attribute with the given name.
+ */
+ private Attribute(String a_name)
+ {
+ name = a_name;
+ }
+
+ /**
+ * Returns the attribute name. The names of the built-in attributes
+ * are always returned in lowercase.
+ */
+ public String toString()
+ {
+ return name;
+ }
+
+ /**
+ * Return an array of all attributes, declared in the HTML.Attribute
+ * class. WARNING: attributes are the only public fields,
+ * expected in this class.
+ */
+ static Attribute[] getAllAttributes()
+ {
+ Field[] f = Attribute.class.getFields();
+ Attribute[] attrs = new Attribute[ f.length ];
+ Field x;
+ int p = 0;
+ Attribute a;
+
+ for (int i = 0; i < f.length; i++)
+ {
+ x = f [ i ];
+
+ if ((x.getModifiers() & Modifier.STATIC) != 0)
+ {
+ if (x.getType().equals(Attribute.class))
+ {
+ try
+ {
+ a = (Attribute) x.get(null);
+ attrs [ p++ ] = a;
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace(System.err);
+ throw new Error("This should never happen, report a bug");
+ }
+ }
+ }
+ }
+
+ return attrs;
+ }
+ }
+
+ /**
+ * Represents a HTML tag.
+ */
+ public static class Tag
+ {
+ /**
+ * The <a> tag
+ */
+ public static final Tag A = new Tag("a");
+
+ /**
+ * The <address> tag
+ */
+ public static final Tag ADDRESS = new Tag("address");
+
+ /**
+ * The <applet> tag
+ */
+ public static final Tag APPLET = new Tag("applet");
+
+ /**
+ * The <area> tag
+ */
+ public static final Tag AREA = new Tag("area");
+
+ /**
+ * The <b> tag
+ */
+ public static final Tag B = new Tag("b");
+
+ /**
+ * The <base> tag
+ */
+ public static final Tag BASE = new Tag("base");
+
+ /**
+ * The <basefont> tag
+ */
+ public static final Tag BASEFONT = new Tag("basefont");
+
+ /**
+ * The <big> tag
+ */
+ public static final Tag BIG = new Tag("big");
+
+ /**
+ * The <blockquote> tag , breaks flow, block tag.
+ */
+ public static final Tag BLOCKQUOTE = new Tag("blockquote", BREAKS | BLOCK);
+
+ /**
+ * The <body> tag , breaks flow, block tag.
+ */
+ public static final Tag BODY = new Tag("body", BREAKS | BLOCK);
+
+ /**
+ * The <br> tag , breaks flow.
+ */
+ public static final Tag BR = new Tag("br", BREAKS);
+
+ /**
+ * The <caption> tag
+ */
+ public static final Tag CAPTION = new Tag("caption");
+
+ /**
+ * The <center> tag , breaks flow.
+ */
+ public static final Tag CENTER = new Tag("center", BREAKS);
+
+ /**
+ * The <cite> tag
+ */
+ public static final Tag CITE = new Tag("cite");
+
+ /**
+ * The <code> tag
+ */
+ public static final Tag CODE = new Tag("code");
+
+ /**
+ * The <dd> tag , breaks flow, block tag.
+ */
+ public static final Tag DD = new Tag("dd", BREAKS | BLOCK);
+
+ /**
+ * The <dfn> tag
+ */
+ public static final Tag DFN = new Tag("dfn");
+
+ /**
+ * The <dir> tag , breaks flow, block tag.
+ */
+ public static final Tag DIR = new Tag("dir", BREAKS | BLOCK);
+
+ /**
+ * The <div> tag , breaks flow, block tag.
+ */
+ public static final Tag DIV = new Tag("div", BREAKS | BLOCK);
+
+ /**
+ * The <dl> tag , breaks flow, block tag.
+ */
+ public static final Tag DL = new Tag("dl", BREAKS | BLOCK);
+
+ /**
+ * The <dt> tag , breaks flow, block tag.
+ */
+ public static final Tag DT = new Tag("dt", BREAKS | BLOCK);
+
+ /**
+ * The <em> tag
+ */
+ public static final Tag EM = new Tag("em");
+
+ /**
+ * The <font> tag
+ */
+ public static final Tag FONT = new Tag("font");
+
+ /**
+ * The <form> tag , breaks flow.
+ */
+ public static final Tag FORM = new Tag("form", BREAKS);
+
+ /**
+ * The <frame> tag
+ */
+ public static final Tag FRAME = new Tag("frame");
+
+ /**
+ * The <frameset> tag
+ */
+ public static final Tag FRAMESET = new Tag("frameset");
+
+ /**
+ * The <h1> tag , breaks flow, block tag.
+ */
+ public static final Tag H1 = new Tag("h1", BREAKS | BLOCK);
+
+ /**
+ * The <h2> tag , breaks flow, block tag.
+ */
+ public static final Tag H2 = new Tag("h2", BREAKS | BLOCK);
+
+ /**
+ * The <h3> tag , breaks flow, block tag.
+ */
+ public static final Tag H3 = new Tag("h3", BREAKS | BLOCK);
+
+ /**
+ * The <h4> tag , breaks flow, block tag.
+ */
+ public static final Tag H4 = new Tag("h4", BREAKS | BLOCK);
+
+ /**
+ * The <h5> tag , breaks flow, block tag.
+ */
+ public static final Tag H5 = new Tag("h5", BREAKS | BLOCK);
+
+ /**
+ * The <h6> tag , breaks flow, block tag.
+ */
+ public static final Tag H6 = new Tag("h6", BREAKS | BLOCK);
+
+ /**
+ * The <head> tag , breaks flow, block tag.
+ */
+ public static final Tag HEAD = new Tag("head", BREAKS | BLOCK);
+
+ /**
+ * The <hr> tag , breaks flow.
+ */
+ public static final Tag HR = new Tag("hr", BREAKS);
+
+ /**
+ * The <html> tag , breaks flow.
+ */
+ public static final Tag HTML = new Tag("html", BREAKS);
+
+ /**
+ * The <i> tag
+ */
+ public static final Tag I = new Tag("i");
+
+ /**
+ * The <img> tag
+ */
+ public static final Tag IMG = new Tag("img");
+
+ /**
+ * The <input> tag
+ */
+ public static final Tag INPUT = new Tag("input");
+
+ /**
+ * The <isindex> tag , breaks flow.
+ */
+ public static final Tag ISINDEX = new Tag("isindex", BREAKS);
+
+ /**
+ * The <kbd> tag
+ */
+ public static final Tag KBD = new Tag("kbd");
+
+ /**
+ * The <li> tag , breaks flow, block tag.
+ */
+ public static final Tag LI = new Tag("li", BREAKS | BLOCK);
+
+ /**
+ * The <link> tag
+ */
+ public static final Tag LINK = new Tag("link");
+
+ /**
+ * The <map> tag
+ */
+ public static final Tag MAP = new Tag("map");
+
+ /**
+ * The <menu> tag , breaks flow, block tag.
+ */
+ public static final Tag MENU = new Tag("menu", BREAKS | BLOCK);
+
+ /**
+ * The <meta> tag
+ */
+ public static final Tag META = new Tag("meta");
+
+ /**
+ * The <nobr> tag
+ */
+ static final Tag NOBR = new Tag("nobr");
+
+ /**
+ * The <noframes> tag , breaks flow, block tag.
+ */
+ public static final Tag NOFRAMES = new Tag("noframes", BREAKS | BLOCK);
+
+ /**
+ * The <object> tag
+ */
+ public static final Tag OBJECT = new Tag("object");
+
+ /**
+ * The <ol> tag , breaks flow, block tag.
+ */
+ public static final Tag OL = new Tag("ol", BREAKS | BLOCK);
+
+ /**
+ * The <option> tag
+ */
+ public static final Tag OPTION = new Tag("option");
+
+ /**
+ * The <p> tag , breaks flow, block tag.
+ */
+ public static final Tag P = new Tag("p", BREAKS | BLOCK);
+
+ /**
+ * The <param> tag
+ */
+ public static final Tag PARAM = new Tag("param");
+
+ /**
+ * The <pre> tag , breaks flow, block tag, preformatted.
+ */
+ public static final Tag PRE = new Tag("pre", BREAKS | BLOCK | PREFORMATTED);
+
+ /**
+ * The <s> tag
+ */
+ public static final Tag S = new Tag("s");
+
+ /**
+ * The <samp> tag
+ */
+ public static final Tag SAMP = new Tag("samp");
+
+ /**
+ * The <script> tag
+ */
+ public static final Tag SCRIPT = new Tag("script");
+
+ /**
+ * The <select> tag
+ */
+ public static final Tag SELECT = new Tag("select");
+
+ /**
+ * The <small> tag
+ */
+ public static final Tag SMALL = new Tag("small");
+
+ /**
+ * The <span> tag
+ */
+ public static final Tag SPAN = new Tag("span");
+
+ /**
+ * The <strike> tag
+ */
+ public static final Tag STRIKE = new Tag("strike");
+
+ /**
+ * The <strong> tag
+ */
+ public static final Tag STRONG = new Tag("strong");
+
+ /**
+ * The <style> tag
+ */
+ public static final Tag STYLE = new Tag("style");
+
+ /**
+ * The <sub> tag
+ */
+ public static final Tag SUB = new Tag("sub");
+
+ /**
+ * The <sup> tag
+ */
+ public static final Tag SUP = new Tag("sup");
+
+ /**
+ * The <table> tag , block tag.
+ */
+ public static final Tag TABLE = new Tag("table", BLOCK);
+
+ /**
+ * The <td> tag , breaks flow, block tag.
+ */
+ public static final Tag TD = new Tag("td", BREAKS | BLOCK);
+
+ /**
+ * The <textarea> tag , preformatted.
+ */
+ public static final Tag TEXTAREA = new Tag("textarea", PREFORMATTED);
+
+ /**
+ * The <th> tag , breaks flow, block tag.
+ */
+ public static final Tag TH = new Tag("th", BREAKS | BLOCK);
+
+ /**
+ * The <title> tag , breaks flow, block tag.
+ */
+ public static final Tag TITLE = new Tag("title", BREAKS | BLOCK);
+
+ /**
+ * The <tr> tag , block tag.
+ */
+ public static final Tag TR = new Tag("tr", BLOCK);
+
+ /**
+ * The <tt> tag
+ */
+ public static final Tag TT = new Tag("tt");
+
+ /**
+ * The <u> tag
+ */
+ public static final Tag U = new Tag("u");
+
+ /**
+ * The <ul> tag , breaks flow, block tag.
+ */
+ public static final Tag UL = new Tag("ul", BREAKS | BLOCK);
+
+ /**
+ * The <var> tag
+ */
+ public static final Tag VAR = new Tag("var");
+
+ /* Special tags */
+
+ /**
+ * Total number of syntetic tags, delared in the Tag class.
+ * This must be adjusted if the new synthetic tags are declared.
+ * Otherwise the HTML.getAllTags() will not work as expected.
+ */
+ private static final int TOTAL_SYNTHETIC_TAGS = 3;
+
+ /**
+ * All comments are labeled with this tag.
+ * This tag is not included into the array, returned by getAllTags().
+ * toString() returns 'comment'. HTML reader synthesizes this tag.
+ */
+ public static final Tag COMMENT = new Tag("comment", SYNTHETIC);
+
+ /**
+ * All text content is labeled with this tag.
+ * This tag is not included into the array, returned by getAllTags().
+ * toString() returns 'content'. HTML reader synthesizes this tag.
+ */
+ public static final Tag CONTENT = new Tag("content", SYNTHETIC);
+
+ /**
+ * All text content must be in a paragraph element.
+ * If a paragraph didn't exist when content was encountered,
+ * a paragraph is manufactured.
+ * toString() returns 'p-implied'. HTML reader synthesizes this tag.
+ */
+ public static final Tag IMPLIED = new Tag("p-implied", SYNTHETIC);
+ final String name;
+ final int flags;
+
+ /**
+ * Create the unitialised instance of HTML.Tag.
+ *
+ * The {@link #breaksFlow()}, {@link #isBlock()}
+ * and {@link #isPreformatted()} will always return false.
+ * The {@link #toString()} will return <code>null</code>.
+ *
+ * @since 1.3
+ */
+ public Tag()
+ {
+ name = null;
+ flags = 0;
+ }
+
+ /**
+ * Creates a new Tag with the specified id, and with causesBreak
+ * and isBlock set to false.
+ */
+ protected Tag(String id)
+ {
+ name = id;
+ flags = 0;
+ }
+
+ /**
+ * Creates a new Tag with the specified tag name and
+ * causesBreak and isBlock properties.
+ */
+ protected Tag(String id, boolean causesBreak, boolean isBlock)
+ {
+ int f = 0;
+
+ if (causesBreak)
+ {
+ f |= BREAKS;
+ }
+
+ if (isBlock)
+ {
+ f |= BLOCK;
+ }
+
+ flags = f;
+ name = id;
+ }
+
+ /**
+ * Create a tag taking flags.
+ */
+ Tag(String id, int a_flags)
+ {
+ name = id;
+ flags = a_flags;
+ }
+
+ /**
+ * Returns true if this tag is a block tag, which is a tag used to
+ * add structure to a document.
+ */
+ public boolean isBlock()
+ {
+ return (flags & BLOCK) != 0;
+ }
+
+ /**
+ * Returns true if this tag is pre-formatted, which is true if
+ * the tag is either PRE or TEXTAREA
+ */
+ public boolean isPreformatted()
+ {
+ return (flags & PREFORMATTED) != 0;
+ }
+
+ /**
+ * Returns true if this tag causes a line break to the flow of text
+ */
+ public boolean breaksFlow()
+ {
+ return (flags & BREAKS) != 0;
+ }
+
+ /**
+ * Returns the tag name. The names of the built-in tags are always
+ * returned in lowercase.
+ */
+ public String toString()
+ {
+ return name;
+ }
+
+ /**
+ * Return an array of HTML tags, declared in HTML.Tag class.
+ * WARNING: This method expects that the Tags are the only
+ * public fields declared in the Tag class.
+ */
+ static Tag[] getAllTags()
+ {
+ Field[] f = Tag.class.getFields();
+ Field x;
+
+ // The syntetic tags are not included.
+ Tag[] tags = new Tag[ f.length - TOTAL_SYNTHETIC_TAGS ];
+ int p = 0;
+ Tag t;
+
+ for (int i = 0; i < f.length; i++)
+ {
+ x = f [ i ];
+
+ if ((x.getModifiers() & Modifier.STATIC) != 0)
+ {
+ if (x.getType().equals(Tag.class))
+ {
+ try
+ {
+ t = (Tag) x.get(null);
+
+ if (!t.isSyntetic())
+ {
+ tags [ p++ ] = t;
+ }
+ }
+ catch (IllegalAccessException ex)
+ {
+ unexpected(ex);
+ }
+ catch (IllegalArgumentException ex)
+ {
+ unexpected(ex);
+ }
+ }
+ }
+ }
+
+ return tags;
+ }
+
+ /**
+ * Returns true for tags, generated by the html reader
+ * (COMMENT, CONTENT and IMPLIED).
+ */
+ boolean isSyntetic()
+ {
+ return (flags & SYNTHETIC) != 0;
+ }
+
+ private static void unexpected(Exception ex)
+ throws Error
+ {
+ throw new Error("This should never happen, report a bug", ex);
+ }
+ }
+
+ /**
+ * Represents an unknown HTML tag.
+ * @author Mark Wielaard (mark at klomp.org)
+ */
+ public static class UnknownTag
+ extends Tag
+ implements Serializable
+ {
+ private static final long serialVersionUID = -1534369342247250625L;
+
+ /**
+ * Creates a new UnknownTag with the specified name
+ * @param name The tag name.
+ *
+ */
+ public UnknownTag(String name)
+ {
+ super(name);
+ }
+ }
+
+ /**
+ * This value is returned for attributes without value that have no
+ * default value defined in the DTD.
+ */
+ public static final String NULL_ATTRIBUTE_VALUE = "#DEFAULT";
+
+ /* Package level html tag flags */
+ static final int BREAKS = 1;
+ static final int BLOCK = 2;
+ static final int PREFORMATTED = 4;
+ static final int SYNTHETIC = 8;
+ private static Map tagMap;
+ private static Map attrMap;
+
+ /**
+ * The public constructor (does nothing). It it seldom required to have
+ * an instance of this class, because all public fields and methods
+ * are static.
+ */
+ public HTML()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Returns the set of the recognized HTML attributes.
+ */
+ public static HTML.Attribute[] getAllAttributeKeys()
+ {
+ return Attribute.getAllAttributes();
+ }
+
+ /**
+ * Returns the set of actual HTML tags that are recognized by
+ * the default HTML reader. The returned array does not include the
+ * COMMENT, CONTENT and IMPLIED tags.
+ */
+ public static HTML.Tag[] getAllTags()
+ {
+ return Tag.getAllTags();
+ }
+
+ /**
+ * Returns an htl attribute constant for the given attribute name.
+ * @param attName the attribute name, case insensitive
+ */
+ public static Attribute getAttributeKey(String attName)
+ {
+ if (attrMap == null)
+ {
+ // Create the map on demand.
+ attrMap = new TreeMap();
+
+ Attribute[] attrs = getAllAttributeKeys();
+
+ for (int i = 0; i < attrs.length; i++)
+ {
+ attrMap.put(attrs [ i ].toString(), attrs [ i ]);
+ }
+ }
+
+ return (Attribute) attrMap.get(attName.toLowerCase());
+ }
+
+ /**
+ * Searches the value of given attribute in the provided set.
+ * If the value is found (String type expected), tries to parse it as
+ * an integer value. If succeded, returns the obtained integer value.
+ *
+ * For example:<p><code>
+ * SimpleAttributeSet ase = new SimpleAttributeSet();
+ * ase.addAttribute(HTML.getAttributeKey("size"),"222");
+ * System.out.println(
+ * HTML.getIntegerAttributeValue
+ * (ase, HTML.getAttributeKey("size"), 333)); // prints "222"
+ * System.out.println(
+ * HTML.getIntegerAttributeValue
+ * (ase, HTML.getAttributeKey("width"), 333)); // prints "333".
+ * </code></p>
+ *
+ *
+ * @param set The attribute set to search in. If the set contains the
+ * given attribute, it must by a type of String.
+ * @param attribute The html attribute to search in
+ * @param defaultValue The value that is returned if the attribute is not
+ * found in the given set or if the NumberFormatException was thrown
+ * during the parsing.
+ */
+ public static int getIntegerAttributeValue(AttributeSet set,
+ HTML.Attribute attribute,
+ int defaultValue
+ )
+ {
+ Object v = set.getAttribute(attribute);
+
+ if (v == null)
+ {
+ return defaultValue;
+ }
+
+ try
+ {
+ return Integer.parseInt(v.toString().trim());
+ }
+ catch (Exception ex)
+ {
+ return defaultValue;
+ }
+ }
+
+ /**
+ * Returns a HTML tag constant for the given HTML attribute name.
+ * If the tag is unknown, the null is returned.
+ * @param tagName the tag name, case insensitive
+ */
+ public static Tag getTag(String tagName)
+ {
+ if (tagMap == null)
+ {
+ // Create the mao on demand.
+ tagMap = new TreeMap();
+
+ Tag[] tags = getAllTags();
+
+ for (int i = 0; i < tags.length; i++)
+ {
+ tagMap.put(tags [ i ].toString(), tags [ i ]);
+ }
+ }
+
+ return (Tag) tagMap.get(tagName.toLowerCase());
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLDocument.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLDocument.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLDocument.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLDocument.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1731 @@
+/* HTMLDocument.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import gnu.classpath.NotImplementedException;
+import gnu.javax.swing.text.html.CharacterAttributeTranslator;
+import gnu.javax.swing.text.html.parser.htmlAttributeSet;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Stack;
+import java.util.Vector;
+
+import javax.swing.JEditorPane;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.HyperlinkEvent.EventType;
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+import javax.swing.text.ElementIterator;
+import javax.swing.text.GapContent;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.html.HTML.Tag;
+
+/**
+ * Represents the HTML document that is constructed by defining the text and
+ * other components (images, buttons, etc) in HTML language. This class can
+ * becomes the default document for {@link JEditorPane} after setting its
+ * content type to "text/html". HTML document also serves as an intermediate
+ * data structure when it is needed to parse HTML and then obtain the content of
+ * the certain types of tags. This class also has methods for modifying the HTML
+ * content.
+ *
+ * @author Audrius Meskauskas (AudriusA at Bioinformatics.org)
+ * @author Anthony Balkissoon (abalkiss at redhat.com)
+ * @author Lillian Angel (langel at redhat.com)
+ */
+public class HTMLDocument extends DefaultStyledDocument
+{
+ /** A key for document properies. The value for the key is
+ * a Vector of Strings of comments not found in the body.
+ */
+ public static final String AdditionalComments = "AdditionalComments";
+ URL baseURL = null;
+ boolean preservesUnknownTags = true;
+ int tokenThreshold = Integer.MAX_VALUE;
+ HTMLEditorKit.Parser parser;
+ StyleSheet styleSheet;
+ AbstractDocument.Content content;
+
+ /**
+ * Constructs an HTML document using the default buffer size and a default
+ * StyleSheet.
+ */
+ public HTMLDocument()
+ {
+ this(null);
+ }
+
+ /**
+ * Constructs an HTML document with the default content storage
+ * implementation and the specified style/attribute storage mechanism.
+ *
+ * @param styles - the style sheet
+ */
+ public HTMLDocument(StyleSheet styles)
+ {
+ this(new GapContent(BUFFER_SIZE_DEFAULT), styles);
+ }
+
+ /**
+ * Constructs an HTML document with the given content storage implementation
+ * and the given style/attribute storage mechanism.
+ *
+ * @param c - the document's content
+ * @param styles - the style sheet
+ */
+ public HTMLDocument(AbstractDocument.Content c, StyleSheet styles)
+ {
+ this.content = c;
+ if (styles == null)
+ {
+ styles = new StyleSheet();
+ styles.importStyleSheet(getClass().getResource(HTMLEditorKit.
+ DEFAULT_CSS));
+ }
+ this.styleSheet = styles;
+ }
+
+ /**
+ * Gets the style sheet with the document display rules (CSS) that were specified
+ * in the HTML document.
+ *
+ * @return - the style sheet
+ */
+ public StyleSheet getStyleSheet()
+ {
+ return styleSheet;
+ }
+
+ /**
+ * This method creates a root element for the new document.
+ *
+ * @return the new default root
+ */
+ protected AbstractElement createDefaultRoot()
+ {
+ AbstractDocument.AttributeContext ctx = getAttributeContext();
+
+ // Create html element.
+ AttributeSet atts = ctx.getEmptySet();
+ atts = ctx.addAttribute(atts, StyleConstants.NameAttribute, HTML.Tag.HTML);
+ BranchElement html = (BranchElement) createBranchElement(null, atts);
+
+ // Create body element.
+ atts = ctx.getEmptySet();
+ atts = ctx.addAttribute(atts, StyleConstants.NameAttribute, HTML.Tag.BODY);
+ BranchElement body = (BranchElement) createBranchElement(html, atts);
+ html.replace(0, 0, new Element[] { body });
+
+ // Create p element.
+ atts = ctx.getEmptySet();
+ atts = ctx.addAttribute(atts, StyleConstants.NameAttribute, HTML.Tag.P);
+ BranchElement p = (BranchElement) createBranchElement(body, atts);
+ body.replace(0, 0, new Element[] { p });
+
+ // Create an empty leaf element.
+ atts = ctx.getEmptySet();
+ atts = ctx.addAttribute(atts, StyleConstants.NameAttribute,
+ HTML.Tag.CONTENT);
+ Element leaf = createLeafElement(p, atts, 0, 1);
+ p.replace(0, 0, new Element[]{ leaf });
+
+ return html;
+ }
+
+ /**
+ * This method returns an HTMLDocument.RunElement object attached to
+ * parent representing a run of text from p0 to p1. The run has
+ * attributes described by a.
+ *
+ * @param parent - the parent element
+ * @param a - the attributes for the element
+ * @param p0 - the beginning of the range >= 0
+ * @param p1 - the end of the range >= p0
+ *
+ * @return the new element
+ */
+ protected Element createLeafElement(Element parent, AttributeSet a, int p0,
+ int p1)
+ {
+ RunElement el = new RunElement(parent, a, p0, p1);
+ el.addAttribute(StyleConstants.NameAttribute, HTML.Tag.CONTENT);
+ return new RunElement(parent, a, p0, p1);
+ }
+
+ /**
+ * This method returns an HTMLDocument.BlockElement object representing the
+ * attribute set a and attached to parent.
+ *
+ * @param parent - the parent element
+ * @param a - the attributes for the element
+ *
+ * @return the new element
+ */
+ protected Element createBranchElement(Element parent, AttributeSet a)
+ {
+ return new BlockElement(parent, a);
+ }
+
+ /**
+ * Returns the parser used by this HTMLDocument to insert HTML.
+ *
+ * @return the parser used by this HTMLDocument to insert HTML.
+ */
+ public HTMLEditorKit.Parser getParser()
+ {
+ return parser;
+ }
+
+ /**
+ * Sets the parser used by this HTMLDocument to insert HTML.
+ *
+ * @param p the parser to use
+ */
+ public void setParser (HTMLEditorKit.Parser p)
+ {
+ parser = p;
+ }
+ /**
+ * Sets the number of tokens to buffer before trying to display the
+ * Document.
+ *
+ * @param n the number of tokens to buffer
+ */
+ public void setTokenThreshold (int n)
+ {
+ tokenThreshold = n;
+ }
+
+ /**
+ * Returns the number of tokens that are buffered before the document
+ * is rendered.
+ *
+ * @return the number of tokens buffered
+ */
+ public int getTokenThreshold ()
+ {
+ return tokenThreshold;
+ }
+
+ /**
+ * Returns the location against which to resolve relative URLs.
+ * This is the document's URL if the document was loaded from a URL.
+ * If a <code>base</code> tag is found, it will be used.
+ * @return the base URL
+ */
+ public URL getBase()
+ {
+ return baseURL;
+ }
+
+ /**
+ * Sets the location against which to resolve relative URLs.
+ * @param u the new base URL
+ */
+ public void setBase(URL u)
+ {
+ baseURL = u;
+ styleSheet.setBase(u);
+ }
+
+ /**
+ * Returns whether or not the parser preserves unknown HTML tags.
+ * @return true if the parser preserves unknown tags
+ */
+ public boolean getPreservesUnknownTags()
+ {
+ return preservesUnknownTags;
+ }
+
+ /**
+ * Sets the behaviour of the parser when it encounters unknown HTML tags.
+ * @param preservesTags true if the parser should preserve unknown tags.
+ */
+ public void setPreservesUnknownTags(boolean preservesTags)
+ {
+ preservesUnknownTags = preservesTags;
+ }
+
+ /**
+ * An iterator to iterate through LeafElements in the document.
+ */
+ class LeafIterator extends Iterator
+ {
+ HTML.Tag tag;
+ HTMLDocument doc;
+ ElementIterator it;
+
+ public LeafIterator (HTML.Tag t, HTMLDocument d)
+ {
+ doc = d;
+ tag = t;
+ it = new ElementIterator(doc);
+ }
+
+ /**
+ * Return the attributes for the tag associated with this iteartor
+ * @return the AttributeSet
+ */
+ public AttributeSet getAttributes()
+ {
+ if (it.current() != null)
+ return it.current().getAttributes();
+ return null;
+ }
+
+ /**
+ * Get the end of the range for the current occurrence of the tag
+ * being defined and having the same attributes.
+ * @return the end of the range
+ */
+ public int getEndOffset()
+ {
+ if (it.current() != null)
+ return it.current().getEndOffset();
+ return -1;
+ }
+
+ /**
+ * Get the start of the range for the current occurrence of the tag
+ * being defined and having the same attributes.
+ * @return the start of the range (-1 if it can't be found).
+ */
+
+ public int getStartOffset()
+ {
+ if (it.current() != null)
+ return it.current().getStartOffset();
+ return -1;
+ }
+
+ /**
+ * Advance the iterator to the next LeafElement .
+ */
+ public void next()
+ {
+ it.next();
+ while (it.current()!= null && !it.current().isLeaf())
+ it.next();
+ }
+
+ /**
+ * Indicates whether or not the iterator currently represents an occurrence
+ * of the tag.
+ * @return true if the iterator currently represents an occurrence of the
+ * tag.
+ */
+ public boolean isValid()
+ {
+ return it.current() != null;
+ }
+
+ /**
+ * Type of tag for this iterator.
+ */
+ public Tag getTag()
+ {
+ return tag;
+ }
+
+ }
+
+ public void processHTMLFrameHyperlinkEvent(HTMLFrameHyperlinkEvent event)
+ throws NotImplementedException
+ {
+ // TODO: Implement this properly.
+ }
+
+ /**
+ * Gets an iterator for the given HTML.Tag.
+ * @param t the requested HTML.Tag
+ * @return the Iterator
+ */
+ public HTMLDocument.Iterator getIterator (HTML.Tag t)
+ {
+ return new HTMLDocument.LeafIterator(t, this);
+ }
+
+ /**
+ * An iterator over a particular type of tag.
+ */
+ public abstract static class Iterator
+ {
+ /**
+ * Return the attribute set for this tag.
+ * @return the <code>AttributeSet</code> (null if none found).
+ */
+ public abstract AttributeSet getAttributes();
+
+ /**
+ * Get the end of the range for the current occurrence of the tag
+ * being defined and having the same attributes.
+ * @return the end of the range
+ */
+ public abstract int getEndOffset();
+
+ /**
+ * Get the start of the range for the current occurrence of the tag
+ * being defined and having the same attributes.
+ * @return the start of the range (-1 if it can't be found).
+ */
+ public abstract int getStartOffset();
+
+ /**
+ * Move the iterator forward.
+ */
+ public abstract void next();
+
+ /**
+ * Indicates whether or not the iterator currently represents an occurrence
+ * of the tag.
+ * @return true if the iterator currently represents an occurrence of the
+ * tag.
+ */
+ public abstract boolean isValid();
+
+ /**
+ * Type of tag this iterator represents.
+ * @return the tag.
+ */
+ public abstract HTML.Tag getTag();
+ }
+
+ public class BlockElement extends AbstractDocument.BranchElement
+ {
+ public BlockElement (Element parent, AttributeSet a)
+ {
+ super(parent, a);
+ }
+
+ /**
+ * Gets the resolving parent. Since HTML attributes are not
+ * inherited at the model level, this returns null.
+ */
+ public AttributeSet getResolveParent()
+ {
+ return null;
+ }
+
+ /**
+ * Gets the name of the element.
+ *
+ * @return the name of the element if it exists, null otherwise.
+ */
+ public String getName()
+ {
+ Object tag = getAttribute(StyleConstants.NameAttribute);
+ String name = null;
+ if (tag != null)
+ name = tag.toString();
+ return name;
+ }
+ }
+
+ /**
+ * RunElement represents a section of text that has a set of
+ * HTML character level attributes assigned to it.
+ */
+ public class RunElement extends AbstractDocument.LeafElement
+ {
+
+ /**
+ * Constructs an element that has no children. It represents content
+ * within the document.
+ *
+ * @param parent - parent of this
+ * @param a - elements attributes
+ * @param start - the start offset >= 0
+ * @param end - the end offset
+ */
+ public RunElement(Element parent, AttributeSet a, int start, int end)
+ {
+ super(parent, a, start, end);
+ }
+
+ /**
+ * Gets the name of the element.
+ *
+ * @return the name of the element if it exists, null otherwise.
+ */
+ public String getName()
+ {
+ Object tag = getAttribute(StyleConstants.NameAttribute);
+ String name = null;
+ if (tag != null)
+ name = tag.toString();
+ return name;
+ }
+
+ /**
+ * Gets the resolving parent. HTML attributes do not inherit at the
+ * model level, so this method returns null.
+ *
+ * @return null
+ */
+ public AttributeSet getResolveParent()
+ {
+ return null;
+ }
+ }
+
+ /**
+ * A reader to load an HTMLDocument with HTML structure.
+ *
+ * @author Anthony Balkissoon abalkiss at redhat dot com
+ */
+ public class HTMLReader extends HTMLEditorKit.ParserCallback
+ {
+ /**
+ * Holds the current character attribute set *
+ */
+ protected MutableAttributeSet charAttr = new SimpleAttributeSet();
+
+ protected Vector parseBuffer = new Vector();
+
+ /**
+ * A stack for character attribute sets *
+ */
+ Stack charAttrStack = new Stack();
+
+ /**
+ * The parse stack. This stack holds HTML.Tag objects that reflect the
+ * current position in the parsing process.
+ */
+ Stack parseStack = new Stack();
+
+ /** A mapping between HTML.Tag objects and the actions that handle them **/
+ HashMap tagToAction;
+
+ /** Tells us whether we've received the '</html>' tag yet **/
+ boolean endHTMLEncountered = false;
+
+ /**
+ * Related to the constructor with explicit insertTag
+ */
+ int popDepth;
+
+ /**
+ * Related to the constructor with explicit insertTag
+ */
+ int pushDepth;
+
+ /**
+ * Related to the constructor with explicit insertTag
+ */
+ int offset;
+
+ /**
+ * The tag (inclusve), after that the insertion should start.
+ */
+ HTML.Tag insertTag;
+
+ /**
+ * This variable becomes true after the insert tag has been encountered.
+ */
+ boolean insertTagEncountered;
+
+
+ /** A temporary variable that helps with the printing out of debug information **/
+ boolean debug = false;
+
+ void print (String line)
+ {
+ if (debug)
+ System.out.println (line);
+ }
+
+ public class TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action. By default this does nothing.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action. By default does nothing.
+ */
+ public void end(HTML.Tag t)
+ {
+ // Nothing to do here.
+ }
+ }
+
+ public class BlockAction extends TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ {
+ // Tell the parse buffer to open a new block for this tag.
+ blockOpen(t, a);
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ {
+ // Tell the parse buffer to close this block.
+ blockClose(t);
+ }
+ }
+
+ public class CharacterAction extends TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ {
+ // Put the old attribute set on the stack.
+ pushCharacterStyle();
+
+ // Translate tag.. return if succesful.
+ if(CharacterAttributeTranslator.translateTag(charAttr, t, a))
+ return;
+
+ // Just add the attributes in <code>a</code>.
+ if (a != null)
+ charAttr.addAttribute(t, a.copyAttributes());
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ {
+ popCharacterStyle();
+ }
+ }
+
+ public class FormAction extends SpecialAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("FormAction.start not implemented");
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("FormAction.end not implemented");
+ }
+ }
+
+ /**
+ * This action indicates that the content between starting and closing HTML
+ * elements (like script - /script) should not be visible. The content is
+ * still inserted and can be accessed when iterating the HTML document. The
+ * parser will only fire
+ * {@link javax.swing.text.html.HTMLEditorKit.ParserCallback#handleText} for
+ * the hidden tags, regardless from that html tags the hidden section may
+ * contain.
+ */
+ public class HiddenAction
+ extends TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ {
+ blockOpen(t, a);
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ {
+ blockClose(t);
+ }
+ }
+
+ public class IsindexAction extends TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("IsindexAction.start not implemented");
+ }
+ }
+
+ public class ParagraphAction extends BlockAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ {
+ blockOpen(t, a);
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ {
+ blockClose(t);
+ }
+ }
+
+ public class PreAction extends BlockAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("PreAction.start not implemented");
+ super.start(t, a);
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("PreAction.end not implemented");
+ super.end(t);
+ }
+ }
+
+ /**
+ * Inserts the elements that are represented by ths single tag with
+ * attributes (only). The closing tag, even if present, mut follow
+ * immediately after the starting tag without providing any additional
+ * information. Hence the {@link TagAction#end} method need not be
+ * overridden and still does nothing.
+ */
+ public class SpecialAction extends TagAction
+ {
+ /**
+ * The functionality is delegated to {@link HTMLReader#addSpecialElement}
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ {
+ addSpecialElement(t, a);
+ }
+ }
+
+ class AreaAction extends TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("AreaAction.start not implemented");
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("AreaAction.end not implemented");
+ }
+ }
+
+ class BaseAction extends TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("BaseAction.start not implemented");
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("BaseAction.end not implemented");
+ }
+ }
+
+ class HeadAction extends BlockAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("HeadAction.start not implemented: "+t);
+ super.start(t, a);
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("HeadAction.end not implemented: "+t);
+ super.end(t);
+ }
+ }
+
+ class LinkAction extends TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("LinkAction.start not implemented");
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("LinkAction.end not implemented");
+ }
+ }
+
+ class MapAction extends TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("MapAction.start not implemented");
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("MapAction.end not implemented");
+ }
+ }
+
+ class MetaAction extends TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("MetaAction.start not implemented");
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("MetaAction.end not implemented");
+ }
+ }
+
+ class StyleAction extends TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("StyleAction.start not implemented");
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("StyleAction.end not implemented");
+ }
+ }
+
+ class TitleAction extends TagAction
+ {
+ /**
+ * This method is called when a start tag is seen for one of the types
+ * of tags associated with this Action.
+ */
+ public void start(HTML.Tag t, MutableAttributeSet a)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("TitleAction.start not implemented");
+ }
+
+ /**
+ * Called when an end tag is seen for one of the types of tags associated
+ * with this Action.
+ */
+ public void end(HTML.Tag t)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("TitleAction.end not implemented");
+ }
+ }
+
+ public HTMLReader(int offset)
+ {
+ this (offset, 0, 0, null);
+ }
+
+ public HTMLReader(int offset, int popDepth, int pushDepth,
+ HTML.Tag insertTag)
+ {
+ print ("HTMLReader created with pop: "+popDepth
+ + " push: "+pushDepth + " offset: "+offset
+ + " tag: "+insertTag);
+ this.insertTag = insertTag;
+ this.offset = offset;
+ this.popDepth = popDepth;
+ this.pushDepth = pushDepth;
+ initTags();
+ }
+
+ void initTags()
+ {
+ tagToAction = new HashMap(72);
+ CharacterAction characterAction = new CharacterAction();
+ HiddenAction hiddenAction = new HiddenAction();
+ AreaAction areaAction = new AreaAction();
+ BaseAction baseAction = new BaseAction();
+ BlockAction blockAction = new BlockAction();
+ SpecialAction specialAction = new SpecialAction();
+ ParagraphAction paragraphAction = new ParagraphAction();
+ HeadAction headAction = new HeadAction();
+ FormAction formAction = new FormAction();
+ IsindexAction isindexAction = new IsindexAction();
+ LinkAction linkAction = new LinkAction();
+ MapAction mapAction = new MapAction();
+ PreAction preAction = new PreAction();
+ MetaAction metaAction = new MetaAction();
+ StyleAction styleAction = new StyleAction();
+ TitleAction titleAction = new TitleAction();
+
+
+ tagToAction.put(HTML.Tag.A, characterAction);
+ tagToAction.put(HTML.Tag.ADDRESS, characterAction);
+ tagToAction.put(HTML.Tag.APPLET, hiddenAction);
+ tagToAction.put(HTML.Tag.AREA, areaAction);
+ tagToAction.put(HTML.Tag.B, characterAction);
+ tagToAction.put(HTML.Tag.BASE, baseAction);
+ tagToAction.put(HTML.Tag.BASEFONT, characterAction);
+ tagToAction.put(HTML.Tag.BIG, characterAction);
+ tagToAction.put(HTML.Tag.BLOCKQUOTE, blockAction);
+ tagToAction.put(HTML.Tag.BODY, blockAction);
+ tagToAction.put(HTML.Tag.BR, specialAction);
+ tagToAction.put(HTML.Tag.CAPTION, blockAction);
+ tagToAction.put(HTML.Tag.CENTER, blockAction);
+ tagToAction.put(HTML.Tag.CITE, characterAction);
+ tagToAction.put(HTML.Tag.CODE, characterAction);
+ tagToAction.put(HTML.Tag.DD, blockAction);
+ tagToAction.put(HTML.Tag.DFN, characterAction);
+ tagToAction.put(HTML.Tag.DIR, blockAction);
+ tagToAction.put(HTML.Tag.DIV, blockAction);
+ tagToAction.put(HTML.Tag.DL, blockAction);
+ tagToAction.put(HTML.Tag.DT, paragraphAction);
+ tagToAction.put(HTML.Tag.EM, characterAction);
+ tagToAction.put(HTML.Tag.FONT, characterAction);
+ tagToAction.put(HTML.Tag.FORM, blockAction);
+ tagToAction.put(HTML.Tag.FRAME, specialAction);
+ tagToAction.put(HTML.Tag.FRAMESET, blockAction);
+ tagToAction.put(HTML.Tag.H1, paragraphAction);
+ tagToAction.put(HTML.Tag.H2, paragraphAction);
+ tagToAction.put(HTML.Tag.H3, paragraphAction);
+ tagToAction.put(HTML.Tag.H4, paragraphAction);
+ tagToAction.put(HTML.Tag.H5, paragraphAction);
+ tagToAction.put(HTML.Tag.H6, paragraphAction);
+ tagToAction.put(HTML.Tag.HEAD, headAction);
+ tagToAction.put(HTML.Tag.HR, specialAction);
+ tagToAction.put(HTML.Tag.HTML, blockAction);
+ tagToAction.put(HTML.Tag.I, characterAction);
+ tagToAction.put(HTML.Tag.IMG, specialAction);
+ tagToAction.put(HTML.Tag.INPUT, formAction);
+ tagToAction.put(HTML.Tag.ISINDEX, isindexAction);
+ tagToAction.put(HTML.Tag.KBD, characterAction);
+ tagToAction.put(HTML.Tag.LI, blockAction);
+ tagToAction.put(HTML.Tag.LINK, linkAction);
+ tagToAction.put(HTML.Tag.MAP, mapAction);
+ tagToAction.put(HTML.Tag.MENU, blockAction);
+ tagToAction.put(HTML.Tag.META, metaAction);
+ tagToAction.put(HTML.Tag.NOFRAMES, blockAction);
+ tagToAction.put(HTML.Tag.OBJECT, specialAction);
+ tagToAction.put(HTML.Tag.OL, blockAction);
+ tagToAction.put(HTML.Tag.OPTION, formAction);
+ tagToAction.put(HTML.Tag.P, paragraphAction);
+ tagToAction.put(HTML.Tag.PARAM, hiddenAction);
+ tagToAction.put(HTML.Tag.PRE, preAction);
+ tagToAction.put(HTML.Tag.SAMP, characterAction);
+ tagToAction.put(HTML.Tag.SCRIPT, hiddenAction);
+ tagToAction.put(HTML.Tag.SELECT, formAction);
+ tagToAction.put(HTML.Tag.SMALL, characterAction);
+ tagToAction.put(HTML.Tag.STRIKE, characterAction);
+ tagToAction.put(HTML.Tag.S, characterAction);
+ tagToAction.put(HTML.Tag.STRONG, characterAction);
+ tagToAction.put(HTML.Tag.STYLE, styleAction);
+ tagToAction.put(HTML.Tag.SUB, characterAction);
+ tagToAction.put(HTML.Tag.SUP, characterAction);
+ tagToAction.put(HTML.Tag.TABLE, blockAction);
+ tagToAction.put(HTML.Tag.TD, blockAction);
+ tagToAction.put(HTML.Tag.TEXTAREA, formAction);
+ tagToAction.put(HTML.Tag.TH, blockAction);
+ tagToAction.put(HTML.Tag.TITLE, titleAction);
+ tagToAction.put(HTML.Tag.TR, blockAction);
+ tagToAction.put(HTML.Tag.TT, characterAction);
+ tagToAction.put(HTML.Tag.U, characterAction);
+ tagToAction.put(HTML.Tag.UL, blockAction);
+ tagToAction.put(HTML.Tag.VAR, characterAction);
+ }
+
+ /**
+ * Pushes the current character style onto the stack.
+ *
+ */
+ protected void pushCharacterStyle()
+ {
+ charAttrStack.push(charAttr.copyAttributes());
+ }
+
+ /**
+ * Pops a character style off of the stack and uses it as the
+ * current character style.
+ *
+ */
+ protected void popCharacterStyle()
+ {
+ if (!charAttrStack.isEmpty())
+ charAttr = (MutableAttributeSet) charAttrStack.pop();
+ }
+
+ /**
+ * Registers a given tag with a given Action. All of the well-known tags
+ * are registered by default, but this method can change their behaviour
+ * or add support for custom or currently unsupported tags.
+ *
+ * @param t the Tag to register
+ * @param a the Action for the Tag
+ */
+ protected void registerTag(HTML.Tag t, HTMLDocument.HTMLReader.TagAction a)
+ {
+ tagToAction.put (t, a);
+ }
+
+ /**
+ * This is the last method called on the HTMLReader, allowing any pending
+ * changes to be flushed to the HTMLDocument.
+ */
+ public void flush() throws BadLocationException
+ {
+ DefaultStyledDocument.ElementSpec[] elements;
+ elements = new DefaultStyledDocument.ElementSpec[parseBuffer.size()];
+ parseBuffer.copyInto(elements);
+ parseBuffer.removeAllElements();
+ if (offset == 0)
+ create(elements);
+ else
+ insert(offset, elements);
+
+ offset += HTMLDocument.this.getLength() - offset;
+ }
+
+ /**
+ * This method is called by the parser to indicate a block of
+ * text was encountered. Should insert the text appropriately.
+ *
+ * @param data the text that was inserted
+ * @param pos the position at which the text was inserted
+ */
+ public void handleText(char[] data, int pos)
+ {
+ if (data != null && data.length > 0)
+ addContent(data, 0, data.length);
+ }
+
+ /**
+ * Checks if the HTML tag should be inserted. The tags before insert tag (if
+ * specified) are not inserted. Also, the tags after the end of the html are
+ * not inserted.
+ *
+ * @return true if the tag should be inserted, false otherwise.
+ */
+ private boolean shouldInsert()
+ {
+ return ! endHTMLEncountered
+ && (insertTagEncountered || insertTag == null);
+ }
+
+ /**
+ * This method is called by the parser and should route the call to the
+ * proper handler for the tag.
+ *
+ * @param t the HTML.Tag
+ * @param a the attribute set
+ * @param pos the position at which the tag was encountered
+ */
+ public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos)
+ {
+ if (t == insertTag)
+ insertTagEncountered = true;
+
+ if (shouldInsert())
+ {
+ TagAction action = (TagAction) tagToAction.get(t);
+ if (action != null)
+ action.start(t, a);
+ }
+ }
+
+ /**
+ * This method called by parser to handle a comment block.
+ *
+ * @param data the comment
+ * @param pos the position at which the comment was encountered
+ */
+ public void handleComment(char[] data, int pos)
+ {
+ if (shouldInsert())
+ {
+ TagAction action = (TagAction) tagToAction.get(HTML.Tag.COMMENT);
+ if (action != null)
+ {
+ action.start(HTML.Tag.COMMENT,
+ htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET);
+ action.end(HTML.Tag.COMMENT);
+ }
+ }
+ }
+
+ /**
+ * This method is called by the parser and should route the call to the
+ * proper handler for the tag.
+ *
+ * @param t the HTML.Tag
+ * @param pos the position at which the tag was encountered
+ */
+ public void handleEndTag(HTML.Tag t, int pos)
+ {
+ if (shouldInsert())
+ {
+ // If this is the </html> tag we need to stop calling the Actions
+ if (t == HTML.Tag.HTML)
+ endHTMLEncountered = true;
+
+ TagAction action = (TagAction) tagToAction.get(t);
+ if (action != null)
+ action.end(t);
+ }
+ }
+
+ /**
+ * This is a callback from the parser that should be routed to the
+ * appropriate handler for the tag.
+ *
+ * @param t the HTML.Tag that was encountered
+ * @param a the attribute set
+ * @param pos the position at which the tag was encountered
+ */
+ public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos)
+ {
+ if (t == insertTag)
+ insertTagEncountered = true;
+
+ if (shouldInsert())
+ {
+ TagAction action = (TagAction) tagToAction.get(t);
+ if (action != null)
+ {
+ action.start(t, a);
+ action.end(t);
+ }
+ }
+ }
+
+ /**
+ * This is invoked after the stream has been parsed but before it has been
+ * flushed.
+ *
+ * @param eol one of \n, \r, or \r\n, whichever was encountered the most in
+ * parsing the stream
+ * @since 1.3
+ */
+ public void handleEndOfLineString(String eol)
+ {
+ // FIXME: Implement.
+ print ("HTMLReader.handleEndOfLineString not implemented yet");
+ }
+
+ /**
+ * Adds the given text to the textarea document. Called only when we are
+ * within a textarea.
+ *
+ * @param data the text to add to the textarea
+ */
+ protected void textAreaContent(char[] data)
+ throws NotImplementedException
+ {
+ // FIXME: Implement.
+ print ("HTMLReader.textAreaContent not implemented yet");
+ }
+
+ /**
+ * Adds the given text that was encountered in a <PRE> element.
+ *
+ * @param data the text
+ */
+ protected void preContent(char[] data)
+ throws NotImplementedException
+ {
+ // FIXME: Implement
+ print ("HTMLReader.preContent not implemented yet");
+ }
+
+ /**
+ * Instructs the parse buffer to create a block element with the given
+ * attributes.
+ *
+ * @param t the tag that requires opening a new block
+ * @param attr the attribute set for the new block
+ */
+ protected void blockOpen(HTML.Tag t, MutableAttributeSet attr)
+ {
+ printBuffer();
+ DefaultStyledDocument.ElementSpec element;
+
+ parseStack.push(t);
+ AbstractDocument.AttributeContext ctx = getAttributeContext();
+ AttributeSet copy = attr.copyAttributes();
+ copy = ctx.addAttribute(copy, StyleConstants.NameAttribute, t);
+ element = new DefaultStyledDocument.ElementSpec(copy,
+ DefaultStyledDocument.ElementSpec.StartTagType);
+ parseBuffer.addElement(element);
+ printBuffer();
+ }
+
+ /**
+ * Instructs the parse buffer to close the block element associated with
+ * the given HTML.Tag
+ *
+ * @param t the HTML.Tag that is closing its block
+ */
+ protected void blockClose(HTML.Tag t)
+ {
+ printBuffer();
+ DefaultStyledDocument.ElementSpec element;
+
+ // If the previous tag is a start tag then we insert a synthetic
+ // content tag.
+ DefaultStyledDocument.ElementSpec prev;
+ prev = (DefaultStyledDocument.ElementSpec)
+ parseBuffer.get(parseBuffer.size() - 1);
+ if (prev.getType() == DefaultStyledDocument.ElementSpec.StartTagType)
+ {
+ AbstractDocument.AttributeContext ctx = getAttributeContext();
+ AttributeSet attributes = ctx.getEmptySet();
+ attributes = ctx.addAttribute(attributes, StyleConstants.NameAttribute,
+ HTML.Tag.CONTENT);
+ element = new DefaultStyledDocument.ElementSpec(attributes,
+ DefaultStyledDocument.ElementSpec.ContentType,
+ new char[0], 0, 0);
+ parseBuffer.add(element);
+ }
+
+ element = new DefaultStyledDocument.ElementSpec(null,
+ DefaultStyledDocument.ElementSpec.EndTagType);
+ parseBuffer.addElement(element);
+ printBuffer();
+ if (parseStack.size() > 0)
+ parseStack.pop();
+ }
+
+ /**
+ * Adds text to the appropriate context using the current character
+ * attribute set.
+ *
+ * @param data the text to add
+ * @param offs the offset at which to add it
+ * @param length the length of the text to add
+ */
+ protected void addContent(char[] data, int offs, int length)
+ {
+ addContent(data, offs, length, true);
+ }
+
+ /**
+ * Adds text to the appropriate context using the current character
+ * attribute set, and possibly generating an IMPLIED Tag if necessary.
+ *
+ * @param data the text to add
+ * @param offs the offset at which to add it
+ * @param length the length of the text to add
+ * @param generateImpliedPIfNecessary whether or not we should generate
+ * an HTML.Tag.IMPLIED tag if necessary
+ */
+ protected void addContent(char[] data, int offs, int length,
+ boolean generateImpliedPIfNecessary)
+ {
+ AbstractDocument.AttributeContext ctx = getAttributeContext();
+ DefaultStyledDocument.ElementSpec element;
+ AttributeSet attributes = null;
+
+ // Copy the attribute set, don't use the same object because
+ // it may change
+ if (charAttr != null)
+ attributes = charAttr.copyAttributes();
+ else
+ attributes = ctx.getEmptySet();
+ attributes = ctx.addAttribute(attributes, StyleConstants.NameAttribute,
+ HTML.Tag.CONTENT);
+ element = new DefaultStyledDocument.ElementSpec(attributes,
+ DefaultStyledDocument.ElementSpec.ContentType,
+ data, offs, length);
+
+ printBuffer();
+ // Add the element to the buffer
+ parseBuffer.addElement(element);
+ printBuffer();
+
+ if (parseBuffer.size() > HTMLDocument.this.getTokenThreshold())
+ {
+ try
+ {
+ flush();
+ }
+ catch (BadLocationException ble)
+ {
+ // TODO: what to do here?
+ }
+ }
+ }
+
+ /**
+ * Adds content that is specified in the attribute set.
+ *
+ * @param t the HTML.Tag
+ * @param a the attribute set specifying the special content
+ */
+ protected void addSpecialElement(HTML.Tag t, MutableAttributeSet a)
+ {
+ a.addAttribute(StyleConstants.NameAttribute, t);
+
+ // Migrate from the rather htmlAttributeSet to the faster, lighter and
+ // unchangeable alternative implementation.
+ AttributeSet copy = a.copyAttributes();
+
+ // The two spaces are required because some special elements like HR
+ // must be broken. At least two characters are needed to break into the
+ // two parts.
+ DefaultStyledDocument.ElementSpec spec =
+ new DefaultStyledDocument.ElementSpec(copy,
+ DefaultStyledDocument.ElementSpec.ContentType,
+ new char[] {' ', ' '}, 0, 2 );
+ parseBuffer.add(spec);
+ }
+
+ void printBuffer()
+ {
+ print ("\n*********BUFFER**********");
+ for (int i = 0; i < parseBuffer.size(); i ++)
+ print (" "+parseBuffer.get(i));
+ print ("***************************");
+ }
+ }
+
+ /**
+ * Gets the reader for the parser to use when loading the document with HTML.
+ *
+ * @param pos - the starting position
+ * @return - the reader
+ */
+ public HTMLEditorKit.ParserCallback getReader(int pos)
+ {
+ return new HTMLReader(pos);
+ }
+
+ /**
+ * Gets the reader for the parser to use when loading the document with HTML.
+ *
+ * @param pos - the starting position
+ * @param popDepth - the number of EndTagTypes to generate before inserting
+ * @param pushDepth - the number of StartTagTypes with a direction
+ * of JoinNextDirection that should be generated before inserting,
+ * but after the end tags have been generated.
+ * @param insertTag - the first tag to start inserting into document
+ * @return - the reader
+ */
+ public HTMLEditorKit.ParserCallback getReader(int pos,
+ int popDepth,
+ int pushDepth,
+ HTML.Tag insertTag)
+ {
+ return new HTMLReader(pos, popDepth, pushDepth, insertTag);
+ }
+
+ /**
+ * Gets the reader for the parser to use when inserting the HTML fragment into
+ * the document. Checks if the parser is present, sets the parent in the
+ * element stack and removes any actions for BODY (it can be only one body in
+ * a HTMLDocument).
+ *
+ * @param pos - the starting position
+ * @param popDepth - the number of EndTagTypes to generate before inserting
+ * @param pushDepth - the number of StartTagTypes with a direction of
+ * JoinNextDirection that should be generated before inserting, but
+ * after the end tags have been generated.
+ * @param insertTag - the first tag to start inserting into document
+ * @param parent the element that will be the parent in the document. HTML
+ * parsing includes checks for the parent, so it must be available.
+ * @return - the reader
+ * @throws IllegalStateException if the parsert is not set.
+ */
+ public HTMLEditorKit.ParserCallback getInsertingReader(int pos, int popDepth,
+ int pushDepth,
+ HTML.Tag insertTag,
+ final Element parent)
+ throws IllegalStateException
+ {
+ if (parser == null)
+ throw new IllegalStateException("Parser has not been set");
+
+ HTMLReader reader = new HTMLReader(pos, popDepth, pushDepth, insertTag)
+ {
+ /**
+ * Ignore BODY.
+ */
+ public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos)
+ {
+ if (t != HTML.Tag.BODY)
+ super.handleStartTag(t, a, pos);
+ }
+
+ /**
+ * Ignore BODY.
+ */
+ public void handleEndTag(HTML.Tag t, int pos)
+ {
+ if (t != HTML.Tag.BODY)
+ super.handleEndTag(t, pos);
+ }
+ };
+
+ // Set the parent HTML tag.
+ reader.parseStack.push(parent.getAttributes().getAttribute(
+ StyleConstants.NameAttribute));
+
+ return reader;
+ }
+
+ /**
+ * Gets the child element that contains the attribute with the value or null.
+ * Not thread-safe.
+ *
+ * @param e - the element to begin search at
+ * @param attribute - the desired attribute
+ * @param value - the desired value
+ * @return the element found with the attribute and value specified or null if
+ * it is not found.
+ */
+ public Element getElement(Element e, Object attribute, Object value)
+ {
+ if (e != null)
+ {
+ if (e.getAttributes().containsAttribute(attribute, value))
+ return e;
+
+ int count = e.getElementCount();
+ for (int j = 0; j < count; j++)
+ {
+ Element child = e.getElement(j);
+ if (child.getAttributes().containsAttribute(attribute, value))
+ return child;
+
+ Element grandChild = getElement(child, attribute, value);
+ if (grandChild != null)
+ return grandChild;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the element that has the given id Attribute (for instance, <p id
+ * ='my paragraph >'). If it is not found, null is returned. The HTML tag,
+ * having this attribute, is not checked by this method and can be any. The
+ * method is not thread-safe.
+ *
+ * @param attrId - the value of the attribute id to look for
+ * @return the element that has the given id.
+ */
+ public Element getElement(String attrId)
+ {
+ return getElement(getDefaultRootElement(), HTML.Attribute.ID,
+ attrId);
+ }
+
+ /**
+ * Replaces the children of the given element with the contents of
+ * the string. The document must have an HTMLEditorKit.Parser set.
+ * This will be seen as at least two events, n inserts followed by a remove.
+ *
+ * @param elem - the brance element whose children will be replaced
+ * @param htmlText - the string to be parsed and assigned to element.
+ * @throws BadLocationException
+ * @throws IOException
+ * @throws IllegalArgumentException - if elem is a leaf
+ * @throws IllegalStateException - if an HTMLEditorKit.Parser has not been set
+ */
+ public void setInnerHTML(Element elem, String htmlText)
+ throws BadLocationException, IOException
+ {
+ if (elem.isLeaf())
+ throw new IllegalArgumentException("Element is a leaf");
+
+ int start = elem.getStartOffset();
+ int end = elem.getEndOffset();
+
+ HTMLEditorKit.ParserCallback reader = getInsertingReader(
+ end, 0, 0, HTML.Tag.BODY, elem);
+
+ // TODO charset
+ getParser().parse(new StringReader(htmlText), reader, true);
+
+ // Remove the previous content
+ remove(start, end - start);
+ }
+
+ /**
+ * Replaces the given element in the parent with the string. When replacing a
+ * leaf, this will attempt to make sure there is a newline present if one is
+ * needed. This may result in an additional element being inserted. This will
+ * be seen as at least two events, n inserts followed by a remove. The
+ * HTMLEditorKit.Parser must be set.
+ *
+ * @param elem - the branch element whose parent will be replaced
+ * @param htmlText - the string to be parsed and assigned to elem
+ * @throws BadLocationException
+ * @throws IOException
+ * @throws IllegalStateException - if parser is not set
+ */
+public void setOuterHTML(Element elem, String htmlText)
+ throws BadLocationException, IOException
+ {
+ // Remove the current element:
+ int start = elem.getStartOffset();
+ int end = elem.getEndOffset();
+
+ remove(start, end-start);
+
+ HTMLEditorKit.ParserCallback reader = getInsertingReader(
+ start, 0, 0, HTML.Tag.BODY, elem);
+
+ // TODO charset
+ getParser().parse(new StringReader(htmlText), reader, true);
+ }
+
+ /**
+ * Inserts the string before the start of the given element. The parser must
+ * be set.
+ *
+ * @param elem - the element to be the root for the new text.
+ * @param htmlText - the string to be parsed and assigned to elem
+ * @throws BadLocationException
+ * @throws IOException
+ * @throws IllegalStateException - if parser has not been set
+ */
+ public void insertBeforeStart(Element elem, String htmlText)
+ throws BadLocationException, IOException
+ {
+ HTMLEditorKit.ParserCallback reader = getInsertingReader(
+ elem.getStartOffset(), 0, 0, HTML.Tag.BODY, elem);
+
+ // TODO charset
+ getParser().parse(new StringReader(htmlText), reader, true);
+ }
+
+ /**
+ * Inserts the string at the end of the element. If elem's children are
+ * leaves, and the character at elem.getEndOffset() - 1 is a newline, then it
+ * will be inserted before the newline. The parser must be set.
+ *
+ * @param elem - the element to be the root for the new text
+ * @param htmlText - the text to insert
+ * @throws BadLocationException
+ * @throws IOException
+ * @throws IllegalStateException - if parser is not set
+ */
+ public void insertBeforeEnd(Element elem, String htmlText)
+ throws BadLocationException, IOException
+ {
+ HTMLEditorKit.ParserCallback reader = getInsertingReader(
+ elem.getEndOffset(), 0, 0, HTML.Tag.BODY, elem);
+
+ // TODO charset
+ getParser().parse(new StringReader(htmlText), reader, true);
+
+ }
+
+ /**
+ * Inserts the string after the end of the given element.
+ * The parser must be set.
+ *
+ * @param elem - the element to be the root for the new text
+ * @param htmlText - the text to insert
+ * @throws BadLocationException
+ * @throws IOException
+ * @throws IllegalStateException - if parser is not set
+ */
+ public void insertAfterEnd(Element elem, String htmlText)
+ throws BadLocationException, IOException
+ {
+ HTMLEditorKit.ParserCallback reader = getInsertingReader(
+ elem.getEndOffset(), 0, 0, HTML.Tag.BODY, elem);
+
+ // TODO charset
+ getParser().parse(new StringReader(htmlText), reader, true);
+ }
+
+ /**
+ * Inserts the string at the start of the element.
+ * The parser must be set.
+ *
+ * @param elem - the element to be the root for the new text
+ * @param htmlText - the text to insert
+ * @throws BadLocationException
+ * @throws IOException
+ * @throws IllegalStateException - if parser is not set
+ */
+ public void insertAfterStart(Element elem, String htmlText)
+ throws BadLocationException, IOException
+ {
+ HTMLEditorKit.ParserCallback reader = getInsertingReader(
+ elem.getStartOffset(), 0, 0, HTML.Tag.BODY, elem);
+
+ // TODO charset
+ getParser().parse(new StringReader(htmlText), reader, true);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLEditorKit.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLEditorKit.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLEditorKit.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLEditorKit.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1176 @@
+/* HTMLEditorKit.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+
+import gnu.classpath.NotImplementedException;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+import java.awt.Cursor;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Serializable;
+import java.io.StringReader;
+import java.io.Writer;
+
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+
+import javax.swing.Action;
+import javax.swing.JEditorPane;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.EditorKit;
+import javax.swing.text.Element;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.StyleContext;
+import javax.swing.text.StyledEditorKit;
+import javax.swing.text.TextAction;
+import javax.swing.text.View;
+import javax.swing.text.ViewFactory;
+import javax.swing.text.html.parser.ParserDelegator;
+
+/* Move these imports here after javax.swing.text.html to make it compile
+ with jikes. */
+import gnu.javax.swing.text.html.parser.GnuParserDelegator;
+import gnu.javax.swing.text.html.parser.HTML_401Swing;
+
+/**
+ * @author Lillian Angel (langel at redhat dot com)
+ */
+public class HTMLEditorKit
+ extends StyledEditorKit
+ implements Serializable, Cloneable, Accessible
+{
+
+ /**
+ * Fires the hyperlink events on the associated component
+ * when needed.
+ */
+ public static class LinkController
+ extends MouseAdapter
+ implements MouseMotionListener, Serializable
+ {
+
+ /**
+ * Constructor
+ */
+ public LinkController()
+ {
+ super();
+ }
+
+ /**
+ * Dispatched when the mouse is clicked. If the component
+ * is read-only, then the clicked event is used to drive an
+ * attempt to follow the reference specified by a link
+ *
+ * @param e - the mouse event
+ */
+ public void mouseClicked(MouseEvent e)
+ {
+ /*
+ These MouseInputAdapter methods generate mouse appropriate events around
+ hyperlinks (entering, exiting, and activating).
+ */
+ // FIXME: Not implemented.
+ }
+
+ /**
+ * Dispatched when the mouse is dragged on a component.
+ *
+ * @param e - the mouse event.
+ */
+ public void mouseDragged(MouseEvent e)
+ {
+ /*
+ These MouseInputAdapter methods generate mouse appropriate events around
+ hyperlinks (entering, exiting, and activating).
+ */
+ // FIXME: Not implemented.
+ }
+
+ /**
+ * Dispatched when the mouse cursor has moved into the component.
+ *
+ * @param e - the mouse event.
+ */
+ public void mouseMoved(MouseEvent e)
+ {
+ /*
+ These MouseInputAdapter methods generate mouse appropriate events around
+ hyperlinks (entering, exiting, and activating).
+ */
+ // FIXME: Not implemented.
+ }
+
+ /**
+ * If the given position represents a link, then linkActivated is called
+ * on the JEditorPane. Implemented to forward to the method with the same
+ * name, but pos == editor == -1.
+ *
+ * @param pos - the position
+ * @param editor - the editor pane
+ */
+ protected void activateLink(int pos,
+ JEditorPane editor)
+ {
+ /*
+ This method creates and fires a HyperlinkEvent if the document is an
+ instance of HTMLDocument and the href tag of the link is not null.
+ */
+ // FIXME: Not implemented.
+ }
+ }
+
+ /**
+ * This class is used to insert a string of HTML into an existing
+ * document. At least 2 HTML.Tags need to be supplied. The first Tag (parentTag)
+ * identifies the parent in the document to add the elements to. The second, (addTag),
+ * identifies that the first tag should be added to the document as seen in the string.
+ * The parser will generate all appropriate (opening/closing tags_ even if they are not
+ * in the HTML string passed in.
+ */
+ public static class InsertHTMLTextAction
+ extends HTMLTextAction
+ {
+
+ /**
+ * Tag in HTML to start adding tags from.
+ */
+ protected HTML.Tag addTag;
+
+ /**
+ * Alternate tag in HTML to start adding tags from if parentTag is
+ * not found and alternateParentTag is not found.
+ */
+ protected HTML.Tag alternateAddTag;
+
+ /**
+ * Alternate tag to check if parentTag is not found.
+ */
+ protected HTML.Tag alternateParentTag;
+
+ /**
+ * HTML to insert.
+ */
+ protected String html;
+
+ /**
+ * Tag to check for in the document.
+ */
+ protected HTML.Tag parentTag;
+
+ /**
+ * Initializes all fields.
+ *
+ * @param name - the name of the document.
+ * @param html - the html to insert
+ * @param parentTag - the parent tag to check for
+ * @param addTag - the tag to start adding from
+ */
+ public InsertHTMLTextAction(String name, String html,
+ HTML.Tag parentTag, HTML.Tag addTag)
+ {
+ this(name, html, parentTag, addTag, null, null);
+ }
+
+ /**
+ * Initializes all fields and calls super
+ *
+ * @param name - the name of the document.
+ * @param html - the html to insert
+ * @param parentTag - the parent tag to check for
+ * @param addTag - the tag to start adding from
+ * @param alternateParentTag - the alternate parent tag
+ * @param alternateAddTag - the alternate add tag
+ */
+ public InsertHTMLTextAction(String name, String html, HTML.Tag parentTag,
+ HTML.Tag addTag, HTML.Tag alternateParentTag,
+ HTML.Tag alternateAddTag)
+ {
+ super(name);
+ // Fields are for easy access when the action is applied to an actual
+ // document.
+ this.html = html;
+ this.parentTag = parentTag;
+ this.addTag = addTag;
+ this.alternateParentTag = alternateParentTag;
+ this.alternateAddTag = alternateAddTag;
+ }
+
+ /**
+ * HTMLEditorKit.insertHTML is called. If an exception is
+ * thrown, it is wrapped in a RuntimeException and thrown.
+ *
+ * @param editor - the editor to use to get the editorkit
+ * @param doc -
+ * the Document to insert the HTML into.
+ * @param offset -
+ * where to begin inserting the HTML.
+ * @param html -
+ * the String to insert
+ * @param popDepth -
+ * the number of ElementSpec.EndTagTypes to generate before
+ * inserting
+ * @param pushDepth -
+ * the number of ElementSpec.StartTagTypes with a direction of
+ * ElementSpec.JoinNextDirection that should be generated before
+ * @param addTag -
+ * the first tag to start inserting into document
+ */
+ protected void insertHTML(JEditorPane editor, HTMLDocument doc, int offset,
+ String html, int popDepth, int pushDepth,
+ HTML.Tag addTag)
+ {
+ try
+ {
+ super.getHTMLEditorKit(editor).insertHTML(doc, offset, html,
+ popDepth, pushDepth, addTag);
+ }
+ catch (IOException e)
+ {
+ throw (RuntimeException) new RuntimeException("Parser is null.").initCause(e);
+ }
+ catch (BadLocationException ex)
+ {
+ throw (RuntimeException) new RuntimeException("BadLocationException: "
+ + offset).initCause(ex);
+ }
+ }
+
+ /**
+ * Invoked when inserting at a boundary. Determines the number of pops,
+ * and then the number of pushes that need to be performed. The it calls
+ * insertHTML.
+ *
+ * @param editor -
+ * the editor to use to get the editorkit
+ * @param doc -
+ * the Document to insert the HTML into.
+ * @param offset -
+ * where to begin inserting the HTML.
+ * @param insertElement -
+ * the element to insert
+ * @param html -
+ * the html to insert
+ * @param parentTag -
+ * the parent tag
+ * @param addTag -
+ * the first tag
+ */
+ protected void insertAtBoundary(JEditorPane editor,
+ HTMLDocument doc, int offset,
+ Element insertElement,
+ String html, HTML.Tag parentTag,
+ HTML.Tag addTag)
+ throws NotImplementedException
+ {
+ /*
+ As its name implies, this protected method is used when HTML is inserted at a
+ boundary. (A boundary in this case is an offset in doc that exactly matches the
+ beginning offset of the parentTag.) It performs the extra work required to keep
+ the tag stack in shape and then calls insertHTML(). The editor and doc argu-
+ ments are the editor pane and document where the HTML should go. The offset
+ argument represents the cursor location or selection start in doc. The insert-
+ Element and parentTag arguments are used to calculate the proper number of
+ tag pops and pushes before inserting the HTML (via html and addTag, which are
+ passed directly to insertHTML()).
+ */
+ // FIXME: not implemented
+ }
+
+ /**
+ * Invoked when inserting at a boundary. Determines the number of pops,
+ * and then the number of pushes that need to be performed. The it calls
+ * insertHTML.
+ *
+ * @param editor - the editor to use to get the editorkit
+ * @param doc -
+ * the Document to insert the HTML into.
+ * @param offset -
+ * where to begin inserting the HTML.
+ * @param insertElement - the element to insert
+ * @param html - the html to insert
+ * @param parentTag - the parent tag
+ * @param addTag - the first tag
+ *
+ * @deprecated as of v1.3, use insertAtBoundary
+ */
+ protected void insertAtBoundry(JEditorPane editor,
+ HTMLDocument doc,
+ int offset, Element insertElement,
+ String html, HTML.Tag parentTag,
+ HTML.Tag addTag)
+ {
+ insertAtBoundary(editor, doc, offset, insertElement,
+ html, parentTag, addTag);
+ }
+
+ /**
+ * Inserts the HTML.
+ *
+ * @param ae - the action performed
+ */
+ public void actionPerformed(ActionEvent ae)
+ {
+ Object source = ae.getSource();
+ if (source instanceof JEditorPane)
+ {
+ JEditorPane pane = ((JEditorPane) source);
+ Document d = pane.getDocument();
+ if (d instanceof HTMLDocument)
+ insertHTML(pane, (HTMLDocument) d, 0, html, 0, 0, addTag);
+ // FIXME: is this correct parameters?
+ }
+ // FIXME: else not implemented
+ }
+ }
+
+ /**
+ * Abstract Action class that helps inserting HTML into an existing document.
+ */
+ public abstract static class HTMLTextAction
+ extends StyledEditorKit.StyledTextAction
+ {
+
+ /**
+ * Constructor
+ */
+ public HTMLTextAction(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Gets the HTMLDocument from the JEditorPane.
+ *
+ * @param e - the editor pane
+ * @return the html document.
+ */
+ protected HTMLDocument getHTMLDocument(JEditorPane e)
+ {
+ Document d = e.getDocument();
+ if (d instanceof HTMLDocument)
+ return (HTMLDocument) d;
+ throw new IllegalArgumentException("Document is not a HTMLDocument.");
+ }
+
+ /**
+ * Gets the HTMLEditorKit
+ *
+ * @param e - the JEditorPane to get the HTMLEditorKit from.
+ * @return the HTMLEditorKit
+ */
+ protected HTMLEditorKit getHTMLEditorKit(JEditorPane e)
+ {
+ EditorKit d = e.getEditorKit();
+ if (d instanceof HTMLEditorKit)
+ return (HTMLEditorKit) d;
+ throw new IllegalArgumentException("EditorKit is not a HTMLEditorKit.");
+ }
+
+ /**
+ * Returns an array of Elements that contain the offset.
+ * The first elements corresponds to the roots of the doc.
+ *
+ * @param doc - the document to get the Elements from.
+ * @param offset - the offset the Elements must contain
+ * @return an array of all the elements containing the offset.
+ */
+ protected Element[] getElementsAt(HTMLDocument doc,
+ int offset)
+ {
+ return getElementsAt(doc.getDefaultRootElement(), offset, 0);
+ }
+
+ /**
+ * Helper function to get all elements using recursion.
+ */
+ private Element[] getElementsAt(Element root, int offset, int depth)
+ {
+ Element[] elements = null;
+ if (root != null)
+ {
+ if (root.isLeaf())
+ {
+ elements = new Element[depth + 1];
+ elements[depth] = root;
+ return elements;
+ }
+ elements = getElementsAt(root.getElement(root.getElementIndex(offset)),
+ offset, depth + 1);
+ elements[depth] = root;
+ }
+ return elements;
+ }
+
+ /**
+ * Returns the number of elements, starting at the deepest point, needed
+ * to get an element representing tag. -1 if no elements are found, 0 if
+ * the parent of the leaf at offset represents the tag.
+ *
+ * @param doc -
+ * the document to search
+ * @param offset -
+ * the offset to check
+ * @param tag -
+ * the tag to look for
+ * @return - the number of elements needed to get an element representing
+ * tag.
+ */
+ protected int elementCountToTag(HTMLDocument doc,
+ int offset, HTML.Tag tag)
+ {
+ Element root = doc.getDefaultRootElement();
+ int num = -1;
+ Element next = root.getElement(root.getElementIndex(offset));
+
+ while (!next.isLeaf())
+ {
+ num++;
+ if (next.getAttributes().
+ getAttribute(StyleConstants.NameAttribute).equals(tag))
+ return num;
+ next = next.getElement(next.getElementIndex(offset));
+ }
+ return num;
+ }
+
+ /**
+ * Gets the deepest element at offset with the
+ * matching tag.
+ *
+ * @param doc - the document to search
+ * @param offset - the offset to check for
+ * @param tag - the tag to match
+ * @return - the element that is found, null if not found.
+ */
+ protected Element findElementMatchingTag(HTMLDocument doc,
+ int offset, HTML.Tag tag)
+ {
+ Element element = doc.getDefaultRootElement();
+ Element tagElement = null;
+
+ while (element != null)
+ {
+ Object otag = element.getAttributes().getAttribute(
+ StyleConstants.NameAttribute);
+ if (otag instanceof HTML.Tag && otag.equals(tag))
+ tagElement = element;
+ element = element.getElement(element.getElementIndex(offset));
+ }
+
+ return tagElement;
+ }
+ }
+
+ /**
+ * A {@link ViewFactory} that is able to create {@link View}s for
+ * the <code>Element</code>s that are supported.
+ */
+ public static class HTMLFactory
+ implements ViewFactory
+ {
+
+ /**
+ * Constructor
+ */
+ public HTMLFactory()
+ {
+ // Do Nothing here.
+ }
+
+ /**
+ * Creates a {@link View} for the specified <code>Element</code>.
+ *
+ * @param element the <code>Element</code> to create a <code>View</code>
+ * for
+ * @return the <code>View</code> for the specified <code>Element</code>
+ * or <code>null</code> if the type of <code>element</code> is
+ * not supported
+ */
+ public View create(Element element)
+ {
+ View view = null;
+ Object attr =
+ element.getAttributes().getAttribute(StyleConstants.NameAttribute);
+ if (attr instanceof HTML.Tag)
+ {
+ HTML.Tag tag = (HTML.Tag) attr;
+
+ if (tag.equals(HTML.Tag.IMPLIED) || tag.equals(HTML.Tag.P)
+ || tag.equals(HTML.Tag.H1) || tag.equals(HTML.Tag.H2)
+ || tag.equals(HTML.Tag.H3) || tag.equals(HTML.Tag.H4)
+ || tag.equals(HTML.Tag.H5) || tag.equals(HTML.Tag.H6)
+ || tag.equals(HTML.Tag.DT))
+ view = new ParagraphView(element);
+ else if (tag.equals(HTML.Tag.LI) || tag.equals(HTML.Tag.DL)
+ || tag.equals(HTML.Tag.DD) || tag.equals(HTML.Tag.BODY)
+ || tag.equals(HTML.Tag.HTML) || tag.equals(HTML.Tag.CENTER)
+ || tag.equals(HTML.Tag.DIV)
+ || tag.equals(HTML.Tag.BLOCKQUOTE)
+ || tag.equals(HTML.Tag.PRE))
+ view = new BlockView(element, View.Y_AXIS);
+ else if (tag.equals(HTML.Tag.IMG))
+ view = new ImageView(element);
+
+ // FIXME: Uncomment when the views have been implemented
+ else if (tag.equals(HTML.Tag.CONTENT))
+ view = new InlineView(element);
+ else if (tag == HTML.Tag.HEAD)
+ view = new NullView(element);
+ else if (tag.equals(HTML.Tag.TABLE))
+ view = new javax.swing.text.html.TableView(element);
+ else if (tag.equals(HTML.Tag.TD))
+ view = new ParagraphView(element);
+ else if (tag.equals(HTML.Tag.HR))
+ view = new HRuleView(element);
+ else if (tag.equals(HTML.Tag.BR))
+ view = new BRView(element);
+
+ /*
+ else if (tag.equals(HTML.Tag.MENU) || tag.equals(HTML.Tag.DIR)
+ || tag.equals(HTML.Tag.UL) || tag.equals(HTML.Tag.OL))
+ view = new ListView(element);
+ else if (tag.equals(HTML.Tag.INPUT) || tag.equals(HTML.Tag.SELECT)
+ || tag.equals(HTML.Tag.TEXTAREA))
+ view = new FormView(element);
+ else if (tag.equals(HTML.Tag.OBJECT))
+ view = new ObjectView(element);
+ else if (tag.equals(HTML.Tag.FRAMESET))
+ view = new FrameSetView(element);
+ else if (tag.equals(HTML.Tag.FRAME))
+ view = new FrameView(element); */
+ }
+ if (view == null)
+ {
+ System.err.println("missing tag->view mapping for: " + element);
+ view = new NullView(element);
+ }
+ return view;
+ }
+ }
+
+ /**
+ * The abstract HTML parser declaration.
+ */
+ public abstract static class Parser
+ {
+ /**
+ * Parse the HTML text, calling various methods of the provided callback
+ * in response to the occurence of the corresponding HTML constructions.
+ * @param reader The reader to read the source HTML from.
+ * @param callback The callback to receive information about the parsed
+ * HTML structures
+ * @param ignoreCharSet If true, the parser ignores all charset information
+ * that may be present in HTML documents.
+ * @throws IOException, normally if the reader throws one.
+ */
+ public abstract void parse(Reader reader, ParserCallback callback,
+ boolean ignoreCharSet) throws IOException;
+ }
+
+ /**
+ * The "hook" that receives all information about the HTML document
+ * structure while parsing it. The methods are invoked by parser
+ * and should be normally overridden.
+ */
+ public static class ParserCallback
+ {
+ /**
+ * If the tag does not occurs in the html stream directly, but
+ * is supposed by parser, the tag attribute set contains this additional
+ * attribute, having value Boolean.True.
+ */
+ public static final Object IMPLIED = "_implied_";
+
+ /**
+ * Constructor
+ */
+ public ParserCallback()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * The parser calls this method after it finishes parsing the document.
+ */
+ public void flush() throws BadLocationException
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Handle HTML comment, present in the given position.
+ * @param comment the comment
+ * @position the position of the comment in the text being parsed.
+ */
+ public void handleComment(char[] comment, int position)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Notifies about the character sequences, used to separate lines in
+ * this document. The parser calls this method after it finishes
+ * parsing the document, but before flush().
+ * @param end_of_line The "end of line sequence", one of: \r or \n or \r\n.
+ */
+ public void handleEndOfLineString(String end_of_line)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * The method is called when the HTML closing tag ((like </table>)
+ * is found or if the parser concludes that the one should be present
+ * in the current position.
+ * @param tag The tag being handled
+ * @param position the tag position in the text being parsed.
+ */
+ public void handleEndTag(HTML.Tag tag, int position)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Handle the error.
+ * @param message The message, explaining the error.
+ * @param position The starting position of the fragment that has caused
+ * the error in the html document being parsed.
+ */
+ public void handleError(String message, int position)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Handle the tag with no content, like <br>. The method is
+ * called for the elements that, in accordance with the current DTD,
+ * has an empty content.
+ * @param tag The tag being handled.
+ * @param position The tag position in the text being parsed.
+ */
+ public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet attributes,
+ int position)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * The method is called when the HTML opening tag ((like <table>)
+ * is found or if the parser concludes that the one should be present
+ * in the current position.
+ * @param tag The tag being handled
+ * @param position The tag position in the text being parsed
+ */
+ public void handleStartTag(HTML.Tag tag, MutableAttributeSet attributes,
+ int position)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Handle the text section.
+ * @param text A section text.
+ * @param position The text position in the HTML document text being parsed.
+ */
+ public void handleText(char[] text, int position)
+ {
+ // Nothing to do here.
+ }
+ }
+
+ /**
+ * Use serialVersionUID (v1.4) for interoperability.
+ */
+ private static final long serialVersionUID = 8751997116710384592L;
+
+ /**
+ * Default cascading stylesheed file ("default.css").
+ */
+ public static final String DEFAULT_CSS = "default.css";
+
+ /**
+ * The <b>bold</b> action identifier.
+ */
+ public static final String BOLD_ACTION = "html-bold-action";
+
+ /**
+ * The <i>italic</i> action identifier.
+ */
+ public static final String ITALIC_ACTION = "html-italic-action";
+
+ /**
+ * The <font color="#FF0000">color</font> action indentifier
+ * (passing the color as an argument).
+ */
+ public static final String COLOR_ACTION = "html-color-action";
+
+ /**
+ * The <font size="+1">increase</font> font action identifier.
+ */
+ public static final String FONT_CHANGE_BIGGER = "html-font-bigger";
+
+ /**
+ * The <font size="-1">decrease</font> font action identifier.
+ */
+ public static final String FONT_CHANGE_SMALLER = "html-font-smaller";
+
+ /**
+ * Align images at the bottom.
+ */
+ public static final String IMG_ALIGN_BOTTOM = "html-image-align-bottom";
+
+ /**
+ * Align images at the middle.
+ */
+ public static final String IMG_ALIGN_MIDDLE = "html-image-align-middle";
+
+ /**
+ * Align images at the top.
+ */
+ public static final String IMG_ALIGN_TOP = "html-image-align-top";
+
+ /**
+ * Align images at the border.
+ */
+ public static final String IMG_BORDER = "html-image-border";
+
+ /**
+ * The "logical style" action identifier, passing that style as parameter.
+ */
+ public static final String LOGICAL_STYLE_ACTION = "html-logical-style-action";
+
+ /**
+ * The "ident paragraph left" action.
+ */
+ public static final String PARA_INDENT_LEFT = "html-para-indent-left";
+
+ /**
+ * The "ident paragraph right" action.
+ */
+ public static final String PARA_INDENT_RIGHT = "html-para-indent-right";
+
+ /**
+ * Actions for HTML
+ */
+ private static final Action[] defaultActions = {
+ // FIXME: Add default actions for html
+ };
+
+ /**
+ * The current style sheet.
+ */
+ StyleSheet styleSheet;
+
+ /**
+ * The ViewFactory for HTMLFactory.
+ */
+ HTMLFactory viewFactory;
+
+ /**
+ * The Cursor for links.
+ */
+ Cursor linkCursor;
+
+ /**
+ * The default cursor.
+ */
+ Cursor defaultCursor;
+
+ /**
+ * The parser.
+ */
+ Parser parser;
+
+ /**
+ * The mouse listener used for links.
+ */
+ LinkController mouseListener;
+
+ /**
+ * Style context for this editor.
+ */
+ StyleContext styleContext;
+
+ /** The content type */
+ String contentType = "text/html";
+
+ /** The input attributes defined by default.css */
+ MutableAttributeSet inputAttributes;
+
+ /** The editor pane used. */
+ JEditorPane editorPane;
+
+ /**
+ * Constructs an HTMLEditorKit, creates a StyleContext, and loads the style sheet.
+ */
+ public HTMLEditorKit()
+ {
+ super();
+ styleContext = new StyleContext();
+ styleSheet = new StyleSheet();
+ styleSheet.importStyleSheet(getClass().getResource(DEFAULT_CSS));
+ // FIXME: Set inputAttributes with default.css
+ }
+
+ /**
+ * Gets a factory suitable for producing views of any
+ * models that are produced by this kit.
+ *
+ * @return the view factory suitable for producing views.
+ */
+ public ViewFactory getViewFactory()
+ {
+ if (viewFactory == null)
+ viewFactory = new HTMLFactory();
+ return viewFactory;
+ }
+
+ /**
+ * Create a text storage model for this type of editor.
+ *
+ * @return the model
+ */
+ public Document createDefaultDocument()
+ {
+ HTMLDocument document = new HTMLDocument(getStyleSheet());
+ document.setParser(getParser());
+ return document;
+ }
+
+ /**
+ * Get the parser that this editor kit uses for reading HTML streams. This
+ * method can be overridden to use the alternative parser.
+ *
+ * @return the HTML parser (by default, {@link ParserDelegator}).
+ */
+ protected Parser getParser()
+ {
+ if (parser == null)
+ {
+ parser = new GnuParserDelegator(HTML_401Swing.getInstance());
+ }
+ return parser;
+ }
+
+ /**
+ * Inserts HTML into an existing document.
+ *
+ * @param doc - the Document to insert the HTML into.
+ * @param offset - where to begin inserting the HTML.
+ * @param html - the String to insert
+ * @param popDepth - the number of ElementSpec.EndTagTypes
+ * to generate before inserting
+ * @param pushDepth - the number of ElementSpec.StartTagTypes
+ * with a direction of ElementSpec.JoinNextDirection that
+ * should be generated before
+ * @param insertTag - the first tag to start inserting into document
+ * @throws IOException - on any I/O error
+ * @throws BadLocationException - if pos represents an invalid location
+ * within the document
+ */
+ public void insertHTML(HTMLDocument doc, int offset, String html,
+ int popDepth, int pushDepth, HTML.Tag insertTag)
+ throws BadLocationException, IOException
+ {
+ Parser parser = getParser();
+ if (offset < 0 || offset > doc.getLength())
+ throw new BadLocationException("Bad location", offset);
+ if (parser == null)
+ throw new IOException("Parser is null.");
+
+ ParserCallback pc = ((HTMLDocument) doc).getReader
+ (offset, popDepth, pushDepth, insertTag);
+
+ // FIXME: What should ignoreCharSet be set to?
+
+ // parser.parse inserts html into the buffer
+ parser.parse(new StringReader(html), pc, false);
+ pc.flush();
+ }
+
+ /**
+ * Inserts content from the given stream. Inserting HTML into a non-empty
+ * document must be inside the body Element, if you do not insert into
+ * the body an exception will be thrown. When inserting into a non-empty
+ * document all tags outside of the body (head, title) will be dropped.
+ *
+ * @param in - the stream to read from
+ * @param doc - the destination for the insertion
+ * @param pos - the location in the document to place the content
+ * @throws IOException - on any I/O error
+ * @throws BadLocationException - if pos represents an invalid location
+ * within the document
+ */
+ public void read(Reader in, Document doc, int pos) throws IOException,
+ BadLocationException
+ {
+ if (doc instanceof HTMLDocument)
+ {
+ Parser parser = getParser();
+ if (pos < 0 || pos > doc.getLength())
+ throw new BadLocationException("Bad location", pos);
+ if (parser == null)
+ throw new IOException("Parser is null.");
+
+ HTMLDocument hd = ((HTMLDocument) doc);
+ if (editorPane != null)
+ hd.setBase(editorPane.getPage());
+ ParserCallback pc = hd.getReader(pos);
+
+ // FIXME: What should ignoreCharSet be set to?
+
+ // parser.parse inserts html into the buffer
+ parser.parse(in, pc, false);
+ pc.flush();
+ }
+ else
+ // read in DefaultEditorKit is called.
+ // the string is inserted in the document as usual.
+ super.read(in, doc, pos);
+ }
+
+ /**
+ * Writes content from a document to the given stream in
+ * an appropriate format.
+ *
+ * @param out - the stream to write to
+ * @param doc - the source for the write
+ * @param pos - the location in the document to get the content.
+ * @param len - the amount to write out
+ * @throws IOException - on any I/O error
+ * @throws BadLocationException - if pos represents an invalid location
+ * within the document
+ */
+ public void write(Writer out, Document doc, int pos, int len)
+ throws IOException, BadLocationException
+ {
+ if (doc instanceof HTMLDocument)
+ {
+ // FIXME: Not implemented. Use HTMLWriter.
+ out.write(doc.getText(pos, len));
+ }
+ else
+ super.write(out, doc, pos, len);
+ }
+
+ /**
+ * Gets the content type that the kit supports.
+ * This kit supports the type text/html.
+ *
+ * @returns the content type supported.
+ */
+ public String getContentType()
+ {
+ return contentType;
+ }
+
+ /**
+ * Creates a copy of the editor kit.
+ *
+ * @return a copy of this.
+ */
+ public Object clone()
+ {
+ // FIXME: Need to clone all fields
+ return (HTMLEditorKit) super.clone();
+ }
+
+ /**
+ * Copies the key/values in elements AttributeSet into set.
+ * This does not copy component, icon, or element names attributes.
+ * This is called anytime the caret moves over a different location.
+ *
+ * @param element - the element to create the input attributes for.
+ * @param set - the set to copy the values into.
+ */
+ protected void createInputAttributes(Element element,
+ MutableAttributeSet set)
+ {
+ set.removeAttributes(set);
+ set.addAttributes(element.getAttributes());
+ // FIXME: Not fully implemented.
+ }
+
+ /**
+ * Called when this is installed into the JEditorPane.
+ *
+ * @param c - the JEditorPane installed into.
+ */
+ public void install(JEditorPane c)
+ {
+ super.install(c);
+ mouseListener = new LinkController();
+ c.addMouseListener(mouseListener);
+ editorPane = c;
+ // FIXME: need to set up hyperlinklistener object
+ }
+
+ /**
+ * Called when the this is removed from the JEditorPane.
+ * It unregisters any listeners.
+ *
+ * @param c - the JEditorPane being removed from.
+ */
+ public void deinstall(JEditorPane c)
+ {
+ super.deinstall(c);
+ c.removeMouseListener(mouseListener);
+ mouseListener = null;
+ editorPane = null;
+ }
+
+ /**
+ * Gets the AccessibleContext associated with this.
+ *
+ * @return the AccessibleContext for this.
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ // FIXME: Should return an instance of
+ // javax.swing.text.html.AccessibleHTML$RootHTMLAccessibleContext
+ // Not implemented yet.
+ return null;
+ }
+
+ /**
+ * Gets the action list. This list is supported by the superclass
+ * augmented by the collection of actions defined locally for style
+ * operations.
+ *
+ * @return an array of all the actions
+ */
+ public Action[] getActions()
+ {
+ return TextAction.augmentList(super.getActions(), defaultActions);
+ }
+
+ /**
+ * Returns the default cursor.
+ *
+ * @return the default cursor
+ */
+ public Cursor getDefaultCursor()
+ {
+ if (defaultCursor == null)
+ defaultCursor = Cursor.getDefaultCursor();
+ return defaultCursor;
+ }
+
+ /**
+ * Returns the cursor for links.
+ *
+ * @return the cursor for links.
+ */
+ public Cursor getLinkCursor()
+ {
+ if (linkCursor == null)
+ linkCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
+ return linkCursor;
+ }
+
+ /**
+ * Sets the Cursor for links.
+ *
+ * @param cursor - the new cursor for links.
+ */
+ public void setLinkCursor(Cursor cursor)
+ {
+ linkCursor = cursor;
+ }
+
+ /**
+ * Sets the default cursor.
+ *
+ * @param cursor - the new default cursor.
+ */
+ public void setDefaultCursor(Cursor cursor)
+ {
+ defaultCursor = cursor;
+ }
+
+ /**
+ * Gets the input attributes used for the styled editing actions.
+ *
+ * @return the attribute set
+ */
+ public MutableAttributeSet getInputAttributes()
+ {
+ return inputAttributes;
+ }
+
+ /**
+ * Get the set of styles currently being used to render the HTML elements.
+ * By default the resource specified by DEFAULT_CSS gets loaded, and is
+ * shared by all HTMLEditorKit instances.
+ *
+ * @return the style sheet.
+ */
+ public StyleSheet getStyleSheet()
+ {
+ if (styleSheet == null)
+ {
+ styleSheet = new StyleSheet();
+ styleSheet.importStyleSheet(getClass().getResource(DEFAULT_CSS));
+ }
+ return styleSheet;
+ }
+
+ /**
+ * Set the set of styles to be used to render the various HTML elements.
+ * These styles are specified in terms of CSS specifications. Each document
+ * produced by the kit will have a copy of the sheet which it can add the
+ * document specific styles to. By default, the StyleSheet specified is shared
+ * by all HTMLEditorKit instances.
+ *
+ * @param s - the new style sheet
+ */
+ public void setStyleSheet(StyleSheet s)
+ {
+ styleSheet = s;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLFrameHyperlinkEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLFrameHyperlinkEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLFrameHyperlinkEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/HTMLFrameHyperlinkEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,130 @@
+/* HTMLFrameHyperlinkEvent.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import java.net.URL;
+
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.text.Element;
+
+/**
+ * HTMLFrameHyperlinkEvent transfers information about the link that was
+ * activated in a frame.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
+ */
+public class HTMLFrameHyperlinkEvent extends HyperlinkEvent
+{
+ private final String target_frame;
+
+ /**
+ * Creates a new hypertext link event.
+ *
+ * @param source The object this link is associated to.
+ * @param type The type of event.
+ * @param url The URL this link pointing too.
+ * @param element The element in the document representing the anchor.
+ * @param frame - the Frame to display the document in.
+ */
+ public HTMLFrameHyperlinkEvent(Object source, EventType type, URL url,
+ Element element, String frame)
+ {
+ super(source, type, url, frame, element);
+ target_frame = frame;
+ }
+
+ /**
+ * Creates a new hypertext link event.
+ *
+ * @param source The object this link is associated to.
+ * @param type The type of event.
+ * @param url The URL this link pointing too.
+ * @param frame - the Frame to display the document in.
+ */
+ public HTMLFrameHyperlinkEvent(Object source, EventType type, URL url,
+ String frame)
+ {
+ super(source, type, url, frame);
+ target_frame = frame;
+ }
+
+ /**
+ * Creates a new hypertext link event.
+ *
+ * @param source The object this link is associated to.
+ * @param type The type of event.
+ * @param url The URL this link pointing too.
+ * @param description The description for this link.
+ * @param element The element in the document representing the anchor.
+ * @param frame - the Frame to display the document in.
+ */
+ public HTMLFrameHyperlinkEvent(Object source, EventType type, URL url,
+ String description, Element element,
+ String frame)
+ {
+ super(source, type, url, description, element);
+ target_frame = frame;
+ }
+
+ /**
+ * Creates a new hypertext link event.
+ *
+ * @param source The object this link is associated to.
+ * @param type The type of event.
+ * @param url The URL this link pointing too.
+ * @param description The description for this link.
+ * @param frame - the Frame to display the document in.
+ */
+ public HTMLFrameHyperlinkEvent(Object source, EventType type, URL url,
+ String description, String frame)
+ {
+ super(source, type, url, description);
+ target_frame = frame;
+ }
+
+ /**
+ * Gets the string, passed as the target frame identifier.
+ *
+ * @return the target for the link.
+ */
+ public String getTarget()
+ {
+ return target_frame;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ImageView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ImageView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ImageView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ImageView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,441 @@
+package javax.swing.text.html;
+
+import gnu.javax.swing.text.html.CombinedAttributes;
+import gnu.javax.swing.text.html.ImageViewIconFactory;
+
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.MediaTracker;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+import javax.swing.text.View;
+import javax.swing.text.Position.Bias;
+import javax.swing.text.html.HTML.Attribute;
+
+/**
+ * A view, representing a single image, represented by the HTML IMG tag.
+ *
+ * @author Audrius Meskauskas (AudriusA at Bioinformatics.org)
+ */
+public class ImageView extends View
+{
+ /**
+ * True if the image loads synchronuosly (on demand). By default, the image
+ * loads asynchronuosly.
+ */
+ boolean loadOnDemand;
+
+ /**
+ * The image icon, wrapping the image,
+ */
+ ImageIcon imageIcon;
+
+ /**
+ * The image state.
+ */
+ byte imageState = MediaTracker.LOADING;
+
+ /**
+ * Creates the image view that represents the given element.
+ *
+ * @param element the element, represented by this image view.
+ */
+ public ImageView(Element element)
+ {
+ super(element);
+ }
+
+ /**
+ * Load or reload the image. This method initiates the image reloading. After
+ * the image is ready, the repaint event will be scheduled. The current image,
+ * if it already exists, will be discarded.
+ *
+ * @param itsTime
+ * also load if the "on demand" property is set
+ */
+ void reloadImage(boolean itsTime)
+ {
+ URL url = getImageURL();
+ if (url == null)
+ imageState = (byte) MediaTracker.ERRORED;
+ else if (!(loadOnDemand && !itsTime))
+ imageIcon = new ImageIcon(url);
+ else
+ imageState = (byte) MediaTracker.LOADING;
+ }
+
+ /**
+ * Get the image alignment. This method works handling standart alignment
+ * attributes in the HTML IMG tag (align = top bottom middle left right).
+ * Depending from the parameter, either horizontal or vertical alingment
+ * information is returned.
+ *
+ * @param axis -
+ * either X_AXIS or Y_AXIS
+ */
+ public float getAlignment(int axis)
+ {
+ AttributeSet attrs = getAttributes();
+ Object al = attrs.getAttribute(Attribute.ALIGN);
+
+ // Default is top left aligned.
+ if (al == null)
+ return 0.0f;
+
+ String align = al.toString();
+
+ if (axis == View.X_AXIS)
+ {
+ if (align.equals("middle"))
+ return 0.5f;
+ else if (align.equals("left"))
+ return 0.0f;
+ else if (align.equals("right"))
+ return 1.0f;
+ else
+ return 0.0f;
+ }
+ else if (axis == View.Y_AXIS)
+ {
+ if (align.equals("middle"))
+ return 0.5f;
+ else if (align.equals("top"))
+ return 0.0f;
+ else if (align.equals("bottom"))
+ return 1.0f;
+ else
+ return 0.0f;
+ }
+ else
+ throw new IllegalArgumentException("axis " + axis);
+ }
+
+ /**
+ * Get the text that should be shown as the image replacement and also as the
+ * image tool tip text. The method returns the value of the attribute, having
+ * the name {@link Attribute#ALT}. If there is no such attribute, the image
+ * name from the url is returned. If the URL is not available, the empty
+ * string is returned.
+ */
+ public String getAltText()
+ {
+ Object rt = getAttributes().getAttribute(Attribute.ALT);
+ if (rt != null)
+ return rt.toString();
+ else
+ {
+ URL u = getImageURL();
+ if (u == null)
+ return "";
+ else
+ return u.getFile();
+ }
+ }
+
+ /**
+ * Returns the combination of the document and the style sheet attributes.
+ */
+ public AttributeSet getAttributes()
+ {
+ StyleSheet styles = getStyleSheet();
+ if (styles == null)
+ return super.getAttributes();
+ else
+ return CombinedAttributes.combine(super.getAttributes(),
+ styles.getViewAttributes(this));
+ }
+
+ /**
+ * Get the image to render. May return null if the image is not yet loaded.
+ */
+ public Image getImage()
+ {
+ if (imageIcon == null)
+ return null;
+ else
+ return imageIcon.getImage();
+ }
+
+ /**
+ * Get the URL location of the image to render. If this method returns null,
+ * the "no image" icon is rendered instead. By defaul, url must be present as
+ * the "src" property of the IMG tag. If it is missing, null is returned and
+ * the "no image" icon is rendered.
+ *
+ * @return the URL location of the image to render.
+ */
+ public URL getImageURL()
+ {
+ Object url = getAttributes().getAttribute(Attribute.SRC);
+ if (url == null)
+ return null;
+
+ try
+ {
+ return new URL(url.toString());
+ }
+ catch (MalformedURLException e)
+ {
+ // The URL is malformed - no image.
+ return null;
+ }
+ }
+
+ /**
+ * Get the icon that should be displayed while the image is loading and hence
+ * not yet available.
+ *
+ * @return an icon, showing a non broken sheet of paper with image.
+ */
+ public Icon getLoadingImageIcon()
+ {
+ return ImageViewIconFactory.getLoadingImageIcon();
+ }
+
+ /**
+ * Get the image loading strategy.
+ *
+ * @return false (default) if the image is loaded when the view is
+ * constructed, true if the image is only loaded on demand when
+ * rendering.
+ */
+ public boolean getLoadsSynchronously()
+ {
+ return loadOnDemand;
+ }
+
+ /**
+ * Get the icon that should be displayed when the image is not available.
+ *
+ * @return an icon, showing a broken sheet of paper with image.
+ */
+ public Icon getNoImageIcon()
+ {
+ return ImageViewIconFactory.getNoImageIcon();
+ }
+
+ /**
+ * Get the preferred span of the image along the axis. The image size is first
+ * requested to the attributes {@link Attribute#WIDTH} and
+ * {@link Attribute#HEIGHT}. If they are missing, and the image is already
+ * loaded, the image size is returned. If there are no attributes, and the
+ * image is not loaded, zero is returned.
+ *
+ * @param axis -
+ * either X_AXIS or Y_AXIS
+ * @return either width of height of the image, depending on the axis.
+ */
+ public float getPreferredSpan(int axis)
+ {
+ AttributeSet attrs = getAttributes();
+
+ Image image = getImage();
+
+ if (axis == View.X_AXIS)
+ {
+ Object w = attrs.getAttribute(Attribute.WIDTH);
+ if (w != null)
+ return Integer.parseInt(w.toString());
+ else if (image != null)
+ return image.getWidth(getContainer());
+ else
+ return getNoImageIcon().getIconWidth();
+ }
+ else if (axis == View.Y_AXIS)
+ {
+ Object w = attrs.getAttribute(Attribute.HEIGHT);
+ if (w != null)
+ return Integer.parseInt(w.toString());
+ else if (image != null)
+ return image.getHeight(getContainer());
+ else
+ return getNoImageIcon().getIconHeight();
+ }
+ else
+ throw new IllegalArgumentException("axis " + axis);
+ }
+
+ /**
+ * Get the associated style sheet from the document.
+ *
+ * @return the associated style sheet.
+ */
+ protected StyleSheet getStyleSheet()
+ {
+ Document d = getElement().getDocument();
+ if (d instanceof HTMLDocument)
+ return ((HTMLDocument) d).getStyleSheet();
+ else
+ return null;
+ }
+
+ /**
+ * Get the tool tip text. This is overridden to return the value of the
+ * {@link #getAltText()}. The parameters are ignored.
+ *
+ * @return that is returned by getAltText().
+ */
+ public String getToolTipText(float x, float y, Shape shape)
+ {
+ return getAltText();
+ }
+
+ /**
+ * Paints the image or one of the two image state icons. The image is resized
+ * to the shape bounds. If there is no image available, the alternative text
+ * is displayed besides the image state icon.
+ *
+ * @param g
+ * the Graphics, used for painting.
+ * @param bounds
+ * the bounds of the region where the image or replacing icon must be
+ * painted.
+ */
+ public void paint(Graphics g, Shape bounds)
+ {
+ Rectangle r = bounds.getBounds();
+
+ if (imageIcon == null)
+
+ {
+ // Loading image on demand, rendering the loading icon so far.
+ reloadImage(true);
+
+ // The reloadImage sets the imageIcon, unless the URL is broken
+ // or malformed.
+ if (imageIcon != null)
+ {
+ if (imageIcon.getImageLoadStatus() != MediaTracker.COMPLETE)
+ {
+ // Render "not ready" icon, unless the image is ready
+ // immediately.
+ renderIcon(g, r, getLoadingImageIcon());
+ // Add the listener to repaint when the icon will be ready.
+ imageIcon.setImageObserver(getContainer());
+ return;
+ }
+ }
+ else
+ {
+ renderIcon(g, r, getNoImageIcon());
+ return;
+ }
+ }
+
+ imageState = (byte) imageIcon.getImageLoadStatus();
+
+ switch (imageState)
+ {
+ case MediaTracker.ABORTED:
+ case MediaTracker.ERRORED:
+ renderIcon(g, r, getNoImageIcon());
+ break;
+ case MediaTracker.LOADING:
+ // If the image is not loaded completely, we still render it, as the
+ // partial image may be available.
+ case MediaTracker.COMPLETE:
+ {
+ // Paint the scaled image.
+ Image scaled = imageIcon.getImage().getScaledInstance(
+ r.width,
+ r.height,
+ Image.SCALE_DEFAULT);
+ ImageIcon painter = new ImageIcon(scaled);
+ painter.paintIcon(getContainer(), g, r.x, r.y);
+ }
+ break;
+ }
+ }
+
+ /**
+ * Render "no image" icon and the alternative "no image" text. The text is
+ * rendered right from the icon and is aligned to the icon bottom.
+ */
+ private void renderIcon(Graphics g, Rectangle bounds, Icon icon)
+ {
+ Shape current = g.getClip();
+ try
+ {
+ g.setClip(bounds);
+ if (icon != null)
+ {
+ icon.paintIcon(getContainer(), g, bounds.x, bounds.y);
+ g.drawString(getAltText(), bounds.x + icon.getIconWidth(),
+ bounds.y + icon.getIconHeight());
+ }
+ }
+ finally
+ {
+ g.setClip(current);
+ }
+ }
+
+ /**
+ * Set if the image should be loaded only when needed (synchronuosly). By
+ * default, the image loads asynchronuosly. If the image is not yet ready, the
+ * icon, returned by the {@link #getLoadingImageIcon()}, is displayed.
+ */
+ public void setLoadsSynchronously(boolean load_on_demand)
+ {
+ loadOnDemand = load_on_demand;
+ }
+
+ /**
+ * Update all cached properties from the attribute set, returned by the
+ * {@link #getAttributes}.
+ */
+ protected void setPropertiesFromAttributes()
+ {
+ // In the current implementation, nothing is cached yet, unless the image
+ // itself.
+ imageIcon = null;
+ }
+
+ /**
+ * Maps the picture co-ordinates into the image position in the model. As the
+ * image is not divideable, this is currently implemented always to return the
+ * start offset.
+ */
+ public int viewToModel(float x, float y, Shape shape, Bias[] bias)
+ {
+ return getStartOffset();
+ }
+
+ /**
+ * This is currently implemented always to return the area of the image view,
+ * as the image is not divideable by character positions.
+ *
+ * @param pos character position
+ * @param area of the image view
+ * @param bias bias
+ *
+ * @return the shape, where the given character position should be mapped.
+ */
+ public Shape modelToView(int pos, Shape area, Bias bias)
+ throws BadLocationException
+ {
+ return area;
+ }
+
+ /**
+ * Starts loading the image asynchronuosly. If the image must be loaded
+ * synchronuosly instead, the {@link #setLoadsSynchronously} must be
+ * called before calling this method. The passed parameters are not used.
+ */
+ public void setSize(float width, float height)
+ {
+ if (imageIcon == null)
+ reloadImage(false);
+ }
+
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/InlineView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/InlineView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/InlineView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/InlineView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,166 @@
+/* InlineView.java -- Renders HTML content
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import java.awt.Shape;
+
+import javax.swing.event.DocumentEvent;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+import javax.swing.text.LabelView;
+import javax.swing.text.View;
+import javax.swing.text.ViewFactory;
+
+/**
+ * Renders HTML content (identified by {@link HTML.Tag#CONTENT}). This is
+ * basically a {@link LabelView} that is adjusted to understand styles defined
+ * by stylesheets.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+public class InlineView
+ extends LabelView
+{
+
+ /**
+ * Creates a new <code>InlineView</code> that renders the specified element.
+ *
+ * @param element the element for this view
+ */
+ public InlineView(Element element)
+ {
+ super(element);
+ }
+
+ /**
+ * Receives notification that something was inserted into the document in
+ * a location that this view is responsible for.
+ *
+ * @param e the document event
+ * @param a the current allocation of this view
+ * @param f the view factory for creating new views
+ *
+ * @since 1.5
+ */
+ public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f)
+ {
+ // FIXME: What to do here?
+ super.insertUpdate(e, a, f);
+ }
+
+ /**
+ * Receives notification that something was removed from the document in
+ * a location that this view is responsible for.
+ *
+ * @param e the document event
+ * @param a the current allocation of this view
+ * @param f the view factory for creating new views
+ *
+ * @since 1.5
+ */
+ public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f)
+ {
+ // FIXME: What to do here?
+ super.removeUpdate(e, a, f);
+ }
+
+ /**
+ * Receives notification that attributes have changed in the document in
+ * a location that this view is responsible for. This calls
+ * {@link #setPropertiesFromAttributes}.
+ *
+ * @param e the document event
+ * @param a the current allocation of this view
+ * @param f the view factory for creating new views
+ *
+ * @since 1.5
+ */
+ public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f)
+ {
+ super.changedUpdate(e, a, f);
+ setPropertiesFromAttributes();
+ }
+
+ /**
+ * Returns the attributes that are used for rendering. This is implemented
+ * to multiplex the attributes specified in the model with a stylesheet.
+ *
+ * @return the attributes that are used for rendering
+ */
+ public AttributeSet getAttributes()
+ {
+ // FIXME: Implement this.
+ return super.getAttributes();
+ }
+
+
+ public int getBreakWeight(int axis, float pos, float len)
+ {
+ // FIXME: Implement this.
+ return super.getBreakWeight(axis, pos, len);
+ }
+
+ public View breakView(int axis, int offset, float pos, float len)
+ {
+ // FIXME: Implement this.
+ return super.breakView(axis, offset, pos, len);
+ }
+
+ protected void setPropertiesFromAttributes()
+ {
+ // FIXME: Implement this.
+ super.setPropertiesFromAttributes();
+ }
+
+ /**
+ * Returns the stylesheet used by this view. This returns the stylesheet
+ * of the <code>HTMLDocument</code> that is rendered by this view.
+ *
+ * @return the stylesheet used by this view
+ */
+ protected StyleSheet getStyleSheet()
+ {
+ Document doc = getDocument();
+ StyleSheet styleSheet = null;
+ if (doc instanceof HTMLDocument)
+ styleSheet = ((HTMLDocument) doc).getStyleSheet();
+ return styleSheet;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ListView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ListView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ListView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ListView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,131 @@
+/* ListView.java --
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.text.html;
+
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.Shape;
+
+import javax.swing.text.Element;
+
+/**
+ * A View to render HTML lists, like the <code><ul></code> and
+ * <code><ol></code> tags.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+public class ListView
+ extends BlockView
+{
+
+ /**
+ * The painter used to paint the list items.
+ */
+ private StyleSheet.ListPainter painter;
+
+ /**
+ * Creates a new <code>ListView</code> for the specified element.
+ *
+ * @param el the element to create a list view for
+ */
+ public ListView(Element el)
+ {
+ super(el, Y_AXIS);
+ }
+
+ /**
+ * Returns the alignment of this view along the specified axis.
+ *
+ * This returns <code>0.5</code> unconditionally.
+ *
+ * @param axis the axis
+ *
+ * @return the alignment of this view along the specified axis
+ */
+ public float getAlignment(int axis)
+ {
+ if (axis != X_AXIS && axis != Y_AXIS)
+ throw new IllegalArgumentException("Illegal axis parameter: " + axis);
+
+ return 0.5F;
+ }
+
+ /**
+ * Paints the <code>ListView</code>.
+ *
+ * @param g the graphics context to use for painting
+ * @param allocation the allocation given to this view
+ */
+ public void paint(Graphics g, Shape allocation)
+ {
+ super.paint(g, allocation);
+ // FIXME: Why is this overridden? I think that painting would be done
+ // by the superclass and the stylesheet... Maybe find out when this
+ // stuff is implemented properly.
+ }
+
+ /**
+ * Paints the child with the specified index into the specified allocation.
+ *
+ * This implementation forwards to the list painter fetched from the
+ * {@link StyleSheet} and then calls
+ * <code>super.paintChild(g, a, index)</code>.
+ *
+ * @param g the graphics context to use
+ * @param a the allocation for the child
+ * @param index the child index
+ */
+ protected void paintChild(Graphics g, Rectangle a, int index)
+ {
+ painter.paint(g, a.x, a.y, a.width, a.height, this, index);
+ super.paintChild(g, a, index);
+ }
+
+ /**
+ * Fetches this view's properties from the style attributes of this view's
+ * element.
+ *
+ * This forwards to super and then fetches a {@link StyleSheet.ListPainter}
+ * from the stylesheet suitable for painting the list.
+ */
+ protected void setPropertiesFromAttributes()
+ {
+ super.setPropertiesFromAttributes();
+ painter = getStyleSheet().getListPainter(getAttributes());
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/MinimalHTMLWriter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/MinimalHTMLWriter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/MinimalHTMLWriter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/MinimalHTMLWriter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,452 @@
+/* MinimalHTMLWriter.java --
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.text.html;
+
+import javax.swing.text.AttributeSet;
+import javax.swing.text.AbstractWriter;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+import javax.swing.text.ElementIterator;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.Style;
+import javax.swing.text.StyledDocument;
+import java.io.Writer;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Stack;
+import java.awt.Color;
+
+/**
+ * MinimalHTMLWriter,
+ * A minimal AbstractWriter implementation for HTML.
+ *
+ * @author Sven de Marothy
+ */
+public class MinimalHTMLWriter extends AbstractWriter
+{
+ private StyledDocument doc;
+ private Stack tagStack;
+ private boolean inFontTag = false;
+
+ /**
+ * Constructs a MinimalHTMLWriter.
+ * @param w - a Writer, for output.
+ * @param doc - the document
+ */
+ public MinimalHTMLWriter(Writer w, StyledDocument doc)
+ {
+ super(w, doc);
+ this.doc = doc;
+ tagStack = new Stack();
+ }
+
+ /**
+ * Constructs a MinimalHTMLWriter.
+ * @param w - a Writer, for output.
+ * @param doc - the document
+ * @param pos - start position
+ * @param len - length
+ */
+ public MinimalHTMLWriter(Writer w, StyledDocument doc, int pos, int len)
+ {
+ super(w, doc, pos, len);
+ this.doc = doc;
+ tagStack = new Stack();
+ }
+
+ /**
+ * Starts a span tag.
+ */
+ protected void startFontTag(String style) throws IOException
+ {
+ if( inFontTag() )
+ endOpenTags();
+ writeStartTag("<span style=\""+style+"\">");
+ inFontTag = true;
+ }
+
+ /**
+ * Returns whether the writer is within two span tags.
+ */
+ protected boolean inFontTag()
+ {
+ return inFontTag;
+ }
+
+ /**
+ * Ends a span tag.
+ */
+ protected void endFontTag() throws IOException
+ {
+ writeEndTag("</span>");
+ inFontTag = false;
+ }
+
+ /**
+ * Write the entire HTML document.
+ */
+ public synchronized void write() throws IOException, BadLocationException
+ {
+ writeStartTag("<html>");
+ writeHeader();
+ writeBody();
+ writeEndTag("</html>");
+ }
+
+ /**
+ * Write a start tag and increment the indent.
+ */
+ protected void writeStartTag(String tag) throws IOException
+ {
+ indent();
+ write(tag+NEWLINE);
+ incrIndent();
+ }
+
+ /**
+ * Write an ending tag and decrement the indent.
+ */
+ protected void writeEndTag(String endTag) throws IOException
+ {
+ decrIndent();
+ indent();
+ write(endTag+NEWLINE);
+ }
+
+ /**
+ * Write the HTML header.
+ */
+ protected void writeHeader() throws IOException
+ {
+ writeStartTag("<head>");
+ writeStartTag("<style>");
+ writeStartTag("<!--");
+ writeStyles();
+ writeEndTag("-->");
+ writeEndTag("</style>");
+ writeEndTag("</head>");
+ }
+
+ /**
+ * Write a paragraph start tag.
+ */
+ protected void writeStartParagraph(Element elem) throws IOException
+ {
+ indent();
+ write("<p class=default>"+NEWLINE); // FIXME: Class value = ?
+ incrIndent();
+ }
+
+ /**
+ * Write a paragraph end tag, closes any other open tags.
+ */
+ protected void writeEndParagraph() throws IOException
+ {
+ endOpenTags();
+ writeEndTag("</p>");
+ }
+
+ /**
+ * Writes the body of the HTML document.
+ */
+ protected void writeBody() throws IOException, BadLocationException
+ {
+ writeStartTag("<body>");
+
+ ElementIterator ei = getElementIterator();
+ Element e = ei.first();
+ boolean inParagraph = false;
+ do
+ {
+ if( e.isLeaf() )
+ {
+ boolean hasNL = (getText(e).indexOf(NEWLINE) != -1);
+ if( !inParagraph && hasText( e ) )
+ {
+ writeStartParagraph(e);
+ inParagraph = true;
+ }
+
+ if( hasText( e ) )
+ writeContent(e, true);
+
+ if( hasNL && inParagraph )
+ {
+ writeEndParagraph();
+ inParagraph = false;
+ }
+ else
+ endOpenTags();
+ }
+ }
+ while((e = ei.next()) != null);
+
+ writeEndTag("</body>");
+ }
+
+ protected void text(Element elem) throws IOException, BadLocationException
+ {
+ write( getText(elem).trim() );
+ }
+
+ /**
+ * Write bold, indent and underline tags.
+ */
+ protected void writeHTMLTags(AttributeSet attr) throws IOException
+ {
+ if(attr.getAttribute(StyleConstants.Bold) != null)
+ if(((Boolean)attr.getAttribute(StyleConstants.Bold)).booleanValue())
+ {
+ write("<b>");
+ tagStack.push("</b>");
+ }
+ if(attr.getAttribute(StyleConstants.Italic) != null)
+ if(((Boolean)attr.getAttribute(StyleConstants.Italic)).booleanValue())
+ {
+ write("<i>");
+ tagStack.push("</i>");
+ }
+ if(attr.getAttribute(StyleConstants.Underline) != null)
+ if(((Boolean)attr.getAttribute(StyleConstants.Underline)).booleanValue())
+ {
+ write("<u>");
+ tagStack.push("</u>");
+ }
+ }
+
+ /**
+ * Returns whether the element contains text or not.
+ */
+ protected boolean isText(Element elem)
+ {
+ return (elem.getEndOffset() != elem.getStartOffset());
+ }
+
+ /**
+ * Writes the content of an element.
+ */
+ protected void writeContent(Element elem, boolean needsIndenting)
+ throws IOException, BadLocationException
+ {
+ writeNonHTMLAttributes(elem.getAttributes());
+ if(needsIndenting)
+ indent();
+ writeHTMLTags(elem.getAttributes());
+ if( isText(elem) )
+ text(elem);
+ else
+ writeLeaf(elem);
+
+ endOpenTags();
+ }
+
+ /**
+ * Writes a non-text leaf element.
+ */
+ protected void writeLeaf(Element e) throws IOException
+ {
+ // NOTE: Haven't tested if this is correct.
+ if(e.getName().equals(StyleConstants.IconElementName))
+ writeImage(e);
+ else
+ writeComponent(e);
+ }
+
+ /**
+ * Write the HTML attributes which do not have tag equivalents,
+ * e.g. attributes other than bold/italic/underlined.
+ */
+ protected void writeNonHTMLAttributes(AttributeSet attr) throws IOException
+ {
+ String style = "";
+
+ // Alignment? Background?
+
+ if( StyleConstants.getForeground(attr) != null )
+ style = style + "color: " +
+ getColor(StyleConstants.getForeground(attr)) + "; ";
+
+ style = style + "font-size: "+StyleConstants.getFontSize(attr)+"pt; ";
+ style = style + "font-family: "+StyleConstants.getFontFamily(attr);
+
+ startFontTag(style);
+ }
+
+ /**
+ * Write the styles used.
+ */
+ protected void writeStyles() throws IOException
+ {
+ if(doc instanceof DefaultStyledDocument)
+ {
+ Enumeration styles = ((DefaultStyledDocument)doc).getStyleNames();
+ while(styles.hasMoreElements())
+ writeStyle(doc.getStyle((String)styles.nextElement()));
+ }
+ else
+ { // What else to do here?
+ Style s = (Style)doc.getStyle("default");
+ if(s != null)
+ writeStyle( s );
+ }
+ }
+
+ /**
+ * Write a set of attributes.
+ */
+ protected void writeAttributes(AttributeSet attr) throws IOException
+ {
+ Enumeration attribs = attr.getAttributeNames();
+ while(attribs.hasMoreElements())
+ {
+ Object attribName = attribs.nextElement();
+ String name = attribName.toString();
+ String output = getAttribute(name, attr.getAttribute(attribName));
+ if( output != null )
+ {
+ indent();
+ write( output + NEWLINE );
+ }
+ }
+ }
+
+ /**
+ * Deliberately unimplemented, handles component elements.
+ */
+ protected void writeComponent(Element elem) throws IOException
+ {
+ }
+
+ /**
+ * Deliberately unimplemented.
+ * Writes StyleConstants.IconElementName elements.
+ */
+ protected void writeImage(Element elem) throws IOException
+ {
+ }
+
+ // -------------------- Private methods. --------------------------------
+
+ /**
+ * Write a single style attribute
+ */
+ private String getAttribute(String name, Object a) throws IOException
+ {
+ if(name.equals("foreground"))
+ return "foreground:"+getColor((Color)a)+";";
+ if(name.equals("background"))
+ return "background:"+getColor((Color)a)+";";
+ if(name.equals("italic"))
+ return "italic:"+(((Boolean)a).booleanValue() ? "italic;" : ";");
+ if(name.equals("bold"))
+ return "bold:"+(((Boolean)a).booleanValue() ? "bold;" : "normal;");
+ if(name.equals("family"))
+ return "family:" + a + ";";
+ if(name.equals("size"))
+ {
+ int size = ((Integer)a).intValue();
+ int htmlSize;
+ if( size > 24 )
+ htmlSize = 7;
+ else if( size > 18 )
+ htmlSize = 6;
+ else if( size > 14 )
+ htmlSize = 5;
+ else if( size > 12 )
+ htmlSize = 4;
+ else if( size > 10 )
+ htmlSize = 3;
+ else if( size > 8 )
+ htmlSize = 2;
+ else
+ htmlSize = 1;
+
+ return "size:" + htmlSize + ";";
+ }
+
+ return null;
+ }
+
+ /**
+ * Stupid that Color doesn't have a method for this.
+ */
+ private String getColor(Color c)
+ {
+ String r = "00" + Integer.toHexString(c.getRed());
+ r = r.substring(r.length() - 2);
+ String g = "00" + Integer.toHexString(c.getGreen());
+ g = g.substring(g.length() - 2);
+ String b = "00" + Integer.toHexString(c.getBlue());
+ b = b.substring(b.length() - 2);
+ return "#" + r + g + b;
+ }
+
+ /**
+ * Empty the stack of open tags
+ */
+ private void endOpenTags() throws IOException
+ {
+ while(!tagStack.empty())
+ write((String)tagStack.pop());
+
+ if( inFontTag() )
+ {
+ write(""+NEWLINE);
+ endFontTag();
+ }
+ }
+
+ /**
+ * Output a single style
+ */
+ private void writeStyle(Style s) throws IOException
+ {
+ if( s == null )
+ return;
+
+ writeStartTag("p."+s.getName()+" {");
+ writeAttributes(s);
+ writeEndTag("}");
+ }
+
+ private boolean hasText(Element e) throws BadLocationException
+ {
+ return (getText(e).trim().length() > 0);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/NullView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/NullView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/NullView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/NullView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,102 @@
+/* NullView.java -- A dummy view that renders nothing
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import java.awt.Graphics;
+import java.awt.Shape;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Element;
+import javax.swing.text.View;
+import javax.swing.text.Position.Bias;
+
+/**
+ * A dummy view that renders nothing. This is used for invisible HTML elements
+ * like <head>.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+class NullView
+ extends View
+{
+
+ /**
+ * Creates a new NullView.
+ *
+ * @param elem the element
+ */
+ public NullView(Element elem)
+ {
+ super(elem);
+ }
+
+ /**
+ * Does nothing.
+ */
+ public void paint(Graphics g, Shape s)
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Returns zero for both directions.
+ */
+ public float getPreferredSpan(int axis)
+ {
+ return 0;
+ }
+
+ /**
+ * Returns the allocation of this view, which should be empty anyway.
+ */
+ public Shape modelToView(int pos, Shape a, Bias b)
+ throws BadLocationException
+ {
+ return a;
+ }
+
+ /**
+ * Returns the start offset of the element.
+ */
+ public int viewToModel(float x, float y, Shape a, Bias[] b)
+ {
+ return getElement().getStartOffset();
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ObjectView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ObjectView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ObjectView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ObjectView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,110 @@
+/* ObjectView.java -- A view for HTML object tags
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import java.awt.Component;
+
+import javax.swing.text.AttributeSet;
+import javax.swing.text.ComponentView;
+import javax.swing.text.Element;
+
+/**
+ * A view for HTML <code><object></code> tags.
+ *
+ * This is a {@link ComponentView} that creates special components depending
+ * on the object specification. If the object tag has a classid attribute, then
+ * this view will try to load the class specified by this attribute using the
+ * classloader that loaded the associated document. If the class could be
+ * loaded, an instance is created and the type narrowed to {@link Component}.
+ *
+ * It is also possible to set bean properties on the created component using
+ * nested <code><param></code> tags. For example:
+ * <pre>
+ * <object classid="javax.swing.JLabel">
+ * <param name="text" value="sample text">
+ * </object>
+ * </pre>
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+public class ObjectView extends ComponentView
+{
+
+ /**
+ * Creates a new <code>ObjectView</code>.
+ *
+ * @param el the element for which to create a view
+ */
+ public ObjectView(Element el)
+ {
+ super(el);
+ }
+
+ /**
+ * Creates a component based on the specification in the element of this
+ * view. See the class description for details.
+ */
+ protected Component createComponent()
+ {
+ Component comp = null;
+ Element el = getElement();
+ AttributeSet atts = el.getAttributes();
+ String classId = (String) atts.getAttribute("classid");
+ try
+ {
+ Class objectClass = Class.forName(classId);
+ Object instance = objectClass.newInstance();
+ comp = (Component) instance;
+ }
+ catch (ClassNotFoundException ex)
+ {
+ // Ignored.
+ }
+ catch (IllegalAccessException ex)
+ {
+ // Ignored.
+ }
+ catch (InstantiationException ex)
+ {
+ // Ignored.
+ }
+ // FIXME: Handle param tags and set bean properties accordingly.
+ return comp;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/Option.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/Option.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/Option.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/Option.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,157 @@
+/* Option.java -- Value class for <option> list model elements
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import javax.swing.text.AttributeSet;
+
+/**
+ * Value class for the combobox model that renders <code><option></code>
+ * elements.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+public class Option
+{
+
+ /**
+ * The attributes of the <option> tag.
+ */
+ private AttributeSet attributes;
+
+ /**
+ * The label.
+ */
+ private String label;
+
+ /**
+ * The selected state of this label.
+ */
+ private boolean selected;
+
+ /**
+ * Creates a new <code>Option</code> instance that uses the specified
+ * tag attributes.
+ *
+ * @param attr the attributes to use
+ */
+ public Option(AttributeSet attr)
+ {
+ attributes = attr;
+ label = null;
+ selected = false;
+ // FIXME: Probably initialize something using the attributes.
+ }
+
+ /**
+ * Sets the label to use for this <code><option></code> tag.
+ *
+ * @param l the label to set
+ */
+ public void setLabel(String l)
+ {
+ label = l;
+ }
+
+ /**
+ * Returns the label of this <code><option></code> tag.
+ *
+ * @return the label of this <code><option></code> tag
+ */
+ public String getLabel()
+ {
+ return label;
+ }
+
+ /**
+ * Returns the attributes used to render this <code><option></code>
+ * tag.
+ *
+ * @return the attributes used to render this <code><option></code> tag
+ */
+ public AttributeSet getAttributes()
+ {
+ return attributes;
+ }
+
+ /**
+ * Returns a string representation of this <code><option></code> tag.
+ * This returns the <code>label</code> property.
+ *
+ * @return a string representation of this <code><option></code> tag
+ */
+ public String toString()
+ {
+ return label;
+ }
+
+ /**
+ * Sets the selected state of this <code><option></code> tag.
+ *
+ * @param s the selected state to set
+ */
+ protected void setSelection(boolean s)
+ {
+ selected = s;
+ }
+
+ /**
+ * Returns <code>true</code> when this option is selected, <code>false</code>
+ * otherwise.
+ *
+ * @return <code>true</code> when this option is selected, <code>false</code>
+ * otherwise
+ */
+ public boolean isSelected()
+ {
+ return selected;
+ }
+
+ /**
+ * Returns the string associated with the <code>value</code> attribute or
+ * the label, if no such attribute is specified.
+ *
+ * @return the string associated with the <code>value</code> attribute or
+ * the label, if no such attribute is specified
+ */
+ public String getValue()
+ {
+ // FIXME: Return some attribute here if specified.
+ return label;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ParagraphView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ParagraphView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ParagraphView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/ParagraphView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,209 @@
+/* ParagraphView.java -- Renders a paragraph in HTML
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import java.awt.Graphics;
+import java.awt.Shape;
+
+import javax.swing.SizeRequirements;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+import javax.swing.text.View;
+
+/**
+ * Renders a paragraph in HTML. This is a subclass of
+ * {@link javax.swing.text.ParagraphView} with some adjustments for
+ * understanding stylesheets.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+public class ParagraphView
+ extends javax.swing.text.ParagraphView
+{
+
+ /**
+ * Creates a new ParagraphView for the specified element.
+ *
+ * @param element the element
+ */
+ public ParagraphView(Element element)
+ {
+ super(element);
+ }
+
+ /**
+ * Sets the parent of this view. This is implemented to call the parent
+ * functionality and then trigger {@link #setPropertiesFromAttributes} in
+ * order to load the stylesheet attributes.
+ *
+ * @param parent the parent view to set
+ */
+ public void setParent(View parent)
+ {
+ super.setParent(parent);
+ if (parent != null)
+ setPropertiesFromAttributes();
+ }
+
+ /**
+ * Returns the attributes used by this view. This is implemented to multiplex
+ * the attributes of the model with the attributes of the stylesheet.
+ */
+ public AttributeSet getAttributes()
+ {
+ // FIXME: Implement this multiplexing thing.
+ return super.getAttributes();
+ }
+
+ /**
+ * Loads the visual properties of the ParagraphView from the element's
+ * attributes and the stylesheet of the HTML document.
+ */
+ protected void setPropertiesFromAttributes()
+ {
+ // FIXME: Implement this.
+ }
+
+ /**
+ * Returns the stylesheet used by this view.
+ *
+ * @return the stylesheet used by this view
+ */
+ protected StyleSheet getStyleSheet()
+ {
+ Document doc = getDocument();
+ StyleSheet styleSheet = null;
+ if (doc instanceof HTMLDocument)
+ styleSheet = ((HTMLDocument) doc).getStyleSheet();
+ return styleSheet;
+ }
+
+ /**
+ * Calculates the minor axis requirements of this view. This is implemented
+ * to return the super class'es requirements and modifies the minimumSpan
+ * slightly so that it is not smaller than the length of the longest word.
+ *
+ * @param axis the axis
+ * @param r the SizeRequirements object to be used as return parameter;
+ * if <code>null</code> a new one will be created
+ *
+ * @return the requirements along the minor layout axis
+ */
+ protected SizeRequirements calculateMinorAxisRequirements(int axis,
+ SizeRequirements r)
+ {
+ // FIXME: Implement the above specified behaviour.
+ return super.calculateMinorAxisRequirements(axis, r);
+ }
+
+ /**
+ * Determines if this view is visible or not. If none of the children is
+ * visible and the only visible child is the break that ends the paragraph,
+ * this paragraph is not considered to be visible.
+ *
+ * @return the visibility of this paragraph
+ */
+ public boolean isVisible()
+ {
+ // FIXME: Implement the above specified behaviour.
+ return super.isVisible();
+ }
+
+ /**
+ * Paints this view. This delegates to the superclass after the coordinates
+ * have been updated for tab calculations.
+ *
+ * @param g the graphics object
+ * @param a the current allocation of this view
+ */
+ public void paint(Graphics g, Shape a)
+ {
+ // FIXME: Implement the above specified behaviour.
+ super.paint(g, a);
+ }
+
+ /**
+ * Returns the preferred span of this view. If this view is not visible,
+ * we return <code>0</code>, otherwise the super class is called.
+ *
+ * @param axis the axis
+ *
+ * @return the preferred span of this view
+ */
+ public float getPreferredSpan(int axis)
+ {
+ float span = 0;
+ if (isVisible())
+ span = super.getPreferredSpan(axis);
+ return span;
+ }
+
+ /**
+ * Returns the minimum span of this view. If this view is not visible,
+ * we return <code>0</code>, otherwise the super class is called.
+ *
+ * @param axis the axis
+ *
+ * @return the minimum span of this view
+ */
+ public float getMinimumSpan(int axis)
+ {
+ float span = 0;
+ if (isVisible())
+ span = super.getMinimumSpan(axis);
+ return span;
+ }
+
+ /**
+ * Returns the maximum span of this view. If this view is not visible,
+ * we return <code>0</code>, otherwise the super class is called.
+ *
+ * @param axis the axis
+ *
+ * @return the maximum span of this view
+ */
+ public float getMaximumSpan(int axis)
+ {
+ float span = 0;
+ if (isVisible())
+ span = super.getMaximumSpan(axis);
+ return span;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/StyleSheet.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/StyleSheet.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/StyleSheet.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/StyleSheet.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,907 @@
+/* StyleSheet.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import gnu.javax.swing.text.html.CharacterAttributeTranslator;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Serializable;
+import java.io.StringReader;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Element;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.Style;
+import javax.swing.text.StyleContext;
+import javax.swing.text.View;
+
+
+/**
+ * This class adds support for defining the visual characteristics of HTML views
+ * being rendered. This enables views to be customized by a look-and-feel, mulitple
+ * views over the same model can be rendered differently. Each EditorPane has its
+ * own StyleSheet, but by default one sheet will be shared by all of the HTMLEditorKit
+ * instances. An HTMLDocument can also have a StyleSheet, which holds specific CSS
+ * specs.
+ *
+ * In order for Views to store less state and therefore be more lightweight,
+ * the StyleSheet can act as a factory for painters that handle some of the
+ * rendering tasks. Since the StyleSheet may be used by views over multiple
+ * documents the HTML attributes don't effect the selector being used.
+ *
+ * The rules are stored as named styles, and other information is stored to
+ * translate the context of an element to a rule.
+ *
+ * @author Lillian Angel (langel at redhat.com)
+ */
+public class StyleSheet extends StyleContext
+{
+
+ /** The base URL */
+ URL base;
+
+ /** Base font size (int) */
+ int baseFontSize;
+
+ /** The style sheets stored. */
+ StyleSheet[] styleSheet;
+
+ /**
+ * Constructs a StyleSheet.
+ */
+ public StyleSheet()
+ {
+ super();
+ baseFontSize = 4; // Default font size from CSS
+ }
+
+ /**
+ * Gets the style used to render the given tag. The element represents the tag
+ * and can be used to determine the nesting, where the attributes will differ
+ * if there is nesting inside of elements.
+ *
+ * @param t - the tag to translate to visual attributes
+ * @param e - the element representing the tag
+ * @return the set of CSS attributes to use to render the tag.
+ */
+ public Style getRule(HTML.Tag t, Element e)
+ {
+ // FIXME: Not implemented.
+ return null;
+ }
+
+ /**
+ * Gets the rule that best matches the selector. selector is a space
+ * separated String of element names. The attributes of the returned
+ * Style will change as rules are added and removed.
+ *
+ * @param selector - the element names separated by spaces
+ * @return the set of CSS attributes to use to render
+ */
+ public Style getRule(String selector)
+ {
+ // FIXME: Not implemented.
+ return null;
+ }
+
+ /**
+ * Adds a set if rules to the sheet. The rules are expected to be in valid
+ * CSS format. This is called as a result of parsing a <style> tag
+ *
+ * @param rule - the rule to add to the sheet
+ */
+ public void addRule(String rule)
+ {
+ CssParser cp = new CssParser();
+ try
+ {
+ cp.parse(base, new StringReader(rule), false, false);
+ }
+ catch (IOException io)
+ {
+ // Do nothing here.
+ }
+ }
+
+ /**
+ * Translates a CSS declaration into an AttributeSet. This is called
+ * as a result of encountering an HTML style attribute.
+ *
+ * @param decl - the declaration to get
+ * @return the AttributeSet representing the declaration
+ */
+ public AttributeSet getDeclaration(String decl)
+ {
+ if (decl == null)
+ return SimpleAttributeSet.EMPTY;
+ // FIXME: Not implemented.
+ return null;
+ }
+
+ /**
+ * Loads a set of rules that have been specified in terms of CSS grammar.
+ * If there are any conflicts with existing rules, the new rule is added.
+ *
+ * @param in - the stream to read the CSS grammar from.
+ * @param ref - the reference URL. It is the location of the stream, it may
+ * be null. All relative URLs specified in the stream will be based upon this
+ * parameter.
+ * @throws IOException - For any IO error while reading
+ */
+ public void loadRules(Reader in, URL ref) throws IOException
+ {
+ CssParser cp = new CssParser();
+ cp.parse(ref, in, false, false);
+ }
+
+ /**
+ * Gets a set of attributes to use in the view. This is a set of
+ * attributes that can be used for View.getAttributes
+ *
+ * @param v - the view to get the set for
+ * @return the AttributeSet to use in the view.
+ */
+ public AttributeSet getViewAttributes(View v)
+ {
+ // FIXME: Not implemented.
+ return null;
+ }
+
+ /**
+ * Removes a style previously added.
+ *
+ * @param nm - the name of the style to remove
+ */
+ public void removeStyle(String nm)
+ {
+ // FIXME: Not implemented.
+ super.removeStyle(nm);
+ }
+
+ /**
+ * Adds the rules from ss to those of the receiver. ss's rules will
+ * override the old rules. An added StyleSheet will never override the rules
+ * of the receiving style sheet.
+ *
+ * @param ss - the new StyleSheet.
+ */
+ public void addStyleSheet(StyleSheet ss)
+ {
+ if (styleSheet == null)
+ styleSheet = new StyleSheet[] {ss};
+ else
+ System.arraycopy(new StyleSheet[] {ss}, 0, styleSheet,
+ styleSheet.length, 1);
+ }
+
+ /**
+ * Removes ss from those of the receiver
+ *
+ * @param ss - the StyleSheet to remove.
+ */
+ public void removeStyleSheet(StyleSheet ss)
+ {
+ if (styleSheet.length == 1 && styleSheet[0].equals(ss))
+ styleSheet = null;
+ else
+ {
+ for (int i = 0; i < styleSheet.length; i++)
+ {
+ StyleSheet curr = styleSheet[i];
+ if (curr.equals(ss))
+ {
+ StyleSheet[] tmp = new StyleSheet[styleSheet.length - 1];
+ if (i != 0 && i != (styleSheet.length - 1))
+ {
+ System.arraycopy(styleSheet, 0, tmp, 0, i);
+ System.arraycopy(styleSheet, i + 1, tmp, i,
+ styleSheet.length - i - 1);
+ }
+ else if (i == 0)
+ System.arraycopy(styleSheet, 1, tmp, 0, styleSheet.length - 1);
+ else
+ System.arraycopy(styleSheet, 0, tmp, 0, styleSheet.length - 1);
+
+ styleSheet = tmp;
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns an array of the linked StyleSheets. May return null.
+ *
+ * @return - An array of the linked StyleSheets.
+ */
+ public StyleSheet[] getStyleSheets()
+ {
+ return styleSheet;
+ }
+
+ /**
+ * Imports a style sheet from the url. The rules are directly added to the
+ * receiver.
+ *
+ * @param url - the URL to import the StyleSheet from.
+ */
+ public void importStyleSheet(URL url)
+ {
+ // FIXME: Not implemented
+ }
+
+ /**
+ * Sets the base url. All import statements that are relative, will be
+ * relative to base.
+ *
+ * @param base -
+ * the base URL.
+ */
+ public void setBase(URL base)
+ {
+ this.base = base;
+ }
+
+ /**
+ * Gets the base url.
+ *
+ * @return - the base
+ */
+ public URL getBase()
+ {
+ return base;
+ }
+
+ /**
+ * Adds a CSS attribute to the given set.
+ *
+ * @param attr - the attribute set
+ * @param key - the attribute to add
+ * @param value - the value of the key
+ */
+ public void addCSSAttribute(MutableAttributeSet attr, CSS.Attribute key,
+ String value)
+ {
+ attr.addAttribute(key, value);
+ }
+
+ /**
+ * Adds a CSS attribute to the given set.
+ * This method parses the value argument from HTML based on key.
+ * Returns true if it finds a valid value for the given key,
+ * and false otherwise.
+ *
+ * @param attr - the attribute set
+ * @param key - the attribute to add
+ * @param value - the value of the key
+ * @return true if a valid value was found.
+ */
+ public boolean addCSSAttributeFromHTML(MutableAttributeSet attr, CSS.Attribute key,
+ String value)
+ {
+ // FIXME: Need to parse value from HTML based on key.
+ attr.addAttribute(key, value);
+ return attr.containsAttribute(key, value);
+ }
+
+ /**
+ * Converts a set of HTML attributes to an equivalent set of CSS attributes.
+ *
+ * @param htmlAttrSet - the set containing the HTML attributes.
+ * @return the set of CSS attributes
+ */
+ public AttributeSet translateHTMLToCSS(AttributeSet htmlAttrSet)
+ {
+ // FIXME: Not implemented.
+ return null;
+ }
+
+ /**
+ * Adds an attribute to the given set and returns a new set. This is implemented
+ * to convert StyleConstants attributes to CSS before forwarding them to the superclass.
+ * The StyleConstants attribute do not have corresponding CSS entry, the attribute
+ * is stored (but will likely not be used).
+ *
+ * @param old - the old set
+ * @param key - the non-null attribute key
+ * @param value - the attribute value
+ * @return the updated set
+ */
+ public AttributeSet addAttribute(AttributeSet old, Object key,
+ Object value)
+ {
+ // FIXME: Not implemented.
+ return super.addAttribute(old, key, value);
+ }
+
+ /**
+ * Adds a set of attributes to the element. If any of these attributes are
+ * StyleConstants, they will be converted to CSS before forwarding to the
+ * superclass.
+ *
+ * @param old - the old set
+ * @param attr - the attributes to add
+ * @return the updated attribute set
+ */
+ public AttributeSet addAttributes(AttributeSet old, AttributeSet attr)
+ {
+ // FIXME: Not implemented.
+ return super.addAttributes(old, attr);
+ }
+
+ /**
+ * Removes an attribute from the set. If the attribute is a
+ * StyleConstants, it will be converted to CSS before forwarding to the
+ * superclass.
+ *
+ * @param old - the old set
+ * @param key - the non-null attribute key
+ * @return the updated set
+ */
+ public AttributeSet removeAttribute(AttributeSet old, Object key)
+ {
+ // FIXME: Not implemented.
+ return super.removeAttribute(old, key);
+ }
+
+ /**
+ * Removes an attribute from the set. If any of the attributes are
+ * StyleConstants, they will be converted to CSS before forwarding to the
+ * superclass.
+ *
+ * @param old - the old set
+ * @param attrs - the attributes to remove
+ * @return the updated set
+ */
+ public AttributeSet removeAttributes(AttributeSet old, AttributeSet attrs)
+ {
+ // FIXME: Not implemented.
+ return super.removeAttributes(old, attrs);
+ }
+
+ /**
+ * Removes a set of attributes for the element. If any of the attributes is a
+ * StyleConstants, they will be converted to CSS before forwarding to the
+ * superclass.
+ *
+ * @param old - the old attribute set
+ * @param names - the attribute names
+ * @return the update attribute set
+ */
+ public AttributeSet removeAttributes(AttributeSet old, Enumeration names)
+ {
+ // FIXME: Not implemented.
+ return super.removeAttributes(old, names);
+ }
+
+ /**
+ * Creates a compact set of attributes that might be shared. This is a hook
+ * for subclasses that want to change the behaviour of SmallAttributeSet.
+ *
+ * @param a - the set of attributes to be represented in the compact form.
+ * @return the set of attributes created
+ */
+ protected StyleContext.SmallAttributeSet createSmallAttributeSet(AttributeSet a)
+ {
+ return super.createSmallAttributeSet(a);
+ }
+
+ /**
+ * Creates a large set of attributes. This set is not shared. This is a hook
+ * for subclasses that want to change the behaviour of the larger attribute
+ * storage format.
+ *
+ * @param a - the set of attributes to be represented in the larger form.
+ * @return the large set of attributes.
+ */
+ protected MutableAttributeSet createLargeAttributeSet(AttributeSet a)
+ {
+ return super.createLargeAttributeSet(a);
+ }
+
+ /**
+ * Gets the font to use for the given set.
+ *
+ * @param a - the set to get the font for.
+ * @return the font for the set
+ */
+ public Font getFont(AttributeSet a)
+ {
+ return super.getFont(a);
+ }
+
+ /**
+ * Takes a set of attributes and turns it into a foreground
+ * color specification. This is used to specify things like, brigher, more hue
+ * etc.
+ *
+ * @param a - the set to get the foreground color for
+ * @return the foreground color for the set
+ */
+ public Color getForeground(AttributeSet a)
+ {
+ return super.getForeground(a);
+ }
+
+ /**
+ * Takes a set of attributes and turns it into a background
+ * color specification. This is used to specify things like, brigher, more hue
+ * etc.
+ *
+ * @param a - the set to get the background color for
+ * @return the background color for the set
+ */
+ public Color getBackground(AttributeSet a)
+ {
+ return super.getBackground(a);
+ }
+
+ /**
+ * Gets the box formatter to use for the given set of CSS attributes.
+ *
+ * @param a - the given set
+ * @return the box formatter
+ */
+ public BoxPainter getBoxPainter(AttributeSet a)
+ {
+ return new BoxPainter(a);
+ }
+
+ /**
+ * Gets the list formatter to use for the given set of CSS attributes.
+ *
+ * @param a - the given set
+ * @return the list formatter
+ */
+ public ListPainter getListPainter(AttributeSet a)
+ {
+ return new ListPainter(a);
+ }
+
+ /**
+ * Sets the base font size between 1 and 7.
+ *
+ * @param sz - the new font size for the base.
+ */
+ public void setBaseFontSize(int sz)
+ {
+ if (sz <= 7 && sz >= 1)
+ baseFontSize = sz;
+ }
+
+ /**
+ * Sets the base font size from the String. It can either identify
+ * a specific font size (between 1 and 7) or identify a relative
+ * font size such as +1 or -2.
+ *
+ * @param size - the new font size as a String.
+ */
+ public void setBaseFontSize(String size)
+ {
+ size.trim();
+ int temp = 0;
+ try
+ {
+ if (size.length() == 2)
+ {
+ int i = new Integer(size.substring(1)).intValue();
+ if (size.startsWith("+"))
+ temp = baseFontSize + i;
+ else if (size.startsWith("-"))
+ temp = baseFontSize - i;
+ }
+ else if (size.length() == 1)
+ temp = new Integer(size.substring(0)).intValue();
+
+ if (temp <= 7 && temp >= 1)
+ baseFontSize = temp;
+ }
+ catch (NumberFormatException nfe)
+ {
+ // Do nothing here
+ }
+ }
+
+ /**
+ * TODO
+ *
+ * @param pt - TODO
+ * @return TODO
+ */
+ public static int getIndexOfSize(float pt)
+ {
+ // FIXME: Not implemented.
+ return 0;
+ }
+
+ /**
+ * Gets the point size, given a size index.
+ *
+ * @param index - the size index
+ * @return the point size.
+ */
+ public float getPointSize(int index)
+ {
+ // FIXME: Not implemented.
+ return 0;
+ }
+
+ /**
+ * Given the string of the size, returns the point size value.
+ *
+ * @param size - the string representation of the size.
+ * @return - the point size value.
+ */
+ public float getPointSize(String size)
+ {
+ // FIXME: Not implemented.
+ return 0;
+ }
+
+ /**
+ * Convert the color string represenation into java.awt.Color. The valid
+ * values are like "aqua" , "#00FFFF" or "rgb(1,6,44)".
+ *
+ * @param colorName the color to convert.
+ * @return the matching java.awt.color
+ */
+ public Color stringToColor(String colorName)
+ {
+ return CharacterAttributeTranslator.getColor(colorName);
+ }
+
+ /**
+ * This class carries out some of the duties of CSS formatting. This enables views
+ * to present the CSS formatting while not knowing how the CSS values are cached.
+ *
+ * This object is reponsible for the insets of a View and making sure
+ * the background is maintained according to the CSS attributes.
+ *
+ * @author Lillian Angel (langel at redhat.com)
+ */
+ public static class BoxPainter extends Object implements Serializable
+ {
+
+ /**
+ * Attribute set for painter
+ */
+ AttributeSet as;
+
+ /**
+ * Package-private constructor.
+ *
+ * @param as - AttributeSet for painter
+ */
+ BoxPainter(AttributeSet as)
+ {
+ this.as = as;
+ }
+
+ /**
+ * Gets the inset needed on a given side to account for the margin, border
+ * and padding.
+ *
+ * @param size - the size of the box to get the inset for. View.TOP, View.LEFT,
+ * View.BOTTOM or View.RIGHT.
+ * @param v - the view making the request. This is used to get the AttributeSet,
+ * amd may be used to resolve percentage arguments.
+ * @return the inset
+ * @throws IllegalArgumentException - for an invalid direction.
+ */
+ public float getInset(int size, View v)
+ {
+ // FIXME: Not implemented.
+ return 0;
+ }
+
+ /**
+ * Paints the CSS box according to the attributes given. This should
+ * paint the border, padding and background.
+ *
+ * @param g - the graphics configuration
+ * @param x - the x coordinate
+ * @param y - the y coordinate
+ * @param w - the width of the allocated area
+ * @param h - the height of the allocated area
+ * @param v - the view making the request
+ */
+ public void paint(Graphics g, float x, float y, float w, float h, View v)
+ {
+ // FIXME: Not implemented.
+ }
+ }
+
+ /**
+ * This class carries out some of the CSS list formatting duties. Implementations
+ * of this class enable views to present the CSS formatting while not knowing anything
+ * about how the CSS values are being cached.
+ *
+ * @author Lillian Angel (langel at redhat.com)
+ */
+ public static class ListPainter extends Object implements Serializable
+ {
+
+ /**
+ * Attribute set for painter
+ */
+ AttributeSet as;
+
+ /**
+ * Package-private constructor.
+ *
+ * @param as - AttributeSet for painter
+ */
+ ListPainter(AttributeSet as)
+ {
+ this.as = as;
+ }
+
+ /**
+ * Paints the CSS list decoration according to the attributes given.
+ *
+ * @param g - the graphics configuration
+ * @param x - the x coordinate
+ * @param y - the y coordinate
+ * @param w - the width of the allocated area
+ * @param h - the height of the allocated area
+ * @param v - the view making the request
+ * @param item - the list item to be painted >=0.
+ */
+ public void paint(Graphics g, float x, float y, float w, float h, View v,
+ int item)
+ {
+ // FIXME: Not implemented.
+ }
+ }
+
+ /**
+ * The parser callback for the CSSParser.
+ */
+ class CssParser implements CSSParser.CSSParserCallback
+ {
+ /**
+ * A vector of all the selectors.
+ * Each element is an array of all the selector tokens
+ * in a single rule.
+ */
+ Vector selectors;
+
+ /** A vector of all the selector tokens in a rule. */
+ Vector selectorTokens;
+
+ /** Name of the current property. */
+ String propertyName;
+
+ /** The set of CSS declarations */
+ MutableAttributeSet declaration;
+
+ /**
+ * True if parsing a declaration, that is the Reader will not
+ * contain a selector.
+ */
+ boolean parsingDeclaration;
+
+ /** True if the attributes are coming from a linked/imported style. */
+ boolean isLink;
+
+ /** The base URL */
+ URL base;
+
+ /** The parser */
+ CSSParser parser;
+
+ /**
+ * Constructor
+ */
+ CssParser()
+ {
+ selectors = new Vector();
+ selectorTokens = new Vector();
+ parser = new CSSParser();
+ base = StyleSheet.this.base;
+ declaration = new SimpleAttributeSet();
+ }
+
+ /**
+ * Parses the passed in CSS declaration into an AttributeSet.
+ *
+ * @param s - the declaration
+ * @return the set of attributes containing the property and value.
+ */
+ public AttributeSet parseDeclaration(String s)
+ {
+ try
+ {
+ return parseDeclaration(new StringReader(s));
+ }
+ catch (IOException e)
+ {
+ // Do nothing here.
+ }
+ return null;
+ }
+
+ /**
+ * Parses the passed in CSS declaration into an AttributeSet.
+ *
+ * @param r - the reader
+ * @return the attribute set
+ * @throws IOException from the reader
+ */
+ public AttributeSet parseDeclaration(Reader r) throws IOException
+ {
+ parse(base, r, true, false);
+ return declaration;
+ }
+
+ /**
+ * Parse the given CSS stream
+ *
+ * @param base - the url
+ * @param r - the reader
+ * @param parseDec - True if parsing a declaration
+ * @param isLink - True if parsing a link
+ */
+ public void parse(URL base, Reader r, boolean parseDec, boolean isLink) throws IOException
+ {
+ parsingDeclaration = parseDec;
+ this.isLink = isLink;
+ this.base = base;
+
+ // flush out all storage
+ propertyName = null;
+ selectors.clear();
+ selectorTokens.clear();
+ declaration.removeAttributes(declaration);
+
+ parser.parse(r, this, parseDec);
+ }
+
+ /**
+ * Invoked when a valid @import is encountered,
+ * will call importStyleSheet if a MalformedURLException
+ * is not thrown in creating the URL.
+ *
+ * @param s - the string after @import
+ */
+ public void handleImport(String s)
+ {
+ if (s != null)
+ {
+ try
+ {
+ if (s.startsWith("url(") && s.endsWith(")"))
+ s = s.substring(4, s.length() - 1);
+ if (s.indexOf("\"") >= 0)
+ s = s.replaceAll("\"","");
+
+ URL url = new URL(s);
+ if (url == null && base != null)
+ url = new URL(base, s);
+
+ importStyleSheet(url);
+ }
+ catch (MalformedURLException e)
+ {
+ // Do nothing here.
+ }
+ }
+ }
+
+ /**
+ * A selector has been encountered.
+ *
+ * @param s - a selector (e.g. P or UL or even P,)
+ */
+ public void handleSelector(String s)
+ {
+ if (s.endsWith(","))
+ s = s.substring(0, s.length() - 1);
+
+ selectorTokens.addElement(s);
+ addSelector();
+ }
+
+ /**
+ * Invoked when the start of a rule is encountered.
+ */
+ public void startRule()
+ {
+ addSelector();
+ }
+
+ /**
+ * Invoked when a property name is encountered.
+ *
+ * @param s - the property
+ */
+ public void handleProperty(String s)
+ {
+ propertyName = s;
+ }
+
+ /**
+ * Invoked when a property value is encountered.
+ *
+ * @param s - the value
+ */
+ public void handleValue(String s)
+ {
+ // call addCSSAttribute
+ // FIXME: Not implemented
+ }
+
+ /**
+ * Invoked when the end of a rule is encountered.
+ */
+ public void endRule()
+ {
+ // FIXME: Not implemented
+ // add rules
+ propertyName = null;
+ }
+
+ /**
+ * Adds the selector to the vector.
+ */
+ private void addSelector()
+ {
+ int length = selectorTokens.size();
+ if (length > 0)
+ {
+ Object[] sel = new Object[length];
+ System.arraycopy(selectorTokens.toArray(), 0, sel, 0, length);
+ selectors.add(sel);
+ selectorTokens.clear();
+ }
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/TableView.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/TableView.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/TableView.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/TableView.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,137 @@
+/* TableView.java -- A table view for HTML tables
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html;
+
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+import javax.swing.text.View;
+import javax.swing.text.ViewFactory;
+
+/**
+ * A conrete implementation of TableView that renders HTML tables.
+ *
+ * @author Roman Kennke (kennke at aicas.com)
+ */
+class TableView
+ extends javax.swing.text.TableView
+{
+ /**
+ * Represents a single table row.
+ */
+ public class RowView extends TableRow
+ {
+ /**
+ * Creates a new instance of the <code>RowView</code>.
+ *
+ * @param el the element for which to create a row view
+ */
+ public RowView(Element el)
+ {
+ super(el);
+ }
+
+ /**
+ * Get the associated style sheet from the document.
+ *
+ * @return the associated style sheet.
+ */
+ protected StyleSheet getStyleSheet()
+ {
+ Document d = getElement().getDocument();
+ if (d instanceof HTMLDocument)
+ return ((HTMLDocument) d).getStyleSheet();
+ else
+ return null;
+ }
+ }
+
+ /**
+ * Creates a new HTML table view for the specified element.
+ *
+ * @param el the element for the table view
+ */
+ public TableView(Element el)
+ {
+ super(el);
+ }
+
+ /**
+ * Get the associated style sheet from the document.
+ *
+ * @return the associated style sheet.
+ */
+ protected StyleSheet getStyleSheet()
+ {
+ Document d = getElement().getDocument();
+ if (d instanceof HTMLDocument)
+ return ((HTMLDocument) d).getStyleSheet();
+ else
+ return null;
+ }
+
+ /**
+ * Creates a view for a table row.
+ *
+ * @param el the element that represents the table row
+ * @return a view for rendering the table row
+ * (and instance of {@link RowView}).
+ */
+ protected TableRow createTableRow(Element el)
+ {
+ return new RowView(el);
+ }
+
+ /**
+ * Loads the children of the Table. This completely bypasses the ViewFactory
+ * and creates instances of TableRow instead.
+ *
+ * @param vf ignored
+ */
+ protected void loadChildren(ViewFactory vf)
+ {
+ Element el = getElement();
+ int numChildren = el.getElementCount();
+ View[] rows = new View[numChildren];
+ for (int i = 0; i < numChildren; ++i)
+ {
+ rows[i] = createTableRow(el.getElement(i));
+ }
+ replace(0, getViewCount(), rows);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/default.css
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/default.css?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/default.css (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/default.css Thu Nov 8 16:56:19 2007
@@ -0,0 +1,378 @@
+/* default.css --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+nobr {
+ white-space: nowrap;
+}
+
+ol {
+ margin-right: 50px;
+ margin-top: 10px;
+ margin-left: 50px;
+ margin-bottom: 10px;
+ list-style-type: decimal;
+}
+
+u {
+ text-decoration: underline;
+}
+
+s {
+ text-decoration: line-through;
+}
+
+p {
+ margin-top: 15px;
+}
+
+dd p {
+ margin-left: 0px;
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+ol li p {
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+
+address {
+ font-style: italic;
+ color: blue;
+}
+
+i {
+ font-style: italic;
+}
+
+h6 {
+ margin-top: 10px;
+ font-size: xx-small;
+ font-weight: bold;
+ margin-bottom: 10px;
+}
+
+h5 {
+ margin-top: 10px;
+ font-size: x-small;
+ font-weight: bold;
+ margin-bottom: 10px;
+}
+
+h4 {
+ margin-top: 10px;
+ font-size: small;
+ font-weight: bold;
+ margin-bottom: 10px;
+}
+
+h3 {
+ margin-top: 10px;
+ font-size: medium;
+ font-weight: bold;
+ margin-bottom: 10px;
+}
+
+dir li p {
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+h2 {
+ margin-top: 10px;
+ font-size: large;
+ font-weight: bold;
+ margin-bottom: 10px;
+}
+
+b {
+ font-weight: bold;
+}
+
+h1 {
+ margin-top: 10px;
+ font-size: x-large;
+ font-weight: bold;
+ margin-bottom: 10px;
+}
+
+caption {
+ text-align: center;
+ caption-side: top;
+}
+
+a {
+ text-decoration: underline;
+ color: blue;
+}
+
+ul li ul li ul li {
+ margin-left: 0px;
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+menu {
+ margin-right: 40px;
+ margin-top: 10px;
+ margin-left: 40px;
+ margin-bottom: 10px;
+}
+
+menu li p {
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+sup {
+ vertical-align: super;
+}
+
+body {
+ margin-right: 0px;
+ margin-left: 0px;
+ font-family: Serif;
+ font-size: 14pt;
+ font-weight: normal;
+ color: black;
+}
+
+ul li ul li ul {
+ margin-right: 25px;
+ margin-left: 25px;
+ list-style-type: square;
+}
+
+blockquote {
+ margin-right: 35px;
+ margin-left: 35px;
+ margin-top: 5px;
+ margin-bottom: 5px;
+}
+
+samp {
+ font-family: Monospaced;
+ font-size: small;
+}
+
+cite {
+ font-style: italic;
+}
+
+sub {
+ vertical-align: sub;
+}
+
+em {
+ font-style: italic;
+}
+
+ul li p {
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+ul li ul li {
+ margin-right: 0px;
+ margin-left: 0px;
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+var {
+ font-style: italic;
+ font-weight: bold;
+}
+
+table {
+ border-color: Gray;
+ border-style: outset;
+}
+
+dfn {
+ font-style: italic;
+}
+
+menu li {
+ margin-right: 0px;
+ margin-left: 0px;
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+strong {
+ font-weight: bold;
+}
+
+ul {
+ margin-right: 50px;
+ margin-top: 10px;
+ margin-left: 50px;
+ margin-bottom: 10px;
+ list-style-type: disc;
+}
+
+center {
+ text-align: center;
+}
+
+ul li ul {
+ margin-right: 25px;
+ margin-left: 25px;
+ list-style-type: circle;
+}
+
+kbd {
+ font-family: Monospaced;
+ font-size: small;
+}
+
+dir li {
+ margin-right: 0px;
+ margin-left: 0px;
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+ul li menu {
+ margin-right: 25px;
+ margin-left: 25px;
+ list-style-type: circle;
+}
+
+dt {
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+ol li {
+ margin-right: 0px;
+ margin-left: 0px;
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+li p {
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+default {
+}
+
+strike {
+ text-decoration: line-through;
+}
+
+dl {
+ margin-left: 0px;
+ margin-top: 10px;
+ margin-bottom: 10px;
+}
+
+tt {
+ font-family: Monospaced;
+}
+
+ul li {
+ margin-right: 0px;
+ margin-left: 0px;
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+dir {
+ margin-right: 40px;
+ margin-top: 10px;
+ margin-left: 40px;
+ margin-bottom: 10px;
+}
+
+tr {
+ text-align: left;
+}
+
+pre p {
+ margin-top: 0px;
+}
+
+dd {
+ margin-right: 40px;
+ margin-top: 0px;
+ margin-left: 40px;
+ margin-bottom: 0px;
+}
+
+th {
+ padding-bottom: 3px;
+ text-align: center;
+ padding-top: 3px;
+ padding-right: 3px;
+ padding-left: 3px;
+ font-weight: bold;
+ border-color: Gray;
+ border-style: inset;
+}
+
+pre {
+ margin-top: 5px;
+ font-family: Monospaced;
+ margin-bottom: 5px;
+}
+
+td {
+ padding-bottom: 3px;
+ padding-top: 3px;
+ padding-right: 3px;
+ padding-left: 3px;
+ border-color: Gray;
+ border-style: inset;
+}
+
+code {
+ font-family: Monospaced;
+ font-size: small;
+}
+
+small {
+ font-size: x-small;
+}
+
+big {
+ font-size: x-large;
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.swing.text.html package.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - javax.swing.text.html</title></head>
+
+<body>
+<p> Provides supporting classes for web browsers,
+ web robots, web page content analysers, web editors and
+ other applications applications working with Hypertext
+ Markup Language (HTML).
+</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/AttributeList.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/AttributeList.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/AttributeList.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/AttributeList.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,294 @@
+/* AttributeList.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html.parser;
+
+import gnu.javax.swing.text.html.parser.support.gnuStringIntMapper;
+
+import java.io.Serializable;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * <p>
+ * Stores the attribute information, obtained by parsing SGML (DTD) tag
+ * <code><!ATTLIST .. ></code></p>
+ * <p>
+ * Elements can have a associated named properties (attributes) having the
+ * assigned values. The element start tag can have any number of attribute
+ * value pairs, separated by spaces. They can appear in any order.
+ * SGML requires you to delimit the attribute values using either double (")
+ * or single (') quotation marks. In HTML, it is possible
+ * (but not recommended) to specify the value of an attribute without
+ * quotation marks. Such attribute value may only contain
+ * letters, digits, hyphens (-) and periods (.) .
+ * </p>
+ * <p>
+ * The <code>AttributeList</code> defines a single attribute that additionally
+ * has a pointer referencing the possible subsequent attribute.
+ * The whole structure is just a simple linked list, storing all attributes of
+ * some <code>Element</code>.
+ * Use the <code>getNext()</code> method repeatedly to see all attributes in
+ * the list.
+ * </p>
+ * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
+ */
+public final class AttributeList
+ implements DTDConstants, Serializable
+{
+ /** Maps between type names and they string values. */
+ private static final gnuStringIntMapper mapper =
+ new gnuStringIntMapper()
+ {
+ protected void create()
+ {
+ add("CDATA", DTDConstants.CDATA);
+ add("ENTITY", DTDConstants.ENTITY);
+ add("ENTITIES", DTDConstants.ENTITIES);
+ add("ID", DTDConstants.ID);
+ add("IDREF", DTDConstants.IDREF);
+ add("IDREFS", DTDConstants.IDREFS);
+ add("NAME", DTDConstants.NAME);
+ add("NAMES", DTDConstants.NAMES);
+ add("NMTOKEN", DTDConstants.NMTOKEN);
+ add("NMTOKENS", DTDConstants.NMTOKENS);
+ add("NOTATION", DTDConstants.NOTATION);
+ add("NUMBER", DTDConstants.NUMBER);
+ add("NUMBERS", DTDConstants.NUMBERS);
+ add("NUTOKEN", DTDConstants.NUTOKEN);
+ add("NUTOKENS", DTDConstants.NUTOKENS);
+ }
+ };
+
+ /** Use serialVersionUID for interoperability. */
+ private static final long serialVersionUID = -1361214058742015233L;
+
+ /**
+ * The value of ( = pointer to ) the next attribute in the linked list,
+ * storing all attributes of some Element. Contains null for the
+ * last attribute.
+ */
+ public AttributeList next;
+
+ /**
+ * The name of the attribute. The attribute names are case insensitive.
+ */
+ public String name;
+
+ /**
+ * The default value of this attribute. Equals to null if no default value
+ * is specified.
+ */
+ public String value;
+
+ /**
+ * The explicit set of the allowed values of this attribute. Equals to
+ * null, if this parameter was not specified.
+ * Values, defined in DTD, are case insensitive.
+ */
+ public Vector values;
+
+ /**
+ * The modifier of this attribute. This field contains one of the
+ * following DTD constants:
+ * <ul>
+ * <li> REQUIRED if the attribute value is always required,</li>
+ * <li> IMPLIED if the user agent must supply the default value itself,</li>
+ * <li> FIXED if the attribute value is fixed to some value and cannot
+ * be changed.</li>
+ * <li> DEFAULT if the attribute default value has been supplied.</li>
+ * <li> CURRENT the value that at any point in the document is
+ * the last value supplied for that element. A value is required to be
+ * supplied for the first* occurrence of an element</li>
+ * <li> CONREF specifies the IDREF value of
+ * the reference to content in another location of the document.
+ * The element with this attribute is empty, the content from
+ * that another location must be used instead.</li>
+ * </ul>
+ */
+ public int modifier;
+
+ /**
+ * The type of the attribute. The possible values of this field
+ * (NUMBER, NAME, ID, CDATA and so on) are defined in DTDConstants.
+ */
+ public int type;
+
+ /**
+ * Creates the attribute with the given name, initializing other fields
+ * to the default values ( 0 and null ).
+ *
+ * @param a_name The name of the attribute.
+ */
+ public AttributeList(String a_name)
+ {
+ name = a_name;
+ }
+
+ /**
+ * Creates the attribute with the given properties.
+ * @param a_name The name of the attribute
+ * @param a_type The type of the attribute. The possible values are defined
+ * in <code> DTDConstants</code>.
+ * @param a_modifier The modifier of this attribute. The possible values
+ * are defined in <code> DTDConstants</code>.
+ * @param a_default The default value of this attribute
+ * @param allowed_values The explicit set of the allowed values of
+ * this attribute
+ * @param a_next The value of the subsequent instance of the AttributeList,
+ * representing the next attribute definition for the same element.
+ * Equals to null for the last attribute definition.
+ */
+ public AttributeList(String a_name, int a_type, int a_modifier,
+ String a_default, Vector allowed_values,
+ AttributeList a_next
+ )
+ {
+ this(a_name);
+ type = a_type;
+ modifier = a_modifier;
+ value = a_default;
+ values = allowed_values;
+ next = a_next;
+ }
+
+ /**
+ * Get the modifier of this attribute. This field contains one of the
+ * following DTD constants:
+ * <ul>
+ * <li> REQUIRED if the attribute value is always required,</li>
+ * <li> IMPLIED if the user agent must supply the default value itself,</li>
+ * <li> FIXED if the attribute value is fixed to some value and cannot
+ * be changed.</li>
+ * <li> DEFAULT if the attribute default value has been supplied.</li>
+ * <li> CURRENT the value that at any point in the document is
+ * the last value supplied for that element. A value is required to be
+ * supplied for the first* occurrence of an element</li>
+ * <li> CONREF specifies the IDREF value of
+ * the reference to content in another location of the document.
+ * The element with this attribute is empty, the content from
+ * that another location must be used instead.</li>
+ * </ul>
+ */
+ public int getModifier()
+ {
+ return modifier;
+ }
+
+ /**
+ * Get the name of the attribute.
+ * The value is returned as it was supplied to a
+ * constructor, preserving the character case.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Get the value of ( = pointer to ) the next attribute in the linked list,
+ * storing all attributes of some Element. Contains null for the
+ * last attribute.
+ */
+ public AttributeList getNext()
+ {
+ return next;
+ }
+
+ /**
+ * Get the type of the attribute. The possible values of this field
+ * (NUMBER, NAME, ID, CDATA and so on) are defined in DTDConstants.
+ */
+ public int getType()
+ {
+ return type;
+ }
+
+ /**
+ * Get the default value of this attribute.
+ */
+ public String getValue()
+ {
+ return value;
+ }
+
+ /**
+ * Get the allowed values of this attribute.
+ */
+ public Enumeration getValues()
+ {
+ return values.elements();
+ }
+
+ /**
+ * Converts a string value, representing a valid SGLM attribute type,
+ * into the corresponding value, defined in DTDConstants.
+ * @param typeName the name of the type (character case is ignored).
+ * @return a value from DTDConstants or DTDConstants.ANY if the
+ * string is not representing a known type. The known attribute types
+ * in this implementation are CDATA, ENTITY, ENTITIES, ID, IDREF, IDREFS,
+ * NAME, NAMES, NMTOKEN, NMTOKENS, NOTATION, NUMBER, NUMBERS, NUTOKEN and
+ * NUTOKENS.
+ * @throws NullPointerException if the passed parameter is null.
+ */
+ public static int name2type(String typeName)
+ {
+ return mapper.get(typeName.toUpperCase());
+ }
+
+ /**
+ * Returns the attribute name.
+ */
+ public String toString()
+ {
+ return name;
+ }
+
+ /**
+ * Converts a value from DTDConstants into the string representation.
+ * @param type - an integer value of the public static integer field,
+ * defined in the DTDConstants class.
+ * @return a corresponding SGML DTD keyword (UPPERCASE) or null if there
+ * are no attribute type constant having the given value.
+ */
+ public static String type2name(int type)
+ {
+ return mapper.get(type);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/ContentModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/ContentModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/ContentModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/ContentModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,221 @@
+/* ContentModel.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html.parser;
+
+import gnu.javax.swing.text.html.parser.models.transformer;
+
+import java.io.Serializable;
+
+import java.util.Vector;
+
+/**
+ * A representation of the element content. The instances of this class
+ * can be arranged into the linked list, representing a BNF expression.
+ * The content model is constructed as a branched tree structure in the
+ * following way:
+ * <pre>
+ * a = new ContentModel('+', A, null); // a reprensents A+
+ * b = new ContentModel('&', B, a); // b represents B & A+
+ * c = new ContentModel('*', b, null); // c represents ( B & A+) *
+ * d = new ContentModel('|', new ContentModel('*', A, null),
+ * new ContentModel('?', B, null)); // d represents ( A* | B? )
+ * </pre>
+ * where the valid operations are:
+ * <ul>
+ * <li><code>E* </code> E occurs zero or more times</li>
+ * <li><code>E+ </code> E occurs one or more times</li>
+ * <li><code>E? </code> E occurs once or not atl all</li>
+ * <li><code>A,B</code> A occurs before B</li>
+ * <li><code>A|B</code> both A and B are permitted in any order.
+ * The '|' alone does not permit the repetetive occurence of A or B
+ * (use <code>(A|B)*</code>.</li>
+ * <li><code>A&B</code> both A and B must occur once (in any order)</li>
+ * </ul>
+ * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
+ */
+public final class ContentModel
+ implements Serializable
+{
+ /** Use serialVersionUID for interoperability. */
+ private static final long serialVersionUID = -1130825523866321257L;
+
+ /**
+ * The next content model model ( = pointer to the next element of
+ * the linked list) for the binary expression (',','&' or '|'). Null
+ * for the last element in the list.
+ */
+ public ContentModel next;
+
+ /**
+ * The document content, containing either Element or the enclosed
+ * content model (that would be in the parentheses in BNF expression).
+ */
+ public Object content;
+
+ /**
+ * Specifies the BNF operation between this node and the node,
+ * stored in the field <code>next</code> (or for this node, if it is
+ * an unary operation.
+ */
+ public int type;
+
+ /**
+ * Create a content model initializing all fields to default values.
+ */
+ public ContentModel()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Create a content model, consisting of the single element.
+ * Examples:
+ *<code>
+ * a = new ContentModel('+', A, null); // a reprensents A+
+ * b = new ContentModel('&', B, a); // b represents B & A+
+ * c = new ContentModel('*', b, null); // c represents ( B & A+) *
+ * d = new ContentModel('|', A,
+ * new ContentModel('?',b, null);
+ * // d represents
+ * </code>
+ */
+ public ContentModel(Element a_content)
+ {
+ content = a_content;
+ }
+
+ /**
+ * Create a content model, involving expression of the given type.
+ * @param a_type The expression operation type ('*','?' or '+'
+ * @param a_content The content for that the expression is applied.
+ */
+ public ContentModel(int a_type, ContentModel a_content)
+ {
+ content = a_content;
+ type = a_type;
+ }
+
+ /**
+ * Create a content model, involving binary expression of the given type.
+ * @param a_type The expression operation type ( ',', '|' or '&').
+ * @param a_content The content of the left part of the expression.
+ * @param a_next The content model, representing the right part of the
+ * expression.
+ */
+ public ContentModel(int a_type, Object a_content, ContentModel a_next)
+ {
+ content = a_content;
+ type = a_type;
+ next = a_next;
+ }
+
+ /**
+ * Adds all list elements to the given vector, ignoring the
+ * operations between the elements. The old vector values are not
+ * discarded.
+ * @param elements - a vector to add the values to.
+ */
+ public void getElements(Vector elements)
+ {
+ ContentModel c = this;
+
+ while (c != null)
+ {
+ elements.add(c.content);
+ c = c.next;
+ }
+ }
+
+ /**
+ * Checks if the content model matches an empty input stream.
+ * The empty content is created using SGML DTD keyword EMPTY.
+ * The empty model is a model with the content field equal to null.
+ *
+ * @return true if the content field is equal to null.
+ */
+ public boolean empty()
+ {
+ return content == null;
+ }
+
+ /**
+ * Get the element, stored in the <code>next.content</code>.
+ * The method is programmed as the part of the standard API, but not
+ * used in this implementation.
+ * @return the value of the field <code>next</code>.
+ */
+ public Element first()
+ {
+ return (Element) next.content;
+ }
+
+ /**
+ * Checks if this object can potentially be the first token in the
+ * ContenModel list. The method is programmed as the part of the
+ * standard API, but not used in this implementation.
+ */
+ public boolean first(Object token)
+ {
+ ContentModel c = this;
+ while (c.next != null)
+ {
+ if (c.content != null && c.content.toString().equals(token.toString()) &&
+ c.type != ','
+ )
+
+ // Agree if the operation with the preceeding element
+ // is not the comma operation.
+ return true;
+ c = c.next;
+ }
+ return false;
+ }
+
+ /**
+ * Returns a string representation (an expression) of this content model.
+ * The expression has BNF-like syntax, except the absence of the
+ * unary operator is additionally indicated by " ' ". It is
+ * advisable to check the created models for correctness using this
+ * method.
+ */
+ public String toString()
+ {
+ return transformer.transform(this).toString();
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DTD.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DTD.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DTD.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DTD.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,608 @@
+/* DTD.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html.parser;
+
+import java.io.DataInputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.BitSet;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+/**
+ * <p>Representation or the SGML DTD document.
+ * Provides basis for describing a syntax of the
+ * HTML documents. The fields of this class are NOT initialized in
+ * constructor. You need to do this separately before passing this data
+ * structure to the HTML parser. The subclasses with the fields, pre-
+ * initialized, for example, for HTML 4.01, can be available only between
+ * the implementation specific classes
+ * ( for example, {@link gnu.javax.swing.text.html.parser.HTML_401F }
+ * in this implementation).</p>
+ * <p>
+ * If you need more information about SGML DTD documents,
+ * the author suggests to read SGML tutorial on
+ * <a href="http://www.w3.org/TR/WD-html40-970708/intro/sgmltut.html"
+ * >http://www.w3.org/TR/WD-html40-970708/intro/sgmltut.html</a>.
+ * We also recommend Goldfarb C.F (1991) <i>The SGML Handbook</i>,
+ * Oxford University Press, 688 p, ISBN: 0198537379.
+ * </p>
+ * <p>
+ * Warning: the html, head and other tag fields will only be automatically
+ * assigned if the VM has the correctly implemented reflection mechanism.
+ * As these fields are not used anywhere in the implementation, not
+ * exception will be thrown in the opposite case.
+ * </p>
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
+ */
+public class DTD
+ implements DTDConstants
+{
+ /**
+ * The version of the persistent data format.
+ * @specnote This was made <code>final</code> in 1.5.
+ */
+ public static final int FILE_VERSION = 1;
+
+ /**
+ * The table of existing available DTDs.
+ */
+ static Hashtable dtdHash = new Hashtable();
+
+ /**
+ * The applet element for this DTD.
+ */
+ public Element applet;
+
+ /**
+ * The base element for this DTD.
+ */
+ public Element base;
+
+ /**
+ * The body element for this DTD.
+ */
+ public Element body;
+
+ /**
+ * The head element for this DTD.
+ */
+ public Element head;
+
+ /**
+ * The html element for this DTD.
+ */
+ public Element html;
+
+ /**
+ * The isindex element of for this DTD.
+ */
+ public Element isindex;
+
+ /**
+ * The meta element for this DTD.
+ */
+ public Element meta;
+
+ /**
+ * The p element for this DTD.
+ */
+ public Element p;
+
+ /**
+ * The param element for this DTD.
+ */
+ public Element param;
+
+ /**
+ * The pcdata for this DTD.
+ */
+ public Element pcdata;
+
+ /**
+ * The title element for this DTD.
+ */
+ public Element title;
+
+ /**
+ * The element for accessing all DTD elements by name.
+ */
+ public Hashtable elementHash = new Hashtable();
+
+ /**
+ * The entity table for accessing all DTD entities by name.
+ */
+ public Hashtable entityHash = new Hashtable();
+
+ /**
+ * The name of this DTD.
+ */
+ public String name;
+
+ /**
+ * Contains all elements in this DTD. The
+ * javax.swing.text.html.parser.Element#index field of all elements
+ * in this vector is set to the element position in this vector.
+ */
+ public Vector elements = new Vector();
+
+ /** Create a new DTD with the specified name. */
+ protected DTD(String a_name)
+ {
+ name = a_name;
+ }
+
+ /** Get this DTD by name. The current implementation
+ * only looks in the internal table of DTD documents. If no corresponding
+ * entry is found, the new entry is created, placed into
+ * the table and returned. */
+ public static DTD getDTD(String name)
+ throws IOException
+ {
+ DTD d = (DTD) dtdHash.get(name);
+
+ if (d == null)
+ {
+ d = new DTD(name);
+ dtdHash.put(d.name, d);
+ }
+
+ return d;
+ }
+
+ /**
+ * Get the element by the element name. If the element is not yet
+ * defined, it is newly created and placed into the element table.
+ * If the element name matches (ingoring case) a public non static
+ * element field in this class, this field is assigned to the value
+ * of the newly created element.
+ */
+ public Element getElement(String element_name)
+ {
+ return newElement(element_name);
+ }
+
+ /**
+ * Get the element by the value of its
+ * {@link javax.swing.text.html.parser.Element#index} field.
+ */
+ public Element getElement(int index)
+ {
+ return (Element) elements.get(index);
+ }
+
+ /**
+ * Get the entity with the given identifier.
+ * @param id that can be returned by
+ * {@link javax.swing.text.html.parser.Entity#name2type(String an_entity)}
+ * @return The entity from this DTD or null if there is no entity with
+ * such id or such entity is not present in the table of this instance.
+ */
+ public Entity getEntity(int id)
+ {
+ String name = Entity.mapper.get(id);
+
+ if (name != null)
+ return (Entity) entityHash.get(name);
+ else
+ return null;
+ }
+
+ /**
+ * Get the named entity by its name.
+ */
+ public Entity getEntity(String entity_name)
+ {
+ return (Entity) entityHash.get(entity_name);
+ }
+
+ /**
+ * Get the name of this instance of DTD
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Creates, adds into the entity table and returns the
+ * character entity like <code><</code>
+ * (means '<code><</code>' );
+ * @param name The entity name (without heading & and closing ;)
+ * @param type The entity type
+ * @param character The entity value (single character)
+ * @return The created entity
+ */
+ public Entity defEntity(String name, int type, int character)
+ {
+ Entity e = newEntity(name, type);
+ e.data = new char[] { (char) character };
+ return e;
+ }
+
+ /**
+ * Define the attributes for the element with the given name.
+ * If the element is not exist, it is created.
+ * @param forElement
+ * @param attributes
+ */
+ public void defineAttributes(String forElement, AttributeList attributes)
+ {
+ Element e = (Element) elementHash.get(forElement.toLowerCase());
+
+ if (e == null)
+ e = newElement(forElement);
+
+ e.atts = attributes;
+ }
+
+ /**
+ * Defines the element and adds it to the element table. Sets the
+ * <code>Element.index</code> field to the value, unique for this
+ * instance of DTD. If the element with the given name already exists,
+ * replaces all other its settings by the method argument values.
+ * @param name the name of the element
+ * @param type the type of the element
+ * @param headless true if the element needs no starting tag
+ * (should not occur in HTML).
+ * @param tailless true if the element needs no ending tag (like
+ * <code><hr></code>
+ * @param content the element content
+ * @param exclusions the set of elements that must not occur inside
+ * this element. The <code>Element.index</code> value defines which
+ * bit in this bitset corresponds to that element.
+ * @param inclusions the set of elements that can occur inside this
+ * element. the <code>Element.index</code> value defines which
+ * bit in this bitset corresponds to that element.
+ * @param attributes the element attributes.
+ * @return the newly defined element.
+ */
+ public Element defineElement(String name, int type, boolean headless,
+ boolean tailless, ContentModel content,
+ BitSet exclusions, BitSet inclusions,
+ AttributeList attributes
+ )
+ {
+ Element e = newElement(name);
+ e.type = type;
+ e.oStart = headless;
+ e.oEnd = tailless;
+ e.content = content;
+ e.exclusions = exclusions;
+ e.inclusions = inclusions;
+ e.atts = attributes;
+
+ return e;
+ }
+
+ /**
+ * Creates, intializes and adds to the entity table the new
+ * entity.
+ * @param name the name of the entity
+ * @param type the type of the entity
+ * @param data the data section of the entity
+ * @return the created entity
+ */
+ public Entity defineEntity(String name, int type, char[] data)
+ {
+ Entity e = newEntity(name, type);
+ e.data = data;
+
+ return e;
+ }
+
+ /** Place this DTD into the DTD table. */
+ public static void putDTDHash(String name, DTD dtd)
+ {
+ dtdHash.put(name, dtd);
+ }
+
+ /**
+ * <p>Reads DTD from an archived format. This format is not standardized
+ * and differs between implementations.</p><p> This implementation
+ * reads and defines all entities and elements using
+ * ObjectInputStream. The elements and entities can be written into the
+ * stream in any order. The objects other than elements and entities
+ * are ignored.</p>
+ * @param stream A data stream to read from.
+ * @throws java.io.IOException If one is thrown by the input stream
+ */
+ public void read(DataInputStream stream)
+ throws java.io.IOException
+ {
+ ObjectInputStream oi = new ObjectInputStream(stream);
+ Object def;
+ try
+ {
+ while (true)
+ {
+ def = oi.readObject();
+ if (def instanceof Element)
+ {
+ Element e = (Element) def;
+ elementHash.put(e.name.toLowerCase(), e);
+ assignField(e);
+ }
+ else if (def instanceof Entity)
+ {
+ Entity e = (Entity) def;
+ entityHash.put(e.name, e);
+ }
+ }
+ }
+ catch (ClassNotFoundException ex)
+ {
+ throw new IOException(ex.getMessage());
+ }
+ catch (EOFException ex)
+ {
+ // ok EOF
+ }
+ }
+
+ /**
+ * Returns the name of this instance of DTD.
+ */
+ public String toString()
+ {
+ return name;
+ }
+
+ /**
+ * Creates and returns new attribute (not an attribute list).
+ * @param name the name of this attribute
+ * @param type the type of this attribute (FIXED, IMPLIED or
+ * REQUIRED from <code>DTDConstants</code>).
+ * @param modifier the modifier of this attribute
+ * @param default_value the default value of this attribute
+ * @param allowed_values the allowed values of this attribute. The multiple
+ * possible values in this parameter are supposed to be separated by
+ * '|', same as in SGML DTD <code><!ATTLIST </code>tag. This parameter
+ * can be null if no list of allowed values is specified.
+ * @param atts the previous attribute of this element. This is
+ * placed to the field
+ * {@link javax.swing.text.html.parser.AttributeList#next },
+ * creating a linked list.
+ * @return The attributes.
+ */
+ protected AttributeList defAttributeList(String name, int type, int modifier,
+ String default_value,
+ String allowed_values,
+ AttributeList atts
+ )
+ {
+ AttributeList al = new AttributeList(name);
+ al.modifier = modifier;
+ al.value = default_value;
+ al.next = atts;
+
+ if (allowed_values != null)
+ {
+ StringTokenizer st = new StringTokenizer(allowed_values, " \t|");
+ Vector v = new Vector(st.countTokens());
+
+ while (st.hasMoreTokens())
+ v.add(st.nextToken());
+
+ al.values = v;
+ }
+
+ return al;
+ }
+
+ /**
+ * Creates a new content model.
+ * @param type specifies the BNF operation for this content model.
+ * The valid operations are documented in the
+ * {@link javax.swing.text.html.parser.ContentModel#type }.
+ * @param content the content of this content model
+ * @param next if the content model is specified by BNF-like
+ * expression, contains the rest of this expression.
+ * @return The newly created content model.
+ */
+ protected ContentModel defContentModel(int type, Object content,
+ ContentModel next
+ )
+ {
+ ContentModel model = new ContentModel();
+ model.type = type;
+ model.next = next;
+ model.content = content;
+
+ return model;
+ }
+
+ /**
+ * Defines a new element and adds it to the element table.
+ * If the element alredy exists,
+ * overrides it settings with the specified values.
+ * @param name the name of the new element
+ * @param type the type of the element
+ * @param headless true if the element needs no starting tag
+ * @param tailless true if the element needs no closing tag
+ * @param content the element content.
+ * @param exclusions the elements that must be excluded from the
+ * content of this element, in all levels of the hierarchy.
+ * @param inclusions the elements that can be included as the
+ * content of this element.
+ * @param attributes the element attributes.
+ * @return the created or updated element.
+ */
+ protected Element defElement(String name, int type, boolean headless,
+ boolean tailless, ContentModel content,
+ String[] exclusions, String[] inclusions,
+ AttributeList attributes
+ )
+ {
+ // compute the bit sets
+ BitSet exclude = bitSet(exclusions);
+ BitSet include = bitSet(inclusions);
+
+ Element e =
+ defineElement(name, type, headless, tailless, content, exclude, include,
+ attributes
+ );
+
+ return e;
+ }
+
+ /**
+ * Creates, intializes and adds to the entity table the new
+ * entity.
+ * @param name the name of the entity
+ * @param type the type of the entity
+ * @param data the data section of the entity
+ * @return the created entity
+ */
+ protected Entity defEntity(String name, int type, String data)
+ {
+ Entity e = newEntity(name, type);
+ e.data = data.toCharArray();
+
+ return e;
+ }
+
+ private void assignField(Element e)
+ {
+ String element_name = e.name;
+ try
+ {
+ // Assign the field via reflection.
+ Field f = getClass().getField(element_name.toLowerCase());
+ if ((f.getModifiers() & Modifier.PUBLIC) != 0)
+ if ((f.getModifiers() & Modifier.STATIC) == 0)
+ if (f.getType().isAssignableFrom(e.getClass()))
+ f.set(this, e);
+ }
+ catch (IllegalAccessException ex)
+ {
+ unexpected(ex);
+ }
+ catch (NoSuchFieldException ex)
+ {
+ // This is ok.
+ }
+
+ // Some virtual machines may still lack the proper
+ // implementation of reflection. As the tag fields
+ // are not used anywhere in this implementation,
+ // (and this class is also rarely used by the end user),
+ // it may be better not to crash everything by throwing an error
+ // for each case when the HTML parsing is required.
+ catch (Throwable t)
+ {
+ // This VM has no reflection mechanism implemented!
+ if (t instanceof OutOfMemoryError)
+ throw (Error) t;
+ }
+ }
+
+ /**
+ * Create the bit set for this array of elements.
+ * The unknown elements are automatically defined and added
+ * to the element table.
+ * @param elements
+ * @return The bit set.
+ */
+ private BitSet bitSet(String[] elements)
+ {
+ BitSet b = new BitSet();
+
+ for (int i = 0; i < elements.length; i++)
+ {
+ Element e = getElement(elements [ i ]);
+
+ if (e == null)
+ e = newElement(elements [ i ]);
+
+ b.set(e.index);
+ }
+
+ return b;
+ }
+
+ /**
+ * Find the element with the given name in the element table.
+ * If not find, create a new element with this name and add to the
+ * table.
+ * @param name the name of the element
+ * @return the found or created element.
+ */
+ private Element newElement(String name)
+ {
+ Element e = (Element) elementHash.get(name.toLowerCase());
+
+ if (e == null)
+ {
+ e = new Element();
+ e.name = name;
+ e.index = elements.size();
+ elements.add(e);
+ elementHash.put(e.name.toLowerCase(), e);
+ assignField(e);
+ }
+ return e;
+ }
+
+ /**
+ * Creates and adds to the element table the entity with an
+ * unitialized data section. Used internally.
+ * @param name the name of the entity
+ * @param type the type of the entity, a bitwise combination
+ * of GENERAL, PARAMETER, SYSTEM and PUBLIC.
+ *
+ * @return the created entity
+ */
+ private Entity newEntity(String name, int type)
+ {
+ Entity e = new Entity(name, type, null);
+ entityHash.put(e.name, e);
+ return e;
+ }
+
+ private void unexpected(Exception ex)
+ {
+ throw new Error("This should never happen, report a bug", ex);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DTDConstants.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DTDConstants.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DTDConstants.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DTDConstants.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,292 @@
+/* DTDConstants.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html.parser;
+
+/**
+ * <p>This class defines the SGML basic types, used for describing HTML 4.01
+ * at <a href="http://www.w3.org/TR/html4/types.html"
+ * >http://www.w3.org/TR/html4/types.html</a>. Not all constants,
+ * defined here, are actually used in HTML 4.01 SGML specification. Some others
+ * are defined just as part of the required implementation.
+ * </p>
+ * <p>
+ * If you need more information about SGML DTD documents,
+ * the author suggests to read SGML tutorial on
+ * <a href="http://www.w3.org/TR/WD-html40-970708/intro/sgmltut.html"
+ * >http://www.w3.org/TR/WD-html40-970708/intro/sgmltut.html</a>.
+ * We also recommend Goldfarb C.F (1991) <i>The SGML Handbook</i>,
+ * Oxford University Press, 688 p, ISBN: 0198537379.
+ * </p>
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
+ */
+public interface DTDConstants
+{
+ /* ----- The data types, used in HTML 4.01 SGML definition: ---- */
+
+ /**
+ * The CDATA (Character data) constant, specifes the content model,
+ * consisting of characters only. In SGML for HTML 4.01, the character
+ * entities must be replaced by characters, the line feeds must be
+ * ignored and any number of the subsequent carriage returns or tabs
+ * must be replaced by a single space.
+ */
+ int CDATA = 1;
+
+ /**
+ * The EMPTY constant, means the element with no content.
+ */
+ int EMPTY = 17;
+
+ /**
+ * The ID constant, means that the token is the unique identifier.
+ * This identifier can be referenced by attribute with value of IDREF.
+ * The identifier must begin with letter, followed by any number of
+ * letters, digits, hyphens, underscores, colons and periods.
+ */
+ int ID = 4;
+
+ /**
+ * The IDREF constant, specifies reference to a valid ID within
+ * the document.
+ */
+ int IDREF = 5;
+
+ /**
+ * The IDREFS constant, a space separated list of IDREFs
+ */
+ int IDREFS = 6;
+
+ /**
+ * The NAME constant, means the token that
+ * must begin with letter, followed by any number of
+ * letters, digits, hyphens, underscores, colons and periods.
+ */
+ int NAME = 7;
+
+ /**
+ * The NAMES constant, specifies a space separated of NAMEs.
+ */
+ int NAMES = 8;
+
+ /**
+ * The NMTOKEN constant, specifies the attribute, consisting of
+ * characters that can be either digits or alphabetic characters).
+ */
+ int NMTOKEN = 9;
+
+ /**
+ * The NMTOKENS constant, specifies a list of NMTOKENs.
+ */
+ int NMTOKENS = 10;
+
+ /**
+ * The NOTATION constant, a previously defined data type.
+ */
+ int NOTATION = 11;
+
+ /**
+ * The NUMBER constant (means that the attribute consists of at least
+ * one decimal digit).
+ */
+ int NUMBER = 12;
+
+ /**
+ * The NUMBERS constant, specifies a space separated list of NUMBERs.
+ */
+ int NUMBERS = 13;
+
+ /**
+ * The NUTOKEN constant.
+ */
+ int NUTOKEN = 14;
+
+ /**
+ * The NUTOKENS constant.
+ */
+ int NUTOKENS = 15;
+
+ /* -------
+ The entity scope constants.
+ As these four constants are combined with the bitwise OR,
+ they are defined in the hexadecimal notation.
+ The reason of setting the two bits at once (for PUBLIC and SYSTEM)
+ is probably historical. ----- */
+
+ /**
+ * The PUBLIC constant, specifies the public entity. The PUBLIC entities
+ * are assumed to be known to many systems so that a full declaration
+ * need not be transmitted. For example,
+ * <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN">
+ */
+ int PUBLIC = 0xA;
+
+ /**
+ * The SYSTEM constant, specifies the system entitiy. The system entities
+ * are assumed to be known but require the clear identifer
+ * (like the file path), where they can be found in the system.
+ * For example, <code>
+ * <DOCTYPE html SYSTEM "/path/to/file.dtd"> </code>.
+ */
+ int SYSTEM = 0x11;
+
+ /**
+ * The PARAMETER constant, specifies that entity is only valid
+ * inside SGML DTD scope.
+ */
+ int PARAMETER = 0x40000;
+
+ /**
+ * The GENERAL constant, specifies theat the entity is valid in the
+ * whole HTML document scope.
+ */
+ int GENERAL = 0x10000;
+
+ /* ---- The constants, defining if the element attribute is required,
+ fixed or implied. ---- */
+
+ /**
+ * The attribute modifier #REQUIRED constant, indicates that the
+ * value must be supplied.
+ */
+ int REQUIRED = 2;
+
+ /**
+ * The attribute modifier #FIXED constant, means that the attribute has
+ * the fixed value that cannot be changed.
+ */
+ int FIXED = 1;
+
+ /**
+ * The attribute modifier #IMPLIED constant,
+ * indicating that for this attribute the user agent must provide
+ * the value itself.
+ */
+ int IMPLIED = 5;
+
+ /**
+ * The attribute modifier #CURRENT constant, specifies the value
+ * that at any point in the document is the last value supplied for
+ * that element. A value is required to be supplied for the first
+ * occurrence of an element
+ */
+ int CURRENT = 3;
+
+ /**
+ * The attribute modifier #CONREF constant, specifies the IDREF value of
+ * the reference to content in another location of the document.
+ * The element with this attribute is empty, the content from
+ * that another location must be used instead.
+ */
+ int CONREF = 4;
+
+ /* ----- Constants, defining if the element
+ start and end tags are required. ---- */
+
+ /**
+ * The STARTTAG, meaning that the element needs a starting tag.
+ */
+ int STARTTAG = 13;
+
+ /**
+ * The ENDTAG constant, meaning that the element needs a closing tag.
+ */
+ int ENDTAG = 14;
+
+ /* ----- Other constants: ----- */
+
+ /**
+ * The ANY constant, specifies
+ * an attribute, consisting from arbitrary characters.
+ */
+ int ANY = 19;
+
+ /**
+ * The DEFAULT constant, specifies the default value.
+ */
+ int DEFAULT = 131072;
+
+ /**
+ * The ENTITIES constant (list of ENTITYes)
+ */
+ int ENTITIES = 3;
+
+ /**
+ * The ENTITY constant, meaning the numeric or symbolic name of some
+ * HTML data.
+ */
+ int ENTITY = 2;
+
+ /**
+ * The MD constant.
+ */
+ int MD = 16;
+
+ /**
+ * The MODEL constant.
+ */
+ int MODEL = 18;
+
+ /**
+ * The MS constant.
+ */
+ int MS = 15;
+
+ /**
+ * The PI (Processing Instruction) constant, specifies a processing
+ * instruction. Processing instructions are used to embed information
+ * intended for specific applications.
+ */
+ int PI = 12;
+
+ /**
+ * The RCDATA constant (Entity References and Character Data), specifies
+ * the content model, consisting of characters AND entities. The
+ * "<" is threated as an ordinary character, but
+ * "<code>&name;</code>" still means the general entity with
+ * the given name.
+ */
+ int RCDATA = 16;
+
+ /**
+ * The SDATA constant. Means that the value contains the entity name
+ * and the replacement value of a character entity reference.
+ */
+ int SDATA = 11;
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DocumentParser.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DocumentParser.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DocumentParser.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/DocumentParser.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,268 @@
+/* DocumentParser.java -- A parser for HTML documents.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html.parser;
+
+import gnu.javax.swing.text.html.parser.htmlAttributeSet;
+import javax.swing.text.html.parser.Parser;
+
+import java.io.IOException;
+import java.io.Reader;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.html.HTMLEditorKit;
+
+/**
+ * <p>A simple error-tolerant HTML parser that uses a DTD document
+ * to access data on the possible tokens, arguments and syntax.</p>
+ * <p> The parser reads an HTML content from a Reader and calls various
+ * notifying methods (which should be overridden in a subclass)
+ * when tags or data are encountered.</p>
+ * <p>Some HTML elements need no opening or closing tags. The
+ * task of this parser is to invoke the tag handling methods also when
+ * the tags are not explicitly specified and must be supposed using
+ * information, stored in the DTD.
+ * For example, parsing the document
+ * <p><table><tr><td>a<td>b<td>c</tr> <br>
+ * will invoke exactly the handling methods exactly in the same order
+ * (and with the same parameters) as if parsing the document: <br>
+ * <em><html><head></head><body><table><
+ * tbody></em><tr><td>a<em></td></em><td>b<em>
+ * </td></em><td>c<em></td></tr></em><
+ * <em>/tbody></table></body></html></em></p>
+ * (supposed tags are given in italics). The parser also supports
+ * obsolete elements of HTML syntax.<p>
+ * </p>
+ * In this implementation, DocumentParser is directly derived from its
+ * ancestor without changes of functionality.
+ * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
+ */
+public class DocumentParser
+ extends Parser
+ implements DTDConstants
+{
+ /**
+ * The enclosed working parser class.
+ */
+ private class gnuParser
+ extends gnu.javax.swing.text.html.parser.support.Parser
+ {
+ private gnuParser(DTD d)
+ {
+ super(d);
+ }
+
+ protected final void handleComment(char[] comment)
+ {
+ parser.handleComment(comment);
+ callBack.handleComment(comment, hTag.where.startPosition);
+ }
+
+ protected final void handleEmptyTag(TagElement tag)
+ throws javax.swing.text.ChangedCharSetException
+ {
+ parser.handleEmptyTag(tag);
+ callBack.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
+ hTag.where.startPosition
+ );
+ }
+
+ protected final void handleEndTag(TagElement tag)
+ {
+ parser.handleEndTag(tag);
+ callBack.handleEndTag(tag.getHTMLTag(), hTag.where.startPosition);
+ }
+
+ protected final void handleError(int line, String message)
+ {
+ parser.handleError(line, message);
+ callBack.handleError(message, hTag.where.startPosition);
+ }
+
+ protected final void handleStartTag(TagElement tag)
+ {
+ parser.handleStartTag(tag);
+ htmlAttributeSet attributes = gnu.getAttributes();
+
+ if (tag.fictional())
+ attributes.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
+ Boolean.TRUE
+ );
+
+ callBack.handleStartTag(tag.getHTMLTag(), attributes,
+ hTag.where.startPosition
+ );
+ }
+
+ protected final void handleText(char[] text)
+ {
+ parser.handleText(text);
+ callBack.handleText(text, hTag.where.startPosition);
+ }
+
+ DTD getDTD()
+ {
+ return dtd;
+ }
+ }
+
+ /**
+ * This field is used to access the identically named
+ * methods of the outer class.
+ * This is package-private to avoid an accessor method.
+ */
+ DocumentParser parser = this;
+
+ /**
+ * The callback.
+ * This is package-private to avoid an accessor method.
+ */
+ HTMLEditorKit.ParserCallback callBack;
+
+ /**
+ * The reference to the working class of HTML parser that is
+ * actually used to parse the document.
+ * This is package-private to avoid an accessor method.
+ */
+ gnuParser gnu;
+
+ /**
+ * Creates a new parser that uses the given DTD to access data on the
+ * possible tokens, arguments and syntax. There is no single - step way
+ * to get a default DTD; you must either refer to the implementation -
+ * specific packages, write your own DTD or obtain the working instance
+ * of parser in other way, for example, by calling
+ * {@link javax.swing.text.html.HTMLEditorKit#getParser()}.
+ *
+ * @param a_dtd a DTD to use.
+ */
+ public DocumentParser(DTD a_dtd)
+ {
+ super(a_dtd);
+ gnu = new gnuParser(a_dtd);
+ }
+
+ /**
+ * Parses the HTML document, calling methods of the provided
+ * callback. This method must be multithread - safe.
+ * @param reader The reader to read the HTML document from
+ * @param aCallback The callback that is notifyed about the presence
+ * of HTML elements in the document.
+ * @param ignoreCharSet If thrue, any charset changes during parsing
+ * are ignored.
+ * @throws java.io.IOException
+ */
+ public void parse(Reader reader, HTMLEditorKit.ParserCallback aCallback,
+ boolean ignoreCharSet
+ )
+ throws IOException
+ {
+ callBack = aCallback;
+ gnu.parse(reader);
+
+ callBack.handleEndOfLineString(gnu.getEndOfLineSequence());
+ try
+ {
+ callBack.flush();
+ }
+ catch (BadLocationException ex)
+ {
+ // Convert this into the supported type of exception.
+ throw new IOException(ex.getMessage());
+ }
+ }
+
+ /**
+ * Handle HTML comment. The default method returns without action.
+ * @param comment the comment being handled
+ */
+ protected void handleComment(char[] comment)
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * Handle the tag with no content, like <br>. The method is
+ * called for the elements that, in accordance with the current DTD,
+ * has an empty content.
+ * @param tag the tag being handled.
+ * @throws javax.swing.text.ChangedCharSetException
+ */
+ protected void handleEmptyTag(TagElement tag)
+ throws javax.swing.text.ChangedCharSetException
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * The method is called when the HTML closing tag ((like </table>)
+ * is found or if the parser concludes that the one should be present
+ * in the current position.
+ * @param tag The tag being handled
+ */
+ protected void handleEndTag(TagElement tag)
+ {
+ // This default implementation does nothing.
+ }
+
+ /* Handle error that has occured in the given line. */
+ protected void handleError(int line, String message)
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * The method is called when the HTML opening tag ((like <table>)
+ * is found or if the parser concludes that the one should be present
+ * in the current position.
+ * @param tag The tag being handled
+ */
+ protected void handleStartTag(TagElement tag)
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * Handle the text section.
+ * @param text a section text.
+ */
+ protected void handleText(char[] text)
+ {
+ // This default implementation does nothing.
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Element.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Element.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Element.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Element.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,317 @@
+/* Element.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html.parser;
+
+import gnu.javax.swing.text.html.parser.support.gnuStringIntMapper;
+
+import java.io.Serializable;
+
+import java.util.BitSet;
+
+/**
+ * <p>
+ * Stores the element information, obtained by parsing SGML DTD
+ * tag <code><!ELEMENT .. ></code>. This class has no public
+ * constructor and can only be instantiated using the
+ * {@link javax.swing.text.html.parser.DTD } methods</p>
+ *
+ * <p>SGML defines elements that represent structures or
+ * behavior. An element typically consists of a start tag, content, and an
+ * end tag. Hence the elements are not tags. The HTML 4.0 definition specifies
+ * that some elements are not required to have the end tags. Also, some
+ * HTML elements (like <code><hr></code>) have no content. Element names
+ * are case sensitive.</p>
+ * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
+ */
+public final class Element
+ implements DTDConstants, Serializable
+{
+ /**
+ * Package level mapper between type names and they string values.
+ */
+ static final gnuStringIntMapper mapper =
+ new gnuStringIntMapper()
+ {
+ protected void create()
+ {
+ add("CDATA", DTDConstants.CDATA);
+ add("RCDATA", DTDConstants.RCDATA);
+ add("EMPTY", DTDConstants.EMPTY);
+ add("ANY", DTDConstants.ANY);
+ }
+ };
+
+ /** Use serialVersionUID for interoperability. */
+ private static final long serialVersionUID = -6717939384601675586L;
+
+ /**
+ * The element attributes.
+ */
+ public AttributeList atts;
+
+ /**
+ * Contains refernces to elements that must NOT occur inside this element,
+ * at any level of hierarchy.
+ */
+ public BitSet exclusions;
+
+ /**
+ * Contains refernces to elements that must CAN occur inside this element,
+ * at any level of hierarchy.
+ */
+ public BitSet inclusions;
+
+ /**
+ * The content model, defining elements, entities and DTD text
+ * that may/may not occur inside this element.
+ */
+ public ContentModel content;
+
+ /**
+ * A field to store additional user data for this Element.
+ */
+ public Object data;
+
+ /**
+ * The element name.
+ */
+ public String name;
+
+ /**
+ * True is this element need not to have the closing tag, false
+ * otherwise. The HTML 4.0 definition specifies
+ * that some elements (like <code><hr></code>are
+ * not required to have the end tags.
+ */
+ public boolean oEnd;
+
+ /**
+ * True is this element need not to have the starting tag, false
+ * otherwise. The HTML 4.0 definition specifies
+ * that some elements (like <code><head></code> or
+ * <code><body></code>) are
+ * not required to have the start tags.
+
+ */
+ public boolean oStart;
+
+ /**
+ * This field contains the unique integer identifier of this Element,
+ * used to refer the element (more exactly, the element flag)
+ * in <code>inclusions</code> and <code>exclusions</code> bit set.
+ */
+ public int index;
+
+ /**
+ * The element type, containing value, defined in DTDConstants.
+ * In this implementation, the element type can be
+ * CDATA, RCDATA, EMPTY or ANY.
+ */
+ public int type;
+
+ /**
+ * The default constructor must have package level access in this
+ * class. Use DTD.defineElement(..) to create an element when required.
+ */
+ Element()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Converts the string representation of the element type
+ * into its unique integer identifier, defined in DTDConstants.
+ * @param a_type A name of the type
+ * @return DTDConstants.CDATA, DTDConstants.RCDATA, DTDConstants.EMPTY,
+ * DTDConstants.ANY or null if the type name is not
+ * "CDATA", "RCDATA", "EMPTY" or "ANY". This function is case sensitive.
+ * @throws NullPointerException if <code>a_type</code> is null.
+ */
+ public static int name2type(String a_type)
+ {
+ return mapper.get(a_type);
+ }
+
+ /**
+ * Get the element attribute by name.
+ * @param attribute the attribute name, case insensitive.
+ * @return the correspoding attribute of this element. The class,
+ * for storing as attribute list, as a single attribute, is used to
+ * store a single attribute in this case.
+ * @throws NullPointerException if the attribute name is null.
+ */
+ public AttributeList getAttribute(String attribute)
+ {
+ AttributeList a = atts;
+
+ while (a != null && !attribute.equalsIgnoreCase(a.name))
+ a = a.next;
+
+ return a;
+ }
+
+ /**
+ * Get the element attribute by its value.
+ * @param a_value the attribute value, case insensitive.
+ * @return the correspoding attribute of this element. The class,
+ * for storing as attribute list, as a single attribute, is used to
+ * store a single attribute in this case. If there are several
+ * attributes with the same value, there is no garranty, which one
+ * is returned.
+ */
+ public AttributeList getAttributeByValue(String a_value)
+ {
+ AttributeList a = atts;
+
+ if (a_value == null)
+ {
+ while (a != null)
+ {
+ if (a.value == null)
+ return a;
+
+ a = a.next;
+ }
+ }
+ else
+ {
+ while (a != null)
+ {
+ if (a.value != null && a_value.equalsIgnoreCase(a.value))
+ return a;
+
+ a = a.next;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Get all attributes of this document as an attribute list.
+ * @return The attribute list.
+ */
+ public AttributeList getAttributes()
+ {
+ return atts;
+ }
+
+ /**
+ * Get the content model, defining elements, entities and DTD text
+ * that may/may not occur inside this element.
+ */
+ public ContentModel getContent()
+ {
+ return content;
+ }
+
+ /**
+ * Returns true for the element with no content.
+ * Empty elements are defined with the SGML DTD keyword "EMPTY".
+ * @return true if content model field (content) method is equal to
+ * null or its method empty() returns true.
+ */
+ public boolean isEmpty()
+ {
+ return content == null || content.empty();
+ }
+
+ /**
+ * Get the unique integer identifier of this Element,
+ * used to refer the element (more exactly, the element flag)
+ * in <code>inclusions</code> and <code>exclusions</code> bit set.
+ * WARNING: This value may not be the same between different
+ * implementations.
+ */
+ public int getIndex()
+ {
+ return index;
+ }
+
+ /**
+ * Get the element name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Get the element type.
+ * @return one of the values, defined DTDConstants.
+ * In this implementation, the element type can be
+ * CDATA, RCDATA, EMPTY or ANY.
+ */
+ public int getType()
+ {
+ return type;
+ }
+
+ /**
+ * True is this element need not to have the starting tag, false
+ * otherwise.s element need not to have the closing tag, false
+ * otherwise. The HTML 4.0 definition specifies
+ * that some elements (like <code><hr></code>are
+ * not required to have the end tags.
+ */
+ public boolean omitEnd()
+ {
+ return oEnd;
+ }
+
+ /**
+ * True is this element need not to have the closing tag, false
+ * otherwise. The HTML 4.0 definition specifies
+ * that some elements (like <code><head></code> or
+ * <code><body></code>) are
+ * not required to have the start tags.
+ */
+ public boolean omitStart()
+ {
+ return oStart;
+ }
+
+ /**
+ * Returns the name of this element.
+ */
+ public String toString()
+ {
+ return name;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Entity.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Entity.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Entity.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Entity.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,185 @@
+/* Entity.java -- Stores information, obtained by parsing SGML DTL
+ * <!ENTITY % .. > tag
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html.parser;
+
+import gnu.javax.swing.text.html.parser.support.gnuStringIntMapper;
+
+import java.io.Serializable;
+
+/**
+ * <p>Stores information, obtained by parsing SGML DTL
+ * <!ENTITY % .. > tag.</p>
+ * <p>
+ * The entity defines some kind of macro that can be used elsewhere in
+ * the document.
+ * When the macro is referred to by the name in the DTD, it is expanded into
+ * a string
+ * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
+ */
+public final class Entity
+ implements DTDConstants
+{
+ /**
+ * Package level mapper between type names and they string values.
+ */
+ final static gnuStringIntMapper mapper =
+ new gnuStringIntMapper()
+ {
+ protected void create()
+ {
+ add("ANY", DTDConstants.ANY);
+ add("CDATA", DTDConstants.CDATA);
+ add("PUBLIC", DTDConstants.PUBLIC);
+ add("SDATA", DTDConstants.SDATA);
+ add("PI", DTDConstants.PI);
+ add("STARTTAG", DTDConstants.STARTTAG);
+ add("ENDTAG", DTDConstants.ENDTAG);
+ add("MS", DTDConstants.MS);
+ add("MD", DTDConstants.MD);
+ add("SYSTEM", DTDConstants.SYSTEM);
+ }
+ };
+
+ /**
+ * The entity name.
+ */
+ public String name;
+
+ /**
+ * The entity data
+ */
+ public char[] data;
+
+ /**
+ * The entity type.
+ */
+ public int type;
+
+ /**
+ * String representation of the entity data.
+ */
+ private String sdata;
+
+ /**
+ * Create a new entity
+ * @param a_name the entity name
+ * @param a_type the entity type
+ * @param a_data the data replacing the entity reference
+ */
+ public Entity(String a_name, int a_type, char[] a_data)
+ {
+ name = a_name;
+ type = a_type;
+ data = a_data;
+ }
+
+ /**
+ * Converts a given string to the corresponding entity type.
+ * @return a value, defined in DTDConstants (one of
+ * PUBLIC, CDATA, SDATA, PI, STARTTAG, ENDTAG, MS, MD, SYSTEM)
+ * or CDATA if the parameter is not a valid entity type.
+ */
+ public static int name2type(String an_entity)
+ {
+ int r = mapper.get(an_entity);
+ return (r == 0) ? DTDConstants.CDATA : r;
+ }
+
+ /**
+ * Get the entity data.
+ */
+ public char[] getData()
+ {
+ return data;
+ }
+
+ /**
+ * Returns true for general entities. Each general entity can be
+ * referenced as <code>&entity-name;</code>. Such entities are
+ * defined by the SGML DTD tag
+ * <code><!ENTITY <i>name</i> "<i>value</i>"></code>. The general
+ * entities can be used anywhere in the document.
+ */
+ public boolean isGeneral()
+ {
+ return (type & DTDConstants.GENERAL) != 0;
+ }
+
+ /**
+ * Get the entity name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Returns true for parameter entities. Each parameter entity can be
+ * referenced as <code>&entity-name;</code>. Such entities are
+ * defined by the SGML DTD tag
+ * <code><!ENTITY % <i>name</i> "<i>value</i>"></code>. The parameter
+ * entities can be used only in SGML context.
+ */
+ public boolean isParameter()
+ {
+ return (type & DTDConstants.PARAMETER) != 0;
+ }
+
+ /**
+ * Returns a data as String
+ */
+ public String getString()
+ {
+ if (sdata == null)
+ sdata = new String(data);
+
+ return sdata;
+ }
+
+ /**
+ * Get the entity type.
+ * @return the value of the {@link #type}.
+ */
+ public int getType()
+ {
+ return type;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Parser.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Parser.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Parser.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/Parser.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,446 @@
+/* Parser.java -- HTML parser
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html.parser;
+
+import java.io.IOException;
+import java.io.Reader;
+
+import javax.swing.text.ChangedCharSetException;
+import javax.swing.text.SimpleAttributeSet;
+
+/*
+ * FOR DEVELOPERS: To avoid regression, please run the package test
+ * textsuite/javax.swing.text.html.parser/AllParserTests after your
+ * modifications.
+ */
+
+/**
+ * <p>A simple error-tolerant HTML parser that uses a DTD document
+ * to access data on the possible tokens, arguments and syntax.</p>
+ * <p> The parser reads an HTML content from a Reader and calls various
+ * notifying methods (which should be overridden in a subclass)
+ * when tags or data are encountered.</p>
+ * <p>Some HTML elements need no opening or closing tags. The
+ * task of this parser is to invoke the tag handling methods also when
+ * the tags are not explicitly specified and must be supposed using
+ * information, stored in the DTD.
+ * For example, parsing the document
+ * <p><table><tr><td>a<td>b<td>c</tr> <br>
+ * will invoke exactly the handling methods exactly in the same order
+ * (and with the same parameters) as if parsing the document: <br>
+ * <em><html><head></head><body><table><
+ * tbody></em><tr><td>a<em></td></em><td>b<em>
+ * </td></em><td>c<em></td></tr></em><
+ * <em>/tbody></table></body></html></em></p>
+ * (supposed tags are given in italics). The parser also supports
+ * obsolete elements of HTML syntax.<p>
+ * </p>
+ * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
+ */
+public class Parser
+ implements DTDConstants
+{
+ /**
+ * The document template description that will be used to parse the documents.
+ */
+ protected DTD dtd;
+
+ /**
+ * The value of this field determines whether or not the Parser will be
+ * strict in enforcing SGML compatibility. The default value is false,
+ * stating that the parser should do everything to parse and get at least
+ * some information even from the incorrectly written HTML input.
+ */
+ protected boolean strict;
+
+ /**
+ * The package level reference to the working HTML parser in this
+ * implementation.
+ */
+ final gnu.javax.swing.text.html.parser.support.Parser gnu;
+
+ /**
+ * Creates a new parser that uses the given DTD to access data on the
+ * possible tokens, arguments and syntax. There is no single - step way
+ * to get a default DTD; you must either refer to the implementation -
+ * specific packages, write your own DTD or obtain the working instance
+ * of parser in other way, for example, by calling
+ * {@link javax.swing.text.html.HTMLEditorKit#getParser() }.
+ * @param a_dtd A DTD to use.
+ */
+ public Parser(DTD a_dtd)
+ {
+ dtd = a_dtd;
+
+ final Parser j = this;
+
+ gnu =
+ new gnu.javax.swing.text.html.parser.support.Parser(dtd)
+ {
+ protected final void handleComment(char[] comment)
+ {
+ j.handleComment(comment);
+ }
+
+ protected final void handleEOFInComment()
+ {
+ j.handleEOFInComment();
+ }
+
+ protected final void handleEmptyTag(TagElement tag)
+ throws javax.swing.text.ChangedCharSetException
+ {
+ j.handleEmptyTag(tag);
+ }
+
+ protected final void handleStartTag(TagElement tag)
+ {
+ j.handleStartTag(tag);
+ }
+
+ protected final void handleEndTag(TagElement tag)
+ {
+ j.handleEndTag(tag);
+ }
+
+ protected final void handleError(int line, String message)
+ {
+ j.handleError(line, message);
+ }
+
+ protected final void handleText(char[] text)
+ {
+ j.handleText(text);
+ }
+
+ protected final void handleTitle(char[] title)
+ {
+ j.handleTitle(title);
+ }
+
+ protected final void markFirstTime(Element element)
+ {
+ j.markFirstTime(element);
+ }
+
+ protected final void startTag(TagElement tag)
+ throws ChangedCharSetException
+ {
+ j.startTag(tag);
+ }
+
+ protected final void endTag(boolean omitted)
+ {
+ j.endTag(omitted);
+ }
+
+ protected TagElement makeTag(Element element)
+ {
+ return j.makeTag(element);
+ }
+
+ protected TagElement makeTag(Element element, boolean isSupposed)
+ {
+ return j.makeTag(element, isSupposed);
+ }
+ };
+ }
+
+ /**
+ * Parse the HTML text, calling various methods in response to the
+ * occurence of the corresponding HTML constructions.
+ * @param reader The reader to read the source HTML from.
+ * @throws IOException If the reader throws one.
+ */
+ public synchronized void parse(Reader reader)
+ throws IOException
+ {
+ gnu.parse(reader);
+ }
+
+ /**
+ * Parses DTD markup declaration. Currently returns without action.
+ * @return null.
+ * @throws java.io.IOException
+ */
+ public String parseDTDMarkup()
+ throws IOException
+ {
+ return gnu.parseDTDMarkup();
+ }
+
+ /**
+ * Parse DTD document declarations. Currently only parses the document
+ * type declaration markup.
+ * @param strBuff
+ * @return true if this is a valid DTD markup declaration.
+ * @throws IOException
+ */
+ protected boolean parseMarkupDeclarations(StringBuffer strBuff)
+ throws IOException
+ {
+ return gnu.parseMarkupDeclarations(strBuff);
+ }
+
+ /**
+ * Get the attributes of the current tag.
+ * @return The attribute set, representing the attributes of the current tag.
+ */
+ protected SimpleAttributeSet getAttributes()
+ {
+ return gnu.getAttributes();
+ }
+
+ /**
+ * Get the number of the document line being parsed.
+ * @return The current line.
+ */
+ protected int getCurrentLine()
+ {
+ return gnu.hTag.where.beginLine;
+ }
+
+ /**
+ * Get the current position in the document being parsed.
+ * @return The current position.
+ */
+ protected int getCurrentPos()
+ {
+ return gnu.hTag.where.startPosition;
+ }
+
+ /**
+ * The method is called when the HTML end (closing) tag is found or if
+ * the parser concludes that the one should be present in the
+ * current position. The method is called immediatly
+ * before calling the handleEndTag().
+ * @param omitted True if the tag is no actually present in the document,
+ * but is supposed by the parser (like </html> at the end of the
+ * document).
+ */
+ protected void endTag(boolean omitted)
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * Invokes the error handler. The default method in this implementation
+ * finally delegates the call to handleError, also providing the number of the
+ * current line.
+ */
+ protected void error(String msg)
+ {
+ gnu.error(msg);
+ }
+
+ /**
+ * Invokes the error handler. The default method in this implementation
+ * finally delegates the call to error (msg+": '"+invalid+"'").
+ */
+ protected void error(String msg, String invalid)
+ {
+ gnu.error(msg, invalid);
+ }
+
+ /**
+ * Invokes the error handler. The default method in this implementation
+ * finally delegates the call to error (parm1+" "+ parm2+" "+ parm3).
+ */
+ protected void error(String parm1, String parm2, String parm3)
+ {
+ gnu.error(parm1, parm2, parm3);
+ }
+
+ /**
+ * Invokes the error handler. The default method in this implementation
+ * finally delegates the call to error
+ * (parm1+" "+ parm2+" "+ parm3+" "+ parm4).
+ */
+ protected void error(String parm1, String parm2, String parm3, String parm4)
+ {
+ gnu.error(parm1, parm2, parm3, parm4);
+ }
+
+ /**
+ * In this implementation, this is never called and returns without action.
+ */
+ protected void flushAttributes()
+ {
+ gnu.flushAttributes();
+ }
+
+ /**
+ * Handle HTML comment. The default method returns without action.
+ * @param comment The comment being handled
+ */
+ protected void handleComment(char[] comment)
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * This is additionally called in when the HTML content terminates
+ * without closing the HTML comment. This can only happen if the
+ * HTML document contains errors (for example, the closing --;gt is
+ * missing. The default method calls the error handler.
+ */
+ protected void handleEOFInComment()
+ {
+ gnu.error("Unclosed comment");
+ }
+
+ /**
+ * Handle the tag with no content, like <br>. The method is
+ * called for the elements that, in accordance with the current DTD,
+ * has an empty content.
+ * @param tag The tag being handled.
+ * @throws javax.swing.text.ChangedCharSetException
+ */
+ protected void handleEmptyTag(TagElement tag)
+ throws ChangedCharSetException
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * The method is called when the HTML closing tag ((like </table>)
+ * is found or if the parser concludes that the one should be present
+ * in the current position.
+ * @param tag The tag being handled
+ */
+ protected void handleEndTag(TagElement tag)
+ {
+ // This default implementation does nothing.
+ }
+
+ /* Handle error that has occured in the given line. */
+ protected void handleError(int line, String message)
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * The method is called when the HTML opening tag ((like <table>)
+ * is found or if the parser concludes that the one should be present
+ * in the current position.
+ * @param tag The tag being handled
+ */
+ protected void handleStartTag(TagElement tag)
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * Handle the text section.
+ * <p> For non-preformatted section, the parser replaces
+ * \t, \r and \n by spaces and then multiple spaces
+ * by a single space. Additionaly, all whitespace around
+ * tags is discarded.
+ * </p>
+ * <p> For pre-formatted text (inside TEXAREA and PRE), the parser preserves
+ * all tabs and spaces, but removes <b>one</b> bounding \r, \n or \r\n,
+ * if it is present. Additionally, it replaces each occurence of \r or \r\n
+ * by a single \n.</p>
+ *
+ * @param text A section text.
+ */
+ protected void handleText(char[] text)
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * Handle HTML <title> tag. This method is invoked when
+ * both title starting and closing tags are already behind.
+ * The passed argument contains the concatenation of all
+ * title text sections.
+ * @param title The title text.
+ */
+ protected void handleTitle(char[] title)
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * Constructs the tag from the given element. In this implementation,
+ * this is defined, but never called.
+ * @param element the base element of the tag.
+ * @return the tag
+ */
+ protected TagElement makeTag(Element element)
+ {
+ return makeTag(element, false);
+ }
+
+ /**
+ * Constructs the tag from the given element.
+ * @param element the tag base {@link javax.swing.text.html.parser.Element}
+ * @param isSupposed true if the tag is not actually present in the
+ * html input, but the parser supposes that it should to occur in
+ * the current location.
+ * @return the tag
+ */
+ protected TagElement makeTag(Element element, boolean isSupposed)
+ {
+ return new TagElement(element, isSupposed);
+ }
+
+ /**
+ * This is called when the tag, representing the given element,
+ * occurs first time in the document.
+ * @param element
+ */
+ protected void markFirstTime(Element element)
+ {
+ // This default implementation does nothing.
+ }
+
+ /**
+ * The method is called when the HTML opening tag ((like <table>)
+ * is found or if the parser concludes that the one should be present
+ * in the current position. The method is called immediately before
+ * calling the handleStartTag.
+ * @param tag The tag
+ */
+ protected void startTag(TagElement tag)
+ throws ChangedCharSetException
+ {
+ // This default implementation does nothing.
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/ParserDelegator.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/ParserDelegator.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/ParserDelegator.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/ParserDelegator.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,207 @@
+/* ParserDelegator.java -- Delegator for ParserDocument.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.text.html.parser;
+
+import gnu.javax.swing.text.html.parser.HTML_401F;
+import gnu.javax.swing.text.html.parser.htmlAttributeSet;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Serializable;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.html.HTMLEditorKit;
+import javax.swing.text.html.HTMLEditorKit.ParserCallback;
+
+/**
+ * This class instantiates and starts the working instance of
+ * html parser, being responsible for providing the default DTD.
+ *
+ * @author Audrius Meskauskas (AudriusA at Bioinformatics.org)
+ */
+public class ParserDelegator
+ extends javax.swing.text.html.HTMLEditorKit.Parser
+ implements Serializable
+{
+ private class gnuParser
+ extends gnu.javax.swing.text.html.parser.support.Parser
+ {
+ private static final long serialVersionUID = 1;
+
+ private gnuParser(DTD d)
+ {
+ super(d);
+ }
+
+ protected final void handleComment(char[] comment)
+ {
+ callBack.handleComment(comment, hTag.where.startPosition);
+ }
+
+ protected final void handleEmptyTag(TagElement tag)
+ throws javax.swing.text.ChangedCharSetException
+ {
+ callBack.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
+ hTag.where.startPosition
+ );
+ }
+
+ protected final void handleEndTag(TagElement tag)
+ {
+ callBack.handleEndTag(tag.getHTMLTag(), hTag.where.startPosition);
+ }
+
+ protected final void handleError(int line, String message)
+ {
+ callBack.handleError(message, hTag.where.startPosition);
+ }
+
+ protected final void handleStartTag(TagElement tag)
+ {
+ htmlAttributeSet attributes = gnu.getAttributes();
+
+ if (tag.fictional())
+ attributes.addAttribute(ParserCallback.IMPLIED, Boolean.TRUE);
+
+ callBack.handleStartTag(tag.getHTMLTag(), attributes,
+ hTag.where.startPosition
+ );
+ }
+
+ protected final void handleText(char[] text)
+ {
+ callBack.handleText(text, hTag.where.startPosition);
+ }
+
+ DTD getDTD()
+ {
+ // Accessing the inherited gnu.javax.swing.text.html.parser.support.Parser
+ // field. super. is a workaround, required to support JDK1.3's javac.
+ return super.dtd;
+ }
+ }
+
+ /**
+ * Use serialVersionUID for interoperability.
+ */
+ private static final long serialVersionUID = -1276686502624777206L;
+
+ private static DTD dtd = HTML_401F.getInstance();
+
+ /**
+ * The callback.
+ * This is package-private to avoid an accessor method.
+ */
+ HTMLEditorKit.ParserCallback callBack;
+
+ /**
+ * The reference to the working class of HTML parser that is
+ * actually used to parse the document.
+ * This is package-private to avoid an accessor method.
+ */
+ gnuParser gnu;
+
+ /**
+ * Parses the HTML document, calling methods of the provided
+ * callback. This method must be multithread - safe.
+ * @param reader The reader to read the HTML document from
+ * @param a_callback The callback that is notifyed about the presence
+ * of HTML elements in the document.
+ * @param ignoreCharSet If thrue, any charset changes during parsing
+ * are ignored.
+ * @throws java.io.IOException
+ */
+ public void parse(Reader reader, HTMLEditorKit.ParserCallback a_callback,
+ boolean ignoreCharSet
+ )
+ throws IOException
+ {
+ callBack = a_callback;
+
+ if (gnu == null || !dtd.equals(gnu.getDTD()))
+ {
+ gnu = new gnuParser(dtd);
+ }
+
+ gnu.parse(reader);
+
+ callBack.handleEndOfLineString(gnu.getEndOfLineSequence());
+ try
+ {
+ callBack.flush();
+ }
+ catch (BadLocationException ex)
+ {
+ // Convert this into the supported type of exception.
+ throw new IOException(ex.getMessage());
+ }
+ }
+
+ /**
+ * Calling this method instructs that, if not specified directly,
+ * the documents will be parsed using the default
+ * DTD of the implementation.
+ */
+ protected static void setDefaultDTD()
+ {
+ dtd = HTML_401F.getInstance();
+ }
+
+ /**
+ * Registers the user - written DTD under the given name, also
+ * making it default for the subsequent parsings. This has effect on
+ * all subsequent calls to the parse(...) . If you need to specify
+ * your DTD locally, simply {@link javax.swing.text.html.parser.Parser}
+ * instead.
+ * @param a_dtd The DTD that will be used to parse documents by this class.
+ * @param name The name of this DTD.
+ * @return No standard is specified on which instance of DTD must be
+ * returned by this method, and it is recommended to leave the returned
+ * value without consideration. This implementation returns the DTD
+ * that was previously set as the default DTD, or the implementations
+ * default DTD if none was set.
+ */
+ protected static DTD createDTD(DTD a_dtd, String name)
+ {
+ DTD.putDTDHash(name, a_dtd);
+
+ DTD dtd_prev = dtd;
+ dtd = a_dtd;
+ return dtd_prev;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/TagElement.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/TagElement.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/TagElement.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/TagElement.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,142 @@
+/* TagElement.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.html.parser;
+
+import javax.swing.text.html.HTML;
+
+/**
+ * The SGML element, defining a single html tag.
+ * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
+ */
+public class TagElement
+{
+ /**
+ * The Element the tag was constructed from.
+ */
+ private final Element element;
+
+ /**
+ * The coresponding HTML tag, assigned once in constructor.
+ */
+ private final HTML.Tag tag;
+
+ /**
+ * The 'fictional' flag.
+ */
+ private final boolean fictional;
+
+ /**
+ * Creates the html tag element from the defintion, stored in the
+ * given element. Sets the flag 'fictional' to false.
+ * @param an_element
+ */
+ public TagElement(Element an_element)
+ {
+ this(an_element, false);
+ }
+
+ /**
+ * Creates the html tag element from the defintion, stored in the
+ * given element, setting the flag 'fictional' to the given value.
+ */
+ public TagElement(Element an_element, boolean is_fictional)
+ {
+ element = an_element;
+ fictional = is_fictional;
+
+ HTML.Tag t = HTML.getTag(element.getName());
+
+ if (t != null)
+ tag = t;
+ else
+ tag = new HTML.UnknownTag(element.getName());
+ }
+
+ /**
+ * Get the element from that the tag was constructed.
+ */
+ public Element getElement()
+ {
+ return element;
+ }
+
+ /**
+ * Get the corresponding HTML tag. This is either one of the
+ * pre-defined HTML tags or the instance of the UnknownTag with the
+ * element name.
+ */
+ public HTML.Tag getHTMLTag()
+ {
+ return tag;
+ }
+
+ /**
+ * Calls isPreformatted() for the corresponding html tag and returns
+ * the obtained value.
+ */
+ public boolean isPreformatted()
+ {
+ return tag.isPreformatted();
+ }
+
+ /**
+ * Calls breaksFlow() for the corresponding html tag and returns
+ * the obtained value.
+ */
+ public boolean breaksFlow()
+ {
+ return tag.breaksFlow();
+ }
+
+ /**
+ * Get the value of the flag 'fictional'.
+ */
+ public boolean fictional()
+ {
+ return fictional;
+ }
+
+ /**
+ * Returns string representation of this object.
+ */
+ public String toString()
+ {
+ return getElement() + (fictional ? "?" : "");
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/html/parser/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.swing.text.html package.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - javax.swing.text.html.parser</title></head>
+
+<body>
+<p> Provides the DTD driven for web browsers,
+ web robots, web page content analysers, web editors and
+ other applications applications working with Hypertext
+ Markup Language (HTML).
+</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.swing.text package.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - javax.swing.text</title></head>
+
+<body>
+<p>Provides core text classes and interfaces representing models and views
+used by the text components for display and editing of text.</p>
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/ControlWordToken.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/ControlWordToken.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/ControlWordToken.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/ControlWordToken.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,86 @@
+/* ControlWordToken.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+/**
+ * A special {@link Token} that represents a control word in RTF like
+ * '\deff0' where 'deff' is the name of the control word and '0' is an
+ * optional parameter.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+class ControlWordToken extends Token
+{
+
+ /**
+ * The name of the control word.
+ */
+ public String name;
+
+ /**
+ * The optional parameter of the control word. Absence of a parameter is
+ * expressed through Integer.MIN_VALUE.
+ */
+ public int param;
+
+ /**
+ * Constructs a new ControlWordToken with the specified name and without
+ * a parameter.
+ *
+ * @param name the name of the control word
+ */
+ public ControlWordToken(String name)
+ {
+ this(name, Integer.MIN_VALUE);
+ }
+
+
+ /**
+ * Constructs a new ControlWordToken with the specified name and parameter.
+ *
+ * @param name the name of the control word
+ */
+ public ControlWordToken(String name, int param)
+ {
+ super(Token.CONTROL_WORD);
+ this.name = name;
+ this.param = param;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFEditorKit.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFEditorKit.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFEditorKit.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFEditorKit.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,114 @@
+/* RTFEditorKit.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.StyledEditorKit;
+
+/**
+ * Provides support for RTF data for use in
+ * {@link javax.swing.JEditorPane}s.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+public class RTFEditorKit
+ extends StyledEditorKit
+{
+
+ /**
+ * Constructs a new RTFEditorKit.
+ */
+ public RTFEditorKit()
+ {
+ super();
+ }
+
+ /**
+ * Returns the MIME content type. In the case of RTFEditorKit this is
+ * 'text/rtf'
+ *
+ * @return the MIME content type for RTFEditorKit
+ */
+ public String getContentType()
+ {
+ return "text/rtf";
+ }
+
+ /**
+ * Reads RTF data from <code>stream</code> into <code>doc</code> at the
+ * specified position <code>pos</code>.
+ *
+ * @param stream the {@link InputStream} from where we read RTF data
+ * @param doc the {@link Document} into which we read the RTF data
+ * @param pos the position where to start
+ *
+ * @throws IOException if an IO error occurs
+ * @throws BadLocationException if the position is not valid
+ */
+ public void read(InputStream stream, Document doc, int pos)
+ throws IOException, BadLocationException
+ {
+ RTFParser parser = new RTFParser(stream, doc, pos);
+ parser.parse();
+ }
+
+
+ /**
+ * Reads RTF data from <code>reader</code> into <code>doc</code> at the
+ * specified position <code>pos</code>.
+ *
+ * @param reader the {@link Reader} from where we read RTF data
+ * @param doc the {@link Document} into which we read the RTF data
+ * @param pos the position where to start
+ *
+ * @throws IOException if an IO error occurs
+ * @throws BadLocationException if the position is not valid
+ */
+ public void read(Reader reader, Document doc, int pos)
+ throws IOException, BadLocationException
+ {
+ RTFParser parser = new RTFParser(reader, doc, pos);
+ parser.parse();
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFParseException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFParseException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFParseException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFParseException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,65 @@
+/* RTFParseException.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+/**
+ * Indicates a parsing error during RTF processing.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+class RTFParseException
+ extends RuntimeException
+{
+ /**
+ * Constructs a new RTFParseException without message.
+ */
+ public RTFParseException()
+ {
+ super();
+ }
+
+ /**
+ * Constructs a new RTFParseException with the specified message.
+ */
+ public RTFParseException(String message)
+ {
+ super(message);
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFParser.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFParser.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFParser.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFParser.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,203 @@
+/* RTFParser.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+
+/**
+ * Parses an RTF file into a {@link Document}. The parser utilizes
+ * {@link RTFScanner}.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+class RTFParser
+{
+
+ /**
+ * Our scanner.
+ */
+ private RTFScanner scanner;
+
+ /**
+ * The document into which we parse.
+ */
+ private Document doc;
+
+ /**
+ * The current position.
+ */
+ private int pos;
+
+ /**
+ * Constructs a new RTFParser for the specified document and position,
+ * without initializing the scanner. This is only used internally.
+ *
+ * @param doc the {@link Document} into which we should parse
+ * @param pos the position to start
+ */
+ private RTFParser(Document doc, int pos)
+ {
+ this.doc = doc;
+ this.pos = pos;
+ }
+
+ /**
+ * Constructs a new RTFParser for the specified <code>stream</code>.
+ *
+ * @param stream the stream from which we parse
+ * @param doc the {@link Document} into which we should parse
+ * @param pos the position to start
+ */
+ public RTFParser(InputStream stream, Document doc, int pos)
+ {
+ this(doc, pos);
+ scanner = new RTFScanner(stream);
+ }
+
+ /**
+ * Constructs a new RTFParser for the specified <code>reader</code>.
+ *
+ * @param reader the reader from which we parse
+ * @param doc the {@link Document} into which we should parse
+ * @param pos the position to start
+ */
+ public RTFParser(Reader reader, Document doc, int pos)
+ {
+ this(doc, pos);
+ scanner = new RTFScanner(reader);
+ }
+
+ /**
+ * Returns the {@link Document} in which we parsed the RTF data.
+ *
+ * @return the {@link Document} in which we parsed the RTF data
+ */
+ public Document getDocument()
+ {
+ return doc;
+ }
+
+ /**
+ * Starts the parsing process.
+ */
+ public void parse()
+ throws IOException, BadLocationException
+ {
+ parseFile();
+ }
+
+ /**
+ * The parse rules for <file>.
+ */
+ private void parseFile()
+ throws IOException, BadLocationException
+ {
+ Token t1 = scanner.readToken();
+ if (t1.type != Token.LCURLY)
+ throw new RTFParseException("expected left curly braces");
+
+ parseHeader();
+ parseDocument();
+
+ Token t2 = scanner.peekToken();
+ if (t2.type == Token.RCURLY)
+ {
+ // Eat the token.
+ scanner.readToken();
+ }
+ else
+ {
+ // Ignore this for maximum robustness when file is broken.
+ System.err.println("RTF warning: expected right curly braces");
+ }
+
+ }
+
+ /**
+ * The parse rules for <header>.
+ *
+ * TODO: implement this properly
+ */
+ private void parseHeader()
+ //throws IOException, BadLocationException
+ {
+ // TODO add parse rules here
+ }
+
+
+ /**
+ * The parse rules for <document>.
+ *
+ * TODO: implement this properly
+ */
+ private void parseDocument()
+ throws IOException, BadLocationException
+ {
+ // !!! TODO !!!
+ // This simply emits every TEXT Token as text to the document
+ // which is plain stupid
+
+ boolean eof = false;
+
+ do {
+ Token token = scanner.readToken();
+ switch (token.type)
+ {
+ case Token.TEXT:
+ TextToken textToken = (TextToken) token;
+ doc.insertString(pos, textToken.text, null);
+ pos += textToken.text.length();
+ break;
+ case Token.EOF:
+ eof = true;
+ break;
+ default:
+ // FIXME
+ break;
+ }
+ } while (!eof);
+
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFScanner.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFScanner.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFScanner.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/RTFScanner.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,294 @@
+/* RTFScanner.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+/**
+ * Provides a scanner that scans an {@link InputStream} for tokens of the
+ * RTF syntax.
+ *
+ * This scanner is based upon the RTF specification 1.6
+ * available at:
+ *
+ * <a
+ * href="http://msdn.microsoft.com/library/en-us/dnrtfspec/html/rtfspec.asp">
+ * RTF specification at MSDN</a>
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+class RTFScanner
+{
+
+ /**
+ * The reader from which we read the RTF data.
+ */
+ private Reader in;
+
+ /**
+ * This is used to constuct strings from the read in chars.
+ */
+ private StringBuffer buffer;
+
+ /**
+ * Lookahead token.
+ */
+ private Token lastToken;
+
+ /**
+ * Constructs a new RTFScanner without initializing the {@link Reader}.
+ */
+ private RTFScanner()
+ {
+ buffer = new StringBuffer();
+ }
+
+ /**
+ * Constructs a new RTFScanner for the given {@link InputStream}.
+ * The stream is wrapped into an {@link InputStreamReader} and if it's
+ * not yet buffered then the Reader is wrapped in a {@link BufferedReader}
+ *
+ * @param stream the {@link InputStream} to read RTF data from
+ */
+ public RTFScanner(InputStream stream)
+ {
+ this();
+ InputStreamReader reader = new InputStreamReader(stream);
+ in = new BufferedReader(reader);
+ }
+
+ /**
+ * Constructs a new RTFScanner for the given {@link Reader}.
+ *
+ * If the reader is not an instance of {@link BufferedReader} then it
+ * is wrapped into a BufferedReader.
+ *
+ * @param reader the {@link BufferedReader} to read RTF data from
+ */
+ public RTFScanner(Reader reader)
+ {
+ this();
+ if (reader instanceof BufferedReader)
+ {
+ in = reader;
+ }
+ else
+ {
+ in = new BufferedReader(reader);
+ }
+ }
+
+ /**
+ * Reads in the next {@link Token} from the stream.
+ *
+ * @return the read {@link Token}
+ *
+ * @throws IOException if the underlying stream has problems
+ */
+ private Token readTokenImpl()
+ throws IOException
+ {
+ Token token = null;
+
+ int c = in.read();
+ switch(c)
+ {
+ case -1:
+ token = new Token(Token.EOF);
+ break;
+
+ case '{':
+ token = new Token(Token.LCURLY);
+ break;
+
+ case '}':
+ token = new Token(Token.RCURLY);
+ break;
+
+ case '\\':
+ buffer.delete(0, buffer.length());
+ buffer.append((char) c);
+ token = readControlWord();
+ break;
+
+ default:
+ buffer.delete(0, buffer.length());
+ buffer.append((char) c);
+ token = readText();
+ break;
+ }
+
+ return token;
+ }
+
+ Token peekToken()
+ throws IOException
+ {
+ lastToken = readTokenImpl();
+ return lastToken;
+ }
+
+ Token readToken()
+ throws IOException
+ {
+ Token token;
+ if (lastToken != null)
+ {
+ token = lastToken;
+ lastToken = null;
+ }
+ else
+ token = readTokenImpl();
+ return token;
+ }
+
+ /**
+ * Reads in a control word and optional parameter.
+ *
+ * @return the read in control word as {@link ControlWordToken}
+ *
+ * @throws IOException if the underlying stream has problems
+ */
+ private Token readControlWord()
+ throws IOException
+ {
+ // this flag indicates if we are still reading the name or are already
+ // in the parameter
+ boolean readingName = true;
+ String name = null;
+ String param = null;
+
+ while (true)
+ {
+ in.mark(1);
+ int c = in.read();
+
+ // check for 'a'..'z'
+ if (readingName && (c >= 'a') && (c <= 'z'))
+ {
+ buffer.append((char) c);
+ }
+ else if ((c >= '0') && (c <= '9'))
+ {
+ // if the last char was in the name, then finish reading the name
+ if (readingName)
+ {
+ name = buffer.toString();
+ buffer.delete(0, buffer.length());
+ readingName = false;
+ }
+ buffer.append((char) c);
+ }
+ else
+ {
+ // if we were in the name, then finish this
+ if (readingName)
+ {
+ name = buffer.toString();
+ }
+ // otherwise finish the parameter
+ else
+ {
+ param = buffer.toString();
+ }
+
+ // clear up
+ buffer.delete(0, buffer.length());
+ // reset input buffer to last char
+ in.reset();
+ // break while loop
+ break;
+ }
+ }
+
+ ControlWordToken token = null;
+
+ if (param == null)
+ token = new ControlWordToken(name);
+ else
+ token =new ControlWordToken(name, Integer.parseInt(param));
+
+ return token;
+
+ }
+
+ /**
+ * Reads in a block of text.
+ *
+ * @return the token for the text
+ */
+ private Token readText()
+ throws IOException
+ {
+
+ boolean readingText = true;
+ while (readingText)
+ {
+ in.mark(1);
+ int c = in.read();
+ switch(c)
+ {
+ case '\\':
+ case '{':
+ case '}':
+ case -1:
+ readingText = false;
+ in.reset();
+ break;
+
+ default:
+ buffer.append((char) c);
+ break;
+ }
+
+ }
+
+ String text = buffer.toString();
+ Token token = new TextToken(text);
+
+ buffer.delete(0, buffer.length());
+
+ return token;
+
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/TextToken.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/TextToken.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/TextToken.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/TextToken.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,65 @@
+/* TextToken.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+/**
+ * A special {@link Token} that represents a piece of text in RTF.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+class TextToken extends Token
+{
+
+ /**
+ * The text.
+ */
+ public String text;
+
+ /**
+ * Constructs a new TextToken with the specified textual data.
+ *
+ * @param text the text for this token
+ */
+ public TextToken(String text)
+ {
+ super(Token.TEXT);
+ this.text = text;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/Token.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/Token.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/Token.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/Token.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,91 @@
+/* Token.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.text.rtf;
+
+/**
+ * Represents a simple token that the RTFScanner can read. A simple
+ * only has a type (like LCURLY or RCURLY). More complex tokens may
+ * attach data to the token.
+ *
+ * @author Roman Kennke (roman at ontographics.com)
+ */
+class Token
+{
+
+ /**
+ * This special type inidicates the end of the input stream.
+ */
+ public static final int EOF = -1;
+
+ /**
+ * A left curly brace '{'.
+ */
+ public static final int LCURLY = 1;
+
+ /**
+ * A right curly brace '}'.
+ */
+ public static final int RCURLY = 2;
+
+ /**
+ * A control word like '\rtf1'. Tokens with this type are represented
+ * through the subclass {@link ControlWordToken}.
+ */
+ public static final int CONTROL_WORD = 3;
+
+ /**
+ * A token that contains text. This is represented through the subclass
+ * {@link TextToken}.
+ */
+ public static final int TEXT = 4;
+
+
+ /** The token type. */
+ public int type;
+
+ /**
+ * Constructs a new Token with the specified type.
+ *
+ * @param type the Token type
+ */
+ public Token(int type)
+ {
+ this.type = type;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/text/rtf/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.swing.text.rtf package.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - javax.swing.text.rtf</title></head>
+
+<body>
+<p>Provides support for Rich Text Format (RTF) data to be used with the
+{@link JEditorPane} component.
+</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/AbstractLayoutCache.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/AbstractLayoutCache.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/AbstractLayoutCache.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/AbstractLayoutCache.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,445 @@
+/* AbstractLayoutCache.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.tree;
+
+import java.awt.Rectangle;
+import java.util.Enumeration;
+
+import javax.swing.event.TreeModelEvent;
+
+/**
+ * class AbstractLayoutCache
+ *
+ * @author Andrew Selkirk
+ */
+public abstract class AbstractLayoutCache
+ implements RowMapper
+{
+ /**
+ * class NodeDimensions
+ */
+ public abstract static class NodeDimensions
+ {
+ /**
+ * Creates <code>NodeDimensions</code> object.
+ */
+ public NodeDimensions()
+ {
+ // Do nothing here.
+ }
+
+ /**
+ * Get the node dimensions. The NodeDimensions property must be set (unless
+ * the method is overridden, like if {@link FixedHeightLayoutCache}. If the
+ * method is not overridden and the property is not set, the InternalError is
+ * thrown.
+ *
+ * @param value the last node in the path
+ * @param row the node row
+ * @param depth the indentation depth
+ * @param expanded true if this node is expanded, false otherwise
+ * @param bounds the area where the tree is displayed
+ */
+ public abstract Rectangle getNodeDimensions(Object value, int row,
+ int depth, boolean expanded,
+ Rectangle bounds);
+ }
+
+ /**
+ * nodeDimensions
+ */
+ protected NodeDimensions nodeDimensions;
+
+ /**
+ * treeModel
+ */
+ protected TreeModel treeModel;
+
+ /**
+ * treeSelectionModel
+ */
+ protected TreeSelectionModel treeSelectionModel;
+
+ /**
+ * rootVisible
+ */
+ protected boolean rootVisible;
+
+ /**
+ * rowHeight
+ */
+ protected int rowHeight;
+
+ /**
+ * Constructor AbstractLayoutCache
+ */
+ public AbstractLayoutCache()
+ {
+ // Do nothing here.
+ }
+
+ /**
+ * setNodeDimensions
+ *
+ * @param dimensions TODO
+ */
+ public void setNodeDimensions(NodeDimensions dimensions)
+ {
+ nodeDimensions = dimensions;
+ }
+
+ /**
+ * getNodeDimensions
+ *
+ * @return NodeDimensions
+ */
+ public NodeDimensions getNodeDimensions()
+ {
+ return nodeDimensions;
+ }
+
+ /**
+ * Get the node dimensions. The NodeDimensions property must be set
+ * (unless the method is overridden, like if
+ * {@link FixedHeightLayoutCache}. If the method is not overridden and
+ * the property is not set, the InternalError is thrown.
+ *
+ * @param value the last node in the path
+ * @param row the node row
+ * @param depth the indentation depth
+ * @param expanded true if this node is expanded, false otherwise
+ * @param bounds the area where the tree is displayed
+ */
+ protected Rectangle getNodeDimensions(Object value, int row, int depth,
+ boolean expanded, Rectangle bounds)
+ {
+ if (nodeDimensions == null)
+ throw new InternalError("The NodeDimensions are not set");
+ return nodeDimensions.getNodeDimensions(value, row, depth, expanded, bounds);
+ }
+
+ /**
+ * Sets the model that provides the tree data.
+ *
+ * @param model the model
+ */
+ public void setModel(TreeModel model)
+ {
+ treeModel = model;
+ }
+
+ /**
+ * Returns the model that provides the tree data.
+ *
+ * @return the model
+ */
+ public TreeModel getModel()
+ {
+ return treeModel;
+ }
+
+ /**
+ * setRootVisible
+ *
+ * @param visible <code>true</code> if root should be visible,
+ * <code>false</code> otherwise
+ */
+ public void setRootVisible(boolean visible)
+ {
+ rootVisible = visible;
+ }
+
+ /**
+ * isRootVisible
+ *
+ * @return <code>true</code> if root is visible,
+ * <code>false</code> otherwise
+ */
+ public boolean isRootVisible()
+ {
+ return rootVisible;
+ }
+
+ /**
+ * setRowHeight
+ *
+ * @param height the row height
+ */
+ public void setRowHeight(int height)
+ {
+ rowHeight = height;
+ invalidateSizes();
+ }
+
+ /**
+ * getRowHeight
+ *
+ * @return the row height
+ */
+ public int getRowHeight()
+ {
+ return rowHeight;
+ }
+
+ /**
+ * setSelectionModel
+ *
+ * @param model the model
+ */
+ public void setSelectionModel(TreeSelectionModel model)
+ {
+ treeSelectionModel = model;
+ }
+
+ /**
+ * getSelectionModel
+ *
+ * @return the model
+ */
+ public TreeSelectionModel getSelectionModel()
+ {
+ return treeSelectionModel;
+ }
+
+ /**
+ * Get the sum of heights for all rows. This class provides a general not
+ * optimized implementation that is overridded in derived classes
+ * ({@link VariableHeightLayoutCache}, {@link FixedHeightLayoutCache}) for
+ * the better performance.
+ */
+ public int getPreferredHeight()
+ {
+ int height = 0;
+ int n = getRowCount();
+ Rectangle r = new Rectangle();
+ for (int i = 0; i < n; i++)
+ {
+ TreePath path = getPathForRow(i);
+ height += getBounds(path, r).height;
+ }
+ return height;
+ }
+
+ /**
+ * Get the maximal width. This class provides a general not
+ * optimized implementation that is overridded in derived classes
+ * ({@link VariableHeightLayoutCache}, {@link FixedHeightLayoutCache}) for
+ * the better performance.
+ *
+ * @param rect the rectangle that is used during the method work
+ */
+ public int getPreferredWidth(Rectangle rect)
+ {
+ int maximalWidth = 0;
+ Rectangle r = new Rectangle();
+ int n = getRowCount();
+ for (int i = 0; i < n; i++)
+ {
+ TreePath path = getPathForRow(i);
+ r.setBounds(0, 0, 0, 0);
+ r = getBounds(path, r);
+ if (r.x + r.width > maximalWidth)
+ maximalWidth = r.x + r.width;
+ // Invalidate the cached value as this may be the very early call
+ // before the heigth is properly set (the vertical coordinate may
+ // not be correct).
+ invalidatePathBounds(path);
+ }
+ return maximalWidth;
+ }
+ /**
+ * isExpanded
+ *
+ * @param value0 TODO
+ *
+ * @return boolean
+ */
+ public abstract boolean isExpanded(TreePath value0);
+
+ /**
+ * getBounds
+ *
+ * @param value0 TODO
+ * @param value1 TODO
+ *
+ * @return Rectangle
+ */
+ public abstract Rectangle getBounds(TreePath value0, Rectangle value1);
+
+ /**
+ * getPathForRow
+ *
+ * @param row the row
+ *
+ * @return the tree path
+ */
+ public abstract TreePath getPathForRow(int row);
+
+ /**
+ * getRowForPath
+ *
+ * @param path the tree path
+ *
+ * @return the row
+ */
+ public abstract int getRowForPath(TreePath path);
+
+ /**
+ * getPathClosestTo
+ *
+ * @param value0 TODO
+ * @param value1 TODO
+ *
+ * @return the tree path
+ */
+ public abstract TreePath getPathClosestTo(int value0, int value1);
+
+ /**
+ * getVisiblePathsFrom
+ *
+ * @param path the tree path
+ *
+ * @return Enumeration
+ */
+ public abstract Enumeration getVisiblePathsFrom(TreePath path);
+
+ /**
+ * getVisibleChildCount
+ *
+ * @param path the tree path
+ *
+ * @return int
+ */
+ public abstract int getVisibleChildCount(TreePath path);
+
+ /**
+ * setExpandedState
+ *
+ * @param value0 TODO
+ *
+ * @param value1 TODO
+ */
+ public abstract void setExpandedState(TreePath value0, boolean value1);
+
+ /**
+ * getExpandedState
+ *
+ * @param path the tree path
+ *
+ * @return boolean
+ */
+ public abstract boolean getExpandedState(TreePath path);
+
+ /**
+ * getRowCount
+ *
+ * @return the number of rows
+ */
+ public abstract int getRowCount();
+
+ /**
+ * invalidateSizes
+ */
+ public abstract void invalidateSizes();
+
+ /**
+ * invalidatePathBounds
+ *
+ * @param path the tree path
+ */
+ public abstract void invalidatePathBounds(TreePath path);
+
+ /**
+ * treeNodesChanged
+ *
+ * @param event the event to send
+ */
+ public abstract void treeNodesChanged(TreeModelEvent event);
+
+ /**
+ * treeNodesInserted
+ *
+ * @param event the event to send
+ */
+ public abstract void treeNodesInserted(TreeModelEvent event);
+
+ /**
+ * treeNodesRemoved
+ *
+ * @param event the event to send
+ */
+ public abstract void treeNodesRemoved(TreeModelEvent event);
+
+ /**
+ * treeStructureChanged
+ *
+ * @param event the event to send
+ */
+ public abstract void treeStructureChanged(TreeModelEvent event);
+
+ /**
+ * Get the tree row numbers for the given pathes. This method performs
+ * the "bulk" conversion that may be faster than mapping pathes one by
+ * one. To have the benefit from the bulk conversion, the method must be
+ * overridden in the derived classes. The default method delegates work
+ * to the {@link #getRowForPath(TreePath)}.
+ *
+ * @param paths the tree paths the array of the tree pathes.
+ * @return the array of the matching tree rows.
+ */
+ public int[] getRowsForPaths(TreePath[] paths)
+ {
+ int[] rows = new int[paths.length];
+ for (int i = 0; i < rows.length; i++)
+ rows[i] = getRowForPath(paths[i]);
+ return rows;
+ }
+
+ /**
+ * Returns true if this layout supposes that all rows have the fixed
+ * height.
+ *
+ * @return boolean true if all rows in the tree must have the fixed
+ * height (false by default).
+ */
+ protected boolean isFixedRowHeight()
+ {
+ return false;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultMutableTreeNode.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultMutableTreeNode.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultMutableTreeNode.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultMutableTreeNode.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1202 @@
+/* DefaultMutableTreeNode.java --
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.tree;
+
+import gnu.java.util.EmptyEnumeration;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.NoSuchElementException;
+import java.util.Stack;
+import java.util.Vector;
+
+
+/**
+ * A default implementation of the {@link MutableTreeNode} interface.
+ *
+ * @author Andrew Selkirk
+ * @author Robert Schuster (robertschuster at fsfe.org)
+ */
+public class DefaultMutableTreeNode
+ implements Cloneable, MutableTreeNode, Serializable
+{
+ private static final long serialVersionUID = -4298474751201349152L;
+
+ /**
+ * An empty enumeration, returned by {@link #children()} if a node has no
+ * children.
+ */
+ public static final Enumeration EMPTY_ENUMERATION =
+ EmptyEnumeration.getInstance();
+
+ /**
+ * The parent of this node (possibly <code>null</code>).
+ */
+ protected MutableTreeNode parent;
+
+ /**
+ * The child nodes for this node (may be empty).
+ */
+ protected Vector children = new Vector();
+
+ /**
+ * userObject
+ */
+ protected transient Object userObject;
+
+ /**
+ * allowsChildren
+ */
+ protected boolean allowsChildren;
+
+ /**
+ * Creates a <code>DefaultMutableTreeNode</code> object.
+ * This is equivalent to <code>DefaultMutableTreeNode(null, true)</code>.
+ */
+ public DefaultMutableTreeNode()
+ {
+ this(null, true);
+ }
+
+ /**
+ * Creates a <code>DefaultMutableTreeNode</code> object with the given
+ * user object attached to it. This is equivalent to
+ * <code>DefaultMutableTreeNode(userObject, true)</code>.
+ *
+ * @param userObject the user object (<code>null</code> permitted).
+ */
+ public DefaultMutableTreeNode(Object userObject)
+ {
+ this(userObject, true);
+ }
+
+ /**
+ * Creates a <code>DefaultMutableTreeNode</code> object with the given
+ * user object attached to it.
+ *
+ * @param userObject the user object (<code>null</code> permitted).
+ * @param allowsChildren <code>true</code> if the code allows to add child
+ * nodes, <code>false</code> otherwise
+ */
+ public DefaultMutableTreeNode(Object userObject, boolean allowsChildren)
+ {
+ this.userObject = userObject;
+ this.allowsChildren = allowsChildren;
+ }
+
+ /**
+ * Returns a clone of the node. The clone contains a shallow copy of the
+ * user object, and does not copy the parent node or the child nodes.
+ *
+ * @return A clone of the node.
+ */
+ public Object clone()
+ {
+ return new DefaultMutableTreeNode(this.userObject, this.allowsChildren);
+ }
+
+ /**
+ * Returns a string representation of the node. This implementation returns
+ * <code>getUserObject().toString()</code>, or <code>null</code> if there
+ * is no user object.
+ *
+ * @return A string representation of the node (possibly <code>null</code>).
+ */
+ public String toString()
+ {
+ if (userObject == null)
+ return null;
+
+ return userObject.toString();
+ }
+
+ /**
+ * Adds a new child node to this node and sets this node as the parent of
+ * the child node. The child node must not be an ancestor of this node.
+ * If the tree uses the {@link DefaultTreeModel}, you must subsequently
+ * call {@link DefaultTreeModel#reload(TreeNode)}.
+ *
+ * @param child the child node (<code>null</code> not permitted).
+ *
+ * @throws IllegalStateException if {@link #getAllowsChildren()} returns
+ * <code>false</code>.
+ * @throws IllegalArgumentException if {@link #isNodeAncestor} returns
+ * <code>true</code>.
+ * @throws IllegalArgumentException if <code>child</code> is
+ * <code>null</code>.
+ */
+ public void add(MutableTreeNode child)
+ {
+ if (! allowsChildren)
+ throw new IllegalStateException();
+
+ if (child == null)
+ throw new IllegalArgumentException();
+
+ if (isNodeAncestor(child))
+ throw new IllegalArgumentException("Cannot add ancestor node.");
+
+ children.add(child);
+ child.setParent(this);
+ }
+
+ /**
+ * Returns the parent node of this node.
+ *
+ * @return The parent node (possibly <code>null</code>).
+ */
+ public TreeNode getParent()
+ {
+ return parent;
+ }
+
+ /**
+ * Removes the child with the given index from this node.
+ *
+ * @param index the index (in the range <code>0</code> to
+ * <code>getChildCount() - 1</code>).
+ *
+ * @throws ArrayIndexOutOfBoundsException if <code>index</code> is outside
+ * the valid range.
+ */
+ public void remove(int index)
+ {
+ MutableTreeNode child = (MutableTreeNode) children.remove(index);
+ child.setParent(null);
+ }
+
+ /**
+ * Removes the given child from this node and sets its parent to
+ * <code>null</code>.
+ *
+ * @param node the child node (<code>null</code> not permitted).
+ *
+ * @throws IllegalArgumentException if <code>node</code> is not a child of
+ * this node.
+ * @throws IllegalArgumentException if <code>node</code> is null.
+ */
+ public void remove(MutableTreeNode node)
+ {
+ if (node == null)
+ throw new IllegalArgumentException("Null 'node' argument.");
+ if (node.getParent() != this)
+ throw new IllegalArgumentException(
+ "The given 'node' is not a child of this node.");
+ children.remove(node);
+ node.setParent(null);
+ }
+
+ /**
+ * writeObject
+ *
+ * @param stream the output stream
+ *
+ * @exception IOException If an error occurs
+ */
+ private void writeObject(ObjectOutputStream stream)
+ throws IOException
+ {
+ // TODO: Implement me.
+ }
+
+ /**
+ * readObject
+ *
+ * @param stream the input stream
+ *
+ * @exception IOException If an error occurs
+ * @exception ClassNotFoundException TODO
+ */
+ private void readObject(ObjectInputStream stream)
+ throws IOException, ClassNotFoundException
+ {
+ // TODO: Implement me.
+ }
+
+ /**
+ * Inserts given child node at the given index.
+ *
+ * @param node the child node (<code>null</code> not permitted).
+ * @param index the index.
+ *
+ * @throws IllegalArgumentException if <code>node</code> is
+ * </code>null</code>.
+ */
+ public void insert(MutableTreeNode node, int index)
+ {
+ if (! allowsChildren)
+ throw new IllegalStateException();
+
+ if (node == null)
+ throw new IllegalArgumentException("Null 'node' argument.");
+
+ if (isNodeAncestor(node))
+ throw new IllegalArgumentException("Cannot insert ancestor node.");
+
+ children.insertElementAt(node, index);
+ }
+
+ /**
+ * Returns a path to this node from the root.
+ *
+ * @return an array of tree nodes
+ */
+ public TreeNode[] getPath()
+ {
+ return getPathToRoot(this, 0);
+ }
+
+ /**
+ * Returns an enumeration containing all children of this node.
+ * <code>EMPTY_ENUMERATION</code> is returned if this node has no children.
+ *
+ * @return an enumeration of tree nodes
+ */
+ public Enumeration children()
+ {
+ if (children.size() == 0)
+ return EMPTY_ENUMERATION;
+
+ return children.elements();
+ }
+
+ /**
+ * Set the parent node for this node.
+ *
+ * @param node the parent node
+ */
+ public void setParent(MutableTreeNode node)
+ {
+ parent = node;
+ }
+
+ /**
+ * Returns the child node at a given index.
+ *
+ * @param index the index
+ *
+ * @return the child node
+ */
+ public TreeNode getChildAt(int index)
+ {
+ return (TreeNode) children.elementAt(index);
+ }
+
+ /**
+ * Returns the number of children of this node.
+ *
+ * @return the number of children
+ */
+ public int getChildCount()
+ {
+ return children.size();
+ }
+
+ /**
+ * Returns the index of the specified child node, or -1 if the node is not
+ * in fact a child of this node.
+ *
+ * @param node the node (<code>null</code> not permitted).
+ *
+ * @return The index of the specified child node, or -1.
+ *
+ * @throws IllegalArgumentException if <code>node</code> is <code>null</code>.
+ */
+ public int getIndex(TreeNode node)
+ {
+ if (node == null)
+ throw new IllegalArgumentException("Null 'node' argument.");
+ return children.indexOf(node);
+ }
+
+ /**
+ * Sets the flag that controls whether or not this node allows the addition /
+ * insertion of child nodes. If the flag is set to <code>false</code>, any
+ * existing children are removed.
+ *
+ * @param allowsChildren the flag.
+ */
+ public void setAllowsChildren(boolean allowsChildren)
+ {
+ if (!allowsChildren)
+ removeAllChildren();
+ this.allowsChildren = allowsChildren;
+ }
+
+ /**
+ * getAllowsChildren
+ *
+ * @return boolean
+ */
+ public boolean getAllowsChildren()
+ {
+ return allowsChildren;
+ }
+
+ /**
+ * Sets the user object for this node
+ *
+ * @param userObject the user object
+ */
+ public void setUserObject(Object userObject)
+ {
+ this.userObject = userObject;
+ }
+
+ /**
+ * Returns the user object attached to this node. <code>null</code> is
+ * returned when no user object is set.
+ *
+ * @return the user object
+ */
+ public Object getUserObject()
+ {
+ return userObject;
+ }
+
+ /**
+ * Removes this node from its parent.
+ */
+ public void removeFromParent()
+ {
+ parent.remove(this);
+ parent = null;
+ }
+
+ /**
+ * Removes all child nodes from this node.
+ */
+ public void removeAllChildren()
+ {
+ for (int i = getChildCount() - 1; i >= 0; i--)
+ remove(i);
+ }
+
+ /**
+ * Returns <code>true</code> if <code>node</code> is an ancestor of this
+ * tree node, and <code>false</code> otherwise. An ancestor node is any of:
+ * <ul>
+ * <li>this tree node;</li>
+ * <li>the parent node (if there is one);</li>
+ * <li>any ancestor of the parent node;</li>
+ * </ul>
+ * If <code>node</code> is <code>null</code>, this method returns
+ * <code>false</code>.
+ *
+ * @param node the node (<code>null</code> permitted).
+ *
+ * @return A boolean.
+ */
+ public boolean isNodeAncestor(TreeNode node)
+ {
+ if (node == null)
+ return false;
+
+ TreeNode current = this;
+
+ while (current != null && current != node)
+ current = current.getParent();
+
+ return current == node;
+ }
+
+ /**
+ * Returns <code>true</code> if <code>node</code> is a descendant of this
+ * tree node, and <code>false</code> otherwise. A descendant node is any of:
+ * <ul>
+ * <li>this tree node;</li>
+ * <li>the child nodes belonging to this tree node, if there are any;</li>
+ * <li>any descendants of the child nodes;</li>
+ * </ul>
+ * If <code>node</code> is <code>null</code>, this method returns
+ * <code>false</code>.
+ *
+ * @param node the node (<code>null</code> permitted).
+ *
+ * @return A boolean.
+ */
+ public boolean isNodeDescendant(DefaultMutableTreeNode node)
+ {
+ if (node == null)
+ return false;
+
+ TreeNode current = node;
+
+ while (current != null
+ && current != this)
+ current = current.getParent();
+
+ return current == this;
+ }
+
+ /**
+ * getSharedAncestor
+ *
+ * @param node TODO
+ *
+ * @return TreeNode
+ */
+ public TreeNode getSharedAncestor(DefaultMutableTreeNode node)
+ {
+ TreeNode current = this;
+ ArrayList list = new ArrayList();
+
+ while (current != null)
+ {
+ list.add(current);
+ current = current.getParent();
+ }
+
+ current = node;
+
+ while (current != null)
+ {
+ if (list.contains(current))
+ return current;
+
+ current = current.getParent();
+ }
+
+ return null;
+ }
+
+ /**
+ * isNodeRelated
+ *
+ * @param node TODO
+ *
+ * @return boolean
+ */
+ public boolean isNodeRelated(DefaultMutableTreeNode node)
+ {
+ if (node == null)
+ return false;
+
+ return node.getRoot() == getRoot();
+ }
+
+ /**
+ * getDepth
+ *
+ * @return int
+ */
+ public int getDepth()
+ {
+ if ((! allowsChildren)
+ || children.size() == 0)
+ return 0;
+
+ Stack stack = new Stack();
+ stack.push(new Integer(0));
+ TreeNode node = getChildAt(0);
+ int depth = 0;
+ int current = 1;
+
+ while (! stack.empty())
+ {
+ if (node.getChildCount() != 0)
+ {
+ node = node.getChildAt(0);
+ stack.push(new Integer(0));
+ current++;
+ }
+ else
+ {
+ if (current > depth)
+ depth = current;
+
+ int size;
+ int index;
+
+ do
+ {
+ node = node.getParent();
+ size = node.getChildCount();
+ index = ((Integer) stack.pop()).intValue() + 1;
+ current--;
+ }
+ while (index >= size
+ && node != this);
+
+ if (index < size)
+ {
+ node = node.getChildAt(index);
+ stack.push(new Integer(index));
+ current++;
+ }
+ }
+ }
+
+ return depth;
+ }
+
+ /**
+ * getLevel
+ *
+ * @return int
+ */
+ public int getLevel()
+ {
+ int count = -1;
+ TreeNode current = this;
+
+ do
+ {
+ current = current.getParent();
+ count++;
+ }
+ while (current != null);
+
+ return count;
+ }
+
+ /**
+ * getPathToRoot
+ *
+ * @param node TODO
+ * @param depth TODO
+ *
+ * @return TreeNode[]
+ */
+ protected TreeNode[] getPathToRoot(TreeNode node, int depth)
+ {
+ if (node == null)
+ {
+ if (depth == 0)
+ return null;
+
+ return new TreeNode[depth];
+ }
+
+ TreeNode[] path = getPathToRoot(node.getParent(), depth + 1);
+ path[path.length - depth - 1] = node;
+ return path;
+ }
+
+ /**
+ * getUserObjectPath
+ *
+ * @return Object[]
+ */
+ public Object[] getUserObjectPath()
+ {
+ TreeNode[] path = getPathToRoot(this, 0);
+ Object[] object = new Object[path.length];
+
+ for (int index = 0; index < path.length; ++index)
+ object[index] = ((DefaultMutableTreeNode) path[index]).getUserObject();
+
+ return object;
+ }
+
+ /**
+ * Returns the root node by iterating the parents of this node.
+ *
+ * @return the root node
+ */
+ public TreeNode getRoot()
+ {
+ TreeNode current = this;
+ TreeNode check = current.getParent();
+
+ while (check != null)
+ {
+ current = check;
+ check = current.getParent();
+ }
+
+ return current;
+ }
+
+ /**
+ * Tells whether this node is the root node or not.
+ *
+ * @return <code>true</code> if this is the root node,
+ * <code>false</code>otherwise
+ */
+ public boolean isRoot()
+ {
+ return parent == null;
+ }
+
+ /**
+ * getNextNode
+ *
+ * @return DefaultMutableTreeNode
+ */
+ public DefaultMutableTreeNode getNextNode()
+ {
+ // Return first child.
+ if (getChildCount() != 0)
+ return (DefaultMutableTreeNode) getChildAt(0);
+
+ // Return next sibling (if needed the sibling of some parent).
+ DefaultMutableTreeNode node = this;
+ DefaultMutableTreeNode sibling;
+
+ do
+ {
+ sibling = node.getNextSibling();
+ node = (DefaultMutableTreeNode) node.getParent();
+ }
+ while (sibling == null &&
+ node != null);
+
+ // Return sibling.
+ return sibling;
+ }
+
+ /**
+ * getPreviousNode
+ *
+ * @return DefaultMutableTreeNode
+ */
+ public DefaultMutableTreeNode getPreviousNode()
+ {
+ // Return null if no parent.
+ if (parent == null)
+ return null;
+
+ DefaultMutableTreeNode sibling = getPreviousSibling();
+
+ // Return parent if no sibling.
+ if (sibling == null)
+ return (DefaultMutableTreeNode) parent;
+
+ // Return last leaf of sibling.
+ if (sibling.getChildCount() != 0)
+ return sibling.getLastLeaf();
+
+ // Return sibling.
+ return sibling;
+ }
+
+ /**
+ * preorderEnumeration
+ *
+ * @return Enumeration
+ */
+ public Enumeration preorderEnumeration()
+ {
+ return new PreorderEnumeration(this);
+ }
+
+ /**
+ * postorderEnumeration
+ *
+ * @return Enumeration
+ */
+ public Enumeration postorderEnumeration()
+ {
+ return new PostorderEnumeration(this);
+ }
+
+ /**
+ * breadthFirstEnumeration
+ *
+ * @return Enumeration
+ */
+ public Enumeration breadthFirstEnumeration()
+ {
+ return new BreadthFirstEnumeration(this);
+ }
+
+ /**
+ * depthFirstEnumeration
+ *
+ * @return Enumeration
+ */
+ public Enumeration depthFirstEnumeration()
+ {
+ return postorderEnumeration();
+ }
+
+ /**
+ * pathFromAncestorEnumeration
+ *
+ * @param node TODO
+ *
+ * @return Enumeration
+ */
+ public Enumeration pathFromAncestorEnumeration(TreeNode node)
+ {
+ if (node == null)
+ throw new IllegalArgumentException();
+
+ TreeNode parent = this;
+ Vector nodes = new Vector();
+ nodes.add(this);
+
+ while (parent != node && parent != null)
+ {
+ parent = parent.getParent();
+ nodes.add(0, parent);
+ }
+
+ if (parent != node)
+ throw new IllegalArgumentException();
+
+ return nodes.elements();
+ }
+
+ /**
+ * Returns <code>true</code> if <code>node</code> is a child of this tree
+ * node, and <code>false</code> otherwise. If <code>node</code> is
+ * <code>null</code>, this method returns <code>false</code>.
+ *
+ * @param node the node (<code>null</code> permitted).
+ *
+ * @return A boolean.
+ */
+ public boolean isNodeChild(TreeNode node)
+ {
+ if (node == null)
+ return false;
+
+ return node.getParent() == this;
+ }
+
+ /**
+ * Returns the first child node belonging to this tree node.
+ *
+ * @return The first child node.
+ *
+ * @throws NoSuchElementException if this tree node has no children.
+ */
+ public TreeNode getFirstChild()
+ {
+ return (TreeNode) children.firstElement();
+ }
+
+ /**
+ * Returns the last child node belonging to this tree node.
+ *
+ * @return The last child node.
+ *
+ * @throws NoSuchElementException if this tree node has no children.
+ */
+ public TreeNode getLastChild()
+ {
+ return (TreeNode) children.lastElement();
+ }
+
+ /**
+ * Returns the next child after the specified <code>node</code>, or
+ * <code>null</code> if there is no child after the specified
+ * <code>node</code>.
+ *
+ * @param node a child of this node (<code>null</code> not permitted).
+ *
+ * @return The next child, or <code>null</code>.
+ *
+ * @throws IllegalArgumentException if <code>node</code> is not a child of
+ * this node, or is <code>null</code>.
+ */
+ public TreeNode getChildAfter(TreeNode node)
+ {
+ if (node == null || node.getParent() != this)
+ throw new IllegalArgumentException();
+
+ int index = getIndex(node) + 1;
+
+ if (index == getChildCount())
+ return null;
+
+ return getChildAt(index);
+ }
+
+ /**
+ * Returns the previous child before the specified <code>node</code>, or
+ * <code>null</code> if there is no child before the specified
+ * <code>node</code>.
+ *
+ * @param node a child of this node (<code>null</code> not permitted).
+ *
+ * @return The previous child, or <code>null</code>.
+ *
+ * @throws IllegalArgumentException if <code>node</code> is not a child of
+ * this node, or is <code>null</code>.
+ */
+ public TreeNode getChildBefore(TreeNode node)
+ {
+ if (node == null || node.getParent() != this)
+ throw new IllegalArgumentException();
+
+ int index = getIndex(node) - 1;
+
+ if (index < 0)
+ return null;
+
+ return getChildAt(index);
+ }
+
+ /**
+ * Returns <code>true</code> if this tree node and <code>node</code> share
+ * the same parent. If <code>node</code> is this tree node, the method
+ * returns <code>true</code> and if <code>node</code> is <code>null</code>
+ * this method returns <code>false</code>.
+ *
+ * @param node the node (<code>null</code> permitted).
+ *
+ * @return A boolean.
+ */
+ public boolean isNodeSibling(TreeNode node)
+ {
+ if (node == null)
+ return false;
+ if (node == this)
+ return true;
+ return node.getParent() == getParent() && getParent() != null;
+ }
+
+ /**
+ * Returns the number of siblings for this tree node. If the tree node has
+ * a parent, this method returns the child count for the parent, otherwise
+ * it returns <code>1</code>.
+ *
+ * @return The sibling count.
+ */
+ public int getSiblingCount()
+ {
+ if (parent == null)
+ return 1;
+
+ return parent.getChildCount();
+ }
+
+ /**
+ * Returns the next sibling for this tree node. If this node has no parent,
+ * or this node is the last child of its parent, this method returns
+ * <code>null</code>.
+ *
+ * @return The next sibling, or <code>null</code>.
+ */
+ public DefaultMutableTreeNode getNextSibling()
+ {
+ if (parent == null)
+ return null;
+
+ int index = parent.getIndex(this) + 1;
+
+ if (index == parent.getChildCount())
+ return null;
+
+ return (DefaultMutableTreeNode) parent.getChildAt(index);
+ }
+
+ /**
+ * Returns the previous sibling for this tree node. If this node has no
+ * parent, or this node is the first child of its parent, this method returns
+ * <code>null</code>.
+ *
+ * @return The previous sibling, or <code>null</code>.
+ */
+ public DefaultMutableTreeNode getPreviousSibling()
+ {
+ if (parent == null)
+ return null;
+
+ int index = parent.getIndex(this) - 1;
+
+ if (index < 0)
+ return null;
+
+ return (DefaultMutableTreeNode) parent.getChildAt(index);
+ }
+
+ /**
+ * Returns <code>true</code> if this tree node is a lead node (that is, it
+ * has no children), and <code>false</otherwise>.
+ *
+ * @return A boolean.
+ */
+ public boolean isLeaf()
+ {
+ return children.size() == 0;
+ }
+
+ /**
+ * Returns the first leaf node that is a descendant of this node. Recall
+ * that a node is its own descendant, so if this node has no children then
+ * it is returned as the first leaf.
+ *
+ * @return The first leaf node.
+ */
+ public DefaultMutableTreeNode getFirstLeaf()
+ {
+ TreeNode current = this;
+
+ while (current.getChildCount() > 0)
+ current = current.getChildAt(0);
+
+ return (DefaultMutableTreeNode) current;
+ }
+
+ /**
+ * Returns the last leaf node that is a descendant of this node. Recall
+ * that a node is its own descendant, so if this node has no children then
+ * it is returned as the last leaf.
+ *
+ * @return The first leaf node.
+ */
+ public DefaultMutableTreeNode getLastLeaf()
+ {
+ TreeNode current = this;
+ int size = current.getChildCount();
+
+ while (size > 0)
+ {
+ current = current.getChildAt(size - 1);
+ size = current.getChildCount();
+ }
+
+ return (DefaultMutableTreeNode) current;
+ }
+
+ /**
+ * Returns the next leaf node after this tree node.
+ *
+ * @return The next leaf node, or <code>null</code>.
+ */
+ public DefaultMutableTreeNode getNextLeaf()
+ {
+ // if there is a next sibling, return its first leaf
+ DefaultMutableTreeNode sibling = getNextSibling();
+ if (sibling != null)
+ return sibling.getFirstLeaf();
+ // otherwise move up one level and try again...
+ if (parent != null)
+ return ((DefaultMutableTreeNode) parent).getNextLeaf();
+ return null;
+ }
+
+ /**
+ * Returns the previous leaf node before this tree node.
+ *
+ * @return The previous leaf node, or <code>null</code>.
+ */
+ public DefaultMutableTreeNode getPreviousLeaf()
+ {
+ // if there is a previous sibling, return its last leaf
+ DefaultMutableTreeNode sibling = getPreviousSibling();
+ if (sibling != null)
+ return sibling.getLastLeaf();
+ // otherwise move up one level and try again...
+ if (parent != null)
+ return ((DefaultMutableTreeNode) parent).getPreviousLeaf();
+ return null;
+ }
+
+ /**
+ * getLeafCount
+ *
+ * @return int
+ */
+ public int getLeafCount()
+ {
+ int count = 0;
+ Enumeration e = depthFirstEnumeration();
+
+ while (e.hasMoreElements())
+ {
+ TreeNode current = (TreeNode) e.nextElement();
+
+ if (current.isLeaf())
+ count++;
+ }
+
+ return count;
+ }
+
+ /** Provides an enumeration of a tree in breadth-first traversal
+ * order.
+ */
+ static class BreadthFirstEnumeration implements Enumeration
+ {
+
+ LinkedList queue = new LinkedList();
+
+ BreadthFirstEnumeration(TreeNode node)
+ {
+ queue.add(node);
+ }
+
+ public boolean hasMoreElements()
+ {
+ return !queue.isEmpty();
+ }
+
+ public Object nextElement()
+ {
+ if (queue.isEmpty())
+ throw new NoSuchElementException("No more elements left.");
+
+ TreeNode node = (TreeNode) queue.removeFirst();
+
+ Enumeration children = node.children();
+ while (children.hasMoreElements())
+ queue.add(children.nextElement());
+
+ return node;
+ }
+ }
+
+ /** Provides an enumeration of a tree traversing it
+ * preordered.
+ */
+ static class PreorderEnumeration implements Enumeration
+ {
+ TreeNode next;
+
+ Stack childrenEnums = new Stack();
+
+ PreorderEnumeration(TreeNode node)
+ {
+ next = node;
+ childrenEnums.push(node.children());
+ }
+
+ public boolean hasMoreElements()
+ {
+ return next != null;
+ }
+
+ public Object nextElement()
+ {
+ if (next == null)
+ throw new NoSuchElementException("No more elements left.");
+
+ Object current = next;
+
+ Enumeration children = (Enumeration) childrenEnums.peek();
+
+ // Retrieves the next element.
+ next = traverse(children);
+
+ return current;
+ }
+
+ private TreeNode traverse(Enumeration children)
+ {
+ // If more children are available step down.
+ if (children.hasMoreElements())
+ {
+ TreeNode child = (TreeNode) children.nextElement();
+ childrenEnums.push(child.children());
+
+ return child;
+ }
+
+ // If no children are left, we return to a higher level.
+ childrenEnums.pop();
+
+ // If there are no more levels left, there is no next
+ // element to return.
+ if (childrenEnums.isEmpty())
+ return null;
+ else
+ {
+ return traverse((Enumeration) childrenEnums.peek());
+ }
+ }
+ }
+
+ /** Provides an enumeration of a tree traversing it
+ * postordered (= depth-first).
+ */
+ static class PostorderEnumeration implements Enumeration
+ {
+
+ Stack nodes = new Stack();
+ Stack childrenEnums = new Stack();
+
+ PostorderEnumeration(TreeNode node)
+ {
+ nodes.push(node);
+ childrenEnums.push(node.children());
+ }
+
+ public boolean hasMoreElements()
+ {
+ return !nodes.isEmpty();
+ }
+
+ public Object nextElement()
+ {
+ if (nodes.isEmpty())
+ throw new NoSuchElementException("No more elements left!");
+
+ Enumeration children = (Enumeration) childrenEnums.peek();
+
+ return traverse(children);
+ }
+
+ private Object traverse(Enumeration children)
+ {
+ if (children.hasMoreElements())
+ {
+ TreeNode node = (TreeNode) children.nextElement();
+ nodes.push(node);
+
+ Enumeration newChildren = node.children();
+ childrenEnums.push(newChildren);
+
+ return traverse(newChildren);
+ }
+ else
+ {
+ childrenEnums.pop();
+
+ // Returns the node whose children
+ // have all been visited. (= postorder)
+ Object next = nodes.peek();
+ nodes.pop();
+
+ return next;
+ }
+ }
+
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,786 @@
+/* DefaultTreeCellEditor.java --
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.tree;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.EventObject;
+
+import javax.swing.DefaultCellEditor;
+import javax.swing.Icon;
+import javax.swing.JTextField;
+import javax.swing.JTree;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.border.Border;
+import javax.swing.event.CellEditorListener;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.EventListenerList;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+
+/**
+ * Participates in the tree cell editing.
+ *
+ * @author Andrew Selkirk
+ * @author Audrius Meskauskas
+ */
+public class DefaultTreeCellEditor
+ implements ActionListener, TreeCellEditor, TreeSelectionListener
+{
+ /**
+ * The number of the fast mouse clicks, required to start the editing
+ * session.
+ */
+ static int CLICK_COUNT_TO_START = 3;
+
+ /**
+ * This container that appears on the tree during editing session.
+ * It contains the editing component displays various other editor -
+ * specific parts like editing icon.
+ */
+ public class EditorContainer extends Container
+ {
+ /**
+ * Use v 1.5 serial version UID for interoperability.
+ */
+ static final long serialVersionUID = 6470339600449699810L;
+
+ /**
+ * Creates an <code>EditorContainer</code> object.
+ */
+ public EditorContainer()
+ {
+ // Do nothing here.
+ }
+
+ /**
+ * This method only exists for API compatibility and is useless as it does
+ * nothing. It got probably introduced by accident.
+ */
+ public void EditorContainer()
+ {
+ // Do nothing here.
+ }
+
+ public void setBounds(Rectangle bounds)
+ {
+ super.setBounds(bounds);
+ doLayout();
+ }
+
+ /**
+ * Overrides Container.paint to paint the node's icon and use the selection
+ * color for the background.
+ *
+ * @param g -
+ * the specified Graphics window
+ */
+ public void paint(Graphics g)
+ {
+ if (editingIcon != null)
+ {
+ // From the previous version, the left margin is taken as half
+ // of the icon width.
+ editingIcon.paintIcon(this, g, 0, 0);
+ }
+ super.paint(g);
+ }
+
+ /**
+ * Lays out this Container, moving the editor component to the left
+ * (leaving place for the icon).
+ */
+ public void doLayout()
+ {
+ // The offset of the editing component.
+ int eOffset;
+
+ // Move the component to the left, leaving room for the editing icon:
+ if (editingIcon != null)
+ eOffset = editingIcon.getIconWidth();
+ else
+ eOffset = 0;
+
+ Rectangle bounds = getBounds();
+ Component c = getComponent(0);
+ c.setLocation(eOffset, 0);
+
+ // Span the editing component near over all window width.
+ c.setSize(bounds.width - eOffset, bounds.height);
+ /*
+ * @specnote the Sun sets some more narrow editing component width (it is
+ * not documented how does it is calculated). However as our text field is
+ * still not able to auto - scroll horizontally, replicating such strategy
+ * would prevent adding extra characters to the text being edited.
+ */
+ }
+ }
+
+ /**
+ * The default text field, used in the editing sessions.
+ */
+ public class DefaultTextField extends JTextField
+ {
+ /**
+ * Use v 1.5 serial version UID for interoperability.
+ */
+ static final long serialVersionUID = -6629304544265300143L;
+
+ /**
+ * The border of the text field.
+ */
+ protected Border border;
+
+ /**
+ * Creates a <code>DefaultTextField</code> object.
+ *
+ * @param aBorder the border to use
+ */
+ public DefaultTextField(Border aBorder)
+ {
+ border = aBorder;
+ }
+
+ /**
+ * Gets the font of this component.
+ * @return this component's font; if a font has not been set for
+ * this component, the font of its parent is returned (if the parent
+ * is not null, otherwise null is returned).
+ */
+ public Font getFont()
+ {
+ Font font = super.getFont();
+ if (font == null)
+ {
+ Component parent = getParent();
+ if (parent != null)
+ return parent.getFont();
+ return null;
+ }
+ return font;
+ }
+
+ /**
+ * Returns the border of the text field.
+ *
+ * @return the border
+ */
+ public Border getBorder()
+ {
+ return border;
+ }
+
+ /**
+ * Overrides JTextField.getPreferredSize to return the preferred size
+ * based on current font, if set, or else use renderer's font.
+ *
+ * @return the Dimension of this textfield.
+ */
+ public Dimension getPreferredSize()
+ {
+ String s = getText();
+
+ Font f = getFont();
+
+ if (f != null)
+ {
+ FontMetrics fm = getToolkit().getFontMetrics(f);
+
+ return new Dimension(SwingUtilities.computeStringWidth(fm, s),
+ fm.getHeight());
+ }
+ return renderer.getPreferredSize();
+ }
+ }
+
+ /**
+ * Listens for the events from the realEditor.
+ */
+ class RealEditorListener implements CellEditorListener
+ {
+ /**
+ * The method is called when the editing has been cancelled.
+ * @param event unused
+ */
+ public void editingCanceled(ChangeEvent event)
+ {
+ cancelCellEditing();
+ }
+
+ /**
+ * The method is called after completing the editing session.
+ *
+ * @param event unused
+ */
+ public void editingStopped(ChangeEvent event)
+ {
+ stopCellEditing();
+ }
+ }
+
+ private EventListenerList listenerList = new EventListenerList();
+
+ /**
+ * Editor handling the editing.
+ */
+ protected TreeCellEditor realEditor;
+
+ /**
+ * Renderer, used to get border and offsets from.
+ */
+ protected DefaultTreeCellRenderer renderer;
+
+ /**
+ * Editing container, will contain the editorComponent.
+ */
+ protected Container editingContainer;
+
+ /**
+ * Component used in editing, obtained from the editingContainer.
+ */
+ protected transient Component editingComponent;
+
+ /**
+ * As of Java 2 platform v1.4 this field should no longer be used.
+ * If you wish to provide similar behavior you should directly
+ * override isCellEditable.
+ */
+ protected boolean canEdit;
+
+ /**
+ * Used in editing. Indicates x position to place editingComponent.
+ */
+ protected transient int offset;
+
+ /**
+ * JTree instance listening too.
+ */
+ protected transient JTree tree;
+
+ /**
+ * Last path that was selected.
+ */
+ protected transient TreePath lastPath;
+
+ /**
+ * Used before starting the editing session.
+ */
+ protected transient javax.swing.Timer timer;
+
+ /**
+ * Row that was last passed into getTreeCellEditorComponent.
+ */
+ protected transient int lastRow;
+
+ /**
+ * True if the border selection color should be drawn.
+ */
+ protected Color borderSelectionColor;
+
+ /**
+ * Icon to use when editing.
+ */
+ protected transient Icon editingIcon;
+
+ /**
+ * Font to paint with, null indicates font of renderer is to be used.
+ */
+ protected Font font;
+
+ /**
+ * Helper field used to save the last path seen while the timer was
+ * running.
+ */
+ private TreePath tPath;
+
+ /**
+ * Constructs a DefaultTreeCellEditor object for a JTree using the
+ * specified renderer and a default editor. (Use this constructor
+ * for normal editing.)
+ *
+ * @param tree - a JTree object
+ * @param renderer - a DefaultTreeCellRenderer object
+ */
+ public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer)
+ {
+ this(tree, renderer, null);
+ }
+
+ /**
+ * Constructs a DefaultTreeCellEditor object for a JTree using the specified
+ * renderer and the specified editor. (Use this constructor
+ * for specialized editing.)
+ *
+ * @param tree - a JTree object
+ * @param renderer - a DefaultTreeCellRenderer object
+ * @param editor - a TreeCellEditor object
+ */
+ public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer,
+ TreeCellEditor editor)
+ {
+ setTree(tree);
+ this.renderer = renderer;
+
+ if (editor == null)
+ editor = createTreeCellEditor();
+ else
+ editor.addCellEditorListener(new RealEditorListener());
+
+ realEditor = editor;
+
+ lastPath = tree.getLeadSelectionPath();
+ tree.addTreeSelectionListener(this);
+ editingContainer = createContainer();
+ setFont(UIManager.getFont("Tree.font"));
+ setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor"));
+ }
+
+ /**
+ * Configures the editing component whenever it is null.
+ *
+ * @param tree the tree to configure to component for.
+ * @param renderer the renderer used to set up the nodes
+ * @param editor the editor used
+ */
+ private void configureEditingComponent(JTree tree,
+ DefaultTreeCellRenderer renderer,
+ TreeCellEditor editor)
+ {
+ if (tree != null && lastPath != null)
+ {
+ Object val = lastPath.getLastPathComponent();
+ boolean isLeaf = tree.getModel().isLeaf(val);
+ boolean expanded = tree.isExpanded(lastPath);
+ determineOffset(tree, val, true, expanded, isLeaf, lastRow);
+
+ // set up icon
+ if (isLeaf)
+ renderer.setIcon(renderer.getLeafIcon());
+ else if (expanded)
+ renderer.setIcon(renderer.getOpenIcon());
+ else
+ renderer.setIcon(renderer.getClosedIcon());
+ editingIcon = renderer.getIcon();
+
+ editingComponent = getTreeCellEditorComponent(tree, val, true,
+ expanded, isLeaf, lastRow);
+ }
+ }
+
+ /**
+ * writeObject
+ *
+ * @param value0
+ * TODO
+ * @exception IOException
+ * TODO
+ */
+ private void writeObject(ObjectOutputStream value0) throws IOException
+ {
+ // TODO
+ }
+
+ /**
+ * readObject
+ * @param value0 TODO
+ * @exception IOException TODO
+ * @exception ClassNotFoundException TODO
+ */
+ private void readObject(ObjectInputStream value0)
+ throws IOException, ClassNotFoundException
+ {
+ // TODO
+ }
+
+ /**
+ * Sets the color to use for the border.
+ * @param newColor - the new border color
+ */
+ public void setBorderSelectionColor(Color newColor)
+ {
+ this.borderSelectionColor = newColor;
+ }
+
+ /**
+ * Returns the color the border is drawn.
+ * @return Color
+ */
+ public Color getBorderSelectionColor()
+ {
+ return borderSelectionColor;
+ }
+
+ /**
+ * Sets the font to edit with. null indicates the renderers
+ * font should be used. This will NOT override any font you have
+ * set in the editor the receiver was instantied with. If null for
+ * an editor was passed in, a default editor will be created that
+ * will pick up this font.
+ *
+ * @param font - the editing Font
+ */
+ public void setFont(Font font)
+ {
+ if (font != null)
+ this.font = font;
+ else
+ this.font = renderer.getFont();
+ }
+
+ /**
+ * Gets the font used for editing.
+ *
+ * @return the editing font
+ */
+ public Font getFont()
+ {
+ return font;
+ }
+
+ /**
+ * Configures the editor. Passed onto the realEditor.
+ * Sets an initial value for the editor. This will cause
+ * the editor to stopEditing and lose any partially edited value
+ * if the editor is editing when this method is called.
+ * Returns the component that should be added to the client's Component
+ * hierarchy. Once installed in the client's hierarchy this component will
+ * then be able to draw and receive user input.
+ *
+ * @param tree - the JTree that is asking the editor to edit; this parameter can be null
+ * @param value - the value of the cell to be edited
+ * @param isSelected - true is the cell is to be rendered with selection highlighting
+ * @param expanded - true if the node is expanded
+ * @param leaf - true if the node is a leaf node
+ * @param row - the row index of the node being edited
+ *
+ * @return the component for editing
+ */
+ public Component getTreeCellEditorComponent(JTree tree, Object value,
+ boolean isSelected, boolean expanded,
+ boolean leaf, int row)
+ {
+ if (realEditor == null)
+ realEditor = createTreeCellEditor();
+
+ return realEditor.getTreeCellEditorComponent(tree, value, isSelected,
+ expanded, leaf, row);
+ }
+
+ /**
+ * Returns the value currently being edited (requests it from the
+ * {@link realEditor}.
+ *
+ * @return the value currently being edited
+ */
+ public Object getCellEditorValue()
+ {
+ return realEditor.getCellEditorValue();
+ }
+
+ /**
+ * If the realEditor returns true to this message, prepareForEditing
+ * is messaged and true is returned.
+ *
+ * @param event - the event the editor should use to consider whether to
+ * begin editing or not
+ * @return true if editing can be started
+ */
+ public boolean isCellEditable(EventObject event)
+ {
+ if (editingComponent == null)
+ configureEditingComponent(tree, renderer, realEditor);
+
+ if (editingComponent != null && realEditor.isCellEditable(event))
+ {
+ prepareForEditing();
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Messages the realEditor for the return value.
+ *
+ * @param event -
+ * the event the editor should use to start editing
+ * @return true if the editor would like the editing cell to be selected;
+ * otherwise returns false
+ */
+ public boolean shouldSelectCell(EventObject event)
+ {
+ return true;
+ }
+
+ /**
+ * If the realEditor will allow editing to stop, the realEditor
+ * is removed and true is returned, otherwise false is returned.
+ * @return true if editing was stopped; false otherwise
+ */
+ public boolean stopCellEditing()
+ {
+ if (editingComponent != null)
+ {
+ stopEditingTimer();
+ tree.stopEditing();
+ editingComponent = null;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Messages cancelCellEditing to the realEditor and removes it
+ * from this instance.
+ */
+ public void cancelCellEditing()
+ {
+ if (editingComponent != null)
+ {
+ tree.cancelEditing();
+ editingComponent = null;
+ }
+ stopEditingTimer();
+ }
+
+ /**
+ * Stop the editing timer, if it is installed and running.
+ */
+ private void stopEditingTimer()
+ {
+ if (timer != null && timer.isRunning())
+ timer.stop();
+ }
+
+ /**
+ * Adds a <code>CellEditorListener</code> object to this editor.
+ *
+ * @param listener
+ * the listener to add
+ */
+ public void addCellEditorListener(CellEditorListener listener)
+ {
+ realEditor.addCellEditorListener(listener);
+ }
+
+ /**
+ * Removes a <code>CellEditorListener</code> object.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeCellEditorListener(CellEditorListener listener)
+ {
+ realEditor.removeCellEditorListener(listener);
+ }
+
+ /**
+ * Returns all added <code>CellEditorListener</code> objects to this editor.
+ *
+ * @return an array of listeners
+ *
+ * @since 1.4
+ */
+ public CellEditorListener[] getCellEditorListeners()
+ {
+ return (CellEditorListener[]) listenerList.getListeners(CellEditorListener.class);
+ }
+
+ /**
+ * Resets lastPath.
+ *
+ * @param e - the event that characterizes the change.
+ */
+ public void valueChanged(TreeSelectionEvent e)
+ {
+ tPath = lastPath;
+ lastPath = e.getNewLeadSelectionPath();
+ lastRow = tree.getRowForPath(lastPath);
+ stopCellEditing();
+ }
+
+ /**
+ * Messaged when the timer fires.
+ *
+ * @param e the event that characterizes the action.
+ */
+ public void actionPerformed(ActionEvent e)
+ {
+ }
+
+ /**
+ * Sets the tree currently editing for. This is needed to add a selection
+ * listener.
+ *
+ * @param newTree -
+ * the new tree to be edited
+ */
+ protected void setTree(JTree newTree)
+ {
+ tree = newTree;
+ }
+
+ /**
+ * Returns true if event is a MouseEvent and the click count is 1.
+ *
+ * @param event - the event being studied
+ * @return true if editing should start
+ */
+ protected boolean shouldStartEditingTimer(EventObject event)
+ {
+ if ((event instanceof MouseEvent) &&
+ ((MouseEvent) event).getClickCount() == 1)
+ return true;
+ return false;
+ }
+
+ /**
+ * Starts the editing timer (if one installed).
+ */
+ protected void startEditingTimer()
+ {
+ if (timer != null)
+ timer.start();
+ }
+
+ /**
+ * Returns true if event is null, or it is a MouseEvent with
+ * a click count > 2 and inHitRegion returns true.
+ *
+ * @param event - the event being studied
+ * @return true if event is null, or it is a MouseEvent with
+ * a click count > 2 and inHitRegion returns true
+ */
+ protected boolean canEditImmediately(EventObject event)
+ {
+ if (event == null || !(event instanceof MouseEvent) || (((MouseEvent) event).
+ getClickCount() > 2 && inHitRegion(((MouseEvent) event).getX(),
+ ((MouseEvent) event).getY())))
+ return true;
+ return false;
+ }
+
+ /**
+ * Returns true if the passed in location is a valid mouse location
+ * to start editing from. This is implemented to return false if x is
+ * less than or equal to the width of the icon and icon
+ * gap displayed by the renderer. In other words this returns true if
+ * the user clicks over the text part displayed by the renderer, and
+ * false otherwise.
+ *
+ * @param x - the x-coordinate of the point
+ * @param y - the y-coordinate of the point
+ *
+ * @return true if the passed in location is a valid mouse location
+ */
+ protected boolean inHitRegion(int x, int y)
+ {
+ Rectangle bounds = tree.getPathBounds(lastPath);
+
+ return bounds.contains(x, y);
+ }
+
+ /**
+ * determineOffset
+ * @param tree -
+ * @param value -
+ * @param isSelected -
+ * @param expanded -
+ * @param leaf -
+ * @param row -
+ */
+ protected void determineOffset(JTree tree, Object value, boolean isSelected,
+ boolean expanded, boolean leaf, int row)
+ {
+ renderer.getTreeCellRendererComponent(tree, value, isSelected, expanded,
+ leaf, row, true);
+ Icon c = renderer.getIcon();
+ if (c != null)
+ offset = renderer.getIconTextGap() + c.getIconWidth();
+ else
+ offset = 0;
+ }
+
+ /**
+ * Invoked just before editing is to start. Will add the
+ * editingComponent to the editingContainer.
+ */
+ protected void prepareForEditing()
+ {
+ editingContainer.removeAll();
+ editingContainer.add(editingComponent);
+ }
+
+ /**
+ * Creates the container to manage placement of editingComponent.
+ *
+ * @return the container to manage the placement of the editingComponent.
+ */
+ protected Container createContainer()
+ {
+ return new DefaultTreeCellEditor.EditorContainer();
+ }
+
+ /**
+ * This is invoked if a TreeCellEditor is not supplied in the constructor.
+ * It returns a TextField editor.
+ *
+ * @return a new TextField editor
+ */
+ protected TreeCellEditor createTreeCellEditor()
+ {
+ DefaultCellEditor editor = new DefaultCellEditor(new DefaultTreeCellEditor.DefaultTextField(
+ UIManager.getBorder("Tree.selectionBorder")));
+ editor.addCellEditorListener(new RealEditorListener());
+ editor.setClickCountToStart(CLICK_COUNT_TO_START);
+ realEditor = editor;
+ return editor;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,715 @@
+/* DefaultTreeCellRenderer.java
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+ This file is part of GNU Classpath.
+
+ GNU Classpath is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU Classpath is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Classpath; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version. */
+
+
+package javax.swing.tree;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Rectangle;
+
+import javax.swing.Icon;
+import javax.swing.JLabel;
+import javax.swing.JTree;
+import javax.swing.LookAndFeel;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.border.Border;
+import javax.swing.plaf.UIResource;
+
+/**
+ * A default implementation of the {@link TreeCellRenderer} interface.
+ *
+ * @author Andrew Selkirk
+ */
+public class DefaultTreeCellRenderer
+ extends JLabel
+ implements TreeCellRenderer
+{
+
+ /**
+ * A flag indicating the current selection status.
+ */
+ protected boolean selected;
+
+ /**
+ * A flag indicating the current focus status.
+ */
+ protected boolean hasFocus;
+
+ /**
+ * drawsFocusBorderAroundIcon // FIXME: is this used?
+ */
+ private boolean drawsFocusBorderAroundIcon;
+
+ /**
+ * The icon used to represent non-leaf nodes that are closed.
+ *
+ * @see #setClosedIcon(Icon)
+ */
+ protected transient Icon closedIcon;
+
+ /**
+ * The icon used to represent leaf nodes.
+ *
+ * @see #setLeafIcon(Icon)
+ */
+ protected transient Icon leafIcon;
+
+ /**
+ * The icon used to represent non-leaf nodes that are open.
+ *
+ * @see #setOpenIcon(Icon)
+ */
+ protected transient Icon openIcon;
+
+ /**
+ * The color used for text in selected cells.
+ *
+ * @see #setTextSelectionColor(Color)
+ */
+ protected Color textSelectionColor;
+
+ /**
+ * The color used for text in non-selected cells.
+ *
+ * @see #setTextNonSelectionColor(Color)
+ */
+ protected Color textNonSelectionColor;
+
+ /**
+ * The background color for selected cells.
+ *
+ * @see #setBackgroundSelectionColor(Color)
+ */
+ protected Color backgroundSelectionColor;
+
+ /**
+ * The background color for non-selected cells.
+ *
+ * @see #setBackgroundNonSelectionColor(Color)
+ */
+ protected Color backgroundNonSelectionColor;
+
+ /**
+ * The border color for selected tree cells.
+ *
+ * @see #setBorderSelectionColor(Color)
+ */
+ protected Color borderSelectionColor;
+
+ /**
+ * Creates a new tree cell renderer with defaults appropriate for the
+ * current {@link LookAndFeel}.
+ */
+ public DefaultTreeCellRenderer()
+ {
+ setLeafIcon(getDefaultLeafIcon());
+ setOpenIcon(getDefaultOpenIcon());
+ setClosedIcon(getDefaultClosedIcon());
+
+ setTextNonSelectionColor(UIManager.getColor("Tree.textForeground"));
+ setTextSelectionColor(UIManager.getColor("Tree.selectionForeground"));
+ setBackgroundNonSelectionColor(UIManager.getColor("Tree.textBackground"));
+ setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground"));
+ setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor"));
+ }
+
+ /**
+ * Returns the default icon for non-leaf tree cells that are open (expanded).
+ * The icon is fetched from the defaults table for the current
+ * {@link LookAndFeel} using the key <code>Tree.openIcon</code>.
+ *
+ * @return The default icon.
+ */
+ public Icon getDefaultOpenIcon()
+ {
+ return UIManager.getIcon("Tree.openIcon");
+ }
+
+ /**
+ * Returns the default icon for non-leaf tree cells that are closed (not
+ * expanded). The icon is fetched from the defaults table for the current
+ * {@link LookAndFeel} using the key <code>Tree.closedIcon</code>.
+ *
+ * @return The default icon.
+ */
+ public Icon getDefaultClosedIcon()
+ {
+ return UIManager.getIcon("Tree.closedIcon");
+ }
+
+ /**
+ * Returns the default icon for leaf tree cells. The icon is fetched from
+ * the defaults table for the current {@link LookAndFeel} using the key
+ * <code>Tree.leafIcon</code>.
+ *
+ * @return The default icon.
+ */
+ public Icon getDefaultLeafIcon()
+ {
+ return UIManager.getIcon("Tree.leafIcon");
+ }
+
+ /**
+ * Sets the icon to be displayed for non-leaf nodes that are open (expanded).
+ * Set this to <code>null</code> if no icon is required.
+ *
+ * @param icon the icon (<code>null</code> permitted).
+ *
+ * @see #getOpenIcon()
+ */
+ public void setOpenIcon(Icon icon)
+ {
+ openIcon = icon;
+ }
+
+ /**
+ * Returns the icon displayed for non-leaf nodes that are open (expanded).
+ * The default value is initialised from the {@link LookAndFeel}.
+ *
+ * @return The open icon (possibly <code>null</code>).
+ *
+ * @see #setOpenIcon(Icon)
+ */
+ public Icon getOpenIcon()
+ {
+ return openIcon;
+ }
+
+ /**
+ * Sets the icon to be displayed for non-leaf nodes that are closed. Set
+ * this to <code>null</code> if no icon is required.
+ *
+ * @param icon the icon (<code>null</code> permitted).
+ *
+ * @see #getClosedIcon()
+ */
+ public void setClosedIcon(Icon icon)
+ {
+ closedIcon = icon;
+ }
+
+ /**
+ * Returns the icon displayed for non-leaf nodes that are closed. The
+ * default value is initialised from the {@link LookAndFeel}.
+ *
+ * @return The closed icon (possibly <code>null</code>).
+ *
+ * @see #setClosedIcon(Icon)
+ */
+ public Icon getClosedIcon()
+ {
+ return closedIcon;
+ }
+
+ /**
+ * Sets the icon to be displayed for leaf nodes. Set this to
+ * <code>null</code> if no icon is required.
+ *
+ * @param icon the icon (<code>null</code> permitted).
+ *
+ * @see #getLeafIcon()
+ */
+ public void setLeafIcon(Icon icon)
+ {
+ leafIcon = icon;
+ }
+
+ /**
+ * Returns the icon displayed for leaf nodes. The default value is
+ * initialised from the {@link LookAndFeel}.
+ *
+ * @return The leaf icon (possibly <code>null</code>).
+ *
+ * @see #setLeafIcon(Icon)
+ */
+ public Icon getLeafIcon()
+ {
+ return leafIcon;
+ }
+
+ /**
+ * Sets the text color for tree cells that are selected.
+ *
+ * @param c the color (<code>null</code> permitted).
+ *
+ * @see #getTextSelectionColor()
+ */
+ public void setTextSelectionColor(Color c)
+ {
+ textSelectionColor = c;
+ }
+
+ /**
+ * Returns the text color for tree cells that are selected.
+ * The default value is obtained from the {@link LookAndFeel} defaults
+ * table using the key <code>Tree.selectionForeground</code>.
+ *
+ * @return The text color for tree cells that are selected.
+ *
+ * @see #setTextSelectionColor(Color)
+ */
+ public Color getTextSelectionColor()
+ {
+ return textSelectionColor;
+ }
+
+ /**
+ * Sets the text color for tree cells that are not selected.
+ *
+ * @param c the color (<code>null</code> permitted).
+ *
+ * @see #getTextNonSelectionColor()
+ */
+ public void setTextNonSelectionColor(Color c)
+ {
+ textNonSelectionColor = c;
+ }
+
+ /**
+ * Returns the text color for tree cells that are not selected.
+ * The default value is obtained from the {@link LookAndFeel} defaults
+ * table using the key <code>Tree.selectionForeground</code>.
+ *
+ * @return The background color for tree cells that are not selected.
+ *
+ * @see #setTextgroundNonSelectionColor(Color)
+ */
+ public Color getTextNonSelectionColor()
+ {
+ return textNonSelectionColor;
+ }
+
+ /**
+ * Sets the background color for tree cells that are selected.
+ *
+ * @param c the color (<code>null</code> permitted).
+ *
+ * @see #getBackgroundSelectionColor()
+ */
+ public void setBackgroundSelectionColor(Color c)
+ {
+ backgroundSelectionColor = c;
+ }
+
+ /**
+ * Returns the background color for tree cells that are selected.
+ * The default value is obtained from the {@link LookAndFeel} defaults
+ * table using the key <code>Tree.selectionBackground</code>.
+ *
+ * @return The background color for tree cells that are selected.
+ *
+ * @see #setBackgroundSelectionColor(Color)
+ */
+ public Color getBackgroundSelectionColor()
+ {
+ return backgroundSelectionColor;
+ }
+
+ /**
+ * Sets the background color for tree cells that are not selected.
+ *
+ * @param c the color (<code>null</code> permitted).
+ *
+ * @see #getBackgroundNonSelectionColor()
+ */
+ public void setBackgroundNonSelectionColor(Color c)
+ {
+ backgroundNonSelectionColor = c;
+ }
+
+ /**
+ * Returns the background color for tree cells that are not selected.
+ * The default value is obtained from the {@link LookAndFeel} defaults
+ * table using the key <code>Tree.textBackground</code>.
+ *
+ * @return The background color for tree cells that are not selected.
+ *
+ * @see #setBackgroundNonSelectionColor(Color)
+ */
+ public Color getBackgroundNonSelectionColor()
+ {
+ return backgroundNonSelectionColor;
+ }
+
+ /**
+ * Sets the border color for tree cells that are selected.
+ *
+ * @param c the color (<code>null</code> permitted).
+ *
+ * @see #getBorderSelectionColor()
+ */
+ public void setBorderSelectionColor(Color c)
+ {
+ borderSelectionColor = c;
+ }
+
+ /**
+ * Returns the border color for tree cells that are selected.
+ * The default value is obtained from the {@link LookAndFeel} defaults
+ * table using the key <code>Tree.selectionBorderColor</code>.
+ *
+ * @return The border color for tree cells that are selected.
+ *
+ * @see #setBorderSelectionColor(Color)
+ */
+ public Color getBorderSelectionColor()
+ {
+ return borderSelectionColor;
+ }
+
+ /**
+ * Sets the font.
+ *
+ * @param f the font.
+ *
+ * @see #getFont()
+ */
+ public void setFont(Font f)
+ {
+ if (f != null && f instanceof UIResource)
+ f = null;
+ super.setFont(f);
+ }
+
+ /**
+ * Sets the background color.
+ *
+ * @param c the color.
+ */
+ public void setBackground(Color c)
+ {
+ if (c != null && c instanceof UIResource)
+ c = null;
+ super.setBackground(c);
+ }
+
+ /**
+ * Returns a component (in fact <code>this</code>) that can be used to
+ * render a tree cell with the specified state.
+ *
+ * @param tree the tree that the cell belongs to.
+ * @param val the cell value.
+ * @param selected indicates whether or not the cell is selected.
+ * @param expanded indicates whether or not the cell is expanded.
+ * @param leaf indicates whether or not the cell is a leaf in the tree.
+ * @param row the row index.
+ * @param hasFocus indicates whether or not the cell has the focus.
+ *
+ * @return <code>this</code>.
+ */
+ public Component getTreeCellRendererComponent(JTree tree, Object val,
+ boolean selected,
+ boolean expanded, boolean leaf,
+ int row, boolean hasFocus)
+ {
+ if (leaf)
+ setIcon(getLeafIcon());
+ else if (expanded)
+ setIcon(getOpenIcon());
+ else
+ setIcon(getClosedIcon());
+
+ setText(val.toString());
+ this.selected = selected;
+ this.hasFocus = hasFocus;
+ setHorizontalAlignment(LEFT);
+ setOpaque(false);
+ setVerticalAlignment(CENTER);
+ setEnabled(true);
+ super.setFont(UIManager.getFont("Tree.font"));
+
+ if (selected)
+ {
+ super.setBackground(getBackgroundSelectionColor());
+ setForeground(getTextSelectionColor());
+
+ if (hasFocus)
+ setBorderSelectionColor(UIManager.getLookAndFeelDefaults().
+ getColor("Tree.selectionBorderColor"));
+ else
+ setBorderSelectionColor(null);
+ }
+ else
+ {
+ super.setBackground(getBackgroundNonSelectionColor());
+ setForeground(getTextNonSelectionColor());
+ setBorderSelectionColor(null);
+ }
+
+ return this;
+ }
+
+ /**
+ * Returns the current font.
+ *
+ * @return The current font.
+ *
+ * @see #setFont(Font)
+ */
+ public Font getFont()
+ {
+ return super.getFont();
+ }
+
+ /**
+ * Paints the value. The background is filled based on selected.
+ *
+ * @param g the graphics device.
+ */
+ public void paint(Graphics g)
+ {
+ // paint background
+ Rectangle vr = new Rectangle();
+ Rectangle ir = new Rectangle();
+ Rectangle tr = new Rectangle();
+
+ Insets insets = new Insets(0, 0, 0, 0);
+ Border border = UIManager.getBorder("Tree.selectionBorder");
+ if (border != null)
+ insets = border.getBorderInsets(this);
+
+ FontMetrics fm = getToolkit().getFontMetrics(getFont());
+ SwingUtilities.layoutCompoundLabel((JLabel) this, fm, getText(),
+ getIcon(), getVerticalAlignment(),
+ getHorizontalAlignment(),
+ getVerticalTextPosition(),
+ getHorizontalTextPosition(), vr, ir, tr,
+ getIconTextGap());
+
+ // Reusing one rectangle.
+ Rectangle bounds = getBounds(ir);
+
+ bounds.x = tr.x - insets.left;
+ bounds.width = tr.width + insets.left + insets.right;
+
+ g.setColor(super.getBackground());
+ g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
+
+ super.paint(g);
+
+ // Paint the border of the focused element only (lead selection)
+ if (hasFocus)
+ {
+ Color b = getBorderSelectionColor();
+ if (b != null)
+ {
+ g.setColor(b);
+ g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height - 1);
+ }
+ }
+ }
+
+ /**
+ * Returns the preferred size of the cell.
+ *
+ * @return The preferred size of the cell.
+ */
+ public Dimension getPreferredSize()
+ {
+ Rectangle vr = new Rectangle();
+ Rectangle ir = new Rectangle();
+ Rectangle tr = new Rectangle();
+
+ FontMetrics fm = getToolkit().getFontMetrics(getFont());
+ SwingUtilities.layoutCompoundLabel((JLabel) this, fm, getText(),
+ getIcon(), getVerticalAlignment(),
+ getHorizontalAlignment(),
+ getVerticalTextPosition(),
+ getHorizontalTextPosition(), vr, ir, tr,
+ getIconTextGap());
+ Rectangle cr = ir.union(tr);
+ return new Dimension(cr.width, cr.height);
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ */
+ public void validate()
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ */
+ public void revalidate()
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ *
+ * @param tm ignored
+ * @param x coordinate of the region to mark as dirty
+ * @param y coordinate of the region to mark as dirty
+ * @param width dimension of the region to mark as dirty
+ * @param height dimension of the region to mark as dirty
+ */
+ public void repaint(long tm, int x, int y, int width, int height)
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ *
+ * @param area the area to repaint.
+ */
+ public void repaint(Rectangle area)
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ *
+ * @param name the property name.
+ * @param oldValue the old value.
+ * @param newValue the new value.
+ */
+ protected void firePropertyChange(String name, Object oldValue,
+ Object newValue)
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ *
+ * @param name the property name.
+ * @param oldValue the old value.
+ * @param newValue the new value.
+ */
+ public void firePropertyChange(String name, byte oldValue, byte newValue)
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ *
+ * @param name the property name.
+ * @param oldValue the old value.
+ * @param newValue the new value.
+ */
+ public void firePropertyChange(String name, char oldValue, char newValue)
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ *
+ * @param name the property name.
+ * @param oldValue the old value.
+ * @param newValue the new value.
+ */
+ public void firePropertyChange(String name, short oldValue, short newValue)
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ *
+ * @param name the property name.
+ * @param oldValue the old value.
+ * @param newValue the new value.
+ */
+ public void firePropertyChange(String name, int oldValue, int newValue)
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ *
+ * @param name the property name.
+ * @param oldValue the old value.
+ * @param newValue the new value.
+ */
+ public void firePropertyChange(String name, long oldValue, long newValue)
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ *
+ * @param name the property name.
+ * @param oldValue the old value.
+ * @param newValue the new value.
+ */
+ public void firePropertyChange(String name, float oldValue, float newValue)
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ *
+ * @param name the property name.
+ * @param oldValue the old value.
+ * @param newValue the new value.
+ */
+ public void firePropertyChange(String name, double oldValue, double newValue)
+ {
+ // Overridden for performance reasons.
+ }
+
+ /**
+ * For performance reasons, this method is overridden to do nothing.
+ *
+ * @param name the property name.
+ * @param oldValue the old value.
+ * @param newValue the new value.
+ */
+ public void firePropertyChange(String name, boolean oldValue,
+ boolean newValue)
+ {
+ // Overridden for performance reasons.
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,607 @@
+/* DefaultTreeModel.java --
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.tree;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.EventListener;
+
+import javax.swing.event.EventListenerList;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.event.TreeModelListener;
+
+/**
+ * DefaultTreeModel
+ *
+ * @author Andrew Selkirk
+ */
+public class DefaultTreeModel
+ implements Serializable, TreeModel
+{
+ static final long serialVersionUID = -2621068368932566998L;
+
+ /**
+ * root
+ */
+ protected TreeNode root;
+
+ /**
+ * listenerList
+ */
+ protected EventListenerList listenerList = new EventListenerList();
+
+ /**
+ * asksAllowsChildren
+ */
+ protected boolean asksAllowsChildren;
+
+ /**
+ * Constructor DefaultTreeModel where any node can have children.
+ *
+ * @param root the tree root.
+ */
+ public DefaultTreeModel(TreeNode root)
+ {
+ this (root, false);
+ }
+
+ /**
+ * Create the DefaultTreeModel that may check if the nodes can have
+ * children or not.
+ *
+ * @param aRoot the tree root.
+ * @param asksAllowsChildren if true, each node is asked if it can have
+ * children. If false, the model does not care about this, supposing, that
+ * any node can have children.
+ */
+ public DefaultTreeModel(TreeNode aRoot, boolean asksAllowsChildren)
+ {
+ if (aRoot == null)
+ aRoot = new DefaultMutableTreeNode();
+ this.root = aRoot;
+ this.asksAllowsChildren = asksAllowsChildren;
+ }
+
+ /**
+ * writeObject
+ *
+ * @param obj the object.
+ * @exception IOException TODO
+ */
+ private void writeObject(ObjectOutputStream obj) throws IOException
+ {
+ // TODO
+ }
+
+ /**
+ * readObject
+ *
+ * @param value0 TODO
+ * @exception IOException TODO
+ * @exception ClassNotFoundException TODO
+ */
+ private void readObject(ObjectInputStream value0) throws IOException,
+ ClassNotFoundException
+ {
+ // TODO
+ }
+
+ /**
+ * asksAllowsChildren
+ *
+ * @return boolean
+ */
+ public boolean asksAllowsChildren()
+ {
+ return asksAllowsChildren;
+ }
+
+ /**
+ * setAsksAllowsChildren
+ *
+ * @param value TODO
+ */
+ public void setAsksAllowsChildren(boolean value)
+ {
+ asksAllowsChildren = value;
+ }
+
+ /**
+ * setRoot
+ *
+ * @param root the root node.
+ */
+ public void setRoot(TreeNode root)
+ {
+ this.root = root;
+ }
+
+ /**
+ * getRoot
+ *
+ * @return Object
+ */
+ public Object getRoot()
+ {
+ return root;
+ }
+
+ /**
+ * getIndexOfChild
+ *
+ * @param parent TODO
+ * @param child TODO
+ * @return int
+ */
+ public int getIndexOfChild(Object parent, Object child)
+ {
+ for (int i = 0; i < getChildCount(parent); i++)
+ {
+ if (getChild(parent, i).equals(child))
+ return i;
+ }
+ return -1;
+ }
+
+ /**
+ * getChild
+ *
+ * @param node TODO
+ * @param idx TODO
+ * @return Object
+ */
+ public Object getChild(Object node, int idx)
+ {
+ if (node instanceof TreeNode)
+ return ((TreeNode) node).getChildAt(idx);
+ else
+ return null;
+ }
+
+ /**
+ * getChildCount
+ *
+ * @param node TODO
+ * @return int
+ */
+ public int getChildCount(Object node)
+ {
+ if (node instanceof TreeNode)
+ return ((TreeNode) node).getChildCount();
+ else
+ return 0;
+ }
+
+ /**
+ * isLeaf
+ *
+ * @param node TODO
+ * @return boolean
+ */
+ public boolean isLeaf(Object node)
+ {
+ if (node instanceof TreeNode)
+ return ((TreeNode) node).isLeaf();
+ else
+ return true;
+ }
+
+ /**
+ * <p>
+ * Invoke this method if you've modified the TreeNodes upon which this model
+ * depends. The model will notify all of its listeners that the model has
+ * changed. It will fire the events, necessary to update the layout caches and
+ * repaint the tree. The tree will <i>not</i> be properly refreshed if you
+ * call the JTree.repaint instead.
+ * </p>
+ * <p>
+ * This method will refresh the information about whole tree from the root. If
+ * only part of the tree should be refreshed, it is more effective to call
+ * {@link #reload(TreeNode)}.
+ * </p>
+ */
+ public void reload()
+ {
+ // Need to duplicate the code because the root can formally be
+ // no an instance of the TreeNode.
+ int n = getChildCount(root);
+ int[] childIdx = new int[n];
+ Object[] children = new Object[n];
+
+ for (int i = 0; i < n; i++)
+ {
+ childIdx[i] = i;
+ children[i] = getChild(root, i);
+ }
+
+ fireTreeStructureChanged(this, new Object[] { root }, childIdx, children);
+ }
+
+ /**
+ * Invoke this method if you've modified the TreeNodes upon which this model
+ * depends. The model will notify all of its listeners that the model has
+ * changed. It will fire the events, necessary to update the layout caches and
+ * repaint the tree. The tree will <i>not</i> be properly refreshed if you
+ * call the JTree.repaint instead.
+ *
+ * @param node - the tree node, from which the tree nodes have changed
+ * (inclusive). If you do not know this node, call {@link #reload()}
+ * instead.
+ */
+ public void reload(TreeNode node)
+ {
+ int n = getChildCount(node);
+ int[] childIdx = new int[n];
+ Object[] children = new Object[n];
+
+ for (int i = 0; i < n; i++)
+ {
+ childIdx[i] = i;
+ children[i] = getChild(node, i);
+ }
+
+ fireTreeStructureChanged(this, getPathToRoot(node), childIdx, children);
+ }
+
+ /**
+ * Messaged when the user has altered the value for the item
+ * identified by path to newValue. If newValue signifies a truly new
+ * value the model should post a treeNodesChanged event.
+ * This sets the user object of the TreeNode identified by
+ * path and posts a node changed. If you use custom user objects
+ * in the TreeModel you're going to need to subclass this and set
+ * the user object of the changed node to something meaningful.
+ *
+ * @param path - path to the node that the user has altered
+ * @param newValue - the new value from the TreeCellEditor
+ */
+ public void valueForPathChanged(TreePath path, Object newValue)
+ {
+ Object node = path.getLastPathComponent();
+ if (node instanceof MutableTreeNode)
+ {
+ ((MutableTreeNode) node).setUserObject(newValue);
+ int[] ci = null;
+ Object[] c = null;
+ Object[] parentPath = path.getPath();
+ if (path.getPathCount() > 1)
+ {
+ Object parent = ((TreeNode) node).getParent();
+ ci = new int[1];
+ ci[0] = getIndexOfChild(parent, node);
+ node = newValue;
+ path = path.getParentPath().pathByAddingChild(node);
+ c = new Object[1];
+ c[0] = node;
+ parentPath = path.getParentPath().getPath();
+ }
+
+ fireTreeNodesChanged(this, parentPath, ci, c);
+ }
+ }
+
+ /**
+ * Invoked this to insert newChild at location index in parents children.
+ * This will then message nodesWereInserted to create the appropriate event.
+ * This is the preferred way to add children as it will create the
+ * appropriate event.
+ *
+ * @param newChild is the node to add to the parent's children
+ * @param parent is the parent of the newChild
+ * @param index is the index of the newChild
+ */
+ public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent,
+ int index)
+ {
+ newChild.setParent(parent);
+ parent.insert(newChild, index);
+ int[] childIndices = new int[1];
+ childIndices[0] = index;
+ nodesWereInserted(parent, childIndices);
+ }
+
+ /**
+ * Message this to remove node from its parent. This will message
+ * nodesWereRemoved to create the appropriate event. This is the preferred
+ * way to remove a node as it handles the event creation for you.
+ *
+ * @param node to be removed
+ */
+ public void removeNodeFromParent(MutableTreeNode node)
+ {
+ TreeNode parent = node.getParent();
+ Object[] children = new Object[1];
+ children[0] = node;
+ int[] childIndices = new int[1];
+ childIndices[0] = getIndexOfChild(parent, node);
+ node.removeFromParent();
+ nodesWereRemoved(parent, childIndices, children);
+ }
+
+ /**
+ * Invoke this method after you've changed how node is to be represented
+ * in the tree.
+ *
+ * @param node that was changed
+ */
+ public void nodeChanged(TreeNode node)
+ {
+ TreeNode parent = node.getParent();
+ int[] childIndices = new int[1];
+ childIndices[0] = getIndexOfChild(parent, node);
+ Object[] children = new Object[1];
+ children[0] = node;
+ fireTreeNodesChanged(this, getPathToRoot(node), childIndices, children);
+ }
+
+ /**
+ * Invoke this method after you've inserted some TreeNodes
+ * into node. childIndices should be the index of the new elements and must
+ * be sorted in ascending order.
+ *
+ * @param parent that had a child added to
+ * @param childIndices of the children added
+ */
+ public void nodesWereInserted(TreeNode parent, int[] childIndices)
+ {
+ Object[] children = new Object[childIndices.length];
+ for (int i = 0; i < children.length; i++)
+ children[i] = getChild(parent, childIndices[i]);
+ fireTreeNodesInserted(this, getPathToRoot(parent), childIndices, children);
+ }
+
+ /**
+ * Invoke this method after you've removed some TreeNodes from node.
+ * childIndices should be the index of the removed elements and
+ * must be sorted in ascending order. And removedChildren should be the
+ * array of the children objects that were removed.
+ *
+ * @param parent that had a child added to
+ * @param childIndices of the children added
+ * @param removedChildren are all the children removed from parent.
+ */
+ public void nodesWereRemoved(TreeNode parent, int[] childIndices,
+ Object[] removedChildren)
+ {
+ fireTreeNodesRemoved(this, getPathToRoot(parent), childIndices,
+ removedChildren);
+ }
+
+ /**
+ * Invoke this method after you've changed how the children identified by
+ * childIndices are to be represented in the tree.
+ *
+ * @param node that is the parent of the children that changed in a tree.
+ * @param childIndices are the child nodes that changed.
+ */
+ public void nodesChanged(TreeNode node, int[] childIndices)
+ {
+ Object[] children = new Object[childIndices.length];
+ for (int i = 0; i < children.length; i++)
+ children[i] = getChild(node, childIndices[i]);
+ fireTreeNodesChanged(this, getPathToRoot(node), childIndices, children);
+ }
+
+ /**
+ * Invoke this method if you've totally changed the children of node and
+ * its childrens children. This will post a treeStructureChanged event.
+ *
+ * @param node that had its children and grandchildren changed.
+ */
+ public void nodeStructureChanged(TreeNode node)
+ {
+ int n = getChildCount(root);
+ int[] childIdx = new int[n];
+ Object[] children = new Object[n];
+
+ for (int i = 0; i < n; i++)
+ {
+ childIdx[i] = i;
+ children[i] = getChild(root, i);
+ }
+
+ fireTreeStructureChanged(this, new Object[] { root }, childIdx, children);
+ }
+
+ /**
+ * Builds the parents of node up to and including the root node, where
+ * the original node is the last element in the returned array. The
+ * length of the returned array gives the node's depth in the tree.
+ *
+ * @param node - the TreeNode to get the path for
+ * @return TreeNode[] - the path from node to the root
+ */
+ public TreeNode[] getPathToRoot(TreeNode node)
+ {
+ return getPathToRoot(node, 0);
+ }
+
+ /**
+ * Builds the parents of node up to and including the root node, where
+ * the original node is the last element in the returned array. The
+ * length of the returned array gives the node's depth in the tree.
+ *
+ * @param node - the TreeNode to get the path for
+ * @param depth - an int giving the number of steps already taken
+ * towards the root (on recursive calls), used to size the returned array
+ * @return an array of TreeNodes giving the path from the root to the
+ * specified node
+ */
+ protected TreeNode[] getPathToRoot(TreeNode node, int depth)
+ {
+ if (node == null)
+ {
+ if (depth == 0)
+ return null;
+
+ return new TreeNode[depth];
+ }
+
+ TreeNode[] path = getPathToRoot(node.getParent(), depth + 1);
+ path[path.length - depth - 1] = node;
+ return path;
+ }
+
+ /**
+ * Registers a listere to the model.
+ *
+ * @param listener the listener to add
+ */
+ public void addTreeModelListener(TreeModelListener listener)
+ {
+ listenerList.add(TreeModelListener.class, listener);
+ }
+
+ /**
+ * Removes a listener from the model.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeTreeModelListener(TreeModelListener listener)
+ {
+ listenerList.remove(TreeModelListener.class, listener);
+ }
+
+ /**
+ * Returns all registered <code>TreeModelListener</code> listeners.
+ *
+ * @return an array of listeners.
+ *
+ * @since 1.4
+ */
+ public TreeModelListener[] getTreeModelListeners()
+ {
+ return (TreeModelListener[]) listenerList
+ .getListeners(TreeModelListener.class);
+ }
+
+ /**
+ * Notifies all listeners that have registered interest for notification
+ * on this event type. The event instance is lazily created using the parameters
+ * passed into the fire method.
+ *
+ * @param source the node being changed
+ * @param path the path to the root node
+ * @param childIndices the indices of the changed elements
+ * @param children the changed elements
+ */
+ protected void fireTreeNodesChanged(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeNodesChanged(event);
+ }
+
+ /**
+ * fireTreeNodesInserted
+ *
+ * @param source the node where new nodes got inserted
+ * @param path the path to the root node
+ * @param childIndices the indices of the new elements
+ * @param children the new elements
+ */
+ protected void fireTreeNodesInserted(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeNodesInserted(event);
+ }
+
+ /**
+ * fireTreeNodesRemoved
+ *
+ * @param source the node where nodes got removed-
+ * @param path the path to the root node
+ * @param childIndices the indices of the removed elements
+ * @param children the removed elements
+ */
+ protected void fireTreeNodesRemoved(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeNodesRemoved(event);
+ }
+
+ /**
+ * fireTreeStructureChanged
+ *
+ * @param source the node where the model has changed
+ * @param path the path to the root node
+ * @param childIndices the indices of the affected elements
+ * @param children the affected elements
+ */
+ protected void fireTreeStructureChanged(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeStructureChanged(event);
+ }
+
+ /**
+ * Returns the registered listeners of a given type.
+ *
+ * @param listenerType the listener type to return
+ *
+ * @return an array of listeners
+ *
+ * @since 1.3
+ */
+ public EventListener[] getListeners(Class listenerType)
+ {
+ return listenerList.getListeners(listenerType);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1023 @@
+/* DefaultTreeSelectionModel.java
+ Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.tree;
+
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.EventListener;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Vector;
+
+import javax.swing.DefaultListSelectionModel;
+import javax.swing.event.EventListenerList;
+import javax.swing.event.SwingPropertyChangeSupport;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+
+/**
+ * The implementation of the default tree selection model. The installed
+ * listeners are notified about the path and not the row changes. If you
+ * specifically need to track the row changes, register the listener for the
+ * expansion events.
+ *
+ * @author Andrew Selkirk
+ * @author Audrius Meskauskas
+ */
+public class DefaultTreeSelectionModel
+ implements Cloneable, Serializable, TreeSelectionModel
+{
+
+ /**
+ * Use serialVersionUID for interoperability.
+ */
+ static final long serialVersionUID = 3288129636638950196L;
+
+ /**
+ * The name of the selection mode property.
+ */
+ public static final String SELECTION_MODE_PROPERTY = "selectionMode";
+
+ /**
+ * Our Swing property change support.
+ */
+ protected SwingPropertyChangeSupport changeSupport;
+
+ /**
+ * The current selection.
+ */
+ protected TreePath[] selection;
+
+ /**
+ * Our TreeSelectionListeners.
+ */
+ protected EventListenerList listenerList;
+
+ /**
+ * The current RowMapper.
+ */
+ protected transient RowMapper rowMapper;
+
+ /**
+ * The current listSelectionModel.
+ */
+ protected DefaultListSelectionModel listSelectionModel;
+
+ /**
+ * The current selection mode.
+ */
+ protected int selectionMode;
+
+ /**
+ * The path that has been added last.
+ */
+ protected TreePath leadPath;
+
+ /**
+ * The index of the last added path.
+ */
+ protected int leadIndex;
+
+ /**
+ * The row of the last added path according to the RowMapper.
+ */
+ protected int leadRow = -1;
+
+ /**
+ * Constructs a new DefaultTreeSelectionModel.
+ */
+ public DefaultTreeSelectionModel()
+ {
+ setSelectionMode(DISCONTIGUOUS_TREE_SELECTION);
+ listenerList = new EventListenerList();
+ }
+
+ /**
+ * Creates a clone of this DefaultTreeSelectionModel with the same selection.
+ * The cloned instance will have the same registered listeners, the listeners
+ * themselves will not be cloned. The selection will be cloned.
+ *
+ * @exception CloneNotSupportedException should not be thrown here
+ * @return a copy of this DefaultTreeSelectionModel
+ */
+ public Object clone() throws CloneNotSupportedException
+ {
+ DefaultTreeSelectionModel cloned =
+ (DefaultTreeSelectionModel) super.clone();
+
+ // Clone the selection and the list selection model.
+ cloned.selection = (TreePath[]) selection.clone();
+ if (listSelectionModel != null)
+ cloned.listSelectionModel
+ = (DefaultListSelectionModel) listSelectionModel.clone();
+ return cloned;
+ }
+
+ /**
+ * Returns a string that shows this object's properties.
+ * The returned string lists the selected tree rows, if any.
+ *
+ * @return a string that shows this object's properties
+ */
+ public String toString()
+ {
+ if (isSelectionEmpty())
+ return "[selection empty]";
+ else
+ {
+ StringBuffer b = new StringBuffer("selected rows: [");
+ for (int i = 0; i < selection.length; i++)
+ {
+ b.append(getRow(selection[i]));
+ b.append(' ');
+ }
+ b.append(", lead " + getLeadSelectionRow());
+ return b.toString();
+ }
+ }
+
+ /**
+ * writeObject
+ *
+ * @param value0 TODO
+ * @exception IOException TODO
+ */
+ private void writeObject(ObjectOutputStream value0) throws IOException
+ {
+ // TODO
+ }
+
+ /**
+ * readObject
+ *
+ * @param value0 TODO
+ * @exception IOException TODO
+ * @exception ClassNotFoundException TODO
+ */
+ private void readObject(ObjectInputStream value0) throws IOException,
+ ClassNotFoundException
+ {
+ // TODO
+ }
+
+ /**
+ * Sets the RowMapper that should be used to map between paths and their rows.
+ *
+ * @param mapper the RowMapper to set
+ * @see RowMapper
+ */
+ public void setRowMapper(RowMapper mapper)
+ {
+ rowMapper = mapper;
+ }
+
+ /**
+ * Returns the RowMapper that is currently used to map between paths and their
+ * rows.
+ *
+ * @return the current RowMapper
+ * @see RowMapper
+ */
+ public RowMapper getRowMapper()
+ {
+ return rowMapper;
+ }
+
+ /**
+ * Sets the current selection mode. Possible values are
+ * {@link #SINGLE_TREE_SELECTION}, {@link #CONTIGUOUS_TREE_SELECTION} and
+ * {@link #DISCONTIGUOUS_TREE_SELECTION}.
+ *
+ * @param mode the selection mode to be set
+ * @see #getSelectionMode
+ * @see #SINGLE_TREE_SELECTION
+ * @see #CONTIGUOUS_TREE_SELECTION
+ * @see #DISCONTIGUOUS_TREE_SELECTION
+ */
+ public void setSelectionMode(int mode)
+ {
+ selectionMode = mode;
+ insureRowContinuity();
+ }
+
+ /**
+ * Returns the current selection mode.
+ *
+ * @return the current selection mode
+ * @see #setSelectionMode
+ * @see #SINGLE_TREE_SELECTION
+ * @see #CONTIGUOUS_TREE_SELECTION
+ * @see #DISCONTIGUOUS_TREE_SELECTION
+ */
+ public int getSelectionMode()
+ {
+ return selectionMode;
+ }
+
+ /**
+ * Sets this path as the only selection. If this changes the selection the
+ * registered TreeSelectionListeners are notified.
+ *
+ * @param path the path to set as selection
+ */
+ public void setSelectionPath(TreePath path)
+ {
+ // The most frequently only one cell in the tree is selected.
+ TreePath[] ose = selection;
+ selection = new TreePath[] { path };
+ TreePath oldLead = leadPath;
+ leadIndex = 0;
+ leadRow = getRow(path);
+ leadPath = path;
+
+ TreeSelectionEvent event;
+
+ if (ose != null && ose.length > 0)
+ {
+ // The first item in the path list is the selected path.
+ // The remaining items are unselected pathes.
+ TreePath[] changed = new TreePath[ose.length + 1];
+ boolean[] news = new boolean[changed.length];
+ news[0] = true;
+ changed[0] = path;
+ System.arraycopy(ose, 0, changed, 1, ose.length);
+ event = new TreeSelectionEvent(this, changed, news, oldLead, path);
+ }
+ else
+ {
+ event = new TreeSelectionEvent(this, path, true, oldLead, path);
+ }
+ fireValueChanged(event);
+ }
+
+ /**
+ * Get the number of the tree row for the given path.
+ *
+ * @param path the tree path
+ * @return the tree row for this path or -1 if the path is not visible.
+ */
+ int getRow(TreePath path)
+ {
+ RowMapper mapper = getRowMapper();
+
+ if (mapper instanceof AbstractLayoutCache)
+ {
+ // The absolute majority of cases, unless the TreeUI is very
+ // seriously rewritten
+ AbstractLayoutCache ama = (AbstractLayoutCache) mapper;
+ return ama.getRowForPath(path);
+ }
+ else
+ {
+ // Generic non optimized implementation.
+ int[] rows = mapper.getRowsForPaths(new TreePath[] { path });
+ if (rows.length == 0)
+ return - 1;
+ else
+ return rows[0];
+ }
+ }
+
+ /**
+ * Sets the paths as selection. This method checks for duplicates and removes
+ * them. If this changes the selection the registered TreeSelectionListeners
+ * are notified.
+ *
+ * @param paths the paths to set as selection
+ */
+ public void setSelectionPaths(TreePath[] paths)
+ {
+ // Must be called, as defined in JDK API 1.4.
+ insureUniqueness();
+ clearSelection();
+ addSelectionPaths(paths);
+ }
+
+ /**
+ * Adds a path to the list of selected paths. This method checks if the path
+ * is already selected and doesn't add the same path twice. If this changes
+ * the selection the registered TreeSelectionListeners are notified.
+ *
+ * The lead path is changed to the added path. This also happen if the
+ * passed path was already selected before.
+ *
+ * @param path the path to add to the selection
+ */
+ public void addSelectionPath(TreePath path)
+ {
+ if (! isPathSelected(path))
+ {
+ if (selectionMode == SINGLE_TREE_SELECTION || isSelectionEmpty()
+ || ! canPathBeAdded(path))
+ setSelectionPath(path);
+ else
+ {
+ TreePath[] temp = new TreePath[selection.length + 1];
+ System.arraycopy(selection, 0, temp, 0, selection.length);
+ temp[temp.length - 1] = path;
+ selection = new TreePath[temp.length];
+ System.arraycopy(temp, 0, selection, 0, temp.length);
+ }
+ }
+
+ if (path != leadPath)
+ {
+ TreePath oldLead = leadPath;
+ leadPath = path;
+ leadRow = getRow(path);
+ leadIndex = selection.length - 1;
+ fireValueChanged(new TreeSelectionEvent(this, path, true, oldLead,
+ leadPath));
+ }
+ }
+
+ /**
+ * Adds the paths to the list of selected paths. This method checks if the
+ * paths are already selected and doesn't add the same path twice. If this
+ * changes the selection the registered TreeSelectionListeners are notified.
+ *
+ * @param paths the paths to add to the selection
+ */
+ public void addSelectionPaths(TreePath[] paths)
+ {
+ // Must be called, as defined in JDK API 1.4.
+ insureUniqueness();
+
+ if (paths != null)
+ {
+ TreePath v0 = null;
+ for (int i = 0; i < paths.length; i++)
+ {
+ v0 = paths[i];
+ if (! isPathSelected(v0))
+ {
+ if (isSelectionEmpty())
+ setSelectionPath(v0);
+ else
+ {
+ TreePath[] temp = new TreePath[selection.length + 1];
+ System.arraycopy(selection, 0, temp, 0, selection.length);
+ temp[temp.length - 1] = v0;
+ selection = new TreePath[temp.length];
+ System.arraycopy(temp, 0, selection, 0, temp.length);
+ }
+ TreePath oldLead = leadPath;
+ leadPath = paths[paths.length - 1];
+ leadRow = getRow(leadPath);
+ leadIndex = selection.length - 1;
+
+ fireValueChanged(new TreeSelectionEvent(this, v0, true,
+ oldLead, leadPath));
+ }
+ }
+ insureRowContinuity();
+ }
+ }
+
+ /**
+ * Removes the path from the selection. If this changes the selection the
+ * registered TreeSelectionListeners are notified.
+ *
+ * @param path the path to remove
+ */
+ public void removeSelectionPath(TreePath path)
+ {
+ if (isSelectionEmpty())
+ return;
+
+ int index = - 1;
+ if (isPathSelected(path))
+ {
+ for (int i = 0; i < selection.length; i++)
+ {
+ if (selection[i].equals(path))
+ {
+ index = i;
+ break;
+ }
+ }
+ TreePath[] temp = new TreePath[selection.length - 1];
+ System.arraycopy(selection, 0, temp, 0, index);
+ System.arraycopy(selection, index + 1, temp, index, selection.length
+ - index - 1);
+ selection = new TreePath[temp.length];
+ System.arraycopy(temp, 0, selection, 0, temp.length);
+
+ // If the removed path was the lead path, set the lead path to null.
+ TreePath oldLead = leadPath;
+ if (path != null && leadPath != null && path.equals(leadPath))
+ leadPath = null;
+
+ fireValueChanged(new TreeSelectionEvent(this, path, false, oldLead,
+ leadPath));
+ insureRowContinuity();
+ }
+ }
+
+ /**
+ * Removes the paths from the selection. If this changes the selection the
+ * registered TreeSelectionListeners are notified.
+ *
+ * @param paths the paths to remove
+ */
+ public void removeSelectionPaths(TreePath[] paths)
+ {
+ if (isSelectionEmpty())
+ return;
+ if (paths != null)
+ {
+ int index = - 1;
+ TreePath v0 = null;
+ TreePath oldLead = leadPath;
+ for (int i = 0; i < paths.length; i++)
+ {
+ v0 = paths[i];
+ if (isPathSelected(v0))
+ {
+ for (int x = 0; x < selection.length; x++)
+ {
+ if (selection[i].equals(v0))
+ {
+ index = x;
+ break;
+ }
+ if (leadPath != null && leadPath.equals(v0))
+ leadPath = null;
+ }
+ TreePath[] temp = new TreePath[selection.length - 1];
+ System.arraycopy(selection, 0, temp, 0, index);
+ System.arraycopy(selection, index + 1, temp, index,
+ selection.length - index - 1);
+ selection = new TreePath[temp.length];
+ System.arraycopy(temp, 0, selection, 0, temp.length);
+
+ fireValueChanged(new TreeSelectionEvent(this, v0, false,
+ oldLead, leadPath));
+ }
+ }
+ insureRowContinuity();
+ }
+ }
+
+ /**
+ * Returns the first path in the selection. This is especially useful when the
+ * selectionMode is {@link #SINGLE_TREE_SELECTION}.
+ *
+ * @return the first path in the selection
+ */
+ public TreePath getSelectionPath()
+ {
+ if ((selection == null) || (selection.length == 0))
+ return null;
+ else
+ return selection[0];
+ }
+
+ /**
+ * Returns the complete selection.
+ *
+ * @return the complete selection
+ */
+ public TreePath[] getSelectionPaths()
+ {
+ return selection;
+ }
+
+ /**
+ * Returns the number of paths in the selection.
+ *
+ * @return the number of paths in the selection
+ */
+ public int getSelectionCount()
+ {
+ if (selection == null)
+ return 0;
+ else
+ return selection.length;
+ }
+
+ /**
+ * Checks if a given path is in the selection.
+ *
+ * @param path the path to check
+ * @return <code>true</code> if the path is in the selection,
+ * <code>false</code> otherwise
+ */
+ public boolean isPathSelected(TreePath path)
+ {
+ if (selection == null)
+ return false;
+
+ for (int i = 0; i < selection.length; i++)
+ {
+ if (selection[i].equals(path))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Checks if the selection is empty.
+ *
+ * @return <code>true</code> if the selection is empty, <code>false</code>
+ * otherwise
+ */
+ public boolean isSelectionEmpty()
+ {
+ return (selection == null) || (selection.length == 0);
+ }
+
+ /**
+ * Removes all paths from the selection. Fire the unselection event.
+ */
+ public void clearSelection()
+ {
+ if (! isSelectionEmpty())
+ {
+ TreeSelectionEvent event = new TreeSelectionEvent(
+ this, selection, new boolean[selection.length], leadPath, null);
+ leadPath = null;
+ selection = null;
+ fireValueChanged(event);
+ }
+ else
+ {
+ leadPath = null;
+ selection = null;
+ }
+ }
+
+ /**
+ * Adds a <code>TreeSelectionListener</code> object to this model.
+ *
+ * @param listener the listener to add
+ */
+ public void addTreeSelectionListener(TreeSelectionListener listener)
+ {
+ listenerList.add(TreeSelectionListener.class, listener);
+ }
+
+ /**
+ * Removes a <code>TreeSelectionListener</code> object from this model.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeTreeSelectionListener(TreeSelectionListener listener)
+ {
+ listenerList.remove(TreeSelectionListener.class, listener);
+ }
+
+ /**
+ * Returns all <code>TreeSelectionListener</code> added to this model.
+ *
+ * @return an array of listeners
+ * @since 1.4
+ */
+ public TreeSelectionListener[] getTreeSelectionListeners()
+ {
+ return (TreeSelectionListener[]) getListeners(TreeSelectionListener.class);
+ }
+
+ /**
+ * fireValueChanged
+ *
+ * @param event the event to fire.
+ */
+ protected void fireValueChanged(TreeSelectionEvent event)
+ {
+ TreeSelectionListener[] listeners = getTreeSelectionListeners();
+
+ for (int i = 0; i < listeners.length; ++i)
+ listeners[i].valueChanged(event);
+ }
+
+ /**
+ * Returns all added listeners of a special type.
+ *
+ * @param listenerType the listener type
+ * @return an array of listeners
+ * @since 1.3
+ */
+ public EventListener[] getListeners(Class listenerType)
+ {
+ return listenerList.getListeners(listenerType);
+ }
+
+ /**
+ * Returns the currently selected rows.
+ *
+ * @return the currently selected rows
+ */
+ public int[] getSelectionRows()
+ {
+ if (rowMapper == null)
+ return null;
+ else
+ return rowMapper.getRowsForPaths(selection);
+ }
+
+ /**
+ * Returns the smallest row index from the selection.
+ *
+ * @return the smallest row index from the selection
+ */
+ public int getMinSelectionRow()
+ {
+ if ((rowMapper == null) || (selection == null) || (selection.length == 0))
+ return - 1;
+ else
+ {
+ int[] rows = rowMapper.getRowsForPaths(selection);
+ int minRow = Integer.MAX_VALUE;
+ for (int index = 0; index < rows.length; index++)
+ minRow = Math.min(minRow, rows[index]);
+ return minRow;
+ }
+ }
+
+ /**
+ * Returns the largest row index from the selection.
+ *
+ * @return the largest row index from the selection
+ */
+ public int getMaxSelectionRow()
+ {
+ if ((rowMapper == null) || (selection == null) || (selection.length == 0))
+ return - 1;
+ else
+ {
+ int[] rows = rowMapper.getRowsForPaths(selection);
+ int maxRow = - 1;
+ for (int index = 0; index < rows.length; index++)
+ maxRow = Math.max(maxRow, rows[index]);
+ return maxRow;
+ }
+ }
+
+ /**
+ * Checks if a particular row is selected.
+ *
+ * @param row the index of the row to check
+ * @return <code>true</code> if the row is in this selection,
+ * <code>false</code> otherwise
+ * @throws NullPointerException if the row mapper is not set (can only happen
+ * if the user has plugged in the custom incorrect TreeUI
+ * implementation.
+ */
+ public boolean isRowSelected(int row)
+ {
+ // Return false if nothing is selected.
+ if (isSelectionEmpty())
+ return false;
+
+ RowMapper mapper = getRowMapper();
+
+ if (mapper instanceof AbstractLayoutCache)
+ {
+ // The absolute majority of cases, unless the TreeUI is very
+ // seriously rewritten
+ AbstractLayoutCache ama = (AbstractLayoutCache) mapper;
+ TreePath path = ama.getPathForRow(row);
+ return isPathSelected(path);
+ }
+ else
+ {
+ // Generic non optimized implementation.
+ int[] rows = mapper.getRowsForPaths(selection);
+ for (int i = 0; i < rows.length; i++)
+ if (rows[i] == row)
+ return true;
+ return false;
+ }
+ }
+
+ /**
+ * Updates the mappings from TreePaths to row indices.
+ */
+ public void resetRowSelection()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * getLeadSelectionRow
+ *
+ * @return int
+ */
+ public int getLeadSelectionRow()
+ {
+ return leadRow;
+ }
+
+ /**
+ * getLeadSelectionPath
+ *
+ * @return TreePath
+ */
+ public TreePath getLeadSelectionPath()
+ {
+ return leadPath;
+ }
+
+ /**
+ * Adds a <code>PropertyChangeListener</code> object to this model.
+ *
+ * @param listener the listener to add.
+ */
+ public void addPropertyChangeListener(PropertyChangeListener listener)
+ {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ /**
+ * Removes a <code>PropertyChangeListener</code> object from this model.
+ *
+ * @param listener the listener to remove.
+ */
+ public void removePropertyChangeListener(PropertyChangeListener listener)
+ {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * Returns all added <code>PropertyChangeListener</code> objects.
+ *
+ * @return an array of listeners.
+ * @since 1.4
+ */
+ public PropertyChangeListener[] getPropertyChangeListeners()
+ {
+ return changeSupport.getPropertyChangeListeners();
+ }
+
+ /**
+ * Makes sure the currently selected paths are valid according to the current
+ * selectionMode. If the selectionMode is set to
+ * {@link #CONTIGUOUS_TREE_SELECTION} and the selection isn't contiguous then
+ * the selection is reset to the first set of contguous paths. If the
+ * selectionMode is set to {@link #SINGLE_TREE_SELECTION} and the selection
+ * has more than one path, the selection is reset to the contain only the
+ * first path.
+ */
+ protected void insureRowContinuity()
+ {
+ if (selection == null || selection.length < 2)
+ return;
+ else if (selectionMode == CONTIGUOUS_TREE_SELECTION)
+ {
+ if (rowMapper == null)
+ // This is the best we can do without the row mapper:
+ selectOne();
+ else
+ {
+ int[] rows = rowMapper.getRowsForPaths(selection);
+ Arrays.sort(rows);
+ int i;
+ for (i = 1; i < rows.length; i++)
+ {
+ if (rows[i - 1] != rows[i] - 1)
+ // Break if no longer continuous.
+ break;
+ }
+
+ if (i < rows.length)
+ {
+ TreePath[] ns = new TreePath[i];
+ for (int j = 0; j < ns.length; j++)
+ ns[i] = getPath(j);
+ setSelectionPaths(ns);
+ }
+ }
+ }
+ else if (selectionMode == SINGLE_TREE_SELECTION)
+ selectOne();
+ }
+
+ /**
+ * Keep only one (normally last or leading) path in the selection.
+ */
+ private void selectOne()
+ {
+ if (leadIndex > 0 && leadIndex < selection.length)
+ setSelectionPath(selection[leadIndex]);
+ else
+ setSelectionPath(selection[selection.length - 1]);
+ }
+
+ /**
+ * Get path for the given row that must be in the current selection.
+ */
+ private TreePath getPath(int row)
+ {
+ if (rowMapper instanceof AbstractLayoutCache)
+ return ((AbstractLayoutCache) rowMapper).getPathForRow(row);
+ else
+ {
+ int[] rows = rowMapper.getRowsForPaths(selection);
+ for (int i = 0; i < rows.length; i++)
+ if (rows[i] == row)
+ return selection[i];
+ }
+ throw new InternalError(row + " not in selection");
+ }
+
+ /**
+ * Returns <code>true</code> if the paths are contiguous (take subsequent
+ * rows in the diplayed tree view. The method returns <code>true</code> if
+ * we have no RowMapper assigned.
+ *
+ * @param paths the paths to check for continuity
+ * @return <code>true</code> if the paths are contiguous or we have no
+ * RowMapper assigned
+ */
+ protected boolean arePathsContiguous(TreePath[] paths)
+ {
+ if (rowMapper == null || paths.length < 2)
+ return true;
+
+ int[] rows = rowMapper.getRowsForPaths(paths);
+
+ // The patches may not be sorted.
+ Arrays.sort(rows);
+
+ for (int i = 1; i < rows.length; i++)
+ {
+ if (rows[i - 1] != rows[i] - 1)
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Checks if the paths can be added. This returns <code>true</code> if:
+ * <ul>
+ * <li><code>paths</code> is <code>null</code> or empty</li>
+ * <li>we have no RowMapper assigned</li>
+ * <li>nothing is currently selected</li>
+ * <li>selectionMode is {@link #DISCONTIGUOUS_TREE_SELECTION}</li>
+ * <li>adding the paths to the selection still results in a contiguous set of
+ * paths</li>
+ *
+ * @param paths the paths to check
+ * @return <code>true</code> if the paths can be added with respect to the
+ * selectionMode
+ */
+ protected boolean canPathsBeAdded(TreePath[] paths)
+ {
+ if (rowMapper == null || isSelectionEmpty()
+ || selectionMode == DISCONTIGUOUS_TREE_SELECTION)
+ return true;
+
+ TreePath [] all = new TreePath[paths.length + selection.length];
+ System.arraycopy(paths, 0, all, 0, paths.length);
+ System.arraycopy(selection, 0, all, paths.length, selection.length);
+
+ return arePathsContiguous(all);
+ }
+
+ /**
+ * Checks if the single path can be added to selection.
+ */
+ private boolean canPathBeAdded(TreePath path)
+ {
+ if (rowMapper == null || isSelectionEmpty()
+ || selectionMode == DISCONTIGUOUS_TREE_SELECTION)
+ return true;
+
+ TreePath[] all = new TreePath[selection.length + 1];
+ System.arraycopy(selection, 0, all, 0, selection.length);
+ all[all.length - 1] = path;
+
+ return arePathsContiguous(all);
+ }
+
+ /**
+ * Checks if the paths can be removed without breaking the continuity of the
+ * selection according to selectionMode.
+ *
+ * @param paths the paths to check
+ * @return <code>true</code> if the paths can be removed with respect to the
+ * selectionMode
+ */
+ protected boolean canPathsBeRemoved(TreePath[] paths)
+ {
+ if (rowMapper == null || isSelectionEmpty()
+ || selectionMode == DISCONTIGUOUS_TREE_SELECTION)
+ return true;
+
+ HashSet set = new HashSet();
+ for (int i = 0; i < selection.length; i++)
+ set.add(selection[i]);
+
+ for (int i = 0; i < paths.length; i++)
+ set.remove(paths[i]);
+
+ TreePath[] remaining = new TreePath[set.size()];
+ Iterator iter = set.iterator();
+
+ for (int i = 0; i < remaining.length; i++)
+ remaining[i] = (TreePath) iter.next();
+
+ return arePathsContiguous(remaining);
+ }
+
+ /**
+ * Notify the installed listeners that the given patches have changed. This
+ * method will call listeners if invoked, but it is not called from the
+ * implementation of this class.
+ *
+ * @param vPathes the vector of the changed patches
+ * @param oldLeadSelection the old selection index
+ */
+ protected void notifyPathChange(Vector vPathes, TreePath oldLeadSelection)
+ {
+ TreePath[] pathes = new TreePath[vPathes.size()];
+ for (int i = 0; i < pathes.length; i++)
+ pathes[i] = (TreePath) vPathes.get(i);
+
+ boolean[] news = new boolean[pathes.length];
+ for (int i = 0; i < news.length; i++)
+ news[i] = isPathSelected(pathes[i]);
+
+ TreeSelectionEvent event = new TreeSelectionEvent(this, pathes, news,
+ oldLeadSelection,
+ leadPath);
+ fireValueChanged(event);
+ }
+
+ /**
+ * Updates the lead selection row number after changing the lead selection
+ * path.
+ */
+ protected void updateLeadIndex()
+ {
+ if (isSelectionEmpty())
+ {
+ leadRow = leadIndex = - 1;
+ }
+ else
+ {
+ leadRow = getRow(leadPath);
+ for (int i = 0; i < selection.length; i++)
+ {
+ if (selection[i].equals(leadPath))
+ {
+ leadIndex = i;
+ break;
+ }
+ }
+ leadIndex = leadRow;
+ }
+ }
+
+ /**
+ * This method exists due historical reasons and returns without action
+ * (unless overridden). For compatibility with the applications that override
+ * it, it is still called from the {@link #setSelectionPaths(TreePath[])} and
+ * {@link #addSelectionPaths(TreePath[])}.
+ */
+ protected void insureUniqueness()
+ {
+ // Following the API 1.4, the method should return without action.
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/ExpandVetoException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/ExpandVetoException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/ExpandVetoException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/ExpandVetoException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,76 @@
+/* ExpandVetoException.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.tree;
+
+import javax.swing.event.TreeExpansionEvent;
+
+/**
+ * ExpandVetoException
+ * @author Andrew Selkirk
+ */
+public class ExpandVetoException extends Exception
+{
+
+ /**
+ * event
+ */
+ protected TreeExpansionEvent event;
+
+
+ /**
+ * Constructor ExpandVetoException
+ * @param event Tree Expansion Event
+ */
+ public ExpandVetoException(TreeExpansionEvent event)
+ {
+ super();
+ this.event = event;
+ }
+
+ /**
+ * Constructor ExpandVetoException
+ * @param event Tree Expansion Event
+ * @param message Message
+ */
+ public ExpandVetoException(TreeExpansionEvent event, String message)
+ {
+ super(message);
+ this.event = event;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,628 @@
+/* FixedHeightLayoutCache.java -- Fixed cell height tree layout cache
+Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.tree;
+
+import gnu.javax.swing.tree.GnuPath;
+
+import java.awt.Rectangle;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.swing.event.TreeModelEvent;
+
+
+/**
+ * The fixed height tree layout. This class assumes that all cells in the tree
+ * have the same fixed height. This may be not the case, for instance, if leaves
+ * and branches have different height, of if the tree rows may have arbitrary
+ * variable height. This class will also work if the NodeDimensions are not
+ * set.
+ *
+ * @author Audrius Meskauskas
+ * @author Andrew Selkirk
+ */
+public class FixedHeightLayoutCache
+ extends VariableHeightLayoutCache
+{
+ /**
+ * The cached node record.
+ */
+ class NodeRecord
+ {
+ NodeRecord(int aRow, int aDepth, Object aNode, Object aParent)
+ {
+ row = aRow;
+ depth = aDepth;
+ parent = aParent;
+ node = aNode;
+
+ isExpanded = expanded.contains(aNode);
+ }
+
+ /**
+ * The row, where the tree node is displayed.
+ */
+ final int row;
+
+ /**
+ * The nesting depth
+ */
+ final int depth;
+
+ /**
+ * The parent of the given node, null for the root node.
+ */
+ final Object parent;
+
+ /**
+ * This node.
+ */
+ final Object node;
+
+ /**
+ * True for the expanded nodes. The value is calculated in constructor.
+ * Using this field saves one hashtable access operation.
+ */
+ final boolean isExpanded;
+
+ /**
+ * The cached bounds of the tree row.
+ */
+ Rectangle bounds;
+
+ /**
+ * The path from the tree top to the given node (computed under first
+ * demand)
+ */
+ private TreePath path;
+
+ /**
+ * Get the path for this node. The derived class is returned,
+ * making check for the last child of some parent easier.
+ */
+ TreePath getPath()
+ {
+ if (path == null)
+ {
+ boolean lastChild = false;
+ if (parent != null)
+ {
+ int nc = treeModel.getChildCount(parent);
+ if (nc > 0)
+ {
+ int n = treeModel.getIndexOfChild(parent, node);
+ if (n == nc - 1)
+ lastChild = true;
+ }
+ }
+
+ LinkedList lpath = new LinkedList();
+ NodeRecord rp = this;
+ while (rp != null)
+ {
+ lpath.addFirst(rp.node);
+ if (rp.parent != null)
+ {
+ Object parent = rp.parent;
+ rp = (NodeRecord) nodes.get(parent);
+ // Add the root node, even if it is not visible.
+ if (rp == null)
+ lpath.addFirst(parent);
+ }
+ else
+ rp = null;
+ }
+ path = new GnuPath(lpath.toArray(), lastChild);
+ }
+ return path;
+ }
+
+ /**
+ * Get the rectangle bounds (compute, if required).
+ */
+ Rectangle getBounds()
+ {
+ // This method may be called in the context when the tree rectangle is
+ // not known. To work around this, it is assumed near infinitely large.
+ if (bounds == null)
+ bounds = getNodeDimensions(node, row, depth, isExpanded,
+ new Rectangle());
+ return bounds;
+ }
+ }
+
+ /**
+ * The set of all expanded tree nodes.
+ */
+ Set expanded = new HashSet();
+
+ /**
+ * Maps nodes to the row numbers.
+ */
+ Hashtable nodes = new Hashtable();
+
+ /**
+ * Maps row numbers to nodes.
+ */
+ Hashtable row2node = new Hashtable();
+
+ /**
+ * If true, the row map must be recomputed before using.
+ */
+ boolean dirty;
+
+ /**
+ * The cumulative height of all rows.
+ */
+ int totalHeight;
+
+ /**
+ * The maximal width.
+ */
+ int maximalWidth;
+
+ /**
+ * Creates the unitialised instance. Before using the class, the row height
+ * must be set with the {@link #setRowHeight(int)} and the model must be set
+ * with {@link #setModel(TreeModel)}. The node dimensions may not be set.
+ */
+ public FixedHeightLayoutCache()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Get the total number of rows in the tree. Every displayed node occupies the
+ * single row. The root node row is included if the root node is set as
+ * visible (false by default).
+ *
+ * @return int the number of the displayed rows.
+ */
+ public int getRowCount()
+ {
+ if (dirty) update();
+ return row2node.size();
+ }
+
+ /**
+ * Refresh the row map.
+ */
+ private final void update()
+ {
+ nodes.clear();
+ row2node.clear();
+
+ totalHeight = maximalWidth = 0;
+
+ Object root = treeModel.getRoot();
+
+ if (rootVisible)
+ {
+ countRows(root, null, 0);
+ }
+ else
+ {
+ int sc = treeModel.getChildCount(root);
+ for (int i = 0; i < sc; i++)
+ {
+ Object child = treeModel.getChild(root, i);
+ countRows(child, root, 0);
+ }
+ }
+ dirty = false;
+ }
+
+ /**
+ * Recursively counts all rows in the tree.
+ */
+ private final void countRows(Object node, Object parent, int depth)
+ {
+ Integer n = new Integer(row2node.size());
+ row2node.put(n, node);
+
+ NodeRecord nr = new NodeRecord(n.intValue(), depth, node, parent);
+ nodes.put(node, nr);
+
+ // For expanded nodes and for the root node.
+ if (expanded.contains(node))
+ {
+ int sc = treeModel.getChildCount(node);
+ int deeper = depth + 1;
+ for (int i = 0; i < sc; i++)
+ {
+ Object child = treeModel.getChild(node, i);
+ countRows(child, node, deeper);
+ }
+ }
+ }
+
+ /**
+ * Discard the bound information for the given path.
+ *
+ * @param path the path, for that the bound information must be recomputed.
+ */
+ public void invalidatePathBounds(TreePath path)
+ {
+ NodeRecord r = (NodeRecord) nodes.get(path.getLastPathComponent());
+ if (r != null)
+ r.bounds = null;
+ }
+
+ /**
+ * Mark all cached information as invalid.
+ */
+ public void invalidateSizes()
+ {
+ dirty = true;
+ }
+
+ /**
+ * Set the expanded state of the given path. The expansion states must be
+ * always updated when expanding and colapsing the tree nodes. Otherwise
+ * other methods will not work correctly after the nodes are collapsed or
+ * expanded.
+ *
+ * @param path the tree path, for that the state is being set.
+ * @param isExpanded the expanded state of the given path.
+ */
+ public void setExpandedState(TreePath path, boolean isExpanded)
+ {
+ if (isExpanded)
+ expanded.add(path.getLastPathComponent());
+ else
+ expanded.remove(path.getLastPathComponent());
+
+ dirty = true;
+ }
+
+ /**
+ * Get the expanded state for the given tree path.
+ *
+ * @return true if the given path is expanded, false otherwise.
+ */
+ public boolean isExpanded(TreePath path)
+ {
+ return expanded.contains(path.getLastPathComponent());
+ }
+
+ /**
+ * Get bounds for the given tree path.
+ *
+ * @param path the tree path
+ * @param rect the rectangle that will be reused to return the result.
+ * @return Rectangle the bounds of the last line, defined by the given path.
+ */
+ public Rectangle getBounds(TreePath path, Rectangle rect)
+ {
+ if (path == null)
+ return null;
+ if (dirty)
+ update();
+ Object last = path.getLastPathComponent();
+ NodeRecord r = (NodeRecord) nodes.get(last);
+ if (r == null)
+ // This node is not visible.
+ {
+ rect.x = rect.y = rect.width = rect.height = 0;
+ }
+ else
+ {
+ if (r.bounds == null)
+ {
+ Rectangle dim = getNodeDimensions(last, r.row, r.depth,
+ r.isExpanded, rect);
+ r.bounds = dim;
+ }
+
+ rect.setRect(r.bounds);
+ }
+ return rect;
+ }
+
+ /**
+ * Get the path, the last element of that is displayed in the given row.
+ *
+ * @param row the row
+ * @return TreePath the path
+ */
+ public TreePath getPathForRow(int row)
+ {
+ if (dirty)
+ update();
+ Object last = row2node.get(new Integer(row));
+ if (last == null)
+ return null;
+ else
+ {
+ NodeRecord r = (NodeRecord) nodes.get(last);
+ return r.getPath();
+ }
+ }
+
+ /**
+ * Get the row, displaying the last node of the given path.
+ *
+ * @param path the path
+ * @return int the row number or -1 if the end of the path is not visible.
+ */
+ public int getRowForPath(TreePath path)
+ {
+ if (path == null)
+ return -1;
+
+ if (dirty) update();
+
+ NodeRecord r = (NodeRecord) nodes.get(path.getLastPathComponent());
+ if (r == null)
+ return - 1;
+ else
+ return r.row;
+ }
+
+ /**
+ * Get the path, closest to the given point.
+ *
+ * @param x the point x coordinate
+ * @param y the point y coordinate
+ * @return the tree path, closest to the the given point
+ */
+ public TreePath getPathClosestTo(int x, int y)
+ {
+ if (dirty)
+ update();
+
+ // As the rows have arbitrary height, we need to iterate.
+ NodeRecord best = null;
+ NodeRecord r;
+ Enumeration en = nodes.elements();
+
+ int dist = Integer.MAX_VALUE;
+
+ while (en.hasMoreElements() && dist > 0)
+ {
+ r = (NodeRecord) en.nextElement();
+ if (best == null)
+ {
+ best = r;
+ dist = distance(r.getBounds(), x, y);
+ }
+ else
+ {
+ int rr = distance(r.getBounds(), x, y);
+ if (rr < dist)
+ {
+ best = r;
+ dist = rr;
+ }
+ }
+ }
+
+ if (best == null)
+ return null;
+ else
+ return best.getPath();
+ }
+
+ /**
+ * Get the closest distance from this point till the given rectangle. Only
+ * vertical distance is taken into consideration.
+ */
+ int distance(Rectangle r, int x, int y)
+ {
+ if (y < r.y)
+ return r.y - y;
+ else if (y > r.y + r.height)
+ return y - (r.y + r.height);
+ else
+ return 0;
+ }
+
+ /**
+ * Get the number of the visible childs for the given tree path. If the node
+ * is not expanded, 0 is returned. Otherwise, the number of children is
+ * obtained from the model as the number of children for the last path
+ * component.
+ *
+ * @param path the tree path
+ * @return int the number of the visible childs (for row).
+ */
+ public int getVisibleChildCount(TreePath path)
+ {
+ if (isExpanded(path))
+ return 0;
+ else
+ return treeModel.getChildCount(path.getLastPathComponent());
+ }
+
+ /**
+ * Get the enumeration over all visible pathes that start from the given
+ * parent path.
+ *
+ * @param parentPath the parent path
+ * @return the enumeration over pathes
+ */
+ public Enumeration getVisiblePathsFrom(TreePath parentPath)
+ {
+ if (dirty)
+ update();
+ Vector p = new Vector(parentPath.getPathCount());
+ Object node;
+ NodeRecord nr;
+
+ for (int i = 0; i < parentPath.getPathCount(); i++)
+ {
+ node = parentPath.getPathComponent(i);
+ nr = (NodeRecord) nodes.get(node);
+ if (nr.row >= 0)
+ p.add(node);
+ }
+ return p.elements();
+ }
+
+ /**
+ * Return the expansion state of the given tree path. The expansion state
+ * must be previously set with the
+ * {@link #setExpandedState(TreePath, boolean)}
+ *
+ * @param path the path being checked
+ * @return true if the last node of the path is expanded, false otherwise.
+ */
+ public boolean getExpandedState(TreePath path)
+ {
+ return expanded.contains(path.getLastPathComponent());
+ }
+
+ /**
+ * The listener method, called when the tree nodes are changed.
+ *
+ * @param event the change event
+ */
+ public void treeNodesChanged(TreeModelEvent event)
+ {
+ dirty = true;
+ }
+
+ /**
+ * The listener method, called when the tree nodes are inserted.
+ *
+ * @param event the change event
+ */
+ public void treeNodesInserted(TreeModelEvent event)
+ {
+ dirty = true;
+ }
+
+ /**
+ * The listener method, called when the tree nodes are removed.
+ *
+ * @param event the change event
+ */
+ public void treeNodesRemoved(TreeModelEvent event)
+ {
+ dirty = true;
+ }
+
+ /**
+ * Called when the tree structure has been changed.
+ *
+ * @param event the change event
+ */
+ public void treeStructureChanged(TreeModelEvent event)
+ {
+ dirty = true;
+ }
+
+ /**
+ * Set the tree model that will provide the data.
+ */
+ public void setModel(TreeModel newModel)
+ {
+ treeModel = newModel;
+ // The root node is expanded by default.
+ expanded.add(treeModel.getRoot());
+ dirty = true;
+ }
+
+ /**
+ * Inform the instance if the tree root node is visible. If this method
+ * is not called, it is assumed that the tree root node is not visible.
+ *
+ * @param visible true if the tree root node is visible, false
+ * otherwise.
+ */
+ public void setRootVisible(boolean visible)
+ {
+ rootVisible = visible;
+ dirty = true;
+ }
+
+ /**
+ * Get the sum of heights for all rows.
+ */
+ public int getPreferredHeight()
+ {
+ if (dirty)
+ update();
+ totalHeight = 0;
+ Enumeration en = nodes.elements();
+ while (en.hasMoreElements())
+ {
+ NodeRecord nr = (NodeRecord) en.nextElement();
+ Rectangle r = nr.getBounds();
+ totalHeight += r.height;
+ }
+ return totalHeight;
+ }
+
+ /**
+ * Get the maximal width.
+ */
+ public int getPreferredWidth(Rectangle value)
+ {
+ if (dirty)
+ update();
+
+ maximalWidth = 0;
+ Enumeration en = nodes.elements();
+ while (en.hasMoreElements())
+ {
+ NodeRecord nr = (NodeRecord) en.nextElement();
+ Rectangle r = nr.getBounds();
+ if (r.x + r.width > maximalWidth)
+ maximalWidth = r.x + r.width;
+ }
+ return maximalWidth;
+ }
+
+ /**
+ * Returns true if this layout supposes that all rows have the fixed
+ * height.
+ *
+ * @return boolean true if all rows in the tree must have the fixed
+ * height (true by default).
+ */
+ protected boolean isFixedRowHeight()
+ {
+ return true;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/MutableTreeNode.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/MutableTreeNode.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/MutableTreeNode.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/MutableTreeNode.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,104 @@
+/* MutableTreeNode.java --
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.tree;
+
+/**
+ * MutableTreeNode public interface
+
+ * @author Andrew Selkirk
+ */
+public interface MutableTreeNode extends TreeNode
+{
+ /**
+ * Inserts a node as child at a given index.
+ *
+ * @param child the note to insert
+ * @param index the index
+ *
+ * @see #remove(int)
+ * @see #remove(MutableTreeNode)
+ * @see #setParent(MutableTreeNode)
+ */
+ void insert(MutableTreeNode child, int index);
+
+ /**
+ * Removes the child node a given index.
+ *
+ * @param index the index
+ *
+ * @see #insert(MutableTreeNode,int)
+ * @see #remove(MutableTreeNode)
+ * @see #removeFromParent()
+ */
+ void remove(int index);
+
+ /**
+ * Removes a given child node.
+ *
+ * @param node the node to remove
+ *
+ * @see #insert(MutableTreeNode,int)
+ * @see #remove(int)
+ * @see #removeFromParent()
+ */
+ void remove(MutableTreeNode node);
+
+ /**
+ * Sets a user object, the data represented by the node.
+ *
+ * @param object the data
+ */
+ void setUserObject(Object object);
+
+ /**
+ * Removes this node from its parent.
+ *
+ * @see #remove(int)
+ * @see #remove(MutableTreeNode)
+ */
+ void removeFromParent();
+
+ /**
+ * Sets the parent of the node.
+ *
+ * @param parent the parent
+ *
+ * @see #insert(MutableTreeNode,int)
+ */
+ void setParent(MutableTreeNode parent);
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/RowMapper.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/RowMapper.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/RowMapper.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/RowMapper.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,54 @@
+/* RowMapper.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.tree;
+
+/**
+ * RowMapper public interface
+ * @author Andrew Selkirk
+ */
+public interface RowMapper
+{
+
+ /**
+ * getRowsForPaths
+ * @param path TreePath
+ * @return TODO
+ */
+ int[] getRowsForPaths(TreePath[] path);
+
+}
\ No newline at end of file
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeCellEditor.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeCellEditor.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeCellEditor.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeCellEditor.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,71 @@
+/* TreeCellEditor.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.tree;
+
+import java.awt.Component;
+
+import javax.swing.CellEditor;
+import javax.swing.JTree;
+
+/**
+ * A <code>TreeCellEditor</code> is used by the {@link JTree} component to
+ * edit individual tree elements (nodes).
+ *
+ * @author Andrew Selkirk
+ */
+public interface TreeCellEditor extends CellEditor
+{
+ /**
+ * Returns a component that has been configured to edit one element (or
+ * node) in a {@link JTree} component. The arguments to this method are used
+ * to pass in the value and state of the element to be edited.
+ *
+ * @param tree the tree.
+ * @param value the value to render.
+ * @param isSelected is the tree element selected?
+ * @param expanded is the tree element expanded?
+ * @param leaf is the tree element a leaf node?
+ * @param row the row index.
+ *
+ * @return A component that is configured for editing the tree element.
+ */
+ Component getTreeCellEditorComponent(JTree tree, Object value,
+ boolean isSelected, boolean expanded,
+ boolean leaf, int row);
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeCellRenderer.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeCellRenderer.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeCellRenderer.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeCellRenderer.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,73 @@
+/* TreeCellRenderer.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.tree;
+
+import java.awt.Component;
+
+import javax.swing.JTree;
+
+/**
+ * A <code>TreeCellRenderer</code> is used by the {@link JTree} component to
+ * paint individual tree elements (nodes).
+ *
+ * @author Andrew Selkirk
+ */
+public interface TreeCellRenderer
+{
+ /**
+ * Returns a component that has been configured to display one element (or
+ * node) in a {@link JTree} component. The arguments to this method are used
+ * to pass in the value and state of the element to be rendered.
+ *
+ * @param tree the tree.
+ * @param value the value to render.
+ * @param selected is the tree element selected?
+ * @param expanded is the tree element expanded?
+ * @param leaf is the tree element a leaf node?
+ * @param row the row index.
+ * @param hasFocus does the tree element have the focus?
+ *
+ * @return A component that is configured for rendering the tree element.
+ */
+ Component getTreeCellRendererComponent(JTree tree, Object value,
+ boolean selected, boolean expanded,
+ boolean leaf, int row,
+ boolean hasFocus);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,105 @@
+/* TreeModel.java --
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.tree;
+
+import javax.swing.event.TreeModelListener;
+
+/**
+ * TreeModel public interface
+ * @author Andrew Selkirk
+ */
+public interface TreeModel
+{
+ /**
+ * getRoot
+ * @returns Object
+ */
+ Object getRoot();
+
+ /**
+ * getChild
+ * @param parent TODO
+ * @param index TODO
+ * @returns Object
+ */
+ Object getChild(Object parent, int index);
+
+ /**
+ * getChildCount
+ * @param parent TODO
+ * @returns int
+ */
+ int getChildCount(Object parent);
+
+ /**
+ * isLeaf
+ * @param node TODO
+ * @returns boolean
+ */
+ boolean isLeaf(Object node);
+
+ /**
+ * valueForPathChanged
+ * @param path TODO
+ * @param newvalue TODO
+ */
+ void valueForPathChanged(TreePath path, Object newvalue);
+
+ /**
+ * getIndexOfChild
+ * @param parent TODO
+ * @param child TODO
+ * @returns int
+ */
+ int getIndexOfChild(Object parent, Object child);
+
+ /**
+ * addTreeModelListener
+ * @param listener TODO
+ */
+ void addTreeModelListener(TreeModelListener listener);
+
+ /**
+ * removeTreeModelListener
+ * @param listener TODO
+ */
+ void removeTreeModelListener(TreeModelListener listener);
+
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeNode.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeNode.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeNode.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeNode.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,113 @@
+/* TreeNode.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.tree;
+
+import java.util.Enumeration;
+
+/**
+ * A tree node.
+ *
+ * @author Andrew Selkirk
+ */
+public interface TreeNode
+{
+
+ /**
+ * Returns the parent node for this tree node, or <code>null</code> if this
+ * node has no parent.
+ *
+ * @return The parent node (possibly <code>null</code>).
+ */
+ TreeNode getParent();
+
+ /**
+ * Returns the index of the specified child node, or -1 if the node is not
+ * in fact a child of this node.
+ *
+ * @param node the node (<code>null</code> not permitted).
+ *
+ * @return The index of the specified child node, or -1.
+ *
+ * @throws IllegalArgumentException if <code>node</code> is <code>null</code>.
+ */
+ int getIndex(TreeNode node);
+
+ /**
+ * Returns the child node at the given index.
+ *
+ * @param index the index (in the range <code>0</code> to
+ * <code>getChildCount() - 1</code>).
+ *
+ * @return The child node at the given index.
+ */
+ TreeNode getChildAt(int index);
+
+ /**
+ * Returns the number of children for this node.
+ *
+ * @return The number of children for this node.
+ */
+ int getChildCount();
+
+ /**
+ * Returns <code>true</code> if this node allows children, and
+ * <code>false</code> otherwise.
+ *
+ * @return A boolean.
+ */
+ boolean getAllowsChildren();
+
+ /**
+ * Returns <code>true</code> if this node is a leaf node, and
+ * <code>false</code> otherwise.
+ *
+ * @return A boolean.
+ */
+ boolean isLeaf();
+
+ /**
+ * Returns an enumeration of the children of this node, or an empty
+ * enumeration if this node has no children.
+ *
+ * @return An enumeration of the children of this node.
+ */
+ Enumeration children();
+
+}
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreePath.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreePath.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreePath.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreePath.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,312 @@
+/* TreePath.java --
+ Copyright (C) 2002, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.tree;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+/**
+ * A <code>TreePath</code> represents a sequence of tree elements that form
+ * a path starting from the root of a tree. A tree element can be represented
+ * by any {@link Object}.
+ *
+ * @author Andrew Selkirk
+ */
+public class TreePath implements Serializable
+{
+ static final long serialVersionUID = 4380036194768077479L;
+
+ /**
+ * The actual patch. The {@link DefaultTreeSelectionModel#clone()}
+ * assumes that the TreePath is immutable, so it is marked final here.
+ */
+ private final Object[] path;
+
+ /**
+ * The parent path (to be reused).
+ */
+ private transient TreePath parentPath;
+
+
+ /**
+ * Creates a path from the list of objects representing tree elements. The
+ * incoming array is copied so that subsequent changes do not affect this
+ * tree path.
+ *
+ * @param path the elements in the path (<code>null</code> not permitted).
+ *
+ * @throws IllegalArgumentException if <code>path</code> is <code>null</code>.
+ */
+ public TreePath(Object[] path)
+ {
+ if (path == null)
+ throw new IllegalArgumentException("Null 'path' not permitted.");
+ this.path = new Object[path.length];
+ System.arraycopy(path, 0, this.path, 0, path.length);
+ }
+
+ /**
+ * Creates a new path from a single element.
+ *
+ * @param element the element (<code>null</code> not permitted).
+ *
+ * @throws IllegalArgumentException if <code>element</code> is
+ * <code>null</code>.
+ */
+ public TreePath(Object element)
+ {
+ path = new Object[1];
+ path[0] = element;
+ }
+
+ /**
+ * Creates a new tree path by adding the specified <code>element</code> to
+ * the <code>path</code>.
+ *
+ * @param path a tree path.
+ * @param element a path element.
+ */
+ protected TreePath(TreePath path, Object element)
+ {
+ if (element == null)
+ throw new NullPointerException("Null 'element' argument.");
+ Object[] treepath = path.getPath();
+
+ // Create Tree Path
+ this.path = new Object[treepath.length + 1];
+ System.arraycopy(treepath, 0, this.path, 0, treepath.length);
+ this.path[treepath.length] = element;
+ }
+
+ /**
+ * Creates a new tree path using the first <code>length</code> elements
+ * from the given array.
+ *
+ * @param path the path elements.
+ * @param length the path length.
+ */
+ protected TreePath(Object[] path, int length)
+ {
+ // Create Path
+ this.path = new Object[length];
+ System.arraycopy(path, 0, this.path, 0, length);
+ }
+
+ /**
+ * Default constructor.
+ */
+ protected TreePath()
+ {
+ path = new Object[0];
+ }
+
+
+ /**
+ * Returns a hashcode for the path.
+ *
+ * @return A hashcode.
+ */
+ public int hashCode()
+ {
+ return getLastPathComponent().hashCode();
+ }
+
+ /**
+ * Tests this path for equality with an arbitrary object. An object is
+ * considered equal to this path if and only if:
+ * <ul>
+ * <li>the object is not <code>null</code>;</li>
+ * <li>the object is an instanceof {@link TreePath};</li>
+ * <li>the object contains the same elements in the same order as this
+ * {@link TreePath};</li>
+ * </ul>
+ *
+ * @param object the object (<code>null</code> permitted).
+ *
+ * @return <code>true</code> if <code>obj</code> is equal to this tree path,
+ * and <code>false</code> otherwise.
+ */
+ public boolean equals(Object object)
+ {
+ Object[] treepath;
+ int index;
+
+ if (object instanceof TreePath)
+ {
+ treepath = ((TreePath) object).getPath();
+ if (treepath.length != path.length)
+ return false;
+ for (index = 0; index < path.length; index++)
+ {
+ if (!path[index].equals(treepath[index]))
+ return false;
+ }
+
+ // Tree Path's are equals
+ return true;
+ }
+
+ // Unequal
+ return false;
+ }
+
+ /**
+ * Returns a string representation of this path.
+ *
+ * @return A string representation of this path.
+ */
+ public String toString()
+ {
+ if (path.length == 1)
+ return String.valueOf(path[0]);
+ else
+ return Arrays.asList(path).toString();
+ }
+
+ /**
+ * Returns an array containing the path elements.
+ *
+ * @return An array containing the path elements.
+ */
+ public Object[] getPath()
+ {
+ return (Object[]) path.clone();
+ }
+
+ /**
+ * Returns the last object in the path.
+ *
+ * @return The last object in the path.
+ */
+ public Object getLastPathComponent()
+ {
+ return path[path.length - 1];
+ }
+
+ /**
+ * Returns the number of elements in the path.
+ *
+ * @return The number of elements in the path.
+ */
+ public int getPathCount()
+ {
+ return path.length;
+ }
+
+ /**
+ * Returns the element at the specified position in the path.
+ *
+ * @param position the element position (<code>0 < N - 1</code>, where
+ * <code>N</code> is the number of elements in the path).
+ *
+ * @return The element at the specified position.
+ *
+ * @throws IllegalArgumentException if <code>position</code> is outside the
+ * valid range.
+ */
+ public Object getPathComponent(int position)
+ {
+ if (position < 0 || position >= getPathCount())
+ throw new IllegalArgumentException("Invalid position: " + position);
+ return path[position];
+ }
+
+ /**
+ * Returns <code>true</code> if <code>path</code> is a descendant of this
+ * path, and <code>false</code> otherwise. If <code>path</code> is
+ * <code>null</code>, this method returns <code>false</code>.
+ *
+ * @param path the path to check (<code>null</code> permitted).
+ *
+ * @return <code>true</code> if <code>path</code> is a descendant of this
+ * path, and <code>false</code> otherwise
+ */
+ public boolean isDescendant(TreePath path)
+ {
+ if (path == null)
+ return false;
+ int count = getPathCount();
+ int otherPathLength = path.getPathCount();
+ if (otherPathLength < count)
+ return false;
+ while (otherPathLength > count)
+ {
+ otherPathLength--;
+ path = path.getParentPath();
+ }
+
+ return equals(path);
+ }
+
+ /**
+ * Creates a new path that is equivalent to this path plus the specified
+ * element.
+ *
+ * @param element the element.
+ *
+ * @return A tree path.
+ */
+ public TreePath pathByAddingChild(Object element)
+ {
+ return new TreePath(this, element);
+ }
+
+ /**
+ * Returns the parent path, which is a path containing all the same elements
+ * as this path, except for the last one. If this path contains only one
+ * element, the method returns <code>null</code>.
+ *
+ * @return The parent path, or <code>null</code> if this path has only one
+ * element.
+ */
+ public TreePath getParentPath()
+ {
+ // If this path has only one element, then we return null. That
+ // is what the JDK does.
+ if (path.length <= 1)
+ return null;
+
+ // Reuse the parent path, if possible. The parent path is requested
+ // during the tree repainting, so reusing generates a lot less garbage.
+ if (parentPath == null)
+ parentPath = new TreePath(this.getPath(), path.length - 1);
+
+ return parentPath;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeSelectionModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeSelectionModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeSelectionModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/TreeSelectionModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,112 @@
+/* TreeSelectionModel.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.tree;
+
+import java.beans.PropertyChangeListener;
+
+import javax.swing.event.TreeSelectionListener;
+
+/**
+ * TreeSelectionModel public interface
+ * @author Andrew Selkirk
+ */
+public interface TreeSelectionModel
+{
+
+ int SINGLE_TREE_SELECTION = 1;
+
+ int CONTIGUOUS_TREE_SELECTION = 2;
+
+ int DISCONTIGUOUS_TREE_SELECTION = 4;
+
+ void setSelectionMode(int mode);
+
+ int getSelectionMode();
+
+ void setSelectionPath(TreePath path);
+
+ void setSelectionPaths(TreePath[] paths);
+
+ void addSelectionPath(TreePath path);
+
+ void addSelectionPaths(TreePath[] paths);
+
+ void removeSelectionPath(TreePath path);
+
+ void removeSelectionPaths(TreePath[] paths);
+
+ TreePath getSelectionPath();
+
+ TreePath[] getSelectionPaths();
+
+ int getSelectionCount();
+
+ boolean isPathSelected(TreePath path);
+
+ boolean isSelectionEmpty();
+
+ void clearSelection();
+
+ void setRowMapper(RowMapper newMapper);
+
+ RowMapper getRowMapper();
+
+ int[] getSelectionRows();
+
+ int getMinSelectionRow();
+
+ int getMaxSelectionRow();
+
+ boolean isRowSelected(int row);
+
+ void resetRowSelection();
+
+ int getLeadSelectionRow();
+
+ TreePath getLeadSelectionPath();
+
+ void addPropertyChangeListener(PropertyChangeListener listener);
+
+ void removePropertyChangeListener(PropertyChangeListener listener);
+
+ void addTreeSelectionListener(TreeSelectionListener x);
+
+ void removeTreeSelectionListener(TreeSelectionListener x);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/VariableHeightLayoutCache.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/VariableHeightLayoutCache.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/VariableHeightLayoutCache.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/VariableHeightLayoutCache.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,623 @@
+/* VariableHeightLayoutCache.java --
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.tree;
+
+import gnu.javax.swing.tree.GnuPath;
+
+import java.awt.Rectangle;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.swing.event.TreeModelEvent;
+
+/**
+ * The fixed height tree layout. This class requires the NodeDimensions to be
+ * set and ignores the row height property.
+ *
+ * @specnote the methods, of this class, returning TreePath, actually returns
+ * the derived class GnuPath that provides additional information for optimized
+ * painting. See the GnuPath code for details.
+ *
+ * @author Audrius Meskauskas
+ */
+public class VariableHeightLayoutCache
+ extends AbstractLayoutCache
+{
+ /**
+ * The cached node record.
+ */
+ class NodeRecord
+ {
+ NodeRecord(int aRow, int aDepth, Object aNode, Object aParent)
+ {
+ row = aRow;
+ depth = aDepth;
+ parent = aParent;
+ node = aNode;
+
+ isExpanded = expanded.contains(aNode);
+ }
+
+ /**
+ * The row, where the tree node is displayed.
+ */
+ final int row;
+
+ /**
+ * The nesting depth
+ */
+ final int depth;
+
+ /**
+ * The parent of the given node, null for the root node.
+ */
+ final Object parent;
+
+ /**
+ * This node.
+ */
+ final Object node;
+
+ /**
+ * True for the expanded nodes. The value is calculated in constructor.
+ * Using this field saves one hashtable access operation.
+ */
+ final boolean isExpanded;
+
+ /**
+ * The cached bounds of the tree row.
+ */
+ Rectangle bounds;
+
+ /**
+ * The path from the tree top to the given node (computed under first
+ * demand)
+ */
+ private TreePath path;
+
+ /**
+ * Get the path for this node. The derived class is returned, making check
+ * for the last child of some parent easier.
+ */
+ TreePath getPath()
+ {
+ if (path == null)
+ {
+ boolean lastChild = false;
+ if (parent != null)
+ {
+ int nc = treeModel.getChildCount(parent);
+ if (nc > 0)
+ {
+ int n = treeModel.getIndexOfChild(parent, node);
+ if (n == nc - 1)
+ lastChild = true;
+ }
+ }
+
+ LinkedList lpath = new LinkedList();
+ NodeRecord rp = this;
+ while (rp != null)
+ {
+ lpath.addFirst(rp.node);
+ if (rp.parent != null)
+ {
+ Object parent = rp.parent;
+ rp = (NodeRecord) nodes.get(parent);
+ // Add the root node, even if it is not visible.
+ if (rp == null)
+ lpath.addFirst(parent);
+ }
+ else
+ rp = null;
+ }
+ path = new GnuPath(lpath.toArray(), lastChild);
+ }
+ return path;
+ }
+
+ /**
+ * Get the rectangle bounds (compute, if required).
+ */
+ Rectangle getBounds()
+ {
+ // This method may be called in the context when the tree rectangle is
+ // not known. To work around this, it is assumed near infinitely large.
+ if (bounds == null)
+ bounds = getNodeDimensions(node, row, depth, isExpanded,
+ new Rectangle());
+ return bounds;
+ }
+ }
+
+ /**
+ * The set of all expanded tree nodes.
+ */
+ Set expanded = new HashSet();
+
+ /**
+ * Maps nodes to the row numbers.
+ */
+ Hashtable nodes = new Hashtable();
+
+ /**
+ * Maps row numbers to nodes.
+ */
+ Hashtable row2node = new Hashtable();
+
+ /**
+ * If true, the row map must be recomputed before using.
+ */
+ boolean dirty;
+
+ /**
+ * The cumulative height of all rows.
+ */
+ int totalHeight;
+
+ /**
+ * The maximal width.
+ */
+ int maximalWidth;
+
+ /**
+ * Creates the unitialised instance. Before using the class, the row height
+ * must be set with the {@link #setRowHeight(int)} and the model must be set
+ * with {@link #setModel(TreeModel)}. The node dimensions may not be set.
+ */
+ public VariableHeightLayoutCache()
+ {
+ // Nothing to do here.
+ }
+
+ /**
+ * Get the total number of rows in the tree. Every displayed node occupies the
+ * single row. The root node row is included if the root node is set as
+ * visible (false by default).
+ *
+ * @return int the number of the displayed rows.
+ */
+ public int getRowCount()
+ {
+ if (dirty) update();
+ return row2node.size();
+ }
+
+ /**
+ * Refresh the row map.
+ */
+ private final void update()
+ {
+ nodes.clear();
+ row2node.clear();
+
+ totalHeight = maximalWidth = 0;
+
+ if (treeModel == null)
+ return;
+
+ Object root = treeModel.getRoot();
+
+ if (rootVisible)
+ {
+ countRows(root, null, 0);
+ }
+ else
+ {
+ int sc = treeModel.getChildCount(root);
+ for (int i = 0; i < sc; i++)
+ {
+ Object child = treeModel.getChild(root, i);
+ countRows(child, root, 0);
+ }
+ }
+ dirty = false;
+ }
+
+ /**
+ * Recursively counts all rows in the tree.
+ */
+ private final void countRows(Object node, Object parent, int depth)
+ {
+ Integer n = new Integer(row2node.size());
+ row2node.put(n, node);
+
+ NodeRecord nr = new NodeRecord(n.intValue(), depth, node, parent);
+ nodes.put(node, nr);
+
+ // For expanded nodes
+ if (expanded.contains(node))
+ {
+ int sc = treeModel.getChildCount(node);
+ int deeper = depth + 1;
+ for (int i = 0; i < sc; i++)
+ {
+ Object child = treeModel.getChild(node, i);
+ countRows(child, node, deeper);
+ }
+ }
+ }
+
+ /**
+ * Discard the bound information for the given path.
+ *
+ * @param path the path, for that the bound information must be recomputed.
+ */
+ public void invalidatePathBounds(TreePath path)
+ {
+ NodeRecord r = (NodeRecord) nodes.get(path.getLastPathComponent());
+ if (r != null)
+ r.bounds = null;
+ }
+
+ /**
+ * Mark all cached information as invalid.
+ */
+ public void invalidateSizes()
+ {
+ dirty = true;
+ }
+
+ /**
+ * Set the expanded state of the given path. The expansion states must be
+ * always updated when expanding and colapsing the tree nodes. Otherwise
+ * other methods will not work correctly after the nodes are collapsed or
+ * expanded.
+ *
+ * @param path the tree path, for that the state is being set.
+ * @param isExpanded the expanded state of the given path.
+ */
+ public void setExpandedState(TreePath path, boolean isExpanded)
+ {
+ if (isExpanded)
+ expanded.add(path.getLastPathComponent());
+ else
+ expanded.remove(path.getLastPathComponent());
+
+ dirty = true;
+ }
+
+ /**
+ * Get the expanded state for the given tree path.
+ *
+ * @return true if the given path is expanded, false otherwise.
+ */
+ public boolean isExpanded(TreePath path)
+ {
+ return expanded.contains(path.getLastPathComponent());
+ }
+
+ /**
+ * Get bounds for the given tree path.
+ *
+ * @param path the tree path
+ * @param rect the rectangle that will be reused to return the result.
+ * @return Rectangle the bounds of the last line, defined by the given path.
+ */
+ public Rectangle getBounds(TreePath path, Rectangle rect)
+ {
+ if (path == null)
+ return null;
+ if (dirty)
+ update();
+ Object last = path.getLastPathComponent();
+ NodeRecord r = (NodeRecord) nodes.get(last);
+ if (r == null)
+ // This node is not visible.
+ {
+ rect.x = rect.y = rect.width = rect.height = 0;
+ }
+ else
+ {
+ if (r.bounds == null)
+ {
+ Rectangle dim = getNodeDimensions(last, r.row, r.depth,
+ r.isExpanded, rect);
+ r.bounds = dim;
+ }
+
+ rect.setRect(r.bounds);
+ }
+ return rect;
+ }
+
+ /**
+ * Get the path, the last element of that is displayed in the given row.
+ *
+ * @param row the row
+ * @return TreePath the path
+ */
+ public TreePath getPathForRow(int row)
+ {
+ if (dirty)
+ update();
+ Object last = row2node.get(new Integer(row));
+ if (last == null)
+ return null;
+ else
+ {
+ NodeRecord r = (NodeRecord) nodes.get(last);
+ return r.getPath();
+ }
+ }
+
+ /**
+ * Get the row, displaying the last node of the given path.
+ *
+ * @param path the path
+ * @return int the row number or -1 if the end of the path is not visible.
+ */
+ public int getRowForPath(TreePath path)
+ {
+ if (path == null)
+ return -1;
+ if (dirty) update();
+
+ NodeRecord r = (NodeRecord) nodes.get(path.getLastPathComponent());
+ if (r == null)
+ return - 1;
+ else
+ return r.row;
+ }
+
+ /**
+ * Get the path, closest to the given point.
+ *
+ * @param x the point x coordinate
+ * @param y the point y coordinate
+ * @return the tree path, closest to the the given point
+ */
+ public TreePath getPathClosestTo(int x, int y)
+ {
+ if (dirty)
+ update();
+
+ // As the rows have arbitrary height, we need to iterate.
+ NodeRecord best = null;
+ NodeRecord r;
+ Enumeration en = nodes.elements();
+
+ int dist = Integer.MAX_VALUE;
+
+ while (en.hasMoreElements() && dist > 0)
+ {
+ r = (NodeRecord) en.nextElement();
+ if (best == null)
+ {
+ best = r;
+ dist = distance(r.getBounds(), x, y);
+ }
+ else
+ {
+ int rr = distance(r.getBounds(), x, y);
+ if (rr < dist)
+ {
+ best = r;
+ dist = rr;
+ }
+ }
+ }
+
+ if (best == null)
+ return null;
+ else
+ return best.getPath();
+ }
+
+ /**
+ * Get the closest distance from this point till the given rectangle. Only
+ * vertical distance is taken into consideration.
+ */
+ int distance(Rectangle r, int x, int y)
+ {
+ if (y < r.y)
+ return r.y - y;
+ else if (y > r.y + r.height)
+ return y - (r.y + r.height);
+ else
+ return 0;
+ }
+
+ /**
+ * Get the number of the visible childs for the given tree path. If the node
+ * is not expanded, 0 is returned. Otherwise, the number of children is
+ * obtained from the model as the number of children for the last path
+ * component.
+ *
+ * @param path the tree path
+ * @return int the number of the visible childs (for row).
+ */
+ public int getVisibleChildCount(TreePath path)
+ {
+ if (isExpanded(path))
+ return 0;
+ else
+ return treeModel.getChildCount(path.getLastPathComponent());
+ }
+
+ /**
+ * Get the enumeration over all visible pathes that start from the given
+ * parent path.
+ *
+ * @param parentPath the parent path
+ * @return the enumeration over pathes
+ */
+ public Enumeration getVisiblePathsFrom(TreePath parentPath)
+ {
+ if (dirty)
+ update();
+ Vector p = new Vector(parentPath.getPathCount());
+ Object node;
+ NodeRecord nr;
+
+ for (int i = 0; i < parentPath.getPathCount(); i++)
+ {
+ node = parentPath.getPathComponent(i);
+ nr = (NodeRecord) nodes.get(node);
+ if (nr.row >= 0)
+ p.add(node);
+ }
+ return p.elements();
+ }
+
+ /**
+ * Return the expansion state of the given tree path. The expansion state
+ * must be previously set with the
+ * {@link #setExpandedState(TreePath, boolean)}
+ *
+ * @param path the path being checked
+ * @return true if the last node of the path is expanded, false otherwise.
+ */
+ public boolean getExpandedState(TreePath path)
+ {
+ return expanded.contains(path.getLastPathComponent());
+ }
+
+ /**
+ * The listener method, called when the tree nodes are changed.
+ *
+ * @param event the change event
+ */
+ public void treeNodesChanged(TreeModelEvent event)
+ {
+ dirty = true;
+ }
+
+ /**
+ * The listener method, called when the tree nodes are inserted.
+ *
+ * @param event the change event
+ */
+ public void treeNodesInserted(TreeModelEvent event)
+ {
+ dirty = true;
+ }
+
+ /**
+ * The listener method, called when the tree nodes are removed.
+ *
+ * @param event the change event
+ */
+ public void treeNodesRemoved(TreeModelEvent event)
+ {
+ dirty = true;
+ }
+
+ /**
+ * Called when the tree structure has been changed.
+ *
+ * @param event the change event
+ */
+ public void treeStructureChanged(TreeModelEvent event)
+ {
+ dirty = true;
+ }
+
+ /**
+ * Set the tree model that will provide the data.
+ */
+ public void setModel(TreeModel newModel)
+ {
+ treeModel = newModel;
+ // We need to clear the table and update the layout,
+ // so that we don't end up with wrong data in the tables.
+ expanded.clear();
+ update();
+ if (treeModel != null)
+ {
+ // The root node is expanded by default.
+ expanded.add(treeModel.getRoot());
+ dirty = true;
+ }
+ }
+
+ /**
+ * Inform the instance if the tree root node is visible. If this method
+ * is not called, it is assumed that the tree root node is not visible.
+ *
+ * @param visible true if the tree root node is visible, false
+ * otherwise.
+ */
+ public void setRootVisible(boolean visible)
+ {
+ rootVisible = visible;
+ dirty = true;
+ }
+
+ /**
+ * Get the sum of heights for all rows.
+ */
+ public int getPreferredHeight()
+ {
+ if (dirty)
+ update();
+ totalHeight = 0;
+ Enumeration en = nodes.elements();
+ while (en.hasMoreElements())
+ {
+ NodeRecord nr = (NodeRecord) en.nextElement();
+ Rectangle r = nr.getBounds();
+ totalHeight += r.height;
+ }
+ return totalHeight;
+ }
+
+ /**
+ * Get the maximal width.
+ */
+ public int getPreferredWidth(Rectangle value)
+ {
+ if (dirty)
+ update();
+
+ maximalWidth = 0;
+ Enumeration en = nodes.elements();
+ while (en.hasMoreElements())
+ {
+ NodeRecord nr = (NodeRecord) en.nextElement();
+ Rectangle r = nr.getBounds();
+ if (r.x + r.width > maximalWidth)
+ maximalWidth = r.x + r.width;
+ }
+ return maximalWidth;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/tree/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.swing.tree package.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - javax.swing.tree</title></head>
+
+<body>
+<p>Interfaces and classes that support the {@link javax.swing.JTree}
+component.</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/AbstractUndoableEdit.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/AbstractUndoableEdit.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/AbstractUndoableEdit.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/AbstractUndoableEdit.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,323 @@
+/* AbstractUndoableEdit.java --
+ Copyright (C) 2002, 2003, 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.undo;
+
+import java.io.Serializable;
+
+import javax.swing.UIManager;
+
+/**
+ * A default implementation of <code>UndoableEdit</code> that can be
+ * used as a base for implementing editing operations.
+ *
+ * @author Andrew Selkirk (aselkirk at sympatico.ca)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class AbstractUndoableEdit
+ implements UndoableEdit, Serializable
+{
+ /**
+ * The serialization ID. Verified using the <code>serialver</code>
+ * tool of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5, and Sun JDK
+ * 1.4.1_01 on GNU/Linux.
+ */
+ static final long serialVersionUID = 580150227676302096L;
+
+
+ /**
+ * The constant string “Undo”, which was returned by
+ * {@link #getUndoPresentationName()} on early versions of the
+ * platform. However, this field has become obsolete with version
+ * 1.3.1. That method now retrieves a localized string from the
+ * {@link javax.swing.UIManager}, using the key
+ * <code>“AbstractUndoableEdit.undoText”</code>.
+ */
+ protected static final String UndoName = "Undo";
+
+
+ /**
+ * The constant string “Redo”, which was returned by
+ * {@link #getRedoPresentationName()} on early versions of the
+ * platform. However, this field has become obsolete with version
+ * 1.3.1. That method now retrieves a localized string from the
+ * {@link javax.swing.UIManager}, using the key
+ * <code>“AbstractUndoableEdit.redoText”</code>.
+ */
+ protected static final String RedoName = "Redo";
+
+
+ /**
+ * Indicates whether this editing action has been executed. A value
+ * of <code>true</code> means that the action was performed, or that
+ * a redo operation was successful. A value of <code>false</code>
+ * means that the action has not yet performed, or that an undo
+ * operation was successful.
+ */
+ private boolean hasBeenDone;
+
+
+ /**
+ * Indicates whether this editing action is still alive. The value
+ * is set to <code>true</code> by the constructor, and to
+ * <code>false</code> by the {@link #die()} method.
+ */
+ private boolean alive;
+
+
+ /**
+ * Constructs a new <code>AbstractUndoableEdit</code>. The initial
+ * state is that the editing action is alive, and
+ * <code>hasBeenDone</code> is <code>true</code>.
+ */
+ public AbstractUndoableEdit()
+ {
+ // The API specification is not clear, but Mauve test code has
+ // determined that hasBeenDone is initially set to true.
+ alive = hasBeenDone = true;
+ }
+
+
+ /**
+ * Undoes this editing action.
+ *
+ * @throws CannotUndoException if {@link #canUndo()} returns
+ * <code>false</code>, for example because this action has already
+ * been undone.
+ *
+ * @see #canUndo()
+ * @see #redo()
+ */
+ public void undo()
+ throws CannotUndoException
+ {
+ if (!canUndo())
+ throw new CannotUndoException();
+ hasBeenDone = false;
+ }
+
+
+ /**
+ * Determines whether it would be possible to undo this editing
+ * action.
+ *
+ * @return <code>true</code> to indicate that this action can be
+ * undone, <code>false</code> otherwise.
+ *
+ * @see #undo()
+ * @see #canRedo()
+ */
+ public boolean canUndo()
+ {
+ return alive && hasBeenDone;
+ }
+
+
+ /**
+ * Redoes this editing action.
+ *
+ * @throws CannotRedoException if {@link #canRedo()} returns
+ * <code>false</code>, for example because this action has not
+ * yet been undone.
+ *
+ * @see #canRedo()
+ * @see #undo()
+ */
+ public void redo()
+ throws CannotRedoException
+ {
+ if (!canRedo())
+ throw new CannotRedoException();
+ hasBeenDone = true;
+ }
+
+
+ /**
+ * Determines whether it would be possible to redo this editing
+ * action.
+ *
+ * @return <code>true</code> to indicate that this action can be
+ * redone, <code>false</code> otherwise.
+ *
+ * @see #redo()
+ * @see #canUndo()
+ */
+ public boolean canRedo()
+ {
+ return alive && !hasBeenDone;
+ }
+
+
+ /**
+ * Informs this edit action that it will no longer be used. Some
+ * actions might use this information to release resources, for
+ * example open files. Called by {@link UndoManager} before this
+ * action is removed from the edit queue.
+ */
+ public void die()
+ {
+ alive = false;
+ }
+
+
+ /**
+ * Incorporates another editing action into this one, thus forming a
+ * combined action.
+ *
+ * <p>The default implementation always returns <code>false</code>,
+ * indicating that the editing action could not be incorporated.
+ *
+ * @param edit the editing action to be incorporated.
+ */
+ public boolean addEdit(UndoableEdit edit)
+ {
+ return false;
+ }
+
+
+ /**
+ * Incorporates another editing action into this one, thus forming a
+ * combined action that replaces the argument action.
+ *
+ * <p>The default implementation always returns <code>false</code>,
+ * indicating that the argument action should not be replaced.
+ *
+ * @param edit the editing action to be replaced.
+ */
+ public boolean replaceEdit(UndoableEdit edit)
+ {
+ return false;
+ }
+
+
+ /**
+ * Determines whether this editing action is significant enough for
+ * being seperately undoable by the user. A typical significant
+ * action would be the resizing of an object. However, changing the
+ * selection in a text document would usually not be considered
+ * significant.
+ *
+ * <p>The default implementation returns <code>true</code>.
+ *
+ * @return <code>true</code> to indicate that the action is
+ * significant enough for being separately undoable, or
+ * <code>false</code> otherwise.
+ */
+ public boolean isSignificant()
+ {
+ return true;
+ }
+
+
+ /**
+ * Returns a human-readable, localized name that describes this
+ * editing action and can be displayed to the user.
+ *
+ * <p>The default implementation returns an empty string.
+ */
+ public String getPresentationName()
+ {
+ return "";
+ }
+
+
+ /**
+ * Calculates a localized name for presenting the undo action to the
+ * user.
+ *
+ * <p>The default implementation returns the concatenation of the
+ * string “Undo” and the action name, which is
+ * determined by calling {@link #getPresentationName()}.
+ *
+ * <p>The string “Undo” is retrieved from the {@link
+ * javax.swing.UIManager}, using the key
+ * <code>“AbstractUndoableEdit.undoText”</code>. This
+ * allows the text to be localized.
+ */
+ public String getUndoPresentationName()
+ {
+ String msg, pres;
+
+ msg = UIManager.getString("AbstractUndoableEdit.undoText");
+ if (msg == null)
+ msg = UndoName;
+
+ pres = getPresentationName();
+ if ((pres == null) || (pres.length() == 0))
+ return msg;
+ else
+ return msg + ' ' + pres;
+ }
+
+
+ /**
+ * Calculates a localized name for presenting the redo action to the
+ * user.
+ *
+ * <p>The default implementation returns the concatenation of the
+ * string “Redo” and the action name, which is
+ * determined by calling {@link #getPresentationName()}.
+ *
+ * <p>The string “Redo” is retrieved from the {@link
+ * javax.swing.UIManager}, using the key
+ * <code>“AbstractUndoableEdit.redoText”</code>. This
+ * allows the text to be localized.
+ */
+ public String getRedoPresentationName()
+ {
+ String msg, pres;
+
+ msg = UIManager.getString("AbstractUndoableEdit.redoText");
+ if (msg == null)
+ msg = RedoName;
+
+ pres = getPresentationName();
+ if ((pres == null) || (pres.length() == 0))
+ return msg;
+ else
+ return msg + ' ' + pres;
+ }
+
+
+ public String toString()
+ {
+ return super.toString()
+ + " hasBeenDone: " + hasBeenDone
+ + " alive: " + alive;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CannotRedoException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CannotRedoException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CannotRedoException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CannotRedoException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,56 @@
+/* CannotRedoException.java
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.undo;
+
+/**
+ * An exception which indicates that an editing action cannot be
+ * redone.
+ *
+ * @author Andrew Selkirk (aselkirk at sympatico.ca)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class CannotRedoException extends RuntimeException
+{
+ /**
+ * Constructs a new instance of a <code>CannotRedoException</code>.
+ */
+ public CannotRedoException()
+ {
+ super();
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CannotUndoException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CannotUndoException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CannotUndoException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CannotUndoException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,58 @@
+/* CannotUndoException.java
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.undo;
+
+
+/**
+ * An exception which indicates that an editing action cannot be
+ * undone.
+ *
+ * @author Andrew Selkirk (aselkirk at sympatico.ca)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class CannotUndoException
+ extends RuntimeException
+{
+ /**
+ * Constructs a new instance of a <code>CannotUndoException</code>.
+ */
+ public CannotUndoException()
+ {
+ super();
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CompoundEdit.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CompoundEdit.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CompoundEdit.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/CompoundEdit.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,400 @@
+/* CompoundEdit.java -- Combines multiple UndoableEdits.
+ Copyright (C) 2002, 2003, 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.undo;
+
+import java.util.Vector;
+
+/**
+ * An editing action that consists of multiple
+ * <code>UndoableEdits</code>.
+ *
+ * <p>The use of a <code>CompoundEdit</code> is divided in two separate
+ * phases.</p>
+ *
+ * <ol>
+ * <li>In the first phase, the <code>CompoundEdit</code> is
+ * initialized. After a new instance of <code>CompoundEdit</code> has
+ * been created, {@link #addEdit(UndoableEdit)} is called for each
+ * element of the compound. To terminate the initialization phase,
+ * call {@link #end()}.</li>
+ * <li>In the second phase, the the <code>CompoundEdit</code> can be
+ * used, typically by invoking {@link #undo()} and
+ * {@link #redo()}.</li>
+ * </ol>
+ *
+ * @author Andrew Selkirk (aselkirk at sympatico.ca)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class CompoundEdit
+ extends AbstractUndoableEdit
+{
+ /**
+ * The identifier of this class in object serialization. Determined
+ * using the serialver tool of Sun J2SE 1.4.1_01.
+ */
+ private static final long serialVersionUID = -6512679249930119683L;
+
+
+ /**
+ * The <code>UndoableEdit</code>s being combined into a compound
+ * editing action.
+ */
+ protected Vector edits;
+
+
+ /**
+ * Indicates whether the creation of this CompoundEdit is still in
+ * progress. Initially, the value of this flag is
+ * <code>true</code>. The {@link #end()} method changes the flag to
+ * <code>false</code>.
+ */
+ private boolean inProgress;
+
+
+ /**
+ * Constructs a new CompoundEdit.
+ */
+ public CompoundEdit()
+ {
+ edits = new Vector();
+ inProgress = true;
+ }
+
+
+ /**
+ * Undoes all edits that are part of of this
+ * <code>CompoundEdit</code>. The compound elements will receive the
+ * <code>undo</code> message in the reverse order of addition.
+ *
+ * @throws CannotUndoException if {@link #canUndo()} returns
+ * <code>false</code>. This can happen if {@link #end()} has not
+ * been called on this <code>CompoundEdit</code>, or if this edit
+ * has already been undone.
+ *
+ * @see #canUndo()
+ * @see #redo()
+ */
+ public void undo()
+ throws CannotUndoException
+ {
+ // AbstractUndoableEdit.undo() will throw a CannotUndoException if
+ // canUndo returns false.
+ super.undo();
+
+ for (int i = edits.size() - 1; i >= 0; i--)
+ ((UndoableEdit) edits.elementAt(i)).undo();
+ }
+
+
+ /**
+ * Redoes all edits that are part of of this
+ * <code>CompoundEdit</code>. The compound elements will receive the
+ * <code>undo</code> message in the same order as they were added.
+ *
+ * @throws CannotRedoException if {@link #canRedo()} returns
+ * <code>false</code>. This can happen if {@link #end()} has not
+ * been called on this <code>CompoundEdit</code>, or if this edit
+ * has already been redone.
+ *
+ * @see #canRedo()
+ * @see #undo()
+ */
+ public void redo()
+ throws CannotRedoException
+ {
+ // AbstractUndoableEdit.redo() will throw a CannotRedoException if
+ // canRedo returns false.
+ super.redo();
+
+ for (int i = 0; i < edits.size(); i++)
+ ((UndoableEdit) edits.elementAt(i)).redo();
+ }
+
+
+ /**
+ * Returns the the <code>UndoableEdit</code> that was last added to
+ * this compound.
+ */
+ protected UndoableEdit lastEdit()
+ {
+ if (edits.size() == 0)
+ return null;
+ else
+ return (UndoableEdit) edits.elementAt(edits.size() - 1);
+ }
+
+
+ /**
+ * Informs this edit action, and all compound edits, that they will
+ * no longer be used. Some actions might use this information to
+ * release resources such as open files. Called by {@link
+ * UndoManager} before this action is removed from the edit queue.
+ *
+ * <p>The compound elements will receive the
+ * <code>die</code> message in the reverse order of addition.
+ */
+ public void die()
+ {
+ for (int i = edits.size() - 1; i >= 0; i--)
+ ((UndoableEdit) edits.elementAt(i)).die();
+
+ super.die();
+ }
+
+
+ /**
+ * Incorporates another editing action into this one, thus forming a
+ * combined edit.
+ *
+ * <p>If this edit’s {@link #end()} method has been called
+ * before, <code>false</code> is returned immediately. Otherwise,
+ * the {@linkplain #lastEdit() last added edit} is given the
+ * opportunity to {@linkplain UndoableEdit#addEdit(UndoableEdit)
+ * incorporate} <code>edit</code>. If this fails, <code>edit</code>
+ * is given the opportunity to {@linkplain
+ * UndoableEdit#replaceEdit(UndoableEdit) replace} the last added
+ * edit. If this fails as well, <code>edit</code> gets added as a
+ * new compound to {@link #edits}.
+ *
+ * @param edit the editing action being added.
+ *
+ * @return <code>true</code> if <code>edit</code> could somehow be
+ * incorporated; <code>false</code> if <code>edit</code> has not
+ * been incorporated because {@link #end()} was called before.
+ */
+ public boolean addEdit(UndoableEdit edit)
+ {
+ UndoableEdit last;
+
+ // If end has been called before, do nothing.
+ if (!inProgress)
+ return false;
+
+ last = lastEdit();
+
+ // If edit is the very first edit, just add it to the list.
+ if (last == null)
+ {
+ edits.add(edit);
+ return true;
+ }
+
+ // Try to incorporate edit into last.
+ if (last.addEdit(edit))
+ return true;
+
+ // Try to replace last by edit.
+ if (edit.replaceEdit(last))
+ {
+ edits.set(edits.size() - 1, edit);
+ return true;
+ }
+
+ // If everything else has failed, add edit to the list of compound
+ // edits.
+ edits.add(edit);
+ return true;
+ }
+
+
+ /**
+ * Informs this <code>CompoundEdit</code> that its construction
+ * phase has been completed. After this method has been called,
+ * {@link #undo()} and {@link #redo()} may be called, {@link
+ * #isInProgress()} will return <code>false</code>, and all attempts
+ * to {@linkplain #addEdit(UndoableEdit) add further edits} will
+ * fail.
+ */
+ public void end()
+ {
+ inProgress = false;
+ }
+
+
+ /**
+ * Determines whether it would be possible to undo this editing
+ * action. The result will be <code>true</code> if {@link #end()}
+ * has been called on this <code>CompoundEdit</code>, {@link #die()}
+ * has not yet been called, and the edit has not been undone
+ * already.
+ *
+ * @return <code>true</code> to indicate that this action can be
+ * undone; <code>false</code> otherwise.
+ *
+ * @see #undo()
+ * @see #canRedo()
+ */
+ public boolean canUndo()
+ {
+ return !inProgress && super.canUndo();
+ }
+
+
+ /**
+ * Determines whether it would be possible to redo this editing
+ * action. The result will be <code>true</code> if {@link #end()}
+ * has been called on this <code>CompoundEdit</code>, {@link #die()}
+ * has not yet been called, and the edit has not been redone
+ * already.
+ *
+ * @return <code>true</code> to indicate that this action can be
+ * redone; <code>false</code> otherwise.
+ *
+ * @see #redo()
+ * @see #canUndo()
+ */
+ public boolean canRedo()
+ {
+ return !inProgress && super.canRedo();
+ }
+
+
+ /**
+ * Determines whether the initial construction phase of this
+ * <code>CompoundEdit</code> is still in progress. During this
+ * phase, edits {@linkplain #addEdit(UndoableEdit) may be
+ * added}. After initialization has been terminated by calling
+ * {@link #end()}, {@link #undo()} and {@link #redo()} can be used.
+ *
+ * @return <code>true</code> if the initialization phase is still in
+ * progress; <code>false</code> if {@link #end()} has been called.
+ *
+ * @see #end()
+ */
+ public boolean isInProgress()
+ {
+ return inProgress;
+ }
+
+
+ /**
+ * Determines whether this editing action is significant enough for
+ * being seperately undoable by the user. A typical significant
+ * action would be the resizing of an object. However, changing the
+ * selection in a text document would usually not be considered
+ * significant.
+ *
+ * <p>A <code>CompoundEdit</code> is significant if any of its
+ * elements are significant.
+ */
+ public boolean isSignificant()
+ {
+ for (int i = edits.size() - 1; i >= 0; i--)
+ if (((UndoableEdit) edits.elementAt(i)).isSignificant())
+ return true;
+
+ return false;
+ }
+
+
+ /**
+ * Returns a human-readable, localized name that describes this
+ * editing action and can be displayed to the user.
+ *
+ * <p>The implementation delegates the call to the {@linkplain
+ * #lastEdit() last added edit action}. If no edit has been added
+ * yet, the inherited implementation will be invoked, which always
+ * returns an empty string.
+ */
+ public String getPresentationName()
+ {
+ UndoableEdit last;
+
+ last = lastEdit();
+ if (last == null)
+ return super.getPresentationName();
+ else
+ return last.getPresentationName();
+ }
+
+
+ /**
+ * Calculates a localized message text for presenting the undo
+ * action to the user.
+ *
+ * <p>The implementation delegates the call to the {@linkplain
+ * #lastEdit() last added edit action}. If no edit has been added
+ * yet, the {@linkplain
+ * AbstractUndoableEdit#getUndoPresentationName() inherited
+ * implementation} will be invoked.
+ */
+ public String getUndoPresentationName()
+ {
+ UndoableEdit last;
+
+ last = lastEdit();
+ if (last == null)
+ return super.getUndoPresentationName();
+ else
+ return last.getUndoPresentationName();
+ }
+
+
+ /**
+ * Calculates a localized message text for presenting the redo
+ * action to the user.
+ *
+ * <p>The implementation delegates the call to the {@linkplain
+ * #lastEdit() last added edit action}. If no edit has been added
+ * yet, the {@linkplain
+ * AbstractUndoableEdit#getRedoPresentationName() inherited
+ * implementation} will be invoked.
+ */
+ public String getRedoPresentationName()
+ {
+ UndoableEdit last;
+
+ last = lastEdit();
+ if (last == null)
+ return super.getRedoPresentationName();
+ else
+ return last.getRedoPresentationName();
+ }
+
+
+ /**
+ * Calculates a string that may be useful for debugging.
+ */
+ public String toString()
+ {
+ return super.toString()
+ + " inProgress: " + inProgress
+ + " edits: " + edits;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/StateEdit.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/StateEdit.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/StateEdit.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/StateEdit.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,265 @@
+/* StateEdit.java -- UndoableEdit for StateEditable implementations.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.undo;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+
+/**
+ * A helper class, making it easy to support undo and redo.
+ *
+ * <p>The following example shows how to use this class.</p>
+ *
+ * <pre>
+ * Foo foo; // class Foo implements {@link StateEditable}
+ * StateEdit edit;
+ *
+ * edit = new StateEdit(foo, "Name Change");
+ * foo.setName("Jane Doe");
+ * edit.end();
+ * undoManager.addEdit(edit);
+ * </pre>
+ *
+ * <p>If <code>Foo</code>’s implementation of {@link
+ * StateEditable} considers the name as part of the editable state,
+ * the user can now choose “Undo Name Change” or
+ * “Redo Name Change” from the respective menu. No
+ * further undo support is needed from the application.</p>
+ *
+ * <p>The following explains what happens in the example.</p>
+ *
+ * <ol>
+ * <li>When a <code>StateEdit</code> is created, the associated
+ * {@link StateEditable} gets asked to store its state into a hash
+ * table, {@link #preState}.</li>
+ * <li>The application will now perform some changes to the edited
+ * object. This typically happens by invoking methods on the edited
+ * object.</li>
+ * <li>The editing phase is terminated by invoking the {@link #end()}
+ * method of the <code>StateEdit</code>. The <code>end()</code> method
+ * does two things.
+ *
+ * <ul>
+ * <li>The edited object receives a second request for storing
+ * its state. This time, it will use a different hash table, {@link
+ * #postState}.</li>
+ * <li>To increase efficiency, the <code>StateEdit</code> now removes
+ * any entries from {@link #preState} and {@link #postState} that have
+ * the same key, and whose values are equal. Equality is determined
+ * by invoking the <code>equals</code> method inherited from
+ * {@link java.lang.Object}.</li>
+ * </ul></li>
+ * <li>When the user later chooses to undo the <code>StateEdit</code>,
+ * the edited object is asked to {@linkplain StateEditable#restoreState
+ * restore its state} from the {@link #preState} table. Similarly,
+ * when the user chooses to <i>redo</i> the <code>StateEdit</code>,
+ * the edited object gets asked to restore its state from the {@link
+ * #postState}.</li>
+ * </ol>
+ *
+ * @author Andrew Selkirk (aselkirk at sympatico.ca)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class StateEdit
+ extends AbstractUndoableEdit
+{
+ /**
+ * The ID of the Java source file in Sun’s Revision Control
+ * System (RCS). This certainly should not be part of the API
+ * specification. But in order to be API-compatible with
+ * Sun’s reference implementation, GNU Classpath also has to
+ * provide this field and match its value. The value used here has
+ * been in every JDK release at least from 1.2 to 1.5.
+ */
+ protected static final String RCSID = "$" +
+ "Id: StateEdit.java,v 1.6 1997/10/01 20:05:51 sandipc Exp $";
+
+
+ /**
+ * The object which is being edited by this <code>StateEdit</code>.
+ */
+ protected StateEditable object;
+
+
+ /**
+ * The state of <code>object</code> at the time of constructing
+ * this <code>StateEdit</code>.
+ */
+ protected Hashtable preState;
+
+
+ /**
+ * The state of <code>object</code> at the time when {@link #end()}
+ * was called.
+ */
+ protected Hashtable postState;
+
+
+ /**
+ * A human-readable name for this edit action.
+ */
+ protected String undoRedoName;
+
+
+ /**
+ * Constructs a <code>StateEdit</code>, specifying the object whose
+ * state is being edited.
+ *
+ * @param obj the object whose state is being edited by this
+ * <code>StateEdit</code>.
+ */
+ public StateEdit(StateEditable obj)
+ {
+ init(obj, null);
+ }
+
+
+ /**
+ * Constructs a <code>StateEdit</code>, specifying the object whose
+ * state is being edited.
+ *
+ * @param obj the object whose state is being edited by this
+ * <code>StateEdit</code>.
+ *
+ * @param name the human-readable name of the editing action.
+ */
+ public StateEdit(StateEditable obj, String name)
+ {
+ init(obj, name);
+ }
+
+
+ /**
+ * Initializes this <code>StateEdit</code>. The edited object will
+ * be asked to store its current state into {@link #preState}.
+ *
+ * @param obj the object being edited.
+ *
+ * @param name the human-readable name of the editing action.
+ */
+ protected void init(StateEditable obj, String name)
+ {
+ object = obj;
+ undoRedoName = name;
+ preState = new Hashtable();
+ postState = new Hashtable();
+ obj.storeState(preState);
+ }
+
+
+ /**
+ * Informs this <code>StateEdit</code> that all edits are finished.
+ * The edited object will be asked to store its state into {@link
+ * #postState}, and any redundant entries will get removed from
+ * {@link #preState} and {@link #postState}.
+ */
+ public void end()
+ {
+ object.storeState(postState);
+ removeRedundantState();
+ }
+
+
+ /**
+ * Undoes this edit operation. The edited object will be asked to
+ * {@linkplain StateEditable#restoreState restore its state} from
+ * {@link #preState}.
+ *
+ * @throws CannotUndoException if {@link #canUndo()} returns
+ * <code>false</code>, for example because this action has already
+ * been undone.
+ */
+ public void undo()
+ {
+ super.undo();
+ object.restoreState(preState);
+ }
+
+
+ /**
+ * Redoes this edit operation. The edited object will be asked to
+ * {@linkplain StateEditable#restoreState restore its state} from
+ * {@link #postState}.
+ *
+ * @throws CannotRedoException if {@link #canRedo()} returns
+ * <code>false</code>, for example because this action has not yet
+ * been undone.
+ */
+ public void redo()
+ {
+ super.redo();
+ object.restoreState(postState);
+ }
+
+
+ /**
+ * Returns a human-readable, localized name that describes this
+ * editing action and can be displayed to the user.
+ *
+ * @return the name, or <code>null</code> if no presentation
+ * name is available.
+ */
+ public String getPresentationName()
+ {
+ return undoRedoName;
+ }
+
+
+ /**
+ * Removes all redundant entries from the pre- and post-edit state
+ * hash tables. An entry is considered redundant if it is present
+ * both before and after the edit, and if the two values are equal.
+ */
+ protected void removeRedundantState()
+ {
+ Iterator i = preState.keySet().iterator();
+ while (i.hasNext())
+ {
+ Object key = i.next();
+ if (postState.containsKey(key))
+ {
+ if (preState.get(key).equals(postState.get(key)))
+ {
+ i.remove();
+ postState.remove(key);
+ }
+ }
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/StateEditable.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/StateEditable.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/StateEditable.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/StateEditable.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,114 @@
+/* StateEditable.java -- Interface for collaborating with StateEdit.
+ Copyright (C) 2002, 2003, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.undo;
+
+import java.util.Hashtable;
+
+
+/**
+ * The interface for objects whose state can be undone or redone by a
+ * {@link StateEdit} action.
+ *
+ * <p>The following example shows how to write a class that implements
+ * this interface.
+ *
+ * <pre> class Foo
+ * implements StateEditable
+ * {
+ * private String name;
+ *
+ * public void setName(String n) { name = n; }
+ *
+ * public void restoreState(Hashtable h)
+ * {
+ * if (h.containsKey("name"))
+ * setName((String) h.get("name"));
+ * }
+ *
+ * public void storeState(Hashtable s)
+ * {
+ * s.put("name", name);
+ * }
+ * }</pre>
+ *
+ * @see StateEdit
+ *
+ * @author Andrew Selkirk (aselkirk at sympatico.ca)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public interface StateEditable
+{
+ /**
+ * The ID of the Java source file in Sun’s Revision Control
+ * System (RCS). This certainly should not be part of the API
+ * specification. But in order to be API-compatible with
+ * Sun’s reference implementation, GNU Classpath also has to
+ * provide this field and match its value. The value used here has
+ * been in every JDK release at least from 1.2 to 1.5.
+ */
+ String RCSID = "$" +
+ "Id: StateEditable.java,v 1.2 1997/09/08 19:39:08 marklin Exp $";
+
+
+ /**
+ * Performs an edit action, taking any editable state information
+ * from the specified hash table.
+ *
+ * <p><b>Note to implementors of this interface:</b> To increase
+ * efficiency, the <code>StateEdit</code> class {@link
+ * StateEdit#removeRedundantState()} removes redundant state
+ * information. Therefore, implementations of this interface must be
+ * prepared for the case where certain keys were stored into the
+ * table by {@link #storeState}, but are not present anymore
+ * when the <code>restoreState</code> method gets called.
+ *
+ * @param state a hash table containing the relevant state
+ * information.
+ */
+ void restoreState(Hashtable state);
+
+
+ /**
+ * Stores any editable state information into the specified hash
+ * table.
+ *
+ * @param state a hash table for storing relevant state
+ * information.
+ */
+ void storeState(Hashtable state);
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoManager.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoManager.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoManager.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoManager.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,625 @@
+/* UndoManager.java --
+ Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.undo;
+
+import javax.swing.UIManager;
+import javax.swing.event.UndoableEditEvent;
+import javax.swing.event.UndoableEditListener;
+
+
+/**
+ * A manager for providing an application’s undo/redo
+ * functionality.
+ *
+ * <p>Tyipcally, an application will create only one single instance
+ * of UndoManager. When the user performs an undoable action, for
+ * instance changing the color of an object from green to blue, the
+ * application registers an {@link UndoableEdit} object with the
+ * <code>UndoManager</code>. To implement the “undo” and
+ * “redo” menu commands, the application invokes the
+ * UndoManager’s {@link #undo} and {@link #redo} methods. The
+ * human-readable text of these menu commands is provided by {@link
+ * #getUndoPresentationName} and {@link #getRedoPresentationName},
+ * respectively. To determine whether the menu item should be
+ * selectable or greyed out, use {@link #canUndo} and {@link
+ * #canRedo}.
+ *
+ * <p>The UndoManager will only keep a specified number of editing
+ * actions, the <em>limit</em>. The value of this parameter can be
+ * retrieved by calling {@link #getLimit} and set with {@link
+ * #setLimit}. If more UndoableEdits are added to the UndoManager,
+ * the oldest actions will be discarded.
+ *
+ * <p>Some applications do not provide separate menu commands for
+ * “undo” and “redo.” Instead, they
+ * have just a single command whose text switches between the two.
+ * Such applications would use an UndoManager with a <code>limit</code>
+ * of 1. The text of this combined menu item is available via
+ * {@link #getUndoOrRedoPresentationName}, and it is implemented
+ * by calling {@link #undoOrRedo}.
+ *
+ * <p><b>Thread Safety:</b> In constrast to the other classes of the
+ * <code>javax.swing.undo</code> package, the public methods of an
+ * <code>UndoManager</code> are safe to call from concurrent threads.
+ * The caller does not need to perform external synchronization, and
+ * {@link javax.swing.event.UndoableEditEvent} sources do not need to
+ * broadcast their events from inside the Swing worker thread.
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class UndoManager
+ extends CompoundEdit
+ implements UndoableEditListener
+{
+ /**
+ * The unique ID for serializing instances of this class. Determined
+ * using the <code>serialver</code> tool of Sun JDK 1.4.1_01 on
+ * GNU/Linux.
+ */
+ static final long serialVersionUID = -2077529998244066750L;
+
+
+ /**
+ * An index into the inherited {@link #edits} Vector that indicates
+ * at which position newly added editing actions would get inserted.
+ *
+ * <p>Normally, the value of <code>indexOfNextAdd</code> equals
+ * the number of UndoableEdits stored by this UndoManager, i.e.
+ * <code>edits.size()</code>. For each call to {@link #undo},
+ * <code>indexOfNextAdd</code> is decremented by one. For each
+ * call to {@link #redo}, it is incremented again.
+ */
+ int indexOfNextAdd;
+
+
+ /**
+ * The maximum number of UndoableEdits stored by this UndoManager.
+ */
+ int limit;
+
+
+ /**
+ * Constructs an UndoManager.
+ *
+ * <p>The <code>limit</code> of the freshly constructed UndoManager
+ * is 100.
+ */
+ public UndoManager()
+ {
+ limit = 100;
+ }
+
+
+ /**
+ * Returns a string representation for this UndoManager. This may be
+ * useful for debugging purposes. For the text of menu items, please
+ * refer to {@link #getUndoPresentationName}, {@link
+ * #getRedoPresentationName}, and {@link
+ * #getUndoOrRedoPresentationName}.
+ */
+ public String toString()
+ {
+ return super.toString()
+ + " limit: " + limit
+ + " indexOfNextAdd: " + indexOfNextAdd;
+ }
+
+
+ /**
+ * Puts this UndoManager into a state where it acts as a normal
+ * {@link CompoundEdit}. It is unlikely that an application would
+ * want to do this.
+ */
+ public synchronized void end()
+ {
+ super.end();
+ trimEdits(indexOfNextAdd, edits.size() - 1);
+ }
+
+
+ /**
+ * Returns how many edits this UndoManager can maximally hold.
+ *
+ * @see #setLimit
+ */
+ public synchronized int getLimit()
+ {
+ return limit;
+ }
+
+
+ /**
+ * Changes the maximal number of edits that this UndoManager can
+ * process. If there are currently more edits than the new limit
+ * allows, they will receive a {@link UndoableEdit#die() die}
+ * message in reverse order of addition.
+ *
+ * @param limit the new limit.
+ *
+ * @throws IllegalStateException if {@link #end()} has already been
+ * called on this UndoManager.
+ */
+ public synchronized void setLimit(int limit)
+ {
+ if (!isInProgress())
+ throw new IllegalStateException();
+
+ this.limit = limit;
+ trimForLimit();
+ }
+
+
+ /**
+ * Discards all editing actions that are currently registered with
+ * this UndoManager. Each {@link UndoableEdit} will receive a {@link
+ * UndoableEdit#die() die message}.
+ */
+ public synchronized void discardAllEdits()
+ {
+ int size;
+
+ size = edits.size();
+ for (int i = size - 1; i >= 0; i--)
+ ((UndoableEdit) edits.get(i)).die();
+ indexOfNextAdd = 0;
+ edits.clear();
+ }
+
+
+ /**
+ * Called by various internal methods in order to enforce
+ * the <code>limit</code> value.
+ */
+ protected void trimForLimit()
+ {
+ int high, s;
+
+ s = edits.size();
+
+ /* The Sun J2SE1.4.1_01 implementation can be observed to do
+ * nothing (instead of throwing an exception) with a negative or
+ * zero limit. It may be debatable whether this is the best
+ * behavior, but we replicate it for sake of compatibility.
+ */
+ if (limit <= 0 || s <= limit)
+ return;
+
+ high = Math.min(indexOfNextAdd + limit/2 - 1, s - 1);
+ trimEdits(high + 1, s - 1);
+ trimEdits(0, high - limit);
+ }
+
+
+ /**
+ * Discards a range of edits. All edits in the range <code>[from
+ * .. to]</code> will receive a {@linkplain UndoableEdit#die() die
+ * message} before being removed from the edits array. If
+ * <code>from</code> is greater than <code>to</code>, nothing
+ * happens.
+ *
+ * @param from the lower bound of the range of edits to be
+ * discarded.
+ *
+ * @param to the upper bound of the range of edits to be discarded.
+ */
+ protected void trimEdits(int from, int to)
+ {
+ if (from > to)
+ return;
+
+ for (int i = to; i >= from; i--)
+ ((UndoableEdit) edits.get(i)).die();
+
+ // Remove the range [from .. to] from edits. If from == to, which
+ // is likely to be a very common case, we can do better than
+ // creating a sub-list and clearing it.
+ if (to == from)
+ edits.remove(from);
+ else
+ edits.subList(from, to + 1).clear();
+
+ if (indexOfNextAdd > to)
+ indexOfNextAdd = indexOfNextAdd - to + from - 1;
+ else if (indexOfNextAdd >= from)
+ indexOfNextAdd = from;
+ }
+
+
+ /**
+ * Determines which significant edit would be undone if {@link
+ * #undo()} was called.
+ *
+ * @return the significant edit that would be undone, or
+ * <code>null</code> if no significant edit would be affected by
+ * calling {@link #undo()}.
+ */
+ protected UndoableEdit editToBeUndone()
+ {
+ UndoableEdit result;
+
+ for (int i = indexOfNextAdd - 1; i >= 0; i--)
+ {
+ result = (UndoableEdit) edits.get(i);
+ if (result.isSignificant())
+ return result;
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Determines which significant edit would be redone if {@link
+ * #redo()} was called.
+ *
+ * @return the significant edit that would be redone, or
+ * <code>null</code> if no significant edit would be affected by
+ * calling {@link #redo()}.
+ */
+ protected UndoableEdit editToBeRedone()
+ {
+ UndoableEdit result;
+
+ for (int i = indexOfNextAdd; i < edits.size(); i++)
+ {
+ result = (UndoableEdit) edits.get(i);
+ if (result.isSignificant())
+ return result;
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Undoes all editing actions in reverse order of addition,
+ * up to the specified action,
+ *
+ * @param edit the last editing action to be undone.
+ */
+ protected void undoTo(UndoableEdit edit)
+ throws CannotUndoException
+ {
+ UndoableEdit cur;
+
+ if (!edits.contains(edit))
+ throw new CannotUndoException();
+
+ while (true)
+ {
+ indexOfNextAdd -= 1;
+ cur = (UndoableEdit) edits.get(indexOfNextAdd);
+ cur.undo();
+ if (cur == edit)
+ return;
+ }
+ }
+
+
+ /**
+ * Redoes all editing actions in the same order as they were
+ * added to this UndoManager, up to the specified action.
+ *
+ * @param edit the last editing action to be redone.
+ */
+ protected void redoTo(UndoableEdit edit)
+ throws CannotRedoException
+ {
+ UndoableEdit cur;
+
+ if (!edits.contains(edit))
+ throw new CannotRedoException();
+
+ while (true)
+ {
+ cur = (UndoableEdit) edits.get(indexOfNextAdd);
+ indexOfNextAdd += 1;
+ cur.redo();
+ if (cur == edit)
+ return;
+ }
+ }
+
+
+ /**
+ * Undoes or redoes the last action. If the last action has already
+ * been undone, it will be re-done, and vice versa.
+ *
+ * <p>This is useful for applications that do not present a separate
+ * undo and redo facility, but just have a single menu item for
+ * undoing and redoing the very last action. Such applications will
+ * use an <code>UndoManager</code> whose <code>limit</code> is 1.
+ */
+ public synchronized void undoOrRedo()
+ throws CannotRedoException, CannotUndoException
+ {
+ if (indexOfNextAdd == edits.size())
+ undo();
+ else
+ redo();
+ }
+
+
+ /**
+ * Determines whether it would be possible to either undo or redo
+ * this editing action.
+ *
+ * <p>This is useful for applications that do not present a separate
+ * undo and redo facility, but just have a single menu item for
+ * undoing and redoing the very last action. Such applications will
+ * use an <code>UndoManager</code> whose <code>limit</code> is 1.
+ *
+ * @return <code>true</code> to indicate that this action can be
+ * undone or redone; <code>false</code> if neither is possible at
+ * the current time.
+ */
+ public synchronized boolean canUndoOrRedo()
+ {
+ return indexOfNextAdd == edits.size() ? canUndo() : canRedo();
+ }
+
+
+ /**
+ * Undoes one significant edit action. If insignificant actions have
+ * been posted after the last signficant action, the insignificant
+ * ones will be undone first.
+ *
+ * <p>However, if {@link #end()} has been called on this
+ * UndoManager, it will behave like a normal {@link
+ * CompoundEdit}. In this case, all actions will be undone in
+ * reverse order of addition. Typical applications will never call
+ * {@link #end()} on their <code>UndoManager</code>.
+ *
+ * @throws CannotUndoException if no action can be undone.
+ *
+ * @see #canUndo()
+ * @see #redo()
+ * @see #undoOrRedo()
+ */
+ public synchronized void undo()
+ throws CannotUndoException
+ {
+ if (!isInProgress())
+ {
+ super.undo();
+ return;
+ }
+
+ UndoableEdit edit = editToBeUndone();
+ if (edit == null)
+ throw new CannotUndoException();
+
+ undoTo(edit);
+ }
+
+
+ /**
+ * Determines whether it would be possible to undo this editing
+ * action.
+ *
+ * @return <code>true</code> to indicate that this action can be
+ * undone; <code>false</code> otherwise.
+ *
+ * @see #undo()
+ * @see #canRedo()
+ * @see #canUndoOrRedo()
+ */
+ public synchronized boolean canUndo()
+ {
+ UndoableEdit edit;
+
+ if (!isInProgress())
+ return super.canUndo();
+
+ edit = editToBeUndone();
+ return edit != null && edit.canUndo();
+ }
+
+
+
+ /**
+ * Redoes one significant edit action. If insignificant actions have
+ * been posted in between, the insignificant ones will be redone
+ * first.
+ *
+ * <p>However, if {@link #end()} has been called on this
+ * UndoManager, it will behave like a normal {@link
+ * CompoundEdit}. In this case, <em>all</em> actions will be redone
+ * in order of addition. Typical applications will never call {@link
+ * #end()} on their <code>UndoManager</code>.
+ *
+ * @throws CannotRedoException if no action can be redone.
+ *
+ * @see #canRedo()
+ * @see #redo()
+ * @see #undoOrRedo()
+ */
+ public synchronized void redo()
+ throws CannotRedoException
+ {
+ if (!isInProgress())
+ {
+ super.redo();
+ return;
+ }
+
+ UndoableEdit edit = editToBeRedone();
+ if (edit == null)
+ throw new CannotRedoException();
+
+ redoTo(edit);
+ }
+
+
+ /**
+ * Determines whether it would be possible to redo this editing
+ * action.
+ *
+ * @return <code>true</code> to indicate that this action can be
+ * redone; <code>false</code> otherwise.
+ *
+ * @see #redo()
+ * @see #canUndo()
+ * @see #canUndoOrRedo()
+ */
+ public synchronized boolean canRedo()
+ {
+ UndoableEdit edit;
+
+ if (!isInProgress())
+ return super.canRedo();
+
+ edit = editToBeRedone();
+ return edit != null && edit.canRedo();
+ }
+
+
+ /**
+ * Registers an undoable editing action with this UndoManager. If
+ * the capacity <code>limit</code> is reached, the oldest action
+ * will be discarded (and receives a {@linkplain UndoableEdit#die()
+ * die message}. Equally, any actions that were undone (but not re-done)
+ * will be discarded, too.
+ *
+ * @param edit the editing action that is added to this UndoManager.
+ *
+ * @return <code>true</code> if <code>edit</code> could be
+ * incorporated; <code>false</code> if <code>edit</code> has not
+ * been incorporated because {@link #end()} has already been called
+ * on this <code>UndoManager</code>.
+ */
+ public synchronized boolean addEdit(UndoableEdit edit)
+ {
+ boolean result;
+
+ // Discard any edits starting at indexOfNextAdd.
+ trimEdits(indexOfNextAdd, edits.size() - 1);
+
+ result = super.addEdit(edit);
+ indexOfNextAdd = edits.size();
+ trimForLimit();
+ return result;
+ }
+
+
+ /**
+ * Calculates a localized text for presenting the undo or redo
+ * action to the user, for example in the form of a menu command.
+ *
+ * <p>This is useful for applications that do not present a separate
+ * undo and redo facility, but just have a single menu item for
+ * undoing and redoing the very last action. Such applications will
+ * use an <code>UndoManager</code> whose <code>limit</code> is 1.
+ *
+ * @return the redo presentation name if the last action has already
+ * been undone, or the undo presentation name otherwise.
+ *
+ * @see #getUndoPresentationName()
+ * @see #getRedoPresentationName()
+ */
+ public synchronized String getUndoOrRedoPresentationName()
+ {
+ if (indexOfNextAdd == edits.size())
+ return getUndoPresentationName();
+ else
+ return getRedoPresentationName();
+ }
+
+
+ /**
+ * Calculates a localized text for presenting the undo action
+ * to the user, for example in the form of a menu command.
+ */
+ public synchronized String getUndoPresentationName()
+ {
+ UndoableEdit edit;
+
+ if (!isInProgress())
+ return super.getUndoPresentationName();
+
+ edit = editToBeUndone();
+ if (edit == null)
+ return UIManager.getString("AbstractUndoableEdit.undoText");
+ else
+ return edit.getUndoPresentationName();
+ }
+
+
+ /**
+ * Calculates a localized text for presenting the redo action
+ * to the user, for example in the form of a menu command.
+ */
+ public synchronized String getRedoPresentationName()
+ {
+ UndoableEdit edit;
+
+ if (!isInProgress())
+ return super.getRedoPresentationName();
+
+ edit = editToBeRedone();
+ if (edit == null)
+ return UIManager.getString("AbstractUndoableEdit.redoText");
+ else
+ return edit.getRedoPresentationName();
+ }
+
+
+ /**
+ * Registers the edit action of an {@link UndoableEditEvent}
+ * with this UndoManager.
+ *
+ * <p><b>Thread Safety:</b> This method may safely be invoked from
+ * concurrent threads. The caller does not need to perform external
+ * synchronization. This means that {@link
+ * javax.swing.event.UndoableEditEvent} sources do not need to broadcast
+ * their events from inside the Swing worker thread.
+ *
+ * @param event the event whose <code>edit</code> will be
+ * passed to {@link #addEdit}.
+ *
+ * @see UndoableEditEvent#getEdit()
+ * @see #addEdit
+ */
+ public void undoableEditHappened(UndoableEditEvent event)
+ {
+ // Note that this method does not need to be synchronized,
+ // because addEdit will obtain and release the mutex.
+ addEdit(event.getEdit());
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoableEdit.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoableEdit.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoableEdit.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoableEdit.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,157 @@
+/* UndoableEdit.java --
+ Copyright (C) 2002, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.undo;
+
+/**
+ * An editing operation that supports undo/redoability.
+ *
+ * @author Andrew Selkirk
+ */
+public interface UndoableEdit
+{
+
+ /**
+ * Incorporates another editing action into this one, thus forming a
+ * combined action.
+ *
+ * @param edit the editing action to be incorporated.
+ *
+ * @return <code>true</code> if the edit was combined successfully, and
+ * <code>false</code> if it could not be combined.
+ */
+ boolean addEdit(UndoableEdit edit);
+
+ /**
+ * Determines whether it would be possible to redo this editing
+ * action.
+ *
+ * @return <code>true</code> to indicate that this action can be
+ * redone, <code>false</code> otherwise.
+ *
+ * @see #redo()
+ * @see #canUndo()
+ */
+ boolean canRedo();
+
+ /**
+ * Determines whether it would be possible to undo this editing
+ * action.
+ *
+ * @return <code>true</code> to indicate that this action can be
+ * undone, <code>false</code> otherwise.
+ *
+ * @see #undo()
+ * @see #canRedo()
+ */
+ boolean canUndo();
+
+ /**
+ * Informs this edit action that it will no longer be used. Some
+ * actions might use this information to release resources, for
+ * example open files. Called by {@link UndoManager} before this
+ * action is removed from the edit queue.
+ */
+ void die();
+
+ /**
+ * Returns a human-readable, localized name that describes this
+ * editing action and can be displayed to the user.
+ *
+ * @return The presentation name.
+ */
+ String getPresentationName();
+
+ /**
+ * Returns the redo presentation name.
+ *
+ * @return The redo presentation name.
+ */
+ String getRedoPresentationName();
+
+ /**
+ * Returns the undo presentation name.
+ *
+ * @return The undo presentation name.
+ */
+ String getUndoPresentationName();
+
+ /**
+ * Determines whether this editing action is significant enough for
+ * being seperately undoable by the user. A typical significant
+ * action would be the resizing of an object. However, changing the
+ * selection in a text document would usually not be considered
+ * significant.
+ *
+ * @return <code>true</code> to indicate that the action is
+ * significant enough for being separately undoable, or
+ * <code>false</code> otherwise.
+ */
+ boolean isSignificant();
+
+ /**
+ * Redoes this editing action.
+ *
+ * @throws CannotRedoException if the edit cannot be undone.
+ *
+ * @see #canRedo()
+ * @see #undo()
+ */
+ void redo() throws CannotRedoException;
+
+ /**
+ * Incorporates another editing action into this one, thus forming a
+ * combined action that replaces the argument action.
+ *
+ * @param edit the editing action to be replaced.
+ *
+ * @return <code>true</code> if the edit is successfully replaced, and
+ * <code>false</code> otherwise.
+ */
+ boolean replaceEdit(UndoableEdit edit);
+
+ /**
+ * Undoes this editing action.
+ *
+ * @throws CannotUndoException if the edit cannot be undone.
+ *
+ * @see #canUndo()
+ * @see #redo()
+ */
+ void undo() throws CannotUndoException;
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoableEditSupport.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoableEditSupport.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoableEditSupport.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/UndoableEditSupport.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,271 @@
+/* UndoableEditSupport.java --
+ Copyright (C) 2002, 2003, 2004, 2005, 2006, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.undo;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import javax.swing.event.UndoableEditEvent;
+import javax.swing.event.UndoableEditListener;
+
+/**
+ * A helper class for supporting {@link
+ * javax.swing.event.UndoableEditListener}.
+ *
+ * @author Andrew Selkirk (aselkirk at sympatico.ca)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+public class UndoableEditSupport
+{
+ /**
+ * The number of times that {@link #beginUpdate()} has been called
+ * without a matching call to {@link #endUpdate()}.
+ */
+ protected int updateLevel;
+
+
+ /**
+ * compoundEdit
+ */
+ protected CompoundEdit compoundEdit;
+
+
+ /**
+ * The currently registered listeners.
+ */
+ protected Vector listeners = new Vector();
+
+
+ /**
+ * The source of the broadcast UndoableEditEvents.
+ */
+ protected Object realSource;
+
+
+ /**
+ * Constructs a new helper for broadcasting UndoableEditEvents. The
+ * events will indicate the newly constructed
+ * <code>UndoableEditSupport</code> instance as their source.
+ *
+ * @see #UndoableEditSupport(java.lang.Object)
+ */
+ public UndoableEditSupport()
+ {
+ realSource = this;
+ }
+
+
+ /**
+ * Constructs a new helper for broadcasting UndoableEditEvents.
+ *
+ * @param realSource the source of the UndoableEditEvents that will
+ * be broadcast by this helper. If <code>realSource</code> is
+ * <code>null</code>, the events will indicate the newly constructed
+ * <code>UndoableEditSupport</code> instance as their source.
+ */
+ public UndoableEditSupport(Object realSource)
+ {
+ if (realSource == null)
+ realSource = this;
+ this.realSource = realSource;
+ }
+
+
+ /**
+ * Returns a string representation of this object that may be useful
+ * for debugging.
+ */
+ public String toString()
+ {
+ // Note that often, this.realSource == this. Therefore, dumping
+ // realSource without additional checks may lead to infinite
+ // recursion. See Classpath bug #7119.
+ return super.toString() + " updateLevel: " + updateLevel
+ + " listeners: " + listeners + " compoundEdit: " + compoundEdit;
+ }
+
+
+ /**
+ * Registers a listener.
+ *
+ * @param val the listener to be added.
+ */
+ public synchronized void addUndoableEditListener(UndoableEditListener val)
+ {
+ listeners.add(val);
+ }
+
+
+ /**
+ * Unregisters a listener.
+ * @param val the listener to be removed.
+ */
+ public synchronized void removeUndoableEditListener(UndoableEditListener val)
+ {
+ listeners.removeElement(val);
+ }
+
+
+ /**
+ * Returns an array containing the currently registered listeners.
+ */
+ public synchronized UndoableEditListener[] getUndoableEditListeners()
+ {
+ UndoableEditListener[] result = new UndoableEditListener[listeners.size()];
+ return (UndoableEditListener[]) listeners.toArray(result);
+ }
+
+
+ /**
+ * Notifies all registered listeners that an {@link
+ * UndoableEditEvent} has occured.
+ *
+ * <p><b>Lack of Thread Safety:</b> It is <em>not</em> safe to call
+ * this method from concurrent threads, unless the call is protected
+ * by a synchronization on this <code>UndoableEditSupport</code>
+ * instance.
+ *
+ * @param edit the edit action to be posted.
+ */
+ protected void _postEdit(UndoableEdit edit)
+ {
+ UndoableEditEvent event;
+ Iterator iter;
+
+ // Do nothing if we have no listeners.
+ if (listeners.isEmpty())
+ return;
+
+ event = new UndoableEditEvent(realSource, edit);
+
+ // We clone the vector because this allows listeners to register
+ // or unregister listeners in their undoableEditHappened method.
+ // Otherwise, this would throw exceptions (in the case of
+ // Iterator, a java.util.ConcurrentModificationException; in the
+ // case of a direct loop over the Vector elements, some
+ // index-out-of-bounds exception).
+ iter = ((Vector) listeners.clone()).iterator();
+ while (iter.hasNext())
+ ((UndoableEditListener) iter.next()).undoableEditHappened(event);
+ }
+
+
+ /**
+ * If {@link #beginUpdate} has been called (so that the current
+ * update level is greater than zero), adds the specified edit
+ * to {@link #compoundEdit}. Otherwise, notify listeners of the
+ * edit by calling {@link #_postEdit(UndoableEdit)}.
+ *
+ * <p><b>Thread Safety:</b> It is safe to call this method from any
+ * thread without external synchronization.
+ *
+ * @param edit the edit action to be posted.
+ */
+ public synchronized void postEdit(UndoableEdit edit)
+ {
+ if (compoundEdit != null)
+ compoundEdit.addEdit(edit);
+ else
+ _postEdit(edit);
+ }
+
+
+ /**
+ * Returns the current update level.
+ */
+ public int getUpdateLevel()
+ {
+ return updateLevel;
+ }
+
+
+ /**
+ * Starts a (possibly nested) update session. If the current update
+ * level is zero, {@link #compoundEdit} is set to the result of the
+ * {@link #createCompoundEdit} method. In any case, the update level
+ * is increased by one.
+ *
+ * <p><b>Thread Safety:</b> It is safe to call this method from any
+ * thread without external synchronization.
+ */
+ public synchronized void beginUpdate()
+ {
+ if (compoundEdit == null)
+ compoundEdit = createCompoundEdit();
+ ++updateLevel;
+ }
+
+
+ /**
+ * Creates a new instance of {@link CompoundEdit}. Called by {@link
+ * #beginUpdate}. If a subclass wants {@link #beginUpdate} to work
+ * on a specific {@link #compoundEdit}, it should override this
+ * method.
+ *
+ * @return a newly created instance of {@link CompoundEdit}.
+ */
+ protected CompoundEdit createCompoundEdit()
+ {
+ return new CompoundEdit();
+ }
+
+
+ /**
+ * Ends an update session. If the terminated session was the
+ * outermost session, {@link #compoundEdit} will receive an
+ * <code>end</code> message, and {@link #_postEdit} gets called in
+ * order to notify any listeners. Finally, the
+ * <code>compoundEdit</code> is discarded.
+ *
+ * <p><b>Thread Safety:</b> It is safe to call this method from any
+ * thread without external synchronization.
+ */
+ public synchronized void endUpdate()
+ {
+ if (updateLevel == 0)
+ throw new IllegalStateException();
+
+ if (--updateLevel > 0)
+ return;
+
+ compoundEdit.end();
+ _postEdit(compoundEdit);
+ compoundEdit = null;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/swing/undo/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.swing.undo package.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - javax.swing.undo</title></head>
+
+<body>
+<p>Provides a mechanism to support undo/redo operations.</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicCommitException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicCommitException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicCommitException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicCommitException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,57 @@
+/* HeuristicCommitException.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.transaction;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public class HeuristicCommitException extends Exception
+{
+ public HeuristicCommitException ()
+ {
+ super();
+ }
+
+ public HeuristicCommitException (String msg)
+ {
+ super(msg);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicMixedException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicMixedException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicMixedException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicMixedException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,57 @@
+/* HeuristicMixedException.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.transaction;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public class HeuristicMixedException extends Exception
+{
+ public HeuristicMixedException ()
+ {
+ super();
+ }
+
+ public HeuristicMixedException (String msg)
+ {
+ super(msg);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicRollbackException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicRollbackException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicRollbackException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/HeuristicRollbackException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,57 @@
+/* HeuristicRollbackException.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.transaction;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public class HeuristicRollbackException extends Exception
+{
+ public HeuristicRollbackException ()
+ {
+ super();
+ }
+
+ public HeuristicRollbackException (String msg)
+ {
+ super(msg);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/InvalidTransactionException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/InvalidTransactionException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/InvalidTransactionException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/InvalidTransactionException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,58 @@
+/* InvalidTransactionException.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.transaction;
+
+import java.rmi.RemoteException;
+
+/**
+ * @author Tom Tromey (tromey at redhat.com)
+ * @date April 18, 2001
+ */
+
+public class InvalidTransactionException extends RemoteException
+{
+ public InvalidTransactionException ()
+ {
+ super();
+ }
+
+ public InvalidTransactionException (String msg)
+ {
+ super(msg);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/NotSupportedException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/NotSupportedException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/NotSupportedException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/NotSupportedException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,57 @@
+/* NotSupportedException.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.transaction;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public class NotSupportedException extends Exception
+{
+ public NotSupportedException ()
+ {
+ super();
+ }
+
+ public NotSupportedException (String msg)
+ {
+ super(msg);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/RollbackException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/RollbackException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/RollbackException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/RollbackException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,57 @@
+/* RollbackException.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.transaction;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public class RollbackException extends Exception
+{
+ public RollbackException ()
+ {
+ super();
+ }
+
+ public RollbackException (String msg)
+ {
+ super(msg);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Status.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Status.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Status.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Status.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,58 @@
+/* Status.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.transaction;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public interface Status
+{
+ int STATUS_ACTIVE = 0;
+ int STATUS_MARKED_ROLLBACK = 1;
+ int STATUS_PREPARED = 2;
+ int STATUS_COMMITTED = 3;
+ int STATUS_ROLLEDBACK = 4;
+ int STATUS_UNKNOWN = 5;
+ int STATUS_NO_TRANSACTION = 6;
+ int STATUS_PREPARING = 7;
+ int STATUS_COMMITTING = 8;
+ int STATUS_ROLLING_BACK = 9;
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Synchronization.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Synchronization.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Synchronization.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Synchronization.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,50 @@
+/* Synchronization.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.transaction;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public interface Synchronization
+{
+ void beforeCompletion();
+ void afterCompletion(int status);
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/SystemException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/SystemException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/SystemException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/SystemException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,65 @@
+/* SystemException.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.transaction;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public class SystemException extends Exception
+{
+ public int errorCode;
+
+ public SystemException ()
+ {
+ super();
+ }
+
+ public SystemException (String msg)
+ {
+ super(msg);
+ }
+
+ public SystemException(int errcode)
+ {
+ super ();
+ this.errorCode = errcode;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Transaction.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Transaction.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Transaction.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/Transaction.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,70 @@
+/* Transaction.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.transaction;
+
+import javax.transaction.xa.XAResource;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public interface Transaction
+{
+ void commit()
+ throws RollbackException, HeuristicMixedException,
+ HeuristicRollbackException, SecurityException, SystemException;
+
+ boolean delistResource(XAResource xaRes, int flag)
+ throws IllegalStateException, SystemException;
+
+ boolean enlistResource(XAResource xaRes)
+ throws RollbackException, IllegalStateException, SystemException;
+
+ int getStatus() throws SystemException;
+
+ void registerSynchronization(Synchronization sync)
+ throws RollbackException, IllegalStateException, SystemException;
+
+ void rollback()
+ throws IllegalStateException, SystemException;
+
+ void setRollbackOnly()
+ throws IllegalStateException, SystemException;
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionManager.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionManager.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionManager.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionManager.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,72 @@
+/* TransactionManager.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.transaction;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public interface TransactionManager
+{
+ void begin() throws NotSupportedException, SystemException;
+
+ void commit()
+ throws RollbackException, HeuristicMixedException,
+ HeuristicRollbackException, SecurityException,
+ IllegalStateException, SystemException;
+
+ int getStatus() throws SystemException;
+
+ Transaction getTransaction() throws SystemException;
+
+ void resume(Transaction tobj)
+ throws InvalidTransactionException, IllegalStateException,
+ SystemException;
+
+ void rollback()
+ throws IllegalStateException, SecurityException, SystemException;
+
+ void setRollbackOnly()
+ throws IllegalStateException, SystemException;
+
+ void setTransactionTimeout(int seconds) throws SystemException;
+
+ Transaction suspend() throws SystemException;
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionRequiredException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionRequiredException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionRequiredException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionRequiredException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,58 @@
+/* TransactionRequiredException --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.transaction;
+
+import java.rmi.RemoteException;
+
+/**
+ * @author Tom Tromey (tromey at redhat.com)
+ * @date April 18, 2001
+ */
+
+public class TransactionRequiredException extends RemoteException
+{
+ public TransactionRequiredException ()
+ {
+ super();
+ }
+
+ public TransactionRequiredException (String msg)
+ {
+ super(msg);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionRolledbackException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionRolledbackException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionRolledbackException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/TransactionRolledbackException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,58 @@
+/* TransactionRolledbackException --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.transaction;
+
+import java.rmi.RemoteException;
+
+/**
+ * @author Tom Tromey (tromey at redhat.com)
+ * @date April 18, 2001
+ */
+
+public class TransactionRolledbackException extends RemoteException
+{
+ public TransactionRolledbackException ()
+ {
+ super();
+ }
+
+ public TransactionRolledbackException (String msg)
+ {
+ super(msg);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/UserTransaction.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/UserTransaction.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/UserTransaction.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/UserTransaction.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,64 @@
+/* UserTransaction.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.transaction;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public interface UserTransaction
+{
+ void begin() throws NotSupportedException, SystemException;
+
+ void commit()
+ throws RollbackException, HeuristicMixedException,
+ HeuristicRollbackException, SecurityException,
+ IllegalStateException, SystemException;
+
+ void rollback()
+ throws IllegalStateException, SecurityException, SystemException;
+
+ void setRollbackOnly()
+ throws IllegalStateException, SystemException;
+
+ int getStatus() throws SystemException;
+
+ void setTransactionTimeout(int seconds) throws SystemException;
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.transaction package.
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - javax.transaction</title></head>
+
+<body>
+<p></p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/XAException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/XAException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/XAException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/XAException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,89 @@
+/* XAException.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.transaction.xa;
+
+/**
+ * @author Tom Tromey (tromey at redhat.com)
+ * @date April 18, 2001
+ */
+
+public class XAException extends Exception
+{
+ public int errorCode;
+ public static final int XA_RBBASE = 100;
+ public static final int XA_RBROLLBACK = 100;
+ public static final int XA_RBCOMMFAIL = 101;
+ public static final int XA_RBDEADLOCK = 102;
+ public static final int XA_RBINTEGRITY = 103;
+ public static final int XA_RBOTHER = 104;
+ public static final int XA_RBPROTO = 105;
+ public static final int XA_RBTIMEOUT = 106;
+ public static final int XA_RBTRANSIENT = 107;
+ public static final int XA_RBEND = 107;
+ public static final int XA_NOMIGRATE = 9;
+ public static final int XA_HEURHAZ = 8;
+ public static final int XA_HEURCOM = 7;
+ public static final int XA_HEURRB = 6;
+ public static final int XA_HEURMIX = 5;
+ public static final int XA_RETRY = 4;
+ public static final int XA_RDONLY = 3;
+ public static final int XAER_ASYNC = -2;
+ public static final int XAER_RMERR = -3;
+ public static final int XAER_NOTA = -4;
+ public static final int XAER_INVAL = -5;
+ public static final int XAER_PROTO = -6;
+ public static final int XAER_RMFAIL = -7;
+ public static final int XAER_DUPID = -8;
+ public static final int XAER_OUTSIDE = -9;
+
+ public XAException ()
+ {
+ super ();
+ }
+
+ public XAException (String msg)
+ {
+ super (msg);
+ }
+
+ public XAException (int errcode)
+ {
+ super ();
+ this.errorCode = errcode;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/XAResource.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/XAResource.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/XAResource.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/XAResource.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,69 @@
+/* XAResource.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.transaction.xa;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public interface XAResource
+{
+ int TMENDRSCAN = 8388608;
+ int TMFAIL = 536870912;
+ int TMJOIN = 2097152;
+ int TMNOFLAGS = 0;
+ int TMONEPHASE = 1073741824;
+ int TMRESUME = 134217728;
+ int TMSTARTRSCAN = 16777216;
+ int TMSUCCESS = 67108864;
+ int TMSUSPEND = 33554432;
+ int XA_RDONLY = 3;
+ int XA_OK = 0;
+
+ void commit(Xid xid, boolean onePhase) throws XAException;
+ void end(Xid xid, int flags) throws XAException;
+ void forget(Xid xid) throws XAException;
+ int getTransactionTimeout() throws XAException;
+ boolean isSameRM(XAResource xares) throws XAException;
+ int prepare(Xid xid) throws XAException;
+ Xid[] recover(int flag) throws XAException;
+ void rollback(Xid xid) throws XAException;
+ boolean setTransactionTimeout(int seconds) throws XAException;
+ void start(Xid xid, int flags) throws XAException;
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/Xid.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/Xid.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/Xid.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/Xid.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,53 @@
+/* Xid.java --
+ Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.transaction.xa;
+
+/**
+ * @author Warren Levy (warrenl at redhat.com)
+ * @date May 25, 2001
+ */
+
+public interface Xid
+{
+ int MAXGTRIDSIZE = 64;
+ int MAXBQUALSIZE = 64;
+
+ int getFormatId();
+ byte[] getGlobalTransactionId();
+ byte[] getBranchQualifier();
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/transaction/xa/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.transaction.xa package.
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - javax.transaction.xa</title></head>
+
+<body>
+<p></p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/XMLConstants.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/XMLConstants.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/XMLConstants.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/XMLConstants.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,131 @@
+/* XMLConstants.java --
+ Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml;
+
+/**
+ * Repository for well-known XML constants.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ * @since 1.5
+ */
+public final class XMLConstants
+{
+
+ private XMLConstants()
+ {
+ // to prevent instantiation
+ }
+
+ /**
+ * Dummy namespace URI indicating that there is no namespace.
+ * @see http://www.w3.org/TR/REC-xml-names/#defaulting
+ */
+ public static final String NULL_NS_URI = "";
+
+ /**
+ * Dummy namespace prefix indicating that there is no namespace.
+ * @see http://www.w3.org/TR/REC-xml-names/#ns-qualnames
+ */
+ public static final String DEFAULT_NS_PREFIX = "";
+
+ /**
+ * The XML Namespace URI.
+ * @see http://www.w3.org/TR/REC-xml-names/#ns-qualnames
+ */
+ public static final String XML_NS_URI =
+ "http://www.w3.org/XML/1998/namespace";
+
+ /**
+ * The XML Namespace prefix.
+ * @see http://www.w3.org/TR/REC-xml-names/#ns-qualnames
+ */
+ public static final String XML_NS_PREFIX = "xml";
+
+ /**
+ * The XML Namespace declaration URI.
+ * @see http://www.w3.org/TR/REC-xml-names/#ns-qualnames
+ */
+ public static final String XMLNS_ATTRIBUTE_NS_URI =
+ "http://www.w3.org/2000/xmlns/";
+
+ /**
+ * The XML Namespace declaration attribute.
+ * @see http://www.w3.org/TR/REC-xml-names/#ns-qualnames
+ */
+ public static final String XMLNS_ATTRIBUTE = "xmlns";
+
+ /**
+ * The XML Schema (XSD) namespace URI.
+ * @see http://www.w3.org/TR/xmlschema-1/#Instance_Document_Constructions
+ */
+ public static final String W3C_XML_SCHEMA_NS_URI =
+ "http://www.w3.org/2001/XMLSchema";
+
+ /**
+ * The XML Schema Instance (XSI) namespace URI.
+ * @see http://www.w3.org/TR/xmlschema-1/#Instance_Document_Constructions
+ */
+ public static final String W3C_XML_SCHEMA_INSTANCE_NS_URI =
+ "http://www.w3.org/2001/XMLSchema-instance";
+
+ /**
+ * The XPath 2.0 datatypes namespace URI.
+ * @see http://www.w3.org/TR/xpath-datamodel
+ */
+ public static final String W3C_XPATH_DATATYPE_NS_URI =
+ "http://www.w3.org/2003/11/xpath-datatypes";
+
+ /**
+ * The XML DTD namespace URI.
+ */
+ public static final String XML_DTD_NS_URI = "http://www.w3.org/TR/REC-xml";
+
+ /**
+ * The RELAX NG Namespace URI.
+ * @see http://relaxng.org/spec-20011203.html
+ */
+ public static final String RELAXNG_NS_URI =
+ "http://relaxng.org/ns/structure/1.0";
+
+ /**
+ * DOM feature for secure processing.
+ */
+ public static final String FEATURE_SECURE_PROCESSING =
+ "http://javax.xml.XMLConstants/feature/secure-processing";
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeConfigurationException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeConfigurationException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeConfigurationException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeConfigurationException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,70 @@
+/* DatatypeConfigurationException.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.datatype;
+
+/**
+ * A serious error during datatype configuration.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ * @since 1.3
+ */
+public class DatatypeConfigurationException
+ extends Exception
+{
+
+ public DatatypeConfigurationException()
+ {
+ super();
+ }
+
+ public DatatypeConfigurationException(String message)
+ {
+ super(message);
+ }
+
+ public DatatypeConfigurationException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public DatatypeConfigurationException(Throwable cause)
+ {
+ super(cause);
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeConstants.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeConstants.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeConstants.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeConstants.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,264 @@
+/* DatatypeConstants.java --
+ Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.datatype;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Basic data type constants.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ * @since 1.5
+ */
+public final class DatatypeConstants
+{
+
+ private DatatypeConstants()
+ {
+ // to prevent instantiation
+ }
+
+ /**
+ * Typesafe enumerated class representing the six fields of the
+ * <a href='Duration.html'>Duration</a> class.
+ */
+ public static final class Field
+ {
+
+ final int id;
+ final String name;
+
+ Field(int id, String name)
+ {
+ this.id = id;
+ this.name = name;
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+
+ }
+
+ /**
+ * Value for January.
+ */
+ public static final int JANUARY = 1;
+
+ /**
+ * Value for February.
+ */
+ public static final int FEBRUARY = 2;
+
+ /**
+ * Value for March.
+ */
+ public static final int MARCH = 3;
+
+ /**
+ * Value for April.
+ */
+ public static final int APRIL = 4;
+
+ /**
+ * Value for May.
+ */
+ public static final int MAY = 5;
+
+ /**
+ * Value for June.
+ */
+ public static final int JUNE = 6;
+
+ /**
+ * Value for July.
+ */
+ public static final int JULY = 7;
+
+ /**
+ * Value for August.
+ */
+ public static final int AUGUST = 8;
+
+ /**
+ * Value for September.
+ */
+ public static final int SEPTEMBER = 9;
+
+ /**
+ * Value for October.
+ */
+ public static final int OCTOBER = 10;
+
+ /**
+ * Value for November.
+ */
+ public static final int NOVEMBER = 11;
+
+ /**
+ * Value for December.
+ */
+ public static final int DECEMBER = 12;
+
+ /**
+ * Comparison result.
+ */
+ public static final int LESSER = -1;
+
+ /**
+ * Comparison result.
+ */
+ public static final int EQUAL = 0;
+
+ /**
+ * Comparison result.
+ */
+ public static final int GREATER = 1;
+
+ /**
+ * Comparison result.
+ */
+ public static final int INDETERMINATE = 2;
+
+ /**
+ * Comparison result.
+ */
+ public static final int FIELD_UNDEFINED = -2147483648;
+
+ /**
+ * Constant that represents the years field.
+ */
+ public static final Field YEARS = new Field(1, "YEARS");
+
+ /**
+ * Constant that represents the months field.
+ */
+ public static final Field MONTHS = new Field(2, "MONTHS");
+
+ /**
+ * Constant that represents the days field.
+ */
+ public static final Field DAYS = new Field(3, "DAYS");
+
+ /**
+ * Constant that represents the hours field.
+ */
+ public static final Field HOURS = new Field(4, "HOURS");
+
+ /**
+ * Constant that represents the minutes field.
+ */
+ public static final Field MINUTES = new Field(5, "MINUTES");
+
+ /**
+ * Constant that represents the seconds field.
+ */
+ public static final Field SECONDS = new Field(6, "SECONDS");
+
+ /**
+ * The qualified-name for the <code>dateTime</code> data type.
+ */
+ public static final QName DATETIME = new QName ("http://www.w3.org/2001/XMLSchema#dateTime", "");
+
+ /**
+ * The qualified-name for the <code>time</code> data type.
+ */
+ public static final QName TIME = new QName ("http://www.w3.org/2001/XMLSchema#time", "");
+
+ /**
+ * The qualified-name for the <code>date</code> data type.
+ */
+ public static final QName DATE = new QName ("http://www.w3.org/2001/XMLSchema#date", "");
+
+ /**
+ * The qualified-name for the <code>gYearMonth</code> data type.
+ */
+ public static final QName GYEARMONTH = new QName ("http://www.w3.org/2001/XMLSchema#gYearMonth", "");
+
+ /**
+ * The qualified-name for the <code>gMonthDay</code> data type.
+ */
+ public static final QName GMONTHDAY = new QName ("http://www.w3.org/2001/XMLSchema#gMonthDay", "");
+
+ /**
+ * The qualified-name for the <code>gYear</code> data type.
+ */
+ public static final QName GYEAR = new QName ("http://www.w3.org/2001/XMLSchema#gYear", "");
+
+ /**
+ * The qualified-name for the <code>gMonth</code> data type.
+ */
+ public static final QName GMONTH = new QName ("http://www.w3.org/2001/XMLSchema#gMonth", "");
+
+ /**
+ * The qualified-name for the <code>gDay</code> data type.
+ */
+ public static final QName GDAY = new QName ("http://www.w3.org/2001/XMLSchema#gDay", "");
+
+ /**
+ * The qualified-name for the <code>duration</code> data type.
+ */
+ public static final QName DURATION = new QName ("http://www.w3.org/2001/XMLSchema#duration", "");
+
+ /**
+ * The qualified-name for the <code>dayTimeDuration</code> data type.
+ */
+ public static final QName DURATION_DAYTIME = new QName ("http://www.w3.org/2001/XMLSchema#dayTimeDuration", "");
+
+ /**
+ * The qualified-name for the <code>yearMonthDuration</code> data type.
+ */
+ public static final QName DURATION_YEARMONTH = new QName ("http://www.w3.org/2001/XMLSchema#yearMonthDuration", "");
+
+ /**
+ * XML Schema maximum timezone offset, in minutes.
+ */
+ public static final int MAX_TIMEZONE_OFFSET = -840;
+
+ /**
+ * XML Schema minimum timezone offset, in minutes.
+ */
+ public static final int MIN_TIMEZONE_OFFSET = 840;
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeFactory.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeFactory.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeFactory.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/DatatypeFactory.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,424 @@
+/* DatatypeFactory.java --
+ Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.datatype;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.GregorianCalendar;
+import java.util.Iterator;
+import java.util.Properties;
+import gnu.classpath.ServiceFactory;
+
+/**
+ * Factory class to create new datatype objects mapping XML to and from Java
+ * objects.
+ *
+ * @author Chris Burdess
+ * @since 1.5
+ */
+public abstract class DatatypeFactory
+{
+
+ /**
+ * JAXP 1.3 default property name.
+ */
+ public static final String DATATYPEFACTORY_PROPERTY = "javax.xml.datatype.DatatypeFactory";
+
+ /**
+ * JAXP 1.3 default implementation class name.
+ */
+ public static final String DATATYPEFACTORY_IMPLEMENTATION_CLASS = "gnu.xml.datatype.JAXPDatatypeFactory";
+
+ protected DatatypeFactory()
+ {
+ }
+
+ /**
+ * Returns a new factory instance.
+ */
+ public static DatatypeFactory newInstance()
+ throws DatatypeConfigurationException
+ {
+ try
+ {
+ // 1. system property
+ String className = System.getProperty(DATATYPEFACTORY_PROPERTY);
+ if (className != null)
+ return (DatatypeFactory) Class.forName(className).newInstance();
+ // 2. jaxp.properties property
+ File javaHome = new File(System.getProperty("java.home"));
+ File javaHomeLib = new File(javaHome, "lib");
+ File jaxpProperties = new File(javaHomeLib, "jaxp.properties");
+ if (jaxpProperties.exists())
+ {
+ FileInputStream in = new FileInputStream(jaxpProperties);
+ Properties p = new Properties();
+ p.load(in);
+ in.close();
+ className = p.getProperty(DATATYPEFACTORY_PROPERTY);
+ if (className != null)
+ return (DatatypeFactory) Class.forName(className).newInstance();
+ }
+ // 3. services
+ Iterator i = ServiceFactory.lookupProviders(DatatypeFactory.class);
+ if (i.hasNext())
+ return (DatatypeFactory) i.next();
+ // 4. fallback
+ Class t = Class.forName(DATATYPEFACTORY_IMPLEMENTATION_CLASS);
+ return (DatatypeFactory) t.newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new DatatypeConfigurationException(e);
+ }
+ }
+
+ /**
+ * Returns a new duration from its string representation.
+ * @param lexicalRepresentation the lexical representation of the
+ * duration, as specified in XML Schema 1.0 section 3.2.6.1.
+ */
+ public abstract Duration newDuration(String lexicalRepresentation);
+
+ /**
+ * Returns a new duration.
+ * @param durationInMilliSeconds the duration in milliseconds
+ */
+ public abstract Duration newDuration(long durationInMilliSeconds);
+
+ /**
+ * Returns a new duration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param years the number of years
+ * @param months the number of months
+ * @param days the number of days
+ * @param hours the number of hours
+ * @param minutes th number of minutes
+ * @param seconds the number of seconds
+ */
+ public abstract Duration newDuration(boolean isPositive,
+ BigInteger years,
+ BigInteger months,
+ BigInteger days,
+ BigInteger hours,
+ BigInteger minutes,
+ BigDecimal seconds);
+
+ /**
+ * Returns a new duration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param years the number of years
+ * @param months the number of months
+ * @param days the number of days
+ * @param hours the number of hours
+ * @param minutes th number of minutes
+ * @param seconds the number of seconds
+ */
+ public Duration newDuration(boolean isPositive,
+ int years,
+ int months,
+ int days,
+ int hours,
+ int minutes,
+ int seconds)
+ {
+ return newDuration(isPositive,
+ BigInteger.valueOf((long) years),
+ BigInteger.valueOf((long) months),
+ BigInteger.valueOf((long) days),
+ BigInteger.valueOf((long) hours),
+ BigInteger.valueOf((long) minutes),
+ BigDecimal.valueOf((long) seconds));
+ }
+
+ /**
+ * Returns a new dayTimeDuration from its string representation.
+ * @param lexicalRepresentation the lexical representation of the
+ * duration, as specified in XML Schema 1.0 section 3.2.6.1.
+ */
+ public Duration newDurationDayTime(String lexicalRepresentation)
+ {
+ return newDuration(lexicalRepresentation);
+ }
+
+ /**
+ * Returns a new dayTimeDuration.
+ * @param durationInMilliseconds the duration in milliseconds
+ */
+ public Duration newDurationDayTime(long durationInMilliseconds)
+ {
+ // TODO xmlSchemaType
+ return newDuration(durationInMilliseconds);
+ }
+
+ /**
+ * Returns a new dayTimeDuration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param days the number of days
+ * @param hours the number of hours
+ * @param minutes th number of minutes
+ * @param seconds the number of seconds
+ */
+ public Duration newDurationDayTime(boolean isPositive,
+ BigInteger days,
+ BigInteger hours,
+ BigInteger minutes,
+ BigInteger seconds)
+ {
+ return newDuration(isPositive,
+ null,
+ null,
+ days,
+ hours,
+ minutes,
+ new BigDecimal(seconds));
+ }
+
+ /**
+ * Returns a new dayTimeDuration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param days the number of days
+ * @param hours the number of hours
+ * @param minutes th number of minutes
+ * @param seconds the number of seconds
+ */
+ public Duration newDurationDayTime(boolean isPositive,
+ int days,
+ int hours,
+ int minutes,
+ int seconds)
+ {
+ return newDuration(isPositive,
+ null,
+ null,
+ BigInteger.valueOf((long) days),
+ BigInteger.valueOf((long) hours),
+ BigInteger.valueOf((long) minutes),
+ BigDecimal.valueOf((long) seconds));
+ }
+
+ /**
+ * Returns a new yearMonthDuration from its string representation.
+ * @param lexicalRepresentation the lexical representation of the
+ * duration, as specified in XML Schema 1.0 section 3.2.6.1.
+ */
+ public Duration newDurationYearMonth(String lexicalRepresentation)
+ {
+ return newDuration(lexicalRepresentation);
+ }
+
+ /**
+ * Returns a new yearMonthDuration.
+ * @param durationInMilliseconds the duration in milliseconds
+ */
+ public Duration newDurationYearMonth(long durationInMilliseconds)
+ {
+ // TODO xmlSchemaType
+ return newDuration(durationInMilliseconds);
+ }
+
+ /**
+ * Returns a new yearMonthDuration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param years the number of years
+ * @param months the number of months
+ */
+ public Duration newDurationYearMonth(boolean isPositive,
+ BigInteger years,
+ BigInteger months)
+ {
+ return newDuration(isPositive,
+ years,
+ months,
+ null,
+ null,
+ null,
+ null);
+ }
+
+ /**
+ * Returns a new yearMonthDuration by specifying the individual components.
+ * @param isPositive whether the duration is positive
+ * @param years the number of years
+ * @param months the number of months
+ */
+ public Duration newDurationYearMonth(boolean isPositive,
+ int years,
+ int months)
+ {
+ return newDuration(isPositive,
+ BigInteger.valueOf((long) years),
+ BigInteger.valueOf((long) months),
+ null,
+ null,
+ null,
+ null);
+ }
+
+ /**
+ * Returns a new XMLGregorianCalendar with no fields initialized.
+ */
+ public abstract XMLGregorianCalendar newXMLGregorianCalendar();
+
+ /**
+ * Returns a new XMLGregorianCalendar from a string representation.
+ * @param lexicalRepresentation the lexical representation as specified in
+ * XML Schema 1.0 Part 2, section 3.2.[7-14].1.
+ */
+ public abstract XMLGregorianCalendar newXMLGregorianCalendar(String lexicalRepresentation);
+
+ /**
+ * Returns a new XMLGregorianCalendar based on the specified Gregorian
+ * calendar.
+ */
+ public abstract XMLGregorianCalendar newXMLGregorianCalendar(GregorianCalendar cal);
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public abstract XMLGregorianCalendar newXMLGregorianCalendar(BigInteger year,
+ int month,
+ int day,
+ int hour,
+ int minute,
+ int second,
+ BigDecimal fractionalSecond,
+ int timezone);
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public XMLGregorianCalendar newXMLGregorianCalendar(int year,
+ int month,
+ int day,
+ int hour,
+ int minute,
+ int second,
+ int millisecond,
+ int timezone)
+ {
+ return newXMLGregorianCalendar(BigInteger.valueOf((long) year),
+ month,
+ day,
+ hour,
+ minute,
+ second,
+ new BigDecimal(((double) millisecond) / 1000.0),
+ timezone);
+ }
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public XMLGregorianCalendar newXMLGregorianCalendarDate(int year,
+ int month,
+ int day,
+ int timezone)
+ {
+ return newXMLGregorianCalendar(BigInteger.valueOf((long) year),
+ month,
+ day,
+ DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED,
+ null,
+ timezone);
+ }
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
+ int minutes,
+ int seconds,
+ int timezone)
+ {
+ return newXMLGregorianCalendar(null,
+ DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED,
+ hours,
+ minutes,
+ seconds,
+ null,
+ timezone);
+ }
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
+ int minutes,
+ int seconds,
+ BigDecimal fractionalSecond,
+ int timezone)
+ {
+ return newXMLGregorianCalendar(null,
+ DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED,
+ hours,
+ minutes,
+ seconds,
+ fractionalSecond,
+ timezone);
+ }
+
+ /**
+ * Returns a new XMLGregorianCalendar with the specified components.
+ */
+ public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
+ int minutes,
+ int seconds,
+ int milliseconds,
+ int timezone)
+ {
+ return newXMLGregorianCalendar(null,
+ DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED,
+ hours,
+ minutes,
+ seconds,
+ new BigDecimal(((double) milliseconds) / 1000.0),
+ timezone);
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/Duration.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/Duration.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/Duration.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/Duration.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,291 @@
+/* Duration.java --
+ Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.datatype;
+
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import javax.xml.datatype.DatatypeConstants;
+import javax.xml.namespace.QName;
+
+/**
+ * An immutable time space as specified in XML Schema 1.0.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ * @since 1.5
+ */
+public abstract class Duration
+{
+
+ /**
+ * Returns the name of the XML Schema data type this value maps to.
+ */
+ public QName getXMLSchemaType()
+ {
+ int state = 0;
+ state |= isSet(DatatypeConstants.YEARS) ? 32 : 0;
+ state |= isSet(DatatypeConstants.MONTHS) ? 16 : 0;
+ state |= isSet(DatatypeConstants.DAYS) ? 8 : 0;
+ state |= isSet(DatatypeConstants.HOURS) ? 4 : 0;
+ state |= isSet(DatatypeConstants.MINUTES) ? 2 : 0;
+ state |= isSet(DatatypeConstants.SECONDS) ? 1 : 0;
+ switch (state)
+ {
+ case 63:
+ return DatatypeConstants.DURATION;
+ case 15:
+ return DatatypeConstants.DURATION_DAYTIME;
+ case 48:
+ return DatatypeConstants.DURATION_YEARMONTH;
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
+ /**
+ * Returns the sign of this value.
+ */
+ public abstract int getSign();
+
+ /**
+ * Returns the years in this duration as an int, or 0 if not present.
+ */
+ public int getYears()
+ {
+ Number val = getField(DatatypeConstants.YEARS);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the months in this duration as an int, or 0 if not present.
+ */
+ public int getMonths()
+ {
+ Number val = getField(DatatypeConstants.MONTHS);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the days in this duration as an int, or 0 if not present.
+ */
+ public int getDays()
+ {
+ Number val = getField(DatatypeConstants.DAYS);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the hours in this duration as an int, or 0 if not present.
+ */
+ public int getHours()
+ {
+ Number val = getField(DatatypeConstants.HOURS);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the minutes in this duration as an int, or 0 if not present.
+ */
+ public int getMinutes()
+ {
+ Number val = getField(DatatypeConstants.MINUTES);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the seconds in this duration as an int, or 0 if not present.
+ */
+ public int getSeconds()
+ {
+ Number val = getField(DatatypeConstants.SECONDS);
+ return (val == null) ? 0 : val.intValue();
+ }
+
+ /**
+ * Returns the duration length in milliseconds.
+ * Because the length of a month or year may vary depending on the year,
+ * the <code>startInstant</code> parameter is used to specify the duration
+ * offset.
+ */
+ public long getTimeInMillis(Calendar startInstant)
+ {
+ Calendar cal = (Calendar) startInstant.clone();
+ long t1 = cal.getTimeInMillis();
+ addTo(cal);
+ long t2 = cal.getTimeInMillis();
+ return t2 - t1;
+ }
+
+ /**
+ * Returns the duration length in milliseconds.
+ * Because the length of a month or year may vary depending on the year,
+ * the <code>startInstant</code> parameter is used to specify the duration
+ * offset.
+ */
+ public long getTimeInMillis(Date startInstant)
+ {
+ Date date = (Date) startInstant.clone();
+ long t1 = date.getTime();
+ addTo(date);
+ long t2 = date.getTime();
+ return t2 - t1;
+ }
+
+ /**
+ * Returns the value of the specified field, or <code>null</code> if the
+ * field is undefined.
+ */
+ public abstract Number getField(DatatypeConstants.Field field);
+
+ /**
+ * Indicates whether the specified field is set.
+ */
+ public abstract boolean isSet(DatatypeConstants.Field field);
+
+ /**
+ * Returns the result of adding the specified duration to this duration.
+ */
+ public abstract Duration add(Duration rhs);
+
+ /**
+ * Adds this duration to the specified calendar.
+ */
+ public abstract void addTo(Calendar calendar);
+ /*{
+ switch (getSign())
+ {
+ case -1:
+ calendar.add(Calendar.YEAR, -getYears());
+ calendar.add(Calendar.MONTH, -getMonths());
+ calendar.add(Calendar.DATE, -getDays());
+ calendar.add(Calendar.HOUR, -getHours());
+ calendar.add(Calendar.MINUTE, -getMinutes());
+ calendar.add(Calendar.SECOND, -getSeconds());
+ break;
+ case 1:
+ calendar.add(Calendar.YEAR, getYears());
+ calendar.add(Calendar.MONTH, getMonths());
+ calendar.add(Calendar.DATE, getDays());
+ calendar.add(Calendar.HOUR, getHours());
+ calendar.add(Calendar.MINUTE, getMinutes());
+ calendar.add(Calendar.SECOND, getSeconds());
+ }
+ }*/
+
+ /**
+ * Adds this duration to the specified date.
+ */
+ public void addTo(Date date)
+ {
+ Calendar calendar = new GregorianCalendar();
+ calendar.setTimeInMillis(date.getTime());
+ addTo(calendar);
+ date.setTime(calendar.getTimeInMillis());
+ }
+
+ /**
+ * Returns the result of subtracting the given duration from this
+ * duration.
+ */
+ public Duration subtract(Duration rhs)
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Returns the result of multiplying this duration by the given factor.
+ */
+ public Duration multiply(int factor)
+ {
+ return multiply(BigDecimal.valueOf((long) factor));
+ }
+
+ /**
+ * Returns the result of multiplying this duration by the given factor.
+ */
+ public abstract Duration multiply(BigDecimal factor);
+
+ /**
+ * Returns the unary negative of this duration.
+ */
+ public abstract Duration negate();
+
+ /**
+ * Converts the years and months fields into the days field using a
+ * specific time instant as the reference point.
+ */
+ public abstract Duration normalizeWith(Calendar startTimeInstant);
+
+ /**
+ * Partial order relation comparison with this duration, in accordance
+ * with XML Schema 1.0 Part 2, Section 3.2.7.6.2.
+ */
+ public abstract int compare(Duration duration);
+
+ public boolean isLongerThan(Duration duration)
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isShorterThan(Duration duration)
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean equals(java.lang.Object duration)
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public abstract int hashCode();
+
+ /**
+ * Returns the lexical representation of this duration.
+ */
+ public String toString()
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/XMLGregorianCalendar.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/XMLGregorianCalendar.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/XMLGregorianCalendar.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/XMLGregorianCalendar.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,217 @@
+/* XMLGregorianCalendar.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.datatype;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+import javax.xml.namespace.QName;
+
+/**
+ * An XML Schema 1.0 date/time data type.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ * @since 1.3
+ */
+public abstract class XMLGregorianCalendar
+ implements Cloneable
+{
+
+ /**
+ * Resets all fields to undefined.
+ */
+ public abstract void clear();
+
+ /**
+ * Resets all fields to their original values.
+ */
+ public abstract void reset();
+
+ public abstract void setYear(BigInteger year);
+
+ public abstract void setYear(int year);
+
+ public abstract void setMonth(int month);
+
+ public abstract void setDay(int day);
+
+ public abstract void setTimezone(int offset);
+
+ public void setTime(int hour, int minute, int second)
+ {
+ setHour(hour);
+ setMinute(minute);
+ setSecond(second);
+ }
+
+ public abstract void setHour(int hour);
+
+ public abstract void setMinute(int minute);
+
+ public abstract void setSecond(int second);
+
+ public abstract void setMillisecond(int millisecond);
+
+ public abstract void setFractionalSecond(BigDecimal fractional);
+
+ public void setTime(int hour, int minute, int second, BigDecimal fractional)
+ {
+ setHour(hour);
+ setMinute(minute);
+ setSecond(second);
+ setFractionalSecond(fractional);
+ }
+
+ public void setTime(int hour, int minute, int second, int millisecond)
+ {
+ setHour(hour);
+ setMinute(minute);
+ setSecond(second);
+ setMillisecond(millisecond);
+ }
+
+ public abstract BigInteger getEon();
+
+ public abstract int getYear();
+
+ public abstract BigInteger getEonAndYear();
+
+ public abstract int getMonth();
+
+ public abstract int getDay();
+
+ public abstract int getTimezone();
+
+ public abstract int getHour();
+
+ public abstract int getMinute();
+
+ public abstract int getSecond();
+
+ public int getMillisecond()
+ {
+ BigDecimal factor = BigDecimal.valueOf(1000L);
+ BigDecimal val = getFractionalSecond().multiply(factor);
+ return val.intValue();
+ }
+
+ public abstract BigDecimal getFractionalSecond();
+
+ public abstract int compare(XMLGregorianCalendar xmlGregorianCalendar);
+
+ public abstract XMLGregorianCalendar normalize();
+
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof XMLGregorianCalendar)
+ {
+ XMLGregorianCalendar xgc = (XMLGregorianCalendar) obj;
+ BigInteger y1 = getEonAndYear();
+ BigInteger y2 = xgc.getEonAndYear();
+ BigDecimal f1 = getFractionalSecond();
+ BigDecimal f2 = xgc.getFractionalSecond();
+ return ((y1 == null && y2 == null) || (y1 != null && y1.equals(y2))) &&
+ getMonth() == xgc.getMonth() &&
+ getDay() == xgc.getDay() &&
+ getTimezone() == xgc.getTimezone() &&
+ getHour() == xgc.getHour() &&
+ getMinute() == xgc.getMinute() &&
+ getSecond() == xgc.getSecond() &&
+ ((f1 == null && f2 == null) || (f1 != null && f1.equals(f2)));
+ }
+ return false;
+ }
+
+ public int hashCode()
+ {
+ int hash = 0;
+ BigInteger y = getEonAndYear();
+ BigDecimal f = getFractionalSecond();
+ if (y != null)
+ {
+ hash *= 31 + y.hashCode();
+ }
+ hash *= 31 + getMonth();
+ hash *= 31 + getDay();
+ hash *= 31 + getTimezone();
+ hash *= 31 + getHour();
+ hash *= 31 + getMinute();
+ hash *= 31 + getSecond();
+ if (f != null)
+ {
+ hash *= 31 + f.hashCode();
+ }
+ return hash;
+ }
+
+ /**
+ * Returns the XML Schema lexical representation of this calendar.
+ */
+ public abstract String toXMLFormat();
+
+ public abstract QName getXMLSchemaType();
+
+ public String toString()
+ {
+ return toXMLFormat();
+ }
+
+ /**
+ * Determines the validity of this calendar by
+ * <code>getXMLSchemaType</code> constraints.
+ */
+ public abstract boolean isValid();
+
+ /**
+ * Adds the specified duration to this calendar.
+ */
+ public abstract void add(Duration duration);
+
+ public abstract GregorianCalendar toGregorianCalendar();
+
+ public abstract GregorianCalendar toGregorianCalendar(TimeZone timezone,
+ Locale locale,
+ XMLGregorianCalendar defaults);
+
+ public abstract TimeZone getTimeZone(int defaultZoneoffset);
+
+ public abstract Object clone();
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/datatype/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,57 @@
+<body>
+
+<div>
+This package provides type mappings between XML and Java data types.
+</div>
+
+<table summary='XML Schema type mappings'>
+ <tr>
+ <th>XML Schema data type</th><th>Java data type</th>
+ </tr>
+ <tr>
+ <td>xs:date</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:dateTime</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:duration</td><td><a href='Duration.html'>Duration</a></td>
+ </tr>
+ <tr>
+ <td>xs:gDay</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:gMonth</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:gMonthDay</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:gYear</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:gYearMonth</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+ <tr>
+ <td>xs:time</td><td><a href='XMLGregorianCalendar.html'>XMLGregorianCalendar</a></td>
+ </tr>
+</table>
+
+<table summary='XPath 2.0 data type mappings'>
+ <tr>
+ <th>XPath 2.0 data type</th><th>Java data type</th>
+ </tr>
+ <tr>
+ <td>xdt:dayTimeDuration</td><td><a href='Duration.html'>Duration</a></td>
+ </tr>
+ <tr>
+ <td>xdt:yearMonthDuration</td><td><a href='Duration.html'>Duration</a></td>
+ </tr>
+</table>
+
+<div>
+Other XML Schema data types are considered to have a <q>natural</q> mapping to
+Java types, which are defined by the Java Architecture for XML Binding (JAXB).
+</div>
+
+</body>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/NamespaceContext.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/NamespaceContext.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/NamespaceContext.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/NamespaceContext.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,66 @@
+/* NamespaceContext.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.namespace;
+
+import java.util.Iterator;
+
+/**
+ * Interface by which namespace properties are made available.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ * @since 1.3
+ */
+public interface NamespaceContext
+{
+
+ /**
+ * Returns the namespace URI currently bound to the given prefix.
+ */
+ public String getNamespaceURI(String prefix);
+
+ /**
+ * Returns the prefix currently bound to the given namespace URI.
+ */
+ public String getPrefix(String namespaceURI);
+
+ /**
+ * Returns all the prefixes currently bound to the given namespace URI.
+ */
+ public Iterator getPrefixes(String namespaceURI);
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/QName.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/QName.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/QName.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/QName.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,168 @@
+/* QName.java - An XML qualified name.
+ Copyright (C) 2004,2005,2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.xml.namespace;
+
+import java.io.Serializable;
+
+import javax.xml.XMLConstants;
+
+/**
+ * An XML
+ * <a href='http://www.w3.org/TR/REC-xml-names/#ns-qualnames'>qualified name</a>.
+ *
+ * @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
+ * @since 1.3
+ */
+public class QName implements Serializable
+{
+ private static final long serialVersionUID = 4418622981026545151L;
+
+ private final String namespaceURI;
+ private final String localPart;
+ private final String prefix;
+ private transient String qName;
+ transient int hashCode = -1;
+
+ public QName(String namespaceURI, String localPart)
+ {
+ this(namespaceURI, localPart, null);
+ }
+
+ public QName(String namespaceURI, String localPart, String prefix)
+ {
+ if (namespaceURI == null)
+ namespaceURI = XMLConstants.NULL_NS_URI;
+ if (localPart == null)
+ throw new IllegalArgumentException();
+ if (prefix == null)
+ prefix = XMLConstants.DEFAULT_NS_PREFIX;
+ else
+ {
+ if (XMLConstants.XML_NS_PREFIX.equals(prefix))
+ namespaceURI = XMLConstants.XML_NS_URI;
+ else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix))
+ namespaceURI = XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+ }
+ this.namespaceURI = namespaceURI;
+ this.localPart = localPart;
+ this.prefix = prefix;
+ }
+
+ public QName(String localPart)
+ {
+ this(null, localPart, null);
+ }
+
+ public String getNamespaceURI()
+ {
+ return namespaceURI;
+ }
+
+ public String getLocalPart()
+ {
+ return localPart;
+ }
+
+ public String getPrefix()
+ {
+ return prefix;
+ }
+
+ public final boolean equals(Object obj)
+ {
+ if (obj instanceof QName)
+ {
+ QName qname = (QName) obj;
+ return qname.getLocalPart().equals(localPart) &&
+ qname.getNamespaceURI().equals(namespaceURI);
+ }
+ return false;
+ }
+
+ public final int hashCode()
+ {
+ if (hashCode == -1)
+ hashCode = localPart.hashCode() ^ namespaceURI.hashCode();
+ return hashCode;
+ }
+
+ public synchronized String toString()
+ {
+ if (qName == null)
+ {
+ StringBuffer buf = new StringBuffer();
+ if (namespaceURI.length() > 0)
+ {
+ buf.append('{');
+ buf.append(namespaceURI);
+ buf.append('}');
+ }
+ if (prefix.length() > 0)
+ {
+ buf.append(prefix);
+ buf.append(':');
+ }
+ buf.append(localPart);
+ qName = buf.toString();
+ }
+ return qName;
+ }
+
+ public static QName valueOf(String qNameAsString)
+ {
+ String namespaceUri = "", prefix = null;
+ int start = qNameAsString.indexOf('{');
+ int end = qNameAsString.indexOf('}');
+ if (start != -1)
+ {
+ if (end < start)
+ throw new IllegalArgumentException(qNameAsString);
+ namespaceUri = qNameAsString.substring(start + 1, end);
+ qNameAsString = qNameAsString.substring(end + 1);
+ }
+ start = qNameAsString.indexOf(':');
+ if (start != -1)
+ {
+ prefix = qNameAsString.substring(0, start);
+ qNameAsString = qNameAsString.substring(start + 1);
+ }
+ return new QName(namespaceUri, qNameAsString, prefix);
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/namespace/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,9 @@
+<html>
+<body>
+
+<div>
+<a href='http://www.w3.org/TR/REC-xml-names'>XML Namespace</a> processing.
+</div>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/DocumentBuilder.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/DocumentBuilder.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/DocumentBuilder.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/DocumentBuilder.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,203 @@
+/* DocumentBuilder.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.parsers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import javax.xml.validation.Schema;
+import org.w3c.dom.Document;
+import org.w3c.dom.DOMImplementation;
+import org.xml.sax.InputSource;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * Convenience class for parsing an XML document into a W3C DOM object
+ * graph.
+ * Instances of this class are <em>not</em> guaranteed to be thread safe.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ */
+public abstract class DocumentBuilder
+{
+
+ protected DocumentBuilder()
+ {
+ }
+
+ /**
+ * Parse the specified input stream and return a DOM Document.
+ * Prefer the version of this method that specifies a system ID, in order
+ * to resolve external references correctly.
+ * @param is an XML input stream
+ * @exception IllegalArgumentException if the input stream is null
+ */
+ public Document parse(InputStream is)
+ throws SAXException, IOException
+ {
+ if (is == null)
+ {
+ throw new IllegalArgumentException("input stream is null");
+ }
+ return parse(new InputSource(is));
+ }
+
+ /**
+ * Parse the specified input stream and return a DOM Document.
+ * @param is an XML input stream
+ * @param systemId the system ID of the XML document
+ * @exception IllegalArgumentException if the input stream is null
+ */
+ public Document parse(InputStream is, String systemId)
+ throws SAXException, IOException
+ {
+ if (is == null)
+ {
+ throw new IllegalArgumentException("input stream is null");
+ }
+ InputSource source = new InputSource(is);
+ source.setSystemId(systemId);
+ return parse(source);
+ }
+
+ /**
+ * Parse the content of the specified URI and return a DOM Document.
+ * @param uri an XML system ID
+ * @exception IllegalArgumentException if the URI is null
+ */
+ public Document parse(String uri)
+ throws SAXException, IOException
+ {
+ if (uri == null)
+ {
+ throw new IllegalArgumentException("URI is null");
+ }
+ return parse(new InputSource(uri));
+ }
+
+ /**
+ * Parse the specified file and return a DOM Document.
+ * @param f the XML file
+ * @exception IllegalArgumentException if the file is null
+ */
+ public Document parse(File f)
+ throws SAXException, IOException
+ {
+ if (f == null)
+ {
+ throw new IllegalArgumentException("file is null");
+ }
+ InputSource source = new InputSource(new FileInputStream(f));
+ source.setSystemId(f.toURL().toString());
+ return parse(source);
+ }
+
+ /**
+ * Parse the specified input source and return a DOM Document.
+ * @param source the input source
+ * @exception IllegalArgumentException if the input source is null
+ */
+ public abstract Document parse(InputSource source)
+ throws SAXException, IOException;
+
+ /**
+ * Indicates whether this document builder is XML Namespace aware.
+ */
+ public abstract boolean isNamespaceAware();
+
+ /**
+ * Indicates whether this document builder will validate its input.
+ */
+ public abstract boolean isValidating();
+
+ /**
+ * Sets the SAX entity resolver callback used to resolve external entities
+ * in the XML document(s) to parse.
+ * @param er an entity resolver
+ */
+ public abstract void setEntityResolver(EntityResolver er);
+
+ /**
+ * Sets the SAX error handler callback used to report parsing errors.
+ * @param eh the error handler
+ */
+ public abstract void setErrorHandler(ErrorHandler eh);
+
+ /**
+ * Creates a new, empty DOM Document.
+ * To create a document with a root element and optional doctype, use the
+ * <code>DOMImplementation</code> instead.
+ * @see org.w3c.dom.DOMImplementation#createDocument
+ */
+ public abstract Document newDocument();
+
+ /**
+ * Returns the DOM implementation.
+ */
+ public abstract DOMImplementation getDOMImplementation();
+
+ // -- JAXP 1.3 methods --
+
+ /**
+ * Reset this document builder to its original configuration.
+ * @since 1.3
+ */
+ public void reset()
+ {
+ }
+
+ /**
+ * Returns the schema in use by the XML processor.
+ */
+ public Schema getSchema()
+ {
+ return null;
+ }
+
+ /**
+ * Returns the XInclude processing mode in use by the parser.
+ */
+ public boolean isXIncludeAware()
+ {
+ return false;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/DocumentBuilderFactory.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/DocumentBuilderFactory.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/DocumentBuilderFactory.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/DocumentBuilderFactory.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,369 @@
+/* DocumentBuilderFactory.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.parsers;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.util.Properties;
+import javax.xml.validation.Schema;
+
+/**
+ * Factory for obtaining document builders.
+ * Instances of this class are <em>not</em> guaranteed to be thread safe.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ */
+public abstract class DocumentBuilderFactory
+{
+
+ private boolean namespaceAware;
+ private boolean validating;
+ private boolean ignoringElementContentWhitespace;
+ private boolean expandEntityReferences = true;
+ private boolean ignoringComments;
+ private boolean coalescing;
+ private Schema schema;
+ private boolean xIncludeAware;
+
+ protected DocumentBuilderFactory()
+ {
+ }
+
+ /**
+ * Creates a new factory instance.
+ * The implementation class to load is the first found in the following
+ * locations:
+ * <ol>
+ * <li>the <code>javax.xml.parsers.DocumentBuilderFactory</code> system
+ * property</li>
+ * <li>the above named property value in the
+ * <code><i>$JAVA_HOME</i>/lib/jaxp.properties</code> file</li>
+ * <li>the class name specified in the
+ * <code>META-INF/services/javax.xml.parsers.DocumentBuilderFactory</code>
+ * system resource</li>
+ * <li>the default factory class</li>
+ * </ol>
+ */
+ public static DocumentBuilderFactory newInstance()
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null)
+ {
+ loader = DocumentBuilderFactory.class.getClassLoader();
+ }
+ String className = null;
+ int count = 0;
+ do
+ {
+ className = getFactoryClassName(loader, count++);
+ if (className != null)
+ {
+ try
+ {
+ Class t = (loader != null) ? loader.loadClass(className) :
+ Class.forName(className);
+ return (DocumentBuilderFactory) t.newInstance();
+ }
+ catch (ClassNotFoundException e)
+ {
+ className = null;
+ }
+ catch (Exception e)
+ {
+ throw new FactoryConfigurationError(e,
+ "error instantiating class " + className);
+ }
+ }
+ }
+ while (className == null && count < 3);
+ return new gnu.xml.dom.DomDocumentBuilderFactory();
+ }
+
+ private static String getFactoryClassName(ClassLoader loader, int attempt)
+ {
+ final String propertyName = "javax.xml.parsers.DocumentBuilderFactory";
+ switch (attempt)
+ {
+ case 0:
+ return System.getProperty(propertyName);
+ case 1:
+ try
+ {
+ File file = new File(System.getProperty("java.home"));
+ file = new File(file, "lib");
+ file = new File(file, "jaxp.properties");
+ InputStream in = new FileInputStream(file);
+ Properties props = new Properties();
+ props.load(in);
+ in.close();
+ return props.getProperty(propertyName);
+ }
+ catch (IOException e)
+ {
+ return null;
+ }
+ case 2:
+ try
+ {
+ String serviceKey = "/META-INF/services/" + propertyName;
+ InputStream in = (loader != null) ?
+ loader.getResourceAsStream(serviceKey) :
+ DocumentBuilderFactory.class.getResourceAsStream(serviceKey);
+ if (in != null)
+ {
+ BufferedReader r =
+ new BufferedReader(new InputStreamReader(in));
+ String ret = r.readLine();
+ r.close();
+ return ret;
+ }
+ }
+ catch (IOException e)
+ {
+ }
+ return null;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Creates a new document builder instance using the currently specified
+ * factory configuration.
+ * @exception ParserConfigurationException if the specified configuration
+ * is not supported
+ */
+ public abstract DocumentBuilder newDocumentBuilder()
+ throws ParserConfigurationException;
+
+ /**
+ * Sets whether document builders obtained from this factory will be XML
+ * Namespace aware.
+ */
+ public void setNamespaceAware(boolean awareness)
+ {
+ namespaceAware = awareness;
+ }
+
+ /**
+ * Sets whether document builders obtained from this factory will validate
+ * their input.
+ */
+ public void setValidating(boolean validating)
+ {
+ this.validating = validating;
+ }
+
+ /**
+ * Sets whether document builders obtained from this factory will
+ * eliminate whitespace within elements that have an element-only content
+ * model.
+ */
+ public void setIgnoringElementContentWhitespace(boolean whitespace)
+ {
+ ignoringElementContentWhitespace = whitespace;
+ }
+
+ /**
+ * Sets whether document builders obtained from this factory will expand
+ * entity reference nodes.
+ */
+ public void setExpandEntityReferences(boolean expandEntityRef)
+ {
+ expandEntityReferences = expandEntityRef;
+ }
+
+ /**
+ * Sets whether document builders obtained from this factory will discard
+ * comment nodes.
+ */
+ public void setIgnoringComments(boolean ignoreComments)
+ {
+ ignoringComments = ignoreComments;
+ }
+
+ /**
+ * Sets whether document builders obtained from this factory will convert
+ * CDATA sections to text nodes and normalize adjacent text nodes into a
+ * single text node.
+ */
+ public void setCoalescing(boolean coalescing)
+ {
+ this.coalescing = coalescing;
+ }
+
+ /**
+ * Indicates whether document builders obtained from this factory will be
+ * XML Namespace aware.
+ */
+ public boolean isNamespaceAware()
+ {
+ return namespaceAware;
+ }
+
+ /**
+ * Indicates whether document builders obtained from this factory will
+ * validate their input.
+ */
+ public boolean isValidating()
+ {
+ return validating;
+ }
+
+ /**
+ * Indicates whether document builders obtained from this factory will
+ * eliminate whitespace within elements that have an element-only content
+ * model.
+ */
+ public boolean isIgnoringElementContentWhitespace()
+ {
+ return ignoringElementContentWhitespace;
+ }
+
+ /**
+ * Indicates whether document builders obtained from this factory will
+ * expand entity reference nodes.
+ */
+ public boolean isExpandEntityReferences()
+ {
+ return expandEntityReferences;
+ }
+
+ /**
+ * Indicates whether document builders obtained from this factory will
+ * discard comment nodes.
+ */
+ public boolean isIgnoringComments()
+ {
+ return ignoringComments;
+ }
+
+ /**
+ * Indicates whether document builders obtained from this factory will
+ * convert CDATA sections to text nodes and normalize adjacent text nodes
+ * into a single text node.
+ */
+ public boolean isCoalescing()
+ {
+ return coalescing;
+ }
+
+ /**
+ * Set the named attribute on the underlying implementation.
+ * @param name the name of the attribute
+ * @param value the new value
+ * @exception IllegalArgumentException if the attribute is not recognized
+ */
+ public abstract void setAttribute(String name, Object value)
+ throws IllegalArgumentException;
+
+ /**
+ * Retrieves the named attribute value from the underlying implementation.
+ * @param name the name of the attribute
+ * @exception IllegalArgumentException if the attribute is not recognized
+ */
+ public abstract Object getAttribute(String name)
+ throws IllegalArgumentException;
+
+ // -- JAXP 1.3 methods --
+
+ /**
+ * Returns the schema.
+ * @see #setSchema
+ * @since 1.5
+ */
+ public Schema getSchema()
+ {
+ return schema;
+ }
+
+ /**
+ * Sets the schema.
+ * @see #getSchema
+ * @since 1.5
+ */
+ public void setSchema(Schema schema)
+ {
+ this.schema = schema;
+ }
+
+ /**
+ * Indicates whether parsers obtained from this factory will be XInclude
+ * aware.
+ * @since 1.5
+ */
+ public boolean isXIncludeAware()
+ {
+ return xIncludeAware;
+ }
+
+ /**
+ * Sets whether parsers obtained from this factory will be XInclude aware.
+ * @since 1.5
+ */
+ public void setXIncludeAware(boolean state)
+ {
+ xIncludeAware = state;
+ }
+
+ /**
+ * Sets the value of the specified feature.
+ * @param name the feature name (URI)
+ * @param value whether to enable the feature or not
+ * @exception ParserConfigurationException if the feature is not
+ * supported.
+ * @since 1.5
+ */
+ public abstract void setFeature(String name, boolean value)
+ throws ParserConfigurationException;
+
+ /**
+ * Returns the value of the specified feature.
+ * @param name the feature name (URI)
+ * @exception ParserConfigurationException if the feature is not
+ * supported.
+ * @since 1.5
+ */
+ public abstract boolean getFeature(String name)
+ throws ParserConfigurationException;
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/FactoryConfigurationError.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/FactoryConfigurationError.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/FactoryConfigurationError.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/FactoryConfigurationError.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,113 @@
+/* FactoryConfigurationError.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.parsers;
+
+/**
+ * An error occurred during configuration of the parser factory.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ */
+public class FactoryConfigurationError
+ extends Error
+{
+
+ /**
+ * The underlying cause of this exception, if any.
+ */
+ private Exception exception;
+
+ /**
+ * Constructor with no detail message.
+ */
+ public FactoryConfigurationError()
+ {
+ super();
+ }
+
+ /**
+ * Constructor with the specified detail message.
+ * @param msg the detail message
+ */
+ public FactoryConfigurationError(String msg)
+ {
+ super(msg);
+ }
+
+ /**
+ * Constructor with the specified underlying cause.
+ * @param e the underlying cause of this exception
+ */
+ public FactoryConfigurationError(Exception e)
+ {
+ super(e);
+ exception = e;
+ }
+
+ /**
+ * Constructor with the specified underlying cause and detail message.
+ * @param e the underlying cause of this exception
+ * @param msg the detail message
+ */
+ public FactoryConfigurationError(Exception e, String msg)
+ {
+ super(msg, e);
+ exception = e;
+ }
+
+ /**
+ * Returns the message for this error, if any.
+ */
+ public String getMessage()
+ {
+ String message = super.getMessage();
+ if (message == null && exception != null)
+ {
+ message = exception.getMessage();
+ }
+ return message;
+ }
+
+ /**
+ * Returns the underlying cause of this exception, if any.
+ */
+ public Exception getException()
+ {
+ return exception;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/ParserConfigurationException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/ParserConfigurationException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/ParserConfigurationException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/ParserConfigurationException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,66 @@
+/* ParserConfigurationException.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.parsers;
+
+/**
+ * An exception occurred during configuration of the XML parser.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ */
+public class ParserConfigurationException
+ extends Exception
+{
+
+ /**
+ * Constructor with no detail message.
+ */
+ public ParserConfigurationException()
+ {
+ super();
+ }
+
+ /**
+ * Constructor with the specified detail message.
+ * @param msg the detail message
+ */
+ public ParserConfigurationException(String msg)
+ {
+ super(msg);
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/SAXParser.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/SAXParser.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/SAXParser.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/SAXParser.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,340 @@
+/* SAXParser.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.parsers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import javax.xml.validation.Schema;
+import org.xml.sax.HandlerBase;
+import org.xml.sax.InputSource;
+import org.xml.sax.Parser;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Convenience class for using or accessing a SAX version 1 or 2 parser.
+ * Instances of this class are <em>not</em> guaranteed to be thread safe.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ */
+public abstract class SAXParser
+{
+
+ protected SAXParser()
+ {
+ }
+
+ /**
+ * Parse the specifed input stream, reporting SAX1 events to the given
+ * handler.
+ * Prefer the SAX2 version of this method, since the HandlerBase class is
+ * now deprecated.
+ * Also prefer the version of this method that specifies a system ID, in
+ * order to resolve external references correctly.
+ * @param is an XML input stream
+ * @param hb the SAX1 handler
+ * @exception IllegalArgumentException if the input stream is null
+ * @see #parse(java.io.InputStream,org.xml.sax.helpers.DefaultHandler)
+ */
+ public void parse(InputStream is, HandlerBase hb)
+ throws SAXException, IOException
+ {
+ if (is == null)
+ {
+ throw new IllegalArgumentException("input stream is null");
+ }
+ parse(new InputSource(is), hb);
+ }
+
+ /**
+ * Parse the specified input stream, reporting SAX1 events to the given
+ * handler.
+ * Prefer the SAX2 version of this method, since the HandlerBase class is
+ * now deprecated.
+ * @param is an XML input stream
+ * @param hb the SAX1 handler
+ * @param systemId the system ID of the XML document
+ * @exception IllegalArgumentException if the input stream is null
+ * @see #parse(java.io.InputStream,org.xml.sax.helpers.DefaultHandler,java.lang.String)
+ */
+ public void parse(InputStream is, HandlerBase hb, String systemId)
+ throws SAXException, IOException
+ {
+ if (is == null)
+ {
+ throw new IllegalArgumentException("input stream is null");
+ }
+ InputSource source = new InputSource(is);
+ source.setSystemId(systemId);
+ parse(source, hb);
+ }
+
+ /**
+ * Parse the specified input stream, reporting SAX2 events to the given
+ * handler.
+ * Prefer the version of this method that specifies a system ID, in
+ * order to resolve external references correctly.
+ * @param is an XML input stream
+ * @param dh the SAX2 handler
+ * @exception IllegalArgumentException if the input stream is null
+ */
+ public void parse(InputStream is, DefaultHandler dh)
+ throws SAXException, IOException
+ {
+ if (is == null)
+ {
+ throw new IllegalArgumentException("input stream is null");
+ }
+ parse(new InputSource(is), dh);
+ }
+
+ /**
+ * Parse the specified input stream, reporting SAX2 events to the given
+ * handler.
+ * @param is an XML input stream
+ * @param dh the SAX2 handler
+ * @param systemId the system ID of the XML document
+ * @exception IllegalArgumentException if the input stream is null
+ */
+ public void parse (InputStream is, DefaultHandler dh, String systemId)
+ throws SAXException, IOException
+ {
+ if (is == null)
+ {
+ throw new IllegalArgumentException("input stream is null");
+ }
+ InputSource source = new InputSource(is);
+ source.setSystemId(systemId);
+ parse(source, dh);
+ }
+
+ /**
+ * Parse the content of the specified URI, reporting SAX1 events to the
+ * given handler.
+ * Prefer the SAX2 version of this method, since the HandlerBase class is
+ * now deprecated.
+ * @param uri an XML system ID
+ * @param hb the SAX1 handler
+ * @exception IllegalArgumentException if the URI is null
+ * @see #parse(java.lang.String,org.xml.sax.helpers.DefaultHandler)
+ */
+ public void parse(String uri, HandlerBase hb)
+ throws SAXException, IOException
+ {
+ if (uri == null)
+ {
+ throw new IllegalArgumentException("URI is null");
+ }
+ parse(new InputSource(uri), hb);
+ }
+
+ /**
+ * Parse the content of the specified URI, reporting SAX2 events to the
+ * given handler.
+ * @param uri an XML system ID
+ * @param dh the SAX2 handler
+ * @exception IllegalArgumentException if the URI is null
+ */
+ public void parse(String uri, DefaultHandler dh)
+ throws SAXException, IOException
+ {
+ if (uri == null)
+ {
+ throw new IllegalArgumentException("URI is null");
+ }
+ parse(new InputSource(uri), dh);
+ }
+
+ /**
+ * Parse the content of the specified file, reporting SAX1 events to the
+ * given handler.
+ * Prefer the SAX2 version of this method, since the HandlerBase class is
+ * now deprecated.
+ * @param f an XML file
+ * @param hb the SAX1 handler
+ * @exception IllegalArgumentException if the file is null
+ * @see #parse(java.io.File,org.xml.sax.helpers.DefaultHandler)
+ */
+ public void parse(File f, HandlerBase hb)
+ throws SAXException, IOException
+ {
+ if (f == null)
+ {
+ throw new IllegalArgumentException("file is null");
+ }
+ InputSource source = new InputSource(new FileInputStream(f));
+ source.setSystemId(f.toURL().toString());
+ parse(source, hb);
+ }
+
+ /**
+ * Parse the content of the specified file, reporting SAX2 events to the
+ * given handler.
+ * @param f an XML file
+ * @param dh the SAX2 handler
+ * @exception IllegalArgumentException if the file is null
+ */
+ public void parse(File f, DefaultHandler dh)
+ throws SAXException, IOException
+ {
+ if (f == null)
+ {
+ throw new IllegalArgumentException("file is null");
+ }
+ InputSource source = new InputSource(new FileInputStream(f));
+ source.setSystemId(f.toURL().toString());
+ parse(source, dh);
+ }
+
+ /**
+ * Parse the specified input source, reporting SAX1 events to the
+ * given handler.
+ * Prefer the SAX2 version of this method, since the HandlerBase class is
+ * now deprecated.
+ * @param is the SAX input source
+ * @param hb the SAX1 handler
+ * @exception IllegalArgumentException if the input source is null
+ * @see #parse(org.xml.sax.InputSource,org.xml.sax.helpers.DefaultHandler)
+ */
+ public void parse(InputSource is, HandlerBase hb)
+ throws SAXException, IOException
+ {
+ if (is == null)
+ {
+ throw new IllegalArgumentException("input source is null");
+ }
+ Parser parser = getParser();
+ parser.setDocumentHandler(hb);
+ parser.setDTDHandler(hb);
+ parser.setEntityResolver(hb);
+ parser.setErrorHandler(hb);
+ parser.parse(is);
+ }
+
+ /**
+ * Parse the specified input source, reporting SAX2 events to the
+ * given handler.
+ * @param is an XML file
+ * @param dh the SAX2 handler
+ * @exception IllegalArgumentException if the input source is null
+ */
+ public void parse(InputSource is, DefaultHandler dh)
+ throws SAXException, IOException
+ {
+ if (is == null)
+ {
+ throw new IllegalArgumentException("input source is null");
+ }
+ XMLReader reader = getXMLReader();
+ reader.setContentHandler(dh);
+ reader.setDTDHandler(dh);
+ reader.setEntityResolver(dh);
+ reader.setErrorHandler(dh);
+ reader.parse(is);
+ }
+
+ /**
+ * Returns the underlying SAX1 parser.
+ */
+ public abstract Parser getParser() throws SAXException;
+
+ /**
+ * Returns the underlying SAX2 parser.
+ * @since 1.1
+ */
+ public abstract XMLReader getXMLReader() throws SAXException;
+
+ /**
+ * Indicates whether this parser is XML Namespace aware.
+ */
+ public abstract boolean isNamespaceAware();
+
+ /**
+ * Indicates whether this parser will validate its input.
+ */
+ public abstract boolean isValidating();
+
+ /**
+ * Sets the specified SAX2 parser property.
+ * @param name the name of the property
+ * @param value the value of the property
+ */
+ public abstract void setProperty(String name, Object value)
+ throws SAXNotRecognizedException, SAXNotSupportedException;
+
+ /**
+ * Returns the value of the specified SAX2 parser property.
+ * @param name the name of the property
+ */
+ public abstract Object getProperty(String name)
+ throws SAXNotRecognizedException, SAXNotSupportedException;
+
+ // -- JAXP 1.3 methods --
+
+ /**
+ * Resets this parser to its original configuration.
+ * @since 1.3
+ */
+ public void reset()
+ {
+ }
+
+ /**
+ * Returns the schema in use by this parser.
+ * @since 1.3
+ */
+ public Schema getSchema()
+ {
+ return null;
+ }
+
+ /**
+ * Indicates whether this parser is XInclude-aware.
+ * @since 1.3
+ */
+ public boolean isXIncludeAware()
+ {
+ return false;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/SAXParserFactory.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/SAXParserFactory.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/SAXParserFactory.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/SAXParserFactory.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,273 @@
+/* SAXParserFactory.java --
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.parsers;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.util.Properties;
+import javax.xml.validation.Schema;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+
+/**
+ * Factory for obtaining SAX parsers.
+ * Instances of this class are <em>not</em> guaranteed to be thread safe.
+ *
+ * @author (a href='mailto:dog at gnu.org'>Chris Burdess</a)
+ */
+public abstract class SAXParserFactory
+{
+
+ private boolean validating;
+ private boolean namespaceAware;
+ private Schema schema;
+ private boolean xIncludeAware;
+
+ protected SAXParserFactory()
+ {
+ }
+
+ /**
+ * Creates a new factory instance.
+ * The implementation class to load is the first found in the following
+ * locations:
+ * <ol>
+ * <li>the <code>javax.xml.parsers.SAXParserFactory</code> system
+ * property</li>
+ * <li>the above named property value in the
+ * <code><i>$JAVA_HOME</i>/lib/jaxp.properties</code> file</li>
+ * <li>the class name specified in the
+ * <code>META-INF/services/javax.xml.parsers.SAXParserFactory</code>
+ * system resource</li>
+ * <li>the default factory class</li>
+ * </ol>
+ */
+ public static SAXParserFactory newInstance()
+ throws FactoryConfigurationError
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null)
+ {
+ loader = SAXParserFactory.class.getClassLoader();
+ }
+ String className = null;
+ int count = 0;
+ do
+ {
+ className = getFactoryClassName(loader, count++);
+ if (className != null)
+ {
+ try
+ {
+ Class t = (loader != null) ? loader.loadClass(className) :
+ Class.forName(className);
+ return (SAXParserFactory) t.newInstance();
+ }
+ catch (ClassNotFoundException e)
+ {
+ className = null;
+ }
+ catch (Exception e)
+ {
+ throw new FactoryConfigurationError(e,
+ "error instantiating class " + className);
+ }
+ }
+ }
+ while (className == null && count < 3);
+ return new gnu.xml.stream.SAXParserFactory();
+ }
+
+ private static String getFactoryClassName(ClassLoader loader, int attempt)
+ {
+ final String propertyName = "javax.xml.parsers.SAXParserFactory";
+ switch (attempt)
+ {
+ case 0:
+ return System.getProperty(propertyName);
+ case 1:
+ try
+ {
+ File file = new File(System.getProperty("java.home"));
+ file = new File(file, "lib");
+ file = new File(file, "jaxp.properties");
+ InputStream in = new FileInputStream(file);
+ Properties props = new Properties();
+ props.load(in);
+ in.close();
+ return props.getProperty(propertyName);
+ }
+ catch (IOException e)
+ {
+ return null;
+ }
+ case 2:
+ try
+ {
+ String serviceKey = "/META-INF/services/" + propertyName;
+ InputStream in = (loader != null) ?
+ loader.getResourceAsStream(serviceKey) :
+ SAXParserFactory.class.getResourceAsStream(serviceKey);
+ if (in != null)
+ {
+ BufferedReader r =
+ new BufferedReader(new InputStreamReader(in));
+ String ret = r.readLine();
+ r.close();
+ return ret;
+ }
+ }
+ catch (IOException e)
+ {
+ }
+ return null;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Creates a new parser instance using the currently specified factory
+ * configuration.
+ * @exception ParserConfigurationException if the specified configuration
+ * is not supported
+ */
+ public abstract SAXParser newSAXParser()
+ throws ParserConfigurationException, SAXException;
+
+ /**
+ * Sets whether parsers obtained from this factory will be XML Namespace
+ * aware.
+ */
+ public void setNamespaceAware(boolean awareness)
+ {
+ namespaceAware = awareness;
+ }
+
+ /**
+ * Sets whether parsers obtained from this factory will validate their
+ * input.
+ */
+ public void setValidating(boolean validating)
+ {
+ this.validating = validating;
+ }
+
+ /**
+ * Indicates whether parsers obtained from this factory will be XML
+ * Namespace aware.
+ */
+ public boolean isNamespaceAware()
+ {
+ return namespaceAware;
+ }
+
+ /**
+ * Indicates whether parsers obtained from this factory will validate
+ * their input.
+ */
+ public boolean isValidating()
+ {
+ return validating;
+ }
+
+ /**
+ * Sets the specified feature for SAX2 parsers obtained from this factory.
+ * @param name the feature name
+ * @param value the featurevalue
+ */
+ public abstract void setFeature(String name, boolean value)
+ throws ParserConfigurationException, SAXNotRecognizedException,
+ SAXNotSupportedException;
+
+ /**
+ * Returns the specified feature for SAX2 parsers obtained from this
+ * factory.
+ * @param name the feature name
+ */
+ public abstract boolean getFeature(String name)
+ throws ParserConfigurationException, SAXNotRecognizedException,
+ SAXNotSupportedException;
+
+ // -- JAXP 1.3 methods --
+
+ /**
+ * Returns the schema.
+ * @since 1.3
+ * @see #setSchema
+ */
+ public Schema getSchema()
+ {
+ return schema;
+ }
+
+ /**
+ * Sets the schema.
+ * @since 1.3
+ * @see #getSchema
+ */
+ public void setSchema(Schema schema)
+ {
+ this.schema = schema;
+ }
+
+ /**
+ * Indicates whether parsers obtained from this factory will be XInclude
+ * aware.
+ * @since 1.3
+ */
+ public boolean isXIncludeAware()
+ {
+ return xIncludeAware;
+ }
+
+ /**
+ * Sets whether parsers obtained from this factory will be XInclude aware.
+ * @since 1.3
+ */
+ public void setXIncludeAware(boolean state)
+ {
+ xIncludeAware = state;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/parsers/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,16 @@
+<html><head>javax.xml.parsers</head><body>
+
+<p>Bootstrapping APIs for JAXP parsers.
+This is the first portable API defined for bootstrapping DOM.
+
+<p>JAXP parsers bootstrap in two stages.
+First is getting a factory, and configuring it.
+Second is asking that factory for a parser.
+
+<p>The SAX bootstrapping support corresponds to functionality
+found in the <em>org.xml.sax.helpers</em> package, except
+that it uses the JAXP two stage bootstrap paradigm and
+that the parser that's bootstrapped is normally wrapping
+a SAX parser rather than exposing it for direct use.
+
+</body></html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/EventFilter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/EventFilter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/EventFilter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/EventFilter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,54 @@
+/* EventFilter.java --
+ Copyright (C) 2005,2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.stream;
+
+import javax.xml.stream.events.XMLEvent;
+
+/**
+ * Simple filter interface for XML events.
+ */
+public interface EventFilter
+{
+
+ /**
+ * Indicates whether this filter can accept the specified event.
+ */
+ boolean accept(XMLEvent event);
+
+}
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/FactoryConfigurationError.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/FactoryConfigurationError.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/FactoryConfigurationError.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/FactoryConfigurationError.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,86 @@
+/* FactoryConfigurationError.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.stream;
+
+/**
+ * Error indicating that a factory could not be configured.
+ */
+public class FactoryConfigurationError
+ extends Error
+{
+
+ private final Exception exception;
+
+ public FactoryConfigurationError()
+ {
+ this((String) null, (Exception) null);
+ }
+
+ public FactoryConfigurationError(Exception e)
+ {
+ this(e, null);
+ }
+
+ public FactoryConfigurationError(Exception e, String msg)
+ {
+ super(msg);
+ exception = e;
+ }
+
+ public FactoryConfigurationError(String msg, Exception e)
+ {
+ this(e, msg);
+ }
+
+ public FactoryConfigurationError(String msg)
+ {
+ this(null, msg);
+ }
+
+ public Exception getException()
+ {
+ return exception;
+ }
+
+ public String getMessage()
+ {
+ return super.getMessage();
+ }
+
+}
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/Location.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/Location.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/Location.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/Location.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,76 @@
+/* Location.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.stream;
+
+/**
+ * Information about the location of an XML event within the underlying
+ * stream.
+ */
+public interface Location
+{
+
+ /**
+ * Returns the line number at which the current event ends,
+ * or -1 if this is not available.
+ */
+ int getLineNumber();
+
+ /**
+ * Returns the column number at which the current event ends,
+ * or -1 if this is not available.
+ */
+ int getColumnNumber();
+
+ /**
+ * Returns the offset from the start of the source, in bytes or characters
+ * depending on the nature of the source, or -1 if this is not available.
+ */
+ int getCharacterOffset();
+
+ /**
+ * Returns the public identifier for this location, if any.
+ */
+ String getPublicId();
+
+ /**
+ * Returns the system identifier for the underlying source.
+ */
+ String getSystemId();
+
+}
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/StreamFilter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/StreamFilter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/StreamFilter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/javax/xml/stream/StreamFilter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,53 @@
+/* StreamFilter.java --
+ Copyright (C) 2005,2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.xml.stream;
+
+/**
+ * Simple filter interface for XMLStreamReaders.
+ */
+public interface StreamFilter
+{
+
+ /**
+ * Indicates whether the current state of the specified reader in part of
+ * this stream.
+ */
+ boolean accept(XMLStreamReader reader);
+
+}
+
More information about the llvm-commits
mailing list