List of usage examples for java.awt Color getRed
public int getRed()
From source file:net.ontopia.topicmaps.viz.VizTopicMapConfigurationManager.java
/** * Sets the color for this association or topic type in the topic map. */// ww w .ja v a2 s . com private void setColor(TopicIF type, TopicIF occtype, Color c) { setOccurenceValue(type, occtype, c.getRed() + " " + c.getGreen() + " " + c.getBlue()); }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Returns <code>true</code> if the passed colors are the same, * <code>false</code> otherwise. * // w w w . j av a 2 s . co m * @param c1 One of the colors to check. * @param c2 One of the colors to check. * @param alpha Pass <code>true</code> to take into account the * alpha component, <code>false</code> otherwise. * @return See above. */ public static boolean isSameColors(Color c1, Color c2, boolean alpha) { if (c1 == null || c2 == null) return false; if (c1.getRed() != c2.getRed()) return false; if (c1.getGreen() != c2.getGreen()) return false; if (c1.getBlue() != c2.getBlue()) return false; if (alpha) { if (c1.getAlpha() != c2.getAlpha()) return false; } return true; }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Converts the passed color.// ww w .ja v a2 s .c o m * * @param c The color to handle. * @return See above. */ public static int convertColor(Color c) { int alpha = c.getAlpha(); if (alpha == 0) alpha = 255; return ((alpha & 0xFF) << 24) | ((c.getRed() & 0xFF) << 16) | ((c.getGreen() & 0xFF) << 8) | ((c.getBlue() & 0xFF) << 0); }
From source file:org.apache.fop.render.pcl.PCLGenerator.java
/** * Generates a user-defined pattern for a dithering pattern matching the grayscale value * of the color given./*from w w w . ja v a2 s. c o m*/ * @param col the color to create the pattern for * @param patternID the pattern ID to use * @param ditherMatrixSize the size of the Bayer dither matrix to use (4 or 8 supported) * @throws IOException In case of an I/O error */ public void defineGrayscalePattern(Color col, int patternID, int ditherMatrixSize) throws IOException { ByteArrayOutputStream baout = new ByteArrayOutputStream(); DataOutputStream data = new DataOutputStream(baout); data.writeByte(0); //Format data.writeByte(0); //Continuation data.writeByte(1); //Pixel Encoding data.writeByte(0); //Reserved data.writeShort(8); //Width in Pixels data.writeShort(8); //Height in Pixels //data.writeShort(600); //X Resolution (didn't manage to get that to work) //data.writeShort(600); //Y Resolution int gray255 = convertToGray(col.getRed(), col.getGreen(), col.getBlue()); byte[] pattern; if (ditherMatrixSize == 8) { pattern = DitherUtil.getBayerDither(DitherUtil.DITHER_MATRIX_8X8, gray255, false); } else { //Since a 4x4 pattern did not work, the 4x4 pattern is applied 4 times to an //8x8 pattern. Maybe this could be changed to use an 8x8 bayer dither pattern //instead of the 4x4 one. pattern = DitherUtil.getBayerDither(DitherUtil.DITHER_MATRIX_4X4, gray255, true); } data.write(pattern); if ((baout.size() % 2) > 0) { baout.write(0); } writeCommand("*c" + patternID + "G"); writeCommand("*c" + baout.size() + "W"); baout.writeTo(this.out); writeCommand("*c4Q"); //temporary pattern }
From source file:monitor.processing.OLD.SoccerField.java
public void drawTree(BaseNode n, RealVector v) { Color c = Color.WHITE; if (n instanceof TransformNode) { v = ((TransformNode) n).getTrasformMatrix().operate(v); c = Color.ORANGE;// ww w .jav a 2 s. c o m } else if (n instanceof StaticMesh) { StaticMesh sm = (StaticMesh) n; if (sm.isTransparent()) { c = Color.BLUE; } else if (sm.isVisible()) { // System.out.println(n.getInfo()); // System.out.println(v); c = Color.RED; if (sm.getModel().contains("naohead") || sm.getModel().contains("naobody")) { c = Color.PINK; } } else { c = Color.CYAN; } } else if (n instanceof StaticMeshNode) { StaticMeshNode smn = (StaticMeshNode) n; if (smn.isTransparent()) { c = Color.GREEN; // cameraSceneX = (float)v.getEntry(0); // cameraSceneY = (float)v.getEntry(1); // cameraSceneZ = (float)v.getEntry(2); } else if (smn.isVisible()) { c = Color.YELLOW; } else { c = Color.MAGENTA; } } pushMatrix(); fill(100); // c = Color.getHSBColor(n.getAddress()*0.05f, 1, 1); stroke(c.getRed(), c.getGreen(), c.getBlue()); translate((float) (scale * v.getEntry(0)), (float) (-scale * v.getEntry(1)), (float) (scale * v.getEntry(2))); box(5); popMatrix(); for (int a = n.getChildren().size() - 1; a >= 0; a--) { drawTree(((ArrayList<BaseNode>) n.getChildren()).get(a), v); } }
From source file:smlm.util.SRutil.java
public static Color getGradientColor(Color ini, Color fin, int numberOfSteps, int step) { if (numberOfSteps == 0) return ini; if (step % numberOfSteps == 0) return ini; if (step % numberOfSteps == numberOfSteps - 1) return fin; else {/*from w w w. j a va 2 s . c o m*/ float[] hsbini = Color.RGBtoHSB(ini.getRed(), ini.getGreen(), ini.getBlue(), null); float[] hsbfin = Color.RGBtoHSB(fin.getRed(), fin.getGreen(), fin.getBlue(), null); float h = ((numberOfSteps - step % numberOfSteps) * hsbini[0] + (step % numberOfSteps) * hsbfin[0]) / numberOfSteps; float s = ((numberOfSteps - step % numberOfSteps) * hsbini[1] + (step % numberOfSteps) * hsbfin[1]) / numberOfSteps; float b = ((numberOfSteps - step % numberOfSteps) * hsbini[2] + (step % numberOfSteps) * hsbfin[2]) / numberOfSteps; return Color.getHSBColor(h, s, b); } }
From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java
/** * *///ww w . j a v a2 s.c o m private static void preparePen(PdfContentByte pdfContentByte, JRPen pen, int lineCap) { float lineWidth = pen.getLineWidth(); if (lineWidth <= 0) { return; } pdfContentByte.setLineWidth(lineWidth); pdfContentByte.setLineCap(lineCap); Color color = pen.getLineColor(); pdfContentByte.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue()); switch (pen.getLineStyleValue()) { case DOUBLE: { pdfContentByte.setLineWidth(lineWidth / 3); pdfContentByte.setLineDash(0f); break; } case DOTTED: { switch (lineCap) { case PdfContentByte.LINE_CAP_BUTT: { pdfContentByte.setLineDash(lineWidth, lineWidth, 0f); break; } case PdfContentByte.LINE_CAP_PROJECTING_SQUARE: { pdfContentByte.setLineDash(0, 2 * lineWidth, 0f); break; } } break; } case DASHED: { switch (lineCap) { case PdfContentByte.LINE_CAP_BUTT: { pdfContentByte.setLineDash(5 * lineWidth, 3 * lineWidth, 0f); break; } case PdfContentByte.LINE_CAP_PROJECTING_SQUARE: { pdfContentByte.setLineDash(4 * lineWidth, 4 * lineWidth, 0f); break; } } break; } case SOLID: default: { pdfContentByte.setLineDash(0f); break; } } }
From source file:userinterface.graph.Graph.java
/** * Allows graphs to be saved to the PRISM 'gra' file format. * //from www . ja v a2s . c om * @param file * The file to save the graph to. * @throws GraphException * If the file cannot be written. */ public void save(File file) throws PrismException { try { JFreeChart chart = getChart(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); Element chartFormat = doc.createElement("chartFormat"); chartFormat.setAttribute("versionString", prism.Prism.getVersion()); chartFormat.setAttribute("graphTitle", getTitle()); Font titleFont = getTitleFont().f; chartFormat.setAttribute("titleFontName", titleFont.getName()); chartFormat.setAttribute("titleFontSize", "" + titleFont.getSize()); chartFormat.setAttribute("titleFontStyle", "" + titleFont.getStyle()); Color titleFontColor = (Color) getTitleFont().c; chartFormat.setAttribute("titleFontColourR", "" + titleFontColor.getRed()); chartFormat.setAttribute("titleFontColourG", "" + titleFontColor.getGreen()); chartFormat.setAttribute("titleFontColourB", "" + titleFontColor.getBlue()); chartFormat.setAttribute("legendVisible", isLegendVisible() ? "true" : "false"); Font legendFont = getLegendFont().f; chartFormat.setAttribute("legendFontName", "" + legendFont.getName()); chartFormat.setAttribute("legendFontSize", "" + legendFont.getSize()); chartFormat.setAttribute("legendFontStyle", "" + legendFont.getStyle()); Color legendFontColor = getLegendFont().c; chartFormat.setAttribute("legendFontColourR", "" + legendFontColor.getRed()); chartFormat.setAttribute("legendFontColourG", "" + legendFontColor.getGreen()); chartFormat.setAttribute("legendFontColourB", "" + legendFontColor.getBlue()); switch (getLegendPosition()) { case LEFT: chartFormat.setAttribute("legendPosition", "left"); break; case BOTTOM: chartFormat.setAttribute("legendPosition", "bottom"); break; case TOP: chartFormat.setAttribute("legendPosition", "top"); break; default: chartFormat.setAttribute("legendPosition", "right"); } Element layout = doc.createElement("layout"); chartFormat.appendChild(layout); Element xAxis = doc.createElement("axis"); getXAxisSettings().save(xAxis); chartFormat.appendChild(xAxis); Element yAxis = doc.createElement("axis"); getYAxisSettings().save(yAxis); chartFormat.appendChild(yAxis); synchronized (getSeriesLock()) { /* Make sure we preserve ordering. */ for (int i = 0; i < seriesList.getSize(); i++) { SeriesKey key = seriesList.getKeyAt(i); Element series = doc.createElement("graph"); SeriesSettings seriesSettings = getGraphSeries(key); seriesSettings.save(series); XYSeries seriesData = getXYSeries(key); for (int j = 0; j < seriesData.getItemCount(); j++) { Element point = doc.createElement("point"); point.setAttribute("x", "" + seriesData.getX(j)); point.setAttribute("y", "" + seriesData.getY(j)); series.appendChild(point); } chartFormat.appendChild(series); } } doc.appendChild(chartFormat); // File writing Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty("doctype-system", "chartformat.dtd"); t.setOutputProperty("indent", "yes"); t.transform(new DOMSource(doc), new StreamResult(new FileOutputStream(file))); } catch (IOException e) { throw new PrismException(e.getMessage()); } catch (DOMException e) { throw new PrismException("Problem saving graph: DOM Exception: " + e); } catch (ParserConfigurationException e) { throw new PrismException("Problem saving graph: Parser Exception: " + e); } catch (TransformerConfigurationException e) { throw new PrismException("Problem saving graph: Error in creating XML: " + e); } catch (TransformerException e) { throw new PrismException("Problem saving graph: Transformer Exception: " + e); } catch (SettingException e) { throw new PrismException(e.getMessage()); } }
From source file:savant.view.tracks.BAMTrackRenderer.java
private Shape renderRead(Graphics2D g2, GraphPaneAdapter gp, BAMIntervalRecord rec, int level, Range range, double readHeight) { SAMRecord samRec = rec.getSAMRecord(); boolean reverseStrand = samRec.getReadNegativeStrandFlag(); ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); Color readColor = cs.getColor(reverseStrand ? ColourKey.REVERSE_STRAND : ColourKey.FORWARD_STRAND); Color override = rec.getColor(); if (override != null) { readColor = override;/*from www .java2s . c om*/ } if ((Boolean) instructions.get(DrawingInstruction.MAPPING_QUALITY)) { int alpha = getConstrainedAlpha(samRec.getMappingQuality()); readColor = new Color(readColor.getRed(), readColor.getGreen(), readColor.getBlue(), alpha); } // cutoffs to determine when not to draw double leftMostX = gp.transformXPos(range.getFrom()); double rightMostX = gp.transformXPos(range.getTo() + 1); //y = gp.transformYPos(0) - (level + 1)*unitHeight; double x = gp.transformXPos(rec.getInterval().getStart()); double y = gp.transformYPos(0) - (level + 1) * readHeight - gp.getOffset(); double w = rec.getInterval().getLength() * gp.getUnitWidth(); // cut off x and w so no drawing happens off-screen double x2; if (rightMostX < x + w) { x2 = rightMostX; } else { x2 = x + w; } if (leftMostX > x) { x = leftMostX; } w = x2 - x; Shape pointyBar = getPointyBar(reverseStrand, x, y, w, readHeight); // Only fill in the read if we're not going to slam bases on top of it. boolean baseQuality = (Boolean) instructions.get(DrawingInstruction.BASE_QUALITY); if (lastMode != DrawingMode.SEQUENCE && !baseQuality) { g2.setColor(readColor); g2.fill(pointyBar); } // Render individual bases/mismatches as appropriate for the current mode. if (lastMode != DrawingMode.STANDARD || baseQuality) { renderBases(g2, gp, samRec, level, refSeq, range, readHeight); } // Draw outline, if there's room if (pointyBar.getBounds().getHeight() >= 4.0) { g2.setColor(cs.getColor(ColourKey.INTERVAL_LINE)); g2.draw(pointyBar); } return pointyBar; }
From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java
private void updateGraph() { XYSeriesCollection dataset = new XYSeriesCollection(); Collection<Stairs> loadProfileEnities = transform( filter(loadProfilesController.getTreeItems(), new IsStairsPredicate()), new LoadProfileEntityToStairsFunction()); GraphPointsCalculator calc = new GraphPointsCalculator(); Map<String, Set<Point>> pointsMap = calc.calculatePoints(loadProfileEnities); for (Entry<String, Set<Point>> entry : pointsMap.entrySet()) { final XYSeries series = new XYSeries(entry.getKey()); for (Point point : entry.getValue()) { series.add(point.getX(), point.getY()); }//from w w w. j ava 2s . c o m dataset.addSeries(series); } String name = txtName.getText(); chart = ChartFactory.createXYLineChart(name, "t (min)", "Executions (1/h)", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRenderer(renderer); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); double maxX = 0; for (OneTime oneTime : getOneTimes()) { String key = oneTime.operation.getName(); XYSeries series; try { // We need the series in order to retrieve paint and stroke series = dataset.getSeries(key); } catch (UnknownKeyException ex) { series = new XYSeries(key); dataset.addSeries(series); } int index = dataset.getSeriesIndex(key); BasicStroke stroke = (BasicStroke) renderer.lookupSeriesStroke(index); stroke = new BasicStroke(stroke.getLineWidth() + 1f, stroke.getEndCap(), stroke.getLineJoin(), stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()); Color paint = (Color) renderer.lookupSeriesPaint(index); paint = new Color(paint.getRed(), paint.getGreen(), paint.getBlue(), 160); double height = rangeAxis.getUpperBound() * .05; // five percent of range double width = domainAxis.getUpperBound() * .01; // one percent of range double center = oneTime.t0; double left = center - width / 2; double right = center + width / 2; // We only add annotations for one times, but nothing to the series plot.addAnnotation(new XYPolygonAnnotation(new double[] { left, 0d, center, height, right, 0d }, stroke, paint, paint)); maxX = max(maxX, right); } for (Marker marker : getMarkers()) { IntervalMarker im = new IntervalMarker(marker.left, marker.right); im.setLabel(marker.name); im.setLabelFont(new Font(getFont().getName(), getFont().getStyle(), getFont().getSize() + 1)); im.setLabelAnchor(RectangleAnchor.TOP); im.setLabelOffset(new RectangleInsets(8d, 0d, 0d, 0d)); im.setLabelPaint(Color.BLACK); im.setAlpha(.3f); im.setPaint(Color.WHITE); im.setOutlinePaint(Color.BLACK); im.setOutlineStroke(new BasicStroke(1.0f)); plot.addDomainMarker(im, Layer.BACKGROUND); maxX = max(maxX, marker.right); } if (domainAxis.getUpperBound() < maxX) { domainAxis.setUpperBound(maxX * 1.05); } chartPanel.setChart(chart); }