summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-08-25 12:00:07 +0000
committerRoman Kennke <roman@kennke.org>2006-08-25 12:00:07 +0000
commit9a68916cc4c616ff0ea89200c84b753fff6c9046 (patch)
tree02129d1af45353841a4004d9fbd69a7a549663ba /examples
parent908cf530f76115ca26a4e64b37bf1895a43b183b (diff)
downloadclasspath-9a68916cc4c616ff0ea89200c84b753fff6c9046.tar.gz
2006-08-24 Roman Kennke <kennke@aicas.com>
* examples/gnu/classpath/examples/swing/Demo.java (LaterMain.run): Removed unused local variable. (Demo): Don't put desktop in scrollpane. (addChildren): Removed unused method. (mkButtonBar): Added HTML demo. (mkMenuBar): Added HTML demo. (mkPanel): Removed unused method. (mkScrollPane): Removed unused method. (mkTree): Removed unused method. (valign2str): Removed unused method. * examples/gnu/classpath/examples/swing/HtmlDemo.java: Initialize text field with some HTML that already works. (DEBUG): New field. Set to true for debugging output. (createContent): Dump element tree after parsing.
Diffstat (limited to 'examples')
-rw-r--r--examples/gnu/classpath/examples/swing/Demo.java94
-rw-r--r--examples/gnu/classpath/examples/swing/HtmlDemo.java53
2 files changed, 50 insertions, 97 deletions
diff --git a/examples/gnu/classpath/examples/swing/Demo.java b/examples/gnu/classpath/examples/swing/Demo.java
index 19bc27c1d..6570cdbad 100644
--- a/examples/gnu/classpath/examples/swing/Demo.java
+++ b/examples/gnu/classpath/examples/swing/Demo.java
@@ -28,7 +28,6 @@ import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
-import javax.swing.tree.*;
import javax.swing.plaf.basic.BasicLookAndFeel;
import javax.swing.plaf.metal.DefaultMetalTheme;
@@ -161,6 +160,8 @@ public class Demo
NavigationFilterDemo.createDemoFactory())));
examples.add(new JMenuItem(new PopupAction("JNI Overhead",
JNIOverhead.createDemoFactory())));
+ examples.add(new JMenuItem(new PopupAction("HTML Demo",
+ HtmlDemo.createDemoFactory())));
final JMenuItem vmMenu;
@@ -294,21 +295,6 @@ public class Demo
return bar;
}
- private static String valign2str(int a)
- {
- switch (a)
- {
- case SwingConstants.CENTER:
- return "Center";
- case SwingConstants.TOP:
- return "Top";
- case SwingConstants.BOTTOM:
- return "Bottom";
- default:
- return "Unknown";
- }
- }
-
static String halign2str(int a)
{
switch (a)
@@ -354,17 +340,6 @@ public class Demo
return mkButton(null, i, -1, -1, -1, -1);
}
-
- private static JScrollPane mkScrollPane(JComponent inner)
- {
- JScrollPane jsp;
- jsp = new JScrollPane(inner,
- JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
- JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
-
- return jsp;
- }
-
public Demo()
{
frame = new JFrame("Swing Activity Board");
@@ -376,10 +351,7 @@ public class Demo
JPanel main = new JPanel();
main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
desktop = createDesktop();
-
- // Put the desktop in a scrollpane. The scrollbars may show then
- // up when the them or LaF is changed.
- main.add(new JScrollPane(desktop));
+ main.add(desktop);
main.add(mkButtonBar());
component.add(main, BorderLayout.CENTER);
frame.pack();
@@ -391,7 +363,7 @@ public class Demo
{
public void run()
{
- Demo demo = new Demo();
+ new Demo();
}
}
@@ -407,16 +379,6 @@ public class Demo
return b;
}
- private static JPanel mkPanel(JComponent[] inners)
- {
- JPanel p = new JPanel();
- for (int i = 0; i < inners.length; ++i)
- {
- p.add(inners[i]);
- }
- return p;
- }
-
static JButton mkDisposerButton(final JFrame c)
{
JButton close = mkBigButton("Close");
@@ -479,52 +441,6 @@ public class Demo
}
}
- /**
- * Create the tree.
- *
- * @return thr scroll pane, containing the tree.
- */
- private static JComponent mkTree()
- {
- DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root node");
-
- addChildren("Node", root, 12);
-
- JTree tree = new JTree(root);
- tree.setLargeModel(true);
- DefaultTreeSelectionModel dtsm = new DefaultTreeSelectionModel();
- dtsm.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
- tree.setSelectionModel(dtsm);
-
- // Make it editable.
- tree.setEditable(true);
-
- JComponent t = mkScrollPane(tree);
- t.setPreferredSize(new Dimension(200,200));
- return t;
- }
-
- /**
- * Add the specified number of children to this parent node. For each
- * child, the method is called recursively adding the nChildren-3 number of
- * grandchildren.
- *
- * @param parent the parent node
- * @param nChildren the number of children
- */
- private static void addChildren(String name, DefaultMutableTreeNode parent,
- int nChildren)
- {
- for (int i = 0; i < nChildren; i++)
- {
- String child_name = parent+"."+i;
- DefaultMutableTreeNode child = new DefaultMutableTreeNode
- (child_name);
- parent.add(child);
- addChildren(child_name, child, nChildren-3);
- }
- }
-
private JPanel mkButtonBar()
{
JPanel panel = new JPanel(new GridLayout(3, 1, 5, 5));
@@ -558,6 +474,8 @@ public class Demo
MetalThemeEditor.createDemoFactory())));
panel.add(new JButton(new PopupAction("JNI Overhead",
JNIOverhead.createDemoFactory())));
+ panel.add(new JButton(new PopupAction("HTML",
+ HtmlDemo.createDemoFactory())));
JButton exitDisposer = mkDisposerButton(frame);
panel.add(exitDisposer);
diff --git a/examples/gnu/classpath/examples/swing/HtmlDemo.java b/examples/gnu/classpath/examples/swing/HtmlDemo.java
index 223ee07cd..d31d8cc9d 100644
--- a/examples/gnu/classpath/examples/swing/HtmlDemo.java
+++ b/examples/gnu/classpath/examples/swing/HtmlDemo.java
@@ -52,6 +52,7 @@ import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
+import javax.swing.text.AbstractDocument;
import javax.swing.text.Element;
import javax.swing.text.html.HTMLDocument;
@@ -62,16 +63,48 @@ import javax.swing.text.html.HTMLDocument;
*/
public class HtmlDemo extends JPanel
{
-
+
+ /**
+ * 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>" +
- "123456789HR!<hr>987654321"+
- "123456789BR!<br>987654321"+
- "<p id='insertHere'>Insertion target</p><p>"+
- "<font color=red>ma</font>"+
- "<sup>sup</sup>normal<sub>sub</sub>normal</p><p>Table:"+
- "<table><tr>a<td>b<td>c<tr>x<td>y<td>z</table></body></html>");
+ JTextArea text = new JTextArea("<html><body>\n"
+
+ + "<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;
@@ -111,7 +144,9 @@ public class HtmlDemo extends JPanel
String t = text.getText();
System.out.println("HtmlDemo.java.createContent:Parsing started");
html.setText(t);
- System.out.println("HtmlDemo.java.createContent:Parsing completed");
+ System.out.println("HtmlDemo.java.createContent:Parsing completed");
+ if (DEBUG)
+ ((AbstractDocument) html.getDocument()).dump(System.out);
}
});