List of usage examples for java.awt Color getBlue
public int getBlue()
From source file:lcmc.common.ui.ResourceGraph.java
/** Draws text on the vertex. */ private void drawVertexText(final Graphics2D g2d, final TextLayout textLayout, final double x, final double y, final Color color, final int alpha) { if (color != null) { g2d.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha)); }// w ww. j a va 2 s .c om textLayout.draw(g2d, (float) x, (float) y); }
From source file:userinterface.graph.Graph.java
/** * Allows graphs to be saved to the PRISM 'gra' file format. * /* www .java 2 s.co m*/ * @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:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
/** * Utility function to update a scatterplot line's data series. * @param data the datagraph data.// www .j a v a 2 s. c o m * @param sheet the Excel sheet which contains corresponding data from the scatterplot data series. * @param seriesIdx the index of the data in the dategraph data. * @param series the XML object representing the series in the chart. */ private static void updateCTScatterSer(final DategraphData data, final XSSFSheet sheet, final int seriesIdx, final CTScatterSer series) { final String sheetName = sheet.getSheetName(); // the series idx starts from 0 final DategraphData.Row row = data.getRows().get(seriesIdx); final String title = row.getLabel(); final Color color = Color.decode(row.getColor()); series.getOrder().setVal(seriesIdx); series.getIdx().setVal(seriesIdx); final CTSolidColorFillProperties fill = series.getSpPr().getLn().getSolidFill(); // We have to set any possible colour type, PowerPoint throws an error if there's multiple fills, and we don't // know what colour type the user may have used in their template slide. if (fill.getSchemeClr() != null) { fill.unsetSchemeClr(); } if (fill.getSrgbClr() != null) { fill.unsetSrgbClr(); } if (fill.getHslClr() != null) { fill.unsetHslClr(); } if (fill.getPrstClr() != null) { fill.unsetPrstClr(); } if (fill.getScrgbClr() != null) { fill.unsetScrgbClr(); } if (fill.getSysClr() != null) { fill.unsetSysClr(); } final CTSRgbColor fillClr = fill.addNewSrgbClr(); final byte[] colorBytes = { (byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue() }; fillClr.setVal(colorBytes); final CTMarker marker = series.getMarker(); if (marker != null) { final CTShapeProperties markerSpPr = marker.getSpPr(); unsetSpPrFills(markerSpPr); markerSpPr.addNewSolidFill().addNewSrgbClr().setVal(colorBytes); final CTLineProperties markerLn = markerSpPr.getLn(); if (markerLn != null) { unsetLineFills(markerLn); markerLn.addNewSolidFill().addNewSrgbClr().setVal(colorBytes); } } final CTStrRef strRef = series.getTx().getStrRef(); strRef.getStrCache().getPtArray()[0].setV(title); strRef.setF(new CellReference(sheetName, 0, seriesIdx + 1, true, true).formatAsString()); final long[] timestamps = data.getTimestamps(); { final CTNumRef timestampCatNumRef = series.getXVal().getNumRef(); timestampCatNumRef.setF(new AreaReference(new CellReference(sheetName, 1, 0, true, true), new CellReference(sheetName, 1 + timestamps.length, 0, true, true)).formatAsString()); final CTNumData timeStampCatNumCache = timestampCatNumRef.getNumCache(); timeStampCatNumCache.getPtCount().setVal(timestamps.length); timeStampCatNumCache.setPtArray(null); for (int ii = 0; ii < timestamps.length; ++ii) { final CTNumVal pt = timeStampCatNumCache.addNewPt(); pt.setIdx(ii); pt.setV(sheet.getRow(1 + ii).getCell(0).getRawValue()); } } { final double[] seriesData = row.getValues(); final CTNumRef valuesNumRef = series.getYVal().getNumRef(); valuesNumRef.setF(new AreaReference(new CellReference(sheetName, 1, seriesIdx + 1, true, true), new CellReference(sheetName, 1 + timestamps.length, seriesIdx + 1, true, true)) .formatAsString()); final CTNumData valuesNumCache = valuesNumRef.getNumCache(); valuesNumCache.getPtCount().setVal(timestamps.length); valuesNumCache.setPtArray(null); for (int ii = 0; ii < timestamps.length; ++ii) { final CTNumVal pt = valuesNumCache.addNewPt(); pt.setIdx(ii); pt.setV(Double.toString(seriesData[ii])); } } }
From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java
private String serializeHighlightToString(Color cd) { if (cd != null) { int red = (cd.getRed() + 255) / 2; int green = (cd.getGreen() + 255) / 2; int blue = (cd.getBlue() + 255) / 2; String r = Integer.toHexString(red); if (red <= 0xF) r = "0" + r; //$NON-NLS-1$ String g = Integer.toHexString(green); if (green <= 0xF) g = "0" + g; //$NON-NLS-1$ String b = Integer.toHexString(blue); if (blue <= 0xF) b = "0" + b; //$NON-NLS-1$ return "#" + r + g + b; //$NON-NLS-1$ }/*from w w w . ja v a 2 s .c om*/ return ""; //$NON-NLS-1$ }
From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java
public void setXORMode(Color xorColor) { if ((color == null) || (xorColor == null)) return;//from w w w .ja v a 2 s .c o m int newColor = ((xorColor.getRed() << 16) + (xorColor.getGreen() << 8) + xorColor.getBlue()) ^ ((color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue()); int r = newColor >> 16 & 0x0000FF; int g = (0x00FF00 & newColor) >> 8; int b = 0x0000FF & newColor; color = new Color(r, g, b); }
From source file:com.alvermont.terraj.planet.ui.MainFrame.java
/** * Set a colour to a randomly chosen one * * @param source The button that was pressed to produce this action * @param index The index of the colour parameter to be set */// w ww .java 2 s.c o m protected void randomizeColour(JButton source, int index) { final Color newColour = randomColour(); source.setBackground(newColour); final int[][] colours = params.getProjectionParameters().getColors(); colours[index][0] = newColour.getRed(); colours[index][1] = newColour.getGreen(); colours[index][2] = newColour.getBlue(); }
From source file:ca.sqlpower.architect.swingui.SwingUIProjectLoader.java
private void savePlayPenComponents(PrintWriter out, PlayPen pp) { List<PlayPenComponent> ppcs = new ArrayList<PlayPenComponent>(); ppcs.addAll(pp.getContentPane().getChildren()); Collections.reverse(ppcs);/*from www .ja v a2s. c o m*/ // save the container panes. for (PlayPenComponent ppc : ppcs) { if (ppc instanceof TablePane) { TablePane tp = (TablePane) ppc; Point p = tp.getLocation(); if (sqlObjectSaveIdMap.get(tp.getModel()) == null) { logger.error("Play pen tried to save a table pane at " + tp.getX() + ", " + tp.getY() + " with the model " + tp.getModel() + " and reference id " + sqlObjectSaveIdMap.get(tp.getModel()) + "." + "\nSaving a table pane with a null reference will cause an NPE on loading."); throw new NullPointerException("Play pen table is saving a null reference."); } Color bgColor = tp.getBackgroundColor(); String bgColorString = String.format("0x%02x%02x%02x", bgColor.getRed(), bgColor.getGreen(), //$NON-NLS-1$ bgColor.getBlue()); Color fgColor = tp.getForegroundColor(); String fgColorString = String.format("0x%02x%02x%02x", fgColor.getRed(), fgColor.getGreen(), //$NON-NLS-1$ fgColor.getBlue()); ioo.println(out, "<table-pane table-ref=" + quote(sqlObjectSaveIdMap.get(tp.getModel())) //$NON-NLS-1$ + " x=\"" + p.x + "\" y=\"" + p.y + "\" bgColor=" + quote(bgColorString) + " fgColor=" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ + quote(fgColorString) + " rounded=\"" + tp.isRounded() + "\" dashed=\"" + tp.isDashed() + "\"/>"); //$NON-NLS-2$ //$NON-NLS-3$ if (pm != null) { pm.setProgress(++progress); } } else if (ppc instanceof CubePane) { CubePane cp = (CubePane) ppc; Point p = cp.getLocation(); String modelId = olapObjectSaveIdMap.get(cp.getModel()); String paneId = "CP" + olapPaneSaveIdMap.size(); //$NON-NLS-1$ ioo.println(out, "<cube-pane id=" + quote(paneId) + " model-ref=" + quote(modelId) //$NON-NLS-1$ //$NON-NLS-2$ + " x=\"" + p.x + "\" y=\"" + p.y + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ olapPaneSaveIdMap.put(cp, paneId); } else if (ppc instanceof DimensionPane) { DimensionPane dp = (DimensionPane) ppc; Point p = dp.getLocation(); String paneId = "DP" + olapPaneSaveIdMap.size(); String modelId = olapObjectSaveIdMap.get(dp.getModel()); ioo.println(out, "<dimension-pane id=" + quote(paneId) + " model-ref=" + quote(modelId) //$NON-NLS-1$ //$NON-NLS-2$ + " x=\"" + p.x + "\" y=\"" + p.y + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ olapPaneSaveIdMap.put(dp, paneId); } else if (ppc instanceof VirtualCubePane) { VirtualCubePane vcp = (VirtualCubePane) ppc; Point p = vcp.getLocation(); String paneId = "VCP" + olapPaneSaveIdMap.size(); String modelId = olapObjectSaveIdMap.get(vcp.getModel()); ioo.println(out, "<virtual-cube-pane id=" + quote(paneId) + " model-ref=" + quote(modelId) //$NON-NLS-1$ //$NON-NLS-2$ + " x=\"" + p.x + "\" y=\"" + p.y + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ olapPaneSaveIdMap.put(vcp, paneId); } else if (ppc instanceof ContainerPane<?, ?>) { logger.warn("Skipping unhandled playpen component: " + ppc); //$NON-NLS-1$ } } // save the connectors. for (PlayPenComponent ppc : ppcs) { if (ppc instanceof Relationship) { Relationship r = (Relationship) ppc; Color relationshipLineColor = r.getForegroundColor(); String rColorString = String.format("0x%02x%02x%02x", relationshipLineColor.getRed(), //$NON-NLS-1$ relationshipLineColor.getGreen(), relationshipLineColor.getBlue()); ioo.println(out, "<table-link relationship-ref=" + quote(sqlObjectSaveIdMap.get(r.getModel())) //$NON-NLS-1$ + " pkConnection=\"" + r.getPkConnection() + "\"" //$NON-NLS-1$ //$NON-NLS-2$ + " fkConnection=\"" + r.getFkConnection() + "\"" //$NON-NLS-1$ //$NON-NLS-2$ + " rLineColor=" + quote(rColorString) //$NON-NLS-1$ + " pkLabelText=" + quote(r.getTextForParentLabel()) //$NON-NLS-1$ + " fkLabelText=" + quote(r.getTextForChildLabel()) //$NON-NLS-1$ + " orientation=\"" + r.getOrientation() + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ } else if (ppc instanceof UsageComponent) { UsageComponent usageComp = (UsageComponent) ppc; String modelId = olapObjectSaveIdMap.get(usageComp.getModel()); String pane1Id = olapPaneSaveIdMap.get(usageComp.getPane1()); String pane2Id = olapPaneSaveIdMap.get(usageComp.getPane2()); ioo.println(out, "<usage-comp model-ref=" + quote(modelId) + //$NON-NLS-1$ " pane1-ref=" + quote(pane1Id) + " pane2-ref=" + quote(pane2Id) + "/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } else if (ppc instanceof ContainerPane<?, ?>) { // do nothing, already handled. } else { logger.warn("Skipping unhandled playpen component: " + ppc); //$NON-NLS-1$ } } }
From source file:org.apache.pdfbox.pdmodel.PDPageContentStream.java
/** * Set the stroking color using an AWT color. Conversion uses the default sRGB color space. * * @param color The color to set./* ww w.ja v a 2 s . co m*/ * @throws IOException If an IO error occurs while writing to the stream. */ public void setStrokingColor(Color color) throws IOException { float[] components = new float[] { color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f }; PDColor pdColor = new PDColor(components, PDDeviceRGB.INSTANCE); setStrokingColor(pdColor); }
From source file:org.apache.pdfbox.pdmodel.PDPageContentStream.java
/** * Set the non-stroking color using an AWT color. Conversion uses the default sRGB color space. * * @param color The color to set./*from ww w . j a v a2 s .co m*/ * @throws IOException If an IO error occurs while writing to the stream. */ public void setNonStrokingColor(Color color) throws IOException { float[] components = new float[] { color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f }; PDColor pdColor = new PDColor(components, PDDeviceRGB.INSTANCE); setNonStrokingColor(pdColor); }
From source file:savant.view.tracks.BAMTrackRenderer.java
/** * Render the individual bases on top of the read. Depending on the drawing * mode this can be either bases read or mismatches. *///from w w w .java 2s. co m private void renderBases(Graphics2D g2, GraphPaneAdapter gp, SAMRecord samRecord, int level, byte[] refSeq, Range range, double unitHeight) { ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); boolean baseQualityEnabled = (Boolean) instructions.get(DrawingInstruction.BASE_QUALITY); boolean drawingAllBases = lastMode == DrawingMode.SEQUENCE || baseQualityEnabled; double unitWidth = gp.getUnitWidth(); int offset = gp.getOffset(); // Cutoffs to determine when not to draw double leftMostX = gp.transformXPos(range.getFrom()); double rightMostX = gp.transformXPos(range.getTo()) + unitWidth; int alignmentStart = samRecord.getAlignmentStart(); byte[] readBases = samRecord.getReadBases(); byte[] baseQualities = samRecord.getBaseQualities(); boolean sequenceSaved = readBases.length > 0; Cigar cigar = samRecord.getCigar(); // Absolute positions in the reference sequence and the read bases, set after each cigar operator is processed int sequenceCursor = alignmentStart; int readCursor = alignmentStart; List<Rectangle2D> insertions = new ArrayList<Rectangle2D>(); FontMetrics fm = g2.getFontMetrics(MISMATCH_FONT); Rectangle2D charRect = fm.getStringBounds("G", g2); boolean fontFits = charRect.getWidth() <= unitWidth && charRect.getHeight() <= unitHeight; if (fontFits) { g2.setFont(MISMATCH_FONT); } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (CigarElement cigarElement : cigar.getCigarElements()) { int operatorLength = cigarElement.getLength(); CigarOperator operator = cigarElement.getOperator(); Rectangle2D.Double opRect = null; double opStart = gp.transformXPos(sequenceCursor); double opWidth = operatorLength * unitWidth; // Cut off start and width so no drawing happens off-screen, must be done in the order w, then x, since w depends on first value of x double x2 = Math.min(rightMostX, opStart + opWidth); opStart = Math.max(leftMostX, opStart); opWidth = x2 - opStart; switch (operator) { case D: // Deletion if (opWidth > 0.0) { renderDeletion(g2, gp, opStart, level, operatorLength, unitHeight); } break; case I: // Insertion insertions.add(new Rectangle2D.Double(gp.transformXPos(sequenceCursor), gp.transformYPos(0) - ((level + 1) * unitHeight) - gp.getOffset(), unitWidth, unitHeight)); break; case M: // Match or mismatch case X: case EQ: // some SAM files do not contain the read bases if (sequenceSaved || operator == CigarOperator.X) { for (int i = 0; i < operatorLength; i++) { // indices into refSeq and readBases associated with this position in the cigar string int readIndex = readCursor - alignmentStart + i; boolean mismatched = false; if (operator == CigarOperator.X) { mismatched = true; } else { int refIndex = sequenceCursor + i - range.getFrom(); if (refIndex >= 0 && refSeq != null && refIndex < refSeq.length) { mismatched = refSeq[refIndex] != readBases[readIndex]; } } if (mismatched || drawingAllBases) { Color col; if ((mismatched && lastMode != DrawingMode.STANDARD) || lastMode == DrawingMode.SEQUENCE) { col = cs.getBaseColor((char) readBases[readIndex]); } else { col = cs.getColor(samRecord.getReadNegativeStrandFlag() ? ColourKey.REVERSE_STRAND : ColourKey.FORWARD_STRAND); } if (baseQualityEnabled && col != null) { col = new Color(col.getRed(), col.getGreen(), col.getBlue(), getConstrainedAlpha( (int) Math.round((baseQualities[readIndex] * 0.025) * 255))); } double xCoordinate = gp.transformXPos(sequenceCursor + i); double top = gp.transformYPos(0) - ((level + 1) * unitHeight) - offset; if (col != null) { opRect = new Rectangle2D.Double(xCoordinate, top, unitWidth, unitHeight); g2.setColor(col); g2.fill(opRect); } if (lastMode != DrawingMode.SEQUENCE && mismatched && fontFits) { // If it's a real mismatch, we want to draw the base letter (space permitting). g2.setColor(new Color(10, 10, 10)); String s = new String(readBases, readIndex, 1); charRect = fm.getStringBounds(s, g2); g2.drawString(s, (float) (xCoordinate + (unitWidth - charRect.getWidth()) * 0.5), (float) (top + fm.getAscent() + (unitHeight - charRect.getHeight()) * 0.5)); } } } } break; case N: // Skipped opRect = new Rectangle2D.Double(opStart, gp.transformYPos(0) - ((level + 1) * unitHeight) - offset, opWidth, unitHeight); g2.setColor(cs.getColor(ColourKey.SKIPPED)); g2.fill(opRect); break; default: // P - passing, H - hard clip, or S - soft clip break; } if (operator.consumesReadBases()) { readCursor += operatorLength; } if (operator.consumesReferenceBases()) { sequenceCursor += operatorLength; } } for (Rectangle2D ins : insertions) { drawInsertion(g2, ins.getX(), ins.getY(), ins.getWidth(), ins.getHeight()); } }