Example usage for java.awt.image BufferedImage getGraphics

List of usage examples for java.awt.image BufferedImage getGraphics

Introduction

In this page you can find the example usage for java.awt.image BufferedImage getGraphics.

Prototype

public java.awt.Graphics getGraphics() 

Source Link

Document

This method returns a Graphics2D , but is here for backwards compatibility.

Usage

From source file:haven.GameUI.java

private void drawprog(GOut g, double prog) {
    int fr = Utils.clip((int) Math.floor(prog * progt.f.length), 0, progt.f.length - 2);
    int bf = Utils.clip((int) (((prog * progt.f.length) - fr) * 255), 0, 255);
    if ((curprog == null) || (curprogf != fr) || (curprogb != bf)) {
        if (curprog != null)
            curprog.dispose();/*  w  w  w .ja v  a  2 s  .c  o  m*/
        WritableRaster buf = PUtils.imgraster(progt.f[fr][0].sz);
        PUtils.blit(buf, progt.f[fr][0].img.getRaster(), Coord.z);
        PUtils.blendblit(buf, progt.f[fr + 1][0].img.getRaster(), Coord.z, bf);
        BufferedImage img = PUtils.rasterimg(buf);

        if (Config.showHourglassPercentage.get()) {
            BufferedImage txt = Text.renderstroked(String.format("%d%%", (int) (100 * prog)), Color.WHITE,
                    Color.BLACK).img;
            img.getGraphics().drawImage(txt, 24 - txt.getWidth() / 2, 9 - txt.getHeight() / 2, null);
        }

        curprog = new TexI(img);
        curprogf = fr;
        curprogb = bf;
    }
    g.aimage(curprog, new Coord(sz.x / 2, (sz.y * 4) / 10), 0.5, 0.5);
}

From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

/**
 *
 * @param xyz/*from   w w  w .  j a v a  2s. c om*/
 * @param sl
 * @param spm
 * @param xybr
 * @param activeGraphics
 * @param dataArea
 * @param info
 * @param crosshairState
 * @return
 */
public BufferedImage prepareData(final XYZDataset xyz, final int sl, final int spm, final XYBlockRenderer xybr,
        Graphics2D activeGraphics, Rectangle2D dataArea, PlotRenderingInfo info,
        CrosshairState crosshairState) {
    long start = System.currentTimeMillis();
    final PaintScale ps = xybr.getPaintScale();
    double minz = Double.POSITIVE_INFINITY, maxz = Double.NEGATIVE_INFINITY;

    for (int i = 0; i < xyz.getSeriesCount(); i++) {
        final int items = xyz.getItemCount(i);
        for (int j = 0; j < items; j++) {
            minz = Math.min(xyz.getZValue(i, j), minz);
            maxz = Math.max(xyz.getZValue(i, j), maxz);
        }
    }
    if (ps instanceof GradientPaintScale) {
        ((GradientPaintScale) ps).setUpperBound(maxz);
        ((GradientPaintScale) ps).setLowerBound(minz);
    }
    Logger.getLogger(getClass().getName()).log(Level.INFO, "Finding min and max data took{0}ms",
            (System.currentTimeMillis() - start));

    //        VolatileImage bi = null;
    //        if (bi == null) {
    //        if (this.getOrientation() == PlotOrientation.VERTICAL) {
    BufferedImage bi = createCompatibleImage(sl, spm, BufferedImage.TRANSLUCENT);
    //        } else {
    //            bi = createCompatibleImage(spm, sl);
    //        }
    //        }else{
    //            img.validate(g.getDeviceConfiguration())
    //        }

    Graphics2D g2 = (Graphics2D) bi.getGraphics();
    g2.setColor((Color) ps.getPaint(ps.getLowerBound()));
    g2.fillRect(0, 0, sl, spm);
    // System.out.println("Using Threshold: " + threshold);
    int height = bi.getHeight();
    //final WritableRaster wr = bi.getRaster();
    XYItemRendererState xyrs = xybr.initialise(g2, dataArea, this, xyz, info);
    for (int i = 0; i < xyz.getSeriesCount(); i++) {
        final int items = xyz.getItemCount(i);
        for (int j = 0; j < items; j++) {
            final double tmp = xyz.getZValue(i, j);
            if (tmp > this.threshholdCutOff) {
                //if(j%50==0)System.out.println("Value > threshold: "+tmp);
                final Paint p = ps.getPaint(tmp);
                //                    final Paint tp = ps.getPaint(this.threshholdCutOff);
                //                    if (!tp.equals(p)) {
                if (p instanceof Color) {
                    final Color c = (Color) p;
                    g2.setColor(c);
                    //                    xybr.drawItem(g2, xyrs, dataArea, info, this, domainAxis, rangeAxis, xyz, i, j, crosshairState, 0);
                    //                        if (this.getOrientation() == PlotOrientation.VERTICAL) {

                    g2.fillRect((int) xyz.getXValue(i, j), height - (int) xyz.getYValue(i, j), 1, 1);
                    //                            wr.setPixel(, , new int[]{c.getRed(),
                    //                                        c.getGreen(), c.getBlue(), c.getAlpha()});
                    //                        } else {
                    //                            wr.setPixel((int) xyz.getYValue(i, j), (int) xyz.getXValue(i, j), new int[]{c.getRed(),
                    //                                        c.getGreen(), c.getBlue(), c.getAlpha()});
                    //                        }
                    //                }
                    //                    }
                }
            }
        }
    }

    Logger.getLogger(getClass().getName()).log(Level.INFO, "Creating image and drawing items took {0}ms",
            (System.currentTimeMillis() - start));

    return bi;
}

From source file:net.geoprism.dashboard.DashboardMap.java

/**
 * Builds an image layer of all the layers in a SavedMap.
 * /*from w ww  .j a v  a 2s.  c om*/
 * @mapWidth
 * @mapHeight
 */
private BufferedImage getLegendExportCanvas(int mapWidth, int mapHeight) {
    int padding = 2;
    BufferedImage base = null;
    Graphics mapBaseGraphic = null;
    Color innerBackgroundColor = Color.darkGray;
    Color outerBorderColor = Color.black;
    int legendTopPlacement = 0;
    int legendLeftPlacement = 0;
    int widestLegend = 0;
    int legendXPosition = 0;
    int legendYPosition = 0;

    List<? extends DashboardLayer> layers = this.getAllHasLayer().getAll();

    try {
        base = new BufferedImage(mapWidth, mapHeight, BufferedImage.TYPE_INT_ARGB);
        mapBaseGraphic = base.getGraphics();
        mapBaseGraphic.drawImage(base, 0, 0, null);

        // Generates map overlays and combines them into a single map image
        for (DashboardLayer layer : layers) {
            if (layer.getDisplayInLegend()) {
                Graphics2D titleBaseGraphic = null;
                Graphics2D iconGraphic = null;

                String requestURL = getLegendURL(layer);

                try {
                    // handle color graphics and categories
                    BufferedImage titleBase = getLegendTitleImage(layer);
                    titleBaseGraphic = titleBase.createGraphics();
                    int paddedTitleWidth = titleBase.getWidth();
                    int paddedTitleHeight = titleBase.getHeight();

                    BufferedImage icon = getImageFromGeoserver(requestURL);
                    int iconHeight = icon.getHeight();
                    int iconWidth = icon.getWidth();
                    int paddedIconWidth = iconWidth + (padding * 2);
                    int paddedIconHeight = iconHeight + (padding * 2);

                    int fullWidth = paddedIconWidth + paddedTitleWidth;
                    int fullHeight;
                    if (paddedIconHeight >= paddedTitleHeight) {
                        fullHeight = paddedIconHeight;
                    } else {
                        fullHeight = paddedTitleHeight;
                    }

                    DashboardLegend legend = layer.getDashboardLegend();
                    if (legend.getGroupedInLegend()) {
                        if (legendTopPlacement + fullHeight >= mapHeight) {
                            legendLeftPlacement = widestLegend + legendLeftPlacement + padding;
                            legendTopPlacement = 0; // reset so 2nd column legends start at the top row
                        }
                        legendXPosition = legendLeftPlacement + padding;
                        legendYPosition = legendTopPlacement + padding;
                    } else {
                        legendXPosition = (int) Math.round((double) legend.getLegendXPosition());
                        legendYPosition = (int) Math.round((double) legend.getLegendYPosition());
                    }

                    BufferedImage legendBase = new BufferedImage(fullWidth + (padding * 2),
                            fullHeight + (padding * 2), BufferedImage.TYPE_INT_ARGB);
                    Graphics2D legendBaseGraphic = legendBase.createGraphics();
                    legendBaseGraphic.setColor(innerBackgroundColor);
                    legendBaseGraphic.fillRect(0, 0, fullWidth, fullHeight);
                    legendBaseGraphic.setColor(outerBorderColor);
                    legendBaseGraphic.setStroke(new BasicStroke(5));
                    legendBaseGraphic.drawRect(0, 0, fullWidth, fullHeight);

                    legendBaseGraphic.drawImage(icon, padding, padding, paddedIconWidth, paddedIconHeight,
                            null);
                    legendBaseGraphic.drawImage(titleBase, paddedIconWidth + (padding * 2),
                            (fullHeight / 2) - (paddedTitleHeight / 2), paddedTitleWidth, paddedTitleHeight,
                            null);
                    mapBaseGraphic.drawImage(legendBase, legendXPosition, legendYPosition, fullWidth,
                            fullHeight, null);

                    if (legend.getGroupedInLegend()) {
                        legendTopPlacement = legendTopPlacement + fullHeight + padding;
                    }

                    if (fullWidth > widestLegend) {
                        widestLegend = fullWidth;
                    }
                } finally {
                    if (titleBaseGraphic != null) {
                        titleBaseGraphic.dispose();
                    }

                    if (iconGraphic != null) {
                        iconGraphic.dispose();
                    }
                }
            }
        }
    } finally {
        mapBaseGraphic.dispose();
    }

    return base;
}

From source file:ru.spbspu.viewer.DataView.java

private void drawScaleFull() {
    int specHeigth = fullSpectrogram.getHeight() - cursor.getHeight() / 2;
    float limit = Integer.valueOf(spinnerLimitFreq.getValue().toString());
    int frameWidth = Integer.valueOf(spinnerFrameWidth.getValue().toString());
    BufferedImage scaleForFrame = new BufferedImage(SCALE_OF_SPECT, specHeigth, BufferedImage.TYPE_INT_RGB);
    Graphics g = scaleForFrame.getGraphics();
    g.drawLine(5, 0, 5, specHeigth);//  w w  w  . jav a 2 s .c  om
    Integer[] yAxis = new Integer[specHeigth / 8];
    for (int i = 0; i < yAxis.length; i++) {
        yAxis[i] = (int) (i * (limit / 1024) * 100);
    }
    int j = 0;
    for (int i = specHeigth; i > 0; i -= specHeigth / 10) {
        g.drawString(yAxis[j].toString(), 7, i - 2);
        g.drawLine(0, i, 40, i);
        j++;
    }
    labelForFullScale.setIcon(new ImageIcon(scaleForFrame));
}

From source file:ru.spbspu.viewer.DataView.java

private void drawScale() {
    int specHeigth = spectrogram.getHeight() - cursor.getHeight() / 2;
    float limit = Integer.valueOf(spinnerLimitFreq.getValue().toString());
    int frameWidth = Integer.valueOf(spinnerFrameWidth.getValue().toString());
    BufferedImage scaleForFrame = new BufferedImage(SCALE_OF_SPECT, specHeigth, BufferedImage.TYPE_INT_RGB);
    Graphics g = scaleForFrame.getGraphics();
    g.drawLine(5, 0, 5, specHeigth);//from  w w  w. jav  a2  s  .c o m
    Integer[] yAxis = new Integer[specHeigth / 8];
    try {
        for (int i = 0; i < yAxis.length; i++) {
            yAxis[i] = (int) (i * (limit / 1024) * 100);
        }
        int j = 0;
        for (int i = specHeigth; i > 0; i -= specHeigth / 10) {
            g.drawString(yAxis[j].toString(), 7, i - 2);
            g.drawLine(0, i, 40, i);
            j++;
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("To small window.");
    }
    labelForFrameScale.setIcon(new ImageIcon(scaleForFrame));
}

From source file:net.geoprism.dashboard.DashboardMap.java

/**
 * Generate an image replicating the users map in the browser.
 * //from w w w  . j  a va 2 s. c  om
 * @outFileFormat - Allowed types (png, gif, jpg, bmp)
 * @mapBounds - JSON constructed as {"bottom":"VALUE", "top":"VALUE", "left":"VALUE", "right":"VALUE"}
 * @mapSize - JSON constructed as {"width":"VALUE", "height":"VALUE"}
 * @activeBaseMap = JSON constructed as {"LAYER_SOURCE_TYPE":"VALUE"}
 */
@Override
public InputStream generateMapImageExport(String outFileFormat, String mapBounds, String mapSize,
        String activeBaseMap) {
    InputStream inStream = null;
    int width;
    int height;

    // Get dimensions of the map window (<div>)
    try {
        JSONObject mapSizeObj = new JSONObject(mapSize);
        width = mapSizeObj.getInt("width");
        height = mapSizeObj.getInt("height");
    } catch (JSONException e) {
        String error = "Could not parse map size.";
        throw new ProgrammingErrorException(error, e);
    }

    // Setup the base canvas to which we will add layers and map elements
    BufferedImage base = null;
    Graphics mapBaseGraphic = null;
    try {
        if (outFileFormat.toLowerCase().equals("png") || outFileFormat.toLowerCase().equals("gif")) {
            base = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        } else if (outFileFormat.equals("jpg") || outFileFormat.toLowerCase().equals("bmp")) {
            base = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        }

        // Create the base canvas that all other map elements will be draped on top of
        mapBaseGraphic = base.getGraphics();
        mapBaseGraphic.setColor(Color.white);
        mapBaseGraphic.fillRect(0, 0, width, height);
        mapBaseGraphic.drawImage(base, 0, 0, null);

        // Ordering the layers from the default map
        DashboardLayer[] orderedLayers = this.getOrderedLayers();

        // Add layers to the base canvas
        BufferedImage layerCanvas = getLayersExportCanvas(width, height, orderedLayers, mapBounds);

        // Get base map
        String baseType = null;
        try {
            JSONObject activeBaseObj = new JSONObject(activeBaseMap);
            baseType = activeBaseObj.getString("LAYER_SOURCE_TYPE");
        } catch (JSONException e) {
            String error = "Could not active base map JSON.";
            throw new ProgrammingErrorException(error, e);
        }

        // Get bounds of the map
        if (baseType.length() > 0) {
            String bottom;
            String top;
            String right;
            String left;
            try {
                JSONObject mapBoundsObj = new JSONObject(mapBounds);
                bottom = mapBoundsObj.getString("bottom");
                top = mapBoundsObj.getString("top");
                right = mapBoundsObj.getString("right");
                left = mapBoundsObj.getString("left");
            } catch (JSONException e) {
                String error = "Could not parse map bounds.";
                throw new ProgrammingErrorException(error, e);
            }

            BufferedImage baseMapImage = this.getBaseMapCanvas(width, height, left, bottom, right, top,
                    baseType);

            if (baseMapImage != null) {
                mapBaseGraphic.drawImage(baseMapImage, 0, 0, null);
            }
        }

        // Offset the layerCanvas so that it is center
        int widthOffset = (int) ((width - layerCanvas.getWidth()) / 2);
        int heightOffset = (int) ((height - layerCanvas.getHeight()) / 2);

        mapBaseGraphic.drawImage(layerCanvas, widthOffset, heightOffset, null);

        // Add legends to the base canvas
        BufferedImage legendCanvas = getLegendExportCanvas(width, height);
        mapBaseGraphic.drawImage(legendCanvas, 0, 0, null);
    } finally {
        ByteArrayOutputStream outStream = null;
        try {
            outStream = new ByteArrayOutputStream();
            ImageIO.write(base, outFileFormat, outStream);
            inStream = new ByteArrayInputStream(outStream.toByteArray());
        } catch (IOException e) {
            String error = "Could not write map image to the output stream.";
            throw new ProgrammingErrorException(error, e);
        } finally {
            if (outStream != null) {
                try {
                    outStream.close();
                } catch (IOException e) {
                    String error = "Could not close stream.";
                    throw new ProgrammingErrorException(error, e);
                }
            }
        }

        if (mapBaseGraphic != null) {
            mapBaseGraphic.dispose();
        }
    }

    return inStream;
}

From source file:com.openkm.module.direct.DirectWorkflowModule.java

@Override
public byte[] getProcessDefinitionImage(String token, long processDefinitionId, String node)
        throws RepositoryException, DatabaseException, WorkflowException {
    log.debug("getProcessDefinitionImage({}, {}, {})", new Object[] { token, processDefinitionId, node });
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    byte[] image = null;
    Session session = null;/*from  w  w w  . j  ava 2s .  c  o  m*/

    try {
        if (token == null) {
            session = JCRUtils.getSession();
        } else {
            session = JcrSessionManager.getInstance().get(token);
        }

        GraphSession graphSession = jbpmContext.getGraphSession();
        org.jbpm.graph.def.ProcessDefinition pd = graphSession.getProcessDefinition(processDefinitionId);
        FileDefinition fileDef = pd.getFileDefinition();

        WorkflowUtils.DiagramInfo dInfo = WorkflowUtils.getDiagramInfo(fileDef.getInputStream("gpd.xml"));
        WorkflowUtils.DiagramNodeInfo dNodeInfo = dInfo.getNodeMap().get(node);
        BufferedImage img = ImageIO.read(fileDef.getInputStream("processimage.jpg"));

        // Obtain all nodes Y
        List<Integer> ordenadas = new ArrayList<Integer>();

        for (WorkflowUtils.DiagramNodeInfo nodeInfo : dInfo.getNodeMap().values()) {
            ordenadas.add(nodeInfo.getY());
        }

        // Calculate minimal Y
        Collections.sort(ordenadas);
        int fix = ordenadas.get(0);

        if (dNodeInfo != null) {
            // Select node
            log.debug("DiagramNodeInfo: {}", dNodeInfo);
            Graphics g = img.getGraphics();
            Graphics2D g2d = (Graphics2D) g;
            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25F));
            g2d.setColor(Color.blue);
            g2d.fillRect(dNodeInfo.getX(), dNodeInfo.getY() - fix, dNodeInfo.getWidth(), dNodeInfo.getHeight());
            g.dispose();
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(img, "jpg", baos);
        image = baos.toByteArray();
        baos.flush();
        baos.close();

        // Activity log
        UserActivity.log(session.getUserID(), "GET_PROCESS_DEFINITION_IMAGE", "" + processDefinitionId, null);
    } catch (javax.jcr.RepositoryException e) {
        throw new RepositoryException(e.getMessage(), e);
    } catch (JbpmException e) {
        throw new WorkflowException(e.getMessage(), e);
    } catch (IOException e) {
        throw new WorkflowException(e.getMessage(), e);
    } finally {
        if (token == null)
            JCRUtils.logout(session);
        jbpmContext.close();
    }

    log.debug("getProcessDefinitionImage: {}", image);
    return image;
}

From source file:replicatorg.app.ui.panels.ControlPanel.java

public ControlPanel() {
    super(Base.getMainWindow(), Dialog.ModalityType.MODELESS);
    initComponents();//w  ww.  ja  va 2  s. c o  m
    Base.writeLog("Control panel opened...", this.getClass());
    setTextLanguage();
    super.centerOnScreen();
    super.enableDrag();
    evaluateInitialConditions();

    this.tempPanel.setLayout(new GridBagLayout());
    this.tempPanel.add(this.makeChart());

    //Sets legend colors
    BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();
    g.setColor(t0MeasuredColor);
    g.fillRect(0, 0, 10, 10);
    Icon icon1 = new ImageIcon(image);

    this.colorCurrentTemp.setIcon(icon1);
    this.colorCurrentTemp.setText("");

    BufferedImage image2 = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
    Graphics g2 = image2.getGraphics();
    g2.setColor(t0TargetColor);
    g2.fillRect(0, 0, 10, 10);
    Icon icon2 = new ImageIcon(image2);

    this.colorTargetTemp.setIcon(icon2);
    this.colorTargetTemp.setText("");

    if (connectedPrinter == PrinterInfo.BEETHEFIRST) {
        jSliderBlowerSpeed.setMaximum(1);
        jSliderBlowerSpeed.setMinorTickSpacing(0);
        jSliderBlowerSpeed.setMajorTickSpacing(1);

        jSliderExtruderSpeed.setEnabled(false);
    }

    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent e) {
            consoleInput.requestFocus();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            if (movButtonHoldDown != null && movButtonHoldDown.isRunning()) {
                movButtonHoldDown.stop();
            }
            driver.dispatchCommand("M1110 S0", COM.NO_RESPONSE);

            if (loggingTemperature == false) {
                disposeThread.cancel();
            }
            inputValidationThread.cancel();
            getInitialValuesThread.cancel();
        }
    });
}

From source file:edu.umn.cs.spatialHadoop.operations.GeometricPlot.java

/**
 * Combines images of different datasets into one image that is displayed
 * to users.// w  ww  .  java 2s . co  m
 * This method is called from the web interface to display one image for
 * multiple selected datasets.
 * @param fs The file system that contains the datasets and images
 * @param files Paths to directories which contains the datasets
 * @param includeBoundaries Also plot the indexing boundaries of datasets
 * @return An image that is the combination of all datasets images
 * @throws IOException
 */
public static BufferedImage combineImages(Configuration conf, Path[] files, boolean includeBoundaries,
        int width, int height) throws IOException {
    BufferedImage result = null;
    // Retrieve the MBRs of all datasets
    Rectangle allMbr = new Rectangle(Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE);
    for (Path file : files) {
        Rectangle mbr = FileMBR.fileMBR(file, new OperationsParams(conf));
        allMbr.expand(mbr);
    }

    // Adjust width and height to maintain aspect ratio
    if ((allMbr.x2 - allMbr.x1) / (allMbr.y2 - allMbr.y1) > (double) width / height) {
        // Fix width and change height
        height = (int) ((allMbr.y2 - allMbr.y1) * width / (allMbr.x2 - allMbr.x1));
    } else {
        width = (int) ((allMbr.x2 - allMbr.x1) * height / (allMbr.y2 - allMbr.y1));
    }
    result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    for (Path file : files) {
        FileSystem fs = file.getFileSystem(conf);
        if (fs.getFileStatus(file).isDir()) {
            // Retrieve the MBR of this dataset
            Rectangle mbr = FileMBR.fileMBR(file, new OperationsParams(conf));
            // Compute the coordinates of this image in the whole picture
            mbr.x1 = (mbr.x1 - allMbr.x1) * width / allMbr.getWidth();
            mbr.x2 = (mbr.x2 - allMbr.x1) * width / allMbr.getWidth();
            mbr.y1 = (mbr.y1 - allMbr.y1) * height / allMbr.getHeight();
            mbr.y2 = (mbr.y2 - allMbr.y1) * height / allMbr.getHeight();
            // Retrieve the image of this dataset
            Path imagePath = new Path(file, "_data.png");
            if (!fs.exists(imagePath))
                throw new RuntimeException("Image " + imagePath + " not ready");
            FSDataInputStream imageFile = fs.open(imagePath);
            BufferedImage image = ImageIO.read(imageFile);
            imageFile.close();
            // Draw the image
            Graphics graphics = result.getGraphics();
            graphics.drawImage(image, (int) mbr.x1, (int) mbr.y1, (int) mbr.getWidth(), (int) mbr.getHeight(),
                    null);
            graphics.dispose();

            if (includeBoundaries) {
                // Plot also the image of the boundaries
                // Retrieve the image of the dataset boundaries
                imagePath = new Path(file, "_partitions.png");
                if (fs.exists(imagePath)) {
                    imageFile = fs.open(imagePath);
                    image = ImageIO.read(imageFile);
                    imageFile.close();
                    // Draw the image
                    graphics = result.getGraphics();
                    graphics.drawImage(image, (int) mbr.x1, (int) mbr.y1, (int) mbr.getWidth(),
                            (int) mbr.getHeight(), null);
                    graphics.dispose();
                }
            }
        }
    }

    return result;
}

From source file:org.pmedv.blackboard.components.BoardEditor.java

public void updateStatusBar() {
    log.debug("editor update");
    StringBuffer text = new StringBuffer();
    if (snapToGrid)
        text.append(resources.getResourceByKey("mode.snap"));
    else/*  ww  w.  j a  va  2 s.  co  m*/
        text.append(resources.getResourceByKey("mode.nosnap"));
    text.append(" | ");
    if (editorMode.equals(EditorMode.SELECT))
        text.append(resources.getResourceByKey("mode.select"));
    else if (editorMode.equals(EditorMode.DRAW_LINE))
        text.append(resources.getResourceByKey("mode.line"));
    else if (editorMode.equals(EditorMode.DRAW_RECTANGLE))
        text.append(resources.getResourceByKey("mode.box"));
    else if (editorMode.equals(EditorMode.DRAW_ELLIPSE))
        text.append(resources.getResourceByKey("mode.ellipse"));
    else if (editorMode.equals(EditorMode.CHECK_CONNECTIONS))
        text.append(resources.getResourceByKey("mode.check"));
    else if (editorMode.equals(EditorMode.MOVE))
        text.append(resources.getResourceByKey("mode.move"));

    text.append(" | ");

    if (magnetic)
        text.append(resources.getResourceByKey("mode.magnetic"));

    BufferedImage image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.getGraphics();
    g.setColor(palette.getCurrentColor());
    g.fillRect(0, 0, 16, 16);
    win.getStatusLabel().setText(text.toString());
    win.getStatusLabel().setIcon(new ImageIcon(image));
    if (saveBoardCommand != null && fileState != null)
        saveBoardCommand.setEnabled(fileState.equals(FileState.DIRTY));
    refresh();
}