summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-11-06 16:26:52 +0000
committerRoman Kennke <roman@kennke.org>2006-11-06 16:26:52 +0000
commit9298ce6ef7dceec1e42cd9a977619cc55ad07a3d (patch)
tree7f53782e4c0c4d7b4f951579f8943fe99faa0e6c /examples
parentf8381b2b65b1e467cb43cc6b94fd14bb266baf22 (diff)
downloadclasspath-9298ce6ef7dceec1e42cd9a977619cc55ad07a3d.tar.gz
2006-11-06 Roman Kennke <kennke@aicas.com>
* examples/gnu/classpath/examples/swing/HtmlDemo.java: Changed to implement a minimalistic browser. * examples/gnu/classpath/examples/swing/forms.html, * examples/gnu/classpath/examples/swing/textstyles.html, * examples/gnu/classpath/examples/swing/welcome.html: Some example content.
Diffstat (limited to 'examples')
-rw-r--r--examples/gnu/classpath/examples/swing/HtmlDemo.java266
-rw-r--r--examples/gnu/classpath/examples/swing/forms.html69
-rw-r--r--examples/gnu/classpath/examples/swing/textstyles.html78
-rw-r--r--examples/gnu/classpath/examples/swing/welcome.html52
4 files changed, 268 insertions, 197 deletions
diff --git a/examples/gnu/classpath/examples/swing/HtmlDemo.java b/examples/gnu/classpath/examples/swing/HtmlDemo.java
index d31d8cc9d..988344f5d 100644
--- a/examples/gnu/classpath/examples/swing/HtmlDemo.java
+++ b/examples/gnu/classpath/examples/swing/HtmlDemo.java
@@ -40,21 +40,22 @@ 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 java.io.IOException;
+import java.net.URL;
+import javax.swing.BoxLayout;
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.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
-import javax.swing.text.AbstractDocument;
-import javax.swing.text.Element;
-import javax.swing.text.html.HTMLDocument;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
/**
* Parses and displays HTML content.
@@ -64,49 +65,36 @@ import javax.swing.text.html.HTMLDocument;
public class HtmlDemo extends JPanel
{
+ private class LoadActionListener
+ implements ActionListener
+ {
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String urlStr = url.getText();
+ try
+ {
+ html.setPage(url.getText());
+ }
+ catch (IOException ex)
+ {
+ System.err.println("exception while loading: " + ex);
+ ex.printStackTrace();
+ }
+ }
+ }
+
/**
* Setting this to true causes the parsed element structure to be dumped.
*/
private static final boolean DEBUG = true;
- JTextPane html = new JTextPane();
-
- JTextArea text = new JTextArea("<html><body>\n"
+ /**
+ * The URL entry field.
+ */
+ JTextField url = new JTextField();
- + "<h1>H1 Headline</h1>\n"
- + "<h2>H2 Headline</h2>\n"
- + "<h3>H3 Headline</h3>\n"
- + "<h4>H4 Headline</h3>\n"
- + "<h5>H5 Headline</h5>\n"
- + "<h6>H6 Headline</h6>\n"
- + "<h1>CSS colors via font tag</h1>\n"
- + "<p>"
- + "<font color=\"maroon\">maroon</font>\n"
- + "<font color=\"red\">red</font>\n"
- + "<font color=\"orange\">orange</font>\n"
- + "<font color=\"yellow\">yellow</font>\n"
- + "<font color=\"olive\">olive</font>\n"
- + "<font color=\"purple\">purlpe</font>\n"
- + "<font color=\"fuchsia\">fuchsia</font>\n"
- + "<font color=\"white\">white</font>\n"
- + "<font color=\"lime\">lime</font>\n"
- + "<font color=\"green\">green</font>\n"
- + "<font color=\"navy\">navy</font>\n"
- + "<font color=\"blue\">blue</font>\n"
- + "<font color=\"aqua\">aqua</font>\n"
- + "<font color=\"teal\">teal</font>\n"
- + "<font color=\"black\">black</font>\n"
- + "<font color=\"silver\">silver</font>\n"
- + "<font color=\"gray\">gray</font>\n"
- + "</p>"
- + "<h1>Some HTML formatting tags</h1>\n"
- + "<p>Normal <b>Bold</b> <i>Italic</i> <b><i>Bold + Italic</i></b></p>\n"
- + "<p><big>Big</big> <em>Emphasized</em> <small>Small</small>\n"
- + "<strike>Strike</strike> <strong>Strong</strong> <u>Underline</u></p>\n"
- + "<p>Normal vs <sup>Superscript</sup> vs <sub>Subscript</sub> text</p>\n"
- + "</body></html>\n");
-
- JPanel buttons;
+ JTextPane html = new JTextPane();
int n;
@@ -116,7 +104,7 @@ public class HtmlDemo extends JPanel
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
@@ -126,158 +114,54 @@ public class HtmlDemo extends JPanel
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");
- if (DEBUG)
- ((AbstractDocument) html.getDocument()).dump(System.out);
- }
- });
-
- buttons.add(parse);
-
- JButton insertBeforeEnd = new JButton("before end");
- insertBeforeEnd.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent event)
- {
- HTMLDocument doc = (HTMLDocument) html.getDocument();
- Element el = doc.getElement("insertHere");
- System.out.println("Element found:"+el);
- try
- {
- doc.insertBeforeEnd(el,"before end "+(n++));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- });
-
- JButton insertBeforeStart = new JButton("before start");
- insertBeforeStart.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent event)
- {
- HTMLDocument doc = (HTMLDocument) html.getDocument();
- Element el = doc.getElement("insertHere");
- System.out.println("Element found:"+el);
- try
- {
- doc.insertBeforeStart(el,"before start "+(n++));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- });
-
- JButton insertAfterEnd = new JButton("after end");
- insertAfterEnd.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent event)
- {
- HTMLDocument doc = (HTMLDocument) html.getDocument();
- Element el = doc.getElement("insertHere");
- System.out.println("Element found:"+el);
- try
- {
- doc.insertAfterEnd(el,"after end "+(n++));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- });
-
- JButton insertAfterStart = new JButton("after start");
- insertAfterStart.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent event)
- {
- HTMLDocument doc = (HTMLDocument) html.getDocument();
- Element el = doc.getElement("insertHere");
- System.out.println("Element found:"+el);
- try
- {
- doc.insertAfterStart(el,"after start "+(n++));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- });
-
- JButton setInner = new JButton("inner");
- setInner.addActionListener(new ActionListener()
+ html.setEditable(false);
+ html.addHyperlinkListener(new HyperlinkListener()
+ {
+
+ public void hyperlinkUpdate(HyperlinkEvent event)
{
- public void actionPerformed(ActionEvent event)
+ URL u = event.getURL();
+ if (u != null)
{
- HTMLDocument doc = (HTMLDocument) html.getDocument();
- Element el = doc.getElement("insertHere");
- System.out.println("Element found:"+el);
+ url.setText(u.toString());
try
{
- doc.setInnerHTML(el,"inner "+(n++));
+ html.setPage(u);
}
- catch (Exception e)
+ catch (IOException ex)
{
- e.printStackTrace();
+ ex.printStackTrace();
}
}
- });
-
- JButton setOuter = new JButton("outer");
- setOuter.addActionListener(new ActionListener()
+ }
+
+ });
+
+ JScrollPane scroller = new JScrollPane(html);
+ JPanel urlPanel = new JPanel();
+ urlPanel.setLayout(new BoxLayout(urlPanel, BoxLayout.X_AXIS));
+ url.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
+ LoadActionListener action = new LoadActionListener();
+ url.addActionListener(action);
+ urlPanel.add(url);
+ JButton loadButton = new JButton("go");
+ urlPanel.add(loadButton);
+ loadButton.addActionListener(action);
+ add(urlPanel, BorderLayout.NORTH);
+ add(scroller, BorderLayout.CENTER);
+
+ // Load start page.
+ URL startpage = getClass().getResource("forms.html");
+ try
{
- public void actionPerformed(ActionEvent event)
- {
- HTMLDocument doc = (HTMLDocument) html.getDocument();
- Element el = doc.getElement("insertHere");
- System.out.println("Element found:"+el);
- try
- {
- doc.setOuterHTML(el,"outer "+(n++));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- });
-
-
- buttons.add(insertBeforeStart);
- buttons.add(insertAfterStart);
- buttons.add(insertBeforeEnd);
- buttons.add(insertAfterEnd);
-
- buttons.add(setInner);
- buttons.add(setOuter);
-
- add(center, BorderLayout.CENTER);
- add(buttons, BorderLayout.SOUTH);
+ html.setPage(startpage);
+ url.setText(startpage.toString());
+ }
+ catch (IOException ex)
+ {
+ System.err.println("couldn't load page: " + startpage);
+ }
}
/**
@@ -294,18 +178,6 @@ public class HtmlDemo extends JPanel
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(700, 480));
diff --git a/examples/gnu/classpath/examples/swing/forms.html b/examples/gnu/classpath/examples/swing/forms.html
new file mode 100644
index 000000000..2cfdb4bcc
--- /dev/null
+++ b/examples/gnu/classpath/examples/swing/forms.html
@@ -0,0 +1,69 @@
+<!-- welcome.html -- Some HTML stuff to show Swing 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. -->
+
+<html>
+
+ <head>
+ <title>HTML text styles</title>
+ </head>
+ <body>
+ <a href="welcome.html">Back to start page</a>
+ <h1>Some form elements</h1>
+ <h2>Textarea</h2>
+ <textarea cols="30" rows="5">
+ Hello GNU Classpath world. This text should show up in a text area
+ that has a size of 30 columns and 5 rows
+ </textarea>
+
+ <h2>Buttons</h2>
+ <p>
+ <input type="submit"></input>
+ <input type="reset"></input>
+ <input type="button" value="Some button"></input>
+ </p>
+
+ <h2>Checkboxes and Radiobuttons</h2>
+ <p>
+ <input type="checkbox">Check this!</input>
+ <input type="checkbox">Or this</input>
+ </p>
+ <p>
+ <input type="radio">A radio button</input>
+ <input type="radio">Another radio</input>
+ </p>
+ </body>
+</html> \ No newline at end of file
diff --git a/examples/gnu/classpath/examples/swing/textstyles.html b/examples/gnu/classpath/examples/swing/textstyles.html
new file mode 100644
index 000000000..786e18b77
--- /dev/null
+++ b/examples/gnu/classpath/examples/swing/textstyles.html
@@ -0,0 +1,78 @@
+<!-- welcome.html -- Some HTML stuff to show Swing 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. -->
+
+<html>
+
+ <head>
+ <title>HTML text styles</title>
+ </head>
+ <body>
+ <a href="welcome.html">Back to start page</a>
+ <h1>Colors</h1>
+ <p>The following are the 16 named colors in HTML. Of course you can also
+ use all RGB colors by specifying a value in the <code>#RRGGBB</code>
+ notation.</p>
+ <p>
+ <font color="black">Black</font>, <font color="gray">Gray</font>,
+ <font color="maroon">Maroon</font>, <font color="red">Red</font>,
+ <font color="green">Green</font>, <font color="lime">Lime</font>,
+ <font color="olive">Olive</font>, <font color="yellow">Yellow</font>,
+ <font color="navy">Navy</font>, <font color="blue">Blue</font>,
+ <font color="purple">Purple</font>, <font color="fuchsia">Fuchsia</font>,
+ <font color="teal">Teal</font>, <font color="aque">Aqua</font>,
+ <font color="silver">Silver</font>, <font color="white">White</font></p>
+ <h1>Font styles</h1>
+ <p>The following lists the logical and physical font styles that can be set
+ by certain HTML tags</p>
+ <p>
+ <!--<abbr>Abbreviation</abbr>, <acronym>Acronym</acronym>,-->
+ <address>Address</address>, <b>Bold</b>, <big>Big</big>,
+ <cite>Citation</cite>, <code>Code</code>, <del>Deleted</del>,
+ <em>Emphasized<em>, <i>Italic</i>, <ins>Inserted</ins>, <q>Quote</q>,
+ <s>Stroke-Through</s>, <samp>Example</samp>, <small>Small</small>,
+ <strike>Strike</strike>, <strong>Strong</strong>, <sub>Subscript</sub>,
+ <sup>Superscript</sup>, <u>Underlined</u>, <var>Variable</var>
+ </p>
+ <h1>Header Level 1</h1>
+ <h2>Header Level 2</h2>
+ <h3>Header Level 3</h3>
+ <h4>Header Level 4</h4>
+ <h5>Header Level 5</h5>
+ <h6>Header Level 6</h6>
+ <center>Some centered Text</center>
+ </body>
+</html> \ No newline at end of file
diff --git a/examples/gnu/classpath/examples/swing/welcome.html b/examples/gnu/classpath/examples/swing/welcome.html
new file mode 100644
index 000000000..62fb51429
--- /dev/null
+++ b/examples/gnu/classpath/examples/swing/welcome.html
@@ -0,0 +1,52 @@
+<!-- welcome.html -- Some HTML stuff to show Swing 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. -->
+
+<html>
+ <head>
+ <title>GNU Classpath HTML Browser</title>
+ </head>
+ <body>
+ <img src="../icons/badge.png">
+ <h1>Welcome to GNU Classpath</h1>
+ <p>These pages are here to demonstrate the HTML rendering capabilities
+ of GNU Classpath's Swing.</p>
+ <ul>
+ <li><a href="textstyles.html">Text styles</li>
+ <li><a href="forms.html">Form elements</li>
+ </ul>
+ </body>
+</html> \ No newline at end of file