|
From: <be...@us...> - 2006-10-23 20:45:42
|
Revision: 39
http://svn.sourceforge.net/jtreemap/?rev=39&view=rev
Author: benoitx
Date: 2006-10-23 13:45:30 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
ready to accept code...
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/
trunk/JTreeMap/src/main/java/net/sf/
trunk/JTreeMap/src/main/java/net/sf/jtreemap/
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 20:53:34
|
Revision: 40
http://svn.sourceforge.net/jtreemap/?rev=40&view=rev
Author: benoitx
Date: 2006-10-23 13:53:08 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/example/
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example (from rev 39, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/example)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 20:54:26
|
Revision: 41
http://svn.sourceforge.net/jtreemap/?rev=41&view=rev
Author: benoitx
Date: 2006-10-23 13:54:03 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/ColorProvider.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/ColorProvider.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/ColorProvider.java (from rev 40, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/ColorProvider.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/ColorProvider.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/ColorProvider.java 2006-10-23 20:54:03 UTC (rev 41)
@@ -0,0 +1,30 @@
+package org.jense.swing.jtreemap;
+
+import javax.swing.JPanel;
+import java.awt.Color;
+
+/**
+ * Abstract class with the methods who attribute color to the elements of
+ * JTreeMap.
+ *
+ * @author Laurent DUTHEIL
+ */
+
+public abstract class ColorProvider {
+
+ /**
+ * get the associated color to the value.
+ *
+ *@param value double value
+ *@return the associated color to the value
+ */
+ public abstract Color getColor(Value value);
+
+ /**
+ * get a legend JPanel.
+ *
+ *@return a legend JPanel
+ */
+ public abstract JPanel getLegendPanel();
+
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/ColorProvider.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/ColorProvider.java 2006-10-23 20:53:08 UTC (rev 40)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/ColorProvider.java 2006-10-23 20:54:03 UTC (rev 41)
@@ -1,30 +0,0 @@
-package org.jense.swing.jtreemap;
-
-import javax.swing.JPanel;
-import java.awt.Color;
-
-/**
- * Abstract class with the methods who attribute color to the elements of
- * JTreeMap.
- *
- * @author Laurent DUTHEIL
- */
-
-public abstract class ColorProvider {
-
- /**
- * get the associated color to the value.
- *
- *@param value double value
- *@return the associated color to the value
- */
- public abstract Color getColor(Value value);
-
- /**
- * get a legend JPanel.
- *
- *@return a legend JPanel
- */
- public abstract JPanel getLegendPanel();
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 20:55:20
|
Revision: 42
http://svn.sourceforge.net/jtreemap/?rev=42&view=rev
Author: benoitx
Date: 2006-10-23 13:54:54 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTip.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultToolTip.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTip.java (from rev 41, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultToolTip.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTip.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTip.java 2006-10-23 20:54:54 UTC (rev 42)
@@ -0,0 +1,58 @@
+/*
+ * Created on 28 sept. 2005
+ */
+package org.jense.swing.jtreemap;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Graphics;
+
+import javax.swing.JToolTip;
+
+/**
+ * Default ToolTip for the jTreeMap.
+ *
+ * @author Laurent DUTHEIL
+ */
+public class DefaultToolTip extends JToolTip {
+ private static final long serialVersionUID = -2492627777999093973L;
+ private JTreeMap jTreeMap;
+ private Font labelFont;
+ private Font valueFont;
+
+ /**
+ * Constructor.
+ *
+ * @param jTreeMap the jTreeMap who display the tooltip
+ */
+ public DefaultToolTip(JTreeMap jTreeMap) {
+ this.jTreeMap = jTreeMap;
+ this.labelFont = new Font("Default", Font.BOLD, 14);
+ this.valueFont = new Font("Default", Font.PLAIN, 10);
+
+ int width = 160;
+ int height = getFontMetrics(this.labelFont).getHeight()
+ + getFontMetrics(this.valueFont).getHeight();
+
+ Dimension size = new Dimension(width, height);
+ this.setSize(size);
+ this.setPreferredSize(size);
+ }
+
+ @Override
+ public void paint(Graphics g) {
+ if (this.jTreeMap.getActiveLeaf() != null) {
+ g.setColor(Color.lightGray);
+ g.fill3DRect(0, 0, this.getWidth(), this.getHeight(), true);
+ g.setColor(Color.black);
+ g.setFont(this.labelFont);
+ g.drawString(this.jTreeMap.getActiveLeaf().getLabel(), 5, g
+ .getFontMetrics(this.labelFont).getAscent());
+ g.setFont(this.valueFont);
+ g.drawString(this.jTreeMap.getActiveLeaf().getLabelValue(), 5, this
+ .getHeight() - 5);
+ }
+ }
+
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultToolTip.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultToolTip.java 2006-10-23 20:54:03 UTC (rev 41)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultToolTip.java 2006-10-23 20:54:54 UTC (rev 42)
@@ -1,58 +0,0 @@
-/*
- * Created on 28 sept. 2005
- */
-package org.jense.swing.jtreemap;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Graphics;
-
-import javax.swing.JToolTip;
-
-/**
- * Default ToolTip for the jTreeMap.
- *
- * @author Laurent DUTHEIL
- */
-public class DefaultToolTip extends JToolTip {
- private static final long serialVersionUID = -2492627777999093973L;
- private JTreeMap jTreeMap;
- private Font labelFont;
- private Font valueFont;
-
- /**
- * Constructor.
- *
- * @param jTreeMap the jTreeMap who display the tooltip
- */
- public DefaultToolTip(JTreeMap jTreeMap) {
- this.jTreeMap = jTreeMap;
- this.labelFont = new Font("Default", Font.BOLD, 14);
- this.valueFont = new Font("Default", Font.PLAIN, 10);
-
- int width = 160;
- int height = getFontMetrics(this.labelFont).getHeight()
- + getFontMetrics(this.valueFont).getHeight();
-
- Dimension size = new Dimension(width, height);
- this.setSize(size);
- this.setPreferredSize(size);
- }
-
- @Override
- public void paint(Graphics g) {
- if (this.jTreeMap.getActiveLeaf() != null) {
- g.setColor(Color.lightGray);
- g.fill3DRect(0, 0, this.getWidth(), this.getHeight(), true);
- g.setColor(Color.black);
- g.setFont(this.labelFont);
- g.drawString(this.jTreeMap.getActiveLeaf().getLabel(), 5, g
- .getFontMetrics(this.labelFont).getAscent());
- g.setFont(this.valueFont);
- g.drawString(this.jTreeMap.getActiveLeaf().getLabelValue(), 5, this
- .getHeight() - 5);
- }
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 20:56:42
|
Revision: 43
http://svn.sourceforge.net/jtreemap/?rev=43&view=rev
Author: benoitx
Date: 2006-10-23 13:56:21 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTipBuilder.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultToolTipBuilder.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTipBuilder.java (from rev 42, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultToolTipBuilder.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTipBuilder.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTipBuilder.java 2006-10-23 20:56:21 UTC (rev 43)
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package org.jense.swing.jtreemap;
+
+import javax.swing.JToolTip;
+
+/**
+ * Default class to build the DefaultToolTip displayed by the JTreeMap.<BR>
+ *
+ * @see org.jense.swing.jtreemap.DefaultToolTip
+ * @author Laurent DUTHEIL
+ *
+ */
+public class DefaultToolTipBuilder implements IToolTipBuilder {
+ private static JToolTip instance = null;
+ private JTreeMap jTreeMap;
+
+ /**
+ * Constructor.
+ *
+ * @param jTreeMap the linked JTreeMap
+ */
+ public DefaultToolTipBuilder(JTreeMap jTreeMap) {
+ this.jTreeMap = jTreeMap;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jense.swing.jtreemap.IToolTipBuilder#getToolTip()
+ */
+ public JToolTip getToolTip() {
+ if (instance == null) {
+ instance = new DefaultToolTip(this.jTreeMap);
+ }
+ return instance;
+ }
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultToolTipBuilder.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultToolTipBuilder.java 2006-10-23 20:54:54 UTC (rev 42)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultToolTipBuilder.java 2006-10-23 20:56:21 UTC (rev 43)
@@ -1,37 +0,0 @@
-/**
- *
- */
-package org.jense.swing.jtreemap;
-
-import javax.swing.JToolTip;
-
-/**
- * Default class to build the DefaultToolTip displayed by the JTreeMap.<BR>
- *
- * @see org.jense.swing.jtreemap.DefaultToolTip
- * @author Laurent DUTHEIL
- *
- */
-public class DefaultToolTipBuilder implements IToolTipBuilder {
- private static JToolTip instance = null;
- private JTreeMap jTreeMap;
-
- /**
- * Constructor.
- *
- * @param jTreeMap the linked JTreeMap
- */
- public DefaultToolTipBuilder(JTreeMap jTreeMap) {
- this.jTreeMap = jTreeMap;
- }
-
- /* (non-Javadoc)
- * @see org.jense.swing.jtreemap.IToolTipBuilder#getToolTip()
- */
- public JToolTip getToolTip() {
- if (instance == null) {
- instance = new DefaultToolTip(this.jTreeMap);
- }
- return instance;
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 20:58:04
|
Revision: 44
http://svn.sourceforge.net/jtreemap/?rev=44&view=rev
Author: benoitx
Date: 2006-10-23 13:57:38 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultValue.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultValue.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultValue.java (from rev 43, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultValue.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultValue.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultValue.java 2006-10-23 20:57:38 UTC (rev 44)
@@ -0,0 +1,72 @@
+/*
+ * Created on 10 oct. 2005
+ */
+package org.jense.swing.jtreemap;
+
+/**
+ * Default Value <BR>
+ * The getLabel() method returns the "" + getValue()
+ *
+ * @author Laurent DUTHEIL
+ */
+public class DefaultValue extends Value {
+ private double value;
+
+ /**
+ * Constructor.
+ */
+ public DefaultValue() {
+ //nothing to do
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param value double value
+ */
+ public DefaultValue(double value) {
+ this.value = value;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jense.swing.jtreemap.Value#getValue()
+ */
+ @Override
+ public double getValue() {
+ return this.value;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jense.swing.jtreemap.Value#getLabel()
+ */
+ @Override
+ public String getLabel() {
+ return "" + this.value;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jense.swing.jtreemap.Value#setValue(double)
+ */
+ @Override
+ public void setValue(double value) {
+ this.value = value;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jense.swing.jtreemap.Value#setLabel(java.lang.String)
+ */
+ @Override
+ public void setLabel(String newLabel) {
+ // ignore
+
+ }
+
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultValue.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultValue.java 2006-10-23 20:56:21 UTC (rev 43)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/DefaultValue.java 2006-10-23 20:57:38 UTC (rev 44)
@@ -1,72 +0,0 @@
-/*
- * Created on 10 oct. 2005
- */
-package org.jense.swing.jtreemap;
-
-/**
- * Default Value <BR>
- * The getLabel() method returns the "" + getValue()
- *
- * @author Laurent DUTHEIL
- */
-public class DefaultValue extends Value {
- private double value;
-
- /**
- * Constructor.
- */
- public DefaultValue() {
- //nothing to do
- }
-
- /**
- * Constructor.
- *
- * @param value double value
- */
- public DefaultValue(double value) {
- this.value = value;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.jense.swing.jtreemap.Value#getValue()
- */
- @Override
- public double getValue() {
- return this.value;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.jense.swing.jtreemap.Value#getLabel()
- */
- @Override
- public String getLabel() {
- return "" + this.value;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.jense.swing.jtreemap.Value#setValue(double)
- */
- @Override
- public void setValue(double value) {
- this.value = value;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.jense.swing.jtreemap.Value#setLabel(java.lang.String)
- */
- @Override
- public void setLabel(String newLabel) {
- // ignore
-
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 20:58:53
|
Revision: 45
http://svn.sourceforge.net/jtreemap/?rev=45&view=rev
Author: benoitx
Date: 2006-10-23 13:58:29 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/IToolTipBuilder.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/IToolTipBuilder.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/IToolTipBuilder.java (from rev 44, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/IToolTipBuilder.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/IToolTipBuilder.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/IToolTipBuilder.java 2006-10-23 20:58:29 UTC (rev 45)
@@ -0,0 +1,25 @@
+/*
+ * Created on 6 mars 2006
+ *
+ */
+package org.jense.swing.jtreemap;
+
+import javax.swing.JToolTip;
+
+/**
+ * Interface used to build your own JToolTip for the jTreeMap.
+ *
+ * @see org.jense.swing.jtreemap.JTreeMap#setToolTipBuilder(IToolTipBuilder)
+ * @author Laurent DUTHEIL
+ */
+public interface IToolTipBuilder {
+
+ /**
+ * Return the instance of the JToolTip.<BR>
+ * Override this method to build your own JToolTip
+ *
+ * @return the instance of the JToolTip
+ */
+ public abstract JToolTip getToolTip();
+
+}
\ No newline at end of file
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/IToolTipBuilder.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/IToolTipBuilder.java 2006-10-23 20:57:38 UTC (rev 44)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/IToolTipBuilder.java 2006-10-23 20:58:29 UTC (rev 45)
@@ -1,25 +0,0 @@
-/*
- * Created on 6 mars 2006
- *
- */
-package org.jense.swing.jtreemap;
-
-import javax.swing.JToolTip;
-
-/**
- * Interface used to build your own JToolTip for the jTreeMap.
- *
- * @see org.jense.swing.jtreemap.JTreeMap#setToolTipBuilder(IToolTipBuilder)
- * @author Laurent DUTHEIL
- */
-public interface IToolTipBuilder {
-
- /**
- * Return the instance of the JToolTip.<BR>
- * Override this method to build your own JToolTip
- *
- * @return the instance of the JToolTip
- */
- public abstract JToolTip getToolTip();
-
-}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 20:59:52
|
Revision: 46
http://svn.sourceforge.net/jtreemap/?rev=46&view=rev
Author: benoitx
Date: 2006-10-23 13:59:22 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/JTreeMap.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/JTreeMap.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/JTreeMap.java (from rev 45, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/JTreeMap.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/JTreeMap.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/JTreeMap.java 2006-10-23 20:59:22 UTC (rev 46)
@@ -0,0 +1,581 @@
+package org.jense.swing.jtreemap;
+
+import java.util.Enumeration;
+import java.awt.Color;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.event.MouseMotionAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.JComponent;
+import javax.swing.JToolTip;
+import javax.swing.ToolTipManager;
+import javax.swing.border.Border;
+
+/**
+ * JComponent who represents each element of a tree in a rectangle of more or
+ * less big size according to its importance in the tree.
+ * <p>
+ * A tree structure may includes more or less important elements. For example,
+ * in a tree structure of files, there can be files of big size. Then it can be
+ * interesting to know which repertory is the most important on a hard disk.
+ * <p>
+ * Moreover, we can add a code color which makes it possible to introduce new
+ * information into the representation of the tree structure.
+ * <p>
+ * So, in a JTreeMap, you can see the size and the value of an element in a
+ * tree.
+ *
+ * @see org.jense.swing.jtreemap.TreeMapNode
+ * @author Laurent Dutheil
+ */
+public class JTreeMap extends JComponent {
+ private static final long serialVersionUID = 7255952672238300249L;
+ private static final Color transparencyColor = new Color(204, 204, 204, 128);
+ // active leaf
+ private TreeMapNode activeLeaf = null;
+ // color provider
+ private ColorProvider colorProvider = null;
+ // displayed root
+ private TreeMapNode displayedRoot = null;
+ // root of the tree
+ private TreeMapNode root = null;
+ // divide strategy
+ private SplitStrategy strategy = null;
+ // tooltip builder
+ private IToolTipBuilder toolTipBuilder;
+ // zoom
+ private Zoom zoom;
+
+ /**
+ * Constructor of JTreeMap. <BR>
+ * The chosen strategy is SplitSquarified. <BR>
+ * The chosen color provider is UniqueColorProvider.
+ *
+ * @see SplitSquarified
+ * @see UniqueColorProvider
+ * @param root the root of the tree to display
+ */
+ public JTreeMap(TreeMapNode root) {
+ this(root, new SplitSquarified());
+ }
+
+ /**
+ * Constructor of JTreeMap. <BR>
+ * The chosen color provider is UniqueColorProvider.
+ *
+ * @see UniqueColorProvider
+ * @param root the root of the tree to display
+ * @param strategy the split strategy
+ */
+ public JTreeMap(TreeMapNode root, SplitStrategy strategy) {
+ // ToolTips appears without delay and stay as long as possible
+ ToolTipManager ttm = ToolTipManager.sharedInstance();
+ ttm.setInitialDelay(0);
+ ttm.setReshowDelay(0);
+ ttm.setDismissDelay(100000);
+ ttm.setEnabled(true);
+ ttm.setLightWeightPopupEnabled(true);
+ this.setToolTipText("");
+
+ // the default DefaultToolTipBuilder
+ this.toolTipBuilder = new DefaultToolTipBuilder(this);
+
+ this.zoom = new Zoom();
+
+ this.setRoot(root);
+ this.setStrategy(strategy);
+ this.setColorProvider(new UniqueColorProvider());
+
+ this.addMouseMotionListener(new HandleMouseMotion());
+ }
+
+ /**
+ * calculate the postitions for the displayed root. <BR>
+ * The positions of the root must be calculated first.
+ */
+ public void calculatePositions() {
+ if (this.getStrategy() != null && this.displayedRoot != null) {
+ this.getStrategy().calculatePositions(this.displayedRoot);
+ }
+ }
+
+ @Override
+ public JToolTip createToolTip() {
+ return this.toolTipBuilder.getToolTip();
+ }
+
+ /**
+ * draw the item.
+ *
+ * @param g Graphics where you have to draw
+ * @param item item to draw
+ */
+ protected void draw(Graphics g, TreeMapNode item) {
+ if (item.isLeaf()) {
+ g.setColor(this.colorProvider.getColor(item.getValue()));
+ g.fillRect(item.getX(), item.getY(), item.getWidth(), item.getHeight());
+ } else {
+ for (Enumeration e = item.children(); e.hasMoreElements();) {
+ draw(g, (TreeMapNode) (e.nextElement()));
+ }
+ }
+ }
+
+ /**
+ * write the label in the middle of the item. <BR>
+ * You have first to define the font of the Graphics. <BR>
+ * You may override this method to change the position or the color of the
+ * label.
+ *
+ * @param g Graphics where you have to draw
+ * @param item TreeMapNode to draw
+ */
+ protected void drawLabel(Graphics g, TreeMapNode item) {
+ FontMetrics fm = g.getFontMetrics(g.getFont());
+ // if the height of the item is high enough
+ if (fm.getHeight() < item.getHeight() - 2) {
+ String label = item.getLabel();
+
+ int y = (item.getHeight() + fm.getAscent() - fm.getDescent()) / 2;
+ int stringWidth = fm.stringWidth(label);
+ // the width of the label depends on the font :
+ // if the width of the label is larger than the item
+ if (item.getWidth() - 5 <= stringWidth) {
+ // We have to truncate the label
+ // number of chars who can be writen in the item
+ int nbChar = (label.length() * item.getWidth()) / stringWidth;
+ if (nbChar > 3) {
+ // and add "..." at the end
+ label = label.substring(0, nbChar - 3) + "...";
+ } else {
+ // if it is not enough large, we display nothing
+ label = "";
+ }
+ }
+ int x = (item.getWidth() - fm.stringWidth(label)) / 2;
+
+ // background in black
+ g.setColor(Color.black);
+ g.drawString(label, item.getX() + x + 1, item.getY() + y + 1);
+ g.drawString(label, item.getX() + x - 1, item.getY() + y + 1);
+ g.drawString(label, item.getX() + x + 1, item.getY() + y - 1);
+ g.drawString(label, item.getX() + x - 1, item.getY() + y - 1);
+ g.drawString(label, item.getX() + x + 1, item.getY() + y);
+ g.drawString(label, item.getX() + x - 1, item.getY() + y);
+ g.drawString(label, item.getX() + x, item.getY() + y + 1);
+ g.drawString(label, item.getX() + x, item.getY() + y - 1);
+ // label in white
+ g.setColor(Color.white);
+ g.drawString(label, item.getX() + x, item.getY() + y);
+ }
+ }
+
+ /**
+ * Draw all the labels to draw. <BR>
+ * You may override this method to draw the labels you want. <BR>
+ * For exemples, all the leaves, or all the first level children, or all of
+ * them...
+ *
+ * @param g Graphics where you have to draw
+ * @param item TreeMapNode to draw
+ */
+ protected void drawLabels(Graphics g, TreeMapNode item) {
+ // add the labels (level -1)
+ g.setFont(this.getFont());
+ if (this.displayedRoot.isLeaf()) {
+ drawLabel(g, this.displayedRoot);
+ } else {
+ for (Enumeration e = this.displayedRoot.children(); e.hasMoreElements();) {
+ drawLabel(g, (TreeMapNode) (e.nextElement()));
+ }
+ }
+
+ /* uncomment to add the labels of the lowered levels (up to depth > 2) */
+ // int depth = item.getLevel() - this.displayedRoot.getLevel();
+ // float newSize = Math.max(20, this.getFont().getSize2D());
+ // java.awt.Font labelFont = this.getFont().deriveFont(java.awt.Font.BOLD,
+ // newSize - 3 * depth);
+ // g.setFont(labelFont);
+ // if (depth > 2) {
+ // drawLabel(g, item);
+ // return;
+ // }
+ // if (item.isLeaf()) {
+ // drawLabel(g, item);
+ // } else {
+ // for (Enumeration e = item.children(); e.hasMoreElements();) {
+ // drawLabels(g, (TreeMapNode) (e.nextElement()));
+ // }
+ // }
+ }
+
+ /**
+ * get the active leaf (the one under the mouse).
+ *
+ * @return Returns the activeLeaf.
+ */
+ public TreeMapNode getActiveLeaf() {
+ return this.activeLeaf;
+ }
+
+ /**
+ * get the ColorProvider.
+ *
+ * @return the ColorProvider
+ */
+ public ColorProvider getColorProvider() {
+ return this.colorProvider;
+ }
+
+ /**
+ * get the displayed root.
+ * <p>
+ * This may be not the root of the jTreeMap. After a zoom, the displayed root
+ * can be the root of an under-tree.
+ * </p>
+ *
+ * @return the displayed root
+ */
+ public TreeMapNode getDisplayedRoot() {
+ return this.displayedRoot;
+ }
+
+ /**
+ * get the root.
+ *
+ * @return the root
+ */
+ public TreeMapNode getRoot() {
+ return this.root;
+ }
+
+ /**
+ * get the SplitStrategy.
+ *
+ * @return the SplitStrategy
+ */
+ public SplitStrategy getStrategy() {
+ return this.strategy;
+ }
+
+ @Override
+ public Point getToolTipLocation(MouseEvent event) {
+ int posX;
+ int posY;
+ JToolTip toolTip = this.createToolTip();
+ int XMax = this.displayedRoot.getX() + this.displayedRoot.getWidth();
+ int YMin = this.displayedRoot.getY();
+ if (this.activeLeaf != null) {
+ if (this.activeLeaf.getWidth() >= toolTip.getWidth() + 8
+ && this.activeLeaf.getHeight() >= toolTip.getHeight() + 8) {
+ posX = this.activeLeaf.getX() + 4;
+ posY = this.activeLeaf.getY() + 4;
+ } else {
+ posX = this.activeLeaf.getX() + this.activeLeaf.getWidth() + 4;
+ posY = this.activeLeaf.getY() - toolTip.getHeight() - 4;
+ }
+
+ if (posY < YMin + 4) {
+ posY = YMin + 4;
+ }
+ if ((posX + toolTip.getWidth() > XMax - 4)
+ && (this.activeLeaf.getX() >= toolTip.getWidth() + 4)) {
+ posX = this.activeLeaf.getX() - 4 - toolTip.getWidth();
+ }
+
+ return new Point(posX, posY);
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
+ */
+ @Override
+ protected void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ int width = getSize().width;
+ int height = getSize().height;
+ Insets insets = getInsets();
+
+ int border = TreeMapNode.getBorder();
+ this.root.setDimension(this.root.getX(), this.root.getY(), width - border
+ - insets.left - insets.right, height - border - insets.top
+ - insets.bottom);
+
+ if (!this.root.equals( this.displayedRoot )) {
+ this.displayedRoot.setDimension(this.displayedRoot.getX(), this.displayedRoot.getY(), width - border
+ - insets.left - insets.right, height - border - insets.top
+ - insets.bottom);
+ }
+
+ this.calculatePositions();
+
+ if (this.displayedRoot.children().hasMoreElements()) {
+ // the background
+ g.setColor(this.getBackground());
+ g.fillRect(this.displayedRoot.getX(), this.displayedRoot.getY(),
+ this.displayedRoot.getWidth() + border, this.displayedRoot
+ .getHeight()
+ + border);
+ // the JTreeMapExample
+ draw(g, this.displayedRoot);
+ // reveal the active leaf
+ if (this.activeLeaf != null) {
+ reveal(g, this.activeLeaf);
+ }
+ // the labels
+ drawLabels(g, this.displayedRoot);
+ }
+
+ }
+
+ /**
+ * reveal the item.
+ *
+ * @param g Graphics where you have to draw
+ * @param item TreeMapNode to reveal
+ */
+ protected void reveal(Graphics g, TreeMapNode item) {
+ if (item.isLeaf()) {
+ g.setColor(transparencyColor);
+ g.fillRect(item.getX(), item.getY(), item.getWidth(), item.getHeight());
+ }
+ }
+
+ /**
+ * set the active leaf.
+ *
+ * @param newActiveLeaf the new active leaf
+ */
+ public void setActiveLeaf(TreeMapNode newActiveLeaf) {
+ if (newActiveLeaf == null || newActiveLeaf.isLeaf()) {
+ this.activeLeaf = newActiveLeaf;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.swing.JComponent#setBorder(javax.swing.border.Border)
+ */
+ @Override
+ public void setBorder(Border border) {
+ // Substract the previous border insets
+ Insets insets = getInsets();
+ this.displayedRoot.setDimension(this.displayedRoot.getX() - insets.left,
+ this.displayedRoot.getY() - insets.top, this.displayedRoot.getWidth()
+ + insets.left + insets.right, this.displayedRoot.getHeight()
+ + insets.top + insets.bottom);
+
+ super.setBorder(border);
+
+ // Add the new border insets
+ insets = getInsets();
+ this.displayedRoot.setDimension(this.displayedRoot.getX() + insets.left,
+ this.displayedRoot.getY() + insets.top, this.displayedRoot.getWidth()
+ - insets.left - insets.right, this.displayedRoot.getHeight()
+ - insets.top - insets.bottom);
+ }
+
+ /**
+ * set the ColorProvider.
+ *
+ * @param newColorProvider the new ColorPorvider
+ */
+ public void setColorProvider(ColorProvider newColorProvider) {
+ this.colorProvider = newColorProvider;
+ }
+
+ /**
+ * set the displayed root.
+ * <p>
+ * This may be not the root of the jTreeMap. After a zoom, the displayed root
+ * can be the root of an under-tree.
+ * </p>
+ *
+ * @param newDisplayedRoot new DiplayedRoot
+ */
+ public void setDisplayedRoot(TreeMapNode newDisplayedRoot) {
+ this.displayedRoot = newDisplayedRoot;
+ }
+
+ /**
+ * set the new root.
+ *
+ * @param newRoot the new root to set
+ */
+ public void setRoot(TreeMapNode newRoot) {
+ this.root = newRoot;
+ Insets insets = getInsets();
+ this.root.setX(insets.left);
+ this.root.setY(insets.top);
+ this.setDisplayedRoot(this.root);
+
+ }
+
+ /**
+ * set the new strategy.
+ *
+ * @param newStrat the new strategy to set
+ */
+ public void setStrategy(SplitStrategy newStrat) {
+ this.strategy = newStrat;
+ }
+
+ /**
+ * Set the builder of the toolTip.<BR>
+ *
+ * @param toolTipBuilder The toolTipBuilder to set.
+ */
+ public void setToolTipBuilder(IToolTipBuilder toolTipBuilder) {
+ this.toolTipBuilder = toolTipBuilder;
+ }
+
+ /**
+ * When you zoom the jTreeMap, you have the choice to keep proportions or not.
+ *
+ * @param keepProportion true if you want to keep proportions, else false
+ */
+ public void setZoomKeepProportion(boolean keepProportion) {
+ this.zoom.setKeepProportion(keepProportion);
+ }
+
+ /**
+ * Undo the zoom to display the root.
+ */
+ public void unzoom() {
+ this.zoom.undo();
+ }
+
+ /**
+ * Zoom the JTreeMap to the dest node.
+ *
+ * @param dest node we want to zoom
+ */
+ public void zoom(TreeMapNode dest) {
+ // undo the last zoom
+ unzoom();
+
+ this.zoom.execute(dest);
+ }
+
+ /**
+ * Listener who define the active leaf and set the tooltip text.
+ *
+ * @author Laurent Dutheil
+ */
+ protected class HandleMouseMotion extends MouseMotionAdapter {
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ if (getDisplayedRoot().children().hasMoreElements()) {
+ TreeMapNode t = getDisplayedRoot().getActiveLeaf(e.getX(), e.getY());
+ if (t != null && !t.equals(getActiveLeaf())) {
+ setActiveLeaf(t);
+ repaint();
+ }
+ if (t != null) {
+ setToolTipText(t.getLabel() + " " + t.getValue().getValue());
+ } else {
+ setToolTipText(null);
+ }
+ }
+ }
+ }
+
+ /**
+ * Class who zoom and unzoom the JTreeMap.
+ *
+ * @author Laurent Dutheil
+ */
+ private class Zoom {
+ private boolean enable;
+ private boolean keepProportion = false;
+
+ /**
+ * Constructor
+ */
+ public Zoom() {
+ this.enable = true;
+ }
+
+ /**
+ * Execute the zoom.
+ * @param dest TreeMapNode where you want to zoom
+ */
+ public void execute(TreeMapNode dest) {
+ if (this.enable) {
+ JTreeMap.this.setActiveLeaf(null);
+
+ setNewDimension(dest);
+
+ JTreeMap.this.setDisplayedRoot(dest);
+
+ this.enable = false;
+ }
+ }
+
+ /**
+ * @return Returns the keepProportion.
+ */
+ public boolean isKeepProportion() {
+ return this.keepProportion;
+ }
+
+ /**
+ * @param keepProportion The keepProportion to set.
+ */
+ public void setKeepProportion(boolean keepProportion) {
+ this.keepProportion = keepProportion;
+ }
+
+ /**
+ * set the new dimensions of the dest root
+ * @param dest the root to dimension
+ */
+ protected void setNewDimension(TreeMapNode dest) {
+ dest.setX(JTreeMap.this.getRoot().getX());
+ dest.setY(JTreeMap.this.getRoot().getY());
+
+ int rootWidth = JTreeMap.this.getRoot().getWidth();
+ int rootHeight = JTreeMap.this.getRoot().getHeight();
+
+ if (isKeepProportion()) {
+ int destHeight = dest.getHeight();
+ int destWidth = dest.getWidth();
+ float divWidth = (float) destWidth / (float) rootWidth;
+ float divHeight = (float) destHeight / (float) rootHeight;
+
+ if (divWidth >= divHeight) {
+ dest.setHeight(Math.round(destHeight / divWidth));
+ dest.setWidth(rootWidth);
+ } else {
+ dest.setHeight(rootHeight);
+ dest.setWidth(Math.round(destWidth / divHeight));
+ }
+
+ } else {
+ dest.setHeight(rootHeight);
+ dest.setWidth(rootWidth);
+ }
+ }
+
+ /**
+ * undo the zoom.
+ */
+ public void undo() {
+ if (!this.enable) {
+ JTreeMap.this.setDisplayedRoot(JTreeMap.this.getRoot());
+ this.enable = true;
+ }
+ }
+
+ }
+
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/JTreeMap.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/JTreeMap.java 2006-10-23 20:58:29 UTC (rev 45)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/JTreeMap.java 2006-10-23 20:59:22 UTC (rev 46)
@@ -1,581 +0,0 @@
-package org.jense.swing.jtreemap;
-
-import java.util.Enumeration;
-import java.awt.Color;
-import java.awt.FontMetrics;
-import java.awt.Graphics;
-import java.awt.Insets;
-import java.awt.Point;
-import java.awt.event.MouseMotionAdapter;
-import java.awt.event.MouseEvent;
-
-import javax.swing.JComponent;
-import javax.swing.JToolTip;
-import javax.swing.ToolTipManager;
-import javax.swing.border.Border;
-
-/**
- * JComponent who represents each element of a tree in a rectangle of more or
- * less big size according to its importance in the tree.
- * <p>
- * A tree structure may includes more or less important elements. For example,
- * in a tree structure of files, there can be files of big size. Then it can be
- * interesting to know which repertory is the most important on a hard disk.
- * <p>
- * Moreover, we can add a code color which makes it possible to introduce new
- * information into the representation of the tree structure.
- * <p>
- * So, in a JTreeMap, you can see the size and the value of an element in a
- * tree.
- *
- * @see org.jense.swing.jtreemap.TreeMapNode
- * @author Laurent Dutheil
- */
-public class JTreeMap extends JComponent {
- private static final long serialVersionUID = 7255952672238300249L;
- private static final Color transparencyColor = new Color(204, 204, 204, 128);
- // active leaf
- private TreeMapNode activeLeaf = null;
- // color provider
- private ColorProvider colorProvider = null;
- // displayed root
- private TreeMapNode displayedRoot = null;
- // root of the tree
- private TreeMapNode root = null;
- // divide strategy
- private SplitStrategy strategy = null;
- // tooltip builder
- private IToolTipBuilder toolTipBuilder;
- // zoom
- private Zoom zoom;
-
- /**
- * Constructor of JTreeMap. <BR>
- * The chosen strategy is SplitSquarified. <BR>
- * The chosen color provider is UniqueColorProvider.
- *
- * @see SplitSquarified
- * @see UniqueColorProvider
- * @param root the root of the tree to display
- */
- public JTreeMap(TreeMapNode root) {
- this(root, new SplitSquarified());
- }
-
- /**
- * Constructor of JTreeMap. <BR>
- * The chosen color provider is UniqueColorProvider.
- *
- * @see UniqueColorProvider
- * @param root the root of the tree to display
- * @param strategy the split strategy
- */
- public JTreeMap(TreeMapNode root, SplitStrategy strategy) {
- // ToolTips appears without delay and stay as long as possible
- ToolTipManager ttm = ToolTipManager.sharedInstance();
- ttm.setInitialDelay(0);
- ttm.setReshowDelay(0);
- ttm.setDismissDelay(100000);
- ttm.setEnabled(true);
- ttm.setLightWeightPopupEnabled(true);
- this.setToolTipText("");
-
- // the default DefaultToolTipBuilder
- this.toolTipBuilder = new DefaultToolTipBuilder(this);
-
- this.zoom = new Zoom();
-
- this.setRoot(root);
- this.setStrategy(strategy);
- this.setColorProvider(new UniqueColorProvider());
-
- this.addMouseMotionListener(new HandleMouseMotion());
- }
-
- /**
- * calculate the postitions for the displayed root. <BR>
- * The positions of the root must be calculated first.
- */
- public void calculatePositions() {
- if (this.getStrategy() != null && this.displayedRoot != null) {
- this.getStrategy().calculatePositions(this.displayedRoot);
- }
- }
-
- @Override
- public JToolTip createToolTip() {
- return this.toolTipBuilder.getToolTip();
- }
-
- /**
- * draw the item.
- *
- * @param g Graphics where you have to draw
- * @param item item to draw
- */
- protected void draw(Graphics g, TreeMapNode item) {
- if (item.isLeaf()) {
- g.setColor(this.colorProvider.getColor(item.getValue()));
- g.fillRect(item.getX(), item.getY(), item.getWidth(), item.getHeight());
- } else {
- for (Enumeration e = item.children(); e.hasMoreElements();) {
- draw(g, (TreeMapNode) (e.nextElement()));
- }
- }
- }
-
- /**
- * write the label in the middle of the item. <BR>
- * You have first to define the font of the Graphics. <BR>
- * You may override this method to change the position or the color of the
- * label.
- *
- * @param g Graphics where you have to draw
- * @param item TreeMapNode to draw
- */
- protected void drawLabel(Graphics g, TreeMapNode item) {
- FontMetrics fm = g.getFontMetrics(g.getFont());
- // if the height of the item is high enough
- if (fm.getHeight() < item.getHeight() - 2) {
- String label = item.getLabel();
-
- int y = (item.getHeight() + fm.getAscent() - fm.getDescent()) / 2;
- int stringWidth = fm.stringWidth(label);
- // the width of the label depends on the font :
- // if the width of the label is larger than the item
- if (item.getWidth() - 5 <= stringWidth) {
- // We have to truncate the label
- // number of chars who can be writen in the item
- int nbChar = (label.length() * item.getWidth()) / stringWidth;
- if (nbChar > 3) {
- // and add "..." at the end
- label = label.substring(0, nbChar - 3) + "...";
- } else {
- // if it is not enough large, we display nothing
- label = "";
- }
- }
- int x = (item.getWidth() - fm.stringWidth(label)) / 2;
-
- // background in black
- g.setColor(Color.black);
- g.drawString(label, item.getX() + x + 1, item.getY() + y + 1);
- g.drawString(label, item.getX() + x - 1, item.getY() + y + 1);
- g.drawString(label, item.getX() + x + 1, item.getY() + y - 1);
- g.drawString(label, item.getX() + x - 1, item.getY() + y - 1);
- g.drawString(label, item.getX() + x + 1, item.getY() + y);
- g.drawString(label, item.getX() + x - 1, item.getY() + y);
- g.drawString(label, item.getX() + x, item.getY() + y + 1);
- g.drawString(label, item.getX() + x, item.getY() + y - 1);
- // label in white
- g.setColor(Color.white);
- g.drawString(label, item.getX() + x, item.getY() + y);
- }
- }
-
- /**
- * Draw all the labels to draw. <BR>
- * You may override this method to draw the labels you want. <BR>
- * For exemples, all the leaves, or all the first level children, or all of
- * them...
- *
- * @param g Graphics where you have to draw
- * @param item TreeMapNode to draw
- */
- protected void drawLabels(Graphics g, TreeMapNode item) {
- // add the labels (level -1)
- g.setFont(this.getFont());
- if (this.displayedRoot.isLeaf()) {
- drawLabel(g, this.displayedRoot);
- } else {
- for (Enumeration e = this.displayedRoot.children(); e.hasMoreElements();) {
- drawLabel(g, (TreeMapNode) (e.nextElement()));
- }
- }
-
- /* uncomment to add the labels of the lowered levels (up to depth > 2) */
- // int depth = item.getLevel() - this.displayedRoot.getLevel();
- // float newSize = Math.max(20, this.getFont().getSize2D());
- // java.awt.Font labelFont = this.getFont().deriveFont(java.awt.Font.BOLD,
- // newSize - 3 * depth);
- // g.setFont(labelFont);
- // if (depth > 2) {
- // drawLabel(g, item);
- // return;
- // }
- // if (item.isLeaf()) {
- // drawLabel(g, item);
- // } else {
- // for (Enumeration e = item.children(); e.hasMoreElements();) {
- // drawLabels(g, (TreeMapNode) (e.nextElement()));
- // }
- // }
- }
-
- /**
- * get the active leaf (the one under the mouse).
- *
- * @return Returns the activeLeaf.
- */
- public TreeMapNode getActiveLeaf() {
- return this.activeLeaf;
- }
-
- /**
- * get the ColorProvider.
- *
- * @return the ColorProvider
- */
- public ColorProvider getColorProvider() {
- return this.colorProvider;
- }
-
- /**
- * get the displayed root.
- * <p>
- * This may be not the root of the jTreeMap. After a zoom, the displayed root
- * can be the root of an under-tree.
- * </p>
- *
- * @return the displayed root
- */
- public TreeMapNode getDisplayedRoot() {
- return this.displayedRoot;
- }
-
- /**
- * get the root.
- *
- * @return the root
- */
- public TreeMapNode getRoot() {
- return this.root;
- }
-
- /**
- * get the SplitStrategy.
- *
- * @return the SplitStrategy
- */
- public SplitStrategy getStrategy() {
- return this.strategy;
- }
-
- @Override
- public Point getToolTipLocation(MouseEvent event) {
- int posX;
- int posY;
- JToolTip toolTip = this.createToolTip();
- int XMax = this.displayedRoot.getX() + this.displayedRoot.getWidth();
- int YMin = this.displayedRoot.getY();
- if (this.activeLeaf != null) {
- if (this.activeLeaf.getWidth() >= toolTip.getWidth() + 8
- && this.activeLeaf.getHeight() >= toolTip.getHeight() + 8) {
- posX = this.activeLeaf.getX() + 4;
- posY = this.activeLeaf.getY() + 4;
- } else {
- posX = this.activeLeaf.getX() + this.activeLeaf.getWidth() + 4;
- posY = this.activeLeaf.getY() - toolTip.getHeight() - 4;
- }
-
- if (posY < YMin + 4) {
- posY = YMin + 4;
- }
- if ((posX + toolTip.getWidth() > XMax - 4)
- && (this.activeLeaf.getX() >= toolTip.getWidth() + 4)) {
- posX = this.activeLeaf.getX() - 4 - toolTip.getWidth();
- }
-
- return new Point(posX, posY);
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
- */
- @Override
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
- int width = getSize().width;
- int height = getSize().height;
- Insets insets = getInsets();
-
- int border = TreeMapNode.getBorder();
- this.root.setDimension(this.root.getX(), this.root.getY(), width - border
- - insets.left - insets.right, height - border - insets.top
- - insets.bottom);
-
- if (!this.root.equals( this.displayedRoot )) {
- this.displayedRoot.setDimension(this.displayedRoot.getX(), this.displayedRoot.getY(), width - border
- - insets.left - insets.right, height - border - insets.top
- - insets.bottom);
- }
-
- this.calculatePositions();
-
- if (this.displayedRoot.children().hasMoreElements()) {
- // the background
- g.setColor(this.getBackground());
- g.fillRect(this.displayedRoot.getX(), this.displayedRoot.getY(),
- this.displayedRoot.getWidth() + border, this.displayedRoot
- .getHeight()
- + border);
- // the JTreeMapExample
- draw(g, this.displayedRoot);
- // reveal the active leaf
- if (this.activeLeaf != null) {
- reveal(g, this.activeLeaf);
- }
- // the labels
- drawLabels(g, this.displayedRoot);
- }
-
- }
-
- /**
- * reveal the item.
- *
- * @param g Graphics where you have to draw
- * @param item TreeMapNode to reveal
- */
- protected void reveal(Graphics g, TreeMapNode item) {
- if (item.isLeaf()) {
- g.setColor(transparencyColor);
- g.fillRect(item.getX(), item.getY(), item.getWidth(), item.getHeight());
- }
- }
-
- /**
- * set the active leaf.
- *
- * @param newActiveLeaf the new active leaf
- */
- public void setActiveLeaf(TreeMapNode newActiveLeaf) {
- if (newActiveLeaf == null || newActiveLeaf.isLeaf()) {
- this.activeLeaf = newActiveLeaf;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.swing.JComponent#setBorder(javax.swing.border.Border)
- */
- @Override
- public void setBorder(Border border) {
- // Substract the previous border insets
- Insets insets = getInsets();
- this.displayedRoot.setDimension(this.displayedRoot.getX() - insets.left,
- this.displayedRoot.getY() - insets.top, this.displayedRoot.getWidth()
- + insets.left + insets.right, this.displayedRoot.getHeight()
- + insets.top + insets.bottom);
-
- super.setBorder(border);
-
- // Add the new border insets
- insets = getInsets();
- this.displayedRoot.setDimension(this.displayedRoot.getX() + in...
[truncated message content] |
|
From: <be...@us...> - 2006-10-23 21:02:58
|
Revision: 47
http://svn.sourceforge.net/jtreemap/?rev=47&view=rev
Author: benoitx
Date: 2006-10-23 14:02:36 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByNumber.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByNumber.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByNumber.java (from rev 46, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByNumber.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByNumber.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByNumber.java 2006-10-23 21:02:36 UTC (rev 47)
@@ -0,0 +1,41 @@
+package org.jense.swing.jtreemap;
+
+import java.util.Vector;
+
+/**
+ * Strategy who split the elements in 2 groups of same cardinal.
+ *
+ * @author Laurent DUTHEIL
+ */
+public class SplitByNumber extends SplitStrategy {
+
+ @Override
+ public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1, Vector<TreeMapNode> v2) {
+ int size = v.size();
+ int middle = size / 2;
+ int index = 0;
+ //we add first elements to v1
+ for (; index < middle; index++) {
+ v1.addElement(v.elementAt(index));
+ }
+ //we add last elements to v2
+ for (; index < size; index++) {
+ v2.addElement(v.elementAt(index));
+ }
+ }
+
+ @Override
+ public double sumWeight(Vector<TreeMapNode> v) {
+ //all the elements must have the same weight
+ double weight = 0.0;
+ for (TreeMapNode node : v) {
+ if (node.isLeaf()) {
+ weight += 1;
+ } else {
+ weight += this.sumWeight(node.getChildren());
+ }
+ }
+ return weight;
+ }
+
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByNumber.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByNumber.java 2006-10-23 20:59:22 UTC (rev 46)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByNumber.java 2006-10-23 21:02:36 UTC (rev 47)
@@ -1,41 +0,0 @@
-package org.jense.swing.jtreemap;
-
-import java.util.Vector;
-
-/**
- * Strategy who split the elements in 2 groups of same cardinal.
- *
- * @author Laurent DUTHEIL
- */
-public class SplitByNumber extends SplitStrategy {
-
- @Override
- public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1, Vector<TreeMapNode> v2) {
- int size = v.size();
- int middle = size / 2;
- int index = 0;
- //we add first elements to v1
- for (; index < middle; index++) {
- v1.addElement(v.elementAt(index));
- }
- //we add last elements to v2
- for (; index < size; index++) {
- v2.addElement(v.elementAt(index));
- }
- }
-
- @Override
- public double sumWeight(Vector<TreeMapNode> v) {
- //all the elements must have the same weight
- double weight = 0.0;
- for (TreeMapNode node : v) {
- if (node.isLeaf()) {
- weight += 1;
- } else {
- weight += this.sumWeight(node.getChildren());
- }
- }
- return weight;
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 21:05:58
|
Revision: 48
http://svn.sourceforge.net/jtreemap/?rev=48&view=rev
Author: benoitx
Date: 2006-10-23 14:05:30 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitBySlice.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitBySlice.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitBySlice.java (from rev 47, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitBySlice.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitBySlice.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitBySlice.java 2006-10-23 21:05:30 UTC (rev 48)
@@ -0,0 +1,111 @@
+/*
+ * Created on 3 nov. 2005
+ */
+package org.jense.swing.jtreemap;
+
+import java.util.Vector;
+
+/**
+ * Split the treemap by slice
+ *
+ * @author Laurent DUTHEIL
+ */
+public class SplitBySlice extends SplitStrategy {
+
+ /**
+ * Calculate the dimension of the elements of the Vector.
+ *
+ * @param x0 x-coordinate
+ * @param y0 y-coordinate
+ * @param w0 width
+ * @param h0 height
+ * @param v elements to split in the dimensions before
+ * @param sumWeight sum of the weights
+ */
+ public static void splitInSlice(int x0, int y0, int w0, int h0,
+ Vector<TreeMapNode> v, double sumWeight) {
+ int offset = 0;
+ boolean vertical = h0 > w0;
+
+ for (TreeMapNode node : v) {
+ if (vertical) {
+ node.setX(x0);
+ node.setWidth(w0);
+ node.setY(y0 + offset);
+ node.setHeight((int) Math.round(h0 * node.getWeight() / sumWeight));
+ offset = offset + node.getHeight();
+ } else {
+ node.setX(x0 + offset);
+ node.setWidth((int) Math.round(w0 * node.getWeight() / sumWeight));
+ node.setY(y0);
+ node.setHeight(h0);
+ offset = offset + node.getWidth();
+ }
+ }
+
+ // Because of the Math.round(), we adjust the last element to fit the
+ // correctly the JTreeMap
+ if (!v.isEmpty()) {
+ TreeMapNode node = v.lastElement();
+ if (vertical && h0 != offset) {
+ node.setHeight(node.getHeight() - offset + h0);
+ } else if (!vertical && w0 != offset) {
+ node.setWidth(node.getWidth() - offset + w0);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jense.swing.jtreemap.SplitStrategy#splitElements(java.util.Vector,
+ * java.util.Vector, java.util.Vector)
+ */
+ @Override
+ public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1,
+ Vector<TreeMapNode> v2) {
+ // ignore
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jense.swing.jtreemap.SplitStrategy#calculatePositionsRec(int, int,
+ * int, int, double, java.util.Vector)
+ */
+ @Override
+ protected void calculatePositionsRec(int x0, int y0, int w0, int h0,
+ double weight0, Vector<TreeMapNode> v) {
+
+ SplitBySlice.splitInSlice(x0, y0, w0, h0, v, weight0);
+
+ for (TreeMapNode node : v) {
+ if (node.isLeaf()) {
+ node.setX(node.getX() + TreeMapNode.getBorder());
+ node.setY(node.getY() + TreeMapNode.getBorder());
+ node.setHeight(node.getHeight() - TreeMapNode.getBorder());
+ node.setWidth(node.getWidth() - TreeMapNode.getBorder());
+ } else {
+ // if this is not a leaf, calculation for the children
+ if (TreeMapNode.getBorder() > 1) {
+ TreeMapNode.setBorder(TreeMapNode.getBorder() - 2);
+ calculatePositionsRec(node.getX() + 2, node.getY() + 2, node
+ .getWidth() - 2, node.getHeight() - 2, node.getWeight(), node
+ .getChildren());
+ TreeMapNode.setBorder(TreeMapNode.getBorder() + 2);
+ } else if (TreeMapNode.getBorder() == 1) {
+ TreeMapNode.setBorder(0);
+ calculatePositionsRec(node.getX() + 1, node.getY() + 1, node
+ .getWidth() - 1, node.getHeight() - 1, node.getWeight(), node
+ .getChildren());
+ TreeMapNode.setBorder(1);
+ } else {
+ calculatePositionsRec(node.getX(), node.getY(), node.getWidth(), node
+ .getHeight(), node.getWeight(), node.getChildren());
+ }
+ }
+ }
+
+ }
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitBySlice.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitBySlice.java 2006-10-23 21:02:36 UTC (rev 47)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitBySlice.java 2006-10-23 21:05:30 UTC (rev 48)
@@ -1,111 +0,0 @@
-/*
- * Created on 3 nov. 2005
- */
-package org.jense.swing.jtreemap;
-
-import java.util.Vector;
-
-/**
- * Split the treemap by slice
- *
- * @author Laurent DUTHEIL
- */
-public class SplitBySlice extends SplitStrategy {
-
- /**
- * Calculate the dimension of the elements of the Vector.
- *
- * @param x0 x-coordinate
- * @param y0 y-coordinate
- * @param w0 width
- * @param h0 height
- * @param v elements to split in the dimensions before
- * @param sumWeight sum of the weights
- */
- public static void splitInSlice(int x0, int y0, int w0, int h0,
- Vector<TreeMapNode> v, double sumWeight) {
- int offset = 0;
- boolean vertical = h0 > w0;
-
- for (TreeMapNode node : v) {
- if (vertical) {
- node.setX(x0);
- node.setWidth(w0);
- node.setY(y0 + offset);
- node.setHeight((int) Math.round(h0 * node.getWeight() / sumWeight));
- offset = offset + node.getHeight();
- } else {
- node.setX(x0 + offset);
- node.setWidth((int) Math.round(w0 * node.getWeight() / sumWeight));
- node.setY(y0);
- node.setHeight(h0);
- offset = offset + node.getWidth();
- }
- }
-
- // Because of the Math.round(), we adjust the last element to fit the
- // correctly the JTreeMap
- if (!v.isEmpty()) {
- TreeMapNode node = v.lastElement();
- if (vertical && h0 != offset) {
- node.setHeight(node.getHeight() - offset + h0);
- } else if (!vertical && w0 != offset) {
- node.setWidth(node.getWidth() - offset + w0);
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.jense.swing.jtreemap.SplitStrategy#splitElements(java.util.Vector,
- * java.util.Vector, java.util.Vector)
- */
- @Override
- public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1,
- Vector<TreeMapNode> v2) {
- // ignore
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.jense.swing.jtreemap.SplitStrategy#calculatePositionsRec(int, int,
- * int, int, double, java.util.Vector)
- */
- @Override
- protected void calculatePositionsRec(int x0, int y0, int w0, int h0,
- double weight0, Vector<TreeMapNode> v) {
-
- SplitBySlice.splitInSlice(x0, y0, w0, h0, v, weight0);
-
- for (TreeMapNode node : v) {
- if (node.isLeaf()) {
- node.setX(node.getX() + TreeMapNode.getBorder());
- node.setY(node.getY() + TreeMapNode.getBorder());
- node.setHeight(node.getHeight() - TreeMapNode.getBorder());
- node.setWidth(node.getWidth() - TreeMapNode.getBorder());
- } else {
- // if this is not a leaf, calculation for the children
- if (TreeMapNode.getBorder() > 1) {
- TreeMapNode.setBorder(TreeMapNode.getBorder() - 2);
- calculatePositionsRec(node.getX() + 2, node.getY() + 2, node
- .getWidth() - 2, node.getHeight() - 2, node.getWeight(), node
- .getChildren());
- TreeMapNode.setBorder(TreeMapNode.getBorder() + 2);
- } else if (TreeMapNode.getBorder() == 1) {
- TreeMapNode.setBorder(0);
- calculatePositionsRec(node.getX() + 1, node.getY() + 1, node
- .getWidth() - 1, node.getHeight() - 1, node.getWeight(), node
- .getChildren());
- TreeMapNode.setBorder(1);
- } else {
- calculatePositionsRec(node.getX(), node.getY(), node.getWidth(), node
- .getHeight(), node.getWeight(), node.getChildren());
- }
- }
- }
-
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 21:09:39
|
Revision: 49
http://svn.sourceforge.net/jtreemap/?rev=49&view=rev
Author: benoitx
Date: 2006-10-23 14:09:11 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitBySortedWeight.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitBySortedWeight.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitBySortedWeight.java (from rev 48, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitBySortedWeight.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitBySortedWeight.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitBySortedWeight.java 2006-10-23 21:09:11 UTC (rev 49)
@@ -0,0 +1,61 @@
+package org.jense.swing.jtreemap;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+/**
+ * Strategy who split the elements in 2 groups of equivalent weight.
+ * <p>
+ * The elements are first sorted by descending weight. Then they are splitted in
+ * 2 groups of equivalent weight.
+ * <p>
+ * The heaviest elements are on the top left of the JTreeMap. The lightest
+ * elements are on the bottom right of the JTreeMap
+ *
+ * @author Laurent Dutheil
+ */
+
+public class SplitBySortedWeight extends SplitStrategy {
+
+ @Override
+ public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1, Vector<TreeMapNode> v2) {
+ Vector<TreeMapNode> vClone = new Vector<TreeMapNode>(v);
+ double memWeight = 0.0;
+ double sumWeight = sumWeight(v);
+ double elemWeight = 0.0;
+
+ sortVector(vClone);
+
+ for (Iterator<TreeMapNode> i = vClone.iterator(); i.hasNext();) {
+ TreeMapNode tmn = i.next();
+ elemWeight = tmn.getWeight();
+ // if adding the current element pass the middle of total weight
+ if (memWeight + elemWeight >= sumWeight / 2) {
+ // we look at the finest split (the nearest of the middle of weight)
+ if (((sumWeight / 2) - memWeight) > ((memWeight + elemWeight) - (sumWeight / 2))) {
+ // if it is after the add, we add the element to the first Vector
+ memWeight += elemWeight;
+ v1.addElement(tmn);
+ } else {
+ // we must have at least 1 element in the first vector
+ if (v1.isEmpty()) {
+ v1.addElement(tmn);
+ } else {
+ // if it is before the add, we add the element to the second Vector
+ v2.addElement(tmn);
+ }
+ }
+ // then we fill the second Vector qith the rest of elements
+ while (i.hasNext()) {
+ tmn = i.next();
+ v2.addElement(tmn);
+ }
+ } else {
+ // we add in the first vector while we don't reach the middle of weight
+ memWeight += elemWeight;
+ v1.addElement(tmn);
+ }
+ }
+ }
+
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitBySortedWeight.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitBySortedWeight.java 2006-10-23 21:05:30 UTC (rev 48)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitBySortedWeight.java 2006-10-23 21:09:11 UTC (rev 49)
@@ -1,61 +0,0 @@
-package org.jense.swing.jtreemap;
-
-import java.util.Iterator;
-import java.util.Vector;
-
-/**
- * Strategy who split the elements in 2 groups of equivalent weight.
- * <p>
- * The elements are first sorted by descending weight. Then they are splitted in
- * 2 groups of equivalent weight.
- * <p>
- * The heaviest elements are on the top left of the JTreeMap. The lightest
- * elements are on the bottom right of the JTreeMap
- *
- * @author Laurent Dutheil
- */
-
-public class SplitBySortedWeight extends SplitStrategy {
-
- @Override
- public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1, Vector<TreeMapNode> v2) {
- Vector<TreeMapNode> vClone = new Vector<TreeMapNode>(v);
- double memWeight = 0.0;
- double sumWeight = sumWeight(v);
- double elemWeight = 0.0;
-
- sortVector(vClone);
-
- for (Iterator<TreeMapNode> i = vClone.iterator(); i.hasNext();) {
- TreeMapNode tmn = i.next();
- elemWeight = tmn.getWeight();
- // if adding the current element pass the middle of total weight
- if (memWeight + elemWeight >= sumWeight / 2) {
- // we look at the finest split (the nearest of the middle of weight)
- if (((sumWeight / 2) - memWeight) > ((memWeight + elemWeight) - (sumWeight / 2))) {
- // if it is after the add, we add the element to the first Vector
- memWeight += elemWeight;
- v1.addElement(tmn);
- } else {
- // we must have at least 1 element in the first vector
- if (v1.isEmpty()) {
- v1.addElement(tmn);
- } else {
- // if it is before the add, we add the element to the second Vector
- v2.addElement(tmn);
- }
- }
- // then we fill the second Vector qith the rest of elements
- while (i.hasNext()) {
- tmn = i.next();
- v2.addElement(tmn);
- }
- } else {
- // we add in the first vector while we don't reach the middle of weight
- memWeight += elemWeight;
- v1.addElement(tmn);
- }
- }
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 21:13:31
|
Revision: 50
http://svn.sourceforge.net/jtreemap/?rev=50&view=rev
Author: benoitx
Date: 2006-10-23 14:13:05 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByWeight.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByWeight.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByWeight.java (from rev 49, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByWeight.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByWeight.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitByWeight.java 2006-10-23 21:13:05 UTC (rev 50)
@@ -0,0 +1,53 @@
+package org.jense.swing.jtreemap;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+/**
+ * Strategy who split the elements in 2 groups of equivalent weight.
+ *
+ * @author Laurent Dutheil
+ */
+
+public class SplitByWeight extends SplitStrategy {
+
+ @Override
+ public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1,
+ Vector<TreeMapNode> v2) {
+ double memWeight = 0.0;
+ double sumWeight = sumWeight(v);
+ double elemWeight = 0.0;
+
+ for (Iterator<TreeMapNode> i = v.iterator(); i.hasNext();) {
+ TreeMapNode tmn = i.next();
+ elemWeight = tmn.getWeight();
+ // if adding the current element pass the middle of total weight
+ if (memWeight + elemWeight >= sumWeight / 2) {
+ // we look at the finest split (the nearest of the middle of weight)
+ if (((sumWeight / 2) - memWeight) > ((memWeight + elemWeight) - (sumWeight / 2))) {
+ // if it is after the add, we add the element to the first Vector
+ memWeight += elemWeight;
+ v1.addElement(tmn);
+ } else {
+ // we must have at least 1 element in the first vector
+ if (v1.isEmpty()) {
+ v1.addElement(tmn);
+ } else {
+ // if it is before the add, we add the element to the second Vector
+ v2.addElement(tmn);
+ }
+ }
+ // then we fill the second Vector qith the rest of elements
+ while (i.hasNext()) {
+ tmn = i.next();
+ v2.addElement(tmn);
+ }
+ } else {
+ // we add in the first vector while we don't reach the middle of weight
+ memWeight += elemWeight;
+ v1.addElement(tmn);
+ }
+ }
+ }
+
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByWeight.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByWeight.java 2006-10-23 21:09:11 UTC (rev 49)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitByWeight.java 2006-10-23 21:13:05 UTC (rev 50)
@@ -1,53 +0,0 @@
-package org.jense.swing.jtreemap;
-
-import java.util.Iterator;
-import java.util.Vector;
-
-/**
- * Strategy who split the elements in 2 groups of equivalent weight.
- *
- * @author Laurent Dutheil
- */
-
-public class SplitByWeight extends SplitStrategy {
-
- @Override
- public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1,
- Vector<TreeMapNode> v2) {
- double memWeight = 0.0;
- double sumWeight = sumWeight(v);
- double elemWeight = 0.0;
-
- for (Iterator<TreeMapNode> i = v.iterator(); i.hasNext();) {
- TreeMapNode tmn = i.next();
- elemWeight = tmn.getWeight();
- // if adding the current element pass the middle of total weight
- if (memWeight + elemWeight >= sumWeight / 2) {
- // we look at the finest split (the nearest of the middle of weight)
- if (((sumWeight / 2) - memWeight) > ((memWeight + elemWeight) - (sumWeight / 2))) {
- // if it is after the add, we add the element to the first Vector
- memWeight += elemWeight;
- v1.addElement(tmn);
- } else {
- // we must have at least 1 element in the first vector
- if (v1.isEmpty()) {
- v1.addElement(tmn);
- } else {
- // if it is before the add, we add the element to the second Vector
- v2.addElement(tmn);
- }
- }
- // then we fill the second Vector qith the rest of elements
- while (i.hasNext()) {
- tmn = i.next();
- v2.addElement(tmn);
- }
- } else {
- // we add in the first vector while we don't reach the middle of weight
- memWeight += elemWeight;
- v1.addElement(tmn);
- }
- }
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 21:15:12
|
Revision: 51
http://svn.sourceforge.net/jtreemap/?rev=51&view=rev
Author: benoitx
Date: 2006-10-23 14:14:44 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitSquarified.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitSquarified.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitSquarified.java (from rev 50, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitSquarified.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitSquarified.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitSquarified.java 2006-10-23 21:14:44 UTC (rev 51)
@@ -0,0 +1,174 @@
+/*
+ * Created on 3 nov. 2005
+ */
+package org.jense.swing.jtreemap;
+
+import java.util.Vector;
+
+/**
+ * The Squarified split strategy
+ *
+ * @author Laurent DUTHEIL
+ */
+public class SplitSquarified extends SplitStrategy {
+ private int w1, h1;
+ private int x, y, w, h;
+ private int x2, y2, w2, h2;
+
+ @Override
+ public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1, Vector<TreeMapNode> v2) {
+ int mid = 0;
+ double weight0 = sumWeight(v);
+ double a = v.get(mid).getWeight() / weight0;
+ double b = a;
+
+ if (this.w < this.h) {
+ // height/width
+ while (mid < v.size()) {
+ double aspect = normAspect(this.h, this.w, a, b);
+ double q = v.get(mid).getWeight() / weight0;
+ if (normAspect(this.h, this.w, a, b + q) > aspect) {
+ break;
+ }
+ mid++;
+ b += q;
+ }
+ int i = 0;
+ for (; i <= mid && i < v.size(); i++) {
+ v1.add(v.get(i));
+ }
+ for (; i < v.size(); i++) {
+ v2.add(v.get(i));
+ }
+ this.h1 = (int) Math.round(this.h * b);
+ this.w1 = this.w;
+ this.x2 = this.x;
+ this.y2 = (int) Math.round(this.y + this.h * b);
+ this.w2 = this.w;
+ this.h2 = this.h - this.h1;
+ } else {
+ // width/height
+ while (mid < v.size()) {
+ double aspect = normAspect(this.w, this.h, a, b);
+ double q = v.get(mid).getWeight() / weight0;
+ if (normAspect(this.w, this.h, a, b + q) > aspect) {
+ break;
+ }
+ mid++;
+ b += q;
+ }
+ int i = 0;
+ for (; i <= mid && i < v.size(); i++) {
+ v1.add(v.get(i));
+ }
+ for (; i < v.size(); i++) {
+ v2.add(v.get(i));
+ }
+ this.h1 = this.h;
+ this.w1 = (int) Math.round(this.w * b);
+ this.x2 = (int) Math.round(this.x + this.w * b);
+ this.y2 = this.y;
+ this.w2 = this.w - this.w1;
+ this.h2 = this.h;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jense.swing.jtreemap.SplitStrategy#calculatePositionsRec(int, int,
+ * int, int, double, java.util.Vector)
+ */
+ @Override
+ protected void calculatePositionsRec(int x0, int y0, int w0, int h0,
+ double weight0, Vector<TreeMapNode> v) {
+ Vector<TreeMapNode> vClone = new Vector<TreeMapNode>(v);
+
+ sortVector(vClone);
+
+ if (vClone.size() <= 2) {
+ SplitBySlice.splitInSlice(x0, y0, w0, h0, vClone, sumWeight(vClone));
+ calculateChildren(vClone);
+ } else {
+ Vector<TreeMapNode> v1 = new Vector<TreeMapNode>();
+ Vector<TreeMapNode> v2 = new Vector<TreeMapNode>();
+ this.x = x0;
+ this.y = y0;
+ this.w = w0;
+ this.h = h0;
+ splitElements(vClone, v1, v2);
+ //before the recurence, we have to "save" the values for the 2nd Vector
+ int x2 = this.x2;
+ int y2 = this.y2;
+ int w2 = this.w2;
+ int h2 = this.h2;
+ SplitBySlice.splitInSlice(x0, y0, this.w1, this.h1, v1, sumWeight(v1));
+ calculateChildren(v1);
+ calculatePositionsRec(x2, y2, w2, h2, sumWeight(v2), v2);
+ }
+
+ }
+
+ private double aspect(double big, double small, double a, double b) {
+ return (big * b) / (small * a / b);
+ }
+
+ /**
+ * Execute the recurence for the children of the elements of the vector.<BR>
+ * Add also the borders if necessary
+ *
+ * @param v Vector with the elements to calculate
+ */
+ private void calculateChildren(Vector<TreeMapNode> v) {
+ for (TreeMapNode node : v) {
+ if (node.isLeaf()) {
+ node.setX(node.getX() + TreeMapNode.getBorder());
+ node.setY(node.getY() + TreeMapNode.getBorder());
+ int w = node.getWidth() - TreeMapNode.getBorder();
+ if (w < 0) {
+ w = 0;
+ }
+ int h = node.getHeight() - TreeMapNode.getBorder();
+ if (h < 0) {
+ h = 0;
+ }
+ node.setHeight(h);
+ node.setWidth(w);
+ } else {
+ //if this is not a leaf, calculation for the children
+ int bSub;
+ if (TreeMapNode.getBorder() > 1) {
+ bSub = 2;
+ } else if (TreeMapNode.getBorder() == 1) {
+ bSub = 1;
+ } else {
+ bSub = 0;
+ }
+
+ int w = node.getWidth() - bSub;
+ if (w < 0) {
+ w = 0;
+ }
+ int h = node.getHeight() - bSub;
+ if (h < 0) {
+ h = 0;
+ }
+
+ TreeMapNode.setBorder(TreeMapNode.getBorder() - bSub);
+ calculatePositionsRec(node.getX() + bSub, node.getY() + bSub, w, h, node.getWeight(), node
+ .getChildren());
+ TreeMapNode.setBorder(TreeMapNode.getBorder() + bSub);
+ }
+
+ }
+ }
+
+ private double normAspect(double big, double small, double a, double b) {
+ double x = aspect(big, small, a, b);
+ if (x < 1) {
+ return 1 / x;
+ }
+ return x;
+ }
+
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitSquarified.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitSquarified.java 2006-10-23 21:13:05 UTC (rev 50)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitSquarified.java 2006-10-23 21:14:44 UTC (rev 51)
@@ -1,174 +0,0 @@
-/*
- * Created on 3 nov. 2005
- */
-package org.jense.swing.jtreemap;
-
-import java.util.Vector;
-
-/**
- * The Squarified split strategy
- *
- * @author Laurent DUTHEIL
- */
-public class SplitSquarified extends SplitStrategy {
- private int w1, h1;
- private int x, y, w, h;
- private int x2, y2, w2, h2;
-
- @Override
- public void splitElements(Vector<TreeMapNode> v, Vector<TreeMapNode> v1, Vector<TreeMapNode> v2) {
- int mid = 0;
- double weight0 = sumWeight(v);
- double a = v.get(mid).getWeight() / weight0;
- double b = a;
-
- if (this.w < this.h) {
- // height/width
- while (mid < v.size()) {
- double aspect = normAspect(this.h, this.w, a, b);
- double q = v.get(mid).getWeight() / weight0;
- if (normAspect(this.h, this.w, a, b + q) > aspect) {
- break;
- }
- mid++;
- b += q;
- }
- int i = 0;
- for (; i <= mid && i < v.size(); i++) {
- v1.add(v.get(i));
- }
- for (; i < v.size(); i++) {
- v2.add(v.get(i));
- }
- this.h1 = (int) Math.round(this.h * b);
- this.w1 = this.w;
- this.x2 = this.x;
- this.y2 = (int) Math.round(this.y + this.h * b);
- this.w2 = this.w;
- this.h2 = this.h - this.h1;
- } else {
- // width/height
- while (mid < v.size()) {
- double aspect = normAspect(this.w, this.h, a, b);
- double q = v.get(mid).getWeight() / weight0;
- if (normAspect(this.w, this.h, a, b + q) > aspect) {
- break;
- }
- mid++;
- b += q;
- }
- int i = 0;
- for (; i <= mid && i < v.size(); i++) {
- v1.add(v.get(i));
- }
- for (; i < v.size(); i++) {
- v2.add(v.get(i));
- }
- this.h1 = this.h;
- this.w1 = (int) Math.round(this.w * b);
- this.x2 = (int) Math.round(this.x + this.w * b);
- this.y2 = this.y;
- this.w2 = this.w - this.w1;
- this.h2 = this.h;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.jense.swing.jtreemap.SplitStrategy#calculatePositionsRec(int, int,
- * int, int, double, java.util.Vector)
- */
- @Override
- protected void calculatePositionsRec(int x0, int y0, int w0, int h0,
- double weight0, Vector<TreeMapNode> v) {
- Vector<TreeMapNode> vClone = new Vector<TreeMapNode>(v);
-
- sortVector(vClone);
-
- if (vClone.size() <= 2) {
- SplitBySlice.splitInSlice(x0, y0, w0, h0, vClone, sumWeight(vClone));
- calculateChildren(vClone);
- } else {
- Vector<TreeMapNode> v1 = new Vector<TreeMapNode>();
- Vector<TreeMapNode> v2 = new Vector<TreeMapNode>();
- this.x = x0;
- this.y = y0;
- this.w = w0;
- this.h = h0;
- splitElements(vClone, v1, v2);
- //before the recurence, we have to "save" the values for the 2nd Vector
- int x2 = this.x2;
- int y2 = this.y2;
- int w2 = this.w2;
- int h2 = this.h2;
- SplitBySlice.splitInSlice(x0, y0, this.w1, this.h1, v1, sumWeight(v1));
- calculateChildren(v1);
- calculatePositionsRec(x2, y2, w2, h2, sumWeight(v2), v2);
- }
-
- }
-
- private double aspect(double big, double small, double a, double b) {
- return (big * b) / (small * a / b);
- }
-
- /**
- * Execute the recurence for the children of the elements of the vector.<BR>
- * Add also the borders if necessary
- *
- * @param v Vector with the elements to calculate
- */
- private void calculateChildren(Vector<TreeMapNode> v) {
- for (TreeMapNode node : v) {
- if (node.isLeaf()) {
- node.setX(node.getX() + TreeMapNode.getBorder());
- node.setY(node.getY() + TreeMapNode.getBorder());
- int w = node.getWidth() - TreeMapNode.getBorder();
- if (w < 0) {
- w = 0;
- }
- int h = node.getHeight() - TreeMapNode.getBorder();
- if (h < 0) {
- h = 0;
- }
- node.setHeight(h);
- node.setWidth(w);
- } else {
- //if this is not a leaf, calculation for the children
- int bSub;
- if (TreeMapNode.getBorder() > 1) {
- bSub = 2;
- } else if (TreeMapNode.getBorder() == 1) {
- bSub = 1;
- } else {
- bSub = 0;
- }
-
- int w = node.getWidth() - bSub;
- if (w < 0) {
- w = 0;
- }
- int h = node.getHeight() - bSub;
- if (h < 0) {
- h = 0;
- }
-
- TreeMapNode.setBorder(TreeMapNode.getBorder() - bSub);
- calculatePositionsRec(node.getX() + bSub, node.getY() + bSub, w, h, node.getWeight(), node
- .getChildren());
- TreeMapNode.setBorder(TreeMapNode.getBorder() + bSub);
- }
-
- }
- }
-
- private double normAspect(double big, double small, double a, double b) {
- double x = aspect(big, small, a, b);
- if (x < 1) {
- return 1 / x;
- }
- return x;
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 21:17:30
|
Revision: 52
http://svn.sourceforge.net/jtreemap/?rev=52&view=rev
Author: benoitx
Date: 2006-10-23 14:17:06 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitStrategy.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitStrategy.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitStrategy.java (from rev 51, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitStrategy.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitStrategy.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/SplitStrategy.java 2006-10-23 21:17:06 UTC (rev 52)
@@ -0,0 +1,163 @@
+package org.jense.swing.jtreemap;
+
+import java.util.Vector;
+
+/**
+ * Abtract class with the method which split the elements of a JTreeMap.
+ * <p>
+ * The split is done by dichotomy. We split the elements in 2 groups with a
+ * defined strategy (for example : take care of the weight of the elements)
+ * <p>
+ *
+ * @author Laurent Dutheil
+ */
+
+public abstract class SplitStrategy {
+ /**
+ * calculate the positions for all the elements of the root.
+ *
+ * @param root the root to calculate
+ */
+ public void calculatePositions(TreeMapNode root) {
+ if (root == null) {
+ return;
+ }
+
+ Vector<TreeMapNode> v = root.getChildren();
+ if (v != null) {
+ calculatePositionsRec(root.getX(), root.getY(), root.getWidth(), root
+ .getHeight(), this.sumWeight(v), v);
+ }
+ }
+
+ /**
+ * split the elements of a JTreeMap.
+ *
+ * @param v Vector with the elements to split (arg IN)
+ * @param v1 first Vector of the split (arg OUT)
+ * @param v2 second Vector of the split (arg OUT)
+ */
+ public abstract void splitElements(Vector<TreeMapNode> v,
+ Vector<TreeMapNode> v1, Vector<TreeMapNode> v2);
+
+ /**
+ * Sum the weight of elements. <BR>
+ * You can override this method if you want to apply a coef on the weights or
+ * to cancel the effect of weight on the strategy.
+ *
+ * @param v Vector with the elements to sum
+ * @return the sum of the weight of elements
+ */
+ public double sumWeight(Vector<TreeMapNode> v) {
+ double d = 0.0;
+ if (v != null) {
+ int size = v.size();
+
+ for (int i = 0; i < size; i++) {
+ d += (v.elementAt(i)).getWeight();
+ }
+ }
+ return d;
+ }
+
+ protected void calculatePositionsRec(int x0, int y0, int w0, int h0,
+ double weight0, Vector<TreeMapNode> v) {
+
+ // if the Vector contains only one element
+ if (v.size() == 1) {
+ TreeMapNode f = v.elementAt(0);
+ if (f.isLeaf()) {
+ // if this is a leaf, we display with the border
+ int w = w0 - TreeMapNode.getBorder();
+ if (w < 0) {
+ w = 0;
+ }
+ int h = h0 - TreeMapNode.getBorder();
+ if (h < 0) {
+ h = 0;
+ }
+ f.setDimension(x0 + TreeMapNode.getBorder(), y0
+ + TreeMapNode.getBorder(), w, h);
+ } else {
+ // if this is not a leaf, calculation for the children
+ f.setDimension(x0, y0, w0, h0);
+
+ int bSub;
+ if (TreeMapNode.getBorder() > 1) {
+ bSub = 2;
+ } else if (TreeMapNode.getBorder() == 1) {
+ bSub = 1;
+ } else {
+ bSub = 0;
+ }
+
+ int w = w0 - bSub;
+ if (w < 0) {
+ w = 0;
+ }
+ int h = h0 - bSub;
+ if (h < 0) {
+ h = 0;
+ }
+
+ TreeMapNode.setBorder(TreeMapNode.getBorder() - bSub);
+ calculatePositionsRec(x0 + bSub, y0 + bSub, w, h, weight0, f
+ .getChildren());
+ TreeMapNode.setBorder(TreeMapNode.getBorder() + bSub);
+ }
+ } else {
+ // if there is more than one element
+ // we split the Vector according to the selected strategy
+ Vector<TreeMapNode> v1 = new Vector<TreeMapNode>();
+ Vector<TreeMapNode> v2 = new Vector<TreeMapNode>();
+ double weight1, weight2; // poids des 2 vecteurs
+ this.splitElements(v, v1, v2);
+ weight1 = this.sumWeight(v1);
+ weight2 = this.sumWeight(v2);
+
+ int w1, w2, h1, h2;
+ int x2, y2;
+ // if width is greater than height, we split the width
+ if (w0 > h0) {
+ w1 = (int) (w0 * weight1 / weight0);
+ w2 = w0 - w1;
+ h1 = h0;
+ h2 = h0;
+ x2 = x0 + w1;
+ y2 = y0;
+ } else {
+ // else we split the height
+ w1 = w0;
+ w2 = w0;
+ h1 = (int) (h0 * weight1 / weight0);
+ h2 = h0 - h1;
+ x2 = x0;
+ y2 = y0 + h1;
+ }
+ // calculation for the new two Vectors
+ calculatePositionsRec(x0, y0, w1, h1, weight1, v1);
+ calculatePositionsRec(x2, y2, w2, h2, weight2, v2);
+ }
+ }
+
+ /**
+ * Sort the elements by descending weight.
+ *
+ * @param v Vector with the elements to be sorted
+ */
+ protected void sortVector(Vector<TreeMapNode> v) {
+ TreeMapNode tmn;
+ // we use the bubble sort
+ for (int i = 0; i < v.size(); i++) {
+ for (int j = v.size() - 1; j > i; j--) {
+ if ((v.elementAt(j)).getWeight() > (v.elementAt(j - 1)).getWeight()) {
+ tmn = (v.elementAt(j));
+ v.setElementAt(v.elementAt(j - 1), j);
+ v.setElementAt(tmn, j - 1);
+ }
+ }
+ }
+
+ }
+
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitStrategy.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitStrategy.java 2006-10-23 21:14:44 UTC (rev 51)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/SplitStrategy.java 2006-10-23 21:17:06 UTC (rev 52)
@@ -1,163 +0,0 @@
-package org.jense.swing.jtreemap;
-
-import java.util.Vector;
-
-/**
- * Abtract class with the method which split the elements of a JTreeMap.
- * <p>
- * The split is done by dichotomy. We split the elements in 2 groups with a
- * defined strategy (for example : take care of the weight of the elements)
- * <p>
- *
- * @author Laurent Dutheil
- */
-
-public abstract class SplitStrategy {
- /**
- * calculate the positions for all the elements of the root.
- *
- * @param root the root to calculate
- */
- public void calculatePositions(TreeMapNode root) {
- if (root == null) {
- return;
- }
-
- Vector<TreeMapNode> v = root.getChildren();
- if (v != null) {
- calculatePositionsRec(root.getX(), root.getY(), root.getWidth(), root
- .getHeight(), this.sumWeight(v), v);
- }
- }
-
- /**
- * split the elements of a JTreeMap.
- *
- * @param v Vector with the elements to split (arg IN)
- * @param v1 first Vector of the split (arg OUT)
- * @param v2 second Vector of the split (arg OUT)
- */
- public abstract void splitElements(Vector<TreeMapNode> v,
- Vector<TreeMapNode> v1, Vector<TreeMapNode> v2);
-
- /**
- * Sum the weight of elements. <BR>
- * You can override this method if you want to apply a coef on the weights or
- * to cancel the effect of weight on the strategy.
- *
- * @param v Vector with the elements to sum
- * @return the sum of the weight of elements
- */
- public double sumWeight(Vector<TreeMapNode> v) {
- double d = 0.0;
- if (v != null) {
- int size = v.size();
-
- for (int i = 0; i < size; i++) {
- d += (v.elementAt(i)).getWeight();
- }
- }
- return d;
- }
-
- protected void calculatePositionsRec(int x0, int y0, int w0, int h0,
- double weight0, Vector<TreeMapNode> v) {
-
- // if the Vector contains only one element
- if (v.size() == 1) {
- TreeMapNode f = v.elementAt(0);
- if (f.isLeaf()) {
- // if this is a leaf, we display with the border
- int w = w0 - TreeMapNode.getBorder();
- if (w < 0) {
- w = 0;
- }
- int h = h0 - TreeMapNode.getBorder();
- if (h < 0) {
- h = 0;
- }
- f.setDimension(x0 + TreeMapNode.getBorder(), y0
- + TreeMapNode.getBorder(), w, h);
- } else {
- // if this is not a leaf, calculation for the children
- f.setDimension(x0, y0, w0, h0);
-
- int bSub;
- if (TreeMapNode.getBorder() > 1) {
- bSub = 2;
- } else if (TreeMapNode.getBorder() == 1) {
- bSub = 1;
- } else {
- bSub = 0;
- }
-
- int w = w0 - bSub;
- if (w < 0) {
- w = 0;
- }
- int h = h0 - bSub;
- if (h < 0) {
- h = 0;
- }
-
- TreeMapNode.setBorder(TreeMapNode.getBorder() - bSub);
- calculatePositionsRec(x0 + bSub, y0 + bSub, w, h, weight0, f
- .getChildren());
- TreeMapNode.setBorder(TreeMapNode.getBorder() + bSub);
- }
- } else {
- // if there is more than one element
- // we split the Vector according to the selected strategy
- Vector<TreeMapNode> v1 = new Vector<TreeMapNode>();
- Vector<TreeMapNode> v2 = new Vector<TreeMapNode>();
- double weight1, weight2; // poids des 2 vecteurs
- this.splitElements(v, v1, v2);
- weight1 = this.sumWeight(v1);
- weight2 = this.sumWeight(v2);
-
- int w1, w2, h1, h2;
- int x2, y2;
- // if width is greater than height, we split the width
- if (w0 > h0) {
- w1 = (int) (w0 * weight1 / weight0);
- w2 = w0 - w1;
- h1 = h0;
- h2 = h0;
- x2 = x0 + w1;
- y2 = y0;
- } else {
- // else we split the height
- w1 = w0;
- w2 = w0;
- h1 = (int) (h0 * weight1 / weight0);
- h2 = h0 - h1;
- x2 = x0;
- y2 = y0 + h1;
- }
- // calculation for the new two Vectors
- calculatePositionsRec(x0, y0, w1, h1, weight1, v1);
- calculatePositionsRec(x2, y2, w2, h2, weight2, v2);
- }
- }
-
- /**
- * Sort the elements by descending weight.
- *
- * @param v Vector with the elements to be sorted
- */
- protected void sortVector(Vector<TreeMapNode> v) {
- TreeMapNode tmn;
- // we use the bubble sort
- for (int i = 0; i < v.size(); i++) {
- for (int j = v.size() - 1; j > i; j--) {
- if ((v.elementAt(j)).getWeight() > (v.elementAt(j - 1)).getWeight()) {
- tmn = (v.elementAt(j));
- v.setElementAt(v.elementAt(j - 1), j);
- v.setElementAt(tmn, j - 1);
- }
- }
- }
-
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 21:18:52
|
Revision: 53
http://svn.sourceforge.net/jtreemap/?rev=53&view=rev
Author: benoitx
Date: 2006-10-23 14:18:29 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/TreeMapNode.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/TreeMapNode.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/TreeMapNode.java (from rev 52, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/TreeMapNode.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/TreeMapNode.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/TreeMapNode.java 2006-10-23 21:18:29 UTC (rev 53)
@@ -0,0 +1,328 @@
+package org.jense.swing.jtreemap;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+
+/**
+ * Node of a JTreeMap.<BR>
+ *
+ * If the node is a branch, only the label is set.<BR>
+ * If the node is a leaf, we need a label, a weight and a value.
+ * <p>
+ * You can also use a TreeMapNode in a JTree.
+ *
+ * @author Laurent Dutheil
+ */
+
+public class TreeMapNode extends DefaultMutableTreeNode {
+ private static final long serialVersionUID = 742372833853976103L;
+ //max border between two nodes of the same level
+ private static int border = 3;
+ private int height;
+ private Value value;
+ private double weight = 0.0;
+ private int width;
+ private int x;
+ private int y;
+
+ /**
+ * Get the max border between two nodes of the same level.
+ *
+ * @return Returns the border.
+ */
+ public static int getBorder() {
+ return TreeMapNode.border;
+ }
+
+ /**
+ * Set the max border between two nodes of the same level.
+ *
+ * @param border The border to set.
+ */
+ public static void setBorder(int border) {
+ TreeMapNode.border = border;
+ }
+
+
+ /**
+ * Constructor for a branch.
+ *
+ * @param label label of the branch.
+ */
+ public TreeMapNode(String label) {
+ super(label);
+ super.allowsChildren = true;
+ }
+
+ /**
+ * Constructor for a leaf.
+ *
+ * @param label label of the leaf.
+ * @param weight weight of the leaf (if negative, we take the absolute value).
+ * @param value Value associ\xE9e \xE0 la feuille
+ */
+ public TreeMapNode(String label, double weight, Value value) {
+ super(label);
+ //the weight must be positive
+ this.weight = Math.abs(weight);
+ this.value = value;
+ super.allowsChildren = false;
+ }
+
+ /**
+ * add a new child to the node.
+ *
+ * @param newChild new child
+ */
+ public void add(TreeMapNode newChild) {
+ super.add(newChild);
+ this.setWeight(this.weight + newChild.getWeight());
+ }
+
+ /**
+ * get the active leaf.<BR>
+ * null if the passed position is not in this tree.
+ *
+ * @param x x-coordinate
+ * @param y y-coordinate
+ * @return active leaf
+ */
+ public TreeMapNode getActiveLeaf(int x, int y) {
+
+ if (this.isLeaf()) {
+ if ((x >= this.getX()) && (x <= this.getX() + this.getWidth())
+ && (y >= this.getY()) && (y <= this.getY() + this.getHeight())) {
+ return this;
+ }
+ } else {
+ for (Enumeration e = this.children(); e.hasMoreElements();) {
+ TreeMapNode node = (TreeMapNode) (e.nextElement());
+ if ((x >= node.getX()) && (x <= node.getX() + node.getWidth())
+ && (y >= node.getY()) && (y <= node.getY() + node.getHeight())) {
+ return node.getActiveLeaf(x, y);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * get the first child which fits the position.<BR>
+ * null if the passed position is not in this tree.
+ *
+ * @param x x-coordinate
+ * @param y y-coordinate
+ * @return the first child which fits the position.
+ */
+ public TreeMapNode getChild(int x, int y) {
+ if (! this.isLeaf()) {
+ for (Enumeration e = this.children(); e.hasMoreElements();) {
+ TreeMapNode node = (TreeMapNode) (e.nextElement());
+ if ((x >= node.getX()) && (x <= node.getX() + node.getWidth())
+ && (y >= node.getY()) && (y <= node.getY() + node.getHeight())) {
+ return node;
+ }
+ }
+
+ }
+ return null;
+ }
+
+ /**
+ * get a Vector with the children.
+ *
+ * @return Vector with the children
+ */
+ @SuppressWarnings("unchecked")
+ public Vector<TreeMapNode> getChildren() {
+ return this.children;
+ }
+
+ /**
+ * get the height.
+ *
+ * @return the height
+ */
+ public int getHeight() {
+ return this.height;
+ }
+
+ /**
+ * get the label.
+ *
+ * @return the label
+ */
+ public String getLabel() {
+ return this.getUserObject().toString();
+ }
+
+ /**
+ * get the label of the Value.
+ *
+ * @return the label of the Value
+ */
+ public String getLabelValue() {
+ return this.value.getLabel();
+ }
+
+ /**
+ * get the Value.
+ *
+ * @return the value
+ */
+ public Value getValue() {
+ return this.value;
+ }
+
+ /**
+ * get the double Value.
+ *
+ * @return the double value
+ */
+ public double getDoubleValue() {
+ return this.value.getValue();
+ }
+
+ /**
+ * get the weight.
+ *
+ * @return the weight
+ */
+ public double getWeight() {
+ return this.weight;
+ }
+
+ /**
+ * get the width.
+ *
+ * @return the width
+ */
+ public int getWidth() {
+ return this.width;
+ }
+
+ /**
+ * get the x-coordinate.
+ *
+ * @return the x-coordinate
+ */
+ public int getX() {
+ return this.x;
+ }
+
+ /**
+ * get the y-coordinate.
+ *
+ * @return the y-coordinate
+ */
+ public int getY() {
+ return this.y;
+ }
+
+ /**
+ * set the position and the size.
+ *
+ * @param x x-coordinate
+ * @param y y-coordinate
+ * @param width the new width
+ * @param height the new height
+ */
+ public void setDimension(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+ /**
+ * set the height.
+ *
+ * @param height la nouvelle valeur de height
+ */
+ public void setHeight(int height) {
+ this.height = height;
+ }
+
+ /**
+ * set the label.
+ *
+ * @param label the new label
+ */
+ public void setLabel(String label) {
+ this.userObject = label;
+ }
+
+ /**
+ * set the position.
+ *
+ * @param x x-coordinate
+ * @param y y-coordinate
+ */
+ public void setPosition(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ /**
+ * set size.
+ *
+ * @param width the new width
+ * @param height the new height
+ */
+ public void setSize(int width, int height) {
+ this.width = width;
+ this.height = height;
+ }
+
+ /**
+ * set the Value.
+ *
+ * @param value the new Value
+ */
+ public void setValue(Value value) {
+ this.value = value;
+ }
+
+ /**
+ * set the weight of the node and update the parents.
+ *
+ * @param weight the new weight
+ */
+ public void setWeight(double weight) {
+ double newWeight = Math.abs(weight);
+ if (this.parent != null) {
+ ((TreeMapNode) this.parent).setWeight(((TreeMapNode) this.parent).weight
+ - this.weight + newWeight);
+ }
+ this.weight = newWeight;
+ }
+
+ /**
+ * set the width.
+ *
+ * @param width la nouvelle valeur de width
+ */
+ public void setWidth(int width) {
+ this.width = width;
+ }
+
+ /**
+ * set the x-coordinate.
+ *
+ * @param x the new x-coordinate
+ */
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ /**
+ * set the y-coordinate.
+ *
+ * @param y the new y-coordinate
+ */
+ public void setY(int y) {
+ this.y = y;
+ }
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/TreeMapNode.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/TreeMapNode.java 2006-10-23 21:17:06 UTC (rev 52)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/TreeMapNode.java 2006-10-23 21:18:29 UTC (rev 53)
@@ -1,328 +0,0 @@
-package org.jense.swing.jtreemap;
-
-import java.util.Enumeration;
-import java.util.Vector;
-
-import javax.swing.tree.DefaultMutableTreeNode;
-
-/**
- * Node of a JTreeMap.<BR>
- *
- * If the node is a branch, only the label is set.<BR>
- * If the node is a leaf, we need a label, a weight and a value.
- * <p>
- * You can also use a TreeMapNode in a JTree.
- *
- * @author Laurent Dutheil
- */
-
-public class TreeMapNode extends DefaultMutableTreeNode {
- private static final long serialVersionUID = 742372833853976103L;
- //max border between two nodes of the same level
- private static int border = 3;
- private int height;
- private Value value;
- private double weight = 0.0;
- private int width;
- private int x;
- private int y;
-
- /**
- * Get the max border between two nodes of the same level.
- *
- * @return Returns the border.
- */
- public static int getBorder() {
- return TreeMapNode.border;
- }
-
- /**
- * Set the max border between two nodes of the same level.
- *
- * @param border The border to set.
- */
- public static void setBorder(int border) {
- TreeMapNode.border = border;
- }
-
-
- /**
- * Constructor for a branch.
- *
- * @param label label of the branch.
- */
- public TreeMapNode(String label) {
- super(label);
- super.allowsChildren = true;
- }
-
- /**
- * Constructor for a leaf.
- *
- * @param label label of the leaf.
- * @param weight weight of the leaf (if negative, we take the absolute value).
- * @param value Value associ\xE9e \xE0 la feuille
- */
- public TreeMapNode(String label, double weight, Value value) {
- super(label);
- //the weight must be positive
- this.weight = Math.abs(weight);
- this.value = value;
- super.allowsChildren = false;
- }
-
- /**
- * add a new child to the node.
- *
- * @param newChild new child
- */
- public void add(TreeMapNode newChild) {
- super.add(newChild);
- this.setWeight(this.weight + newChild.getWeight());
- }
-
- /**
- * get the active leaf.<BR>
- * null if the passed position is not in this tree.
- *
- * @param x x-coordinate
- * @param y y-coordinate
- * @return active leaf
- */
- public TreeMapNode getActiveLeaf(int x, int y) {
-
- if (this.isLeaf()) {
- if ((x >= this.getX()) && (x <= this.getX() + this.getWidth())
- && (y >= this.getY()) && (y <= this.getY() + this.getHeight())) {
- return this;
- }
- } else {
- for (Enumeration e = this.children(); e.hasMoreElements();) {
- TreeMapNode node = (TreeMapNode) (e.nextElement());
- if ((x >= node.getX()) && (x <= node.getX() + node.getWidth())
- && (y >= node.getY()) && (y <= node.getY() + node.getHeight())) {
- return node.getActiveLeaf(x, y);
- }
- }
- }
- return null;
- }
-
- /**
- * get the first child which fits the position.<BR>
- * null if the passed position is not in this tree.
- *
- * @param x x-coordinate
- * @param y y-coordinate
- * @return the first child which fits the position.
- */
- public TreeMapNode getChild(int x, int y) {
- if (! this.isLeaf()) {
- for (Enumeration e = this.children(); e.hasMoreElements();) {
- TreeMapNode node = (TreeMapNode) (e.nextElement());
- if ((x >= node.getX()) && (x <= node.getX() + node.getWidth())
- && (y >= node.getY()) && (y <= node.getY() + node.getHeight())) {
- return node;
- }
- }
-
- }
- return null;
- }
-
- /**
- * get a Vector with the children.
- *
- * @return Vector with the children
- */
- @SuppressWarnings("unchecked")
- public Vector<TreeMapNode> getChildren() {
- return this.children;
- }
-
- /**
- * get the height.
- *
- * @return the height
- */
- public int getHeight() {
- return this.height;
- }
-
- /**
- * get the label.
- *
- * @return the label
- */
- public String getLabel() {
- return this.getUserObject().toString();
- }
-
- /**
- * get the label of the Value.
- *
- * @return the label of the Value
- */
- public String getLabelValue() {
- return this.value.getLabel();
- }
-
- /**
- * get the Value.
- *
- * @return the value
- */
- public Value getValue() {
- return this.value;
- }
-
- /**
- * get the double Value.
- *
- * @return the double value
- */
- public double getDoubleValue() {
- return this.value.getValue();
- }
-
- /**
- * get the weight.
- *
- * @return the weight
- */
- public double getWeight() {
- return this.weight;
- }
-
- /**
- * get the width.
- *
- * @return the width
- */
- public int getWidth() {
- return this.width;
- }
-
- /**
- * get the x-coordinate.
- *
- * @return the x-coordinate
- */
- public int getX() {
- return this.x;
- }
-
- /**
- * get the y-coordinate.
- *
- * @return the y-coordinate
- */
- public int getY() {
- return this.y;
- }
-
- /**
- * set the position and the size.
- *
- * @param x x-coordinate
- * @param y y-coordinate
- * @param width the new width
- * @param height the new height
- */
- public void setDimension(int x, int y, int width, int height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
-
- /**
- * set the height.
- *
- * @param height la nouvelle valeur de height
- */
- public void setHeight(int height) {
- this.height = height;
- }
-
- /**
- * set the label.
- *
- * @param label the new label
- */
- public void setLabel(String label) {
- this.userObject = label;
- }
-
- /**
- * set the position.
- *
- * @param x x-coordinate
- * @param y y-coordinate
- */
- public void setPosition(int x, int y) {
- this.x = x;
- this.y = y;
- }
-
- /**
- * set size.
- *
- * @param width the new width
- * @param height the new height
- */
- public void setSize(int width, int height) {
- this.width = width;
- this.height = height;
- }
-
- /**
- * set the Value.
- *
- * @param value the new Value
- */
- public void setValue(Value value) {
- this.value = value;
- }
-
- /**
- * set the weight of the node and update the parents.
- *
- * @param weight the new weight
- */
- public void setWeight(double weight) {
- double newWeight = Math.abs(weight);
- if (this.parent != null) {
- ((TreeMapNode) this.parent).setWeight(((TreeMapNode) this.parent).weight
- - this.weight + newWeight);
- }
- this.weight = newWeight;
- }
-
- /**
- * set the width.
- *
- * @param width la nouvelle valeur de width
- */
- public void setWidth(int width) {
- this.width = width;
- }
-
- /**
- * set the x-coordinate.
- *
- * @param x the new x-coordinate
- */
- public void setX(int x) {
- this.x = x;
- }
-
- /**
- * set the y-coordinate.
- *
- * @param y the new y-coordinate
- */
- public void setY(int y) {
- this.y = y;
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 21:19:45
|
Revision: 54
http://svn.sourceforge.net/jtreemap/?rev=54&view=rev
Author: benoitx
Date: 2006-10-23 14:19:24 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/TreeMapNodeBuilder.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/TreeMapNodeBuilder.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/TreeMapNodeBuilder.java (from rev 53, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/TreeMapNodeBuilder.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/TreeMapNodeBuilder.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/TreeMapNodeBuilder.java 2006-10-23 21:19:24 UTC (rev 54)
@@ -0,0 +1,63 @@
+package org.jense.swing.jtreemap;
+
+/**
+ * Tree builder for a JTreeMap.
+ *
+ * @author Laurent Dutheil
+ */
+
+public class TreeMapNodeBuilder {
+ private TreeMapNode root;
+
+ /**
+ * Add a branch to the tree. <BR>
+ * If the parent is null, the build node become the root if and only if the
+ * tree have no root yet. If the parent is null and if the root is already
+ * build, the node will NOT be added to the tree.
+ *
+ * @param label label of the node
+ * @param parent father of the node
+ * @return the created node
+ */
+ public TreeMapNode buildBranch(String label, TreeMapNode parent) {
+ TreeMapNode node = new TreeMapNode(label);
+ if (parent != null) {
+ parent.add(node);
+ } else if (this.root == null) {
+ this.root = node;
+ }
+ return node;
+ }
+
+ /**
+ * add a leaf to the tree. <BR>
+ * If the parent is null, the build node become the root if and only if the
+ * tree have no root yet. If the parent is null and if the root is already
+ * build, the node will NOT be added to the tree.
+ *
+ * @param label label of the leaf
+ * @param weight weight of the leaf
+ * @param value Value of the leaf
+ * @param parent father of the leaf
+ * @return the created node
+ */
+ public TreeMapNode buildLeaf(String label, double weight, Value value,
+ TreeMapNode parent) {
+ TreeMapNode node = new TreeMapNode(label, weight, value);
+ if (parent != null) {
+ parent.add(node);
+ } else if (this.root == null) {
+ this.root = node;
+ }
+ return node;
+ }
+
+ /**
+ * get the build tree.
+ *
+ * @return the root of the tree
+ */
+ public TreeMapNode getRoot() {
+ return this.root;
+ }
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/TreeMapNodeBuilder.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/TreeMapNodeBuilder.java 2006-10-23 21:18:29 UTC (rev 53)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/TreeMapNodeBuilder.java 2006-10-23 21:19:24 UTC (rev 54)
@@ -1,63 +0,0 @@
-package org.jense.swing.jtreemap;
-
-/**
- * Tree builder for a JTreeMap.
- *
- * @author Laurent Dutheil
- */
-
-public class TreeMapNodeBuilder {
- private TreeMapNode root;
-
- /**
- * Add a branch to the tree. <BR>
- * If the parent is null, the build node become the root if and only if the
- * tree have no root yet. If the parent is null and if the root is already
- * build, the node will NOT be added to the tree.
- *
- * @param label label of the node
- * @param parent father of the node
- * @return the created node
- */
- public TreeMapNode buildBranch(String label, TreeMapNode parent) {
- TreeMapNode node = new TreeMapNode(label);
- if (parent != null) {
- parent.add(node);
- } else if (this.root == null) {
- this.root = node;
- }
- return node;
- }
-
- /**
- * add a leaf to the tree. <BR>
- * If the parent is null, the build node become the root if and only if the
- * tree have no root yet. If the parent is null and if the root is already
- * build, the node will NOT be added to the tree.
- *
- * @param label label of the leaf
- * @param weight weight of the leaf
- * @param value Value of the leaf
- * @param parent father of the leaf
- * @return the created node
- */
- public TreeMapNode buildLeaf(String label, double weight, Value value,
- TreeMapNode parent) {
- TreeMapNode node = new TreeMapNode(label, weight, value);
- if (parent != null) {
- parent.add(node);
- } else if (this.root == null) {
- this.root = node;
- }
- return node;
- }
-
- /**
- * get the build tree.
- *
- * @return the root of the tree
- */
- public TreeMapNode getRoot() {
- return this.root;
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 21:21:44
|
Revision: 56
http://svn.sourceforge.net/jtreemap/?rev=56&view=rev
Author: benoitx
Date: 2006-10-23 14:21:20 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/UniqueColorProvider.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/UniqueColorProvider.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/UniqueColorProvider.java (from rev 55, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/UniqueColorProvider.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/UniqueColorProvider.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/UniqueColorProvider.java 2006-10-23 21:21:20 UTC (rev 56)
@@ -0,0 +1,80 @@
+/*
+ * Created on 7 oct. 2005
+ *
+ */
+package org.jense.swing.jtreemap;
+
+import java.awt.Color;
+import java.awt.Graphics;
+
+import javax.swing.JPanel;
+
+/**
+ * Color Provider by default.<BR>
+ * All values are associated to a unique color.
+ *
+ * @author Laurent DUTHEIL
+ *
+ */
+public class UniqueColorProvider extends ColorProvider {
+ private final static Color defaultColor = new Color(153,153,51);
+ private Color color;
+ private JPanel legend;
+
+ /**
+ * Constructor.
+ */
+ public UniqueColorProvider() {
+ this.color = defaultColor;
+ }
+
+ /**
+ * Constructor.
+ * @param color unique color
+ */
+ public UniqueColorProvider(Color color) {
+ this.color = color;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jense.swing.jtreemap.ColorProvider#getColor(double)
+ */
+ @Override
+ public Color getColor(Value value) {
+ return this.color;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jense.swing.jtreemap.ColorProvider#getLegendPanel()
+ */
+ @Override
+ public JPanel getLegendPanel() {
+ if (this.legend == null) {
+ this.legend = new Legend();
+ }
+ return this.legend;
+ }
+ /**
+ * Panel with the legend.
+ *
+ * @author Laurent Dutheil
+ */
+ private class Legend extends JPanel {
+ private static final long serialVersionUID = -8046211081305644785L;
+ private String text = "Unique Color Provider";
+
+ /**
+ * Constructor.
+ */
+ public Legend() {
+ this.setPreferredSize(new java.awt.Dimension(100, 40));
+
+ }
+
+ @Override
+ public void paint(Graphics g) {
+ g.setColor(Color.black);
+ g.drawString(this.text, 20, 20);
+ }
+ }
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/UniqueColorProvider.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/UniqueColorProvider.java 2006-10-23 21:21:02 UTC (rev 55)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/UniqueColorProvider.java 2006-10-23 21:21:20 UTC (rev 56)
@@ -1,80 +0,0 @@
-/*
- * Created on 7 oct. 2005
- *
- */
-package org.jense.swing.jtreemap;
-
-import java.awt.Color;
-import java.awt.Graphics;
-
-import javax.swing.JPanel;
-
-/**
- * Color Provider by default.<BR>
- * All values are associated to a unique color.
- *
- * @author Laurent DUTHEIL
- *
- */
-public class UniqueColorProvider extends ColorProvider {
- private final static Color defaultColor = new Color(153,153,51);
- private Color color;
- private JPanel legend;
-
- /**
- * Constructor.
- */
- public UniqueColorProvider() {
- this.color = defaultColor;
- }
-
- /**
- * Constructor.
- * @param color unique color
- */
- public UniqueColorProvider(Color color) {
- this.color = color;
- }
-
- /* (non-Javadoc)
- * @see org.jense.swing.jtreemap.ColorProvider#getColor(double)
- */
- @Override
- public Color getColor(Value value) {
- return this.color;
- }
-
- /* (non-Javadoc)
- * @see org.jense.swing.jtreemap.ColorProvider#getLegendPanel()
- */
- @Override
- public JPanel getLegendPanel() {
- if (this.legend == null) {
- this.legend = new Legend();
- }
- return this.legend;
- }
- /**
- * Panel with the legend.
- *
- * @author Laurent Dutheil
- */
- private class Legend extends JPanel {
- private static final long serialVersionUID = -8046211081305644785L;
- private String text = "Unique Color Provider";
-
- /**
- * Constructor.
- */
- public Legend() {
- this.setPreferredSize(new java.awt.Dimension(100, 40));
-
- }
-
- @Override
- public void paint(Graphics g) {
- g.setColor(Color.black);
- g.drawString(this.text, 20, 20);
- }
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <be...@us...> - 2006-10-23 21:23:06
|
Revision: 57
http://svn.sourceforge.net/jtreemap/?rev=57&view=rev
Author: benoitx
Date: 2006-10-23 14:22:42 -0700 (Mon, 23 Oct 2006)
Log Message:
-----------
Moved remotely
Added Paths:
-----------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/Value.java
Removed Paths:
-------------
trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/Value.java
Copied: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/Value.java (from rev 56, trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/Value.java)
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/Value.java (rev 0)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/Value.java 2006-10-23 21:22:42 UTC (rev 57)
@@ -0,0 +1,64 @@
+package org.jense.swing.jtreemap;
+
+
+/**
+ * Class who permits to associate a double value to a label
+ *
+ * @author Laurent DUTHEIL
+ */
+
+public abstract class Value implements Comparable {
+ /**
+ * get the double value.
+ *
+ *@return the double value
+ */
+ public abstract double getValue();
+
+ /**
+ * get the formatedValue.
+ *
+ *@return the label of the value
+ */
+ public abstract String getLabel();
+
+ /**
+ * set the double value.
+ *
+ *@param value the new double value
+ */
+ public abstract void setValue(double value);
+
+ /**
+ * set the new label.
+ *
+ *@param newLabel the new label
+ */
+ public abstract void setLabel(String newLabel);
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object value) {
+ if (value != null && value instanceof Value) {
+ Value value2 = (Value) value;
+ return value2.getValue() == this.getValue();
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object value) {
+ if (value != null && value instanceof Value) {
+ Value value2 = (Value) value;
+ if (this.getValue() < value2.getValue()) {
+ return -1;
+ }
+ return this.getValue() > value2.getValue() ? 1 : 0;
+ }
+ throw new IllegalArgumentException();
+ }
+}
Deleted: trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/Value.java
===================================================================
--- trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/Value.java 2006-10-23 21:21:20 UTC (rev 56)
+++ trunk/JTreeMap/src/main/java/org/jense/swing/jtreemap/Value.java 2006-10-23 21:22:42 UTC (rev 57)
@@ -1,64 +0,0 @@
-package org.jense.swing.jtreemap;
-
-
-/**
- * Class who permits to associate a double value to a label
- *
- * @author Laurent DUTHEIL
- */
-
-public abstract class Value implements Comparable {
- /**
- * get the double value.
- *
- *@return the double value
- */
- public abstract double getValue();
-
- /**
- * get the formatedValue.
- *
- *@return the label of the value
- */
- public abstract String getLabel();
-
- /**
- * set the double value.
- *
- *@param value the new double value
- */
- public abstract void setValue(double value);
-
- /**
- * set the new label.
- *
- *@param newLabel the new label
- */
- public abstract void setLabel(String newLabel);
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object value) {
- if (value != null && value instanceof Value) {
- Value value2 = (Value) value;
- return value2.getValue() == this.getValue();
- }
- return false;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
- public int compareTo(Object value) {
- if (value != null && value instanceof Value) {
- Value value2 = (Value) value;
- if (this.getValue() < value2.getValue()) {
- return -1;
- }
- return this.getValue() > value2.getValue() ? 1 : 0;
- }
- throw new IllegalArgumentException();
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <eki...@us...> - 2006-11-05 13:15:07
|
Revision: 94
http://svn.sourceforge.net/jtreemap/?rev=94&view=rev
Author: ekingulen
Date: 2006-11-05 05:14:46 -0800 (Sun, 05 Nov 2006)
Log Message:
-----------
Modified Paths:
--------------
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/BuilderTM3.java
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/BuilderXML.java
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/JTreeMapAppletExample.java
Added Paths:
-----------
trunk/JTreeMap/src/main/java/TreeMap.dtd
Added: trunk/JTreeMap/src/main/java/TreeMap.dtd
===================================================================
--- trunk/JTreeMap/src/main/java/TreeMap.dtd (rev 0)
+++ trunk/JTreeMap/src/main/java/TreeMap.dtd 2006-11-05 13:14:46 UTC (rev 94)
@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='ISO-8859-1'?>
+<!ELEMENT root (label,(branch |leaf)*)>
+<!ELEMENT branch (label,(branch|leaf)*)>
+<!ELEMENT leaf (label,weight,value) >
+<!ELEMENT label (#PCDATA) >
+<!ELEMENT weight (#PCDATA) >
+<!ELEMENT value (#PCDATA) >
\ No newline at end of file
Modified: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/BuilderTM3.java
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/BuilderTM3.java 2006-11-04 18:07:39 UTC (rev 93)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/BuilderTM3.java 2006-11-05 13:14:46 UTC (rev 94)
@@ -102,10 +102,22 @@
*/
public BuilderTM3(final File tm3File) throws IOException {
this.builder = new TreeMapNodeBuilder();
- parse(tm3File);
+ parse(new BufferedReader(new FileReader(tm3File)));
}
/**
+ * Constructor
+ *
+ * @param reader
+ * reader associated with tm3 file
+ * @throws IOException
+ */
+ public BuilderTM3(final BufferedReader reader) throws IOException {
+ this.builder = new TreeMapNodeBuilder();
+ parse(reader);
+ }
+
+ /**
* @return the number fields (ie INTEGER and FLOAT)
*/
public String[] getNumberFields() {
@@ -222,17 +234,14 @@
}
/**
- * @param tm3File
- * TM3 file
+ * @param reader The <code>BufferedReader</code>.
* @throws IOException
*/
- private void parse(final File tm3File) throws IOException {
-
- final BufferedReader in = new BufferedReader(new FileReader(tm3File));
+ private void parse(final BufferedReader reader) throws IOException {
try {
String line = "";
// read the field names
- line = in.readLine();
+ line = reader.readLine();
StringTokenizer st = new StringTokenizer(line, "\t");
FIELD_NAMES.clear();
while (st.hasMoreTokens()) {
@@ -240,7 +249,7 @@
}
// read the field types
- line = in.readLine();
+ line = reader.readLine();
st = new StringTokenizer(line, "\t");
FIELD_TYPES.clear();
while (st.hasMoreTokens()) {
@@ -249,7 +258,7 @@
// read the VALUES
VALUES.clear();
- while ((line = in.readLine()) != null) {
+ while ((line = reader.readLine()) != null) {
st = new StringTokenizer(line, "\t");
final HashMap<String, Object> mapNodeValues = new HashMap<String, Object>();
// the VALUES are formated
@@ -281,8 +290,8 @@
createNodes(st, mapNodeValues);
}
} finally {
- if (in != null) {
- in.close();
+ if (reader != null) {
+ reader.close();
}
}
}
Modified: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/BuilderXML.java
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/BuilderXML.java 2006-11-04 18:07:39 UTC (rev 93)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/BuilderXML.java 2006-11-05 13:14:46 UTC (rev 94)
@@ -34,6 +34,7 @@
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.text.ParseException;
import javax.xml.parsers.DocumentBuilder;
@@ -99,6 +100,19 @@
}
/**
+ * Constructor
+ *
+ * @param stream
+ * <code>InputStream </code> representing XML file object
+ * @throws ParseException
+ * if the file don't correspond to the TreeMap.dtd
+ */
+ public BuilderXML(final InputStream stream) throws ParseException {
+ this.builder = new TreeMapNodeBuilder();
+ parse(stream);
+ }
+
+ /**
* get the build root
*
* @return the build root
@@ -160,6 +174,26 @@
throw new ParseException("The file don't correspond to the TreeMap.dtd (" + e.getMessage() + ")", 0);
}
}
+
+ private void parse(final InputStream stream) throws ParseException {
+ try {
+ final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
+
+ final DocumentBuilder constructeur = fabrique.newDocumentBuilder();
+ this.document = constructeur.parse(stream);
+
+ final Element root = this.document.getDocumentElement();
+
+ build(root, null);
+ } catch (final ParserConfigurationException e) {
+ throw new ParseException("The file don't correspond to the TreeMap.dtd (" + e.getMessage() + ")", 0);
+ } catch (final SAXException e) {
+ throw new ParseException("The file don't correspond to the TreeMap.dtd (" + e.getMessage() + ")", 0);
+ } catch (final IOException e) {
+ e.printStackTrace();
+ throw new ParseException("The file don't correspond to the TreeMap.dtd (" + e.getMessage() + ")", 0);
+ }
+ }
}
/*
* ObjectLab is supporing JTreeMap
Modified: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/JTreeMapAppletExample.java
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/JTreeMapAppletExample.java 2006-11-04 18:07:39 UTC (rev 93)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/JTreeMapAppletExample.java 2006-11-05 13:14:46 UTC (rev 94)
@@ -38,10 +38,12 @@
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.io.File;
+import java.io.BufferedReader;
import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
import java.text.ParseException;
import javax.swing.JApplet;
@@ -119,7 +121,7 @@
TreeMapNode root = null;
if(TM3.equalsIgnoreCase(dataFileType)) {
try {
- builderTM3 = new BuilderTM3(new File(new URI(getCodeBase() + dataFile)));
+ builderTM3 = new BuilderTM3(createReader(dataFile));
root = builderTM3.getRoot();
if (showTM3CTonf) {
setTM3Fields();
@@ -127,18 +129,20 @@
}
} catch (final IOException e) {
root = handleException(e);
- } catch (URISyntaxException e) {
- root = handleException(e);
- }
+ }
} else if(XML.equalsIgnoreCase(dataFileType)) {
try {
- final BuilderXML bXml = new BuilderXML(new File(new URI(getCodeBase() + dataFile)));
+ URL url = new URL(getCodeBase() + dataFile);
+ URLConnection connection = url.openConnection();
+ final BuilderXML bXml = new BuilderXML(connection.getInputStream());
root = bXml.getRoot();
} catch (final ParseException e) {
root = handleException(e);
- } catch (URISyntaxException e) {
+ } catch (MalformedURLException e) {
root = handleException(e);
- }
+ } catch (IOException e) {
+ root = handleException(e);
+ }
} else {
root = DemoUtil.buildDemoRoot();
@@ -154,6 +158,20 @@
getJContentPane().add(this.jTreeMap, BorderLayout.CENTER);
}
+ /**
+ * @param dataFile
+ * @return
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ private BufferedReader createReader(String dataFile) throws MalformedURLException, IOException {
+ URL url = new URL(getCodeBase() + dataFile);
+ URLConnection connection = url.openConnection();
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(connection.getInputStream()));
+ return reader;
+ }
+
private TreeMapNode handleException(final Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, e.getMessage(), "File error", JOptionPane.ERROR_MESSAGE);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|