+
+ /**
+ * update comp using rendering settings from gcol
+ *
+ * @param comp
+ * @param gcol
+ */
+ public static void renderGraduatedColor(JLabel comp, GraduatedColor gcol)
+ {
+ int w = comp.getWidth(), h = comp.getHeight();
+ if (w < 20)
+ {
+ w = (int) comp.getPreferredSize().getWidth();
+ h = (int) comp.getPreferredSize().getHeight();
+ if (w < 20)
+ {
+ w = 80;
+ h = 12;
+ }
+ }
+ renderGraduatedColor(comp, gcol, w, h);
+ }
+
+ public static void renderGraduatedColor(JLabel comp, GraduatedColor gcol,
+ int w, int h)
+ {
+ boolean thr = false;
+ String tt = "";
+ String tx = "";
+ if (gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD)
+ {
+ thr = true;
+ tx += ">";
+ tt += "Thresholded (Above " + gcol.getThresh() + ") ";
+ }
+ if (gcol.getThreshType() == AnnotationColourGradient.BELOW_THRESHOLD)
+ {
+ thr = true;
+ tx += "<";
+ tt += "Thresholded (Below " + gcol.getThresh() + ") ";
+ }
+ if (gcol.isColourByLabel())
+ {
+ tt = "Coloured by label text. " + tt;
+ if (thr)
+ {
+ tx += " ";
+ }
+ tx += "Label";
+ comp.setIcon(null);
+ }
+ else
+ {
+ Color newColor = gcol.getMaxColor();
+ comp.setBackground(newColor);
+ // System.err.println("Width is " + w / 2);
+ Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr);
+ comp.setIcon(ficon);
+ // tt+="RGB value: Max (" + newColor.getRed() + ", "
+ // + newColor.getGreen() + ", " + newColor.getBlue()
+ // + ")\nMin (" + minCol.getRed() + ", " + minCol.getGreen()
+ // + ", " + minCol.getBlue() + ")");
+ }
+ comp.setHorizontalAlignment(SwingConstants.CENTER);
+ comp.setText(tx);
+ if (tt.length() > 0)
+ {
+ if (comp.getToolTipText() == null)
+ {
+ comp.setToolTipText(tt);
+ }
+ else
+ {
+ comp.setToolTipText(tt + " " + comp.getToolTipText());
+ }
+ }
+ }
+}
+
+class FeatureIcon implements Icon
+{
+ GraduatedColor gcol;
+
+ Color backg;
+
+ boolean midspace = false;
+
+ int width = 50, height = 20;
+
+ int s1, e1; // start and end of midpoint band for thresholded symbol
+
+ Color mpcolour = Color.white;
+
+ FeatureIcon(GraduatedColor gfc, Color bg, int w, int h, boolean mspace)
+ {
+ gcol = gfc;
+ backg = bg;
+ width = w;
+ height = h;
+ midspace = mspace;
+ if (midspace)
+ {
+ s1 = width / 3;
+ e1 = s1 * 2;
+ }
+ else
+ {
+ s1 = width / 2;
+ e1 = s1;
+ }
+ }
+
+ public int getIconWidth()
+ {
+ return width;
+ }
+
+ public int getIconHeight()
+ {
+ return height;
+ }
+
+ public void paintIcon(Component c, Graphics g, int x, int y)
+ {
+
+ if (gcol.isColourByLabel())
+ {
+ g.setColor(backg);
+ g.fillRect(0, 0, width, height);
+ // need an icon here.
+ g.setColor(gcol.getMaxColor());
+
+ g.setFont(new Font("Verdana", Font.PLAIN, 9));
+
+ // g.setFont(g.getFont().deriveFont(
+ // AffineTransform.getScaleInstance(
+ // width/g.getFontMetrics().stringWidth("Label"),
+ // height/g.getFontMetrics().getHeight())));
+
+ g.drawString(MessageManager.getString("label.label"), 0, 0);
+
+ }
+ else
+ {
+ Color minCol = gcol.getMinColor();
+ g.setColor(minCol);
+ g.fillRect(0, 0, s1, height);
+ if (midspace)
+ {
+ g.setColor(Color.white);
+ g.fillRect(s1, 0, e1 - s1, height);
+ }
+ g.setColor(gcol.getMaxColor());
+ g.fillRect(0, e1, width - e1, height);
+ }
+ }