From 1431bc47695e73e7f91855ce5c487944c9a902ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Dr=C3=A4ger?= Date: Wed, 28 Apr 2010 07:32:10 +0000 Subject: [PATCH] Now a legend will display names for all elements if at least one of the pair color and label are different. --- src/eva2/gui/GraphPointSetLegend.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/eva2/gui/GraphPointSetLegend.java b/src/eva2/gui/GraphPointSetLegend.java index f013ed42..e040598a 100644 --- a/src/eva2/gui/GraphPointSetLegend.java +++ b/src/eva2/gui/GraphPointSetLegend.java @@ -33,21 +33,25 @@ public class GraphPointSetLegend { /** * * @author draeger - * + * */ private static class PairComp implements Comparator> { /* * (non-Javadoc) + * * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(Pair o1, Pair o2) { - return o1.car().compareTo(o2.car()); + int comp = o1.car().compareTo(o2.car()); + // Same text; let us see if the color is also identical. + return comp == 0 ? comp = Integer.valueOf(o1.cdr().getRGB()) + .compareTo(Integer.valueOf(o2.cdr().getRGB())) : comp; } - + } - - private static final PairComp comperator = new PairComp(); + + private static final PairComp comperator = new PairComp(); /** * @@ -167,8 +171,7 @@ public class GraphPointSetLegend { // System.out.println(legendEntries[i].toString() + "\tcontaines: " // + set.contains(legendEntries[i])); g.setColor(legendEntry.tail); - Rectangle2D stringBounds = fm.getStringBounds( - legendEntry.head, g); + Rectangle2D stringBounds = fm.getStringBounds(legendEntry.head, g); xOffs = (int) (maxX - stringBounds.getWidth() - 5); g.drawString(legendEntry.head, xOffs, yOffs); // g.drawString(legendEntries[i].head, 80, 80);