Example usage for java.awt Color getRed

List of usage examples for java.awt Color getRed

Introduction

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

Prototype

public int getRed() 

Source Link

Document

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

Usage

From source file:haven.Utils.java

public static Color blendcol(Color x, Color y, double a) {
    int f1 = (int) (a * 255), f2 = 255 - f1;
    return (new Color(((x.getRed() * f2) + (y.getRed() * f1)) / 255,
            ((x.getGreen() * f2) + (y.getGreen() * f1)) / 255, ((x.getBlue() * f2) + (y.getBlue() * f1)) / 255,
            ((x.getAlpha() * f2) + (y.getAlpha() * f1)) / 255));
}

From source file:org.polymap.core.mapeditor.tooling.edit.VectorLayerStyler.java

/**
 * Calculates styles for {@link #hover} and {@link #select} intent based on the
 * {@link #standard} style. Override in order to change the standard behaviour.
 *//*  w  w w  . j  a va2s  .  c  o  m*/
protected void calculateHoverSelectStyle() {
    hover = Maps.newHashMap(standard);
    RGB rgb = (RGB) standard.get("strokeColor");

    // just brighter
    //        Color c = new Color( rgb.red, rgb.green, rgb.blue ).brighter().brighter().brighter();

    // gray
    //        int gray = (int)((0.299 * rgb.red) + (0.587 * rgb.green) + (0.114 * rgb.blue));
    //        Color c = new Color( gray, gray, gray ).brighter();

    HSLColor hsl = new HSLColor(new Color(rgb.red, rgb.green, rgb.blue));
    Color c = hsl.adjustShade(40).adjustSaturation(100).toRGB();

    // hover
    hover.put("strokeColor", new RGB(c.getRed(), c.getGreen(), c.getBlue()));
    hover.put("strokeDashstyle", "solid");
    Number strokeWidth = (Number) hover.get("strokeWidth");
    hover.put("strokeWidth", strokeWidth);
    hover.put("fillOpacity", 0.25);

    //        hsl = new HSLColor( new Color( rgb.red, rgb.green, rgb.blue ) );
    //        c = hsl.adjustHue( 180 ).adjustShade( 10 ).toRGB();

    // select
    select = Maps.newHashMap(standard);
    select.put("strokeColor", new RGB(c.getRed(), c.getGreen(), c.getBlue()));
    select.put("strokeDashstyle", "solid");
    strokeWidth = (Number) select.get("strokeWidth");
    select.put("strokeWidth", strokeWidth);
    select.put("fillOpacity", 0.20);
}

From source file:util.program.ProgramTextCreator.java

private static void startInfoSection(StringBuilder buffer, String section) {
    Color foreground = Color.black;//Settings.propProgramPanelForegroundColor.getColor();

    buffer.append("<tr><td valign=\"top\" style=\"color:#808080; font-size:");
    buffer.append(mBodyFontSize);/*from  w w w .j a v a2s .  com*/
    buffer.append("\"><b>");
    buffer.append(section);
    buffer.append("</b></td><td style=\"color:rgb(" + foreground.getRed() + "," + foreground.getGreen() + ","
            + foreground.getBlue() + "); font-size:");
    buffer.append(mBodyFontSize);
    buffer.append("\">");
}

From source file:haven.Utils.java

public static Color blendcol(Color in, Color bl) {
    int f1 = bl.getAlpha();
    int f2 = 255 - bl.getAlpha();
    return (new Color(((in.getRed() * f2) + (bl.getRed() * f1)) / 255,
            ((in.getGreen() * f2) + (bl.getGreen() * f1)) / 255,
            ((in.getBlue() * f2) + (bl.getBlue() * f1)) / 255, in.getAlpha()));
}

From source file:net.sf.maltcms.chromaui.charts.GradientPaintScale.java

/**
 *
 * @param f/*from w  w  w .j a v a  2 s .co m*/
 */
public void saveGradientPaintScale(File f) {
    try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) {
        double lowerBound = getLowerBound();
        double upperBound = getUpperBound();
        double incr = (upperBound - lowerBound) / 256.0d;
        double value = lowerBound;
        for (int i = 0; i < 256; i++) {
            Paint p = getPaint(value);
            if (p instanceof Color) {
                Color c = (Color) p;
                bw.write(c.getRed() + "\t" + c.getGreen() + "\t" + c.getBlue());
                bw.newLine();
            }
            lowerBound += incr;
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}

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

public String getComplementColour(String hexColour) throws JspException {

    String output = null;//from   w w  w.  ja v  a  2 s  .co  m
    Integer i = null;

    if (hexColour == null || hexColour.equals("")) {
        i = 0;
    } else {
        i = Integer.parseInt(hexColour, 16);
    }

    int red = (i >> 16);
    int green = (i >> 8) & 0xFF;
    int blue = i & 0xFF;

    float[] hsl;
    float alpha;

    Color rgb = new Color(red, green, blue);
    hsl = fromRGB(rgb);
    alpha = rgb.getAlpha() / 255.0f;

    float hue = (hsl[0] + 180.0f) % 360.0f;
    Color complement = toRGB(hue, hsl[1], hsl[2], 1.0f);

    output = rgb2hex(complement.getRed(), complement.getGreen(), complement.getBlue());

    return output;
}

From source file:com.alkacon.opencms.survey.CmsFormReportingBean.java

/**
 * Returns a lazy initialized map that provides the color of the label for each background color used as a key in the Map.<p> 
 * //from   w  w  w. ja v a 2  s  .c  o m
 * Dark background color returns white.<p>
 * Light background color returns black.<p>
 * 
 * @return a lazy initialized map
 */
public Map getTextColor() {

    if (m_color == null) {
        m_color = LazyMap.decorate(new HashMap(), new Transformer() {

            /**
             * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
             */
            public Object transform(Object input) {

                try {
                    // get the color from the given value
                    String value = String.valueOf(input);
                    Color color = Color.decode(value);

                    // look if its a dark color or a light
                    int dezColor = color.getBlue() + color.getGreen() + color.getRed();
                    if (dezColor < SEP_DARK_LIGHT) {
                        return "#FFF";
                    }

                } catch (Exception e) {
                    // NOOP
                }
                return "#000";
            }
        });
    }
    return m_color;
}

From source file:com.hygenics.imaging.ImageCleanup.java

public byte[] reaverage(double factor, byte[] ibytes) {
    // tone red coloring
    BufferedImage color = BufferImage(ibytes);

    if (color != null) {
        BufferedImage averaged = new BufferedImage(color.getWidth(), color.getHeight(),
                BufferedImage.TYPE_INT_RGB);

        for (int i = 0; i < color.getWidth(); i++) {
            for (int j = 0; j < color.getHeight(); j++) {
                Color c = new Color(color.getRGB(i, j));

                averaged.setRGB(i, j,/* w w w  .  j  a  va 2  s.c om*/
                        new Color((int) Math.round(c.getRed() / factor), c.getGreen(), c.getBlue()).getRGB());
            }
        }

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        // convert to jpeg for compression
        try {
            // use apache to read to a buffered image with certain metadata
            // and then convert to a jpg
            ImageIO.write(averaged, "jpg", bos);
            return ibytes = bos.toByteArray();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return ibytes;

}

From source file:util.ui.UiUtilities.java

/**
 * Creates a Html EditorPane that holds a HTML-Help Text.
 *
 * Add a Listener if you want to have clickable Links
 *
 * @param html//  ww  w  .  j  a va2 s .  c om
 *          HTML-Text to display
 * @param listener
 *          Link-Listener for this HelpText
 * @param background The color for the background.
 * @return EditorPane that holds a Help Text
 * @since 2.7.2
 */
public static JEditorPane createHtmlHelpTextArea(String html, HyperlinkListener listener, Color background) {
    // Quick "hack". Remove HTML-Code and replace it with Code that includes the
    // correct Font
    if (html.indexOf("<html>") >= 0) {
        html = StringUtils.substringBetween(html, "<html>", "</html>");
    }
    JLabel label = new JLabel();
    Font font = label.getFont();
    html = "<html><div style=\"color:" + UiUtilities.getHTMLColorCode(label.getForeground()) + ";font-family:"
            + font.getName() + "; font-size:" + font.getSize() + ";background-color:rgb(" + background.getRed()
            + "," + background.getGreen() + "," + background.getBlue() + ");\">" + html + "</div></html>";

    final JEditorPane pane = new JEditorPane("text/html", html);
    pane.setBorder(BorderFactory.createEmptyBorder());
    pane.setEditable(false);
    pane.setFont(font);
    pane.setOpaque(false);
    pane.setFocusable(false);

    if (listener != null) {
        pane.addHyperlinkListener(listener);
    }
    return pane;
}

From source file:org.polymap.core.data.image.WmsRenderProcessor.java

protected void getMap(GetMapRequest request, ProcessorContext context) throws Exception {
    int width = request.getWidth();
    int height = request.getHeight();
    BoundingBox bbox = request.getBoundingBox();
    log.debug("bbox=" + bbox + ", imageSize=" + width + "x" + height);

    Set<ILayer> layers = context.getLayers();
    IService service = context.getService();

    // skip if no layers are visible
    if (layers.isEmpty()) {
        log.debug("no layers.");
    }// w ww. j  av a2s  .  c o  m

    WebMapServer wms = service.resolve(WebMapServer.class, null);
    org.geotools.data.wms.request.GetMapRequest getMap = wms.createGetMapRequest();

    getMap.setFormat(request.getFormat());
    getMap.setDimensions(width, height);
    getMap.setTransparent(true);
    Color color = request.getBgColor();
    if (color != null) {
        getMap.setBGColour(String.format("#%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue()));
    }
    //getMap.setBGColour( "0xFFFFFF" );

    //CRSEnvelope envelop = calculateRequestBBox( )
    // CRSEnvelope envelop = new CRSEnvelope( "EPSG:31468", 4621529.925,5657790.683333333,4623149.175,5659484.016666667 );
    BoundingBox requestBBox = bbox;
    getMap.setBBox(requestBBox.getMinX() + "," + requestBBox.getMinY() //$NON-NLS-1$
            + "," + requestBBox.getMaxX() //$NON-NLS-1$
            + "," + requestBBox.getMaxY()); //$NON-NLS-1$
    // FIXME hack for LRA to support EPSG3857, see GeoServerWms
    // check to see if backend wms supports 900913 or not
    String srs = request.getCRS();
    //String srs = request.getCRS().equals( "EPSG:900913" )
    //        ? "EPSG:3857" : request.getCRS(); 
    getMap.setSRS(srs);

    //getMap.setBBox(  );

    //request.setSRS( "EPSG:4326" );
    //request.setBBox( "-131.13151509433965,46.60532747661736,-117.61620566037737,56.34191403281659" );
    // Note: you can look at the layer metadata to determine a layer's bounding box for a SRS

    //        Map sortedLayersMap = MultiValueMap.decorate( new TreeMap() );
    //        for (Iterator it=visibleLayers.referencedLayers(); it.hasNext();) {
    //            Layer layer = (Layer)availableLayers.get( it.next() );
    //            Integer layerOrder = (Integer)layerOrderMap.get( layer.getName() );
    //            // reverse order; request.addLayer() works that way
    //            Integer key = Integer.valueOf( Integer.MAX_VALUE - layerOrder.intValue() );
    //            sortedLayersMap.put( key, layer );
    //        }
    for (ILayer layer : layers) {
        IGeoResource geores = layer.getGeoResource();
        Layer wmsLayer = geores.resolve(org.geotools.data.ows.Layer.class, null);
        getMap.addLayer(wmsLayer);
        log.debug("    request: layer: " + layer.getLabel());
    }
    log.debug("    WMS URL:" + getMap.getFinalURL());

    InputStream in = null;
    try {
        long start = System.currentTimeMillis();
        GetMapResponse wmsResponse = wms.issueRequest(getMap);
        log.debug("Got repsonse (" + (System.currentTimeMillis() - start) + "ms). providing data: "
                + wmsResponse.getContentType());

        in = wmsResponse.getInputStream();
        int count = 0;
        byte[] buf = new byte[8 * 1024];
        for (int c = in.read(buf); c != -1; c = in.read(buf)) {
            context.sendResponse(new EncodedImageResponse(buf, c));
            buf = new byte[8 * 2048];
            //log.debug( "    --->data sent: " + c );
            count += c;
        }
        if (count == 0) {
            throw new IOException("WMSResponse is empty.");
        }
        context.sendResponse(ProcessorResponse.EOP);
        log.debug("...all data send.");
    } finally {
        IOUtils.closeQuietly(in);
    }
}