This is the first part of the CSS parser I'm working on. This breaks
down the input stream in more handy tokens.
The reason why I check in a half complete thing is a problem in the
stream handling. At the end of the stream I get a \FFFF followed by the
normal -1, which looks very suspicious, because \FFFF is definitly not
in the file. Try it out yourself by simply running:
jamvm gnu.javax.swing.html.css.CSSScanner
The class has a small testprog, that reads in the file
javax/swing/text/html/default.css, and has some debug output in nextToken().
2006-08-16 Roman Kennke <[EMAIL PROTECTED]>
* gnu/javax/swing/text/html/css/CSSScanner.java: New file.
* gnu/javax/swing/text/html/css/CSSLexicalException.java:
New file.
/Roman
Index: javax/swing/plaf/metal/MetalTreeUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalTreeUI.java,v
retrieving revision 1.17
diff -u -1 -2 -r1.17 MetalTreeUI.java
--- javax/swing/plaf/metal/MetalTreeUI.java 23 Mar 2006 00:30:14 -0000 1.17
+++ javax/swing/plaf/metal/MetalTreeUI.java 16 Aug 2006 00:30:30 -0000
@@ -29,42 +29,105 @@
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 javax.swing.plaf.metal;
-import gnu.classpath.NotImplementedException;
-
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import javax.swing.JTree;
+import javax.swing.UIManager;
import javax.swing.tree.TreePath;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTreeUI;
/**
* A UI delegate for the [EMAIL PROTECTED] JTree} component.
*/
public class MetalTreeUI extends BasicTreeUI
{
/**
+ * Listens for property changes of the line style and updates the
+ * internal setting.
+ */
+ private class LineStyleListener
+ implements PropertyChangeListener
+ {
+
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ if (e.getPropertyName().equals(LINE_STYLE_PROPERTY))
+ decodeLineStyle(e.getNewValue());
+ }
+
+ }
+
+ /**
+ * The key to the lineStyle client property.
+ */
+ private static final String LINE_STYLE_PROPERTY = "JTree.lineStyle";
+
+ /**
+ * The property value indicating no line style.
+ */
+ private static final String LINE_STYLE_VALUE_NONE = "None";
+
+ /**
+ * The property value indicating angled line style.
+ */
+ private static final String LINE_STYLE_VALUE_ANGLED = "Angled";
+
+ /**
+ * The property value indicating horizontal line style.
+ */
+ private static final String LINE_STYLE_VALUE_HORIZONTAL = "Horizontal";
+
+ /**
+ * The line style for None.
+ */
+ private static final int LINE_STYLE_NONE = 0;
+
+ /**
+ * The line style for Angled.
+ */
+ private static final int LINE_STYLE_ANGLED = 1;
+
+ /**
+ * The line style for Horizontal.
+ */
+ private static final int LINE_STYLE_HORIZONTAL = 2;
+
+ /**
+ * The current line style.
+ */
+ private int lineStyle;
+
+ /**
+ * Listens for changes on the line style property and updates the
+ * internal settings.
+ */
+ private PropertyChangeListener lineStyleListener;
+
+ /**
* Constructs a new instance of <code>MetalTreeUI</code>.
*/
public MetalTreeUI()
{
super();
}
/**
* Returns a new instance of <code>MetalTreeUI</code>.
*
* @param component the component for which we return an UI instance
*
@@ -94,59 +157,72 @@
* opacity, etc. on the component. Whenever possible, property values
* initialized by the client program should not be overridden.
* 2. Install a LayoutManager on the component if necessary.
* 3. Create/add any required sub-components to the component.
* 4. Create/install event listeners on the component.
* 5. Create/install a PropertyChangeListener on the component in order
* to detect and respond to component property changes appropriately.
* 6. Install keyboard UI (mnemonics, traversal, etc.) on the component.
* 7. Initialize any appropriate instance data.
*/
public void installUI(JComponent c)
{
- // TODO: What to do here, if anything?
super.installUI(c);
+
+ Object lineStyleProp = c.getClientProperty(LINE_STYLE_PROPERTY);
+ decodeLineStyle(lineStyleProp);
+ if (lineStyleListener == null)
+ lineStyleListener = new LineStyleListener();
+ c.addPropertyChangeListener(lineStyleListener);
}
/**
* Reverses configuration which was done on the specified component during
* installUI. This method is invoked when this UIComponent instance is being
* removed as the UI delegate for the specified component. This method should
* undo the configuration performed in installUI, being careful to leave the
* JComponent instance in a clean state (no extraneous listeners,
* look-and-feel-specific property objects, etc.). This should include
* the following:
* 1. Remove any UI-set borders from the component.
* 2. Remove any UI-set layout managers on the component.
* 3. Remove any UI-added sub-components from the component.
* 4. Remove any UI-added event/property listeners from the component.
* 5. Remove any UI-installed keyboard UI from the component.
* 6. Nullify any allocated instance data objects to allow for GC.
*/
public void uninstallUI(JComponent c)
{
- // TODO: What to do here?
super.uninstallUI(c);
+ if (lineStyleListener != null)
+ c.removePropertyChangeListener(lineStyleListener);
+ lineStyleListener = null;
}
/**
* This function converts between the string passed into the client
* property and the internal representation (currently an int).
*
* @param lineStyleFlag - String representation
*/
protected void decodeLineStyle(Object lineStyleFlag)
- throws NotImplementedException
{
- // FIXME: not implemented
+ if (lineStyleFlag == null || lineStyleFlag.equals(LINE_STYLE_VALUE_ANGLED))
+ lineStyle = LINE_STYLE_ANGLED;
+ else if (lineStyleFlag.equals(LINE_STYLE_VALUE_HORIZONTAL))
+ lineStyle = LINE_STYLE_HORIZONTAL;
+ else if (lineStyleFlag.equals(LINE_STYLE_VALUE_NONE))
+ lineStyle = LINE_STYLE_NONE;
+ else
+ lineStyle = LINE_STYLE_ANGLED;
}
/**
* Checks if the location is in expand control.
*
* @param row - current row
* @param rowLevel - current level
* @param mouseX - current x location of the mouse click
* @param mouseY - current y location of the mouse click
*/
protected boolean isLocationInExpandControl(int row, int rowLevel,
int mouseX, int mouseY)
@@ -161,57 +237,81 @@
* specified component is being painted. Subclasses should override this
* method and use the specified Graphics object to render the content of
* the component.
*
* @param g - the current graphics configuration.
* @param c - the current component to draw
*/
public void paint(Graphics g, JComponent c)
{
// Calls BasicTreeUI's paint since it takes care of painting all
// types of icons.
super.paint(g, c);
+
+ if (lineStyle == LINE_STYLE_HORIZONTAL)
+ paintHorizontalSeparators(g, c);
}
/**
* Paints the horizontal separators.
*
* @param g - the current graphics configuration.
* @param c - the current component to draw
*/
protected void paintHorizontalSeparators(Graphics g, JComponent c)
- throws NotImplementedException
{
- // FIXME: not implemented
+ g.setColor(UIManager.getColor("Tree.line"));
+ Rectangle clip = g.getClipBounds();
+ int row0 = getRowForPath(tree, getClosestPathForLocation(tree, 0, clip.y));
+ int row1 =
+ getRowForPath(tree, getClosestPathForLocation(tree, 0,
+ clip.y + clip.height - 1));
+ if (row0 >= 0 && row1 >= 0)
+ {
+ for (int i = row0; i <= row1; i++)
+ {
+ TreePath p = getPathForRow(tree, i);
+ if (p != null && p.getPathCount() == 2)
+ {
+ Rectangle r = getPathBounds(tree, getPathForRow(tree, i));
+ if (r != null)
+ {
+ g.drawLine(clip.x, r.y, clip.x + clip.width, r.y);
+ }
+ }
+ }
+ }
}
/**
* Paints the vertical part of the leg. The receiver should NOT modify
* clipBounds, insets.
*
* @param g - the current graphics configuration.
* @param clipBounds -
* @param insets -
* @param path - the current path
*/
protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds,
Insets insets, TreePath path)
{
- super.paintVerticalPartOfLeg(g, clipBounds, insets, path);
+ if (lineStyle == LINE_STYLE_ANGLED)
+ super.paintVerticalPartOfLeg(g, clipBounds, insets, path);
}
/**
* Paints the horizontal part of the leg. The receiver should NOT \
* modify clipBounds, or insets.
* NOTE: parentRow can be -1 if the root is not visible.
*/
protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds,
Insets insets, Rectangle bounds,
TreePath path, int row,
boolean isExpanded, boolean hasBeenExpanded,
boolean isLeaf)
{
- super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds, path, row,
- isExpanded, hasBeenExpanded, isLeaf);
+ if (lineStyle == LINE_STYLE_ANGLED)
+ super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds, path, row,
+ isExpanded, hasBeenExpanded, isLeaf);
}
}
Index: examples/gnu/classpath/examples/swing/TreeDemo.java
===================================================================
RCS file: /cvsroot/classpath/classpath/examples/gnu/classpath/examples/swing/TreeDemo.java,v
retrieving revision 1.4
diff -u -1 -2 -r1.4 TreeDemo.java
--- examples/gnu/classpath/examples/swing/TreeDemo.java 27 Apr 2006 08:23:46 -0000 1.4
+++ examples/gnu/classpath/examples/swing/TreeDemo.java 16 Aug 2006 00:30:30 -0000
@@ -30,45 +30,44 @@
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.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;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
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
implements ActionListener
{
TreeDemo()
{
super();
createContent();
}
@@ -213,29 +212,57 @@
now == null ? "none":now.getLastPathComponent().toString();
choice.setText("From "+swas+" to "+snow);
}
}
);
setLayout(new BorderLayout());
JPanel p2 = new JPanel();
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);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("CLOSE"))
{
System.exit(0);
}
}