List of usage examples for java.awt Graphics2D fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
private void renderRange(LongRange pRange, LongRange pStartRange, LongRange pArriveRange, boolean pIsStartRange, boolean pIsArriveRange, Graphics2D pG2D, TimeSpan pSpanForRange, HashMap<String, Object> pPopupInfo) { int rangeStart = 0; int rangeWidth = 0; if (pRange.overlapsRange(pStartRange)) { //start range rendering long startDelta = pStartRange.getMinimumLong(); rangeStart = Math.round((pRange.getMinimumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE); // int rangeEnd = Math.round((pRange.getMaximumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE); rangeWidth = Math/*from ww w. j a v a2 s . co m*/ .round((pRange.getMaximumLong() - pRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE); } else if (pRange.overlapsRange(pArriveRange)) { //end range rendering long startDelta = pStartRange.getMinimumLong(); rangeStart = Math.round((pRange.getMinimumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE); // int rangeEnd = Math.round((pRange.getMaximumLong() - arriveDelta) / DateUtils.MILLIS_PER_MINUTE); rangeWidth = Math .round((pRange.getMaximumLong() - pRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE); } //correct small widths if (rangeWidth == 0) { rangeWidth = 5; } long max = Math.round( (pArriveRange.getMaximumLong() - pStartRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE); if (rangeStart > max) { return; } SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy HH:mm:ss"); String labelString = ""; if (pSpanForRange != null) { labelString = pSpanForRange.toString(); } else { labelString = f.format(new Date(pRange.getMinimumLong())) + " bis " + f.format(new Date(pRange.getMaximumLong())); } Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(labelString, pG2D); if (pIsStartRange) { pG2D.setColor(Color.RED); pG2D.fillRect(rangeStart, 20, rangeWidth, 20); pG2D.setColor(Color.BLACK); pG2D.drawRect(rangeStart, 20, rangeWidth, 20); pG2D.setColor(Color.RED); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 14.0f)); pG2D.drawString(labelString, rangeStart, (int) labelBounds.getHeight()); } else if (pIsArriveRange) { pG2D.setColor(Color.GREEN.darker()); pG2D.fillRect(rangeStart, 20, rangeWidth, 20); pG2D.setColor(Color.BLACK); pG2D.drawRect(rangeStart, 20, rangeWidth, 20); pG2D.setColor(Color.GREEN.darker()); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 14.0f)); pG2D.drawString(labelString, rangeStart, (int) labelBounds.getHeight() + 40); } else { pG2D.fillRect(rangeStart, 20, rangeWidth, 20); pG2D.setColor(Color.BLACK); pG2D.drawRect(rangeStart, 20, rangeWidth, 20); Point loc = getMousePosition(); if (loc != null && new Rectangle(rangeStart, 20, rangeWidth, 20).contains(loc)) { pPopupInfo.put("popup.location", loc); pPopupInfo.put("popup.label", labelString); pPopupInfo.put("active.range", pRange); pPopupInfo.put("span.for.range", pSpanForRange); } } }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java
/** * Draw the sunrise/sunset curves// w w w . j a v a2 s . c om * * @param g2 the graphics area * @param plot the plot * @param dataArea the date range */ private void drawSunriseSunset(Graphics2D g2, XYPlot plot, Rectangle2D dataArea) { if (sunriseLocation == null) { return; } DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); Date startDate = ((DateAxis) domainAxis).getMinimumDate(); Date endDate = ((DateAxis) domainAxis).getMaximumDate(); if ((sunriseDates == null) || !Misc.equals(startDate, lastStartDate) || !Misc.equals(endDate, lastEndDate)) { lastStartDate = startDate; lastEndDate = endDate; sunriseDates = IdvTimeline.makeSunriseDates(sunriseLocation, startDate, endDate); } int top = (int) (dataArea.getY()); int bottom = (int) (dataArea.getY() + dataArea.getHeight()); int height = bottom - top; g2.setColor(Color.yellow); Shape originalClip = g2.getClip(); g2.clip(dataArea); for (int i = 0; i < sunriseDates.size(); i += 2) { Date d1 = (Date) sunriseDates.get(i + 1); Date d2 = (Date) sunriseDates.get(i); int x1 = (int) domainAxis.valueToJava2D(d1.getTime(), dataArea, RectangleEdge.BOTTOM); int x2 = (int) domainAxis.valueToJava2D(d2.getTime(), dataArea, RectangleEdge.BOTTOM); g2.fillRect(x1, top, (x2 - x1), height); } g2.setClip(originalClip); }
From source file:com.dlya.facturews.DlyaPdfExporter2.java
/** * *//*from w w w. j ava2 s . c o m*/ public void exportImage(JRPrintImage printImage) throws DocumentException, IOException, JRException { if (printImage.getModeValue() == ModeEnum.OPAQUE) { pdfContentByte.setRGBColorFill(printImage.getBackcolor().getRed(), printImage.getBackcolor().getGreen(), printImage.getBackcolor().getBlue()); pdfContentByte.rectangle(printImage.getX() + getOffsetX(), jasperPrint.getPageHeight() - printImage.getY() - getOffsetY(), printImage.getWidth(), -printImage.getHeight()); pdfContentByte.fill(); } int topPadding = printImage.getLineBox().getTopPadding().intValue(); int leftPadding = printImage.getLineBox().getLeftPadding().intValue(); int bottomPadding = printImage.getLineBox().getBottomPadding().intValue(); int rightPadding = printImage.getLineBox().getRightPadding().intValue(); int availableImageWidth = printImage.getWidth() - leftPadding - rightPadding; availableImageWidth = (availableImageWidth < 0) ? 0 : availableImageWidth; int availableImageHeight = printImage.getHeight() - topPadding - bottomPadding; availableImageHeight = (availableImageHeight < 0) ? 0 : availableImageHeight; Renderable renderer = printImage.getRenderable(); if (renderer != null && availableImageWidth > 0 && availableImageHeight > 0) { if (renderer.getTypeValue() == RenderableTypeEnum.IMAGE) { // Image renderers are all asked for their image data at some point. // Better to test and replace the renderer now, in case of lazy load error. renderer = RenderableUtil.getInstance(jasperReportsContext).getOnErrorRendererForImageData(renderer, printImage.getOnErrorTypeValue()); } } else { renderer = null; } if (renderer != null) { int xoffset = 0; int yoffset = 0; Chunk chunk = null; float scaledWidth = availableImageWidth; float scaledHeight = availableImageHeight; if (renderer.getTypeValue() == RenderableTypeEnum.IMAGE) { com.lowagie.text.Image image = null; float xalignFactor = getXAlignFactor(printImage); float yalignFactor = getYAlignFactor(printImage); switch (printImage.getScaleImageValue()) { case CLIP: { // Image load might fail, from given image data. // Better to test and replace the renderer now, in case of lazy load error. renderer = RenderableUtil.getInstance(jasperReportsContext) .getOnErrorRendererForDimension(renderer, printImage.getOnErrorTypeValue()); if (renderer == null) { break; } int normalWidth = availableImageWidth; int normalHeight = availableImageHeight; Dimension2D dimension = renderer.getDimension(jasperReportsContext); if (dimension != null) { normalWidth = (int) dimension.getWidth(); normalHeight = (int) dimension.getHeight(); } xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth)); yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight)); int minWidth = Math.min(normalWidth, availableImageWidth); int minHeight = Math.min(normalHeight, availableImageHeight); BufferedImage bi = new BufferedImage(minWidth, minHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); if (printImage.getModeValue() == ModeEnum.OPAQUE) { g.setColor(printImage.getBackcolor()); g.fillRect(0, 0, minWidth, minHeight); } renderer.render(jasperReportsContext, g, new java.awt.Rectangle((xoffset > 0 ? 0 : xoffset), (yoffset > 0 ? 0 : yoffset), normalWidth, normalHeight)); g.dispose(); xoffset = (xoffset < 0 ? 0 : xoffset); yoffset = (yoffset < 0 ? 0 : yoffset); //awtImage = bi.getSubimage(0, 0, minWidth, minHeight); //image = com.lowagie.text.Image.getInstance(awtImage, printImage.getBackcolor()); image = com.lowagie.text.Image.getInstance(bi, null); break; } case FILL_FRAME: { if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer)) { image = loadedImagesMap.get(renderer); } else { try { image = com.lowagie.text.Image.getInstance(renderer.getImageData(jasperReportsContext)); imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0); } catch (Exception e) { JRImageRenderer tmpRenderer = JRImageRenderer.getOnErrorRendererForImage( jasperReportsContext, JRImageRenderer.getInstance(renderer.getImageData(jasperReportsContext)), printImage.getOnErrorTypeValue()); if (tmpRenderer == null) { break; } java.awt.Image awtImage = tmpRenderer.getImage(jasperReportsContext); image = com.lowagie.text.Image.getInstance(awtImage, null); } if (printImage.isUsingCache()) { loadedImagesMap.put(renderer, image); } } image.scaleAbsolute(availableImageWidth, availableImageHeight); break; } case RETAIN_SHAPE: default: { if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer)) { image = loadedImagesMap.get(renderer); } else { try { image = com.lowagie.text.Image.getInstance(renderer.getImageData(jasperReportsContext)); imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0); } catch (Exception e) { JRImageRenderer tmpRenderer = JRImageRenderer.getOnErrorRendererForImage( jasperReportsContext, JRImageRenderer.getInstance(renderer.getImageData(jasperReportsContext)), printImage.getOnErrorTypeValue()); if (tmpRenderer == null) { break; } java.awt.Image awtImage = tmpRenderer.getImage(jasperReportsContext); image = com.lowagie.text.Image.getInstance(awtImage, null); } if (printImage.isUsingCache()) { loadedImagesMap.put(renderer, image); } } image.scaleToFit(availableImageWidth, availableImageHeight); xoffset = (int) (xalignFactor * (availableImageWidth - image.plainWidth())); yoffset = (int) (yalignFactor * (availableImageHeight - image.plainHeight())); xoffset = (xoffset < 0 ? 0 : xoffset); yoffset = (yoffset < 0 ? 0 : yoffset); break; } } if (image != null) { chunk = new Chunk(image, 0, 0); scaledWidth = image.scaledWidth(); scaledHeight = image.scaledHeight(); } } else { double normalWidth = availableImageWidth; double normalHeight = availableImageHeight; double displayWidth = availableImageWidth; double displayHeight = availableImageHeight; double ratioX = 1f; double ratioY = 1f; Rectangle2D clip = null; Dimension2D dimension = renderer.getDimension(jasperReportsContext); if (dimension != null) { normalWidth = dimension.getWidth(); normalHeight = dimension.getHeight(); displayWidth = normalWidth; displayHeight = normalHeight; float xalignFactor = getXAlignFactor(printImage); float yalignFactor = getYAlignFactor(printImage); switch (printImage.getScaleImageValue()) { case CLIP: { xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth)); yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight)); clip = new Rectangle2D.Double(-xoffset, -yoffset, availableImageWidth, availableImageHeight); break; } case FILL_FRAME: { ratioX = availableImageWidth / normalWidth; ratioY = availableImageHeight / normalHeight; normalWidth *= ratioX; normalHeight *= ratioY; xoffset = 0; yoffset = 0; break; } case RETAIN_SHAPE: default: { ratioX = availableImageWidth / normalWidth; ratioY = availableImageHeight / normalHeight; ratioX = ratioX < ratioY ? ratioX : ratioY; ratioY = ratioX; normalWidth *= ratioX; normalHeight *= ratioY; xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth)); yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight)); break; } } } PdfTemplate template = pdfContentByte.createTemplate((float) displayWidth, (float) displayHeight); Graphics2D g = forceSvgShapes ? template.createGraphicsShapes((float) displayWidth, (float) displayHeight) : template.createGraphics(availableImageWidth, availableImageHeight, new LocalFontMapper()); if (clip != null) { g.setClip(clip); } if (printImage.getModeValue() == ModeEnum.OPAQUE) { g.setColor(printImage.getBackcolor()); g.fillRect(0, 0, (int) displayWidth, (int) displayHeight); } Rectangle2D rectangle = new Rectangle2D.Double(0, 0, displayWidth, displayHeight); renderer.render(jasperReportsContext, g, rectangle); g.dispose(); pdfContentByte.saveState(); pdfContentByte.addTemplate(template, (float) ratioX, 0f, 0f, (float) ratioY, printImage.getX() + getOffsetX() + xoffset, jasperPrint.getPageHeight() - printImage.getY() - getOffsetY() - (int) normalHeight - yoffset); pdfContentByte.restoreState(); Image image = getPxImage(); image.scaleAbsolute(availableImageWidth, availableImageHeight); chunk = new Chunk(image, 0, 0); } /* image.setAbsolutePosition( printImage.getX() + offsetX + borderOffset, jasperPrint.getPageHeight() - printImage.getY() - offsetY - image.scaledHeight() - borderOffset ); pdfContentByte.addImage(image); */ if (chunk != null) { setAnchor(chunk, printImage, printImage); setHyperlinkInfo(chunk, printImage); //tagHelper.startImage(printImage); ColumnText colText = new ColumnText(pdfContentByte); int upperY = jasperPrint.getPageHeight() - printImage.getY() - topPadding - getOffsetY() - yoffset; int lowerX = printImage.getX() + leftPadding + getOffsetX() + xoffset; colText.setSimpleColumn(new Phrase(chunk), lowerX, upperY - scaledHeight, lowerX + scaledWidth, upperY, scaledHeight, Element.ALIGN_LEFT); colText.go(); //tagHelper.endImage(); } } if (printImage.getLineBox().getTopPen().getLineWidth().floatValue() <= 0f && printImage.getLineBox().getLeftPen().getLineWidth().floatValue() <= 0f && printImage.getLineBox().getBottomPen().getLineWidth().floatValue() <= 0f && printImage.getLineBox().getRightPen().getLineWidth().floatValue() <= 0f) { if (printImage.getLinePen().getLineWidth().floatValue() > 0f) { exportPen(printImage.getLinePen(), printImage); } } else { /* */ exportBox(printImage.getLineBox(), printImage); } }
From source file:com.t3.client.ui.ChatTypingNotification.java
/** * This component is only made visible when there are notifications to be displayed. That means the first couple of * IF statements in this method are redundant since paintComponent() will not be called unless the component is * visible, and it will only be visible when there are notifications... *//*ww w. ja va 2 s .c o m*/ @Override protected void paintComponent(Graphics g) { // System.out.println("Chat panel is painting itself..."); if (AppPreferences.getTypingNotificationDuration() != 0) { LinkedMap<String, Long> chatTypers = TabletopTool.getFrame().getChatNotificationTimers() .getChatTypers(); if (chatTypers == null || chatTypers.isEmpty()) { return; } Boolean showBackground = AppPreferences.getChatNotificationShowBackground(); Graphics2D statsG = (Graphics2D) g.create(); Font boldFont = AppStyle.labelFont.deriveFont(Font.BOLD); Font font = AppStyle.labelFont; FontMetrics valueFM = g.getFontMetrics(font); FontMetrics keyFM = g.getFontMetrics(boldFont); int PADDING7 = 7; int PADDING3 = 3; int PADDING2 = 2; BufferedImage img = AppStyle.panelTexture; int rowHeight = Math.max(valueFM.getHeight(), keyFM.getHeight()); setBorder(null); int width = AppStyle.miniMapBorder.getRightMargin() + AppStyle.miniMapBorder.getLeftMargin(); int height = getHeight() - PADDING2 + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin(); statsG.setFont(font); SwingUtil.useAntiAliasing(statsG); Rectangle bounds = new Rectangle(AppStyle.miniMapBorder.getLeftMargin(), height - getHeight() - AppStyle.miniMapBorder.getTopMargin(), getWidth() - width, getHeight() - AppStyle.miniMapBorder.getBottomMargin() - AppStyle.miniMapBorder.getTopMargin() + PADDING2); int y = bounds.y + rowHeight; rowHeight = Math.max(rowHeight, AppStyle.chatImage.getHeight()); setSize(getWidth(), ((chatTypers.size() * (PADDING3 + rowHeight)) + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin())); if (showBackground) { g.drawImage(img, 0, 0, getWidth(), getHeight() + PADDING7, this); AppStyle.miniMapBorder.paintAround(statsG, bounds); } Rectangle rightRow = new Rectangle(AppStyle.miniMapBorder.getLeftMargin() + PADDING7, AppStyle.miniMapBorder.getTopMargin() + PADDING7, AppStyle.chatImage.getWidth(), AppStyle.chatImage.getHeight()); Set<?> keySet = chatTypers.keySet(); @SuppressWarnings("unchecked") Set<String> playerTimers = (Set<String>) keySet; Color c1 = new Color(249, 241, 230, 140); Color c2 = new Color(175, 163, 149); for (String playerNamer : playerTimers) { if (showBackground) { statsG.setColor(c1); statsG.fillRect(bounds.x + PADDING3, y - keyFM.getAscent(), (bounds.width - PADDING7 / 2) - PADDING3, rowHeight); statsG.setColor(c2); statsG.drawRect(bounds.x + PADDING3, y - keyFM.getAscent(), (bounds.width - PADDING7 / 2) - PADDING3, rowHeight); } g.drawImage(AppStyle.chatImage, bounds.x + 5, y - keyFM.getAscent(), (int) rightRow.getWidth(), (int) rightRow.getHeight(), this); // Values statsG.setColor(TabletopTool.getFrame().getChatTypingLabelColor()); statsG.setFont(boldFont); statsG.drawString(I18N.getText("msg.commandPanel.liveTyping", playerNamer), bounds.x + AppStyle.chatImage.getWidth() + PADDING7 * 2, y + 5); y += PADDING2 + rowHeight; } if (showBackground) { AppStyle.shadowBorder.paintWithin(statsG, bounds); } else { setOpaque(false); } } }
From source file:juicebox.track.EigenvectorTrack.java
/** * Render the track in the supplied rectangle. It is the responsibility of the track to draw within the * bounds of the rectangle.//from w w w.j av a 2s . c om * * @param g2d the graphics context * @param rect the track bounds, relative to the enclosing DataPanel bounds. * @param gridAxis */ @Override public void render(Graphics2D g2d, Context context, Rectangle rect, TrackPanel.Orientation orientation, HiCGridAxis gridAxis) { g2d.setColor(color); int height = orientation == TrackPanel.Orientation.X ? rect.height : rect.width; int width = orientation == TrackPanel.Orientation.X ? rect.width : rect.height; int y = orientation == TrackPanel.Orientation.X ? rect.y : rect.x; int x = orientation == TrackPanel.Orientation.X ? rect.x : rect.y; MatrixZoomData zd; try { zd = hic.getZd(); } catch (Exception e) { return; } int zoom = zd.getZoom().getBinSize(); if (zoom != currentZoom) { clearDataCache(); } int chrIdx = orientation == TrackPanel.Orientation.X ? zd.getChr1Idx() : zd.getChr2Idx(); double[] eigen = dataCache.get(chrIdx); if (eigen == null) { eigen = hic.getEigenvector(chrIdx, 0); currentZoom = zoom; setData(chrIdx, eigen); } if (eigen == null || eigen.length == 0) { Font original = g2d.getFont(); g2d.setFont(FontManager.getFont(12)); if (orientation == TrackPanel.Orientation.X) { GraphicUtils.drawCenteredText("Eigenvector not available at this resolution", rect, g2d); } else { drawRotatedString(g2d, "Eigenvector not available at this resolution", (2 * rect.height) / 3, rect.x + 15); } g2d.setFont(original); return; } double dataMax = dataMaxCache.get(chrIdx); double median = medianCache.get(chrIdx); int h = height / 2; for (int bin = (int) context.getBinOrigin(); bin < eigen.length; bin++) { if (Double.isNaN(eigen[bin])) continue; int xPixelLeft = x + (int) ((bin - context.getBinOrigin()) * hic.getScaleFactor()); int xPixelRight = x + (int) ((bin + 1 - context.getBinOrigin()) * hic.getScaleFactor()); if (xPixelRight < x) { continue; } else if (xPixelLeft > x + width) { break; } double x2 = eigen[bin] - median; double max = dataMax - median; int myh = (int) ((x2 / max) * h); if (x2 > 0) { g2d.fillRect(xPixelLeft, y + h - myh, (xPixelRight - xPixelLeft), myh); } else { g2d.fillRect(xPixelLeft, y + h, (xPixelRight - xPixelLeft), -myh); } } }
From source file:org.pmedv.blackboard.components.BoardEditor.java
/** * Draws the selected item to the graphics context * //from w w w.j a v a2 s .c o m * @param layer the layer to be drawn * @param g2d the graphics context */ private void drawLayer(Layer layer, Graphics2D g2d) { if (!layer.isVisible()) return; DefaultTransformModel xmodel = null; if (zoomLayer != null) { TransformUI ui = (TransformUI) (Object) zoomLayer.getUI(); xmodel = (DefaultTransformModel) ui.getModel(); } if (layer.getName().equalsIgnoreCase("board")) { if (backgroundImage != null) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity())); g2d.drawImage(backgroundImage, 0, 0, this); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); } else { g2d.setColor(Color.WHITE); g2d.fillRect(0, 0, getWidth(), getHeight()); } g2d.setColor(Color.LIGHT_GRAY); g2d.setStroke(BoardUtil.stroke_1_0f); Boolean dotGrid = (Boolean) Preferences.values .get("org.pmedv.blackboard.BoardDesignerPerspective.dotGrid"); // draw grid if (gridVisible) { BoardUtil.drawGrid(g2d, raster, model.getWidth(), model.getHeight(), dotGrid.booleanValue()); } return; } if (layer.getName().equalsIgnoreCase("ratsnest")) { if (layer.getImage() != null) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity())); g2d.drawImage(layer.getImage(), 0, 0, this); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); } return; } for (Item item : layer.getItems()) { if (xmodel != null) item.setMirror(xmodel.isMirror()); item.setOpacity(layer.getOpacity()); if (item instanceof Line) { Line line = (Line) item; if (line.getStroke() != null) g2d.setStroke(line.getStroke()); else g2d.setStroke(BoardUtil.stroke_3_0f); g2d.setColor(item.getColor()); } item.draw(g2d); if (selectedItems.contains(item)) { g2d.setColor(Color.GREEN); g2d.setStroke(BoardUtil.stroke_1_0f); item.drawHandles(g2d, 8); } } }
From source file:org.prom5.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * convenience method for internal use./*from ww w . j av a 2 s. co m*/ * paints the log lane, with time indicators. * @param gOrig * @param dMin date on the left boundary * @param dMax date on the right boundary */ protected void paintComponentLane(Graphics2D g, int width, int hight) { g.setFont(g.getFont().deriveFont((float) 10.0)); // set initial colors Color fgColor = null; Color bgColor = null; Color tmpColor = null; fgColor = null; bgColor = null; // calculate common coordinates int unitHeight = hight / getHashMapSize(); int yTop = 0; int yBottom = hight; int pixStart = 0; String dateStr, timeStr, millisStr = null; // calculate area to be painted clipL = 0; clipR = width; // initialze start color fgColor = colorLogDark; bgColor = colorLogBright; // calculate current top int currentTop = yTop; // paint actual log lane (only the part in the clipping range determined) Iterator itr = dcModel.getSortedKeySetList().iterator(); //dcModel.getItemMap().keySet().iterator(); g.setFont(new Font("Dialog", Font.BOLD, 13)); int index = 0; currentTop = yTop; while (itr.hasNext()) { String dimName = (String) itr.next(); if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(dimName)) continue; g.setColor(bgColor); g.fillRect(pixStart, currentTop, clipR, currentTop + unitHeight); g.setColor(fgColor); index++; currentTop = unit2Cord_buffer(index, hight); // swap colors tmpColor = fgColor; fgColor = bgColor; bgColor = tmpColor; } g.setFont(new Font("Dialog", Font.PLAIN, 12)); // draw horizontal delimiters g.setColor(colorTimeLine); g.drawLine(clipL, yTop, clipR, yTop); g.drawLine(clipL, yBottom, clipR, yBottom); clipLeftTs = coord2timeMillis(clipL); clipRightTs = coord2timeMillis(clipR); }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * convenience method for internal use. paints the log lane, with time * indicators.//w w w . j a v a 2 s . c o m * * @param gOrig * @param dMin * date on the left boundary * @param dMax * date on the right boundary */ protected void paintComponentLane(Graphics2D g, int width, int hight) { g.setFont(g.getFont().deriveFont((float) 10.0)); // set initial colors Color fgColor = null; Color bgColor = null; Color tmpColor = null; fgColor = null; bgColor = null; // calculate common coordinates int unitHeight = hight / getHashMapSize(); int yTop = 0; int yBottom = hight; int pixStart = 0; String dateStr, timeStr, millisStr = null; // calculate area to be painted clipL = 0; clipR = width; // initialze start color fgColor = colorLogDark; bgColor = colorLogBright; // calculate current top int currentTop = yTop; // paint actual log lane (only the part in the clipping range // determined) Iterator itr = dcModel.getSortedKeySetList().iterator(); // dcModel.getItemMap().keySet().iterator(); g.setFont(new Font("Dialog", Font.BOLD, 13)); int index = 0; currentTop = yTop; while (itr.hasNext()) { String dimName = (String) itr.next(); if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(dimName)) continue; g.setColor(bgColor); g.fillRect(pixStart, currentTop, clipR, currentTop + unitHeight); g.setColor(fgColor); index++; currentTop = unit2Cord_buffer(index, hight); // swap colors tmpColor = fgColor; fgColor = bgColor; bgColor = tmpColor; } g.setFont(new Font("Dialog", Font.PLAIN, 12)); // draw horizontal delimiters g.setColor(colorTimeLine); g.drawLine(clipL, yTop, clipR, yTop); g.drawLine(clipL, yBottom, clipR, yBottom); clipLeftTs = coord2timeMillis(clipL); clipRightTs = coord2timeMillis(clipR); }
From source file:org.tsho.dmc2.core.chart.BifurcationSimpleRenderer.java
public void render(final Graphics2D g2, final Rectangle2D dataArea, PlotRenderingInfo info) { if (model instanceof ODE) { boolean pointBeyondPoincareSection; int numVar = model.getNVar(); ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); Stepper.Point2D result;/*from w w w .j a v a2 s. com*/ g2.setPaint(plot.getPaint()); parLower = domainAxis.getRange().getLowerBound(); parUpper = domainAxis.getRange().getUpperBound(); final double parStep; parStep = Math.abs(parUpper - parLower) / dataArea.getWidth(); stepper.setAxes(variableIdx, variableIdx); state = STATE_RUNNING; for (index = parLower; index < parUpper; index += parStep) { fixedParameters[parameterIdx] = index; stepper.setParameters(fixedParameters); stepper.setInitialValue(initialValue); stepper.initialize(); int h = 0; int transX, transY; double[] currentPoint = new double[numVar]; double[] previousPoint = new double[numVar]; stepper.getCurrentValue(currentPoint); stepper.getCurrentValue(previousPoint); pointBeyondPoincareSection = positionWrtPoincareSection(currentPoint); for (int j = 0; j < time / step; j++) { stepper.step(); stepper.getCurrentValue(currentPoint); if (positionWrtPoincareSection(currentPoint) == pointBeyondPoincareSection) { stepper.getCurrentValue(previousPoint); continue; } pointBeyondPoincareSection = !pointBeyondPoincareSection; double[] pointOnSection = pointOnPoincareSection(previousPoint, currentPoint); stepper.setInitialValue(pointOnSection); stepper.initialize(); stepper.getCurrentValue(currentPoint); stepper.getCurrentValue(previousPoint); //pointBeyondPoincareSection=positionWrtPoincareSection(currentPoint,coeff); result = stepper.getCurrentPoint2D(); transX = (int) domainAxis.valueToJava2D(index, dataArea, RectangleEdge.BOTTOM); transY = (int) rangeAxis.valueToJava2D(result.getX(), dataArea, RectangleEdge.LEFT); h++; if (h > transients) { g2.fillRect(transX, transY, 1, 1); } } if (!fixedInitialPoint) { stepper.getCurrentValue(initialValue); } if (stopped) { state = STATE_STOPPED; return; } } state = STATE_FINISHED; } else { //the system is discrete ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); Stepper.Point2D result; g2.setPaint(plot.getPaint()); parLower = domainAxis.getRange().getLowerBound(); parUpper = domainAxis.getRange().getUpperBound(); final double parStep; parStep = Math.abs(parUpper - parLower) / dataArea.getWidth(); stepper.setAxes(variableIdx, variableIdx); state = STATE_RUNNING; for (index = parLower; index < parUpper; index += parStep) { fixedParameters[parameterIdx] = index; stepper.setParameters(fixedParameters); stepper.setInitialValue(initialValue); stepper.initialize(); for (int h = 0; h < transients; h++) { if (stopped) { state = STATE_STOPPED; return; } stepper.step(); } int transX, transY; for (int j = 0; j < iterations; j++) { stepper.step(); result = stepper.getCurrentPoint2D(); transX = (int) domainAxis.valueToJava2D(index, dataArea, RectangleEdge.BOTTOM); transY = (int) rangeAxis.valueToJava2D(result.getX(), dataArea, RectangleEdge.LEFT); g2.fillRect(transX, transY, 1, 1); } if (!fixedInitialPoint) { stepper.getCurrentValue(initialValue); } if (stopped) { state = STATE_STOPPED; return; } } state = STATE_FINISHED; } }
From source file:org.tsho.dmc2.core.chart.LyapunovRenderer.java
public boolean renderVsParameter(Graphics2D g2, Rectangle2D dataArea) { final int imageWidth = (int) dataArea.getWidth(); g2.setPaint(Color.red);/*w w w .j a v a 2 s . c om*/ final double parStep; int prevX[] = new int[model.getNVar()]; int prevY[] = new int[model.getNVar()]; //? 28.7.2004 ValueAxis domainAxis = plot.getDomainAxis(); lower = domainAxis.getRange().getLowerBound(); upper = domainAxis.getRange().getUpperBound(); parStep = Math.abs(upper - lower) / imageWidth; String colNames[] = new String[model.getNVar() + 1]; colNames[0] = firstParLabel; for (int j = 1; j < (model.getNVar() + 1); j++) colNames[j] = "" + (new Integer(j)); Dataset dataset = new Dataset(colNames); lyapunovComponent.setDataobject(dataset); double tmpRow[]; if (model instanceof ODE) { double step = stepSize; // stepSize and timeStep probably mean the same thing, one for discrete another for ODE for (double i = lower; i < upper; i += parStep) { double[] result = new double[model.getNVar()];//initializing not needed but compiler too cautious. int transX, transY; parameters.put(firstParLabel, i); result = Lua.evaluateLyapunovExponentsODE(model, parameters, initialPoint, timePeriod, stepSize); tmpRow = new double[model.getNVar() + 1]; tmpRow[0] = i; for (int a1 = 1; a1 < tmpRow.length; a1++) tmpRow[a1] = result[a1 - 1]; try { dataset.addRow(tmpRow); } catch (DatasetException de) { System.out.println("" + de); } for (int j = 0; j < result.length; j++) { if (Double.isNaN(result[j])) break; transX = (int) plot.getDomainAxis().valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) plot.getRangeAxis().valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); g2.setPaint(paintSequence[j]); 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; } } } //? 28.7.2004 else { for (double i = lower; i < upper; i += parStep) { double[] result; int transX, transY; parameters.put(firstParLabel, i); result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, iterations); tmpRow = new double[model.getNVar() + 1]; tmpRow[0] = i; for (int a1 = 1; a1 < tmpRow.length; a1++) tmpRow[a1] = result[a1 - 1]; try { dataset.addRow(tmpRow); } catch (DatasetException de) { System.out.println("" + de); } for (int j = 0; j < result.length; j++) { if (Double.isNaN(result[j])) break; transX = (int) plot.getDomainAxis().valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) plot.getRangeAxis().valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); g2.setPaint(paintSequence[j]); 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; } } } return true; }