if i add legendpanel to another panel which has layout other than cardLayout (which is used in example). it does not draw all colors and does not draw max value label string as well. ?
can some one explain me why
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yes... HSBTreeMapColorProvider has the same issue.
following is the fix.
i found with text width of color bar becomes too narrow. so i changed Legend.WIDTH = 150 (original was 120)
instead of hard coding the X_INSET.. calculate like following.. that would fix the issue
FontMetrics fm = g.getFontMetrics();
int x_inset = fm.stringWidth(max.getLabel());
g.drawString(max.getLabel(), Legend.X + Legend.WIDTH - x_inset, Legend.Y - Y_INSET);
this works like charm..
i will checkout the latest code and test... (once i set up cvs on my work machine... can't do that from work machine)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
- private static final int WIDTH = 120;
+ private static final int WIDTH = 150;
private static final int X = 20;
@@ -386,11 +387,14 @@
}
final Value min = HSBTreeMapColorProvider.this.minValue;
final Value max = HSBTreeMapColorProvider.this.maxValue;
+ FontMetrics fm = g.getFontMetrics();
if i add legendpanel to another panel which has layout other than cardLayout (which is used in example). it does not draw all colors and does not draw max value label string as well. ?
can some one explain me why
there is the error in preferredsize calculation of RedGreenColorProvider. fixing that fixes this issue
in the constructor of legen()
replace existing code with this (just adding bracket ( ) then multiply by 2)
this.setPreferredSize(new java.awt.Dimension(
2 * (Legend.X + RedGreenColorProvider.this.tabColor.length * Legend.WIDTH), 2 * Legend.Y + Legend.HEIGHT));
while painting the max value instead of using (xCursor - 1) * Legend.WIDTH) .. use (xCursor - 2) * Legend.WIDTH
this fixes the issue of layout
Hi
Thanks for reporting this. I have applied your patches.
Benoit
could you checkout the latest code, compile it and check that it is ok.
Would you say that the HSBTreeMapColorProvider has the same problem?
At some point, I'd like to isolate the Legend generation through an interface...
Thanks
Benoit
yes... HSBTreeMapColorProvider has the same issue.
following is the fix.
i found with text width of color bar becomes too narrow. so i changed Legend.WIDTH = 150 (original was 120)
instead of hard coding the X_INSET.. calculate like following.. that would fix the issue
FontMetrics fm = g.getFontMetrics();
int x_inset = fm.stringWidth(max.getLabel());
g.drawString(max.getLabel(), Legend.X + Legend.WIDTH - x_inset, Legend.Y - Y_INSET);
this works like charm..
i will checkout the latest code and test... (once i set up cvs on my work machine... can't do that from work machine)
Thanks Janu25 for doing all this.
Could I ask you to make the modification locally and send me a patch (svn patch) so that I can see exactly what has changed.
Thanks
B
sure.. but that i can do during weekend. so i can provide you early next week. (need to do that from home machine)
ok i created the patch for HSBColorProvider. how do i give it to you, just copy and paste here in forum.. or how do i attach the file here ..?
Hi
You can attach here but do specify in details what the changes are and whether the changes should be in other providers.
Many thanks
B
import java.awt.Color;
+import java.awt.FontMetrics;
import java.awt.Graphics;
import java.util.Enumeration;
@@ -364,7 +365,7 @@
private static final int HEIGHT = 20;
- private static final int WIDTH = 120;
+ private static final int WIDTH = 150;
private static final int X = 20;
@@ -386,11 +387,14 @@
}
final Value min = HSBTreeMapColorProvider.this.minValue;
final Value max = HSBTreeMapColorProvider.this.maxValue;
+ FontMetrics fm = g.getFontMetrics();
g.setColor(Color.black);
if (min != null && max != null) {
g.drawString(min.getLabel(), Legend.X - X_INSET, Legend.Y - Y_INSET);
- g.drawString(max.getLabel(), Legend.X + Legend.WIDTH - X_INSET, Legend.Y - Y_INSET);
+ int x_inset = fm.stringWidth(max.getLabel());
+ //g.drawString(max.getLabel(), Legend.X + Legend.WIDTH - X_INSET, Legend.Y - Y_INSET); // original
+ g.drawString(max.getLabel(), Legend.X + Legend.WIDTH - x_inset, Legend.Y - Y_INSET);
final double step = (max.getValue() - min.getValue()) / Legend.WIDTH;
final Value value = new DefaultValue(min.getValue());
Hi
This does not tell me which class you have changed...
please email me the file (see my profile for email address)
Thanks
B
that was patch for HSBTreeMapColorProvider. whatever changes you make in RedGreenColorProvider is fine and working (i checked from SVN copy)
i didn't test other providers, since we are not using those.. i didnt bother to strudy :(
let me know if this works.