Example usage for java.awt Color getBlue

List of usage examples for java.awt Color getBlue

Introduction

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

Prototype

public int getBlue() 

Source Link

Document

Returns the blue component in the range 0-255 in the default sRGB space.

Usage

From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java

/**
 * Returns the paint used to fill data items as they are drawn.
 * <p/>//from   w w  w .j  a  v a  2 s  .  c o  m
 * The default implementation passes control to the
 * <code>lookupSeriesPaint()</code> method. You can override this method
 * if you require different behaviour.
 *
 * @param row    the row (or series) index (zero-based).
 * @param column the column (or category) index (zero-based).
 * @return The paint (never <code>null</code>).
 */
@Override
public Paint getItemPaint(int row, int column) {
    Color paint = dataset.getColor(row, column);

    if (paint == null) {
        paint = DEFAULT_COLOR;
    }

    if (shouldHighlight(row, column)) {
        return new Color(paint.getRed(), paint.getGreen(), paint.getBlue(), 255);
    }

    return new Color(paint.getRed(), paint.getGreen(), paint.getBlue(), 127);
}

From source file:com.jaspersoft.studio.property.color.chooser.AdvancedColorWidget.java

/**
 * Read the color under the mouse position and set it as the current color. This 
 * is done only if JSS or one of its components are focused. It is necessary to control
 * this dialog and its content because it modal, so every other component of JSS can not be focused
 *///from   w w  w . j a  v a 2  s. c o  m
private void checkColorPicker() {
    if (!isDisposed() && (getShell().isFocusControl() || checkControlFocused(getShell().getChildren()))) {
        Robot robot;
        try {
            robot = new Robot();
            Point pos = Display.getCurrent().getCursorLocation();
            java.awt.Color color = robot.getPixelColor(pos.x, pos.y);
            RGB rgbColor = new RGB(color.getRed(), color.getGreen(), color.getBlue());
            colorsSelector.setSelectedColor(rgbColor, false);
            updateText(rgbColor, rgbColor.getHSB(), null);
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.kurento.kmf.test.client.BrowserClient.java

public boolean colorSimilarTo(Color expectedColor) {
    String[] realColor = driver.findElement(By.id("color")).getAttribute("value").split(",");
    int red = Integer.parseInt(realColor[0]);
    int green = Integer.parseInt(realColor[1]);
    int blue = Integer.parseInt(realColor[2]);

    double distance = Math.sqrt((red - expectedColor.getRed()) * (red - expectedColor.getRed())
            + (green - expectedColor.getGreen()) * (green - expectedColor.getGreen())
            + (blue - expectedColor.getBlue()) * (blue - expectedColor.getBlue()));

    log.info("Color comparision: real {}, expected {}, distance {}", realColor, expectedColor, distance);

    return distance <= getMaxDistance();
}

From source file:TableDialogEditDemo.java

public Component getTableCellRendererComponent(JTable table, Object color, boolean isSelected, boolean hasFocus,
        int row, int column) {
    Color newColor = (Color) color;
    setBackground(newColor);/*from   w w  w .j a va  2 s .  c  o  m*/
    if (isBordered) {
        if (isSelected) {
            if (selectedBorder == null) {
                selectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5, table.getSelectionBackground());
            }
            setBorder(selectedBorder);
        } else {
            if (unselectedBorder == null) {
                unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5, table.getBackground());
            }
            setBorder(unselectedBorder);
        }
    }

    setToolTipText("RGB value: " + newColor.getRed() + ", " + newColor.getGreen() + ", " + newColor.getBlue());
    return this;
}

From source file:org.mrgeo.colorscale.ColorScale.java

/**
 * Interpolate the color value for the given scalar value. The result is placed in color.
 *
 * @param v/*w  w  w  .  j  a va  2  s .  c  o m*/
 * @param color
 * @return
 */
final private void interpolateValue(final double v, final int[] color) {
    final double search;
    switch (scaling) {
    case Absolute:
        search = v;
        break;
    case MinMax:
        search = (v - min) / (max - min);
        break;
    case Modulo:
        search = (v - min) % (max - min);
        break;
    default:
        search = 0;
        break;
    }

    final Map.Entry<Double, Color> lower = floorEntry(search);
    final Map.Entry<Double, Color> upper = higherEntry(search);

    assert (upper != null || lower != null);

    if (upper == null) {
        final Color c = lower.getValue();
        color[R] = c.getRed();
        color[G] = c.getGreen();
        color[B] = c.getBlue();
        color[A] = c.getAlpha();
    } else if (lower == null) {
        final Color c = upper.getValue();
        color[R] = c.getRed();
        color[G] = c.getGreen();
        color[B] = c.getBlue();
        color[A] = c.getAlpha();
    } else {
        final double diff = upper.getKey().doubleValue() - lower.getKey().doubleValue();
        final double lw = 1.0 - ((search - lower.getKey().doubleValue()) / diff);
        final double uw = 1.0 - lw;

        final Color lc = lower.getValue();
        final Color uc = upper.getValue();
        color[R] = (int) Math.round(lc.getRed() * lw + uc.getRed() * uw);
        color[G] = (int) Math.round(lc.getGreen() * lw + uc.getGreen() * uw);
        color[B] = (int) Math.round(lc.getBlue() * lw + uc.getBlue() * uw);
        color[A] = (int) Math.round(lc.getAlpha() * lw + uc.getAlpha() * uw);
    }
}

From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java

@Override
public void mouseClicked(MouseEvent event, final StateRenderer2D source) {

    if (event.getButton() == MouseEvent.BUTTON3) {
        final LinkedHashMap<String, Vector<AssetPosition>> positions = positionsByType();
        JPopupMenu popup = new JPopupMenu();
        for (String type : positions.keySet()) {
            JMenu menu = new JMenu(type + "s");
            for (final AssetPosition p : positions.get(type)) {

                if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection)
                    continue;

                Color c = cmap.getColor(1 - (p.getAge() / (7200000.0)));
                String htmlColor = String.format("#%02X%02X%02X", c.getRed(), c.getGreen(), c.getBlue());
                menu.add("<html><b>" + p.getAssetName() + "</b> <font color=" + htmlColor + ">" + getAge(p)
                        + "</font>").addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                source.focusLocation(p.getLoc());
                            }//  w  w w  .  j  a v a  2 s  .c  om
                        });
            }
            popup.add(menu);
        }

        popup.addSeparator();
        popup.add("Settings").addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                PluginUtils.editPluginProperties(SituationAwareness.this, true);
            }
        });

        popup.add("Fetch asset properties").addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //                    for (AssetTrack track : assets.values()) {
                //                        track.setColor(new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255)));
                //                    }
                fetchAssetProperties();
            }
        });

        popup.add("Select location sources").addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                JPanel p = new JPanel();
                p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));

                for (ILocationProvider l : localizers) {
                    JCheckBox check = new JCheckBox(l.getName());
                    check.setSelected(true);
                    p.add(check);
                    check.setSelected(updateMethodNames.contains(l.getName()));
                }

                int op = JOptionPane.showConfirmDialog(getConsole(), p, "Location update sources",
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (op == JOptionPane.CANCEL_OPTION)
                    return;

                Vector<String> methods = new Vector<String>();
                for (int i = 0; i < p.getComponentCount(); i++) {

                    if (p.getComponent(i) instanceof JCheckBox) {
                        JCheckBox sel = (JCheckBox) p.getComponent(i);
                        if (sel.isSelected())
                            methods.add(sel.getText());
                    }
                }
                updateMethods = StringUtils.join(methods, ", ");
                propertiesChanged();
            }
        });

        popup.add("Select hidden positions types").addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                JPanel p = new JPanel();
                p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));

                for (String type : positions.keySet()) {
                    JCheckBox check = new JCheckBox(type);
                    check.setSelected(true);
                    p.add(check);
                    check.setSelected(hiddenPosTypes.contains(type));
                }

                int op = JOptionPane.showConfirmDialog(getConsole(), p, "Position types to be hidden",
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (op == JOptionPane.CANCEL_OPTION)
                    return;

                Vector<String> types = new Vector<String>();
                for (int i = 0; i < p.getComponentCount(); i++) {

                    if (p.getComponent(i) instanceof JCheckBox) {
                        JCheckBox sel = (JCheckBox) p.getComponent(i);
                        if (sel.isSelected())
                            types.add(sel.getText());
                    }
                }
                hiddenTypes = StringUtils.join(types, ", ");
                propertiesChanged();
            }
        });

        popup.addSeparator();
        popup.add("Decision Support").addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (dialogDecisionSupport == null) {
                    dialogDecisionSupport = new JDialog(getConsole());
                    dialogDecisionSupport.setModal(false);
                    dialogDecisionSupport.setAlwaysOnTop(true);
                    dialogDecisionSupport.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
                }
                ArrayList<AssetPosition> tags = new ArrayList<AssetPosition>();
                LinkedHashMap<String, Vector<AssetPosition>> positions = positionsByType();
                Vector<AssetPosition> spots = positions.get("SPOT Tag");
                Vector<AssetPosition> argos = positions.get("Argos Tag");
                if (spots != null)
                    tags.addAll(spots);
                if (argos != null)
                    tags.addAll(argos);
                if (!assets.containsKey(getConsole().getMainSystem())) {
                    GuiUtils.errorMessage(getConsole(), "Decision Support", "UUV asset position is unknown");
                    return;
                }
                supportTable.setAssets(assets.get(getConsole().getMainSystem()).getLatest(), tags);
                JXTable table = new JXTable(supportTable);
                dialogDecisionSupport.setContentPane(new JScrollPane(table));
                dialogDecisionSupport.invalidate();
                dialogDecisionSupport.validate();
                dialogDecisionSupport.setSize(600, 300);
                dialogDecisionSupport.setTitle("Decision Support Table");
                dialogDecisionSupport.setVisible(true);
                dialogDecisionSupport.toFront();
                GuiUtils.centerOnScreen(dialogDecisionSupport);
            }
        });
        popup.show(source, event.getX(), event.getY());
    }
    super.mouseClicked(event, source);
}

From source file:org.openstreetmap.josm.tools.Utils.java

/**
 * Multiply the alpha value of the given color with the factor. The alpha value is clamped to 0..255
 * @param color The color//from  w  w  w  . j  a  va  2s. c  o  m
 * @param alphaFactor The factor to multiply alpha with.
 * @return The new color.
 * @since 11692
 */
public static Color alphaMultiply(Color color, float alphaFactor) {
    int alpha = Utils.colorFloat2int(Utils.colorInt2float(color.getAlpha()) * alphaFactor);
    alpha = clamp(alpha, 0, 255);
    return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
}

From source file:playground.christoph.evacuation.analysis.EvacuationTimePictureWriter.java

private ScreenOverlayType createHistogram(String transportMode, Map<Id, Double> evacuationTimes)
        throws IOException {

    /*//from  w w  w .ja  v  a 2  s .c  o m
     * Remove NaN entries from the List
     */
    List<Double> listWithoutNaN = new ArrayList<Double>();
    for (Double d : evacuationTimes.values())
        if (!d.isNaN())
            listWithoutNaN.add(d);

    /*
     * If trip with significant to high evacuation times should be cut off
     */
    if (limitMaxEvacuationTime) {
        double cutOffValue = meanEvacuationTime + standardDeviation * evacuationTimeCutOffFactor;
        ListIterator<Double> iter = listWithoutNaN.listIterator();
        while (iter.hasNext()) {
            double value = iter.next();
            if (value > cutOffValue)
                iter.remove();
        }
    }

    double[] array = new double[listWithoutNaN.size()];
    int i = 0;
    for (double d : listWithoutNaN)
        array[i++] = d;

    JFreeChart chart = createHistogramChart(transportMode, array);
    BufferedImage chartImage = chart.createBufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT);
    BufferedImage image = new BufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT,
            BufferedImage.TYPE_4BYTE_ABGR);

    // clone image and set alpha value
    for (int x = 0; x < OVERALLHISTOGRAMWIDTH; x++) {
        for (int y = 0; y < OVERALLHISTOGRAMHEIGHT; y++) {
            int rgb = chartImage.getRGB(x, y);
            Color c = new Color(rgb);
            int r = c.getRed();
            int b = c.getBlue();
            int g = c.getGreen();
            int argb = 225 << 24 | r << 16 | g << 8 | b; // 225 as transparency value
            image.setRGB(x, y, argb);
        }
    }

    byte[] imageBytes = bufferedImageToByteArray(image);
    this.kmzWriter.addNonKMLFile(imageBytes, transportMode + OVERALLHISTROGRAM);

    ScreenOverlayType overlay = kmlObjectFactory.createScreenOverlayType();
    LinkType icon = kmlObjectFactory.createLinkType();
    icon.setHref(transportMode + OVERALLHISTROGRAM);
    overlay.setIcon(icon);
    overlay.setName("Histogram " + transportMode);
    // place the image top right
    Vec2Type overlayXY = kmlObjectFactory.createVec2Type();
    overlayXY.setX(0.0);
    overlayXY.setY(1.0);
    overlayXY.setXunits(UnitsEnumType.FRACTION);
    overlayXY.setYunits(UnitsEnumType.FRACTION);
    overlay.setOverlayXY(overlayXY);
    Vec2Type screenXY = kmlObjectFactory.createVec2Type();
    screenXY.setX(0.02);
    screenXY.setY(0.98);
    screenXY.setXunits(UnitsEnumType.FRACTION);
    screenXY.setYunits(UnitsEnumType.FRACTION);
    overlay.setScreenXY(screenXY);
    return overlay;
}

From source file:de._13ducks.cor.graphics.GraphicsComponent.java

protected void calcColoredMaps(Color[] colors) {
    // Berechnet die eingefrbten Texturen, z.B. fr Gebude
    ArrayList<CoRImage> tList = new ArrayList<CoRImage>();
    tList.addAll(coloredImgMap.values());
    coloredImgMap.clear();/*from  ww w  . j a  v  a2s .c  o  m*/
    for (int i = 0; i < tList.size(); i++) {
        BufferedImage im = (BufferedImage) tList.get(i).getImage();
        for (int playerId = 0; playerId < colors.length; playerId++) {
            BufferedImage preImg = new BufferedImage(im.getWidth(), im.getHeight(),
                    BufferedImage.TYPE_INT_ARGB);
            for (int x = 0; x < im.getWidth(); x++) {
                for (int y = 0; y < im.getHeight(); y++) {
                    // Das ganze Raster durchgehen und Farben ersetzen
                    // Ersetzfarbe da?
                    int rgb = im.getRGB(x, y);

                    float[] col = Color.RGBtoHSB((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff, null);
                    if (col[0] >= 0.8583333f && col[0] <= 0.8666666f) {
                        // Ja, ersetzen
                        Color tc = colors[playerId];
                        int targetC = Color.HSBtoRGB(
                                Color.RGBtoHSB(tc.getRed(), tc.getGreen(), tc.getBlue(), null)[0], 1.0f,
                                col[2]);
                        int a = (rgb >> 24) & 0xff;
                        targetC = (targetC & (~(0xff << 24)) | (a << 24));
                        preImg.setRGB(x, y, targetC);

                    } else {
                        preImg.setRGB(x, y, im.getRGB(x, y));
                    }
                }
            }
            // Bild berechnet, einfgen
            CoRImage newImg = new CoRImage(preImg);
            newImg.setImageName(tList.get(i).getImageName());
            coloredImgMap.put(newImg.getImageName() + playerId, newImg);
        }

    }
}

From source file:org.apache.fop.render.pcl.PCLGenerator.java

/**
 * Convert a Color value to a PCL shade value (0-100).
 * @param col the color/*  w w  w.j av  a  2 s  . c  o m*/
 * @return the PCL shade value (100=black)
 */
public final int convertToPCLShade(Color col) {
    float gray = convertToGray(col.getRed(), col.getGreen(), col.getBlue()) / 255f;
    return (int) (100 - (gray * 100f));
}