Example usage for java.awt Image SCALE_SMOOTH

List of usage examples for java.awt Image SCALE_SMOOTH

Introduction

In this page you can find the example usage for java.awt Image SCALE_SMOOTH.

Prototype

int SCALE_SMOOTH

To view the source code for java.awt Image SCALE_SMOOTH.

Click Source Link

Document

Choose an image-scaling algorithm that gives higher priority to image smoothness than scaling speed.

Usage

From source file:com.digitalgeneralists.assurance.ui.components.ComparisonResultPanel.java

private void buildMergePanel(ComparisonResult result) {
    this.standardPanel.remove(this.mergePanel);

    GridBagConstraints mergePanelConstraints = new GridBagConstraints();
    mergePanelConstraints.anchor = GridBagConstraints.CENTER;
    mergePanelConstraints.fill = GridBagConstraints.BOTH;
    mergePanelConstraints.gridx = 1;/*from   w ww.j ava 2  s. c  o  m*/
    mergePanelConstraints.gridy = 0;
    mergePanelConstraints.weightx = 0.2;
    mergePanelConstraints.weighty = 1.0;
    mergePanelConstraints.gridheight = 1;
    mergePanelConstraints.gridwidth = 1;
    mergePanelConstraints.insets = new Insets(0, 0, 0, 0);

    this.mergePanel = new JPanel();
    this.mergePanel.setOpaque(false);
    GridBagLayout mergePanelGridbag = new GridBagLayout();
    this.mergePanel.setLayout(mergePanelGridbag);
    this.standardPanel.add(this.mergePanel, mergePanelConstraints);

    AssuranceResultResolution resolution = AssuranceResultResolution.UNRESOLVED;
    if (result != null) {
        resolution = result.getResolution();
    }

    if (resolution == AssuranceResultResolution.UNRESOLVED) {
        if (this.editable) {
            GridBagConstraints mergeTargetToSourceButtonConstraints = new GridBagConstraints();
            mergeTargetToSourceButtonConstraints.anchor = GridBagConstraints.CENTER;
            mergeTargetToSourceButtonConstraints.gridx = 0;
            mergeTargetToSourceButtonConstraints.gridy = 0;
            mergeTargetToSourceButtonConstraints.weightx = 1.0;
            mergeTargetToSourceButtonConstraints.weighty = 1.0;
            mergeTargetToSourceButtonConstraints.gridheight = 1;
            mergeTargetToSourceButtonConstraints.gridwidth = 1;
            mergeTargetToSourceButtonConstraints.insets = new Insets(5, 5, 5, 5);

            this.mergeTargetToSourceButton.addActionListener(this);
            Image icon;
            try {
                icon = ImageIO.read(Application.class.getClassLoader().getResource("replace-source.png"));
                icon = icon.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                this.mergeTargetToSourceButton.setIcon(new ImageIcon(icon));
                this.mergeTargetToSourceButton.setText("");
                this.mergeTargetToSourceButton.setToolTipText("Replace source with target.");
            } catch (IOException e) {
                logger.warn("Unable to load icon resources.", e);
            }
            this.mergeTargetToSourceButton.setActionCommand(AssuranceActions.replaceSourceAction);
            this.mergePanel.add(this.mergeTargetToSourceButton, mergeTargetToSourceButtonConstraints);

            GridBagConstraints mergeSourceToTargetButtonConstraints = new GridBagConstraints();
            mergeSourceToTargetButtonConstraints.anchor = GridBagConstraints.CENTER;
            mergeSourceToTargetButtonConstraints.gridx = 0;
            mergeSourceToTargetButtonConstraints.gridy = 1;
            mergeSourceToTargetButtonConstraints.weightx = 1.0;
            mergeSourceToTargetButtonConstraints.weighty = 1.0;
            mergeSourceToTargetButtonConstraints.gridheight = 1;
            mergeSourceToTargetButtonConstraints.gridwidth = 1;
            mergeSourceToTargetButtonConstraints.insets = new Insets(5, 5, 5, 5);

            this.mergeSourceToTargetButton.addActionListener(this);
            try {
                icon = ImageIO.read(Application.class.getClassLoader().getResource("replace-target.png"));
                icon = icon.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                this.mergeSourceToTargetButton.setIcon(new ImageIcon(icon));
                this.mergeSourceToTargetButton.setText("");
                this.mergeSourceToTargetButton.setToolTipText("Replace target with source.");
            } catch (IOException e) {
                logger.warn("Unable to load icon resources.", e);
            }
            this.mergeSourceToTargetButton.setActionCommand(AssuranceActions.replaceTargetAction);
            this.mergePanel.add(this.mergeSourceToTargetButton, mergeSourceToTargetButtonConstraints);
        }
    } else {
        Image resolutionLabelValue = null;
        try {
            switch (result.getResolution()) {
            case REPLACE_SOURCE:
            case DELETE_SOURCE:
                resolutionLabelValue = ImageIO
                        .read(Application.class.getClassLoader().getResource("replace-source.png"));
                resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                break;
            case REPLACE_TARGET:
            case DELETE_TARGET:
                resolutionLabelValue = ImageIO
                        .read(Application.class.getClassLoader().getResource("replace-target.png"));
                resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                break;
            case PROCESSING_ERROR_ENCOUNTERED:
                resolutionLabelValue = ImageIO
                        .read(Application.class.getClassLoader().getResource("resolution-error.png"));
                resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                break;
            default:
                resolutionLabelValue = ImageIO
                        .read(Application.class.getClassLoader().getResource("undetermined.png"));
                resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                break;
            }
        } catch (IOException e) {
            logger.warn("Unable to load icon resources.", e);
        }

        GridBagConstraints mergeResolutionLabelConstraints = new GridBagConstraints();
        mergeResolutionLabelConstraints.anchor = GridBagConstraints.CENTER;
        mergeResolutionLabelConstraints.gridx = 0;
        mergeResolutionLabelConstraints.gridy = 0;
        mergeResolutionLabelConstraints.weightx = 1.0;
        mergeResolutionLabelConstraints.weighty = 1.0;
        mergeResolutionLabelConstraints.gridheight = 1;
        mergeResolutionLabelConstraints.gridwidth = 1;
        mergeResolutionLabelConstraints.insets = new Insets(5, 5, 5, 5);

        JLabel mergeResolutionLabel = new JLabel(new ImageIcon(resolutionLabelValue));
        this.mergePanel.add(mergeResolutionLabel, mergeResolutionLabelConstraints);

        if ((result.getResolution() == AssuranceResultResolution.DELETE_SOURCE)
                || (result.getResolution() == AssuranceResultResolution.DELETE_TARGET)) {
            File deletedFile = null;
            if (result.getResolution() == AssuranceResultResolution.DELETE_SOURCE) {
                deletedFile = result
                        .getSourceDeletedItemLocation(MergeEngine.getApplicationDeletedItemsLocation());
            }
            if (result.getResolution() == AssuranceResultResolution.DELETE_TARGET) {
                deletedFile = result
                        .getTargetDeletedItemLocation(MergeEngine.getApplicationDeletedItemsLocation());
            }

            if (deletedFile.exists()) {
                GridBagConstraints mergeRestoreButtonConstraints = new GridBagConstraints();
                mergeRestoreButtonConstraints.anchor = GridBagConstraints.CENTER;
                mergeRestoreButtonConstraints.gridx = 0;
                mergeRestoreButtonConstraints.gridy = 1;
                mergeRestoreButtonConstraints.weightx = 1.0;
                mergeRestoreButtonConstraints.weighty = 1.0;
                mergeRestoreButtonConstraints.gridheight = 1;
                mergeRestoreButtonConstraints.gridwidth = 1;
                mergeRestoreButtonConstraints.insets = new Insets(5, 5, 5, 5);

                Image icon = null;
                try {
                    icon = ImageIO.read(Application.class.getClassLoader().getResource("restore.png"));
                    icon = icon.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                } catch (IOException e) {
                    logger.warn("Unable to load icon resources.", e);
                }
                this.mergeRestoreButton.setIcon(new ImageIcon(icon));
                this.mergeRestoreButton.setText("");
                this.mergeRestoreButton.setToolTipText("Restore");
                this.mergeRestoreButton.addActionListener(this);
                this.mergeRestoreButton.setActionCommand(AssuranceActions.restoreDeletedItemAction);
                this.mergePanel.add(this.mergeRestoreButton, mergeRestoreButtonConstraints);
            }
            deletedFile = null;
        } else if (result.getResolution() == AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED) {
            mergeResolutionLabel.setToolTipText(result.getResolutionError());
        }
    }
}

From source file:baocaoxla.compare.java

private void jMenuOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuOpenActionPerformed
    JFileChooser fc = new JFileChooser();
    int f = fc.showOpenDialog(this);
    if (f == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        try {/*from www.ja va  2  s  .co m*/
            img = ImageIO.read(new File(file.getPath()));
            ImageIcon icon = new ImageIcon(
                    img.getScaledInstance(lbimage.getWidth(), lbimage.getHeight(), Image.SCALE_SMOOTH));
            lbimage.setIcon(icon);
            pnimagehistogram.removeAll();
            pnimagehistogram.add(xuly.displayhistogram(img));
            pnimagehistogram.validate();
        } catch (IOException ex) {
            Logger.getLogger(compare.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (jcbtwo.isSelected()) {
            fc.showOpenDialog(this);
            file = fc.getSelectedFile();
            try {
                imgcompare = ImageIO.read(new File(file.getPath()));
                ImageIcon icon1 = new ImageIcon(imgcompare.getScaledInstance(lbimagecompare.getWidth(),
                        lbimagecompare.getHeight(), Image.SCALE_SMOOTH));
                lbimagecompare.setIcon(icon1);
                pnimagehistogram1.removeAll();
                pnimagehistogram1.add(xuly.displayhistogram(imgcompare));
                pnimagehistogram1.validate();
            } catch (IOException ex) {
                Logger.getLogger(compare.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

}

From source file:util.ui.UiUtilities.java

/**
 * Scales an image to a specific size and returns an BufferedImage
 *
 * @param img//from www.jav a 2 s . c  om
 *          Scale this image
 * @param width
 *          new width
 * @param height
 *          new height
 * @param type The type of the image.
 * @return Scaled BufferedImage
 *
 * @since 3.0
 */
public static BufferedImage scaleIconToBufferedImage(BufferedImage img, int width, int height, int type,
        Color backgroundColor) {
    // Scale Image
    Image image = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);

    BufferedImage im = new BufferedImage(width, height, type);

    Graphics2D g2 = im.createGraphics();
    if (backgroundColor != null) {
        g2.setColor(backgroundColor);
        g2.fillRect(0, 0, width, height);
    }

    g2.drawImage(image, null, null);
    g2.dispose();

    im.flush();
    return im;

}

From source file:net.cbtltd.server.UploadFileService.java

private static boolean getImage(String fn, BufferedImage image, Map<String, byte[]> images) {
    int fullsizepixels = Text.FULLSIZE_PIXELS_VALUE;
    int thumbnailpixels = Text.THUMBNAIL_PIXELS_VALUE;
    //      ByteBuffer byteArray = new ByteBuffer();
    ByteArrayOutputStream bOutputReg = new ByteArrayOutputStream();
    ByteArrayOutputStream bOutputThumb = new ByteArrayOutputStream();
    ImageIcon imageIcon = new ImageIcon(image);
    //      if(image.getIconHeight() > 0 && image.getIconWidth() > 0) {
    if (imageIcon.getImageLoadStatus() == MediaTracker.COMPLETE) {
        ImageIcon fullsizeImage = new ImageIcon(
                imageIcon.getImage().getScaledInstance(-1, fullsizepixels, Image.SCALE_SMOOTH));
        LOG.debug("\n UploadFileService setImage image= " + imageIcon + " width=" + fullsizeImage.getIconWidth()
                + "  height=" + fullsizeImage.getIconHeight());
        BufferedImage fullsizeBufferedImage = new BufferedImage(fullsizeImage.getIconWidth(),
                fullsizeImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics fullsizeGraphics = fullsizeBufferedImage.getGraphics();
        fullsizeGraphics.drawImage(fullsizeImage.getImage(), 0, 0, null);
        String fullsizeFile = fn.substring(0, fn.lastIndexOf('.')) + ".jpg";

        try {//from   w  ww .j  av  a 2s  . com
            ImageIO.write(fullsizeBufferedImage, FULLSIZE_JPEG, bOutputReg);
            bOutputReg.flush();
            images.put(fullsizeFile, bOutputReg.toByteArray());
            bOutputReg.close();
        } catch (IOException x) {
            throw new RuntimeException("Error saving full sized image " + x.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage() + " Error saving full sized image: " + fullsizeFile);
        }

        ImageIcon thumbnailImage = new ImageIcon(
                imageIcon.getImage().getScaledInstance(-1, thumbnailpixels, Image.SCALE_SMOOTH));
        String thumbnailFile = fn.substring(0, fn.lastIndexOf('.')) + "Thumb.jpg";

        BufferedImage thumbnailBufferedImage = new BufferedImage(thumbnailImage.getIconWidth(),
                thumbnailImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics thumbnailGraphics = thumbnailBufferedImage.getGraphics();
        thumbnailGraphics.drawImage(thumbnailImage.getImage(), 0, 0, null);
        try {
            ImageIO.write(thumbnailBufferedImage, FULLSIZE_JPEG, bOutputThumb);
            bOutputThumb.flush();
            images.put(thumbnailFile, bOutputThumb.toByteArray());
            bOutputThumb.close();
        } catch (IOException x) {
            throw new RuntimeException("Error saving thumbnail image " + x.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage() + " Error saving thumbnail image: " + thumbnailFile);
        }

        return true;
    } else {
        LOG.error("\n UploadFileService setImage image= " + imageIcon + " width=" + imageIcon.getIconWidth()
                + "  height=" + imageIcon.getIconHeight());
        return false;
    }
}

From source file:com.floreantpos.ui.model.PizzaItemForm.java

private void doSelectImageFile() {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    int option = fileChooser.showOpenDialog(POSUtil.getBackOfficeWindow());

    if (option == JFileChooser.APPROVE_OPTION) {
        File imageFile = fileChooser.getSelectedFile();
        try {//from   w ww  .j  av a2s  . co m
            byte[] itemImage = FileUtils.readFileToByteArray(imageFile);
            int imageSize = itemImage.length / 1024;

            if (imageSize > 20) {
                POSMessageDialog.showMessage(Messages.getString("MenuItemForm.0")); //$NON-NLS-1$
                itemImage = null;
                return;
            }

            ImageIcon imageIcon = new ImageIcon(
                    new ImageIcon(itemImage).getImage().getScaledInstance(80, 80, Image.SCALE_SMOOTH));
            lblImagePreview.setIcon(imageIcon);

            MenuItem menuItem = (MenuItem) getBean();
            menuItem.setImageData(itemImage);

        } catch (IOException e) {
            PosLog.error(getClass(), e);
        }
    }
}

From source file:fr.msch.wissl.server.Library.java

public static String resizeArtwork(String artPath) throws IOException {
    BufferedImage orig = ImageIO.read(new File(artPath));

    if (orig == null) {
        throw new IOException("Failed to open image");
    }//  w  w w  .  ja  v a  2  s  .co  m
    Image sc = orig.getScaledInstance(70, 70, Image.SCALE_SMOOTH);

    BufferedImage scaled = new BufferedImage(70, 70, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = scaled.createGraphics();
    g.drawImage(sc, 0, 0, 70, 70, null);
    g.dispose();

    File ret = new File(artPath + "_SCALED.jpg");
    ImageIO.write(scaled, "JPG", ret);

    return ret.getAbsolutePath();
}

From source file:org.yccheok.jstock.gui.Utils.java

public static java.awt.Image getScaledImage(Image image, int maxWidth, int maxHeight) {
    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    final int imgWidth = image.getWidth(null);
    final int imgHeight = image.getHeight(null);

    final int preferredWidth = Math.min(imgWidth, maxWidth);
    final int preferredHeight = Math.min(imgHeight, maxHeight);

    final double scaleX = (double) preferredWidth / (double) imgWidth;
    final double scaleY = (double) preferredHeight / (double) imgHeight;

    final double bestScale = Math.min(scaleX, scaleY);

    return image.getScaledInstance((int) ((double) imgWidth * bestScale),
            (int) ((double) imgHeight * bestScale), Image.SCALE_SMOOTH);
}

From source file:nl.phanos.liteliveresultsclient.gui.ResultsWindows.java

private void showPhoto() {
    int pheight = jScrollPane1.getPreferredSize().height;
    if (jCheckBoxMenuItem2.getState() == true && this.resultFile != null && this.resultFile.Photo != null) {
        ImageIcon myPicture = new ImageIcon(this.resultFile.Photo);
        Dimension dim = getScaledDimension(myPicture.getIconWidth(), myPicture.getIconHeight(),
                LayerdPane.getWidth() / 2, pheight);
        Image image = myPicture.getImage(); // transform it 
        Image newimg = image.getScaledInstance(dim.width, dim.height, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way  
        myPicture = new ImageIcon(newimg); // transform it back
        photolabel.setIcon(myPicture);//from  w  w  w.j  a v  a  2s.  com
        photopanel.setPreferredSize(new Dimension(LayerdPane.getWidth() / 2, pheight));
        System.out.println(myPicture.getIconWidth());
    } else {
        photopanel.setPreferredSize(new Dimension(0, pheight));
    }
    repaint();
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private Container initContainer() {
    JPanel containerPanel = new JPanel(new CardLayout());
    JLabel loadingModelLabel = new JLabel("Loading model...");
    loadingModelLabel.setHorizontalAlignment(SwingConstants.CENTER);
    containerPanel.add(loadingModelLabel, LOADING_MODEL_ID);
    tabbedPane = new JTabbedPane();
    containerPanel.add(tabbedPane, PARAMETERS_PANEL_ID);

    // create two number of turns field
    numberOfTurnsField = new JFormattedTextField();
    numberOfTurnsField.setFocusLostBehavior(JFormattedTextField.COMMIT);
    numberOfTurnsField.setInputVerifier(new InputVerifier() {

        @Override/*from  w  ww.  jav a2 s.c  om*/
        public boolean verify(final JComponent input) {
            if (!checkNumberOfTurnsField(true)) {
                final PopupFactory popupFactory = PopupFactory.getSharedInstance();
                final Point locationOnScreen = numberOfTurnsField.getLocationOnScreen();
                final JLabel message = new JLabel("Please specify a (possibly floating point) number!");
                message.setBorder(new LineBorder(Color.RED, 2, true));
                if (errorPopup != null)
                    errorPopup.hide();
                errorPopup = popupFactory.getPopup(numberOfTurnsField, message, locationOnScreen.x - 10,
                        locationOnScreen.y - 30);

                errorPopup.show();

                return false;
            } else {
                if (errorPopup != null) {
                    errorPopup.hide();
                    errorPopup = null;
                }
                return true;
            }
        }
    });
    numberOfTurnsField.setText(String.valueOf(Dashboard.NUMBER_OF_TURNS));
    numberOfTurnsField
            .setToolTipText("The turn when the simulation should stop specified as an integer value.");
    numberOfTurnsField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            wizard.clickDefaultButton();
        }
    });

    numberOfTurnsFieldPSW = new JFormattedTextField();
    numberOfTurnsFieldPSW.setFocusLostBehavior(JFormattedTextField.COMMIT);
    numberOfTurnsFieldPSW.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(final JComponent input) {
            if (!checkNumberOfTurnsField(false)) {
                final PopupFactory popupFactory = PopupFactory.getSharedInstance();
                final Point locationOnScreen = numberOfTurnsFieldPSW.getLocationOnScreen();
                final JLabel message = new JLabel("Please specify a (possibly floating point) number!");
                message.setBorder(new LineBorder(Color.RED, 2, true));
                if (errorPopup != null)
                    errorPopup.hide();
                errorPopup = popupFactory.getPopup(numberOfTurnsFieldPSW, message, locationOnScreen.x - 10,
                        locationOnScreen.y - 30);

                errorPopup.show();

                return false;
            } else {
                if (errorPopup != null) {
                    errorPopup.hide();
                    errorPopup = null;
                }
                return true;
            }
        }
    });
    numberOfTurnsFieldPSW.setText(String.valueOf(Dashboard.NUMBER_OF_TURNS));
    numberOfTurnsFieldPSW
            .setToolTipText("The turn when the simulation should stop specified as an integer value.");
    numberOfTurnsFieldPSW.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            wizard.clickDefaultButton();
        }
    });

    // create two number of time-steps to ignore field
    numberTimestepsIgnored = new JFormattedTextField();
    numberTimestepsIgnored.setFocusLostBehavior(JFormattedTextField.COMMIT);
    numberTimestepsIgnored.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(final JComponent input) {
            if (!checkNumberTimestepsIgnored(true)) {
                final PopupFactory popupFactory = PopupFactory.getSharedInstance();
                final Point locationOnScreen = numberTimestepsIgnored.getLocationOnScreen();
                final JLabel message = new JLabel("Please specify an integer number!");
                message.setBorder(new LineBorder(Color.RED, 2, true));
                if (errorPopup != null)
                    errorPopup.hide();
                errorPopup = popupFactory.getPopup(numberTimestepsIgnored, message, locationOnScreen.x - 10,
                        locationOnScreen.y - 30);

                errorPopup.show();

                return false;
            } else {
                if (errorPopup != null) {
                    errorPopup.hide();
                    errorPopup = null;
                }
                return true;
            }
        }
    });
    numberTimestepsIgnored.setText(String.valueOf(Dashboard.NUMBER_OF_TIMESTEPS_TO_IGNORE));
    numberTimestepsIgnored.setToolTipText(
            "The turn when the simulation should start charting specified as an integer value.");
    numberTimestepsIgnored.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            wizard.clickDefaultButton();
        }
    });

    numberTimestepsIgnoredPSW = new JFormattedTextField();
    numberTimestepsIgnoredPSW.setFocusLostBehavior(JFormattedTextField.COMMIT);
    numberTimestepsIgnoredPSW.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(final JComponent input) {
            if (!checkNumberTimestepsIgnored(false)) {
                final PopupFactory popupFactory = PopupFactory.getSharedInstance();
                final Point locationOnScreen = numberTimestepsIgnoredPSW.getLocationOnScreen();
                final JLabel message = new JLabel("Please specify an integer number!");
                message.setBorder(new LineBorder(Color.RED, 2, true));
                if (errorPopup != null)
                    errorPopup.hide();
                errorPopup = popupFactory.getPopup(numberTimestepsIgnoredPSW, message, locationOnScreen.x - 10,
                        locationOnScreen.y - 30);

                errorPopup.show();

                return false;
            } else {
                if (errorPopup != null) {
                    errorPopup.hide();
                    errorPopup = null;
                }
                return true;
            }
        }
    });
    numberTimestepsIgnoredPSW.setText(String.valueOf(Dashboard.NUMBER_OF_TIMESTEPS_TO_IGNORE));
    numberTimestepsIgnoredPSW.setToolTipText(
            "The turn when the simulation should start charting specified as an integer value.");
    numberTimestepsIgnoredPSW.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            wizard.clickDefaultButton();
        }
    });

    onLineChartsCheckBox = new JCheckBox();
    //      onLineChartsCheckBoxPSW = new JCheckBox();
    advancedChartsCheckBox = new JCheckBox();
    advancedChartsCheckBox.setSelected(true);

    // create the scroll pane for the simple parameter setting page
    JLabel label = null;
    label = new JLabel(new ImageIcon(new ImageIcon(getClass().getResource(DECORATION_IMAGE)).getImage()
            .getScaledInstance(DECORATION_IMAGE_WIDTH, -1, Image.SCALE_SMOOTH)));
    Style.registerCssClasses(label, Dashboard.CSS_CLASS_COMMON_PANEL);
    parametersScrollPane = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    parametersScrollPane.setBorder(null);
    parametersScrollPane.setViewportBorder(null);

    breadcrumb = new Breadcrumb();
    Style.registerCssClasses(breadcrumb, CSS_ID_BREADCRUMB);

    singleRunParametersPanel = new ScrollableJPanel(new SizeProvider() {

        @Override
        public int getHeight() {
            Component component = tabbedPane.getSelectedComponent();
            if (component == null) {
                return 0;
            }
            JScrollBar scrollBar = parametersScrollPane.getHorizontalScrollBar();
            return component.getSize().height - breadcrumb.getHeight()
                    - (scrollBar.isVisible() ? scrollBar.getPreferredSize().height : 0);
        }

        @Override
        public int getWidth() {
            final int hScrollBarWidth = parametersScrollPane.getHorizontalScrollBar().getPreferredSize().width;
            final int width = dashboard.getSize().width - Page_Parameters.DECORATION_IMAGE_WIDTH
                    - hScrollBarWidth;
            return width;
        }
    });
    BoxLayout boxLayout = new BoxLayout(singleRunParametersPanel, BoxLayout.X_AXIS);
    singleRunParametersPanel.setLayout(boxLayout);
    parametersScrollPane.setViewportView(singleRunParametersPanel);

    JPanel breadcrumbPanel = new JPanel(new BorderLayout());
    breadcrumbPanel.add(breadcrumb, BorderLayout.NORTH);
    breadcrumbPanel.add(parametersScrollPane, BorderLayout.CENTER);

    final JPanel simpleForm = FormsUtils.build("p ~ p:g", "01 t:p", label, breadcrumbPanel).getPanel();
    Style.registerCssClasses(simpleForm, Dashboard.CSS_CLASS_COMMON_PANEL);

    tabbedPane.add("Single run", simpleForm);

    // create the form for the parameter sweep setting page
    tabbedPane.add("Parameter sweep", createParamsweepGUI());

    gaSearchHandler = new GASearchHandler(currentModelHandler);
    gaSearchPanel = new GASearchPanel(gaSearchHandler, this);
    tabbedPane.add("Genetic Algorithm Search", gaSearchPanel);

    return containerPanel;
}

From source file:net.cbtltd.server.UploadFileService.java

private static boolean getCompressedImage(String fn, BufferedImage image, Map<String, byte[]> images) {
    int fullsizepixels = Text.FULLSIZE_PIXELS_VALUE;
    int thumbnailpixels = Text.THUMBNAIL_PIXELS_VALUE;
    //      ByteBuffer byteArray = new ByteBuffer();
    ByteArrayOutputStream bOutputReg = new ByteArrayOutputStream();
    ByteArrayOutputStream bOutputThumb = new ByteArrayOutputStream();
    ImageIcon imageIcon = new ImageIcon(image);
    try {//from w ww.j  a va  2 s.  c o  m
        GZIPOutputStream zipStreamReg = new GZIPOutputStream(bOutputReg);
        GZIPOutputStream zipStreamThumb = new GZIPOutputStream(bOutputThumb);

        if (imageIcon.getImageLoadStatus() == MediaTracker.COMPLETE) {
            ImageIcon fullsizeImage = new ImageIcon(
                    imageIcon.getImage().getScaledInstance(-1, fullsizepixels, Image.SCALE_SMOOTH));
            LOG.debug("\n UploadFileService setImage image= " + imageIcon + " width="
                    + fullsizeImage.getIconWidth() + "  height=" + fullsizeImage.getIconHeight());
            BufferedImage fullsizeBufferedImage = new BufferedImage(fullsizeImage.getIconWidth(),
                    fullsizeImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
            Graphics fullsizeGraphics = fullsizeBufferedImage.getGraphics();
            fullsizeGraphics.drawImage(fullsizeImage.getImage(), 0, 0, null);
            String fullsizeFile = fn.substring(0, fn.lastIndexOf('.')) + ".jpg";

            try {
                ImageIO.write(fullsizeBufferedImage, FULLSIZE_JPEG, zipStreamReg);
                zipStreamReg.close();
                bOutputReg.close();
                images.put(fullsizeFile, bOutputReg.toByteArray());
            } catch (IOException x) {
                throw new RuntimeException("Error saving full sized image " + x.getMessage());
            }

            ImageIcon thumbnailImage = new ImageIcon(
                    imageIcon.getImage().getScaledInstance(-1, thumbnailpixels, Image.SCALE_SMOOTH));
            String thumbnailFile = fn.substring(0, fn.lastIndexOf('.')) + "Thumb.jpg";

            BufferedImage thumbnailBufferedImage = new BufferedImage(thumbnailImage.getIconWidth(),
                    thumbnailImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
            Graphics thumbnailGraphics = thumbnailBufferedImage.getGraphics();
            thumbnailGraphics.drawImage(thumbnailImage.getImage(), 0, 0, null);
            try {
                ImageIO.write(thumbnailBufferedImage, FULLSIZE_JPEG, zipStreamThumb);
                zipStreamThumb.close();
                bOutputThumb.close();
                images.put(thumbnailFile, bOutputThumb.toByteArray());
            } catch (IOException x) {
                throw new RuntimeException("Error saving thumbnail image " + x.getMessage());
            }

            return true;
        } else {
            LOG.error("\n UploadFileService setImage image= " + imageIcon + " width=" + imageIcon.getIconWidth()
                    + "  height=" + imageIcon.getIconHeight());
            return false;
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return true;
}