summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAudrius Meskauskas <audriusa@Bioinformatics.org>2006-06-09 12:51:22 +0000
committerAudrius Meskauskas <audriusa@Bioinformatics.org>2006-06-09 12:51:22 +0000
commit5d6bfeb57b947a5e41afd1fda928371bc9586c71 (patch)
tree0e78e814bed23aefbc034d970c4feb25912d643a
parentcd6642bb405aeebdc0ec9ec65b79acd6b76734d8 (diff)
downloadclasspath-5d6bfeb57b947a5e41afd1fda928371bc9586c71.tar.gz
2006-06-09 Audrius Meskauskas <AudriusA@Bioinformatics.org>
* gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java (constructor): Do not lowercase the values. * javax/swing/text/html/HTMLDocument.java (HTMLReader.addSpecialElement): Implemented. * examples/gnu/classpath/examples/swing/HtmlDemo.java: New file.
-rw-r--r--ChangeLog8
-rw-r--r--examples/gnu/classpath/examples/swing/HtmlDemo.java165
-rw-r--r--gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java2
-rw-r--r--javax/swing/text/html/HTMLDocument.java39
4 files changed, 204 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 8daf2dccf..b033e9bd1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-06-09 Audrius Meskauskas <AudriusA@Bioinformatics.org>
+
+ * gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java
+ (constructor): Do not lowercase the values.
+ * javax/swing/text/html/HTMLDocument.java
+ (HTMLReader.addSpecialElement): Implemented.
+ * examples/gnu/classpath/examples/swing/HtmlDemo.java: New file.
+
2006-06-09 Raif S. Naffah <raif@swiftdsl.com.au>
On behalf of Matthew Wringe <mwringe@redhat.com>
diff --git a/examples/gnu/classpath/examples/swing/HtmlDemo.java b/examples/gnu/classpath/examples/swing/HtmlDemo.java
new file mode 100644
index 000000000..6ac626717
--- /dev/null
+++ b/examples/gnu/classpath/examples/swing/HtmlDemo.java
@@ -0,0 +1,165 @@
+/* HtmlDemo.java -- HTML viewer demo
+ 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 gnu.classpath.examples.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextPane;
+import javax.swing.SwingUtilities;
+
+/**
+ * Parses and displays HTML content.
+ *
+ * @author Audrius Meskauskas (audriusa@bioinformatics.org)
+ */
+public class HtmlDemo extends JPanel
+{
+
+ JTextPane html = new JTextPane();
+
+ //JTextArea text = new JTextArea("<html><body><p><img src='' alt='alt txt'></p></body></html>");
+ JTextArea text = new JTextArea("<html><body><p>nor<font color=red>ma</font>l<sup>sup</sup>normal<sub>sub</sub>normal</p></body></html>");
+
+ JPanel buttons;
+
+ public HtmlDemo()
+ {
+ super();
+ html.setContentType("text/html"); // not now.
+ createContent();
+ }
+
+ /**
+ * Returns a panel with the demo content. The panel uses a BorderLayout(), and
+ * the BorderLayout.SOUTH area is empty, to allow callers to add controls to
+ * the bottom of the panel if they want to (a close button is added if this
+ * demo is being run as a standalone demo).
+ */
+ private void createContent()
+ {
+ setLayout(new BorderLayout());
+
+ JPanel center = new JPanel();
+ GridLayout layout = new GridLayout();
+ layout.setRows(2);
+ center.setLayout(layout);
+ center.add(new JScrollPane(text));
+ center.add(new JScrollPane(html));
+
+ buttons = new JPanel();
+
+ JButton parse = new JButton("parse");
+ parse.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ String t = text.getText();
+ System.out.println("HtmlDemo.java.createContent:Parsing started");
+ html.setText(t);
+ System.out.println("HtmlDemo.java.createContent:Parsing completed");
+ }
+ });
+
+ buttons.add(parse);
+
+ add(center, BorderLayout.CENTER);
+ add(buttons, BorderLayout.SOUTH);
+ }
+
+ /**
+ * The executable method to display the editable table.
+ *
+ * @param args
+ * unused.
+ */
+ public static void main(String[] args)
+ {
+ SwingUtilities.invokeLater
+ (new Runnable()
+ {
+ public void run()
+ {
+ HtmlDemo demo = new HtmlDemo();
+
+ JButton exit = new JButton("exit");
+ exit.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ System.exit(0);
+ }
+ });
+
+ demo.buttons.add(exit);
+
+ JFrame frame = new JFrame();
+ frame.getContentPane().add(demo);
+ frame.setSize(new Dimension(640, 480));
+ frame.setVisible(true);
+ }
+ });
+ }
+
+ /**
+ * Returns a DemoFactory that creates a HtmlDemo.
+ *
+ * @return a DemoFactory that creates a HtmlDemo
+ */
+ public static DemoFactory createDemoFactory()
+ {
+ return new DemoFactory()
+ {
+ public JComponent createDemo()
+ {
+ return new HtmlDemo();
+ }
+ };
+ }
+}
+
diff --git a/gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java b/gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java
index 45e1dce7b..930a324f9 100644
--- a/gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java
+++ b/gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java
@@ -100,8 +100,6 @@ public class SmallHtmlAttributeSet
key = en.nextElement();
keys[i] = key;
value = copyFrom.getAttribute(key);
- if (value instanceof String)
- value = ((String) value).toLowerCase();
values[i] = value;
}
}
diff --git a/javax/swing/text/html/HTMLDocument.java b/javax/swing/text/html/HTMLDocument.java
index b7a706904..92f591ec8 100644
--- a/javax/swing/text/html/HTMLDocument.java
+++ b/javax/swing/text/html/HTMLDocument.java
@@ -39,13 +39,15 @@ exception statement from your version. */
package javax.swing.text.html;
import gnu.classpath.NotImplementedException;
-
import gnu.javax.swing.text.html.CharacterAttributeTranslator;
+
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Stack;
import java.util.Vector;
+
+import javax.swing.JEditorPane;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
@@ -59,9 +61,15 @@ import javax.swing.text.StyleConstants;
import javax.swing.text.html.HTML.Tag;
/**
- * TODO: Add more comments here
+ * 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, Lithuania (AudriusA@Bioinformatics.org)
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
* @author Anthony Balkissoon (abalkiss@redhat.com)
* @author Lillian Angel (langel@redhat.com)
*/
@@ -727,11 +735,17 @@ public class HTMLDocument extends DefaultStyledDocument
}
}
+ /**
+ * 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
{
/**
- * This method is called when a start tag is seen for one of the types
- * of tags associated with this Action.
+ * The functionality is delegated to {@link HTMLReader#addSpecialElement}
*/
public void start(HTML.Tag t, MutableAttributeSet a)
{
@@ -1407,10 +1421,19 @@ public class HTMLDocument extends DefaultStyledDocument
* @param a the attribute set specifying the special content
*/
protected void addSpecialElement(HTML.Tag t, MutableAttributeSet a)
- throws NotImplementedException
{
- // FIXME: Implement
- print ("HTMLReader.addSpecialElement not implemented yet");
+ a.addAttribute(StyleConstants.NameAttribute, t);
+
+ // Migrate from the rather htmlAttributeSet to the faster, lighter and
+ // unchangeable alternative implementation.
+ AttributeSet copy = a.copyAttributes();
+
+ // TODO: Figure out why we must always insert this single character
+ // (otherwise the element does not appear). Either fix or add explaining
+ // comment or at least report a normal bug.
+ ElementSpec spec = new ElementSpec(copy, ElementSpec.ContentType,
+ new char[] {' '}, 0, 1 );
+ parseBuffer.add(spec);
}
void printBuffer()