Esempio n. 1
0
 private void writeImage(File imageFile) throws IOException {
   BufferedImage resultImage = null;
   if (selectedGraph >= 0 && selectedGraph < graphImageFactories.length) {
     resultImage =
         graphImageFactories[selectedGraph].createGraphImage(
             Util.getTime(), sourceIdentifier, null, showMaxCheckBox.isSelected());
   }
   if (resultImage != null) {
     final String format = "png";
     BufferedOutputStream imageOutput = null;
     try {
       imageOutput = new BufferedOutputStream(new FileOutputStream(imageFile));
       boolean writerFound = ImageIO.write(resultImage, format, imageOutput);
       if (!writerFound) {
         String msg = "Couldn't write image! No writer found for format '" + format + "'!";
         if (logger.isErrorEnabled()) logger.error(msg);
         throw new IOException(msg);
       }
     } finally {
       // close output stream no matter what. shouldn't be necessary...
       IOUtilities.closeQuietly(imageOutput);
       resultImage.flush();
     }
   }
 }
Esempio n. 2
0
 private void updateGraph() {
   if (sourceIdentifier != null
       && selectedGraph >= 0
       && selectedGraph < graphImageFactories.length) {
     GraphImageProducer graphImageFactory = graphImageFactories[selectedGraph];
     imageToggle[imageIndex] =
         graphImageFactory.createGraphImage(
             Util.getTime(),
             sourceIdentifier,
             imageToggle[imageIndex],
             showMaxCheckBox.isSelected());
     if (imageToggle[imageIndex] != null) {
       ImageIcon graphImageIcon = new ImageIcon();
       graphImageIcon.setImage(imageToggle[imageIndex]);
       graphLabel.setIcon(graphImageIcon);
       graphLabel.setText("");
     } else {
       graphLabel.setIcon(null);
       graphLabel.setText("Couldn't create graph image!");
     }
     if (imageIndex == 0) {
       imageIndex = 1;
     } else {
       imageIndex = 0;
     }
     graphLabel.repaint();
   }
 }