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:lu.lippmann.cdb.ext.hydviga.ui.GapFillingFrame.java

private void showError(final double mae, final Instances decomposition, final Attribute diffAttribute,
        final List<XYAnnotation> aaa) {
    //System.out.println("*************** SHOW ERROR **************************");
    final Attribute timestampDiffAttribute = decomposition
            .attribute(WekaDataStatsUtil.getFirstDateAttributeIdx(decomposition));
    final Color cc = ColorHelper.getColorForAString(diffAttribute.name());
    final Color newcc = new Color(cc.getRed(), cc.getGreen(), cc.getBlue(), cc.getAlpha() / 4).brighter();
    for (int i = 1; i < decomposition.numInstances() - 1; i++) {
        //if (i%10!=1) continue;
        if (!decomposition.instance(i).isMissing(diffAttribute)/*&&i%10==0*/) {
            final double d = decomposition.instance(i).value(diffAttribute);
            final double timestamp = decomposition.instance(i).value(timestampDiffAttribute);

            aaa.add(new XYDrawableAnnotation(timestamp, d + mae, 0.5, 0.5, new AnnotationDrawer(newcc)));
            aaa.add(new XYDrawableAnnotation(timestamp, d - mae, 0.5, 0.5, new AnnotationDrawer(newcc)));
            for (double dd = d - mae; dd <= d + mae; dd += mae / 20) {
                aaa.add(new XYDrawableAnnotation(timestamp, dd, 1, 1, new AnnotationDrawer(newcc)));
            }/*from w  ww.j a  va 2 s  .  com*/
            //aaa.add(new XYDrawableAnnotation(timestamp,d,1,1,new AnnotationDrawer(cc)));
        }
    }
    //System.out.println("*****************************************************");
}

From source file:gate.gui.docview.AnnotationStack.java

/**
 * Draw the annotation stack in a JPanel with a GridBagLayout.
 *//*from  w w w.jav  a2 s  .c  o m*/
public void drawStack() {

    // clear the panel
    removeAll();

    boolean textTooLong = text.length() > maxTextLength;
    int upperBound = text.length() - (maxTextLength / 2);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.BOTH;

    /**********************
     * First row of text *
     *********************/

    gbc.gridwidth = 1;
    gbc.insets = new java.awt.Insets(10, 10, 10, 10);
    JLabel labelTitle = new JLabel("Context");
    labelTitle.setOpaque(true);
    labelTitle.setBackground(Color.WHITE);
    labelTitle.setBorder(new CompoundBorder(
            new EtchedBorder(EtchedBorder.LOWERED, new Color(250, 250, 250), new Color(250, 250, 250).darker()),
            new EmptyBorder(new Insets(0, 2, 0, 2))));
    labelTitle.setToolTipText("Expression and its context.");
    add(labelTitle, gbc);
    gbc.insets = new java.awt.Insets(10, 0, 10, 0);

    int expressionStart = contextBeforeSize;
    int expressionEnd = text.length() - contextAfterSize;

    // for each character
    for (int charNum = 0; charNum < text.length(); charNum++) {

        gbc.gridx = charNum + 1;
        if (textTooLong) {
            if (charNum == maxTextLength / 2) {
                // add ellipsis dots in case of a too long text displayed
                add(new JLabel("..."), gbc);
                // skip the middle part of the text if too long
                charNum = upperBound + 1;
                continue;
            } else if (charNum > upperBound) {
                gbc.gridx -= upperBound - (maxTextLength / 2) + 1;
            }
        }

        // set the text and color of the feature value
        JLabel label = new JLabel(text.substring(charNum, charNum + 1));
        if (charNum >= expressionStart && charNum < expressionEnd) {
            // this part is matched by the pattern, color it
            label.setBackground(new Color(240, 201, 184));
        } else {
            // this part is the context, no color
            label.setBackground(Color.WHITE);
        }
        label.setOpaque(true);

        // get the word from which belongs the current character charNum
        int start = text.lastIndexOf(" ", charNum);
        int end = text.indexOf(" ", charNum);
        String word = text.substring((start == -1) ? 0 : start, (end == -1) ? text.length() : end);
        // add a mouse listener that modify the query
        label.addMouseListener(textMouseListener.createListener(word));
        add(label, gbc);
    }

    /************************************
     * Subsequent rows with annotations *
     ************************************/

    // for each row to display
    for (StackRow stackRow : stackRows) {
        String type = stackRow.getType();
        String feature = stackRow.getFeature();
        if (feature == null) {
            feature = "";
        }
        String shortcut = stackRow.getShortcut();
        if (shortcut == null) {
            shortcut = "";
        }

        gbc.gridy++;
        gbc.gridx = 0;
        gbc.gridwidth = 1;
        gbc.insets = new Insets(0, 0, 3, 0);

        // add the header of the row
        JLabel annotationTypeAndFeature = new JLabel();
        String typeAndFeature = type + (feature.equals("") ? "" : ".") + feature;
        annotationTypeAndFeature.setText(!shortcut.equals("") ? shortcut
                : stackRow.getSet() != null ? stackRow.getSet() + "#" + typeAndFeature : typeAndFeature);
        annotationTypeAndFeature.setOpaque(true);
        annotationTypeAndFeature.setBackground(Color.WHITE);
        annotationTypeAndFeature
                .setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(250, 250, 250),
                        new Color(250, 250, 250).darker()), new EmptyBorder(new Insets(0, 2, 0, 2))));
        if (feature.equals("")) {
            annotationTypeAndFeature.addMouseListener(headerMouseListener.createListener(type));
        } else {
            annotationTypeAndFeature.addMouseListener(headerMouseListener.createListener(type, feature));
        }
        gbc.insets = new java.awt.Insets(0, 10, 3, 10);
        add(annotationTypeAndFeature, gbc);
        gbc.insets = new java.awt.Insets(0, 0, 3, 0);

        // add all annotations for this row
        HashMap<Integer, TreeSet<Integer>> gridSet = new HashMap<Integer, TreeSet<Integer>>();
        int gridyMax = gbc.gridy;
        for (StackAnnotation ann : stackRow.getAnnotations()) {
            gbc.gridx = ann.getStartNode().getOffset().intValue() - expressionStartOffset + contextBeforeSize
                    + 1;
            gbc.gridwidth = ann.getEndNode().getOffset().intValue() - ann.getStartNode().getOffset().intValue();
            if (gbc.gridx == 0) {
                // column 0 is already the row header
                gbc.gridwidth -= 1;
                gbc.gridx = 1;
            } else if (gbc.gridx < 0) {
                // annotation starts before displayed text
                gbc.gridwidth += gbc.gridx - 1;
                gbc.gridx = 1;
            }
            if (gbc.gridx + gbc.gridwidth > text.length()) {
                // annotation ends after displayed text
                gbc.gridwidth = text.length() - gbc.gridx + 1;
            }
            if (textTooLong) {
                if (gbc.gridx > (upperBound + 1)) {
                    // x starts after the hidden middle part
                    gbc.gridx -= upperBound - (maxTextLength / 2) + 1;
                } else if (gbc.gridx > (maxTextLength / 2)) {
                    // x starts in the hidden middle part
                    if (gbc.gridx + gbc.gridwidth <= (upperBound + 3)) {
                        // x ends in the hidden middle part
                        continue; // skip the middle part of the text
                    } else {
                        // x ends after the hidden middle part
                        gbc.gridwidth -= upperBound - gbc.gridx + 2;
                        gbc.gridx = (maxTextLength / 2) + 2;
                    }
                } else {
                    // x starts before the hidden middle part
                    if (gbc.gridx + gbc.gridwidth < (maxTextLength / 2)) {
                        // x ends before the hidden middle part
                        // do nothing
                    } else if (gbc.gridx + gbc.gridwidth < upperBound) {
                        // x ends in the hidden middle part
                        gbc.gridwidth = (maxTextLength / 2) - gbc.gridx + 1;
                    } else {
                        // x ends after the hidden middle part
                        gbc.gridwidth -= upperBound - (maxTextLength / 2) + 1;
                    }
                }
            }
            if (gbc.gridwidth == 0) {
                gbc.gridwidth = 1;
            }

            JLabel label = new JLabel();
            Object object = ann.getFeatures().get(feature);
            String value = (object == null) ? " " : Strings.toString(object);
            if (value.length() > maxFeatureValueLength) {
                // show the full text in the tooltip
                label.setToolTipText((value.length() > 500)
                        ? "<html><textarea rows=\"30\" cols=\"40\" readonly=\"readonly\">"
                                + value.replaceAll("(.{50,60})\\b", "$1\n") + "</textarea></html>"
                        : ((value.length() > 100)
                                ? "<html><table width=\"500\" border=\"0\" cellspacing=\"0\">" + "<tr><td>"
                                        + value.replaceAll("\n", "<br>") + "</td></tr></table></html>"
                                : value));
                if (stackRow.getCrop() == CROP_START) {
                    value = "..." + value.substring(value.length() - maxFeatureValueLength - 1);
                } else if (stackRow.getCrop() == CROP_END) {
                    value = value.substring(0, maxFeatureValueLength - 2) + "...";
                } else {// cut in the middle
                    value = value.substring(0, maxFeatureValueLength / 2) + "..."
                            + value.substring(value.length() - (maxFeatureValueLength / 2));
                }
            }
            label.setText(value);
            label.setBackground(AnnotationSetsView.getColor(stackRow.getSet(), ann.getType()));
            label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
            label.setOpaque(true);

            label.addMouseListener(annotationMouseListener.createListener(stackRow.getSet(), type,
                    String.valueOf(ann.getId())));

            // show the feature values in the tooltip
            if (!ann.getFeatures().isEmpty()) {
                String width = (Strings.toString(ann.getFeatures()).length() > 100) ? "500" : "100%";
                String toolTip = "<html><table width=\"" + width
                        + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">";
                Color color = (Color) UIManager.get("ToolTip.background");
                float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
                color = Color.getHSBColor(hsb[0], hsb[1], Math.max(0f, hsb[2] - hsb[2] * 0.075f)); // darken the color
                String hexColor = Integer.toHexString(color.getRed()) + Integer.toHexString(color.getGreen())
                        + Integer.toHexString(color.getBlue());
                boolean odd = false; // alternate background color every other row

                List<Object> features = new ArrayList<Object>(ann.getFeatures().keySet());
                //sort the features into alphabetical order
                Collections.sort(features, new Comparator<Object>() {
                    @Override
                    public int compare(Object o1, Object o2) {
                        return o1.toString().compareToIgnoreCase(o2.toString());
                    }
                });

                for (Object key : features) {
                    String fv = Strings.toString(ann.getFeatures().get(key));
                    toolTip += "<tr align=\"left\"" + (odd ? " bgcolor=\"#" + hexColor + "\"" : "")
                            + "><td><strong>" + key + "</strong></td><td>"
                            + ((fv.length() > 500)
                                    ? "<textarea rows=\"20\" cols=\"40\" cellspacing=\"0\">" + StringEscapeUtils
                                            .escapeHtml(fv.replaceAll("(.{50,60})\\b", "$1\n")) + "</textarea>"
                                    : StringEscapeUtils.escapeHtml(fv).replaceAll("\n", "<br>"))
                            + "</td></tr>";
                    odd = !odd;
                }
                label.setToolTipText(toolTip + "</table></html>");
            } else {
                label.setToolTipText("No features.");
            }

            if (!feature.equals("")) {
                label.addMouseListener(annotationMouseListener.createListener(stackRow.getSet(), type, feature,
                        Strings.toString(ann.getFeatures().get(feature)), String.valueOf(ann.getId())));
            }
            // find the first empty row span for this annotation
            int oldGridy = gbc.gridy;
            for (int y = oldGridy; y <= (gridyMax + 1); y++) {
                // for each cell of this row where spans the annotation
                boolean xSpanIsEmpty = true;
                for (int x = gbc.gridx; (x < (gbc.gridx + gbc.gridwidth)) && xSpanIsEmpty; x++) {
                    xSpanIsEmpty = !(gridSet.containsKey(x) && gridSet.get(x).contains(y));
                }
                if (xSpanIsEmpty) {
                    gbc.gridy = y;
                    break;
                }
            }
            // save the column x and row y of the current value
            TreeSet<Integer> ts;
            for (int x = gbc.gridx; x < (gbc.gridx + gbc.gridwidth); x++) {
                ts = gridSet.get(x);
                if (ts == null) {
                    ts = new TreeSet<Integer>();
                }
                ts.add(gbc.gridy);
                gridSet.put(x, ts);
            }
            add(label, gbc);
            gridyMax = Math.max(gridyMax, gbc.gridy);
            gbc.gridy = oldGridy;
        }

        // add a button at the end of the row
        gbc.gridwidth = 1;
        if (stackRow.getLastColumnButton() != null) {
            // last cell of the row
            gbc.gridx = Math.min(text.length(), maxTextLength) + 1;
            gbc.insets = new Insets(0, 10, 3, 0);
            gbc.fill = GridBagConstraints.NONE;
            gbc.anchor = GridBagConstraints.WEST;
            add(stackRow.getLastColumnButton(), gbc);
            gbc.insets = new Insets(0, 0, 3, 0);
            gbc.fill = GridBagConstraints.BOTH;
            gbc.anchor = GridBagConstraints.CENTER;
        }

        // set the new gridy to the maximum row we put a value
        gbc.gridy = gridyMax;
    }

    if (lastRowButton != null) {
        // add a configuration button on the last row
        gbc.insets = new java.awt.Insets(0, 10, 0, 10);
        gbc.gridx = 0;
        gbc.gridy++;
        add(lastRowButton, gbc);
    }

    // add an empty cell that takes all remaining space to
    // align the visible cells at the top-left corner
    gbc.gridy++;
    gbc.gridx = Math.min(text.length(), maxTextLength) + 1;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.gridheight = GridBagConstraints.REMAINDER;
    gbc.weightx = 1;
    gbc.weighty = 1;
    add(new JLabel(""), gbc);

    validate();
    updateUI();
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingFrame.java

private void showEnvelope(final int[] arr, final List<XYAnnotation> aaa) throws Exception {
    final Color cc = ColorHelper.getColorForAString(attr.name());
    final Color newcc = new Color(cc.getRed(), cc.getGreen(), cc.getBlue(), cc.getAlpha() / 4).brighter();

    final Map<Double, Double> minMap = new HashMap<Double, Double>();
    final Map<Double, Double> maxMap = new HashMap<Double, Double>();

    for (final Algo aall : Algo.values()) {
        Instances filteredDs2 = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSet, arr);

        filteredDs2 = WekaDataProcessingUtil.buildFilteredDataSet(filteredDs2, 0,
                filteredDs2.numAttributes() - 1, Math.max(0, this.position - this.valuesBeforeAndAfter),
                Math.min(this.position + this.gapsize + this.valuesBeforeAndAfter,
                        filteredDs2.numInstances() - 1));

        final GapFiller gp = GapFillerFactory.getGapFiller(aall);

        final Instances completedds2 = gp.fillGaps(filteredDs2);
        final Instances diff2 = WekaTimeSeriesUtil.buildDiff(filteredDs2, completedds2);

        //final double mae2=this.gapFiller.evaluateMeanAbsoluteError(filteredDs2,valuesBeforeAndAfterForMAE);

        final Instances decomposition2 = WekaTimeSeriesUtil.buildMergedDataSet(filteredDs2, diff2);
        final Attribute diffAttribute2 = decomposition2.attribute(attr.name() + "_diff");

        final Attribute timestampDiffAttribute2 = decomposition2
                .attribute(WekaDataStatsUtil.getFirstDateAttributeIdx(decomposition2));

        for (int i = 1; i < decomposition2.numInstances() - 1; i++) {
            if (!decomposition2.instance(i).isMissing(diffAttribute2)/*&&i%10==0*/) {
                final double d = decomposition2.instance(i).value(diffAttribute2);
                final double timestamp = decomposition2.instance(i).value(timestampDiffAttribute2);

                aaa.add(new XYDrawableAnnotation(timestamp, d, 1, 1, new AnnotationDrawer(newcc)));

                if (!minMap.containsKey(timestamp) || minMap.get(timestamp) > d)
                    minMap.put(timestamp, d);
                if (!maxMap.containsKey(timestamp) || maxMap.get(timestamp) < d)
                    maxMap.put(timestamp, d);
            }//w ww. j  a  v a  2  s  .c  o  m
        }
    }

    for (final Map.Entry<Double, Double> entry : minMap.entrySet()) {
        final Double timestamp = entry.getKey();
        final Double min = minMap.get(timestamp);
        final Double max = maxMap.get(timestamp);
        if (min > max)
            throw new IllegalStateException("min>max -> " + min + ">" + max);
        else if (max > min) {
            final double step = (max - min) / 20d;
            for (double dd = min; dd <= max; dd += step) {
                aaa.add(new XYDrawableAnnotation(timestamp, dd, 1, 1, new AnnotationDrawer(newcc)));
            }
        }
    }

    System.out.println("done");
}

From source file:org.kurento.test.browser.WebPage.java

public boolean compareColor(String videoTag, Color expectedColor, boolean logWarn) {
    @SuppressWarnings("unchecked")
    List<Long> realColor = (List<Long>) browser
            .executeScriptAndWaitOutput("return kurentoTest.colorInfo['" + videoTag + "'].currentColor;");

    long red = realColor.get(0);
    long green = realColor.get(1);
    long blue = realColor.get(2);

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

    String expectedColorStr = "[R=" + expectedColor.getRed() + ", G=" + expectedColor.getGreen() + ", B="
            + expectedColor.getBlue() + "]";
    String realColorStr = "[R=" + red + ", G=" + green + ", B=" + blue + "]";
    boolean out = distance <= browser.getColorDistance();
    if (!out) {/*from  w w  w.  j av  a2  s  .  c o m*/
        if (logWarn) {
            log.warn("Color NOT detected in video stream. Expected: {}, Real: {}", expectedColorStr,
                    realColorStr);
        }
    } else {
        log.debug("Detected color in video stream. Expected: {}, Real: {}", expectedColorStr, realColorStr);
    }

    return out;
}

From source file:com.siteview.ecc.report.xls.JRXlsExporter.java

/**
 *
 */// w w  w  .  j  a va 2s .co  m
protected static HSSFColor getNearestColor(Color awtColor) {
    HSSFColor color = (HSSFColor) hssfColorsCache.get(awtColor);
    if (color == null) {
        Map triplets = HSSFColor.getTripletHash();
        if (triplets != null) {
            Collection keys = triplets.keySet();
            if (keys != null && keys.size() > 0) {
                Object key = null;
                HSSFColor crtColor = null;
                short[] rgb = null;
                int diff = 0;
                int minDiff = 999;
                for (Iterator it = keys.iterator(); it.hasNext();) {
                    key = it.next();

                    crtColor = (HSSFColor) triplets.get(key);
                    rgb = crtColor.getTriplet();

                    diff = Math.abs(rgb[0] - awtColor.getRed()) + Math.abs(rgb[1] - awtColor.getGreen())
                            + Math.abs(rgb[2] - awtColor.getBlue());

                    if (diff < minDiff) {
                        minDiff = diff;
                        color = crtColor;
                    }
                }
            }
        }

        hssfColorsCache.put(awtColor, color);
    }

    return color;
}

From source file:org.openmicroscopy.shoola.agents.dataBrowser.view.WellsModel.java

/**
 * Handles the selection of a cell//from   w ww  .jav  a 2s.  c  om
 * 
 * @param cell The selected cell.
 * @param well The well to handle.
 * @param results The collection of objects to update.
 */
private void handleCellSelection(CellDisplay cell, WellImageSet well, List<DataObject> results) {
    String description = cell.getDescription();
    Color c = cell.getHighlight();
    WellData data = (WellData) well.getHierarchyObject();
    data.setWellType(description);
    well.setDescription(description);
    results.add(data);
    if (c == null || !cell.isSpecified()) {
        data.setRed(null);
    } else {
        data.setRed(c.getRed());
        data.setGreen(c.getGreen());
        data.setBlue(c.getBlue());
        data.setAlpha(c.getAlpha());
    }
    well.setHighlight(c);
}

From source file:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.ExtendedBoxAndWhiskerRenderer.java

/**
 * Draws the visual representation of a single data item when the plot has a
 * vertical orientation.//from w w  w  .  ja  va 2 s  .  c  om
 *
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the area within which the plot is being drawn.
 * @param plot the plot (can be used to obtain standard color information
 * etc).
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the dataset.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 */
@Override
public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
        CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row,
        int column) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }

    //Determine the catgory start and end.
    BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset;

    double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryWidth = categoryEnd - categoryStart;

    domainAxis.setCategoryMargin(0.25);

    rangeAxis.setUpperMargin(0.3);
    rangeAxis.setLowerMargin(0.3);

    double xx = categoryStart;
    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();

    if (seriesCount > 1) {
        double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
        double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1));
        // offset the start of the boxes if the total width used is smaller
        // than the category width
        double offset = (categoryWidth - usedWidth) / 2;
        xx = xx + offset + (row * (state.getBarWidth() + seriesGap));
    } else {
        // offset the start of the box if the box width is smaller than the category width
        double offset = (categoryWidth - state.getBarWidth()) / 2;
        xx = xx + offset;
    }
    double xxmid = xx + state.getBarWidth() / 2.0;

    //Draw the box.
    Paint p = getItemPaint(row, column);
    if (p != null) {
        g2.setPaint(p);
    }
    Stroke s = getItemStroke(row, column);
    g2.setStroke(s);

    RectangleEdge location = plot.getRangeAxisEdge();
    Shape box = null;

    Number yQ1 = bawDataset.getQ1Value(row, column);
    Number yQ3 = bawDataset.getQ3Value(row, column);
    Number yMax = bawDataset.getMaxRegularValue(row, column);
    Number yMin = bawDataset.getMinRegularValue(row, column);

    if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) {

        double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location);
        double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location);
        double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location);
        double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location);

        // set the paint according to the right technical replicate
        int length = GuiUtils.getAvailableColors().length;
        int colorIndex = row % length;
        Color color = GuiUtils.getAvailableColors()[colorIndex];
        g2.setPaint(color);

        // draw the upper whisker
        g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3));
        g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax));
        // draw the lower whisker
        g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1));
        g2.draw(new Line2D.Double(xx, yyMin, xx + state.getBarWidth(), yyMin));

        // draw the body
        box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3));
        g2.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(), 175));

        //            if (getFillBox()) {
        //                g2.fill(box);
        //            }
        g2.draw(box);
    }

    // draw mean 
    g2.setPaint(getArtifactPaint());
    double yyAverage = 0.0;
    double aRadius = 2.0; // mean radius                       
    Number yMean = bawDataset.getMeanValue(row, column);
    if (yMean != null) {
        yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location);
        Ellipse2D.Double avgEllipse = new Ellipse2D.Double((xxmid - aRadius), (yyAverage - aRadius),
                aRadius * 2, aRadius * 2);
        g2.draw(avgEllipse);
    }

    //draw median
    double yyMedian = 0.0;
    Number yMedian = bawDataset.getMedianValue(row, column);
    if (yMedian != null) {
        yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location);
        g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian));
    }

    //Outliers and Farouts                 
    double oRadius = 2.0; //outlier radius
    double foRadius = 1.0; //farout radius

    // From outlier array sort out which are outliers and put these into a 
    // list. If there are any farouts, add them to the farout list.    
    // draw the outliers and farouts only if they are within the data area.
    double yyOutlier;
    double yyFarout;
    List outliers = new ArrayList();
    List farOutValues = new ArrayList();
    List yOutliers = bawDataset.getOutliers(row, column);
    if (yOutliers != null) {
        for (int i = 0; i < yOutliers.size(); i++) {
            Number outlierNum = (Number) yOutliers.get(i);
            double outlier = outlierNum.doubleValue();
            Number minOutlier = bawDataset.getMinOutlier(row, column);
            Number maxOutlier = bawDataset.getMaxOutlier(row, column);
            Number minRegular = bawDataset.getMinRegularValue(row, column);
            Number maxRegular = bawDataset.getMaxRegularValue(row, column);
            if (outlier > maxOutlier.doubleValue() || outlier < minOutlier.doubleValue()) {
                yyFarout = rangeAxis.valueToJava2D(outlier, dataArea, location);
                Outlier faroutToAdd = new Outlier(xxmid, yyFarout, foRadius);
                if (dataArea.contains(faroutToAdd.getPoint())) {
                    farOutValues.add(faroutToAdd);
                }
            } else if (outlier > maxRegular.doubleValue() || outlier < minRegular.doubleValue()) {
                yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
                Outlier outlierToAdd = new Outlier(xxmid, yyOutlier, oRadius);
                if (dataArea.contains(outlierToAdd.getPoint())) {
                    outliers.add(outlierToAdd);
                }
            }
        }

        //draw the outliers
        g2.setPaint(this.outlierPaint);
        for (Iterator iterator = outliers.iterator(); iterator.hasNext();) {
            Outlier outlier = (Outlier) iterator.next();
            Point2D point = outlier.getPoint();
            Shape dot = createEllipse(point, oRadius);
            g2.draw(dot);
        }

        //draw the farout values
        g2.setPaint(this.farOutColor);
        for (Iterator iterator = farOutValues.iterator(); iterator.hasNext();) {
            Outlier outlier = (Outlier) iterator.next();
            Point2D point = outlier.getPoint();
            Shape triangle = createTriangleVertical(point, foRadius);
            g2.draw(triangle);
        }
    }
}

From source file:org.datavyu.views.DataControllerV.java

private static String toRGBString(final Color color) {
    return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
}

From source file:userinterface.graph.AxisSettings.java

public void save(Element axis) throws SettingException {
    axis.setAttribute("heading", getHeading());

    Font headingFont = getHeadingFont().f;
    axis.setAttribute("headingFontName", headingFont.getName());
    axis.setAttribute("headingFontSize", "" + headingFont.getSize());
    axis.setAttribute("headingFontStyle", "" + headingFont.getStyle());

    Color headingFontColor = getHeadingFont().c;
    axis.setAttribute("headingFontColourR", "" + headingFontColor.getRed());
    axis.setAttribute("headingFontColourG", "" + headingFontColor.getGreen());
    axis.setAttribute("headingFontColourB", "" + headingFontColor.getBlue());

    Font numberFont = getNumberFont().f;
    axis.setAttribute("numberFontName", numberFont.getName());
    axis.setAttribute("numberFontSize", "" + numberFont.getSize());
    axis.setAttribute("numberFontStyle", "" + numberFont.getStyle());

    Color numberFontColor = getHeadingFont().c;
    axis.setAttribute("numberFontColourR", "" + numberFontColor.getRed());
    axis.setAttribute("numberFontColourG", "" + numberFontColor.getGreen());
    axis.setAttribute("numberFontColourB", "" + numberFontColor.getBlue());

    axis.setAttribute("showMajor", showGrid() ? "true" : "false");

    Color gridColor = gridColour.getColorValue();
    axis.setAttribute("majorColourR", "" + gridColor.getRed());
    axis.setAttribute("majorColourG", "" + gridColor.getGreen());
    axis.setAttribute("majorColourB", "" + gridColor.getBlue());

    axis.setAttribute("logarithmic", isLogarithmic() ? "true" : "false");

    axis.setAttribute("minValue", "" + getMinValue());
    axis.setAttribute("maxValue", "" + getMaxValue());

    axis.setAttribute("majorGridInterval", "" + getGridInterval());
    axis.setAttribute("logBase", "" + getLogBase());
    axis.setAttribute("logStyle", "" + getLogStyle());

    axis.setAttribute("minimumPower", "" + getMinimumPower());
    axis.setAttribute("maximumPower", "" + getMaximumPower());

    axis.setAttribute("autoscale", isAutoScale() ? "true" : "false");
}

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

/**
 * Private method that performs the sharpen
 *///from w  w  w.j  av a  2s  .co m
public byte[] sharpen(byte[] ibytes, int weight, String format) {
    /*
     * Kernel is |-1|-1|-1| |-1|weight|-1||-1|-1|-1|
     */
    try {
        InputStream is = new ByteArrayInputStream(ibytes);
        BufferedImage proxyimage = ImageIO.read(is);
        // a secondary image for storing new outcomes
        BufferedImage image2 = new BufferedImage(proxyimage.getWidth(), proxyimage.getHeight(),
                BufferedImage.TYPE_BYTE_GRAY);

        // image width and height
        int width = proxyimage.getWidth();
        int height = proxyimage.getHeight();
        int r = 0;
        int g = 0;
        int b = 0;
        Color c = null;
        for (int x = 1; x < width - 1; x++) {
            for (int y = 1; y < height - 1; y++) {
                // sharpen the image using the kernel (center is c5)
                Color c00 = new Color(proxyimage.getRGB(x - 1, y - 1));
                Color c01 = new Color(proxyimage.getRGB(x - 1, y));
                Color c02 = new Color(proxyimage.getRGB(x - 1, y + 1));
                Color c10 = new Color(proxyimage.getRGB(x, y - 1));
                Color c11 = new Color(proxyimage.getRGB(x, y));
                Color c12 = new Color(proxyimage.getRGB(x, y + 1));
                Color c20 = new Color(proxyimage.getRGB(x + 1, y - 1));
                Color c21 = new Color(proxyimage.getRGB(x + 1, y));
                Color c22 = new Color(proxyimage.getRGB(x + 1, y + 1));

                // apply the kernel for r
                r = -c00.getRed() - c01.getRed() - c02.getRed() - c10.getRed() + (weight * c11.getRed())
                        - c12.getRed() - c20.getRed() - c21.getRed() - c22.getRed();

                // apply the kernel for g
                g = c00.getGreen() - c01.getGreen() - c02.getGreen() - c10.getGreen()
                        + (weight * c11.getGreen()) - c12.getGreen() - c20.getGreen() - c21.getGreen()
                        - c22.getGreen();

                // apply the transformation for b
                b = c00.getBlue() - c01.getBlue() - c02.getBlue() - c10.getBlue() + (weight * c11.getBlue())
                        - c12.getBlue() - c20.getBlue() - c21.getBlue() - c22.getBlue();

                // set the new rgb values
                r = Math.min(255, Math.max(0, r));
                g = Math.min(255, Math.max(0, g));
                b = Math.min(255, Math.max(0, b));

                c = new Color(r, g, b);

                // set the new mask colors in the new image
                image2.setRGB(x, y, c.getRGB());

            }
        }

        // add the new values back to the original image
        Color cmask = null;
        Color corig = null;
        for (int x = 1; x < width - 1; x++) {
            for (int y = 1; y < height - 1; y++) {
                // get the 2 colors
                cmask = new Color(image2.getRGB(x, y));
                corig = new Color(proxyimage.getRGB(x, y));

                // add the new values
                r = cmask.getRed() + corig.getRed();
                g = cmask.getGreen() + corig.getGreen();
                b = cmask.getBlue() + corig.getBlue();

                // set the new rgb values
                r = Math.min(255, Math.max(0, r));
                g = Math.min(255, Math.max(0, g));
                b = Math.min(255, Math.max(0, b));

                proxyimage.setRGB(x, y, new Color(r, g, b).getRGB());
            }
        }

        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
            ImageIO.write(proxyimage, format, baos);
            ibytes = baos.toByteArray();
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return ibytes;
}