CVSROOT: /sources/classpath Module name: classpath Changes by: Audrius Meskauskas <audriusa> 06/06/09 12:51:24
Modified files: . : ChangeLog javax/swing/text/html: HTMLDocument.java gnu/javax/swing/text/html/parser: SmallHtmlAttributeSet.java Added files: examples/gnu/classpath/examples/swing: HtmlDemo.java Log message: 2006-06-09 Audrius Meskauskas <[EMAIL PROTECTED]> * 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. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.7733&r2=1.7734 http://cvs.savannah.gnu.org/viewcvs/classpath/javax/swing/text/html/HTMLDocument.java?cvsroot=classpath&r1=1.31&r2=1.32 http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java?cvsroot=classpath&r1=1.1&r2=1.2 http://cvs.savannah.gnu.org/viewcvs/classpath/examples/gnu/classpath/examples/swing/HtmlDemo.java?cvsroot=classpath&rev=1.1 Patches: Index: ChangeLog =================================================================== RCS file: /sources/classpath/classpath/ChangeLog,v retrieving revision 1.7733 retrieving revision 1.7734 diff -u -b -r1.7733 -r1.7734 --- ChangeLog 9 Jun 2006 11:49:53 -0000 1.7733 +++ ChangeLog 9 Jun 2006 12:51:22 -0000 1.7734 @@ -1,3 +1,11 @@ +2006-06-09 Audrius Meskauskas <[EMAIL PROTECTED]> + + * 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 <[EMAIL PROTECTED]> On behalf of Matthew Wringe <[EMAIL PROTECTED]> Index: javax/swing/text/html/HTMLDocument.java =================================================================== RCS file: /sources/classpath/classpath/javax/swing/text/html/HTMLDocument.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -b -r1.31 -r1.32 --- javax/swing/text/html/HTMLDocument.java 6 Jun 2006 19:39:53 -0000 1.31 +++ javax/swing/text/html/HTMLDocument.java 9 Jun 2006 12:51:24 -0000 1.32 @@ -39,13 +39,15 @@ 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.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 [EMAIL PROTECTED] 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 ([EMAIL PROTECTED]) + * @author Audrius Meskauskas ([EMAIL PROTECTED]) * @author Anthony Balkissoon ([EMAIL PROTECTED]) * @author Lillian Angel ([EMAIL PROTECTED]) */ @@ -727,11 +735,17 @@ } } + /** + * 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] HTMLReader#addSpecialElement} */ public void start(HTML.Tag t, MutableAttributeSet a) { @@ -1407,10 +1421,19 @@ * @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() Index: gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java =================================================================== RCS file: /sources/classpath/classpath/gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java 6 Jun 2006 12:57:27 -0000 1.1 +++ gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java 9 Jun 2006 12:51:24 -0000 1.2 @@ -100,8 +100,6 @@ key = en.nextElement(); keys[i] = key; value = copyFrom.getAttribute(key); - if (value instanceof String) - value = ((String) value).toLowerCase(); values[i] = value; } } Index: examples/gnu/classpath/examples/swing/HtmlDemo.java =================================================================== RCS file: examples/gnu/classpath/examples/swing/HtmlDemo.java diff -N examples/gnu/classpath/examples/swing/HtmlDemo.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ examples/gnu/classpath/examples/swing/HtmlDemo.java 9 Jun 2006 12:51:24 -0000 1.1 @@ -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 ([EMAIL PROTECTED]) + */ +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(); + } + }; + } +} +