[Schmitzm-commits] r714 - in trunk/src/skrueger: . geotools swing swing/checkboxtree

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Feb 21 20:17:36 CET 2010


Author: alfonx
Date: 2010-02-21 20:17:34 +0100 (Sun, 21 Feb 2010)
New Revision: 714

Added:
   trunk/src/skrueger/CheckBoxNodeTreeSample.java
   trunk/src/skrueger/swing/checkboxtree/
   trunk/src/skrueger/swing/checkboxtree/CheckBoxNode.java
   trunk/src/skrueger/swing/checkboxtree/CheckBoxNodeEditor.java
   trunk/src/skrueger/swing/checkboxtree/CheckBoxNodeRenderer.java
   trunk/src/skrueger/swing/checkboxtree/NamedVector.java
Modified:
   trunk/src/skrueger/geotools/StyledLayerUtil.java
Log:
Started a new wizard to import maps and data from other GP atlases. Basically works. This included some simplifacation in the ResourceManager code. It is now a field of the specific AtlasConfig instance. 

Added: trunk/src/skrueger/CheckBoxNodeTreeSample.java
===================================================================
--- trunk/src/skrueger/CheckBoxNodeTreeSample.java	2010-02-19 18:00:30 UTC (rev 713)
+++ trunk/src/skrueger/CheckBoxNodeTreeSample.java	2010-02-21 19:17:34 UTC (rev 714)
@@ -0,0 +1,58 @@
+package skrueger;
+
+/*
+Definitive Guide to Swing for Java 2, Second Edition
+By John Zukowski     
+ISBN: 1-893115-78-X
+Publisher: APress
+*/
+
+import java.awt.BorderLayout;
+import java.util.Vector;
+
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JTree;
+
+import skrueger.swing.checkboxtree.CheckBoxNode;
+import skrueger.swing.checkboxtree.CheckBoxNodeEditor;
+import skrueger.swing.checkboxtree.CheckBoxNodeRenderer;
+import skrueger.swing.checkboxtree.NamedVector;
+
+public class CheckBoxNodeTreeSample {
+  public static void main(String args[]) {
+    JFrame frame = new JFrame("CheckBox Tree");
+
+    CheckBoxNode accessibilityOptions[] = {
+        new CheckBoxNode(
+            "Move system caret with focus/selection changes", false),
+        new CheckBoxNode("Always expand alt text for images", true) };
+    CheckBoxNode browsingOptions[] = {
+        new CheckBoxNode("Notify when downloads complete", true),
+        new CheckBoxNode("Disable script debugging", true),
+        new CheckBoxNode("Use AutoComplete", true),
+        new CheckBoxNode("Browse in a new process", false) };
+    Vector accessVector = new NamedVector("Accessibility",
+        accessibilityOptions);
+    Vector browseVector = new NamedVector("Browsing", browsingOptions);
+    Object rootNodes[] = { accessVector, browseVector };
+    Vector rootVector = new NamedVector("Root", rootNodes);
+    JTree tree = new JTree(rootVector);
+
+    CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer();
+    tree.setCellRenderer(renderer);
+
+    tree.setCellEditor(new CheckBoxNodeEditor(tree));
+    tree.setEditable(true);
+
+    JScrollPane scrollPane = new JScrollPane(tree);
+    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
+    frame.setSize(300, 150);
+    frame.setVisible(true);
+  }
+}
+
+
+
+
+           
\ No newline at end of file


Property changes on: trunk/src/skrueger/CheckBoxNodeTreeSample.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Modified: trunk/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- trunk/src/skrueger/geotools/StyledLayerUtil.java	2010-02-19 18:00:30 UTC (rev 713)
+++ trunk/src/skrueger/geotools/StyledLayerUtil.java	2010-02-21 19:17:34 UTC (rev 714)
@@ -1241,6 +1241,8 @@
 	 */
 	public static void checkAttribMetaData(
 			AttributeMetadataMap attributeMetaDataMap, SimpleFeatureType schema) {
+		
+		if (schema == null) throw new IllegalArgumentException("schmema may not be null!");
 
 		ArrayList<Name> willRemove = new ArrayList<Name>();
 

Added: trunk/src/skrueger/swing/checkboxtree/CheckBoxNode.java
===================================================================
--- trunk/src/skrueger/swing/checkboxtree/CheckBoxNode.java	2010-02-19 18:00:30 UTC (rev 713)
+++ trunk/src/skrueger/swing/checkboxtree/CheckBoxNode.java	2010-02-21 19:17:34 UTC (rev 714)
@@ -0,0 +1,33 @@
+package skrueger.swing.checkboxtree;
+
+public class CheckBoxNode {
+  String text;
+
+  boolean selected;
+
+  public CheckBoxNode(String text, boolean selected) {
+    this.text = text;
+    this.selected = selected;
+  }
+
+  public boolean isSelected() {
+    return selected;
+  }
+
+  public void setSelected(boolean newValue) {
+    selected = newValue;
+  }
+
+  public String getText() {
+    return text;
+  }
+
+  public void setText(String newValue) {
+    text = newValue;
+  }
+
+  public String toString() {
+    return getClass().getName() + "[" + text + "/" + selected + "]";
+  }
+
+}
\ No newline at end of file


Property changes on: trunk/src/skrueger/swing/checkboxtree/CheckBoxNode.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/src/skrueger/swing/checkboxtree/CheckBoxNodeEditor.java
===================================================================
--- trunk/src/skrueger/swing/checkboxtree/CheckBoxNodeEditor.java	2010-02-19 18:00:30 UTC (rev 713)
+++ trunk/src/skrueger/swing/checkboxtree/CheckBoxNodeEditor.java	2010-02-21 19:17:34 UTC (rev 714)
@@ -0,0 +1,74 @@
+package skrueger.swing.checkboxtree;
+
+import java.awt.Component;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.MouseEvent;
+import java.util.EventObject;
+
+import javax.swing.AbstractCellEditor;
+import javax.swing.JCheckBox;
+import javax.swing.JTree;
+import javax.swing.event.ChangeEvent;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreeCellEditor;
+import javax.swing.tree.TreePath;
+
+public class CheckBoxNodeEditor extends AbstractCellEditor implements TreeCellEditor {
+
+  protected CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer();
+
+  ChangeEvent changeEvent = null;
+
+  JTree tree;
+
+  public CheckBoxNodeEditor(JTree tree) {
+    this.tree = tree;
+  }
+
+  public Object getCellEditorValue() {
+    JCheckBox checkbox = renderer.getLeafRenderer();
+    CheckBoxNode checkBoxNode = new CheckBoxNode(checkbox.getText(),
+        checkbox.isSelected());
+    return checkBoxNode; 
+  }
+
+  public boolean isCellEditable(EventObject event) {
+    boolean returnValue = false;
+    if (event instanceof MouseEvent) {
+      MouseEvent mouseEvent = (MouseEvent) event;
+      TreePath path = tree.getPathForLocation(mouseEvent.getX(),
+          mouseEvent.getY());
+      if (path != null) {
+        Object node = path.getLastPathComponent();
+        if ((node != null) && (node instanceof DefaultMutableTreeNode)) {
+          DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
+          Object userObject = treeNode.getUserObject();
+          returnValue = ((treeNode.isLeaf()) && (userObject instanceof CheckBoxNode));
+        }
+      }
+    }
+    return returnValue;
+  }
+
+  public Component getTreeCellEditorComponent(JTree tree, Object value,
+      boolean selected, boolean expanded, boolean leaf, int row) {
+
+    Component editor = renderer.getTreeCellRendererComponent(tree, value,
+        true, expanded, leaf, row, true);
+
+    // editor always selected / focused
+    ItemListener itemListener = new ItemListener() {
+      public void itemStateChanged(ItemEvent itemEvent) {
+        if (stopCellEditing()) {
+          fireEditingStopped();
+        }
+      }
+    };
+    if (editor instanceof JCheckBox) {
+      ((JCheckBox) editor).addItemListener(itemListener);
+    }
+
+    return editor;
+  }
+}


Property changes on: trunk/src/skrueger/swing/checkboxtree/CheckBoxNodeEditor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/src/skrueger/swing/checkboxtree/CheckBoxNodeRenderer.java
===================================================================
--- trunk/src/skrueger/swing/checkboxtree/CheckBoxNodeRenderer.java	2010-02-19 18:00:30 UTC (rev 713)
+++ trunk/src/skrueger/swing/checkboxtree/CheckBoxNodeRenderer.java	2010-02-21 19:17:34 UTC (rev 714)
@@ -0,0 +1,93 @@
+package skrueger.swing.checkboxtree;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Font;
+
+import javax.swing.BorderFactory;
+import javax.swing.JCheckBox;
+import javax.swing.JTree;
+import javax.swing.UIManager;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.TreeCellRenderer;
+
+public class CheckBoxNodeRenderer implements TreeCellRenderer {
+  protected JCheckBox leafRenderer = new JCheckBox();
+
+  protected DefaultTreeCellRenderer nonLeafRenderer = new DefaultTreeCellRenderer();
+
+  Color selectionBorderColor;
+
+protected Color selectionForeground;
+
+protected Color selectionBackground;
+
+protected Color textForeground;
+
+protected Color textBackground;
+
+  public JCheckBox getLeafRenderer() {
+    return leafRenderer;
+  }
+
+  public CheckBoxNodeRenderer() {
+    Font fontValue;
+    fontValue = UIManager.getFont("Tree.font");
+    if (fontValue != null) {
+      leafRenderer.setFont(fontValue);
+    }
+    Boolean booleanValue = (Boolean) UIManager
+        .get("Tree.drawsFocusBorderAroundIcon");
+    leafRenderer.setFocusPainted((booleanValue != null)
+        && (booleanValue.booleanValue()));
+    
+    leafRenderer.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
+
+    selectionBorderColor = UIManager.getColor("Tree.selectionBorderColor");
+    selectionForeground = UIManager.getColor("Tree.selectionForeground");
+    selectionBackground = UIManager.getColor("Tree.selectionBackground");
+    textForeground = UIManager.getColor("Tree.textForeground");
+    textBackground = UIManager.getColor("Tree.textBackground");
+  }
+
+  public Component getTreeCellRendererComponent(JTree tree, Object value,
+      boolean selected, boolean expanded, boolean leaf, int row,
+      boolean hasFocus) {
+
+    Component returnValue;
+    if (leaf) {
+
+      String stringValue = tree.convertValueToText(value, selected,
+          expanded, leaf, row, false);
+      leafRenderer.setText(stringValue);
+      leafRenderer.setSelected(false);
+
+      leafRenderer.setEnabled(tree.isEnabled());
+
+      if (selected) {
+        leafRenderer.setForeground(selectionForeground);
+        leafRenderer.setBackground(selectionBackground);
+      } else {
+        leafRenderer.setForeground(textForeground);
+        leafRenderer.setBackground(textBackground);
+      }
+
+      if ((value != null) && (value instanceof DefaultMutableTreeNode)) {
+        Object userObject = ((DefaultMutableTreeNode) value)
+            .getUserObject();
+        if (userObject instanceof CheckBoxNode) {
+          CheckBoxNode node = (CheckBoxNode) userObject;
+          leafRenderer.setText(node.getText());
+          leafRenderer.setSelected(node.isSelected());
+        }
+        
+      }
+      returnValue = leafRenderer;
+    } else {
+      returnValue = nonLeafRenderer.getTreeCellRendererComponent(tree,
+          value, selected, expanded, leaf, row, hasFocus);
+    }
+    return returnValue;
+  }
+}
\ No newline at end of file


Property changes on: trunk/src/skrueger/swing/checkboxtree/CheckBoxNodeRenderer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/src/skrueger/swing/checkboxtree/NamedVector.java
===================================================================
--- trunk/src/skrueger/swing/checkboxtree/NamedVector.java	2010-02-19 18:00:30 UTC (rev 713)
+++ trunk/src/skrueger/swing/checkboxtree/NamedVector.java	2010-02-21 19:17:34 UTC (rev 714)
@@ -0,0 +1,22 @@
+package skrueger.swing.checkboxtree;
+
+import java.util.Vector;
+
+public class NamedVector extends Vector {
+  String name;
+
+  public NamedVector(String name) {
+    this.name = name;
+  }
+
+  public NamedVector(String name, Object elements[]) {
+    this.name = name;
+    for (int i = 0, n = elements.length; i < n; i++) {
+      add(elements[i]);
+    }
+  }
+
+  public String toString() {
+    return "[" + name + "]";
+  }
+}
\ No newline at end of file


Property changes on: trunk/src/skrueger/swing/checkboxtree/NamedVector.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native



More information about the Schmitzm-commits mailing list