List of usage examples for java.awt Color gray
Color gray
To view the source code for java.awt Color gray.
Click Source Link
From source file:com.juanhg.triangle.TriangleApplet.java
public void updateTriangle(double z) { double[] polygon = new double[6]; polygon[1] = polygon[0] = polygon[3] = polygon[4] = 0; polygon[2] = model.getA(z);//ww w . j a va 2s .c om polygon[5] = model.getB(z); yPulley = polygon[5] + 1; double yIncrement = normalize(60 - z, 0, 40, 0, 0.3); double xIncrement = normalize(z, 20, 60, 0, 0.09); oYBox = yBox = model.getB(z) + yIncrement; oXBox = xBox + xIncrement; chartTriangle.deleteAnnotation(ropeAnnotation); ropeAnnotation = chartTriangle.drawLine(xPulley, yPulley + 0.5, xBox, yBox, new BasicStroke(4f), Color.BLACK); chartTriangle.deleteAnnotation(baseAnnotation); baseAnnotation = chartTriangle.setImageAtPoint(baseImage, xBase, polygon[5] - 0.1); chartTriangle.deleteAnnotation(pulleyAnnotation); pulleyAnnotation = chartTriangle.setImageAtPoint(pulleyImage(), xPulley, yPulley); chartTriangle.deleteAnnotation(triangleAnnotation); triangleAnnotation = new XYPolygonAnnotation(polygon, new BasicStroke(2f), Color.BLACK, Color.gray); chartTriangle.setAnnotation(triangleAnnotation); boxImage = ImageProcessing.rotateDegrees(oBoxImage, -z); chartTriangle.deleteAnnotation(boxAnnotation); boxAnnotation = chartTriangle.setImageAtPoint(boxImage, xBox + xIncrement, yBox); updatePanels(); repaint(); }
From source file:ca.nines.ise.writer.RTFWriter.java
@Override public void render(DOM dom, Annotation annotation) throws DocumentException, IOException { this.preprocess(dom, annotation); fontStack = new ArrayDeque<>(); fontStack.push(FontFactory.getFont("Times New Roman", 12, Color.BLACK)); Font font;/*w ww .j a v a2 s . co m*/ boolean inSP = false; // in speech prefix boolean inSD = false; // in stage direction boolean inDQ = false; // in a double quote boolean inS = false; // in a speech boolean inHW = false; char part = 'i'; String mode = "verse"; doc.open(); startParagraph(); for (Node n : dom) { switch (n.type()) { case ABBR: break; case CHAR: addChunk(n.unicode()); break; case EMPTY: switch (n.getName()) { case "FNLOC": EmptyNode fnloc = (EmptyNode) n; Note note = annotation.get(Integer.parseInt(fnloc.getAttribute("ref")) - 1); if (!note.hasNoteLevel("1")) { break; } this.footnote(note); break; case "TLN": case "L": if (mode.equals("prose")) { break; } if (inS) { startParagraph(p2); } else { startParagraph(p1); } EmptyNode en = (EmptyNode) n; if (en.hasAttribute("part")) { part = en.getAttribute("part").charAt(0); } else { part = 'i'; } break; } break; case END: switch (n.getName()) { case "FOREIGN": fontStack.pop(); break; case "HW": inHW = false; break; case "I": fontStack.pop(); break; case "LD": startParagraph(); break; case "S": inS = false; break; case "SD": fontStack.pop(); inSD = false; break; case "SP": addChunk(". "); inSP = false; break; } break; case START: switch (n.getName()) { case "FOREIGN": font = new Font(fontStack.getFirst()); font.setStyle(Font.ITALIC); fontStack.push(font); break; case "HW": inHW = true; break; case "I": font = new Font(fontStack.getFirst()); font.setStyle(Font.ITALIC); fontStack.push(font); break; case "LD": startParagraph(ld); break; case "MODE": mode = ((TagNode) n).getAttribute("t"); break; case "S": if (mode.equals("prose")) { startParagraph(prose); } inS = true; break; case "SD": font = new Font(fontStack.getFirst()); font.setStyle(Font.ITALIC); StartNode start = (StartNode) n; if (start.hasAttribute("t") && start.getAttribute("t").contains("exit")) { startParagraph(exit); } if (start.hasAttribute("t") && start.getAttribute("t").contains("optional")) { font.setColor(Color.GRAY); } fontStack.push(font); inSD = true; break; case "SP": inSP = true; break; } break; case TEXT: String txt = n.getText(); txt = txt.replace("--", "\u2014"); txt = txt.replace("\n", ""); if (inSP) { addChunk(txt.toUpperCase()); break; } if (inHW) { txt = txt.replaceFirst("[(]", ""); inHW = false; } if (inSD) { // DOES NOT MATCH AFTER A TAG. if ((txt.indexOf('[') >= 0) || (txt.indexOf(']') >= 0)) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < txt.length(); i++) { char c = txt.charAt(i); if (c == '[' || c == ']') { if (sb.length() > 0) { addChunk(sb.toString()); sb = new StringBuilder(); } addDirect("{\\i0" + String.valueOf(c) + "}"); } else { sb.append(c); } } if (sb.length() > 0) { addChunk(sb.toString()); } break; } else { addChunk(txt); break; } } if (part != 'i' && inS) { RtfTab tab = null; String tabStr = ""; if (part == 'm') { tab = new RtfTab(100, RtfTab.TAB_LEFT_ALIGN); tabStr = "\t"; } if (part == 'f') { tab = new RtfTab(200, RtfTab.TAB_LEFT_ALIGN); tabStr = "\t\t"; } if (tab != null) { p.add(tab); addChunk(tabStr); } part = 'i'; // ensure it's only done once for m or f. } // fix quotation marks. StringBuilder sb = new StringBuilder(); for (int i = 0; i < txt.length(); i++) { char c = txt.charAt(i); switch (c) { case '"': if (inDQ) { // typographer's end quote. sb.append("\u201D"); inDQ = false; } else { // typographer's start quote. sb.append("\u201C"); inDQ = true; } break; case '\'': sb.append("\u2019"); // appostrophe break; default: sb.append(c); } } addChunk(sb.toString()); break; } } startParagraph(); doc.close(); }
From source file:com.juanhg.car.CarApplet.java
private void initSimulation() { float grosor = 2f; Point2D[] nullArray = new Point2D[0]; //Crear modelo model = new CarModel(Va, r, mg, Vcar, Qc); supRoadXLimit = (int) model.getX() + (int) (model.getX() * 0.1); // Inicializar charts chartPlot = new Grafica(nullArray, "", "", "V", "P", false, Color.BLUE, grosor, true); chartPlot.agregarGrafica(model.chart1AsArray(), "", Color.BLUE, grosor, true); chartPlot.agregarGrafica(model.chart2AsArray(), "", Color.BLUE, grosor, true); chartPlot.agregarGrafica(model.chart3AsArray(), "", Color.BLUE, grosor, true); chartPlot.agregarGrafica(model.chart4AsArray(), "", Color.BLUE, grosor, true); chartPlot.setRangeAxis((model.getV2() - model.getV1() * 0.1), (model.getV1() + model.getV1() * 0.1), model.getPa() - model.getPmax() * 0.1, model.getPmax() + model.getPmax() * 0.1); chartPiston = new Grafica(nullArray, "", "", "", "", false, Color.BLUE, grosor, true); chartPiston.setRangeAxis(infPistonXLimit, supPistonXLimit, infPistonYLimit, supPistonYLimit); // chartPiston.fijaFondo(Color.WHITE); chartPiston.setAxisVisible(false);/*from w w w .j av a 2 s .co m*/ chartCar = new Grafica(nullArray, "", "", "", "", false, Color.BLUE, grosor, true); chartCar.setRangeAxis(infRoadXLimit, supRoadXLimit, infRoadYLimit, supRoadYLimit); //Load Images roadImage = loadImage(road); carImage = loadImage(car); pistonImage = loadImage(piston); headImage = loadImage(head); //Set Images chartCar.setImageAtPoint(roadImage, (supRoadXLimit - infRoadXLimit) / 2.0, (supRoadYLimit - infRoadYLimit) / 2.0); carAnnotation = chartCar.setImageAtPoint(carImage, (supRoadXLimit - infRoadXLimit) / 2.0, (supRoadYLimit - infRoadYLimit) / 2.0); pistonBodyAnnotation = chartPiston.setImageAtPoint(pistonImage, (supPistonXLimit - infPistonXLimit) / 2.0, 3); lineAnnotation = chartPiston.drawBox(((supPistonXLimit - infPistonXLimit) / 2.0) - 0.1, -4, ((supPistonXLimit - infPistonXLimit) / 2.0) + 0.1, 7, new BasicStroke(2f), Color.BLACK, Color.GRAY); headAnnotation = chartPiston.setImageAtPoint(headImage, (supPistonXLimit - infPistonXLimit) / 2.0, 6.5); //Actualize panels updatePanels(); repaint(); }
From source file:unalcol.termites.boxplots.SucessfulRates.java
private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) { JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18)); jfreechart.setBackgroundPaint(new Color(221, 223, 238)); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinePaint(Color.gray); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer renderer = (BarRenderer) categoryplot.getRenderer(); //categoryplot.setBackgroundPaint(new Color(221, 223, 238)); renderer.setSeriesPaint(0, new Color(130, 165, 70)); renderer.setSeriesPaint(1, new Color(220, 165, 70)); renderer.setSeriesPaint(4, new Color(255, 165, 70)); renderer.setDrawBarOutline(false);/* w ww. j a v a 2 s . co m*/ renderer.setShadowVisible(false); // renderer.setMaximumBarWidth(1); renderer.setGradientPaintTransformer(null); renderer.setDefaultBarPainter(new StandardBarPainter()); categoryplot.setRenderer(renderer); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setUpperMargin(0.25D); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); categoryitemrenderer.setBaseItemLabelsVisible(true); categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null)); numberaxis.setRange(0, 100); //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12); numberaxis.setTickLabelFont(font); CategoryAxis axisd = categoryplot.getDomainAxis(); ValueAxis axisr = categoryplot.getRangeAxis(); axisd.setTickLabelFont(font); axisr.setTickLabelFont(font); final ChartPanel chartPanel = new ChartPanel(jfreechart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); FileOutputStream output; try { output = new FileOutputStream("sucessrates1" + pf + mazeMode + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 650, 370, null); } catch (FileNotFoundException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } return jfreechart; }
From source file:it.unibo.alchemist.boundary.monitors.Generic2DDisplay.java
/** * Actually draws the environment on the view. * /*w w w . ja v a 2 s. c o m*/ * @param g * {@link Graphics2D} object responsible for drawing */ protected final void drawEnvOnView(final Graphics2D g) { if (wormhole == null || !isVisible() || !isEnabled()) { return; } accessData(); if (hooked.isPresent()) { final Position hcoor = positions.get(hooked.get()); final Point hp = wormhole.getViewPoint(hcoor); if (hp.distance(getCenter()) > FREEDOM_RADIUS) { wormhole.setViewPosition(hp); } } /* * Compute nodes in sight and their screen position */ final Map<Node<T>, Point> onView = positions.entrySet().parallelStream() .map(pair -> new Pair<>(pair.getKey(), wormhole.getViewPoint(pair.getValue()))) .filter(p -> wormhole.isInsideView(p.getSecond())) .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); g.setColor(Color.BLACK); if (obstacles != null) { /* * TODO: only draw obstacles if on view */ obstacles.parallelStream().map(this::convertObstacle).forEachOrdered(g::fill); } if (paintLinks) { g.setColor(Color.GRAY); onView.keySet().parallelStream().map(neighbors::get) .flatMap(neigh -> neigh.getNeighbors().parallelStream() .map(node -> node.compareTo(neigh.getCenter()) > 0 ? new Pair<>(neigh.getCenter(), node) : new Pair<>(node, neigh.getCenter()))) .distinct().map( pair -> mapPair(pair, node -> Optional.ofNullable(onView.get(node)) .orElse(wormhole.getViewPoint(positions.get(node))))) .forEachOrdered(line -> { final Point p1 = line.getFirst(); final Point p2 = line.getSecond(); g.drawLine(p1.x, p1.y, p2.x, p2.y); }); } releaseData(); if (isDraggingMouse && status == ViewStatus.MOVING && originPoint.isPresent() && endingPoint.isPresent()) { for (final Node<T> n : selectedNodes) { if (onView.containsKey(n)) { onView.put(n, new Point(onView.get(n).x + (endingPoint.get().x - originPoint.get().x), onView.get(n).y + (endingPoint.get().y - originPoint.get().y))); } } } g.setColor(Color.GREEN); if (effectStack != null) { effectStack.forEach(effect -> { onView.entrySet().forEach(entry -> { final Point p = entry.getValue(); effect.apply(g, entry.getKey(), p.x, p.y); }); }); } if (isCloserNodeMarked()) { final Optional<Map.Entry<Node<T>, Point>> closest = onView.entrySet().parallelStream() .min((pair1, pair2) -> { final Point p1 = pair1.getValue(); final Point p2 = pair2.getValue(); final double d1 = Math.hypot(p1.x - mousex, p1.y - mousey); final double d2 = Math.hypot(p2.x - mousex, p2.y - mousey); return Double.compare(d1, d2); }); if (closest.isPresent()) { nearest = closest.get().getKey(); final int nearestx = closest.get().getValue().x; final int nearesty = closest.get().getValue().y; drawFriedEgg(g, nearestx, nearesty, Color.RED, Color.YELLOW); } } else { nearest = null; } if (isDraggingMouse && status == ViewStatus.SELECTING && originPoint.isPresent() && endingPoint.isPresent()) { g.setColor(Color.BLACK); final int x = originPoint.get().x < endingPoint.get().x ? originPoint.get().x : endingPoint.get().x; final int y = originPoint.get().y < endingPoint.get().y ? originPoint.get().y : endingPoint.get().y; final int width = Math.abs(endingPoint.get().x - originPoint.get().x); final int height = Math.abs(endingPoint.get().y - originPoint.get().y); g.drawRect(x, y, width, height); selectedNodes = onView.entrySet().parallelStream() .filter(nodes -> isInsideRectangle(nodes.getValue(), x, y, width, height)) .map(onScreen -> onScreen.getKey()).collect(Collectors.toSet()); } selectedNodes.parallelStream().map(e -> Optional.ofNullable(onView.get(e))).filter(Optional::isPresent) .map(Optional::get).forEachOrdered(p -> drawFriedEgg(g, p.x, p.y, Color.BLUE, Color.CYAN)); }
From source file:org.fhcrc.cpl.viewer.quant.gui.PanelWithSpectrumChart.java
License:asdf
/** * Generate all the charts//from www. j a v a 2 s .c o m */ public void generateCharts() { int minScanIndex = Math.abs(run.getIndexForScanNum(minScan)); int maxScanIndex = Math.abs(run.getIndexForScanNum(maxScan)); int numScans = maxScanIndex - minScanIndex + 1; int numMzBins = (int) ((float) resolution * (maxMz - minMz)) + 1; double[] scanValues = new double[numScans]; double[] mzValues = new double[numMzBins]; for (int i = 0; i < numScans; i++) scanValues[i] = run.getScanNumForIndex(minScanIndex + i); for (int i = 0; i < numMzBins; i++) mzValues[i] = minMz + (i / (float) resolution); //Resampling adds some slop on each end float minMzForRange = (int) minMz; if (minMzForRange > minMz) minMzForRange--; float maxMzForRange = (int) maxMz; if (maxMzForRange < maxMz) maxMzForRange++; FloatRange mzWindowForResample = new FloatRange(minMzForRange, maxMzForRange); double[][] intensityValues = new double[numScans][numMzBins]; _log.debug("Loading spectrum in range...."); double[] sumIntensitiesInQuantRange = new double[numMzBins]; //carry just the intensities used in quantitation double[] sumPeakIntensitiesInQuantRange = new double[numMzBins]; if (numSafePeaks < 0) numSafePeaks = Math.min(Math.round((heavyMz - lightMz) * charge), MAX_Q3_PEAKS); if (heavyMz < lightMz) numSafePeaks = 4; if (peakMzs != null) numSafePeaks = Math.min(numSafePeaks, peakMzs.length); List<Float> peakMzsToQuantitate = new ArrayList<Float>(); List<Float> nonMonoisotopicPeakMzList = new ArrayList<Float>(); for (int i = 0; i < numSafePeaks; i++) { float lightPeakMz = lightMz + (peakSeparationMass / charge) * i; float heavyPeakMz = heavyMz + (peakSeparationMass / charge) * i; if (peakMzs != null) { lightPeakMz = peakMzs[i]; heavyPeakMz = heavyMz + (lightPeakMz - lightMz); } peakMzsToQuantitate.add(lightPeakMz); peakMzsToQuantitate.add(heavyPeakMz); nonMonoisotopicPeakMzList.add(lightPeakMz); if (heavyPeakMz > lightMz) nonMonoisotopicPeakMzList.add(heavyPeakMz); } int heavyMonoisotopicPeakIndex = numSafePeaks; float[] nonMonoisotopicPeakMzs = new float[nonMonoisotopicPeakMzList.size()]; for (int i = 0; i < nonMonoisotopicPeakMzs.length; i++) { nonMonoisotopicPeakMzs[i] = nonMonoisotopicPeakMzList.get(i); } Collections.sort(peakMzsToQuantitate); //dhmay adding 20090723 //For calculating single-peak ratio based on theoretical highest peak int maxIdealPeakIndex = Spectrum.calcMaxIdealPeakIndex(lightMz - Spectrum.HYDROGEN_ION_MASS) * charge; float lightMaxIdealPeakIntensitySum = 0f; float heavyMaxIdealPeakIntensitySum = 0f; for (int scanArrayIndex = 0; scanArrayIndex < numScans; scanArrayIndex++) { int scanIndex = minScanIndex + scanArrayIndex; MSRun.MSScan scan = run.getScan(scanIndex); if (scan.getNum() == idEventScan) specifiedScanFoundMS1 = true; float[] signalFromResample = Spectrum.Resample(scan.getSpectrum(), mzWindowForResample, resolution); int firstIndexToKeep = -1; for (int i = 0; i < signalFromResample.length; i++) { float mzValueThisIndex = minMzForRange + (i / (float) resolution); if (mzValueThisIndex >= minMz && firstIndexToKeep == -1) { firstIndexToKeep = i; break; } } //this is horrible. arraycopy would be better, but need to convert float to double double[] signal = new double[numMzBins]; for (int i = 0; i < numMzBins; i++) { signal[i] = signalFromResample[firstIndexToKeep + i]; } if (shouldGenerateLineCharts) { double[] signalPeaks = new double[numMzBins]; int currentPeakIndex = -1; float minMzCurrentPeak = -1; float maxMzCurrentPeak = -1; for (int i = 0; i < numMzBins; i++) { double mz = mzValues[i]; if (mz > maxMzCurrentPeak && currentPeakIndex < peakMzsToQuantitate.size() - 1) { currentPeakIndex++; float currentPeakMz = peakMzsToQuantitate.get(currentPeakIndex); float currentPeakMass = (currentPeakMz - Spectrum.HYDROGEN_ION_MASS) * charge; float deltaMz = (peakTolerancePPM * currentPeakMass / 1000000f) / charge; minMzCurrentPeak = currentPeakMz - deltaMz; maxMzCurrentPeak = currentPeakMz + deltaMz; } if (mz >= minMzCurrentPeak && mz <= maxMzCurrentPeak) { signalPeaks[i] += signal[i]; } } upperZBoundNearPeak = Math.max(upperZBoundNearPeak, BasicStatistics.max(signalPeaks)); PanelWithLineChart lineChart = new PanelWithPeakChart(mzValues, signalPeaks, "Scan " + (int) scanValues[scanArrayIndex], PanelWithLineChart.defaultShape, Color.BLUE); lineChart.addData(mzValues, signal, "all", PanelWithLineChart.defaultShape, Color.GRAY); lineChart.setAxisLabels("m/z", "intensity"); scanLineChartMap.put((int) scanValues[scanArrayIndex], lineChart); } intensityValues[scanArrayIndex] = signal; upperZBound = Math.max(upperZBound, BasicStatistics.max(signal)); if (scan.getNum() >= lightFirstScanLine && scan.getNum() >= heavyFirstScanLine && scan.getNum() <= lightLastScanLine && scan.getNum() <= heavyLastScanLine) { int currentPeakIndex = -1; float minMzCurrentPeak = -1; float maxMzCurrentPeak = -1; for (int i = 0; i < sumIntensitiesInQuantRange.length; i++) { sumIntensitiesInQuantRange[i] += signal[i]; float mz = (float) mzValues[i]; if (mz > maxMzCurrentPeak && currentPeakIndex < peakMzsToQuantitate.size() - 1) { currentPeakIndex++; float currentPeakMz = peakMzsToQuantitate.get(currentPeakIndex); float currentPeakMass = (currentPeakMz - Spectrum.HYDROGEN_ION_MASS) * charge; float deltaMz = (peakTolerancePPM * currentPeakMass / 1000000f) / charge; minMzCurrentPeak = currentPeakMz - deltaMz; maxMzCurrentPeak = currentPeakMz + deltaMz; } if (mz >= minMzCurrentPeak && mz <= maxMzCurrentPeak) { sumPeakIntensitiesInQuantRange[i] += signal[i]; //dhmay adding 20090723 for single-peak quantitation if (currentPeakIndex == maxIdealPeakIndex) lightMaxIdealPeakIntensitySum += signal[i]; else if (currentPeakIndex == heavyMonoisotopicPeakIndex + maxIdealPeakIndex) heavyMaxIdealPeakIntensitySum += signal[i]; } } } } ratioOnePeak = lightMaxIdealPeakIntensitySum / Math.max(heavyMaxIdealPeakIntensitySum, 0.001f); double maxIntensityOnSumChart = BasicStatistics.max(sumIntensitiesInQuantRange); double maxPeakIntensity = BasicStatistics.max(sumPeakIntensitiesInQuantRange); if (maxIntensityOnSumChart < 1) maxIntensityOnSumChart = maxPeakIntensity; float[] monoisotopicMzs = new float[] { lightMz, heavyMz }; double intensityForSumChartHeight = maxIntensityOnSumChart * 1.5; float[] monoisotopicIntensitiesSumChart = new float[] { (float) intensityForSumChartHeight, (float) intensityForSumChartHeight }; intensitySumChart = new PanelWithPeakChart(mzValues, sumPeakIntensitiesInQuantRange, "Peak Intensities"); intensitySumChart.addData(mzValues, sumIntensitiesInQuantRange, "Intensity Sum", PanelWithLineChart.defaultShape, Color.LIGHT_GRAY); if (heavyMz > 0) intensitySumChart.addDataFloat(monoisotopicMzs, monoisotopicIntensitiesSumChart, "Monoisotopic light and heavy", PanelWithLineChart.defaultShape, Color.GREEN); else intensitySumChart.addDataFloat(new float[] { lightMz }, new float[] { (float) intensityForSumChartHeight }, "Monoisotopic light and heavy", PanelWithLineChart.defaultShape, Color.GREEN); if (nonMonoisotopicPeakMzs.length > 0) { //for (float mz : nonMonoisotopicPeakMzs) System.err.println("***" + mz); float[] nonmonoisotopicIntensitiesSumChart = new float[nonMonoisotopicPeakMzs.length]; Arrays.fill(nonmonoisotopicIntensitiesSumChart, (float) intensityForSumChartHeight); //System.err.println("ADDING LINES, peakMzs null ? " + (peakMzs == null)); if (peakMzs != null) { intensitySumChart.addDataFloat(nonMonoisotopicPeakMzs, nonmonoisotopicIntensitiesSumChart, "Nonmonoisotopic light and heavy (exact)", PanelWithLineChart.defaultShape, Color.RED); } else { intensitySumChart.addDataFloat(nonMonoisotopicPeakMzs, nonmonoisotopicIntensitiesSumChart, "Nonmonoisotopic light and heavy (approx)", PanelWithLineChart.defaultShape, Color.ORANGE); } } intensitySumChart.getChart().removeLegend(); intensitySumChart.setAxisLabels("m/z", "Intensity (Sum)"); if (maxPeakIntensity > 1) ((XYPlot) intensitySumChart.getPlot()).getRangeAxis().setRange(0, maxPeakIntensity * 1.25); intensitySumChart.setSize(getWidth(), getHeight()); if (shouldGenerateLineCharts) { float rangeMax = (float) upperZBoundNearPeak * 1.25f; for (PanelWithLineChart lineChart : scanLineChartMap.values()) { ((XYPlot) lineChart.getPlot()).getRangeAxis().setRange(0, rangeMax); float[] monoisotopicIntensities = new float[] { (float) rangeMax, rangeMax }; lineChart.addDataFloat(monoisotopicMzs, monoisotopicIntensities, "Monoisotopic light and heavy", PanelWithLineChart.defaultShape, Color.GREEN); if (nonMonoisotopicPeakMzs.length > 0) { float[] nonMonoisotopicIntensities = new float[nonMonoisotopicPeakMzs.length]; Arrays.fill(nonMonoisotopicIntensities, rangeMax); lineChart.addDataFloat(nonMonoisotopicPeakMzs, nonMonoisotopicIntensities, "Nonmonoisotopic light and heavy", PanelWithLineChart.defaultShape, Color.ORANGE); } lineChart.getChart().removeLegend(); } } int lightFirstScanLineIndex = -1; int lightLastScanLineIndex = -1; int heavyFirstScanLineIndex = -1; int heavyLastScanLineIndex = -1; int numScansPadded = maxScan - minScan + 1; double[] scanValuesPadded; double[][] intensityValuesPadded; setPaintScale(createHeatMapPaintScale()); if (numScansPadded == numScans) { scanValuesPadded = scanValues; intensityValuesPadded = intensityValues; if (lightFirstScanLine > 0) { for (int i = 0; i < scanValues.length; i++) { if (scanValues[i] < lightFirstScanLine) lightFirstScanLineIndex = i; else break; } } if (lightLastScanLine > 0) { for (int i = 0; i < scanValues.length; i++) { if (scanValues[i] <= lightLastScanLine + 1) lightLastScanLineIndex = i; else break; } } if (heavyFirstScanLine > 0) { for (int i = 0; i < scanValues.length; i++) { if (scanValues[i] < heavyFirstScanLine) heavyFirstScanLineIndex = i; else break; } } if (heavyLastScanLine > 0) { for (int i = 0; i < scanValues.length; i++) { if (scanValues[i] <= heavyLastScanLine + 1) heavyLastScanLineIndex = i; else break; } } } else { _log.debug("Padding! unpadded: " + numScans + ", padded: " + numScansPadded); scanValuesPadded = new double[numScansPadded]; intensityValuesPadded = new double[numScansPadded][numMzBins]; int unPaddedIndex = 0; for (int i = 0; i < scanValuesPadded.length; i++) { int scanValue = minScan + i; scanValuesPadded[i] = scanValue; if (unPaddedIndex < scanValues.length - 1 && scanValue >= scanValues[unPaddedIndex + 1]) unPaddedIndex++; System.arraycopy(intensityValues[unPaddedIndex], 0, intensityValuesPadded[i], 0, intensityValues[unPaddedIndex].length); } //add the lines for the scanlines, just outside the specified boundaries if (lightFirstScanLine > 0) { lightFirstScanLineIndex = 0; for (int i = 0; i < scanValuesPadded.length; i++) { if (scanValuesPadded[i] < lightFirstScanLine) { lightFirstScanLineIndex = i; } else break; } } if (lightLastScanLine > 0) { lightLastScanLineIndex = 0; int nextScanAfterLine2 = 0; for (int i = 0; i < scanValues.length; i++) if (scanValues[i] > lightLastScanLine) { nextScanAfterLine2 = (int) scanValues[i]; break; } if (nextScanAfterLine2 == 0) lightLastScanLineIndex = 0; else { for (int i = 0; i < scanValuesPadded.length; i++) { if (scanValuesPadded[i] >= nextScanAfterLine2) { lightLastScanLineIndex = i; break; } } } } if (heavyFirstScanLine > 0) { heavyFirstScanLineIndex = 0; for (int i = 0; i < scanValuesPadded.length; i++) { if (scanValuesPadded[i] < heavyFirstScanLine) { heavyFirstScanLineIndex = i; } else break; } } if (heavyLastScanLine > 0) { heavyLastScanLineIndex = 0; int nextScanAfterLine2 = 0; for (int i = 0; i < scanValues.length; i++) if (scanValues[i] > heavyLastScanLine) { nextScanAfterLine2 = (int) scanValues[i]; break; } if (nextScanAfterLine2 == 0) heavyLastScanLineIndex = 0; else { for (int i = 0; i < scanValuesPadded.length; i++) { if (scanValuesPadded[i] >= nextScanAfterLine2) { heavyLastScanLineIndex = i; break; } } } } } int lightMzIndex = 0; for (lightMzIndex = 0; lightMzIndex < intensityValuesPadded[0].length; lightMzIndex++) if (mzValues[lightMzIndex] > lightMz) break; int heavyMzIndex = 0; for (heavyMzIndex = 0; heavyMzIndex < intensityValuesPadded[0].length; heavyMzIndex++) if (mzValues[heavyMzIndex] > heavyMz) break; if (lightFirstScanLineIndex > 0) shadeArea(intensityValuesPadded, 0, 0, lightFirstScanLineIndex, lightMzIndex); if (lightLastScanLineIndex > 0) shadeArea(intensityValuesPadded, lightLastScanLineIndex, 0, intensityValuesPadded.length - 1, lightMzIndex); if (heavyFirstScanLineIndex > 0) shadeArea(intensityValuesPadded, 0, heavyMzIndex, heavyFirstScanLineIndex, intensityValuesPadded[0].length - 1); if (lightLastScanLineIndex > 0) shadeArea(intensityValuesPadded, heavyLastScanLineIndex, heavyMzIndex, intensityValuesPadded.length - 1, intensityValuesPadded[0].length - 1); //if light and heavy first scan are same, shade the remaining area on the left. Same with last scan if (lightFirstScanLineIndex > 0 && heavyFirstScanLineIndex == lightFirstScanLineIndex) shadeArea(intensityValuesPadded, 0, lightMzIndex + 1, lightFirstScanLineIndex, heavyMzIndex - 1); if (lightLastScanLineIndex > 0 && heavyLastScanLineIndex == lightLastScanLineIndex) shadeArea(intensityValuesPadded, lightLastScanLineIndex, lightMzIndex + 1, intensityValuesPadded.length - 1, heavyMzIndex - 1); //special value for tick intensity float intensityForTickMark = -2f; float intensityForIdCross = -2f; //cross for ID event if (idEventScan > 0 && idEventMz > 0) { drawHeatmapCrossForEvent(scanValuesPadded, mzValues, intensityValuesPadded, idEventScan, idEventMz, intensityForIdCross); } if (otherEventScans != null && !otherEventScans.isEmpty()) { for (int i = 0; i < otherEventScans.size(); i++) drawHeatmapCrossForEvent(scanValuesPadded, mzValues, intensityValuesPadded, otherEventScans.get(i), otherEventMZs.get(i), intensityForIdCross); } //tick marks for specified m/z's if (lightMz > 0) { placeHeatmapTick(mzValues, intensityValuesPadded, lightMz, intensityForTickMark); } if (heavyMz > 0) { placeHeatmapTick(mzValues, intensityValuesPadded, heavyMz, intensityForTickMark); } if (peakMzs != null) { for (float mz : nonMonoisotopicPeakMzs) placeHeatmapTick(mzValues, intensityValuesPadded, mz, intensityForTickMark); } if (shouldGenerate3DChart) generate3DPlot(scanValuesPadded, mzValues, intensityValuesPadded); _log.debug("Done loading spectrum in range."); setData(scanValuesPadded, mzValues, intensityValuesPadded); getChart().removeLegend(); //try {contourPlot.saveAllImagesToFiles(new File("/home/dhmay/temp/charts"));} catch(IOException e) {} ((XYPlot) _plot).getDomainAxis().setRange(minScan, maxScan); ((XYPlot) _plot).getRangeAxis().setRange(minMz, maxMz); }
From source file:org.mwc.debrief.track_shift.views.BaseStackedDotsView.java
/** * method to create a working plot (to contain our data) * /*from w w w .j a v a2 s .c o m*/ * @return the chart, in it's own panel */ @SuppressWarnings("deprecation") protected void createStackedPlot() { // first create the x (time) axis final SimpleDateFormat _df = new SimpleDateFormat("HHmm:ss"); _df.setTimeZone(TimeZone.getTimeZone("GMT")); final DateAxis xAxis = new CachedTickDateAxis(""); xAxis.setDateFormatOverride(_df); Font tickLabelFont = new Font("Courier", Font.PLAIN, 13); xAxis.setTickLabelFont(tickLabelFont); xAxis.setTickLabelPaint(Color.BLACK); xAxis.setStandardTickUnits(DateAxisEditor.createStandardDateTickUnitsAsTickUnits()); xAxis.setAutoTickUnitSelection(true); // create the special stepper plot _dotPlot = new XYPlot(); NumberAxis errorAxis = new NumberAxis("Error (" + getUnits() + ")"); Font axisLabelFont = new Font("Courier", Font.PLAIN, 16); errorAxis.setLabelFont(axisLabelFont); errorAxis.setTickLabelFont(tickLabelFont); _dotPlot.setRangeAxis(errorAxis); _dotPlot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); _dotPlot.setRenderer(new ColourStandardXYItemRenderer(null, null, _dotPlot)); _dotPlot.setRangeGridlinePaint(Color.LIGHT_GRAY); _dotPlot.setRangeGridlineStroke(new BasicStroke(2)); _dotPlot.setDomainGridlinePaint(Color.LIGHT_GRAY); _dotPlot.setDomainGridlineStroke(new BasicStroke(2)); // now try to do add a zero marker on the error bar final Paint thePaint = Color.DARK_GRAY; final Stroke theStroke = new BasicStroke(3); final ValueMarker zeroMarker = new ValueMarker(0.0, thePaint, theStroke); _dotPlot.addRangeMarker(zeroMarker); _linePlot = new XYPlot(); final NumberAxis absBrgAxis = new NumberAxis("Absolute (" + getUnits() + ")"); absBrgAxis.setLabelFont(axisLabelFont); absBrgAxis.setTickLabelFont(tickLabelFont); _linePlot.setRangeAxis(absBrgAxis); absBrgAxis.setAutoRangeIncludesZero(false); _linePlot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); final DefaultXYItemRenderer lineRend = new ColourStandardXYItemRenderer(null, null, _linePlot); lineRend.setPaint(Color.DARK_GRAY); _linePlot.setRenderer(lineRend); _linePlot.setDomainCrosshairVisible(true); _linePlot.setRangeCrosshairVisible(true); _linePlot.setDomainCrosshairPaint(Color.GRAY); _linePlot.setRangeCrosshairPaint(Color.GRAY); _linePlot.setDomainCrosshairStroke(new BasicStroke(3.0f)); _linePlot.setRangeCrosshairStroke(new BasicStroke(3.0f)); _linePlot.setRangeGridlinePaint(Color.LIGHT_GRAY); _linePlot.setRangeGridlineStroke(new BasicStroke(2)); _linePlot.setDomainGridlinePaint(Color.LIGHT_GRAY); _linePlot.setDomainGridlineStroke(new BasicStroke(2)); // and the plot object to display the cross hair value final XYTextAnnotation annot = new XYTextAnnotation("-----", 2, 2); annot.setTextAnchor(TextAnchor.TOP_LEFT); Font annotationFont = new Font("Courier", Font.BOLD, 16); annot.setFont(annotationFont); annot.setPaint(Color.DARK_GRAY); annot.setBackgroundPaint(Color.white); _linePlot.addAnnotation(annot); // give them a high contrast backdrop _dotPlot.setBackgroundPaint(Color.white); _linePlot.setBackgroundPaint(Color.white); // set the y axes to autocalculate _dotPlot.getRangeAxis().setAutoRange(true); _linePlot.getRangeAxis().setAutoRange(true); _combined = new CombinedDomainXYPlot(xAxis); _combined.add(_linePlot); _combined.add(_dotPlot); _combined.setOrientation(PlotOrientation.HORIZONTAL); // put the plot into a chart _myChart = new JFreeChart(null, null, _combined, true); final LegendItemSource[] sources = { _linePlot }; _myChart.getLegend().setSources(sources); _myChart.addProgressListener(new ChartProgressListener() { public void chartProgress(final ChartProgressEvent cpe) { if (cpe.getType() != ChartProgressEvent.DRAWING_FINISHED) return; // is hte line plot visible? if (!_showLinePlot.isChecked()) return; // double-check our label is still in the right place final double xVal = _linePlot.getRangeAxis().getLowerBound(); final double yVal = _linePlot.getDomainAxis().getUpperBound(); boolean annotChanged = false; if (annot.getX() != yVal) { annot.setX(yVal); annotChanged = true; } if (annot.getY() != xVal) { annot.setY(xVal); annotChanged = true; } // and write the text final String numA = MWC.Utilities.TextFormatting.GeneralFormat .formatOneDecimalPlace(_linePlot.getRangeCrosshairValue()); final Date newDate = new Date((long) _linePlot.getDomainCrosshairValue()); final SimpleDateFormat _df = new SimpleDateFormat("HHmm:ss"); _df.setTimeZone(TimeZone.getTimeZone("GMT")); final String dateVal = _df.format(newDate); final String theMessage = " [" + dateVal + "," + numA + "]"; if (!theMessage.equals(annot.getText())) { annot.setText(theMessage); annotChanged = true; } if (annotChanged) { _linePlot.removeAnnotation(annot); _linePlot.addAnnotation(annot); } } }); // and insert into the panel _holder.setChart(_myChart); // do a little tidying to reflect the memento settings if (!_showLinePlot.isChecked()) _combined.remove(_linePlot); if (!_showDotPlot.isChecked() && _showLinePlot.isChecked()) _combined.remove(_dotPlot); }
From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYPrincipalComponentAnalysisPlot.java
/** * Get the color for a PCA data point. The color is determined by the Color by parameter. * @param pcaPoint/*from ww w .jav a2 s . com*/ * @return */ private Color getColorForDataPoint(ISPYPCADataPoint pcaPoint) { Color defaultColor = Color.GRAY; Color retColor = null; ClinicalResponseType clinResp = null; ClinicalStageType clinStage = null; TimepointType timepoint = null; if (colorBy == ColorByType.CLINICALRESPONSE) { clinResp = pcaPoint.getClinicalResponse(); if (clinResp != null) { retColor = clinResp.getColor(); } } else if (colorBy == ColorByType.DISEASESTAGE) { clinStage = pcaPoint.getClinicalStage(); if (clinStage != null) { retColor = clinStage.getColor(); } } else if (colorBy == ColorByType.TIMEPOINT) { timepoint = pcaPoint.getTimepoint(); if (timepoint != null) { retColor = timepoint.getColor(); } } if (retColor == null) { retColor = defaultColor; } return retColor; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.SimpleBlockChart.java
/** * Creates a chart for the specified dataset. * // w w w .ja v a 2s .c o m * @param dataset the dataset. * * @return A chart instance. */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1"); JFreeChart chart = null; NumberAxis xAxis = new NumberAxis(xLabel); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (xLowerBound != null && xUpperBound != null) { xAxis.setLowerBound(xLowerBound); xAxis.setUpperBound(xUpperBound); } else { xAxis.setAutoRange(true); } xAxis.setAxisLinePaint(Color.white); xAxis.setTickMarkPaint(Color.white); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { xAxis.setLabelFont(addLabelsStyle.getFont()); xAxis.setLabelPaint(addLabelsStyle.getColor()); } NumberAxis yAxis = new NumberAxis(yLabel); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (yLowerBound != null && yUpperBound != null) { yAxis.setLowerBound(yLowerBound); yAxis.setUpperBound(yUpperBound); } else yAxis.setAutoRange(true); yAxis.setAxisLinePaint(Color.white); yAxis.setTickMarkPaint(Color.white); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { yAxis.setLabelFont(addLabelsStyle.getFont()); yAxis.setLabelPaint(addLabelsStyle.getColor()); } XYBlockRenderer renderer = new XYBlockRenderer(); PaintScale paintScale = null; if (grayPaintScale) { paintScale = new GrayPaintScale(minScaleValue, maxScaleValue); } else { if (scaleLowerBound != null && scaleUpperBound != null) { paintScale = new LookupPaintScale(scaleLowerBound, scaleUpperBound, Color.gray); } else { paintScale = new LookupPaintScale(minScaleValue, maxScaleValue, Color.gray); } for (int i = 0; i < zRangeArray.length; i++) { ZRange zRange = zRangeArray[i]; ((LookupPaintScale) paintScale).add(zRange.getValue().doubleValue(), zRange.getColor()); } } renderer.setPaintScale(paintScale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); plot.setForegroundAlpha(0.66f); chart = new JFreeChart(plot); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } chart.removeLegend(); NumberAxis scaleAxis = new NumberAxis(zLabel); scaleAxis.setAxisLinePaint(Color.white); scaleAxis.setTickMarkPaint(Color.white); scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7)); if (scaleLowerBound != null && scaleUpperBound != null) { scaleAxis.setLowerBound(scaleLowerBound); scaleAxis.setUpperBound(scaleUpperBound); } else scaleAxis.setAutoRange(true); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { scaleAxis.setLabelFont(addLabelsStyle.getFont()); scaleAxis.setLabelPaint(addLabelsStyle.getColor()); } if (blockHeight != null && blockWidth != null) { renderer.setBlockWidth(blockWidth.doubleValue()); renderer.setBlockHeight(blockHeight.doubleValue()); } PaintScaleLegend legend = new PaintScaleLegend(paintScale, scaleAxis); legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); legend.setAxisOffset(5.0); legend.setMargin(new RectangleInsets(5, 5, 5, 5)); legend.setFrame(new BlockBorder(Color.black)); legend.setPadding(new RectangleInsets(10, 10, 10, 10)); legend.setStripWidth(10); legend.setPosition(RectangleEdge.RIGHT); legend.setBackgroundPaint(color); chart.addSubtitle(legend); // chart.setBackgroundPaint(new Color(180, 180, 250)); chart.setBackgroundPaint(color); logger.debug("OUT"); return chart; }
From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_Stat_Raw_Vertical.java
/** * reset dataTable to default (demo data), and refesh chart *//*from ww w.j a v a 2 s . co m*/ public void resetExample() { dataset = createDataset(true); JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, false); setChart(); hasExample = true; convertor.valueList2Table_vertical(values_storage, SERIES_COUNT, CATEGORY_COUNT); JTable tempDataTable = convertor.getTable(); // resetTable(); resetTableRows(tempDataTable.getRowCount() + 1); resetTableColumns(tempDataTable.getColumnCount()); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); dataPanel.add(new JScrollPane(dataTable)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); dataTable.doLayout(); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // do the mapping //addButtonDependent(); setMapping(); updateStatus(url); }