Example usage for java.awt Graphics dispose

List of usage examples for java.awt Graphics dispose

Introduction

In this page you can find the example usage for java.awt Graphics dispose.

Prototype

public abstract void dispose();

Source Link

Document

Disposes of this graphics context and releases any system resources that it is using.

Usage

From source file:org.deegree.ogcwebservices.wms.dataaccess.ID2PInterpolation.java

public BufferedImage perform(GetLegendGraphic glg) {

    BufferedImage bi = new BufferedImage(150, colorMap.size() * 25, BufferedImage.TYPE_4BYTE_ABGR);
    Iterator<double[]> iterator = colorMap.keySet().iterator();
    List<double[]> list = new ArrayList<double[]>(colorMap.size());

    while (iterator.hasNext()) {
        double[] ds = iterator.next();
        list.add(ds);/*from  ww w  .j  ava2 s. c  om*/
    }

    for (int i = list.size() - 1; 0 <= i; i--) {
        for (int j = 0; j < i; j++) {
            if (list.get(j + 1)[0] < list.get(j)[0]) {
                double[] ds = list.get(j + 1);
                list.set(j + 1, list.get(j));
                list.set(j, ds);
            }
        }
    }

    int i = 0;
    Graphics g = bi.getGraphics();
    for (double[] ds : list) {
        Color color = colorMap.get(ds);
        g.setColor(color);
        g.fillRect(2, 2 + i * 25, 20, 20);
        g.setColor(Color.BLACK);
        g.drawRect(2, 2 + i * 25, 20, 20);
        g.drawString(Double.toString(ds[0]) + " - " + Double.toString(ds[1]), 25, 17 + i * 25);
        i++;
    }
    g.dispose();
    return bi;

}

From source file:com.opopov.cloud.image.service.ImageStitchingServiceImpl.java

private byte[] combineImagesIntoStitchedImage(@RequestBody ImageStitchingConfiguration config,
        IndexMap indexMap) throws IOException {
    int tileWidth = config.getSourceWidth();
    int tileHeight = config.getSourceHeight();

    //we are creating this big image in memory for the very short time frame, just when
    //all source data has been downloaded and decoded
    BufferedImage image = new BufferedImage(config.getRowCount() * tileWidth,
            config.getColumnCount() * tileHeight, BufferedImage.TYPE_4BYTE_ABGR);

    Graphics g = image.getGraphics();
    int indexOfTileInList = 0;
    for (int i = 0; i < config.getRowCount(); i++) {
        for (int j = 0; j < config.getColumnCount(); j++) {
            Optional<DecodedImage> decoded = indexMap.get(indexOfTileInList++);
            if (decoded != null) {
                if (decoded.isPresent()) {
                    g.drawImage(decoded.get().getImage(), i * config.getSourceWidth(),
                            j * config.getSourceHeight(), null);
                }/*  w w  w  . j av a  2 s .c o  m*/
            }
        }
    }

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    image.flush();
    ImageIO.write(image, config.getOutputFormat(), buffer);
    g.dispose();

    return buffer.toByteArray();
}

From source file:de.tor.tribes.ui.views.DSWorkbenchNotepad.java

@Override
public void actionPerformed(ActionEvent e) {

    NoteTableTab activeTab = getActiveTab();
    if (e.getActionCommand() != null && activeTab != null) {
        if (e.getActionCommand().equals("Copy")) {
            activeTab.transferSelection(NoteTableTab.TRANSFER_TYPE.COPY_TO_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("BBCopy")) {
            activeTab.transferSelection(NoteTableTab.TRANSFER_TYPE.CLIPBOARD_BB);
        } else if (e.getActionCommand().equals("BBCopy_Village")) {
            activeTab.copyVillagesAsBBCodes();
        } else if (e.getActionCommand().equals("Cut")) {
            activeTab.transferSelection(NoteTableTab.TRANSFER_TYPE.CUT_TO_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("Paste")) {
            activeTab.transferSelection(NoteTableTab.TRANSFER_TYPE.FROM_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("Delete")) {
            activeTab.deleteSelection(true);
        } else if (e.getActionCommand().equals("Delete_Village")) {
            activeTab.deleteVillagesFromNotes();
        } 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  w  w  . j  a  v a 2 s  .c  o m
            g.dispose();
            TexturePaint paint = new TexturePaint(back,
                    new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));
            jxSearchPane.setBackgroundPainter(new MattePainter(paint));
            jxSearchPane.setVisible(true);
        }
    }
}

From source file:ar.edu.uns.cs.vyglab.arq.rockar.gui.JFrameControlPanel.java

protected void exportOverview() {
    File currentDir = new File(System.getProperty("user.dir"));
    JFileChooser saveDialog = new JFileChooser(currentDir);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("PNG File", "png", "ong");
    saveDialog.setFileFilter(filter);// w w w.j  a  va 2 s.c  o  m
    int response = saveDialog.showSaveDialog(this);
    if (response == saveDialog.APPROVE_OPTION) {
        File outputfile = saveDialog.getSelectedFile();
        if (outputfile.getName().lastIndexOf(".") == -1) {
            outputfile = new File(outputfile.getName() + ".png");
        }
        try {
            //ImageIO.write(this.overview, "jpg", outputfile);
            BufferedImage bi = new BufferedImage(this.jLabelOverview.getIcon().getIconWidth(),
                    this.jLabelOverview.getIcon().getIconHeight(), BufferedImage.TYPE_INT_RGB);
            Graphics g = bi.createGraphics();
            // paint the Icon to the BufferedImage.
            this.jLabelOverview.getIcon().paintIcon(null, g, 0, 0);
            g.dispose();
            ImageIO.write(bi, "png", outputfile);

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:org.deegree.portal.standard.wms.control.DynLegendListener.java

/**
 * takes in a HashMap holding the properties of the legend and returns the size of the legend to be
 * /*from   w w w  .j a v a2s .  co m*/
 * @param map
 *            Hashmap holding the GetLegendGraphic properties
 * @return A rectangle holding the legend size
 */
private Rectangle calcLegendSize(HashMap<String, Object> map) {

    String[] layers = (String[]) map.get("NAMES");
    String[] titles = (String[]) map.get("TITLES");
    BufferedImage[] legs = (BufferedImage[]) map.get("IMAGES");

    int w = 0;
    int h = 0;
    for (int i = 0; i < layers.length; i++) {
        h += legs[i].getHeight() + 5;
        if (separator != null && i < layers.length - 1) {
            h += separator.getHeight() + 5;
        }
        Graphics g = legs[i].getGraphics();
        if (useLayerTitle && legs[i].getHeight() < maxNNLegendSize && !missing.contains(layers[i])) {
            Rectangle2D rect = g.getFontMetrics().getStringBounds(titles[i], g);
            g.dispose();
            if ((rect.getWidth() + legs[i].getWidth()) > w) {
                w = (int) rect.getWidth() + legs[i].getWidth();
            }
        } else {
            if (legs[i].getWidth() > w) {
                w = legs[i].getWidth();
            }
        }
    }
    w += 20;

    return new Rectangle(w, h);
}

From source file:de.tor.tribes.ui.views.DSWorkbenchConquersFrame.java

@Override
public void actionPerformed(ActionEvent e) {
    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  ww w .ja  v a2 s  . c o m*/
        g.dispose();
        TexturePaint paint = new TexturePaint(back,
                new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));
        jxFilterPane.setBackgroundPainter(new MattePainter(paint));
        DefaultListModel model = new DefaultListModel();

        for (int i = 0; i < jConquersTable.getColumnCount(); i++) {
            TableColumnExt col = jConquersTable.getColumnExt(i);
            if (col.isVisible() && !col.getTitle().equals("Entfernung")
                    && !col.getTitle().equals("Dorfpunkte")) {
                model.addElement(col.getTitle());
            }
        }
        jXColumnList.setModel(model);
        jXColumnList.setSelectedIndex(0);
        jxFilterPane.setVisible(true);
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchTroopsFrame.java

@Override
public void actionPerformed(ActionEvent e) {
    TroopTableTab activeTab = getActiveTab();
    if (e.getActionCommand().equals("Delete")) {
        if (activeTab != null) {
            activeTab.deleteSelection();
        }/*from   w  w  w.j ava2 s. c om*/
    } else if (e.getActionCommand().equals("BBCopy")) {
        if (activeTab != null) {
            activeTab.transferSelection(TroopTableTab.TRANSFER_TYPE.CLIPBOARD_BB);
        }
    } 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);
        g.dispose();
        TexturePaint paint = new TexturePaint(back,
                new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));
        jxSearchPane.setBackgroundPainter(new MattePainter(paint));
        updateTagList();
        jxSearchPane.setVisible(true);
    } else if (e.getActionCommand() != null && activeTab != null) {
        if (e.getActionCommand().equals("SelectionDone")) {
            activeTab.updateSelectionInfo();
        }
    }
}

From source file:org.deegree.services.wps.provider.jrxml.contentprovider.map.MapContentProvider.java

private Object prepareMap(List<OrderedDatasource<?>> datasources, String type, int originalWidth,
        int originalHeight, int width, int height, Envelope bbox, int resolution) throws ProcessletException {
    if ("net.sf.jasperreports.engine.JRRenderable".equals(type)) {
        return new MapRenderable(datasources, bbox, resolution);
    } else {//from   w  w  w .j a  va2s . c o m
        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics g = bi.getGraphics();
        for (OrderedDatasource<?> datasource : datasources) {
            BufferedImage image = datasource.getImage(width, height, bbox);
            if (image != null) {
                g.drawImage(image, 0, 0, null);
            }
        }
        g.dispose();
        return convertImageToReportFormat(type, bi);
    }
}

From source file:org.jtrfp.trcl.core.ResourceManager.java

/**
 * Returns RAW image as an R8-G8-B8 buffer with a side-width which is the square root of the total number of pixels
 * @param name/*from w w w. j a v a2s  . c  o m*/
 * @param palette
 * @param proc
 * @return
 * @throws IOException
 * @throws FileLoadException
 * @throws IllegalAccessException
 * @throws NotSquareException 
 * @since Oct 26, 2012
 */
public BufferedImage getRAWImage(String name, Color[] palette) throws IOException, FileLoadException,
        IllegalAccessException, NotSquareException, NonPowerOfTwoException {
    final RAWFile dat = getRAW(name);
    final byte[] raw = dat.getRawBytes();
    if (raw.length != dat.getSideLength() * dat.getSideLength())
        throw new NotSquareException(name);
    if ((dat.getSideLength() & (dat.getSideLength() - 1)) != 0)
        throw new NonPowerOfTwoException(name);
    final BufferedImage stamper = new BufferedImage(dat.getSideLength(), dat.getSideLength(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics stG = stamper.getGraphics();
    for (int i = 0; i < raw.length; i++) {
        Color c = palette[(int) raw[i] & 0xFF];
        stG.setColor(c);
        stG.fillRect(i % dat.getSideLength(), i / dat.getSideLength(), 1, 1);
    }
    stG.dispose();
    Graphics g = stamper.getGraphics();
    //The following code stamps the filename into the texture for debugging purposes
    if (tr.isStampingTextures()) {
        g.setFont(new Font(g.getFont().getName(), g.getFont().getStyle(), 9));
        g.drawString(name, 1, 16);
    }

    g.dispose();
    return stamper;
}

From source file:lucee.runtime.img.Image.java

public static BufferedImage toBufferedImage(java.awt.Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }/*  w  w  w  . ja v a2 s.c  om*/

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels; for this method's
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        // Determine the type of transparency of the new buffered image
        int transparency = Transparency.OPAQUE;
        if (hasAlpha) {
            transparency = Transparency.BITMASK;
        }

        // Create the buffered image
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
        // The system does not have a screen
    }

    if (bimage == null) {
        // Create a buffered image using the default color model
        int type = BufferedImage.TYPE_INT_RGB;
        if (hasAlpha) {
            type = BufferedImage.TYPE_INT_ARGB;
        }
        bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();

    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bimage;
}