List of usage examples for java.awt Graphics2D fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:com.att.aro.diagnostics.GraphPanel.java
/** * Creating DchTail and FachTail Cross Hatch * /*from w ww .ja v a 2 s . co m*/ * @return Paint The Tail state paint object */ private static Paint getTailPaint(Color color) { BufferedImage bufferedImage = new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bufferedImage.createGraphics(); g2.setColor(Color.white); g2.fillRect(0, 0, 5, 5); g2.setColor(color); g2.drawLine(0, 0, 5, 5); g2.drawLine(5, 5, 0, 0); g2.drawLine(0, 5, 5, 0); Rectangle2D rect = new Rectangle2D.Double(0, 0, 5, 5); return new TexturePaint(bufferedImage, rect); }
From source file:com.openbravo.pos.util.ThumbNailBuilder.java
public Image getThumbNailText(Image img, String text) { /*/* w w w. ja v a2 s.com*/ * Create an image containing a thumbnail of the product image, * or default image. * * Then apply the text of the product name. Use text wrapping. * * If the product name is too big for the label, ensure that * the first part is displayed. */ img = getThumbNail(img); BufferedImage imgtext = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = imgtext.createGraphics(); // The text // <p style="width: 100px"> DOES NOT WORK PROPERLY. // use width= instead. String html = "<html><p style=\"text-align:center\" width=\"" + imgtext.getWidth() + "\">" + StringEscapeUtils.escapeHtml(text) + "</p>"; JLabel label = new JLabel(html); label.setOpaque(false); //label.setText("<html><center>Line1<br>Line2"); label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); label.setVerticalAlignment(javax.swing.SwingConstants.TOP); Dimension d = label.getPreferredSize(); label.setBounds(0, 0, imgtext.getWidth(), d.height); // The background Color c1 = new Color(0xff, 0xff, 0xff, 0x40); Color c2 = new Color(0xff, 0xff, 0xff, 0xd0); // Point2D center = new Point2D.Float(imgtext.getWidth() / 2, label.getHeight()); // float radius = imgtext.getWidth() / 3; // float[] dist = {0.1f, 1.0f}; // Color[] colors = {c2, c1}; // Paint gpaint = new RadialGradientPaint(center, radius, dist, colors); Paint gpaint = new GradientPaint(new Point(0, 0), c1, new Point(label.getWidth() / 2, 0), c2, true); g2d.drawImage(img, 0, 0, null); int ypos = imgtext.getHeight() - label.getHeight(); int ypos_min = -4; // todo: configurable if (ypos < ypos_min) ypos = ypos_min; // Clamp label g2d.translate(0, ypos); g2d.setPaint(gpaint); g2d.fillRect(0, 0, imgtext.getWidth(), label.getHeight()); label.paint(g2d); g2d.dispose(); return imgtext; }
From source file:savant.view.swing.GraphPane.java
/** * Render the background of this GraphPane * * @param g The graphics object to use//w ww. ja v a 2 s . co m */ private void renderBackground(Graphics2D g2, boolean xGridOn, boolean yGridOn) { int h = getHeight(); int w = getWidth(); // Paint a gradient from top to bottom GradientPaint gp0 = new GradientPaint(0, 0, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_TOP), 0, h, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_BOTTOM)); g2.setPaint(gp0); g2.fillRect(0, 0, w, h); // We don't want the axes stomping on our labels, so make sure the clip excludes them. Area clipArea = new Area(new Rectangle(0, 0, w, h)); Color gridColor = ColourSettings.getColor(ColourKey.AXIS_GRID); if (yGridOn) { // Smallish font for tick labels. Font tickFont = g2.getFont().deriveFont(Font.PLAIN, 9); int[] yTicks = MiscUtils.getTickPositions(transformYPixel(getHeight()), transformYPixel(0.0)); g2.setColor(gridColor); g2.setFont(tickFont); for (int t : yTicks) { double y = transformYPos(t); // Skip labels at the top or bottom of the window because they look stupid. if (y != 0.0 && y != getHeight()) { String s = Integer.toString(t); Rectangle2D labelRect = tickFont.getStringBounds(s, g2.getFontRenderContext()); double baseline = y + labelRect.getHeight() * 0.5 - 2.0; g2.drawString(s, 4.0F, (float) baseline); clipArea.subtract(new Area(new Rectangle2D.Double(3.0, baseline - labelRect.getHeight() - 1.0, labelRect.getWidth() + 2.0, labelRect.getHeight() + 2.0))); } } g2.setClip(clipArea); for (int t2 : yTicks) { double y = transformYPos(t2); g2.draw(new Line2D.Double(0.0, y, w, y)); } } if (xGridOn) { Range r = LocationController.getInstance().getRange(); int[] xTicks = MiscUtils.getTickPositions(r); g2.setColor(gridColor); for (int t : xTicks) { double x = transformXPos(t); g2.draw(new Line2D.Double(x, 0, x, h)); } } g2.setClip(null); }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
public void generateBufferedImage(int width, int height) { bDrawLine = dca.getSettingPanel().isDrawLine(); matrixBuffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D gr = matrixBuffer.createGraphics(); gr.setColor(colorBg);//from ww w .ja v a 2 s . c o m gr.fillRect(0, 0, width, height); paintComponentLane(gr, width, height); // calculate are to be painted int unitHeight = height / getHashMapSize(); int currentTop = 0; // paint items if (dcModel.getItemMap().size() > 0) { String key = null; AbstractLogUnit item = null; // iterate through sets int index = 0; for (Iterator itSets = dcModel.getSortedKeySetList().iterator(); itSets.hasNext();) { key = (String) itSets.next(); // if key is not in instanceIDs, skip.. if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(key)) continue; currentTop = unit2Cord_buffer(index, height) + unitHeight / 2; LogUnitList tempUnitList = new LogUnitList(); // iterate through items for (Iterator itItm = ((LogUnitList) dcModel.getItemMap().get(key)).iterator(); itItm.hasNext();) { item = (AbstractLogUnit) itItm.next(); if (dcModel.getEventTypeToKeep() != null && (!dcModel.getEventTypeToKeep().contains(item.getType()) || !dcModel .getInstanceTypeToKeep().contains(item.getProcessInstance().getName()))) continue; // to do if (bDrawLine && item.getType().equals(dca.getSettingPanel().getStartEvent())) tempUnitList.addEvent(item); assignColorByItem(item, gr); clipL = 0; clipR = width; double milli2pixels = (double) ((width) - 10) / (double) (dcModel.getLogBoundaryRight().getTime() - dcModel.getLogBoundaryLeft().getTime()); // + 2 is // added // to // extend // bound long clipLeftTs2 = coord2timeMillis_buffer(clipL, milli2pixels); long clipRightTs2 = coord2timeMillis_buffer(clipR, milli2pixels); // to do : if line is added if (bDrawLine && item.getType().equals(dca.getSettingPanel().getEndEvent())) { for (Iterator itr = tempUnitList.iterator(); itr.hasNext();) { AbstractLogUnit item2 = (AbstractLogUnit) itr.next(); if (item2.getElement().equals(item.getElement()) && item2.getProcessInstance().equals(item.getProcessInstance())) { paintItemLine_buffer( time2coord_buffer(item2.getCurrentTimeStamp(), milli2pixels) + 3, currentTop, time2coord_buffer(item.getCurrentTimeStamp(), milli2pixels) + 3, gr); tempUnitList.removeEvent(item2); break; } } } // if item is not shown on the screen, skip drawing if (item.getCurrentTimeStamp().getTime() < clipLeftTs2 || item.getCurrentTimeStamp().getTime() > clipRightTs2) continue; // paint an item this.paintItem_buffer(time2coord_buffer(item.getCurrentTimeStamp(), milli2pixels) + 3, currentTop, gr, assignShapeByItem(item)); } // move y point index++; } } }
From source file:edu.ku.brc.ui.UIRegistry.java
/** * Writes a string message into the BufferedImage on GlassPane and sets the main component's visibility to false and * shows the GlassPane./*from w w w. ja v a 2s. c o m*/ * @param msg the message * @param pointSize the Font point size for the message to be writen in */ public static GhostGlassPane writeGlassPaneMsg(final String msg, final int pointSize) { GhostGlassPane glassPane = getGlassPane(); if (glassPane != null) { glassPane.finishDnD(); } glassPane.setMaskingEvents(true); Component mainComp = get(MAINPANE); if (mainComp != null && glassPane != null) { JFrame frame = (JFrame) get(FRAME); frameRect = frame.getBounds(); int y = 0; JMenuBar menuBar = null; Dimension size = mainComp.getSize(); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { menuBar = frame.getJMenuBar(); size.height += menuBar.getSize().height; y += menuBar.getSize().height; } BufferedImage buffer = getGlassPaneBufferedImage(size.width, size.height); Graphics2D g2 = buffer.createGraphics(); if (menuBar != null) { menuBar.paint(g2); } g2.translate(0, y); mainComp.paint(g2); g2.translate(0, -y); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(new Color(255, 255, 255, 128)); g2.fillRect(0, 0, size.width, size.height); g2.setFont(new Font((new JLabel()).getFont().getName(), Font.BOLD, pointSize)); FontMetrics fm = g2.getFontMetrics(); int tw = fm.stringWidth(msg); int th = fm.getHeight(); int tx = (size.width - tw) / 2; int ty = (size.height - th) / 2; int expand = 20; int arc = expand * 2; g2.setColor(Color.WHITE); g2.fillRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc, arc); g2.setColor(Color.DARK_GRAY); g2.drawRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc, arc); g2.setColor(Color.BLACK); g2.drawString(msg, tx, ty); g2.dispose(); glassPane.setImage(buffer); glassPane.setPoint(new Point(0, 0), GhostGlassPane.ImagePaintMode.ABSOLUTE); glassPane.setOffset(new Point(0, 0)); glassPane.setVisible(true); mainComp.setVisible(false); //Using paintImmediately fixes problems with glass pane not showing, such as for workbench saves initialed //during workbench or app shutdown. Don't know if there is a better way to fix it. //glassPane.repaint(); glassPane.paintImmediately(glassPane.getBounds()); showingGlassPane = true; } return glassPane; }
From source file:org.tsho.dmc2.core.chart.DmcLyapunovPlot.java
public boolean renderVsTime(Graphics2D g2, Rectangle2D dataArea) { final int imageWidth = (int) dataArea.getWidth(); g2.setPaint(Color.red);/*from www .jav a 2 s.c o m*/ final int timeStep; if (Math.abs(upper - lower) >= imageWidth) { timeStep = ((int) upper - (int) lower) / imageWidth; } else { timeStep = 1; } CoreStatusEvent statusEv = new CoreStatusEvent(this); int prevX[] = new int[model.getNVar()]; int prevY[] = new int[model.getNVar()]; int ratio = (int) upper / 100; for (int i = (int) lower; i < (int) upper; i += timeStep) { double[] result; int transX, transY; result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, i); for (int j = 0; j < result.length; j++) { transX = (int) this.domainAxis.valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) this.rangeAxis.valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); // System.out.println("time: " + i); // System.out.println("ly[" + j + "] = " + result[j]); // System.out.println("x: " + transX + " y: " + transY); g2.setPaint(paintSequence[j]); //g2.fillRect(transX, transY, 1, 1); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i > (int) lower) { g2.drawLine(transX, transY, prevX[j], prevY[j]); } prevX[j] = transX; prevY[j] = transY; } } if (stopped == true) { return false; } else if (ratio > 0) { statusEv.setPercent(i / ratio); statusEv.setType(CoreStatusEvent.COUNT | CoreStatusEvent.PERCENT); notifyCoreStatusListeners(statusEv); } } return true; }
From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
protected void paintComponent(final Graphics g) { if (fpsCalculator.isActive()) { fpsCalculator.tick();/*from ww w . ja va 2 s .c om*/ } final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(new Color(224, 224, 224)); g2.fillRect(0, 0, getWidth(), getHeight()); final int leftBorder = (int) getLeftBorder(); final int topBorder = (int) getTopBorder(); final float scaleFactor = getRenderContext().getZoomModel().getZoomAsPercentage(); // draw the page area .. final PageDefinition pageDefinition = getRenderContext().getContextRoot().getPageDefinition(); final Rectangle2D.Double area = new Rectangle2D.Double(0, 0, pageDefinition.getWidth() * scaleFactor, getHeight()); g2.translate(leftBorder * scaleFactor, topBorder * scaleFactor); g2.clip(area); g2.setColor(Color.WHITE); g2.fill(area); // draw the grid (unscaled, but translated) final Point2D offset = getOffset(); if (offset.getX() != 0) { // The blackout area is for inline sub-reports and is the area where the subreport is not interested in // (so we can clip out). The blackout area is only visible in the sub-report. final Rectangle2D.Double blackoutArea = new Rectangle2D.Double(0, 0, offset.getX() * scaleFactor, getHeight()); g2.setColor(Color.LIGHT_GRAY); g2.fill(blackoutArea); } paintGrid(g2); paintElementAlignment(g2); g2.dispose(); final Graphics2D logicalPageAreaG2 = (Graphics2D) g.create(); // draw the renderable content ... logicalPageAreaG2.translate(leftBorder * scaleFactor, topBorder * scaleFactor); logicalPageAreaG2.clip(area); logicalPageAreaG2.scale(scaleFactor, scaleFactor); try { final ElementRenderer rendererRoot = getElementRenderer(); if (rendererRoot != null) { if (rendererRoot.draw(logicalPageAreaG2) == false) { rendererRoot.handleError(designerContext, renderContext); logicalPageAreaG2.scale(1f / scaleFactor, 1f / scaleFactor); logicalPageAreaG2.setPaint(Color.WHITE); logicalPageAreaG2.fill(area); } } } catch (Exception e) { // ignore for now.. UncaughtExceptionsModel.getInstance().addException(e); } logicalPageAreaG2.dispose(); final OverlayRenderer[] renderers = new OverlayRenderer[4]; renderers[0] = new OverlappingElementOverlayRenderer(getDefaultElement()); // displays the red border for warning renderers[1] = new SelectionOverlayRenderer(getDefaultElement()); renderers[2] = new GuidelineOverlayRenderer(horizontalLinealModel, verticalLinealModel); renderers[3] = new SelectionRectangleOverlayRenderer(); // blue box when you shift and drag the region to select multiple // elements for (int i = 0; i < renderers.length; i++) { final OverlayRenderer renderer = renderers[i]; final Graphics2D selectionG2 = (Graphics2D) g.create(); renderer.validate(getRenderContext(), scaleFactor, offset); renderer.draw(selectionG2, new Rectangle2D.Double(getLeftBorder(), getTopBorder(), getWidth(), getHeight()), this); selectionG2.dispose(); } }
From source file:com.pronoiahealth.olhie.server.services.BookCoverImageService.java
/** * Create the front cover/*from w w w . j a v a 2 s . c o m*/ * * @param coverId * @param logoBytes * @param authorStr * @param titleStr * @param textColor * - ex. #FFFFFF * @param width * @param height * @param type * - ex. BufferedImage.TYPE_INT_ARGB * @param imgFormat * - ex. ImageFormat.IMAGE_FORMAT_PNG * @return * @throws Exception */ public byte[] createFrontCover(String coverId, byte[] logoBytes, String authorStr, String titleStr, String spineColor, String authorTextColor, String titleTextColor, int width, int height, int type, ImageFormat imgFormat, int maxColors) throws Exception { Graphics2D g = null; try { // Front cover first // Read in base cover image BufferedImage coverImg = Imaging.getBufferedImage(coverMap.get(coverId)); // Resize cover image to the basic 300 X 400 for front cover BufferedImage frontCoverImg = resize(coverImg, 300, 400, type); g = (Graphics2D) frontCoverImg.getGraphics(); // Draw logo if present if (logoBytes != null && logoBytes.length > 0) { // Resize logo to 200x100 BufferedImage logoImg = Imaging.getBufferedImage(logoBytes); BufferedImage outLogo = null; int logoHeight = logoImg.getHeight(); int logoWidth = logoImg.getWidth(); if (logoHeight > 100 || logoWidth > 200) { outLogo = this.resize(logoImg, logoWidth > 200 ? 200 : logoWidth, logoHeight > 100 ? 100 : logoHeight, type); } else { outLogo = logoImg; } // Add to coverImg g.drawImage(outLogo, 32, 25, null); } // Add spine if present if (spineColor != null && spineColor.length() > 0) { g.setColor(Color.decode(spineColor)); g.fillRect(0, 0, 2, frontCoverImg.getHeight()); } // Add author if present if (authorStr != null && authorStr.length() > 0) { // Add author text to image BufferedImage authorTextImg = createText(40, 220, authorStr, authorTextColor, false, authorFontMap, type); g.drawImage(authorTextImg, 30, 215, null); } // Add title if present if (titleStr != null && titleStr.length() > 0) { BufferedImage titleTextImg = createText(100, 220, titleStr, titleTextColor, false, titleFontMap, type); g.drawImage(titleTextImg, 30, 240, null); } // If the requested size is not 300X400 convert the image BufferedImage outImg = null; if (width != 300 || height != 400) { outImg = resize(frontCoverImg, width, height, type); } else { outImg = frontCoverImg; } // Do we want a PNG with a fixed number of colors if (maxColors >= 2 && imgFormat == ImageFormat.IMAGE_FORMAT_PNG) { outImg = ImageUtils.reduce32(outImg, maxColors); } // Return bytes Map<String, Object> params = new HashMap<String, Object>(); byte[] outBytes = Imaging.writeImageToBytes(outImg, imgFormat, params); return outBytes; } finally { if (g != null) { g.dispose(); } } }
From source file:savant.view.swing.GraphPane.java
public boolean render(Graphics2D g2, Range xRange, Range yRange) { LOG.trace("GraphPane.render(g2, " + xRange + ", " + yRange + ")"); double oldUnitHeight = unitHeight; int oldYMax = yMax; // Paint a gradient from top to bottom GradientPaint gp0 = new GradientPaint(0, 0, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_TOP), 0, getHeight(), ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_BOTTOM)); g2.setPaint(gp0);//from w w w . ja va 2s . c om g2.fillRect(0, 0, getWidth(), getHeight()); GraphPaneController gpc = GraphPaneController.getInstance(); LocationController lc = LocationController.getInstance(); JScrollBar scroller = getVerticalScrollBar(); if (gpc.isPanning() && !isLocked()) { double fromX = transformXPos(gpc.getMouseClickPosition()); double toX = transformXPos(gpc.getMouseReleasePosition()); g2.translate(toX - fromX, 0); } // Deal with the progress-bar. if (tracks == null) { parentFrame.updateProgress(); return false; } else { for (Track t : tracks) { if (t.getRenderer().isWaitingForData()) { String progressMsg = (String) t.getRenderer().getInstruction(DrawingInstruction.PROGRESS); setPreferredSize(new Dimension(getWidth(), 0)); showProgress(progressMsg, -1.0); return false; } } } if (progressPanel != null) { remove(progressPanel); progressPanel = null; } int minYRange = Integer.MAX_VALUE; int maxYRange = Integer.MIN_VALUE; AxisType bestYAxis = AxisType.NONE; for (Track t : tracks) { // ask renderers for extra info on range; consolidate to maximum Y range AxisRange axisRange = (AxisRange) t.getRenderer().getInstruction(DrawingInstruction.AXIS_RANGE); if (axisRange != null) { int axisYMin = axisRange.getYMin(); int axisYMax = axisRange.getYMax(); if (axisYMin < minYRange) { minYRange = axisYMin; } if (axisYMax > maxYRange) { maxYRange = axisYMax; } } // Ask renderers if they want horizontal grid-lines; if any say yes, draw them. switch (t.getYAxisType(t.getResolution(xRange))) { case INTEGER_GRIDLESS: if (bestYAxis == AxisType.NONE) { bestYAxis = AxisType.INTEGER_GRIDLESS; } break; case INTEGER: if (bestYAxis != AxisType.REAL) { bestYAxis = AxisType.INTEGER; } break; case REAL: bestYAxis = AxisType.REAL; break; } } setXAxisType(tracks[0].getXAxisType(tracks[0].getResolution(xRange))); setXRange(xRange); setYAxisType(bestYAxis); Range consolidatedYRange = new Range(minYRange, maxYRange); setYRange(consolidatedYRange); consolidatedYRange = new Range(yMin, yMax); DrawingMode currentMode = tracks[0].getDrawingMode(); boolean sameRange = (prevRange != null && xRange.equals(prevRange)); if (!sameRange) { PopupPanel.hidePopup(); } boolean sameMode = currentMode == prevMode; boolean sameSize = prevSize != null && getSize().equals(prevSize) && parentFrame.getFrameLandscape().getWidth() == oldWidth && parentFrame.getFrameLandscape().getHeight() == oldHeight; boolean sameRef = prevRef != null && lc.getReferenceName().equals(prevRef); boolean withinScrollBounds = bufferedImage != null && scroller.getValue() >= getOffset() && scroller.getValue() < getOffset() + getViewportHeight() * 2; //bufferedImage stores the current graphic for future use. If nothing //has changed in the track since the last render, bufferedImage will //be used to redraw the current view. This method allows for fast repaints //on tracks where nothing has changed (panning, selection, plumbline,...) //if nothing has changed draw buffered image if (sameRange && sameMode && sameSize && sameRef && !renderRequired && withinScrollBounds) { g2.drawImage(bufferedImage, 0, getOffset(), this); renderCurrentSelected(g2); //force unitHeight from last render unitHeight = oldUnitHeight; yMax = oldYMax; } else { // Otherwise prepare for new render. renderRequired = false; int h = getHeight(); if (!forcedHeight) { h = Math.min(h, getViewportHeight() * 3); } LOG.debug("Requesting " + getWidth() + "\u00D7" + h + " bufferedImage."); bufferedImage = new BufferedImage(getWidth(), h, BufferedImage.TYPE_INT_RGB); if (bufferedImage.getHeight() == getHeight()) { setOffset(0); } else { setOffset(scroller.getValue() - getViewportHeight()); } LOG.debug("Rendering fresh " + bufferedImage.getWidth() + "\u00D7" + bufferedImage.getHeight() + " bufferedImage at (0, " + getOffset() + ")"); Graphics2D g3 = bufferedImage.createGraphics(); g3.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); prevRange = xRange; prevSize = getSize(); prevMode = tracks[0].getDrawingMode(); prevRef = lc.getReferenceName(); renderBackground(g3, xAxisType == AxisType.INTEGER || xAxisType == AxisType.REAL, yAxisType == AxisType.INTEGER || yAxisType == AxisType.REAL); // Call the actual render() methods. boolean nothingRendered = true; String message = null; int priority = -1; for (Track t : tracks) { // Change renderers' drawing instructions to reflect consolidated YRange AxisRange axes = (AxisRange) t.getRenderer().getInstruction(DrawingInstruction.AXIS_RANGE); if (axes == null) { axes = new AxisRange(xRange, consolidatedYRange); } else { axes = new AxisRange(axes.getXRange(), consolidatedYRange); } //System.out.println("Consolidated y range for " + t.getName() + " is " + consolidatedYRange); t.getRenderer().addInstruction(DrawingInstruction.AXIS_RANGE, axes); try { t.getRenderer().render(g3, this); nothingRendered = false; } catch (RenderingException rx) { if (rx.getPriority() > priority) { // If we have more than one message with the same priority, the first one will end up being drawn. message = rx.getMessage(); priority = rx.getPriority(); } } catch (Throwable x) { // Renderer itself threw an exception. LOG.error("Error rendering " + t, x); message = MiscUtils.getMessage(x); priority = RenderingException.ERROR_PRIORITY; } } if (nothingRendered && message != null) { setPreferredSize(new Dimension(getWidth(), 0)); revalidate(); drawMessage(g3, message); } updateYMax(); // If a change has occured that affects scrollbar... if (paneResize) { paneResize = false; // Change size of current frame if (getHeight() != newHeight) { Dimension newSize = new Dimension(getWidth(), newHeight); setPreferredSize(newSize); setSize(newSize); parentFrame.validate(); // Ensures that scroller.getMaximum() is up to date. // If pane is resized, scrolling always starts at the bottom. The only place // where looks wrong is when we have a continuous track with negative values. scroller.setValue(scroller.getMaximum()); repaint(); return false; } } else if (oldViewHeight != -1 && oldViewHeight != getViewportHeight()) { int newViewHeight = getViewportHeight(); int oldScroll = scroller.getValue(); scroller.setValue(oldScroll + (oldViewHeight - newViewHeight)); oldViewHeight = newViewHeight; } oldWidth = parentFrame.getFrameLandscape().getWidth(); oldHeight = parentFrame.getFrameLandscape().getHeight(); g2.drawImage(bufferedImage, 0, getOffset(), this); fireExportEvent(xRange, bufferedImage); renderCurrentSelected(g2); } return true; }
From source file:org.tsho.dmc2.core.chart.DmcLyapunovPlot.java
public boolean renderVsParameter(Graphics2D g2, Rectangle2D dataArea) { final int imageWidth = (int) dataArea.getWidth(); g2.setPaint(Color.red);//from w ww .j a v a2 s . c o m final double parStep; parStep = Math.abs(upper - lower) / imageWidth; CoreStatusEvent statusEv = new CoreStatusEvent(this); //int ratio = upper / 100; int prevX[] = new int[model.getNVar()]; int prevY[] = new int[model.getNVar()]; for (double i = lower; i < upper; i += parStep) { double[] result; int transX, transY; parameters.put(firstParLabel, i); try { result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, iterations); } catch (ModelException e) { String mess = "Exception while:\n" + dumpVariableDoubles(parameters) + dumpVariableDoubles(initialPoint); throw new ModelException(mess, e); } for (int j = 0; j < result.length; j++) { transX = (int) this.domainAxis.valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) this.rangeAxis.valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); // System.out.println("ly[" + j + "] = " + result[j]); // System.out.println("x: " + transX + " y: " + transY); g2.setPaint(paintSequence[j]); //g2.fillRect(transX, transY, 1, 1); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i != lower) { g2.drawLine(transX, transY, prevX[j], prevY[j]); } prevX[j] = transX; prevY[j] = transY; } } if (stopped == true) { return false; } //else if (ratio > 0 && i % ratio == 0) { statusEv.setPercent(0); statusEv.setType(CoreStatusEvent.COUNT | CoreStatusEvent.PERCENT); notifyCoreStatusListeners(statusEv); //} } return true; }