|
From: <eki...@us...> - 2006-12-12 00:10:33
|
Revision: 116
http://svn.sourceforge.net/jtreemap/?rev=116&view=rev
Author: ekingulen
Date: 2006-12-11 16:10:31 -0800 (Mon, 11 Dec 2006)
Log Message:
-----------
- Tooltip made configurable.
Modified Paths:
--------------
trunk/JTreeMap/runConfs/JTreeMapAppletExample XML.launch
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTip.java
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTipBuilder.java
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/JTreeMap.java
trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/JTreeMapAppletExample.java
Modified: trunk/JTreeMap/runConfs/JTreeMapAppletExample XML.launch
===================================================================
--- trunk/JTreeMap/runConfs/JTreeMapAppletExample XML.launch 2006-12-11 20:34:41 UTC (rev 115)
+++ trunk/JTreeMap/runConfs/JTreeMapAppletExample XML.launch 2006-12-12 00:10:31 UTC (rev 116)
@@ -11,7 +11,10 @@
<mapAttribute key="org.eclipse.jdt.launching.APPLET_PARAMETERS">
<mapEntry key="dataFile" value="../../dataDump.xml"/>
<mapEntry key="viewTree" value="true"/>
+<mapEntry key="showWeight" value="true"/>
+<mapEntry key="valuePrefix" value="Value"/>
<mapEntry key="dataFileType" value="xml"/>
+<mapEntry key="weightPrefix" value="Weight"/>
</mapAttribute>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.5.0_09"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
Modified: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTip.java
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTip.java 2006-12-11 20:34:41 UTC (rev 115)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTip.java 2006-12-12 00:10:31 UTC (rev 116)
@@ -36,6 +36,7 @@
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
+import java.awt.Graphics2D;
import javax.swing.JToolTip;
@@ -58,15 +59,24 @@
private Font labelFont;
private Font valueFont;
-
+
+ private String weightPrefix;
+
+ private String valuePrefix;
+
+ private boolean showWeight;
+
/**
* Constructor.
*
* @param jTreeMap
* the jTreeMap who display the tooltip
*/
- public DefaultToolTip(final JTreeMap jTreeMap) {
+ public DefaultToolTip(final JTreeMap jTreeMap, final String weightPrefix, final String valuePrefix, final boolean showWeight) {
this.jTreeMap = jTreeMap;
+ this.weightPrefix = weightPrefix;
+ this.valuePrefix = valuePrefix;
+ this.showWeight = showWeight;
this.labelFont = new Font("Default", Font.BOLD, DEFAULT_LABEL_SIZE);
this.valueFont = new Font("Default", Font.PLAIN, DEFAULT_VALUE_SIZE);
@@ -81,13 +91,24 @@
@Override
public void paint(final 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(), TOOLTIP_OFFSET, g.getFontMetrics(this.labelFont).getAscent());
- g.setFont(this.valueFont);
- g.drawString(this.jTreeMap.getActiveLeaf().getLabelValue(), TOOLTIP_OFFSET, this.getHeight() - TOOLTIP_OFFSET);
+ Graphics2D g2D = (Graphics2D) g;
+ g2D.setColor(Color.YELLOW);
+ g2D.fill3DRect(0, 0, this.getWidth(), this.getHeight(), true);
+ g2D.setColor(Color.black);
+ g2D.setFont(this.labelFont);
+ g2D.drawString(this.jTreeMap.getActiveLeaf().getLabel(), TOOLTIP_OFFSET, g2D.getFontMetrics(this.labelFont).getAscent());
+ g2D.setFont(this.valueFont);
+ String toDraw = this.jTreeMap.getActiveLeaf().getLabelValue();
+ if (valuePrefix != null) {
+ toDraw = valuePrefix + " " + toDraw;
+ }
+ if (showWeight) {
+ toDraw = this.jTreeMap.getActiveLeaf().getWeight() + ", " + toDraw;
+ }
+ if (weightPrefix != null && showWeight) {
+ toDraw = weightPrefix + " " + toDraw;
+ }
+ g2D.drawString(toDraw, TOOLTIP_OFFSET, this.getHeight() - TOOLTIP_OFFSET);
}
}
}
Modified: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTipBuilder.java
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTipBuilder.java 2006-12-11 20:34:41 UTC (rev 115)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/DefaultToolTipBuilder.java 2006-12-12 00:10:31 UTC (rev 116)
@@ -53,14 +53,23 @@
private JTreeMap jTreeMap;
+ private String weightPrefix;
+
+ private String valuePrefix;
+
+ private boolean showWeight;
+
/**
* Constructor.
*
* @param jTreeMap
* the linked JTreeMap
*/
- public DefaultToolTipBuilder(final JTreeMap jTreeMap) {
+ public DefaultToolTipBuilder(final JTreeMap jTreeMap, final String weightPrefix, final String valuePrefix, final boolean showWeight) {
this.jTreeMap = jTreeMap;
+ this.weightPrefix = weightPrefix;
+ this.valuePrefix = valuePrefix;
+ this.showWeight = showWeight;
}
/*
@@ -70,7 +79,8 @@
*/
public JToolTip getToolTip() {
if (instance == null) {
- instance = new DefaultToolTip(this.jTreeMap);
+ instance = new DefaultToolTip(this.jTreeMap, this.weightPrefix,
+ this.valuePrefix, this.showWeight);
}
return instance;
}
Modified: trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/JTreeMap.java
===================================================================
--- trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/JTreeMap.java 2006-12-11 20:34:41 UTC (rev 115)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/JTreeMap.java 2006-12-12 00:10:31 UTC (rev 116)
@@ -117,7 +117,7 @@
* the root of the tree to display
*/
public JTreeMap(final TreeMapNode root) {
- this(root, new SplitSquarified());
+ this(root, new SplitSquarified(), null, null, false);
}
/**
@@ -131,7 +131,7 @@
* @param treeView The tree representation of the hierarchical data.
*/
public JTreeMap(final TreeMapNode root, final JTree treeView) {
- this(root, new SplitSquarified());
+ this(root, new SplitSquarified(), null, null, false);
this.treeView = treeView;
}
@@ -146,8 +146,9 @@
* the split strategy
* @param treeView The tree representation of the hierarchical data.
*/
- public JTreeMap(final TreeMapNode root, final SplitStrategy strategy, final JTree treeView) {
- this(root, strategy);
+ public JTreeMap(final TreeMapNode root, final SplitStrategy strategy, final JTree treeView,
+ final String weightPrefix, final String valuePrefix, final boolean showWeight) {
+ this(root, strategy, weightPrefix, valuePrefix, showWeight);
this.treeView = treeView;
}
/**
@@ -160,7 +161,8 @@
* @param strategy
* the split strategy
*/
- public JTreeMap(final TreeMapNode root, final SplitStrategy strategy) {
+ public JTreeMap(final TreeMapNode root, final SplitStrategy strategy,
+ final String weightPrefix, final String valuePrefix, final boolean showWeight) {
// ToolTips appears without delay and stay as long as possible
final ToolTipManager ttm = ToolTipManager.sharedInstance();
ttm.setInitialDelay(0);
@@ -171,7 +173,7 @@
setToolTipText("");
// the default DefaultToolTipBuilder
- toolTipBuilder = new DefaultToolTipBuilder(this);
+ toolTipBuilder = new DefaultToolTipBuilder(this, weightPrefix, valuePrefix, showWeight);
zoom = new Zoom();
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-12-11 20:34:41 UTC (rev 115)
+++ trunk/JTreeMap/src/main/java/net/sf/jtreemap/swing/example/JTreeMapAppletExample.java 2006-12-12 00:10:31 UTC (rev 116)
@@ -110,6 +110,12 @@
private boolean showTree;
+ private boolean showWeight;
+
+ private String weightPrefix;
+
+ private String valuePrefix;
+
private JTree treeView;
private DefaultTreeModel treeModel;
@@ -159,7 +165,7 @@
root = DemoUtil.buildDemoRoot();
}
- this.jTreeMap = new JTreeMap(root, new SplitBySortedWeight(), treeView);
+ this.jTreeMap = new JTreeMap(root, new SplitBySortedWeight(), treeView, weightPrefix, valuePrefix, showWeight);
this.jTreeMap.setFont(new Font(null, Font.BOLD, DEFAULT_FONT_SIZE));
final String colourProvider = getParameter("colorProvider");
@@ -340,6 +346,9 @@
this.setContentPane(getJContentPane());
showTM3CTonf = "true".equalsIgnoreCase(getParameter("showTM3Conf"));
showTree = "true".equalsIgnoreCase(getParameter("viewTree"));
+ showWeight = "true".equalsIgnoreCase(getParameter("showWeight"));
+ weightPrefix = getParameter("weightPrefix");
+ valuePrefix = getParameter("valuePrefix");
if (showTM3CTonf) {
addPanelEast(getJContentPane());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|