Example usage for java.awt Color getRGB

List of usage examples for java.awt Color getRGB

Introduction

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

Prototype

public int getRGB() 

Source Link

Document

Returns the RGB value representing the color in the default sRGB ColorModel .

Usage

From source file:org.geoserver.community.css.web.CssHandler.java

@Override
public String getStyle(StyleType type, Color color, String colorName, String layerName) {
    String template = TEMPLATES.get(type);
    String colorCode = Integer.toHexString(color.getRGB());
    colorCode = colorCode.substring(2, colorCode.length());
    return template.replace("${colorName}", colorName).replace("${colorCode}", "#" + colorCode)
            .replace("${layerName}", layerName);
}

From source file:net.dv8tion.jda.core.requests.restaction.RoleAction.java

/**
 * Sets the color which the new role should be displayed with.
 *
 * @param  color/*from  w  ww .ja v  a 2s  . co m*/
 *         An {@link java.awt.Color Color} for the new role, null to use default white/black
 *
 * @return The current RoleAction, for chaining convenience
 */
@CheckReturnValue
public RoleAction setColor(Color color) {
    return this.setColor(color != null ? color.getRGB() : null);
}

From source file:gr.iti.mklab.reveal.forensics.util.Util.java

public static BufferedImage visualizeWithJet(double[][] inputGrayImage) {
    // Take a [0,1] single-channel image and return a Jet visualization
    double[][] map = JetMap.colorMap;
    BufferedImage outIm = new BufferedImage(inputGrayImage.length, inputGrayImage[0].length, 5);
    Color rgb;
    byte bytevalue;
    for (int ii = 0; ii < inputGrayImage.length; ii++) {
        for (int jj = 0; jj < inputGrayImage[0].length; jj++) {
            bytevalue = (byte) Math.round(inputGrayImage[ii][jj] * 63);
            rgb = new Color((float) map[bytevalue][0], (float) map[bytevalue][1],
                    (float) map[(byte) Math.round(inputGrayImage[ii][jj]) * 63][2]);
            outIm.setRGB(ii, jj, rgb.getRGB());
        }/*from   w  w  w  .jav  a2 s .c  om*/
    }
    return outIm;
}

From source file:org.emonocot.portal.view.Functions.java

private static Map<String, String> getColorMap(Set<String> categories) {
    int numberOfCategories = categories.size();
    float increment = 0.5f / (numberOfCategories / 5);
    Map<String, String> colorMap = new HashMap<String, String>();

    int i = 0;/*from   w w  w . ja va 2s . c  o  m*/
    for (String category : categories) {
        Color baseColor = baseColors[i % 5];
        int offset = i / 5;
        if (offset > 0) {
            float hsbVals[] = Color.RGBtoHSB(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(),
                    null);
            Color highlight = Color.getHSBColor(hsbVals[0], hsbVals[1], offset * increment * (1f + hsbVals[2]));
            colorMap.put(category, String.format("#%06X", (0xFFFFFF & highlight.getRGB())));
        } else {
            colorMap.put(category, String.format("#%06X", (0xFFFFFF & baseColor.getRGB())));
        }
        i++;
    }

    return colorMap;
}

From source file:de.btobastian.javacord.utils.handler.server.role.GuildRoleUpdateHandler.java

@Override
public void handle(JSONObject packet) {
    String guildId = packet.getString("guild_id");
    JSONObject roleJson = packet.getJSONObject("role");

    Server server = api.getServerById(guildId);
    final ImplRole role = (ImplRole) server.getRoleById(roleJson.getString("id"));

    String name = roleJson.getString("name");
    if (!role.getName().equals(name)) {
        final String oldName = role.getName();
        role.setName(name);// ww w.  j  a v  a  2  s .com
        listenerExecutorService.submit(new Runnable() {
            @Override
            public void run() {
                List<RoleChangeNameListener> listeners = api.getListeners(RoleChangeNameListener.class);
                synchronized (listeners) {
                    for (RoleChangeNameListener listener : listeners) {
                        try {
                            listener.onRoleChangeName(api, role, oldName);
                        } catch (Throwable t) {
                            logger.warn("Uncaught exception in RoleChangeNameListener!", t);
                        }
                    }
                }
            }
        });
    }

    Permissions permissions = new ImplPermissions(roleJson.getInt("permissions"));
    if (!role.getPermissions().equals(permissions)) {
        final Permissions oldPermissions = role.getPermissions();
        role.setPermissions((ImplPermissions) permissions);
        listenerExecutorService.submit(new Runnable() {
            @Override
            public void run() {
                List<RoleChangePermissionsListener> listeners = api
                        .getListeners(RoleChangePermissionsListener.class);
                synchronized (listeners) {
                    for (RoleChangePermissionsListener listener : listeners) {
                        try {
                            listener.onRoleChangePermissions(api, role, oldPermissions);
                        } catch (Throwable t) {
                            logger.warn("Uncaught exception in RoleChangePermissionsListener!", t);
                        }
                    }
                }
            }
        });
    }

    Color color = new Color(roleJson.getInt("color"));
    if (role.getColor().getRGB() != color.getRGB()) {
        final Color oldColor = role.getColor();
        role.setColor(color);
        listenerExecutorService.submit(new Runnable() {
            @Override
            public void run() {
                List<RoleChangeColorListener> listeners = api.getListeners(RoleChangeColorListener.class);
                synchronized (listeners) {
                    for (RoleChangeColorListener listener : listeners) {
                        try {
                            listener.onRoleChangeColor(api, role, oldColor);
                        } catch (Throwable t) {
                            logger.warn("Uncaught exception in RoleChangeColorListener!", t);
                        }
                    }
                }
            }
        });
    }

    if (role.getHoist() != roleJson.getBoolean("hoist")) {
        role.setHoist(!role.getHoist());
        listenerExecutorService.submit(new Runnable() {
            @Override
            public void run() {
                List<RoleChangeHoistListener> listeners = api.getListeners(RoleChangeHoistListener.class);
                synchronized (listeners) {
                    for (RoleChangeHoistListener listener : listeners) {
                        try {
                            listener.onRoleChangeHoist(api, role, !role.getHoist());
                        } catch (Throwable t) {
                            logger.warn("Uncaught exception in RoleChangeHoistListener!", t);
                        }
                    }
                }
            }
        });
    }

    synchronized (Role.class) { // we don't want strange positions
        int position = roleJson.getInt("position");
        if (role.getPosition() != position) {
            final int oldPosition = role.getPosition();
            role.setPosition(position);
            listenerExecutorService.submit(new Runnable() {
                @Override
                public void run() {
                    List<RoleChangePositionListener> listeners = api
                            .getListeners(RoleChangePositionListener.class);
                    synchronized (listeners) {
                        for (RoleChangePositionListener listener : listeners) {
                            try {
                                listener.onRoleChangePosition(api, role, oldPosition);
                            } catch (Throwable t) {
                                logger.warn("Uncaught exception in RoleChangePositionListener!", t);
                            }
                        }
                    }
                }
            });
        }
    }
}

From source file:com.github.alexfalappa.nbspringboot.projects.initializr.InitializrProjectPanelVisual2.java

public InitializrProjectPanelVisual2() {
    initComponents();/*ww  w.  ja  v a 2 s  .  c o m*/
    // setup key listener on search field linked to dependencies panel
    FilterFieldListener ffl = new FilterFieldListener(pBootDependencies);
    txFilter.addKeyListener(ffl);
    txFilter.getDocument().addDocumentListener(ffl);
    // fix white area showing when the scroller is wider than the dependencies panel on some LAFs
    // for some reasons setting the UIManager color directly doesn't work it must be copied in a new Color object
    final Color cr = UIManager.getColor("Panel.background");
    scroller.getViewport().setBackground(new Color(cr.getRGB()));
}

From source file:org.yardstickframework.report.jfreechart.JFreeChartGraphPlotter.java

/**
 * @param folderToWrite Folder to write the resulted charts.
 * @param plots Collections of plots./*www.ja  v a  2 s.co  m*/
 * @param infoMap Map with additional plot info.
 * @param mode Generation mode.
 * @throws Exception If failed.
 */
private static void processPlots(File folderToWrite, Collection<List<PlotData>> plots,
        Map<String, List<JFreeChartPlotInfo>> infoMap, JFreeChartGenerationMode mode) throws Exception {
    ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

    int idx = -1;

    while (true) {
        idx++;

        DefaultXYDataset dataSet = new DefaultXYDataset();

        List<JFreeChartPlotInfo> infoList = new ArrayList<>();

        String xAxisLabel = "";
        String yAxisLabel = "";
        String plotName = "";

        int cnt = 0;

        for (List<PlotData> plotData0 : plots) {
            if (plotData0.size() <= idx)
                continue;

            PlotData plotData = plotData0.get(idx);

            dataSet.addSeries(plotData.plotName() + "_" + cnt++, plotData.series().data);

            xAxisLabel = plotData.xAxisLabel;
            yAxisLabel = plotData.yAxisLabel;
            plotName = plotData.plotName();

            infoList.add(info(plotData.series(), mode));
        }

        if (infoList.isEmpty())
            break;

        JFreeChart chart = ChartFactory.createXYLineChart("", xAxisLabel, yAxisLabel, dataSet,
                PlotOrientation.VERTICAL, false, false, false);

        AxisSpace as = new AxisSpace();

        as.add(150, RectangleEdge.LEFT);

        XYPlot plot = (XYPlot) chart.getPlot();

        BasicStroke stroke = new BasicStroke(1);

        plot.setRenderer(renderer);
        plot.setBackgroundPaint(WHITE);
        plot.setRangeGridlinePaint(GRAY);
        plot.setDomainGridlinePaint(GRAY);
        plot.setFixedRangeAxisSpace(as);
        plot.setOutlineStroke(stroke);

        for (int i = 0; i < infoList.size(); i++) {
            Color color = PLOT_COLORS[i % PLOT_COLORS.length];

            renderer.setSeriesPaint(i, color);
            renderer.setSeriesStroke(i, new BasicStroke(3)); // Line thickness.

            infoList.get(i).color(Integer.toHexString(color.getRGB()).substring(2));
        }

        ValueAxis axis = plot.getRangeAxis();

        Font font = new Font("Helvetica,Arial,sans-serif", Font.BOLD, axis.getTickLabelFont().getSize() + 5);

        axis.setTickLabelFont(font);
        axis.setLabelFont(font);
        plot.getDomainAxis().setTickLabelFont(font);
        plot.getDomainAxis().setLabelFont(font);

        chart.setTitle(new TextTitle(yAxisLabel, new Font(font.getName(), font.getStyle(), 30)));

        File res = new File(folderToWrite, plotName + ".png");

        ChartUtilities.saveChartAsPNG(res, chart, 1000, 500, info);

        infoMap.put(res.getAbsolutePath(), infoList);

        println("Chart is saved to file: ", res);
    }
}

From source file:org.gitools.analysis.clustering.hierarchical.HierarchicalClusterer.java

private Color nameClusters(List<HierarchicalCluster> children, int level) {

    if (children.isEmpty()) {
        return next();
    }//ww w . j  ava  2 s  .  c  o m

    int digits = calculateDigits(children.size());

    Collections.sort(children, Collections.reverseOrder());

    Color colorParent = null;
    Double weightParent = 0.0;
    for (int i = 0; i < children.size(); i++) {
        HierarchicalCluster child = children.get(i);
        if (child.getChildren().isEmpty()) {
            child.setName(JOINER.join(child.getIdentifiers()));
        } else {
            child.setName(child.getParentName() + createLabel(i, digits));
        }
        Color colorChild = nameClusters(child.getChildren(), level + 1);
        child.setColor(colorChild.getRGB());

        if (colorParent == null) {
            colorParent = colorChild;
            weightParent = (child.getChildren().isEmpty() ? 0.0 : child.getWeight());
        } else {
            colorParent = mixColors(colorParent, weightParent, colorChild, child.getWeight());
            weightParent += (child.getChildren().isEmpty() ? 0.0 : child.getWeight());
        }

    }

    if (level > 10) {
        return next();
    }

    return colorParent;

}

From source file:net.sf.mzmine.modules.visualization.twod.TwoDXYPlot.java

public boolean render(final Graphics2D g2, final Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {

    // if this is not TwoDDataSet
    if (index != 0)
        return super.render(g2, dataArea, index, info, crosshairState);

    // prepare some necessary constants
    final int x = (int) dataArea.getX();
    final int y = (int) dataArea.getY();
    final int width = (int) dataArea.getWidth();
    final int height = (int) dataArea.getHeight();

    final double imageRTMin = (double) getDomainAxis().getRange().getLowerBound();
    final double imageRTMax = (double) getDomainAxis().getRange().getUpperBound();
    final double imageRTStep = (imageRTMax - imageRTMin) / width;
    final double imageMZMin = (double) getRangeAxis().getRange().getLowerBound();
    final double imageMZMax = (double) getRangeAxis().getRange().getUpperBound();
    final double imageMZStep = (imageMZMax - imageMZMin) / height;

    if ((zoomOutBitmap != null) && (imageRTMin == totalRTRange.getMin())
            && (imageRTMax == totalRTRange.getMax()) && (imageMZMin == totalMZRange.getMin())
            && (imageMZMax == totalMZRange.getMax()) && (zoomOutBitmap.getWidth() == width)
            && (zoomOutBitmap.getHeight() == height)) {
        g2.drawImage(zoomOutBitmap, x, y, null);
        return true;
    }//from w  w  w  .j  a va2  s  .c om

    // Save current time
    Date renderStartTime = new Date();

    // prepare a double array of summed intensities
    double values[][] = new double[width][height];
    maxValue = 0; // now this is an instance variable
    Random r = new Random();

    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {

            double pointRTMin = imageRTMin + (i * imageRTStep);
            double pointRTMax = pointRTMin + imageRTStep;
            double pointMZMin = imageMZMin + (j * imageMZStep);
            double pointMZMax = pointMZMin + imageMZStep;

            double lv = dataset.getMaxIntensity(new Range(pointRTMin, pointRTMax),
                    new Range(pointMZMin, pointMZMax), plotMode);

            if (logScale) {
                lv = Math.log10(lv);
                if (lv < 0 || Double.isInfinite(lv))
                    lv = 0;
                values[i][j] = lv;
                //values[r.nextInt(width)][r.nextInt(height)] = lv;
            } else {
                values[i][j] = lv;
            }

            if (lv > maxValue)
                maxValue = lv;

        }

    // This should never happen, but just for correctness
    if (maxValue == 0)
        return false;

    // Normalize all values
    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            values[i][j] /= maxValue;
        }

    // prepare a bitmap of required size
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    // draw image points
    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            Color pointColor = paletteType.getColor(values[i][j]);
            image.setRGB(i, height - j - 1, pointColor.getRGB());
        }

    // if we are zoomed out, save the values
    if ((imageRTMin == totalRTRange.getMin()) && (imageRTMax == totalRTRange.getMax())
            && (imageMZMin == totalMZRange.getMin()) && (imageMZMax == totalMZRange.getMax())) {
        zoomOutBitmap = image;
    }

    // Paint image
    g2.drawImage(image, x, y, null);

    Date renderFinishTime = new Date();

    logger.finest("Finished rendering 2D visualizer, "
            + (renderFinishTime.getTime() - renderStartTime.getTime()) + " ms");

    return true;

}

From source file:net.dv8tion.jda.core.managers.RoleManagerUpdatable.java

protected void setupFields() {
    this.name = new RoleField<String>(this, role::getName) {
        @Override//from   w ww .j  a v a 2 s.c om
        public void checkValue(String value) {
            Checks.notNull(value, "name");
            if (value.isEmpty() || value.length() > 32)
                throw new IllegalArgumentException("Provided role name must be 1 to 32 characters in length");
        }
    };

    this.color = new RoleField<Color>(this, role::getColor) {
        @Override
        public RoleManagerUpdatable setValue(Color color) {
            if (color != null && color.getRGB() == 0)
                color = null;

            super.setValue(color);
            return manager;
        }

        @Override
        public void checkValue(Color value) {
        }
    };

    this.hoisted = new RoleField<Boolean>(this, role::isHoisted) {
        @Override
        public void checkValue(Boolean value) {
            Checks.notNull(value, "hoisted Boolean");
        }
    };

    this.mentionable = new RoleField<Boolean>(this, role::isMentionable) {
        @Override
        public void checkValue(Boolean value) {
            Checks.notNull(value, "mentionable Boolean");
        }
    };

    this.permissions = new PermissionField(this, role::getPermissionsRaw);
}