Example usage for java.awt Color getRGBColorComponents

List of usage examples for java.awt Color getRGBColorComponents

Introduction

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

Prototype

public float[] getRGBColorComponents(float[] compArray) 

Source Link

Document

Returns a float array containing only the color components of the Color , in the default sRGB color space.

Usage

From source file:org.apache.pdfbox.pdmodel.fdf.FDFAnnotationPolygon.java

/**
 * This will set interior color of the drawn area.
 *
 * @param color The interior color of the drawn area.
 *///  w  ww  .  j a  v  a  2  s.  c  om
public void setInteriorColor(Color color) {
    COSArray array = null;
    if (color != null) {
        float[] colors = color.getRGBColorComponents(null);
        array = new COSArray();
        array.setFloatArray(colors);
    }
    annot.setItem(COSName.IC, array);
}

From source file:org.webcurator.ui.admin.controller.CreateFlagController.java

/**
 *  Convert a RGB Color to it corresponding HSL values.
 *
 *  @return an array containing the 3 HSL values.
 *///from   ww w  .  ja  v a  2 s .com
public static float[] fromRGB(Color color) {
    //  Get RGB values in the range 0 - 1

    float[] rgb = color.getRGBColorComponents(null);
    float r = rgb[0];
    float g = rgb[1];
    float b = rgb[2];

    //   Minimum and Maximum RGB values are used in the HSL calculations

    float min = Math.min(r, Math.min(g, b));
    float max = Math.max(r, Math.max(g, b));

    //  Calculate the Hue

    float h = 0;

    if (max == min)
        h = 0;
    else if (max == r)
        h = ((60 * (g - b) / (max - min)) + 360) % 360;
    else if (max == g)
        h = (60 * (b - r) / (max - min)) + 120;
    else if (max == b)
        h = (60 * (r - g) / (max - min)) + 240;

    //  Calculate the Luminance

    float l = (max + min) / 2;
    //System.out.println(max + " : " + min + " : " + l);

    //  Calculate the Saturation

    float s = 0;

    if (max == min)
        s = 0;
    else if (l <= .5f)
        s = (max - min) / (max + min);
    else
        s = (max - min) / (2 - max - min);

    return new float[] { h, s * 100, l * 100 };
}

From source file:repast.simphony.visualization.gui.styleBuilder.EditedStyleDialog.java

private void fontColorButtonActionPerformed(ActionEvent e) {
    float labelColor[] = userStyleData.getLabelColor();
    Color labelPaint = new Color(labelColor[0], labelColor[1], labelColor[2]);

    Color color = JColorChooser.showDialog(EditedStyleDialog.this, "Choose a Font Color", labelPaint);
    if (color != null) {
        userStyleData.setLabelColor(color.getRGBColorComponents(null));
        fontColorButton.setIcon(new SquareIcon(14, 14, color));
        preview.setEditorFontColor(color);
    }//w ww . j  a  v a 2 s . com
}

From source file:repast.simphony.visualization.gui.styleBuilder.EditedStyleDialog.java

private void iconColorbuttonActionPerformed(ActionEvent e) {
    float iconColor[] = userStyleData.getColor();
    Color iconPaint = new Color(iconColor[0], iconColor[1], iconColor[2]);

    Color color = JColorChooser.showDialog(EditedStyleDialog.this, "Choose an Icon Color", iconPaint);
    if (color != null) {
        float col[] = color.getRGBColorComponents(null);
        userStyleData.setColor(col);//  w ww.  j  a v a2s  .  c  o m
        userStyleData.setRedMethod(null);
        userStyleData.setGreenMethod(null);
        userStyleData.setBlueMethod(null);
        variableIconRedColorValueModel.addElement(col[0]);
        variableIconGreenColorValueModel.addElement(col[1]);
        variableIconBlueColorValueModel.addElement(col[2]);
        variableIconRedColorValueModel.setSelectedItem(col[0]);
        variableIconGreenColorValueModel.setSelectedItem(col[1]);
        variableIconBlueColorValueModel.setSelectedItem(col[2]);

        iconColorbutton.setIcon(new SquareIcon(14, 14, color));
        preview.setFillColor(color);
    }
}

From source file:uk.ac.ncl.aries.entanglement.cli.export.MongoGraphToGephi.java

public void exportGexf(File outputFile) throws IOException, GraphModelException, RevisionLogException {
    //Load colour mappings, if any
    Map<String, Color> nodeColorMappings = new HashMap<>();
    if (colorPropsFile != null) {
        nodeColorMappings.putAll(loadColorMappings(colorPropsFile));
    }/*from  w ww  . j a va2s  . com*/

    // Init a gephi project - and therefore a workspace
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    pc.newProject();
    Workspace workspace = pc.getCurrentWorkspace();

    // Get a graph model - it exists because we have a workspace
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel();

    // Create a directed graph based on this graph model
    DirectedGraph directedGraph = graphModel.getDirectedGraph();
    // Add column for node type
    AttributeController ac = Lookup.getDefault().lookup(AttributeController.class);
    AttributeModel attributeModel = ac.getModel();

    //        AttributeColumn nodeTypeCol = attributeModel.getNodeTable().addColumn(
    //                "nodeType",
    //                AttributeType.STRING );

    Map<String, AttributeColumn> nodeAttrNameToAttributeCol = new HashMap<>();

    // Create Gephi nodes
    //        Iterable<Node> nodeItr = new DeserialisingIterable<>(nodeDao.iterateAll(), marshaller, Node.class);
    //        for (Node node : nodeItr) {
    for (DBObject node : nodeDao.iterateAll()) {
        String uidStr = (String) node.get(NodeDAO.FIELD_UID);
        String name = (String) node.get(NodeDAO.FIELD_NAME);
        String type = (String) node.get(NodeDAO.FIELD_TYPE);
        Color nodeColour = DEFAULT_COLOR;
        if (nodeColorMappings.containsKey(type)) {
            nodeColour = nodeColorMappings.get(type);
        }

        org.gephi.graph.api.Node gephiNode = graphModel.factory().newNode(uidStr);
        if (name == null || name.isEmpty()) {
            gephiNode.getNodeData().setLabel(uidStr);
        } else {
            gephiNode.getNodeData().setLabel(name);
        }
        float[] rgbColorComp = nodeColour.getRGBColorComponents(null);
        gephiNode.getNodeData().setColor(rgbColorComp[0], rgbColorComp[1], rgbColorComp[2]);
        //      gephiNode.getNodeData().setColor(nodeColour.getRed(), nodeColour.
        //              getGreen(), nodeColour.getBlue());
        //            gephiNode.getNodeData().getAttributes().setValue( nodeTypeCol.getIndex(), node.getType() );

        for (String nodeAttrName : node.keySet()) {
            Object val = node.get(nodeAttrName);
            if (nodeAttrName.equals("_id")) {
                continue;
            }
            if (val instanceof BasicDBList) {
                val = val.toString();
            }
            if (val == null) {
                continue;
            }
            AttributeColumn attrCol = nodeAttrNameToAttributeCol.get(nodeAttrName);
            if (attrCol == null) {
                attrCol = attributeModel.getNodeTable().addColumn(nodeAttrName, AttributeType.parse(val));
                nodeAttrNameToAttributeCol.put(nodeAttrName, attrCol);
            }
            //        logger.info("nodeAttrName: " + nodeAttrName + ", val: " + val + ", type: " + val.getClass().getName());
            //        logger.info("attrCol: " + attrCol);
            gephiNode.getNodeData().getAttributes().setValue(attrCol.getIndex(), val);
        }

        directedGraph.addNode(gephiNode);
    }

    // Create Gephi edges; currently with a standard weight of 1
    // and no set color
    Iterable<Edge> edgeItr = new DeserialisingIterable<>(edgeDao.iterateAll(), marshaller, Edge.class);
    for (Edge edge : edgeItr) {
        String fromUidStr = edge.getFromUid();
        String toUidStr = edge.getToUid();
        org.gephi.graph.api.Edge gephiEdge = graphModel.factory().newEdge(directedGraph.getNode(fromUidStr),
                directedGraph.getNode(toUidStr), 1f, true);
        gephiEdge.getEdgeData().setLabel(edge.getType());
        directedGraph.addEdge(gephiEdge);
    }

    // Print out a summary of the full graph
    System.out.println("Complete Nodes: " + directedGraph.getNodeCount() + " Complete Edges: "
            + directedGraph.getEdgeCount());

    // This line is a hack to get around a weird NullPointerException
    // which crops up when exporting to gexf. See url below for details:
    // https://forum.gephi.org/viewtopic.php?f=27&t=2337
    DynamicModel dynamicModel = Lookup.getDefault().lookup(DynamicController.class).getModel();

    // Export full graph in GEXF format
    ExportController ec = Lookup.getDefault().lookup(ExportController.class);
    System.out.println(outputFile.getAbsoluteFile());
    ec.exportFile(outputFile);

}