Example usage for java.awt Color getHSBColor

List of usage examples for java.awt Color getHSBColor

Introduction

In this page you can find the example usage for java.awt Color getHSBColor.

Prototype

public static Color getHSBColor(float h, float s, float b) 

Source Link

Document

Creates a Color object based on the specified values for the HSB color model.

Usage

From source file:edu.umn.cs.spatialHadoop.nasa.HDFRasterLayer.java

protected Color calculateColor(float value, float minValue, float maxValue) {
    Color color;//from ww w .  j  a  v a  2  s  . c  om
    if (value < minValue) {
        color = colors[0];
    } else if (value > maxValue) {
        color = colors[1];
    } else {
        // Interpolate between two colors according to gradient type
        float ratio = (value - minValue) / (maxValue - minValue);
        if (gradientType == GradientType.GT_HSB) {
            // Interpolate between two hues
            float hue = hues[0] * (1.0f - ratio) + hues[1] * ratio;
            float saturation = saturations[0] * (1.0f - ratio) + saturations[1] * ratio;
            float brightness = brightnesses[0] * (1.0f - ratio) + brightnesses[1] * ratio;
            color = Color.getHSBColor(hue, saturation, brightness);
            int alpha = (int) (colors[0].getAlpha() * (1.0f - ratio) + colors[1].getAlpha() * ratio);
            color = new Color(color.getRGB() & 0xffffff | (alpha << 24), true);
        } else if (gradientType == GradientType.GT_RGB) {
            // Interpolate between colors
            int red = (int) (colors[0].getRed() * (1.0f - ratio) + colors[1].getRed() * ratio);
            int green = (int) (colors[0].getGreen() * (1.0f - ratio) + colors[1].getGreen() * ratio);
            int blue = (int) (colors[0].getBlue() * (1.0f - ratio) + colors[1].getBlue() * ratio);
            int alpha = (int) (colors[0].getAlpha() * (1.0f - ratio) + colors[1].getAlpha() * ratio);
            color = new Color(red, green, blue, alpha);
        } else {
            throw new RuntimeException("Unsupported gradient type: " + gradientType);
        }
    }
    return color;
}

From source file:gui.GraphsPanel.java

/** TODO: re-implement the algorithm from vertexColor.
 * Vertice Coloring algorithm executed before the vertexColor Transformer is
 * called//  w w w.  j av a2 s .co m
 * TV same algorithm initially set as a vertexColor Transformer COPY FROM
 * PROCESSCLUSTERRESULTS
 */
public void colorizeTree(TreeNode root, float threshold) {
    // System.out.println("___GraphsPanel: COLORIZE TREE!");
    Color customColor = Color.WHITE;

    // int groupCount =
    // cluster.getAvLnkDendrogram().getGroupCount(threshold);
    // int counter = groupCount;

    // traverese the tree
    // Enumeration en =
    // ((DefaultMutableTreeNode)root).depthFirstEnumeration();
    @SuppressWarnings("unchecked")
    Enumeration<DefaultMutableTreeNode> en = ((DefaultMutableTreeNode) root).breadthFirstEnumeration();
    while (en.hasMoreElements()) {
        // Unfortunately the enumeration isn't genericised so we need to
        // downcast
        // when calling nextElement():
        DefaultMutableTreeNode node = en.nextElement();
        DenNode dNode = (DenNode) node.getUserObject();
        Integer level = node.getLevel();

        if (level == 0) {
            dNode.setColor(customColor);
        } else if (level != 0) {
            DenNode pdNode = (DenNode) ((DefaultMutableTreeNode) (node.getParent())).getUserObject();
            if ((dNode.getSimilarity() > threshold) && (pdNode.getColor().equals(Color.WHITE))) {
                dNode.setColor(
                        Color.getHSBColor((float) (Math.cos(dNode.getSimilarity() * 90) * 360), 0.8f, 0.8f));
            } else {
                dNode.setColor(pdNode.getColor());
            }
            // TV
            if (((dNode.getSimilarity() - pdNode.getSimilarity()) > this.getSensitivity())) {
                dNode.setEdgeColor(Color.BLACK);
            }
        }
    }
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

private Color getTopLight(Color primary) {
    float hsbVals[] = new float[3];
    Color.RGBtoHSB(primary.getRed(), primary.getGreen(), primary.getBlue(), hsbVals);
    hsbVals[1] = 0.3f;//  w w  w  .ja  v  a 2 s  .c o m
    hsbVals[2] = 0.97f;
    return Color.getHSBColor(hsbVals[0], hsbVals[1], hsbVals[2]);
}

From source file:edu.umn.cs.spatialHadoop.operations.Plot.java

public static void drawShape(Graphics2D graphics, Shape s, Rectangle fileMbr, int imageWidth, int imageHeight,
        double scale) {
    if (s instanceof NASAPoint) {
        final int MinValue = 7500;
        final int MaxValue = 16000;
        NASAPoint pt = (NASAPoint) s;/* w  w  w .j  a  v  a  2  s .  c  om*/
        int x = (int) ((pt.x - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1));
        int y = (int) ((pt.y - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1));
        int value = pt.value;

        if (value < min_value && value > 1000)
            min_value = value;
        if (value > max_value)
            max_value = value;

        if (value > 0 && x >= 0 && x < imageWidth && y >= 0 && y < imageHeight) {
            Color color;
            if (value < MinValue) {
                color = Color.BLACK;
            } else if (value < MaxValue) {
                float ratio = 0.78f - 0.78f * (value - MinValue) / (MaxValue - MinValue);
                color = Color.getHSBColor(ratio, 0.5f, 1.0f);
            } else {
                color = Color.WHITE;
            }
            graphics.setColor(color);
            graphics.fillRect(x, y, 1, 1);
        }
    } else if (s instanceof Point) {
        Point pt = (Point) s;
        int x = (int) ((pt.x - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1));
        int y = (int) ((pt.y - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1));

        if (x >= 0 && x < imageWidth && y >= 0 && y < imageHeight)
            graphics.fillRect(x, y, 1, 1);
    } else if (s instanceof Rectangle) {
        Rectangle r = (Rectangle) s;
        int s_x1 = (int) ((r.x1 - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1));
        int s_y1 = (int) ((r.y1 - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1));
        int s_x2 = (int) (((r.x2) - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1));
        int s_y2 = (int) (((r.y2) - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1));
        graphics.drawRect(s_x1, s_y1, s_x2 - s_x1 + 1, s_y2 - s_y1 + 1);
    } else if (s instanceof OGCShape) {
        OGCShape ogc_shape = (OGCShape) s;
        OGCGeometry geom = ogc_shape.geom;
        Color shape_color = graphics.getColor();
        if (geom instanceof OGCGeometryCollection) {
            OGCGeometryCollection geom_coll = (OGCGeometryCollection) geom;
            for (int i = 0; i < geom_coll.numGeometries(); i++) {
                OGCGeometry sub_geom = geom_coll.geometryN(i);
                // Recursive call to draw each geometry
                drawShape(graphics, new OGCShape(sub_geom), fileMbr, imageWidth, imageHeight, scale);
            }
        } else if (geom.getEsriGeometry() instanceof MultiPath) {
            MultiPath path = (MultiPath) geom.getEsriGeometry();
            double sub_geom_alpha = path.calculateLength2D() * scale;
            int color_alpha = sub_geom_alpha > 1.0 ? 255 : (int) Math.round(sub_geom_alpha * 255);

            if (color_alpha == 0)
                return;

            int[] xpoints = new int[path.getPointCount()];
            int[] ypoints = new int[path.getPointCount()];

            for (int i = 0; i < path.getPointCount(); i++) {
                double px = path.getPoint(i).getX();
                double py = path.getPoint(i).getY();

                // Transform a point in the polygon to image coordinates
                xpoints[i] = (int) Math.round((px - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1));
                ypoints[i] = (int) Math.round((py - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1));
            }

            // Draw the polygon
            graphics.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true));
            if (path instanceof Polygon)
                graphics.drawPolygon(xpoints, ypoints, path.getPointCount());
            else if (path instanceof Polyline)
                graphics.drawPolyline(xpoints, ypoints, path.getPointCount());
        }
    } else if (s instanceof JTSShape) {
        JTSShape jts_shape = (JTSShape) s;
        Geometry geom = jts_shape.geom;
        Color shape_color = graphics.getColor();

        drawJTSShape(graphics, geom, fileMbr, imageWidth, imageHeight, scale, shape_color);
    } else {
        LOG.warn("Cannot draw a shape of type: " + s.getClass());
        Rectangle r = s.getMBR();
        int s_x1 = (int) ((r.x1 - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1));
        int s_y1 = (int) ((r.y1 - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1));
        int s_x2 = (int) (((r.x2) - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1));
        int s_y2 = (int) (((r.y2) - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1));
        if (s_x1 >= 0 && s_x1 < imageWidth && s_y1 >= 0 && s_y1 < imageHeight)
            graphics.drawRect(s_x1, s_y1, s_x2 - s_x1 + 1, s_y2 - s_y1 + 1);
    }
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

private Color getTopDark(Color primary) {
    float hsbVals[] = new float[3];
    Color.RGBtoHSB(primary.getRed(), primary.getGreen(), primary.getBlue(), hsbVals);
    hsbVals[1] = 0.9f;//w  w w.j  ava2 s . co m
    hsbVals[2] = 0.6f;
    return Color.getHSBColor(hsbVals[0], hsbVals[1], hsbVals[2]);
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

private Color getFrontDark(Color primary) {
    float hsbVals[] = new float[3];
    Color.RGBtoHSB(primary.getRed(), primary.getGreen(), primary.getBlue(), hsbVals);
    hsbVals[1] = 1.0f;/*from   w  w w  . j a v a 2s  .c o m*/
    hsbVals[2] = 0.5f;
    return Color.getHSBColor(hsbVals[0], hsbVals[1], hsbVals[2]);
}

From source file:gui.GraphsPanel.java

/** detectWeakEdges().
 * //  w  ww. ja v  a 2  s. co  m
 */
public void detectWeakEdges(TreeNode root, float sensitivity) {
    Color customColor = Color.WHITE;

    // TV get a snapshot of original colors for each node with singleton
    Color prevColor = null;

    @SuppressWarnings("unchecked")
    Enumeration<DefaultMutableTreeNode> en = ((DefaultMutableTreeNode) root).breadthFirstEnumeration();
    while (en.hasMoreElements()) {
        DefaultMutableTreeNode node = en.nextElement();
        DenNode dNode = (DenNode) node.getUserObject();
        Integer level = node.getLevel();

        if (prevColor == null) {
            prevColor = dNode.getColor();
        }

        if (level == 0) {
            dNode.setColor(customColor);
        } else if (level != 0) {
            DenNode pdNode = (DenNode) ((DefaultMutableTreeNode) (node.getParent())).getUserObject();
            if ((dNode.getSimilarity() > this.getThreshold()) && (pdNode.getColor().equals(Color.WHITE))) {
                dNode.setColor(
                        Color.getHSBColor((float) (Math.cos(dNode.getSimilarity() * 90) * 360), 0.8f, 0.8f));
            } else {
                dNode.setColor(pdNode.getColor());
            }
            dNode.resetEdgeColor();
            if (((dNode.getSimilarity() - pdNode.getSimilarity()) > sensitivity)) {
                dNode.setEdgeColor(Color.RED);
            }
        }
    }
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

private Color getSideLight(Color primary) {
    float hsbVals[] = new float[3];
    Color.RGBtoHSB(primary.getRed(), primary.getGreen(), primary.getBlue(), hsbVals);
    hsbVals[1] = .6f;//  ww  w .  java 2s  .com
    hsbVals[2] = 0.6f;
    return Color.getHSBColor(hsbVals[0], hsbVals[1], hsbVals[2]);
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

private Color getSideDark(Color primary) {
    float hsbVals[] = new float[3];
    Color.RGBtoHSB(primary.getRed(), primary.getGreen(), primary.getBlue(), hsbVals);
    hsbVals[1] = 1.0f;//from  www .j  a va 2  s.c  o m
    hsbVals[2] = 0.3f;
    return Color.getHSBColor(hsbVals[0], hsbVals[1], hsbVals[2]);
}

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

private static Color[] generateJetSpectrum(int n) {
    Color[] colors = new Color[n];
    for (int i = 0; i < n; i++) {
        colors[i] = Color.getHSBColor(-(0.75f * i / n + 0.3f), 0.85f, 1.0f);
    }//  www.  j  a  v a2  s.  c  o  m
    return colors;
}