List of usage examples for java.awt Color getGreen
public int getGreen()
From source file:edu.ku.brc.af.prefs.AppPreferences.java
/** * @param name/* ww w . j a v a2 s . c om*/ * @param color */ public void putColor(final String name, final Color color) { put(name, String.format("%d, %d, %d", color.getRed(), color.getGreen(), color.getBlue())); //$NON-NLS-1$ }
From source file:umontreal.iro.lecuyer.charts.HistogramSeriesCollection.java
public String toLatex(double XScale, double YScale, double XShift, double YShift, double xmin, double xmax, double ymin, double ymax) { // Calcule les bornes reelles du graphique, en prenant en compte la position des axes xmin = Math.min(XShift, xmin); xmax = Math.max(XShift, xmax); ymin = Math.min(YShift, ymin); ymax = Math.max(YShift, ymax); CustomHistogramDataset tempSeriesCollection = (CustomHistogramDataset) seriesCollection; Formatter formatter = new Formatter(Locale.US); double var; double margin = ((XYBarRenderer) renderer).getMargin(); for (int i = tempSeriesCollection.getSeriesCount() - 1; i >= 0; i--) { List temp = tempSeriesCollection.getBins(i); ListIterator iter = temp.listIterator(); Color color = (Color) renderer.getSeriesPaint(i); String colorString = detectXColorClassic(color); if (colorString == null) { colorString = "color" + i; formatter.format("\\definecolor{%s}{rgb}{%.2f, %.2f, %.2f}%n", colorString, color.getRed() / 255.0, color.getGreen() / 255.0, color.getBlue() / 255.0); }/* ww w . j ava2 s .com*/ HistogramBin currentBin = null; while (iter.hasNext()) { double currentMargin; currentBin = (HistogramBin) iter.next(); currentMargin = ((margin * (currentBin.getEndBoundary() - currentBin.getStartBoundary()))) * XScale; if ((currentBin.getStartBoundary() >= xmin && currentBin.getStartBoundary() <= xmax) && (currentBin.getCount() >= ymin && currentBin.getCount() <= ymax)) { var = Math.min(currentBin.getEndBoundary(), xmax); if (filled[i]) { formatter.format( "\\filldraw [line width=%.2fpt, opacity=%.2f, color=%s] ([xshift=%.4f] %.4f, %.4f) rectangle ([xshift=-%.4f] %.4f, %.4f); %%%n", lineWidth[i], (color.getAlpha() / 255.0), colorString, currentMargin, (currentBin.getStartBoundary() - XShift) * XScale, 0.0, currentMargin, (var - XShift) * XScale, (currentBin.getCount() - YShift) * YScale); } else { formatter.format( "\\draw [line width=%.2fpt, color=%s] ([xshift=%.4f] %.4f, %.4f) rectangle ([xshift=-%.4f] %.4f, %.4f); %%%n", lineWidth[i], colorString, currentMargin, (currentBin.getStartBoundary() - XShift) * XScale, 0.0, currentMargin, (var - XShift) * XScale, (currentBin.getCount() - YShift) * YScale); } } else if ((currentBin.getStartBoundary() >= xmin && currentBin.getStartBoundary() <= xmax) && (currentBin.getCount() >= ymin && currentBin.getCount() > ymax)) { // Cas ou notre rectangle ne peut pas etre affiche en entier (trop haut) var = Math.min(currentBin.getEndBoundary(), xmax); if (filled[i]) { formatter.format( "\\filldraw [line width=%.2fpt, opacity=%.2f, color=%s] ([xshift=%.4f] %.4f, %.4f) rectangle ([xshift=-%.4f] %.4f, %.4f); %%%n", lineWidth[i], (color.getAlpha() / 255.0), colorString, currentMargin, (currentBin.getStartBoundary() - XShift) * XScale, 0.0, currentMargin, (var - XShift) * XScale, (ymax - YShift) * YScale); formatter.format( "\\draw [line width=%.2fpt, color=%s, style=dotted] ([xshift=%.4f] %.4f, %.4f) rectangle ([yshift=3mm, xshift=-%.4f] %.4f, %.4f); %%%n", lineWidth[i], colorString, currentMargin, (currentBin.getStartBoundary() - XShift) * XScale, (ymax - YShift) * YScale, currentMargin, (var - XShift) * XScale, (ymax - YShift) * YScale); } else { formatter.format( "\\draw [line width=%.2fpt, color=%s] ([xshift=%.4f] %.4f, %.4f) rectangle ([xshift=-%.4f] %.4f, %.4f); %%%n", lineWidth[i], colorString, currentMargin, (currentBin.getStartBoundary() - XShift) * XScale, 0.0, currentMargin, (var - XShift) * XScale, (ymax - YShift) * YScale); formatter.format( "\\draw [line width=%.2fpt, color=%s, style=dotted] ([xshift=%.4f] %.4f, %.4f) rectangle ([yshift=3mm, xshift=-%.4f] %.4f, %.4f); %%%n", lineWidth[i], colorString, currentMargin, (currentBin.getStartBoundary() - XShift) * XScale, (ymax - YShift) * YScale, currentMargin, (var - XShift) * XScale, (ymax - YShift) * YScale); } } } } return formatter.toString(); }
From source file:com.jaspersoft.studio.utils.ModelUtils.java
public static org.eclipse.swt.graphics.Color getSWTColorFromAWT(java.awt.Color awtColor) { return new org.eclipse.swt.graphics.Color(null, awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue()); }
From source file:net.chaosserver.timelord.swingui.CommonTaskPanel.java
/** * Builds the common task list in the main panel. This cycles through all * components currently in the task list and disposes of them. Then removes * them from the container. Afterwards it gets all TimelordTaskDays * associated with the displayDate and creates TaskDayPanels for them. This * is a slow operation and should be avoided. *//*from w w w .j a v a2 s . c o m*/ protected synchronized void buildTaskList() { // Dispose of the child components. disposeChildComponents(); // For good measure null out the listeners if (popupMenu != null) { popupMenu.setTaskDayPanel(null); } // Remove the components. commonTaskPanel.removeAll(); // After all components have been disposed of, cycle through all // the timelord days for ones with the display date and generate // new TaskDayPanels for each of them. Collection<TimelordTask> taskCollection = getTimelordDayView().getTaskCollection(); Iterator<TimelordTask> taskCollectionIterator = taskCollection.iterator(); int i = 0; while (taskCollectionIterator.hasNext()) { TimelordTask timelordTask = (TimelordTask) taskCollectionIterator.next(); TimelordTaskDay todayTaskDay; if (isToday()) { todayTaskDay = timelordTask.getToday(); } else { todayTaskDay = timelordTask.getTaskDay(this.getDateDisplayed()); } // If the task filter is on, show what matches fitler. // If not on, show all non-hidden and hidden with time tracked. boolean showLine = false; if (tasknameFilter == null || tasknameFilter.trim().length() == 0) { showLine = !timelordTask.isHidden() || todayTaskDay.getHours() > 0; } else { showLine = isFilterPassed(timelordTask, tasknameFilter); } if (showLine) { TaskDayPanel taskDayPanel; if (todayTaskDay != null) { taskDayPanel = new TaskDayPanel(timelordTask, todayTaskDay); } else { taskDayPanel = new TaskDayPanel(timelordTask, getDateDisplayed()); } // If this does not pass, then leave the original // color. if ((i % 2) != 0) { Color color = taskDayPanel.getBackground(); Color color2 = new Color(color.getRed() + LayoutConstants.LIGHTEN_AMOUNT, color.getGreen() + LayoutConstants.LIGHTEN_AMOUNT, color.getBlue() + LayoutConstants.LIGHTEN_AMOUNT); taskDayPanel.setBackground(color2); } commonTaskPanel.add(taskDayPanel); i++; } } // Now that we have rebuilt with todays data (or possibly build for // the first time) it may have triggered the creation of a bunch of // task days for today. So we reset the today listeners. This should // be the TimelordDayView's responsility, but putting it here allows // for a performance increase. // TODO jdr - This really shouldn't be the views responsibility. getTimelordData().resetTaskListeners(); // Force the container to re-layout the components in the layout // manager. this.doLayout(); this.validate(); }
From source file:architecture.common.util.TextUtils.java
/** * Convert Color to html hex string. (#012345) * // w w w .j av a 2 s .com * @param c * the Color to convert * @return A string with a hexadecimal RGB encoding */ public final static String colorToHex(java.awt.Color c) { String r = Integer.toHexString(c.getRed()); String g = Integer.toHexString(c.getGreen()); String b = Integer.toHexString(c.getBlue()); if (r.length() < 2) { r = '0' + r; } if (g.length() < 2) { g = '0' + g; } if (b.length() < 2) { b = '0' + b; } return '#' + r + g + b; }
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))); }// www . j a v a2 s . c o m //aaa.add(new XYDrawableAnnotation(timestamp,d,1,1,new AnnotationDrawer(cc))); } } //System.out.println("*****************************************************"); }
From source file:playground.christoph.evacuation.analysis.EvacuationTimePictureWriter.java
private ScreenOverlayType createHistogram(String transportMode, Map<Id, Double> evacuationTimes) throws IOException { /*//from w w w . j a v a2 s . co 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:gate.gui.docview.AnnotationStack.java
/** * Draw the annotation stack in a JPanel with a GridBagLayout. *///from w w w.j a v a2 s . c om 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:org.mrgeo.colorscale.ColorScale.java
/** * Find the color band that this value falls in and assign that color. * * @param v/*from ww w . j a v a2 s .co m*/ * @param color */ final private void absoluteValue(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 % (max - min); break; default: search = 0; break; } final Map.Entry<Double, Color> lower = floorEntry(search); Color c; if (lower == null) { c = entrySet().iterator().next().getValue(); } else { c = lower.getValue(); } color[R] = c.getRed(); color[G] = c.getGreen(); color[B] = c.getBlue(); color[A] = c.getAlpha(); }
From source file:org.broad.igv.renderer.SpliceJunctionRenderer.java
/** * Draw a filled arc representing a single feature. The thickness and height of the arc are proportional to the * depth of coverage. Some of this gets a bit arcane -- the result of lots of visual tweaking. * * @param pixelFeatureStart the starting position of the feature, whether on-screen or not * @param pixelFeatureEnd the ending position of the feature, whether on-screen or not * @param pixelJunctionStart the starting position of the junction, whether on-screen or not * @param pixelJunctionEnd the ending position of the junction, whether on-screen or not * @param depth coverage depth * @param trackRectangle//from www. ja v a2s . co m * @param context * @param strand * @param junctionFeature * @param shouldHighlight * @param featureColor the color specified for this feature. May be null. */ protected void drawFeature(int pixelFeatureStart, int pixelFeatureEnd, int pixelJunctionStart, int pixelJunctionEnd, float depth, Rectangle trackRectangle, RenderContext context, Strand strand, SpliceJunctionFeature junctionFeature, boolean shouldHighlight, Color featureColor, boolean shouldShowFlankingRegions) { boolean isPositiveStrand = true; // Get the feature's direction, color appropriately if (strand != null && strand.equals(Strand.NEGATIVE)) isPositiveStrand = false; //If the feature color is specified, use it, except that we set our own alpha depending on whether //the feature is highlighted. Otherwise default based on strand and highlight. Color color; if (featureColor != null) { int r = featureColor.getRed(); int g = featureColor.getGreen(); int b = featureColor.getBlue(); int alpha = shouldHighlight ? 255 : 140; color = new Color(r, g, b, alpha); } else { if (isPositiveStrand) color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_POS : ARC_COLOR_POS; else color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_NEG : ARC_COLOR_NEG; } Graphics2D g2D = context.getGraphic2DForColor(color); if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.ENABLE_ANTIALISING)) { g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } //Height of top of an arc of maximum depth int maxPossibleArcHeight = (trackRectangle.height - 1) / 2; if (shouldShowFlankingRegions) { if (junctionFeature.hasFlankingRegionDepthArrays()) { //draw a wigglegram of the splice junction flanking region depth of coverage int startFlankingRegionPixelLength = pixelJunctionStart - pixelFeatureStart; int endFlankingRegionPixelLength = pixelFeatureEnd - pixelJunctionEnd; drawFlankingRegion(g2D, pixelFeatureStart, startFlankingRegionPixelLength, junctionFeature.getStartFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle, isPositiveStrand); drawFlankingRegion(g2D, pixelJunctionEnd + 1, endFlankingRegionPixelLength, junctionFeature.getEndFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle, isPositiveStrand); } else { //Draw rectangles indicating the overlap on each side of the junction int overlapRectHeight = 3; int overlapRectTopX = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -2 : 0); if (pixelFeatureStart < pixelJunctionStart) { g2D.fillRect(pixelFeatureStart, overlapRectTopX, pixelJunctionStart - pixelFeatureStart, overlapRectHeight); } if (pixelJunctionEnd < pixelFeatureEnd) { g2D.fillRect(pixelJunctionEnd, overlapRectTopX, pixelFeatureEnd - pixelJunctionEnd, overlapRectHeight); } } } //Create a path describing the arc, using Bezier curves. The Bezier control points for the top and //bottom arcs are based on the boundary points of the rectangles containing the arcs //proportion of the maximum arc height used by a minimum-height arc double minArcHeightProportion = 0.33; int innerArcHeight = (int) (maxPossibleArcHeight * minArcHeightProportion); float depthProportionOfMax = Math.min(1, depth / maxDepth); int arcWidth = Math.max(1, (int) ((1 - minArcHeightProportion) * maxPossibleArcHeight * depthProportionOfMax)); int outerArcHeight = innerArcHeight + arcWidth; //Height of bottom of the arc int arcBeginY = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -1 : 1); int outerArcPeakY = isPositiveStrand ? arcBeginY - outerArcHeight : arcBeginY + outerArcHeight; int innerArcPeakY = isPositiveStrand ? arcBeginY - innerArcHeight : arcBeginY + innerArcHeight; //dhmay: I don't really understand Bezier curves. For some reason I have to put the Bezier control //points farther up or down than I want the arcs to extend. This multiplier seems about right int outerBezierY = arcBeginY + (int) (1.3 * (outerArcPeakY - arcBeginY)); int innerBezierY = arcBeginY + (int) (1.3 * (innerArcPeakY - arcBeginY)); //Putting the Bezier control points slightly off to the sides of the arc int bezierXPad = Math.max(1, (pixelJunctionEnd - pixelJunctionStart) / 30); GeneralPath arcPath = new GeneralPath(); arcPath.moveTo(pixelJunctionStart, arcBeginY); arcPath.curveTo(pixelJunctionStart - bezierXPad, outerBezierY, //Bezier 1 pixelJunctionEnd + bezierXPad, outerBezierY, //Bezier 2 pixelJunctionEnd, arcBeginY); //Arc end arcPath.curveTo(pixelJunctionEnd + bezierXPad, innerBezierY, //Bezier 1 pixelJunctionStart - bezierXPad, innerBezierY, //Bezier 2 pixelJunctionStart, arcBeginY); //Arc end //Draw the arc, to ensure outline is drawn completely (fill won't do it, necessarily). This will also //give the arc a darker outline g2D.draw(arcPath); //Fill the arc g2D.fill(arcPath); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT); g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); }