From 97b8365cafc3a344a22d3980b8ed885f5c6d8357 Mon Sep 17 00:00:00 2001
From: Tom Tromey Insertion target "+
- "ma"+
- "supnormalsubnormal Table:"+
- " The following are the 16 named colors in HTML. Of course you can also
+ use all RGB colors by specifying a value in the
+ Black, Gray,
+ Maroon, Red,
+ Green, Lime,
+ Olive, Yellow,
+ Navy, Blue,
+ Purple, Fuchsia,
+ Teal, Aqua,
+ Silver, White The following lists the logical and physical font styles that can be set
+ by certain HTML tags
+
+
987654321"+
- "123456789BR!
987654321"+
- "
");
-
- JPanel buttons;
+ private class LoadActionListener
+ implements ActionListener
+ {
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String urlStr = url.getText();
+ try
+ {
+ setPage(new URL(url.getText()));
+ }
+ catch (MalformedURLException ex)
+ {
+ // Do something more useful here.
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Setting this to true causes the parsed element structure to be dumped.
+ */
+ private static final boolean DEBUG = true;
+
+ /**
+ * The URL entry field.
+ */
+ JTextField url = new JTextField();
+
+ JTextPane html = new JTextPane();
int n;
+ /**
+ * The browsing history.
+ *
+ * Package private to avoid accessor method.
+ */
+ LinkedList history;
+
public HtmlDemo()
{
super();
- html.setContentType("text/html"); // not now.
+ history = new LinkedList();
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
@@ -93,158 +130,128 @@ 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()
+
+ JEditorPane.registerEditorKitForContentType("text/html",
+ BrowserEditorKit.class.getName());
+ html.setEditable(false);
+ html.addHyperlinkListener(new HyperlinkListener()
+ {
+
+ public void hyperlinkUpdate(HyperlinkEvent event)
{
- public void actionPerformed(ActionEvent event)
+ if (event instanceof FormSubmitEvent)
{
- String t = text.getText();
- System.out.println("HtmlDemo.java.createContent:Parsing started");
- html.setText(t);
- System.out.println("HtmlDemo.java.createContent:Parsing completed");
+ submitForm((FormSubmitEvent) event);
}
- });
-
- buttons.add(parse);
-
- JButton insertBeforeEnd = new JButton("before end");
- insertBeforeEnd.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent event)
+ else
{
- 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)
+ URL u = event.getURL();
+ if (u != null)
{
- e.printStackTrace();
+ setPage(u);
}
}
- });
-
- 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()
+ }
+
+ });
+
+ 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);
+
+ // Setup control panel.
+ JToolBar controlPanel = createToolBar();
+ JPanel browserPanel = new JPanel();
+ browserPanel.setLayout(new BorderLayout());
+ browserPanel.add(urlPanel, BorderLayout.NORTH);
+ browserPanel.add(scroller, BorderLayout.CENTER);
+ add(controlPanel, BorderLayout.NORTH);
+ add(browserPanel, BorderLayout.CENTER);
+
+ // Load start page.
+ try
{
- 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()
+ URL startpage = getClass().getResource("welcome.html");
+ html.setPage(startpage);
+ url.setText(startpage.toString());
+ history.addLast(startpage);
+ }
+ catch (Exception ex)
{
- 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();
- }
- }
- });
-
+ System.err.println("couldn't load page: "/* + startpage*/);
+ ex.printStackTrace();
+ }
+ setPreferredSize(new Dimension(800, 600));
+ }
+
- JButton setInner = new JButton("inner");
- setInner.addActionListener(new ActionListener()
+ /**
+ * Creates the toolbar with the control buttons.
+ *
+ * @return the toolbar with the control buttons
+ */
+ JToolBar createToolBar()
+ {
+ JToolBar tb = new JToolBar();
+ Icon backIcon = Demo.getIcon("/gnu/classpath/examples/icons/back.png",
+ "back");
+ JButton back = new JButton(backIcon);
+ back.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent ev)
{
- public void actionPerformed(ActionEvent event)
+ if (history.size() > 1)
{
- HTMLDocument doc = (HTMLDocument) html.getDocument();
- Element el = doc.getElement("insertHere");
- System.out.println("Element found:"+el);
+ URL last = (URL) history.removeLast();
+ last = (URL) history.getLast();
+ url.setText(last.toString());
try
{
- doc.setInnerHTML(el,"inner "+(n++));
+ html.setPage(last);
}
- catch (Exception e)
+ catch (IOException ex)
{
- e.printStackTrace();
+ // Do something more useful.
+ ex.printStackTrace();
}
}
- });
-
- JButton setOuter = new JButton("outer");
- setOuter.addActionListener(new ActionListener()
+ }
+ });
+ tb.add(back);
+ Icon reloadIcon = Demo.getIcon("/gnu/classpath/examples/icons/reload.png",
+ "reload");
+ JButton reload = new JButton(reloadIcon);
+ reload.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent ev)
{
- public void actionPerformed(ActionEvent event)
+ if (history.size() > 0)
{
- HTMLDocument doc = (HTMLDocument) html.getDocument();
- Element el = doc.getElement("insertHere");
- System.out.println("Element found:"+el);
+ URL last = (URL) history.getLast();
+ url.setText(last.toString());
try
{
- doc.setOuterHTML(el,"outer "+(n++));
+ html.setPage(last);
}
- catch (Exception e)
+ catch (IOException ex)
{
- e.printStackTrace();
+ // Do something more useful.
+ ex.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);
+ }
+ });
+ tb.add(reload);
+ return tb;
}
-
+
/**
* The executable method to display the editable table.
*
@@ -259,27 +266,102 @@ 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));
+ frame.setSize(new Dimension(750, 480));
frame.setVisible(true);
}
});
}
/**
+ * Helper method to navigate to a new URL.
+ *
+ * @param u the new URL to navigate to
+ */
+ void setPage(URL u)
+ {
+ try
+ {
+ url.setText(u.toString());
+ html.setPage(u);
+ history.addLast(u);
+ }
+ catch (IOException ex)
+ {
+ // Do something more useful here.
+ ex.printStackTrace();
+ }
+ }
+
+ /**
+ * Submits a form when a FormSubmitEvent is received. The HTML API
+ * provides automatic form submit but when this is enabled we don't
+ * receive any notification and can't update our location field.
+ *
+ * @param ev the form submit event
+ */
+ void submitForm(FormSubmitEvent ev)
+ {
+ URL url = ev.getURL();
+ String data = ev.getData();
+ FormSubmitEvent.MethodType method = ev.getMethod();
+ if (method == FormSubmitEvent.MethodType.POST)
+ {
+ try
+ {
+ URLConnection conn = url.openConnection();
+ postData(conn, data);
+ }
+ catch (IOException ex)
+ {
+ // Deal with this.
+ ex.printStackTrace();
+ }
+ }
+ else
+ {
+ try
+ {
+ url = new URL(url.toString() + "?" + data);
+ }
+ catch (MalformedURLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ setPage(url);
+ }
+
+ /**
+ * Posts the form data for forms with HTTP POST method.
+ *
+ * @param conn the connection
+ * @param data the form data
+ */
+ private void postData(URLConnection conn, String data)
+ {
+ conn.setDoOutput(true);
+ PrintWriter out = null;
+ try
+ {
+ out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream()));
+ out.print(data);
+ out.flush();
+ }
+ catch (IOException ex)
+ {
+ // Deal with this!
+ ex.printStackTrace();
+ }
+ finally
+ {
+ if (out != null)
+ out.close();
+ }
+ }
+
+ /**
* Returns a DemoFactory that creates a HtmlDemo.
*
* @return a DemoFactory that creates a HtmlDemo
diff --git a/libjava/classpath/examples/gnu/classpath/examples/swing/TabbedPaneDemo.java b/libjava/classpath/examples/gnu/classpath/examples/swing/TabbedPaneDemo.java
index 527fe45..bd0e6bf 100644
--- a/libjava/classpath/examples/gnu/classpath/examples/swing/TabbedPaneDemo.java
+++ b/libjava/classpath/examples/gnu/classpath/examples/swing/TabbedPaneDemo.java
@@ -39,15 +39,24 @@ exception statement from your version. */
package gnu.classpath.examples.swing;
import java.awt.BorderLayout;
+import java.awt.Color;
import java.awt.GridLayout;
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.JComponent;
import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
+import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
@@ -55,6 +64,10 @@ public class TabbedPaneDemo
extends JPanel
implements ActionListener
{
+ static Color[] colors = { Color.BLUE, Color.CYAN, Color.GRAY, Color.GREEN,
+ Color.MAGENTA, Color.ORANGE, Color.PINK,
+ Color.ORANGE, Color.RED, Color.BLUE, Color.YELLOW
+ };
TabbedPaneDemo()
{
super();
@@ -64,25 +77,123 @@ public class TabbedPaneDemo
private void createContent()
{
JPanel p = new JPanel();
- p.setLayout(new GridLayout(2, 2));
- JTabbedPane tabs1 = new JTabbedPane(SwingConstants.TOP);
- tabs1.add("Top Item 1", new JButton("Content: Top Item 1"));
- tabs1.add("Top Item 2", new JButton("Content: Top Item 2"));
- JTabbedPane tabs2 = new JTabbedPane(SwingConstants.LEFT);
- tabs2.add("Left Item 1", new JButton("Content: Left Item 1"));
- tabs2.add("Left Item 2", new JButton("Content: Left Item 2"));
- JTabbedPane tabs3 = new JTabbedPane(SwingConstants.BOTTOM);
- tabs3.add("Bottom Item 1", new JButton("Content: Bottom Item 1"));
- tabs3.add("Bottom Item 2", new JButton("Content: Bottom Item 2"));
- JTabbedPane tabs4 = new JTabbedPane(SwingConstants.RIGHT);
- tabs4.add("Right Item 1", new JButton("Content: Right Item 1"));
- tabs4.add("Right Item 2", new JButton("Content: Right Item 2"));
- p.add(tabs1);
- p.add(tabs2);
- p.add(tabs3);
- p.add(tabs4);
+ p.setLayout(new GridLayout(1, 1));
+
+ int COUNT = 25;
+ JTabbedPane tp = createTabbedPane(SwingConstants.TOP, "tab", COUNT);
+ p.add(tp);
+
+ final JPopupMenu popup = new JPopupMenu();
+
+ JMenu menu = new JMenu("tab placement");
+ menu.add(createPlacementChangingMenuItem("top",
+ SwingConstants.TOP,
+ tp));
+
+ menu.add(createPlacementChangingMenuItem("bottom",
+ SwingConstants.BOTTOM,
+ tp));
+
+ menu.add(createPlacementChangingMenuItem("left",
+ SwingConstants.LEFT,
+ tp));
+
+ menu.add(createPlacementChangingMenuItem("right",
+ SwingConstants.RIGHT,
+ tp));
+ popup.add(menu);
+
+ menu = new JMenu("tab layout");
+ menu.add(createLayoutPolicyChangingMenuItem("wrapping tabs",
+ JTabbedPane.WRAP_TAB_LAYOUT,
+ tp));
+
+ menu.add(createLayoutPolicyChangingMenuItem("scrolling tabs",
+ JTabbedPane.SCROLL_TAB_LAYOUT,
+ tp));
+ popup.add(menu);
+
+ tp.addMouseListener(new MouseAdapter()
+ {
+ public void mousePressed(MouseEvent e) {
+ showPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ showPopup(e);
+ }
+
+ void showPopup(MouseEvent e) {
+ if (e.isPopupTrigger()) {
+ popup.show(e.getComponent(), e.getX(), e.getY());
+ }
+ }
+ });
+
setLayout(new BorderLayout());
add(p, BorderLayout.CENTER);
+
+ }
+
+ private JMenuItem createPlacementChangingMenuItem(String t,
+ final int v,
+ final JTabbedPane dst)
+ {
+ JMenuItem item = new JMenuItem(t);
+
+ item.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent ae)
+ {
+ dst.setTabPlacement(v);
+ }
+ });
+
+ return item;
+ }
+
+ private JMenuItem createLayoutPolicyChangingMenuItem(String t,
+ final int v,
+ final JTabbedPane dst)
+ {
+ JMenuItem item = new JMenuItem(t);
+
+ item.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent ae)
+ {
+ dst.setTabLayoutPolicy(v);
+ }
+ });
+
+ return item;
+ }
+
+ private JTabbedPane createTabbedPane(int direction, String name, int count)
+ {
+ JTabbedPane pane = new JTabbedPane(direction);
+
+ for(int i = 0; i< count; i++)
+ {
+ pane.addTab(name + " " + i, createTabContent(name + " " + i));
+ if (Math.random() >= 0.75)
+ pane.setEnabledAt(i, false);
+ }
+
+ return pane;
+ }
+
+ private JPanel createTabContent(String name)
+ {
+ JTextArea ta;
+ JPanel panel = new JPanel();
+ panel.add(new JLabel(name));
+ panel.add(new JButton(name));
+ panel.add(new JScrollPane(ta = new JTextArea(5, 5)));
+
+ ta.setBackground(colors[(int) (Math.random() * colors.length)]);
+
+ return panel;
}
public void actionPerformed(ActionEvent e)
diff --git a/libjava/classpath/examples/gnu/classpath/examples/swing/TreeDemo.java b/libjava/classpath/examples/gnu/classpath/examples/swing/TreeDemo.java
index 32f765f..8da3750 100644
--- a/libjava/classpath/examples/gnu/classpath/examples/swing/TreeDemo.java
+++ b/libjava/classpath/examples/gnu/classpath/examples/swing/TreeDemo.java
@@ -39,17 +39,17 @@ exception statement from your version. */
package gnu.classpath.examples.swing;
import java.awt.BorderLayout;
-import java.awt.JobAttributes.DefaultSelectionType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import javax.swing.DebugGraphics;
+import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
@@ -59,7 +59,6 @@ import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.DefaultTreeSelectionModel;
import javax.swing.tree.TreePath;
-import javax.swing.tree.TreeSelectionModel;
public class TreeDemo
extends JPanel
@@ -222,11 +221,39 @@ public class TreeDemo
p2.add(add);
p2.add(cbSingle);
p2.add(cbRoot);
-
+
tree.getSelectionModel().
setSelectionMode(DefaultTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
+ // Panel for selecting line style.
+ ActionListener l = new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ JRadioButton b = (JRadioButton) e.getSource();
+ tree.putClientProperty("JTree.lineStyle", b.getText());
+ tree.repaint();
+ }
+ };
+ JPanel lineStylePanel = new JPanel();
+ ButtonGroup buttons = new ButtonGroup();
+ lineStylePanel.add(new JLabel("Line style: "));
+ JRadioButton none = new JRadioButton("None");
+ lineStylePanel.add(none);
+ buttons.add(none);
+ none.addActionListener(l);
+ JRadioButton angled = new JRadioButton("Angled");
+ lineStylePanel.add(angled);
+ buttons.add(angled);
+ angled.addActionListener(l);
+ JRadioButton horizontal = new JRadioButton("Horizontal");
+ lineStylePanel.add(horizontal);
+ buttons.add(horizontal);
+ horizontal.addActionListener(l);
+ p2.add(lineStylePanel);
+
add(p2, BorderLayout.NORTH);
+
add(new JScrollPane(tree), BorderLayout.CENTER);
add(choice, BorderLayout.SOUTH);
}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/swing/forms.html b/libjava/classpath/examples/gnu/classpath/examples/swing/forms.html
new file mode 100644
index 0000000..010a94c
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/swing/forms.html
@@ -0,0 +1,98 @@
+
+
+
+
+
+ a b c x y z Top Left Frame
+
+
diff --git a/libjava/classpath/examples/gnu/classpath/examples/swing/frame2.html b/libjava/classpath/examples/gnu/classpath/examples/swing/frame2.html
new file mode 100644
index 0000000..9dbf33c
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/swing/frame2.html
@@ -0,0 +1,42 @@
+
+
+
+Top Right
+ Frame
+
+
diff --git a/libjava/classpath/examples/gnu/classpath/examples/swing/frame3.html b/libjava/classpath/examples/gnu/classpath/examples/swing/frame3.html
new file mode 100644
index 0000000..e677bd6
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/swing/frame3.html
@@ -0,0 +1,42 @@
+
+
+
+Bottom Left Frame
+
+
+
diff --git a/libjava/classpath/examples/gnu/classpath/examples/swing/frame4.html b/libjava/classpath/examples/gnu/classpath/examples/swing/frame4.html
new file mode 100644
index 0000000..1da53b1
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/swing/frame4.html
@@ -0,0 +1,41 @@
+
+
+
+Bottom Left Frame
+
+
diff --git a/libjava/classpath/examples/gnu/classpath/examples/swing/frames.html b/libjava/classpath/examples/gnu/classpath/examples/swing/frames.html
new file mode 100644
index 0000000..e7e2bf8
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/swing/frames.html
@@ -0,0 +1,44 @@
+
+
+
+
\ No newline at end of file
diff --git a/libjava/classpath/examples/gnu/classpath/examples/swing/tables.html b/libjava/classpath/examples/gnu/classpath/examples/swing/tables.html
new file mode 100644
index 0000000..af908e1
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/swing/tables.html
@@ -0,0 +1,66 @@
+
+
+
+
+
+ Table examples
+Table with grid and mixed rowspan/colspan
+
+
+
diff --git a/libjava/classpath/examples/gnu/classpath/examples/swing/textstyles.html b/libjava/classpath/examples/gnu/classpath/examples/swing/textstyles.html
new file mode 100644
index 0000000..786e18b
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/swing/textstyles.html
@@ -0,0 +1,78 @@
+
+
+
+
+
+
+
+ Spans two columns
+ Spans three rows
+
+
+ Spans two rows
+ This is the center
+
+
+ This should be in the middle of row number 3
+
+
+ A small one cell box
+ Spans two x two cells
+
+
+ Another small one cell box
+ Colors
+ #RRGGBB
+ notation.Font styles
+ Code
, Deleted,
+ Emphasized, Italic, Inserted, Quote
,
+ Stroke-Through, Example, Small,
+ Strike, Strong, Subscript,
+ Superscript, Underlined, Variable
+
These few pages are here to demonstrate and test the HTML rendering + capabilities of GNU Classpath's Swing.
+