List of usage examples for java.awt.image BufferedImage getGraphics
public java.awt.Graphics getGraphics()
From source file:au.com.gaiaresources.bdrs.controller.test.TestDataCreator.java
private byte[] createImage(int width, int height, String text) throws IOException { if (width < 0) { width = random.nextInt(DEFAULT_MAX_IMAGE_WIDTH - DEFAULT_MIN_IMAGE_WIDTH) + DEFAULT_MIN_IMAGE_WIDTH; }/*w w w. j a v a2s . co m*/ if (height < 0) { height = random.nextInt(DEFAULT_MAX_IMAGE_HEIGHT - DEFAULT_MIN_IMAGE_HEIGHT) + DEFAULT_MIN_IMAGE_HEIGHT; } BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) img.getGraphics(); g2.setBackground(new Color(220, 220, 220)); Dimension size; float fontSize = g2.getFont().getSize(); // Make the text as large as possible. do { g2.setFont(g2.getFont().deriveFont(fontSize)); FontMetrics metrics = g2.getFontMetrics(g2.getFont()); int hgt = metrics.getHeight(); int adv = metrics.stringWidth(text); size = new Dimension(adv + 2, hgt + 2); fontSize = fontSize + 1f; } while (size.width < Math.round(0.9 * width) && size.height < Math.round(0.9 * height)); g2.setColor(Color.DARK_GRAY); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.drawString(text, (width - size.width) / 2, (height - size.height) / 2); g2.setColor(Color.LIGHT_GRAY); g2.drawRect(0, 0, width - 1, height - 1); ByteArrayOutputStream baos = new ByteArrayOutputStream(width * height); ImageIO.write(img, "png", baos); baos.flush(); byte[] rawBytes = baos.toByteArray(); baos.close(); return rawBytes; }
From source file:org.colombbus.tangara.CommandSelection.java
/** * Initializes the icons//from www. ja va 2 s . co m * */ private void initializeIcons() { BufferedImage imageSelected = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) imageSelected.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(selectedBackgroundColor); g.fillRect(0, 0, iconSize, iconSize); g.setColor(Color.green); g.fillOval(0, 0, iconSize - 1, iconSize - 1); iconSelected = new ImageIcon(imageSelected); BufferedImage imageNotSelected = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_RGB); g = (Graphics2D) imageNotSelected.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.white); g.fillRect(0, 0, iconSize, iconSize); g.setColor(Color.lightGray); g.fillOval(0, 0, iconSize - 1, iconSize - 1); iconNotSelected = new ImageIcon(imageNotSelected); }
From source file:gdt.jgui.entity.webset.JWeblinkEditor.java
/** * Get the context locator./* w w w .j a v a 2 s . co m*/ * @return the context locator. */ @Override public String getLocator() { try { Properties locator = new Properties(); locator.setProperty(BaseHandler.HANDLER_CLASS, getClass().getName()); locator.setProperty(BaseHandler.HANDLER_SCOPE, JConsoleHandler.CONSOLE_SCOPE); locator.setProperty(JContext.CONTEXT_TYPE, getType()); locator.setProperty(Locator.LOCATOR_TITLE, getTitle()); if (entityLabel$ != null) { locator.setProperty(EntityHandler.ENTITY_LABEL, entityLabel$); } if (entityKey$ != null) locator.setProperty(EntityHandler.ENTITY_KEY, entityKey$); if (entihome$ != null) locator.setProperty(Entigrator.ENTIHOME, entihome$); if (webLinkKey$ != null) locator.setProperty(JWeblinksPanel.WEB_LINK_KEY, webLinkKey$); String icon$ = null; try { Icon icon = iconIcon.getIcon(); int type = BufferedImage.TYPE_INT_RGB; BufferedImage out = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), type); Graphics2D g2 = out.createGraphics(); icon.paintIcon(new JPanel(), out.getGraphics(), 0, 0); g2.dispose(); ByteArrayOutputStream b = new ByteArrayOutputStream(); ImageIO.write(out, "png", b); b.close(); byte[] ba = b.toByteArray(); icon$ = Base64.encodeBase64String(ba); } catch (Exception ee) { } if (icon$ == null) icon$ = Support.readHandlerIcon(null, JEntitiesPanel.class, "edit.png"); locator.setProperty(Locator.LOCATOR_ICON, icon$); return Locator.toString(locator); } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); return null; } }
From source file:J3dSwingFrame.java
/** * Set the texture on our goemetry//from w w w .j a va2 s .c om * <P> * Always specified as a URL so that we may fetch it from anywhere. * * @param url * The url to the image. */ public void setTexture(URL url) { Toolkit tk = Toolkit.getDefaultToolkit(); Image src_img = tk.createImage(url); BufferedImage buf_img = null; if (!(src_img instanceof BufferedImage)) { // create a component anonymous inner class to give us the image // observer we need to get the width and height of the source image. Component obs = new Component() { }; int width = src_img.getWidth(obs); int height = src_img.getHeight(obs); // construct the buffered image from the source data. buf_img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics g = buf_img.getGraphics(); g.drawImage(src_img, 0, 0, null); g.dispose(); } else buf_img = (BufferedImage) src_img; src_img.flush(); ImageComponent img_comp = new ImageComponent2D(ImageComponent.FORMAT_RGB, buf_img); texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, img_comp.getWidth(), img_comp.getHeight()); appearance.setTexture(texture); buf_img.flush(); }
From source file:at.gv.egiz.pdfas.lib.impl.signing.pdfbox.PADESPDFBOXSigner.java
@Override public Image generateVisibleSignaturePreview(SignParameter parameter, java.security.cert.X509Certificate cert, int resolution, OperationStatus status, RequestedSignature requestedSignature) throws PDFASError { try {//from w w w. j a v a 2s .co m PDFBOXObject pdfObject = (PDFBOXObject) status.getPdfObject(); PDDocument origDoc = new PDDocument(); origDoc.addPage(new PDPage(PDPage.PAGE_SIZE_A4)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); origDoc.save(baos); baos.close(); pdfObject.setOriginalDocument(new ByteArrayDataSource(baos.toByteArray())); SignatureProfileSettings signatureProfileSettings = TableFactory .createProfile(requestedSignature.getSignatureProfileID(), pdfObject.getStatus().getSettings()); // create Table describtion Table main = TableFactory.createSigTable(signatureProfileSettings, MAIN, pdfObject.getStatus(), requestedSignature); IPDFStamper stamper = StamperFactory.createDefaultStamper(pdfObject.getStatus().getSettings()); IPDFVisualObject visualObject = stamper.createVisualPDFObject(pdfObject, main); SignatureProfileConfiguration signatureProfileConfiguration = pdfObject.getStatus() .getSignatureProfileConfiguration(requestedSignature.getSignatureProfileID()); String signaturePosString = signatureProfileConfiguration.getDefaultPositioning(); PositioningInstruction positioningInstruction = null; if (signaturePosString != null) { positioningInstruction = Positioning.determineTablePositioning(new TablePos(signaturePosString), "", origDoc, visualObject, false, false); } else { positioningInstruction = Positioning.determineTablePositioning(new TablePos(), "", origDoc, visualObject, false, false); } origDoc.close(); SignaturePositionImpl position = new SignaturePositionImpl(); position.setX(positioningInstruction.getX()); position.setY(positioningInstruction.getY()); position.setPage(positioningInstruction.getPage()); position.setHeight(visualObject.getHeight()); position.setWidth(visualObject.getWidth()); requestedSignature.setSignaturePosition(position); PDFAsVisualSignatureProperties properties = new PDFAsVisualSignatureProperties( pdfObject.getStatus().getSettings(), pdfObject, (PdfBoxVisualObject) visualObject, positioningInstruction, signatureProfileSettings); properties.buildSignature(); PDDocument visualDoc; synchronized (PDDocument.class) { visualDoc = PDDocument.load(properties.getVisibleSignature()); } // PDPageable pageable = new PDPageable(visualDoc); List<PDPage> pages = new ArrayList<PDPage>(); visualDoc.getDocumentCatalog().getPages().getAllKids(pages); PDPage firstPage = pages.get(0); float stdRes = 72; float targetRes = resolution; float factor = targetRes / stdRes; BufferedImage outputImage = firstPage.convertToImage(BufferedImage.TYPE_4BYTE_ABGR, (int) targetRes); BufferedImage cutOut = new BufferedImage((int) (position.getWidth() * factor), (int) (position.getHeight() * factor), BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = (Graphics2D) cutOut.getGraphics(); graphics.drawImage(outputImage, 0, 0, cutOut.getWidth(), cutOut.getHeight(), (int) (1 * factor), (int) (outputImage.getHeight() - ((position.getHeight() + 1) * factor)), (int) ((1 + position.getWidth()) * factor), (int) (outputImage.getHeight() - ((position.getHeight() + 1) * factor) + (position.getHeight() * factor)), null); return cutOut; } catch (PdfAsException e) { logger.warn("PDF-AS Exception", e); throw ErrorExtractor.searchPdfAsError(e, status); } catch (Throwable e) { logger.warn("Unexpected Throwable Exception", e); throw ErrorExtractor.searchPdfAsError(e, status); } }
From source file:at.gv.egiz.pdfas.lib.impl.signing.pdfbox2.PADESPDFBOXSigner.java
@Override public Image generateVisibleSignaturePreview(SignParameter parameter, java.security.cert.X509Certificate cert, int resolution, OperationStatus status, RequestedSignature requestedSignature) throws PDFASError { try {//from w w w . j a v a2 s.c o m PDFBOXObject pdfObject = (PDFBOXObject) status.getPdfObject(); PDDocument origDoc = new PDDocument(); origDoc.addPage(new PDPage(PDRectangle.A4)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); origDoc.save(baos); baos.close(); pdfObject.setOriginalDocument(new ByteArrayDataSource(baos.toByteArray())); SignatureProfileSettings signatureProfileSettings = TableFactory .createProfile(requestedSignature.getSignatureProfileID(), pdfObject.getStatus().getSettings()); // create Table describtion Table main = TableFactory.createSigTable(signatureProfileSettings, MAIN, pdfObject.getStatus(), requestedSignature); IPDFStamper stamper = StamperFactory.createDefaultStamper(pdfObject.getStatus().getSettings()); IPDFVisualObject visualObject = stamper.createVisualPDFObject(pdfObject, main); SignatureProfileConfiguration signatureProfileConfiguration = pdfObject.getStatus() .getSignatureProfileConfiguration(requestedSignature.getSignatureProfileID()); String signaturePosString = signatureProfileConfiguration.getDefaultPositioning(); PositioningInstruction positioningInstruction = null; if (signaturePosString != null) { positioningInstruction = Positioning.determineTablePositioning(new TablePos(signaturePosString), "", origDoc, visualObject, pdfObject.getStatus().getSettings()); } else { positioningInstruction = Positioning.determineTablePositioning(new TablePos(), "", origDoc, visualObject, pdfObject.getStatus().getSettings()); } origDoc.close(); SignaturePositionImpl position = new SignaturePositionImpl(); position.setX(positioningInstruction.getX()); position.setY(positioningInstruction.getY()); position.setPage(positioningInstruction.getPage()); position.setHeight(visualObject.getHeight()); position.setWidth(visualObject.getWidth()); requestedSignature.setSignaturePosition(position); PDFAsVisualSignatureProperties properties = new PDFAsVisualSignatureProperties( pdfObject.getStatus().getSettings(), pdfObject, (PdfBoxVisualObject) visualObject, positioningInstruction, signatureProfileSettings); properties.buildSignature(); PDDocument visualDoc; synchronized (PDDocument.class) { visualDoc = PDDocument.load(properties.getVisibleSignature()); } // PDPageable pageable = new PDPageable(visualDoc); PDPage firstPage = visualDoc.getDocumentCatalog().getPages().get(0); float stdRes = 72; float targetRes = resolution; float factor = targetRes / stdRes; int targetPageNumber = 0;//TODO: is this always the case PDFRenderer pdfRenderer = new PDFRenderer(visualDoc); BufferedImage outputImage = pdfRenderer.renderImageWithDPI(targetPageNumber, targetRes, ImageType.ARGB); //BufferedImage outputImage = firstPage.convertToImage(BufferedImage.TYPE_4BYTE_ABGR, (int) targetRes); BufferedImage cutOut = new BufferedImage((int) (position.getWidth() * factor), (int) (position.getHeight() * factor), BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = (Graphics2D) cutOut.getGraphics(); graphics.drawImage(outputImage, 0, 0, cutOut.getWidth(), cutOut.getHeight(), (int) (1 * factor), (int) (outputImage.getHeight() - ((position.getHeight() + 1) * factor)), (int) ((1 + position.getWidth()) * factor), (int) (outputImage.getHeight() - ((position.getHeight() + 1) * factor) + (position.getHeight() * factor)), null); return cutOut; } catch (PdfAsException e) { logger.warn("PDF-AS Exception", e); throw ErrorExtractor.searchPdfAsError(e, status); } catch (Throwable e) { logger.warn("Unexpected Throwable Exception", e); throw ErrorExtractor.searchPdfAsError(e, status); } }
From source file:au.org.ala.layers.web.UserDataService.java
@RequestMapping(value = WS_USERDATA_WMS, method = RequestMethod.GET) public void getPointsMap( @RequestParam(value = "CQL_FILTER", required = false, defaultValue = "") String cql_filter, @RequestParam(value = "ENV", required = false, defaultValue = "") String env, @RequestParam(value = "BBOX", required = false, defaultValue = "") String bboxString, @RequestParam(value = "WIDTH", required = false, defaultValue = "") String widthString, @RequestParam(value = "HEIGHT", required = false, defaultValue = "") String heightString, HttpServletRequest request, HttpServletResponse response) { RecordsLookup.setUserDataDao(userDataDao); response.setHeader("Cache-Control", "max-age=86400"); //age == 1 day response.setContentType("image/png"); //only png images generated int width = 256, height = 256; try {//from w w w .ja v a 2 s. c o m width = Integer.parseInt(widthString); height = Integer.parseInt(heightString); } catch (Exception e) { logger.error("error parsing to int: " + widthString + " or " + heightString, e); } try { env = URLDecoder.decode(env, "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error("error decoding env from UTF-8: " + env, e); } int red = 0, green = 0, blue = 0, alpha = 0; String name = "circle"; int size = 4; boolean uncertainty = false; String highlight = null; String colourMode = null; for (String s : env.split(";")) { String[] pair = s.split(":"); if (pair[0].equals("color")) { while (pair[1].length() < 6) { pair[1] = "0" + pair[1]; } red = Integer.parseInt(pair[1].substring(0, 2), 16); green = Integer.parseInt(pair[1].substring(2, 4), 16); blue = Integer.parseInt(pair[1].substring(4), 16); } else if (pair[0].equals("name")) { name = pair[1]; } else if (pair[0].equals("size")) { size = Integer.parseInt(pair[1]); } else if (pair[0].equals("opacity")) { alpha = (int) (255 * Double.parseDouble(pair[1])); // } else if (pair[0].equals("uncertainty")) { // uncertainty = true; } else if (pair[0].equals("sel")) { try { highlight = URLDecoder.decode(s.substring(4), "UTF-8").replace("%3B", ";"); } catch (Exception e) { } } else if (pair[0].equals("colormode")) { colourMode = pair[1]; } } double[] bbox = new double[4]; int i; i = 0; for (String s : bboxString.split(",")) { try { bbox[i] = Double.parseDouble(s); i++; } catch (Exception e) { logger.error("error converting bounding box value to double: " + s, e); } } try { //adjust bbox extents with half pixel width/height double pixelWidth = (bbox[2] - bbox[0]) / width; double pixelHeight = (bbox[3] - bbox[1]) / height; bbox[0] += pixelWidth / 2; bbox[2] -= pixelWidth / 2; bbox[1] += pixelHeight / 2; bbox[3] -= pixelHeight / 2; //offset for points bounding box by size double xoffset = (bbox[2] - bbox[0]) / (double) width * (size + (highlight != null ? HIGHLIGHT_RADIUS * 2 + size * 0.2 : 0) + 5); double yoffset = (bbox[3] - bbox[1]) / (double) height * (size + (highlight != null ? HIGHLIGHT_RADIUS * 2 + size * 0.2 : 0) + 5); //check offset for points bb by maximum uncertainty (?? 30k ??) if (uncertainty) { double xuoffset = 30000; double yuoffset = 30000; if (xoffset < xuoffset) { xoffset = xuoffset; } if (yoffset < yuoffset) { yoffset = yuoffset; } } //adjust offset for pixel height/width xoffset += pixelWidth; yoffset += pixelHeight; double[][] bb = { { SpatialUtils.convertMetersToLng(bbox[0] - xoffset), SpatialUtils.convertMetersToLat(bbox[1] - yoffset) }, { SpatialUtils.convertMetersToLng(bbox[2] + xoffset), SpatialUtils.convertMetersToLat(bbox[3] + yoffset) } }; double[] pbbox = new double[4]; //pixel bounding box pbbox[0] = SpatialUtils.convertLngToPixel(SpatialUtils.convertMetersToLng(bbox[0])); pbbox[1] = SpatialUtils.convertLatToPixel(SpatialUtils.convertMetersToLat(bbox[1])); pbbox[2] = SpatialUtils.convertLngToPixel(SpatialUtils.convertMetersToLng(bbox[2])); pbbox[3] = SpatialUtils.convertLatToPixel(SpatialUtils.convertMetersToLat(bbox[3])); String lsid = null; int p1 = 0; int p2 = cql_filter.indexOf('&', p1 + 1); if (p2 < 0) { p2 = cql_filter.indexOf(';', p1 + 1); } if (p2 < 0) { p2 = cql_filter.length(); } if (p1 >= 0) { lsid = cql_filter.substring(0, p2); } double[] points = null; ArrayList<QueryField> listHighlight = null; QueryField colours = null; double[] pointsBB = null; Facet facet = null; String[] facetFields = null; if (highlight != null && !(colourMode != null && colourMode.equals("grid"))) { facet = Facet.parseFacet(highlight); facetFields = facet.getFields(); listHighlight = new ArrayList<QueryField>(); } int[] idx = null; if (lsid != null) { Object[] data = (Object[]) RecordsLookup.getData(lsid); points = (double[]) data[1]; pointsBB = (double[]) data[4]; idx = (int[]) data[5]; if (points == null || points.length == 0 || pointsBB[0] > bb[1][0] || pointsBB[2] < bb[0][0] || pointsBB[1] > bb[1][1] || pointsBB[3] < bb[0][1]) { setImageBlank(response); return; } ArrayList<QueryField> fields = (ArrayList<QueryField>) data[2]; for (int j = 0; j < fields.size(); j++) { if (facet != null) { for (int k = 0; k < facetFields.length; k++) { if (facetFields[k].equals(fields.get(j).getName())) { listHighlight.add(fields.get(j)); } } } if (colourMode != null) { if (fields.get(j).getName().equals(colourMode)) { synchronized (fields.get(j)) { //need to resize 'colours' facet to the correct length and store as new QueryField for (int k = 0; k < fields.size(); k++) { if (fields.get(k).getName().equals(colourMode + " resized")) { colours = fields.get(k); } } if (colours == null) { colours = fields.get(j); //does it need to be rebuilt to the correct length? int count = colours.getIntData() != null ? colours.getIntData().length : colours.getLongData() != null ? colours.getLongData().length : colours.getFloatData() != null ? colours.getFloatData().length : colours.getDoubleData() != null ? colours.getDoubleData().length : 0; if (count != points.length / 2) { QueryField qf = new QueryField(); qf.setDisplayName(colours.getDisplayName()); qf.setName(colours.getName() + " resized"); for (int k = 0; k < idx.length; k++) { qf.add(colours.getAsString(idx[k])); } qf.store(); fields.add(qf); colours = qf; } } } } } } } /* TODO: make this a copy instead of create */ BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) img.getGraphics(); g.setColor(new Color(0, 0, 0, 0)); g.fillRect(0, 0, width, height); g.setColor(new Color(red, green, blue, alpha)); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int x, y; int pointWidth = size * 2 + 1; double width_mult = (width / (pbbox[2] - pbbox[0])); double height_mult = (height / (pbbox[1] - pbbox[3])); if (colourMode != null && colourMode.equals("grid")) { int divs = 16; double grid_width_mult = (width / (pbbox[2] - pbbox[0])) / (256 / divs); double grid_height_mult = (height / (pbbox[1] - pbbox[3])) / (256 / divs); int[][] gridCounts = new int[divs][divs]; for (i = 0; i < points.length; i += 2) { x = (int) ((SpatialUtils.convertLngToPixel(points[i]) - pbbox[0]) * grid_width_mult); y = (int) ((SpatialUtils.convertLatToPixel(points[i + 1]) - pbbox[3]) * grid_height_mult); if (x >= 0 && x < divs && y >= 0 && y < divs) { gridCounts[x][y]++; } } int xstep = 256 / divs; int ystep = 256 / divs; for (x = 0; x < divs; x++) { for (y = 0; y < divs; y++) { int v = gridCounts[x][y]; if (v > 0) { if (v > 500) { v = 500; } int colour = Legend.getLinearColour(v, 0, 500, 0xFFFFFF00, 0xFFFF0000); g.setColor(new Color(colour)); g.fillRect(x * xstep, y * ystep, xstep, ystep); } } } } else { //circle type if (name.equals("circle")) { if (colours == null) { for (i = 0; i < points.length; i += 2) { if (points[i] >= bb[0][0] && points[i] <= bb[1][0] && points[i + 1] >= bb[0][1] && points[i + 1] <= bb[1][1]) { x = (int) ((SpatialUtils.convertLngToPixel(points[i]) - pbbox[0]) * width_mult); y = (int) ((SpatialUtils.convertLatToPixel(points[i + 1]) - pbbox[3]) * height_mult); g.fillOval(x - size, y - size, pointWidth, pointWidth); } } } else { int prevColour = -1; //!= colours[0] g.setColor(new Color(prevColour)); for (i = 0; i < points.length; i += 2) { if (points[i] >= bb[0][0] && points[i] <= bb[1][0] && points[i + 1] >= bb[0][1] && points[i + 1] <= bb[1][1]) { //colours is made the correct length, see above int thisColour = colours.getColour(i / 2); if (thisColour != prevColour) { g.setColor(new Color(thisColour)); prevColour = thisColour; } x = (int) ((SpatialUtils.convertLngToPixel(points[i]) - pbbox[0]) * width_mult); y = (int) ((SpatialUtils.convertLatToPixel(points[i + 1]) - pbbox[3]) * height_mult); g.fillOval(x - size, y - size, pointWidth, pointWidth); } } } } if (highlight != null && facet != null) { g.setStroke(new BasicStroke(2)); g.setColor(new Color(255, 0, 0, 255)); int sz = size + HIGHLIGHT_RADIUS; int w = sz * 2 + 1; for (i = 0; i < points.length; i += 2) { if (points[i] >= bb[0][0] && points[i] <= bb[1][0] && points[i + 1] >= bb[0][1] && points[i + 1] <= bb[1][1]) { if (facet.isValid(listHighlight, idx[i / 2])) { x = (int) ((SpatialUtils.convertLngToPixel(points[i]) - pbbox[0]) * width_mult); y = (int) ((SpatialUtils.convertLatToPixel(points[i + 1]) - pbbox[3]) * height_mult); g.drawOval(x - sz, y - sz, w, w); } } } } } g.dispose(); try { OutputStream os = response.getOutputStream(); ImageIO.write(img, "png", os); os.flush(); os.close(); } catch (IOException e) { logger.error("error in outputting wms/reflect image as png", e); } } catch (Exception e) { logger.error("error generating wms/reflect tile", e); } //logger.debug("[wms tile: " + (System.currentTimeMillis() - start) + "ms]"); }
From source file:de.tor.tribes.ui.views.DSWorkbenchAttackFrame.java
@Override public void actionPerformed(ActionEvent e) { AttackTableTab activeTab = getActiveTab(); int idx = jAttackTabPane.getSelectedIndex(); if (e.getActionCommand() != null && activeTab != null) { if (e.getActionCommand().equals("TimeChange")) { activeTab.fireChangeTimeEvent(); } else if (e.getActionCommand().equals("UnitChange")) { activeTab.fireChangeUnitEvent(); } else if (e.getActionCommand().equals("Recolor")) { activeTab.updateSortHighlighter(); } else if (e.getActionCommand().equals("ExportScript")) { activeTab.fireExportScriptEvent(); } else if (e.getActionCommand().equals("Copy")) { activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.COPY_TO_INTERNAL_CLIPBOARD); } else if (e.getActionCommand().equals("BBCopy")) { activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.CLIPBOARD_BB); } else if (e.getActionCommand().equals("Cut")) { activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.CUT_TO_INTERNAL_CLIPBOARD); jAttackTabPane.setSelectedIndex(idx); } else if (e.getActionCommand().equals("Paste")) { activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.FROM_INTERNAL_CLIPBOARD); jAttackTabPane.setSelectedIndex(idx); } else if (e.getActionCommand().equals("Delete")) { activeTab.deleteSelection(true); } else if (e.getActionCommand().equals("Find")) { BufferedImage back = ImageUtils.createCompatibleBufferedImage(3, 3, BufferedImage.TRANSLUCENT); Graphics g = back.getGraphics(); g.setColor(new Color(120, 120, 120, 120)); g.fillRect(0, 0, back.getWidth(), back.getHeight()); g.setColor(new Color(120, 120, 120)); g.drawLine(0, 0, 3, 3);//from w ww .j a v a2s . c om g.dispose(); TexturePaint paint = new TexturePaint(back, new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight())); jxSearchPane.setBackgroundPainter(new MattePainter(paint)); DefaultListModel model = new DefaultListModel(); for (int i = 0; i < activeTab.getAttackTable().getColumnCount(); i++) { TableColumnExt col = activeTab.getAttackTable().getColumnExt(i); if (col.isVisible()) { if (!col.getTitle().equals("Einheit") && !col.getTitle().equals("Typ") && !col.getTitle().equals("Sonstiges") && !col.getTitle().equals("Abschickzeit") && !col.getTitle().equals("Ankunftzeit") && !col.getTitle().equals("Verbleibend")) { model.addElement(col.getTitle()); } } } jXColumnList.setModel(model); jXColumnList.setSelectedIndex(0); jxSearchPane.setVisible(true); } } }
From source file:org.executequery.gui.browser.TableDataTab.java
private Object setTableResultsPanel(DatabaseObject databaseObject) { tableDataChanges.clear();//from w ww. ja va2s .co m primaryKeyColumns.clear(); foreignKeyColumns.clear(); this.databaseObject = databaseObject; try { initialiseModel(); tableModel.setCellsEditable(false); tableModel.removeTableModelListener(this); if (isDatabaseTable()) { DatabaseTable databaseTable = asDatabaseTable(); if (databaseTable.hasPrimaryKey()) { primaryKeyColumns = databaseTable.getPrimaryKeyColumnNames(); canEditTableLabel.setText("This table has a primary key(s) and data may be edited here"); } if (databaseTable.hasForeignKey()) { foreignKeyColumns = databaseTable.getForeignKeyColumnNames(); } if (primaryKeyColumns.isEmpty()) { canEditTableLabel.setText("This table has no primary keys defined and is not editable here"); } canEditTableNotePanel.setVisible(alwaysShowCanEditNotePanel); } if (!isDatabaseTable()) { canEditTableNotePanel.setVisible(false); } Log.debug("Retrieving data for table - " + databaseObject.getName()); ResultSet resultSet = databaseObject.getData(true); tableModel.createTable(resultSet); if (table == null) { createResultSetTable(); } tableModel.setNonEditableColumns(primaryKeyColumns); TableSorter sorter = new TableSorter(tableModel); table.setModel(sorter); sorter.setTableHeader(table.getTableHeader()); if (isDatabaseTable()) { SortableHeaderRenderer renderer = new SortableHeaderRenderer(sorter) { private ImageIcon primaryKeyIcon = GUIUtilities .loadIcon(BrowserConstants.PRIMARY_COLUMNS_IMAGE); private ImageIcon foreignKeyIcon = GUIUtilities .loadIcon(BrowserConstants.FOREIGN_COLUMNS_IMAGE); @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); Icon keyIcon = iconForValue(value); if (keyIcon != null) { Icon icon = renderer.getIcon(); if (icon != null) { BufferedImage image = new BufferedImage( icon.getIconWidth() + keyIcon.getIconWidth() + 2, Math.max(keyIcon.getIconHeight(), icon.getIconHeight()), BufferedImage.TYPE_INT_ARGB); Graphics graphics = image.getGraphics(); keyIcon.paintIcon(null, graphics, 0, 0); icon.paintIcon(null, graphics, keyIcon.getIconWidth() + 2, 5); setIcon(new ImageIcon(image)); } else { setIcon(keyIcon); } } return renderer; } private ImageIcon iconForValue(Object value) { if (value != null) { String name = value.toString(); if (primaryKeyColumns.contains(name)) { return primaryKeyIcon; } else if (foreignKeyColumns.contains(name)) { return foreignKeyIcon; } } return null; } }; sorter.setTableHeaderRenderer(renderer); } table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); scroller.getViewport().add(table); removeAll(); add(canEditTableNotePanel, canEditTableNoteConstraints); add(scroller, scrollerConstraints); if (displayRowCount && SystemProperties.getBooleanProperty("user", "browser.query.row.count")) { add(rowCountPanel, rowCountPanelConstraints); rowCountField.setText(String.valueOf(sorter.getRowCount())); } } catch (DataSourceException e) { if (!cancelled) { addErrorLabel(e); } else { addCancelledLabel(); } } finally { tableModel.addTableModelListener(this); } setTableProperties(); validate(); repaint(); return "done"; }
From source file:net.cit.tetrad.rrd.service.TetradRrdDbServiceImpl.java
public String totalMultiGraphPerRrd(GraphDefInfo graphDefInfo) { String fileName = null;//from w ww . ja v a2 s . c om RrdGraphDef rrdGraphDef = null; try { String imagePath = CommonUtils.getDefaultRrdImgPath(); fileName = graphDefInfo.getFileName() + ".png"; rrdGraphDef = tetradRrdGraphDef.createTotalMultiGraphPerRrd(graphDefInfo); rrdGraphDef.setFilename(imagePath + fileName); RrdGraph rrdGraph = new RrdGraph(rrdGraphDef); BufferedImage bim = new BufferedImage(graphDefInfo.getWidth(), graphDefInfo.getHeight(), BufferedImage.TYPE_INT_RGB); rrdGraph.render(bim.getGraphics()); } catch (Exception e) { logger.error(e, e); fileName = ""; } return fileName; }