Package net.codebuilders.desktop.imagetools

Source Code of net.codebuilders.desktop.imagetools.ImageToolsView

/*
* Copyright (C) 2009 Carl B. Marcum - CodeBuilders.net
* Phone (937) 242-6519 - <http://www.codebuilders.net>
*
* This file is part of "Image Tools by CodeBuilders.net"
* hereafter referered to as "Image Tools".
*
* Image Tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Image Tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Image Tools.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
* ImageToolsView.java
*/
package net.codebuilders.desktop.imagetools;

import java.awt.Dimension;
import java.awt.event.KeyListener;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;

/**
* The application's main frame.
*/
public class ImageToolsView extends FrameView implements KeyListener {

    public ImageToolsView(SingleFrameApplication app) {
        super(app);

        // mainFrame = ImageToolsApp.getApplication().getMainFrame();
        imageArea = new ImageArea();

        // Construct a save file chooser. Initialize the starting directory to
        // the current directory, do not allow the user to select the "all files"
        // filter, and restrict the files that can be selected to those ending
        // with .jpg or .jpeg extensions.

        imageChooser = new JFileChooser();
        imageChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
        imageChooser.setAcceptAllFileFilterUsed(false);
        imageChooser.setFileFilter(new ImageFileFilter());

        itModel = ImageToolsApp.getApplication().getItModel();

        initComponents();

        // setup button enabled status for startup
        this.setFileOpenEnabled(true);
        this.setFileSaveEnabled(false);
        this.setFileCloseEnabled(false);
        this.setCaptureEnabled(true);
        this.setCropEnabled(false);
        this.setDrawLineEnabled(false);
        this.setDrawRectangleEnabled(false);
        this.setDrawTextEnabled(false);
        // this.setColorRedEnabled(true); set with methods
        // this.setColorBlueEnabled(true); set with methods

        // undo and redo depends on their collection status


        // find a way to make this work
        // application saves last size a starts with it.
        // force a re-layout
        this.getRootPane().validate();
        // fix size
        this.getFrame().pack();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });

        // get the model from the app
        //itModel = ImageToolsApp.getApplication().getItModel();
        // get it in the method

        // listen for imageArea to update it's image then update the model
        imageArea.addPropertyChangeListener("image", new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
                // DEBUG
                System.out.println("ImageArea Event Caught...");

                // update the model
                // ImageToolsModel itModel = ImageToolsApp.getApplication().getItModel();
                itModel.setImage((BufferedImage) imageArea.getImage());

            }
        });

        // listen for ImageTools Model to update - test 2009-03-20
        itModel.pcs.addPropertyChangeListener("image", new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
                // DEBUG
                System.out.println("Model Event Caught...");

                // update the view


                setUndoEnabled(!itModel.undoQueue.isEmpty());
                setRedoEnabled(!itModel.redoQueue.isEmpty());

            }
        });

        errorIcon = resourceMap.getIcon("message.error.icon");
        infoIcon = resourceMap.getIcon("message.info.icon");
        warningIcon = resourceMap.getIcon("message.warning.icon");

    } // end constructor

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            // JFrame mainFrame = ImageToolsApp.getApplication().getMainFrame();
            aboutBox = new ImageToolsAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        ImageToolsApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        fileOpenItem = new javax.swing.JMenuItem();
        fileCloseItem = new javax.swing.JMenuItem();
        fileSaveItem = new javax.swing.JMenuItem();
        filePrintItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        editUndoItem = new javax.swing.JMenuItem();
        editRedoItem = new javax.swing.JMenuItem();
        imageMenu = new javax.swing.JMenu();
        imageCaptureItem = new javax.swing.JMenuItem();
        imageCropItem = new javax.swing.JMenuItem();
        drawMenu = new javax.swing.JMenu();
        drawLineItem = new javax.swing.JMenuItem();
        drawRectangleItem = new javax.swing.JMenuItem();
        drawTextItem = new javax.swing.JMenuItem();
        optionsMenu = new javax.swing.JMenu();
        colorRedItem = new javax.swing.JRadioButtonMenuItem();
        colorBlueItem = new javax.swing.JRadioButtonMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        fontSerifItem = new javax.swing.JRadioButtonMenuItem();
        fontSansSerifItem = new javax.swing.JRadioButtonMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        usingMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        toolBar = new javax.swing.JToolBar();
        openButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        closeButton = new javax.swing.JButton();
        printButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        undoButton = new javax.swing.JButton();
        redoButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        captureButton = new javax.swing.JButton();
        cropButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        lineButton = new javax.swing.JToggleButton();
        rectangleButton = new javax.swing.JToggleButton();
        textButton = new javax.swing.JToggleButton();
        drawButtonGroup = new javax.swing.ButtonGroup();
        colorButtonGroup = new javax.swing.ButtonGroup();
        fontButtonGroup = new javax.swing.ButtonGroup();

        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(425, 300));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(net.codebuilders.desktop.imagetools.ImageToolsApp.class).getContext().getResourceMap(ImageToolsView.class);
        jLabel1.setIcon(resourceMap.getIcon("splash.icon")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel1)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(net.codebuilders.desktop.imagetools.ImageToolsApp.class).getContext().getActionMap(ImageToolsView.class, this);
        fileOpenItem.setAction(actionMap.get("fileOpen")); // NOI18N
        fileOpenItem.setName("fileOpenItem"); // NOI18N
        fileMenu.add(fileOpenItem);

        fileCloseItem.setAction(actionMap.get("fileClose")); // NOI18N
        fileCloseItem.setText(resourceMap.getString("fileCloseItem.text")); // NOI18N
        fileCloseItem.setName("fileCloseItem"); // NOI18N
        fileMenu.add(fileCloseItem);

        fileSaveItem.setAction(actionMap.get("fileSave")); // NOI18N
        fileSaveItem.setText(resourceMap.getString("fileSaveItem.text")); // NOI18N
        fileSaveItem.setName("fileSaveItem"); // NOI18N
        fileMenu.add(fileSaveItem);

        filePrintItem.setAction(actionMap.get("filePrint")); // NOI18N
        filePrintItem.setText(resourceMap.getString("Print.text")); // NOI18N
        filePrintItem.setName("Print"); // NOI18N
        fileMenu.add(filePrintItem);

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setIcon(resourceMap.getIcon("exitMenuItem.icon")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setText(resourceMap.getString("editMenu.text")); // NOI18N
        editMenu.setName("editMenu"); // NOI18N

        editUndoItem.setAction(actionMap.get("undo")); // NOI18N
        editUndoItem.setText(resourceMap.getString("editUndoItem.text")); // NOI18N
        editUndoItem.setName("editUndoItem"); // NOI18N
        editMenu.add(editUndoItem);

        editRedoItem.setAction(actionMap.get("redo")); // NOI18N
        editRedoItem.setText(resourceMap.getString("editRedoItem.text")); // NOI18N
        editRedoItem.setName("editRedoItem"); // NOI18N
        editMenu.add(editRedoItem);

        menuBar.add(editMenu);

        imageMenu.setText(resourceMap.getString("imageMenu.text")); // NOI18N
        imageMenu.setName("imageMenu"); // NOI18N

        imageCaptureItem.setAction(actionMap.get("captureScreen")); // NOI18N
        imageCaptureItem.setName("imageCaptureItem"); // NOI18N
        imageMenu.add(imageCaptureItem);

        imageCropItem.setAction(actionMap.get("cropImage")); // NOI18N
        imageCropItem.setText(resourceMap.getString("imageCropItem.text")); // NOI18N
        imageCropItem.setName("imageCropItem"); // NOI18N
        imageMenu.add(imageCropItem);

        menuBar.add(imageMenu);

        drawMenu.setText(resourceMap.getString("drawMenu.text")); // NOI18N
        drawMenu.setName("drawMenu"); // NOI18N

        drawLineItem.setAction(actionMap.get("drawLine")); // NOI18N
        drawLineItem.setText(resourceMap.getString("drawLineItem.text")); // NOI18N
        drawLineItem.setName("drawLineItem"); // NOI18N
        drawMenu.add(drawLineItem);

        drawRectangleItem.setAction(actionMap.get("drawRectangle")); // NOI18N
        drawRectangleItem.setText(resourceMap.getString("drawRectangleItem.text")); // NOI18N
        drawRectangleItem.setName("drawRectangleItem"); // NOI18N
        drawMenu.add(drawRectangleItem);

        drawTextItem.setAction(actionMap.get("drawText")); // NOI18N
        drawTextItem.setText(resourceMap.getString("drawTextItem.text")); // NOI18N
        drawTextItem.setName("drawTextItem"); // NOI18N
        drawMenu.add(drawTextItem);

        menuBar.add(drawMenu);

        optionsMenu.setText(resourceMap.getString("optionsMenu.text")); // NOI18N
        optionsMenu.setName("optionsMenu"); // NOI18N

        colorRedItem.setAction(actionMap.get("setColorRed")); // NOI18N
        colorButtonGroup.add(colorRedItem);
        colorRedItem.setSelected(true);
        colorRedItem.setText(resourceMap.getString("colorRedItem.text")); // NOI18N
        colorRedItem.setName("colorRedItem"); // NOI18N
        optionsMenu.add(colorRedItem);

        colorBlueItem.setAction(actionMap.get("setColorBlue")); // NOI18N
        colorButtonGroup.add(colorBlueItem);
        colorBlueItem.setText(resourceMap.getString("colorBlueItem.text")); // NOI18N
        colorBlueItem.setName("colorBlueItem"); // NOI18N
        optionsMenu.add(colorBlueItem);

        jSeparator4.setName("jSeparator4"); // NOI18N
        optionsMenu.add(jSeparator4);

        fontSerifItem.setAction(actionMap.get("setFontSerif")); // NOI18N
        fontButtonGroup.add(fontSerifItem);
        fontSerifItem.setFont(resourceMap.getFont("fontSerifItem.font")); // NOI18N
        fontSerifItem.setText(resourceMap.getString("fontSerifItem.text")); // NOI18N
        fontSerifItem.setName("fontSerifItem"); // NOI18N
        optionsMenu.add(fontSerifItem);

        fontSansSerifItem.setAction(actionMap.get("setFontSansSerif")); // NOI18N
        fontButtonGroup.add(fontSansSerifItem);
        fontSansSerifItem.setFont(resourceMap.getFont("fontSansSerifItem.font")); // NOI18N
        fontSansSerifItem.setSelected(true);
        fontSansSerifItem.setText(resourceMap.getString("fontSansSerifItem.text")); // NOI18N
        fontSansSerifItem.setName("fontSansSerifItem"); // NOI18N
        optionsMenu.add(fontSansSerifItem);

        menuBar.add(optionsMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        usingMenuItem.setAction(actionMap.get("showUsingBox")); // NOI18N
        usingMenuItem.setText(resourceMap.getString("usingMenuItem.text")); // NOI18N
        usingMenuItem.setToolTipText(resourceMap.getString("usingMenuItem.toolTipText")); // NOI18N
        usingMenuItem.setName("usingMenuItem"); // NOI18N
        helpMenu.add(usingMenuItem);

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setText(resourceMap.getString("statusMessageLabel.text")); // NOI18N
        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 444, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 203, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        toolBar.setRollover(true);
        toolBar.setName("toolBar"); // NOI18N

        openButton.setAction(actionMap.get("fileOpen")); // NOI18N
        openButton.setText(resourceMap.getString("openButton.text")); // NOI18N
        openButton.setFocusable(false);
        openButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        openButton.setName("openButton"); // NOI18N
        openButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(openButton);

        saveButton.setAction(actionMap.get("fileSave")); // NOI18N
        saveButton.setText(resourceMap.getString("saveButton.text")); // NOI18N
        saveButton.setFocusable(false);
        saveButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        saveButton.setName("saveButton"); // NOI18N
        saveButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(saveButton);

        closeButton.setAction(actionMap.get("fileClose")); // NOI18N
        closeButton.setText(resourceMap.getString("closeButton.text")); // NOI18N
        closeButton.setFocusable(false);
        closeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        closeButton.setName("closeButton"); // NOI18N
        closeButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(closeButton);

        printButton.setAction(actionMap.get("filePrint")); // NOI18N
        printButton.setText(resourceMap.getString("printButton.text")); // NOI18N
        printButton.setFocusable(false);
        printButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        printButton.setName("printButton"); // NOI18N
        printButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(printButton);

        jSeparator1.setName("jSeparator1"); // NOI18N
        toolBar.add(jSeparator1);

        undoButton.setAction(actionMap.get("undo")); // NOI18N
        undoButton.setText(resourceMap.getString("undoButton.text")); // NOI18N
        undoButton.setFocusable(false);
        undoButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        undoButton.setName("undoButton"); // NOI18N
        undoButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(undoButton);

        redoButton.setAction(actionMap.get("redo")); // NOI18N
        redoButton.setText(resourceMap.getString("redoButton.text")); // NOI18N
        redoButton.setFocusable(false);
        redoButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        redoButton.setName("redoButton"); // NOI18N
        redoButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(redoButton);

        jSeparator3.setName("jSeparator3"); // NOI18N
        toolBar.add(jSeparator3);

        captureButton.setAction(actionMap.get("captureScreen")); // NOI18N
        captureButton.setText(resourceMap.getString("captureButton.text")); // NOI18N
        captureButton.setFocusable(false);
        captureButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        captureButton.setName("captureButton"); // NOI18N
        captureButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(captureButton);

        cropButton.setAction(actionMap.get("cropImage")); // NOI18N
        cropButton.setText(resourceMap.getString("cropButton.text")); // NOI18N
        cropButton.setFocusable(false);
        cropButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cropButton.setName("cropButton"); // NOI18N
        cropButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(cropButton);

        jSeparator2.setName("jSeparator2"); // NOI18N
        toolBar.add(jSeparator2);

        lineButton.setAction(actionMap.get("drawLine")); // NOI18N
        drawButtonGroup.add(lineButton);
        lineButton.setText(resourceMap.getString("lineButton.text")); // NOI18N
        lineButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        lineButton.setName("lineButton"); // NOI18N
        lineButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        lineButton.addKeyListener(this);
        toolBar.add(lineButton);

        rectangleButton.setAction(actionMap.get("drawRectangle")); // NOI18N
        drawButtonGroup.add(rectangleButton);
        rectangleButton.setText(resourceMap.getString("rectangleButton.text")); // NOI18N
        rectangleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        rectangleButton.setName("rectangleButton"); // NOI18N
        rectangleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        rectangleButton.addKeyListener(this);
        toolBar.add(rectangleButton);

        textButton.setAction(actionMap.get("drawText")); // NOI18N
        drawButtonGroup.add(textButton);
        textButton.setText(resourceMap.getString("textButton.text")); // NOI18N
        textButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        textButton.setName("textButton"); // NOI18N
        textButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        textButton.addKeyListener(this);
        toolBar.add(textButton);

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
        setToolBar(toolBar);
    }

    // Code for dispatching events from components to event handlers.

    public void keyPressed(java.awt.event.KeyEvent evt) {
        if (evt.getSource() == lineButton) {
            ImageToolsView.this.lineButtonKeyPressed(evt);
        }
        else if (evt.getSource() == rectangleButton) {
            ImageToolsView.this.rectangleButtonKeyPressed(evt);
        }
        else if (evt.getSource() == textButton) {
            ImageToolsView.this.textButtonKeyPressed(evt);
        }
    }

    public void keyReleased(java.awt.event.KeyEvent evt) {
    }

    public void keyTyped(java.awt.event.KeyEvent evt) {
    }// </editor-fold>//GEN-END:initComponents

    private void lineButtonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lineButtonKeyPressed
        // if ESC key, unselect button
        if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
            drawButtonGroup.clearSelection();
            imageArea.tearDownMouseListeners();
        }

    }//GEN-LAST:event_lineButtonKeyPressed

    private void rectangleButtonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_rectangleButtonKeyPressed
        // if ESC key, unselect button
        if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
            drawButtonGroup.clearSelection();
            imageArea.tearDownMouseListeners();
        }
    }//GEN-LAST:event_rectangleButtonKeyPressed

    private void textButtonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textButtonKeyPressed
        // if ESC key, unselect button
        if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
            drawButtonGroup.clearSelection();
            imageArea.tearDownMouseListeners();
        }
    }//GEN-LAST:event_textButtonKeyPressed

    @Action(enabledProperty = "captureEnabled", selectedProperty = "captureSelected")
    public void captureScreen() {

        // get the frame and hide it

        this.mainFrame = ImageToolsApp.getApplication().getMainFrame();
        this.mainFrame.setVisible(false);

        // capture
        // ImageToolsModel itModel = ImageToolsApp.getApplication().getItModel();
        itModel.capture();

        // ImageArea imageArea = new ImageArea();

        imageArea.setImage(itModel.getImage(), false);

        JScrollPane scrollPane = new JScrollPane(imageArea);

        // switch to new panel with image
        this.setComponent(scrollPane);

        statusMessageLabel.setText("Select area to crop.");

        // set mouse listener for crop rectangle
        imageArea.setMouseEvtType(ImageArea.DRAW_CROP_RECTANGLE);

        // setup button enabled status after a capture
        this.setFileOpenEnabled(false);
        this.setFileSaveEnabled(true);
        this.setFileCloseEnabled(true);
        this.setFilePrintEnabled(true);
        this.setCaptureEnabled(false);
        this.setCropEnabled(true);
        this.setDrawLineEnabled(true);
        this.setDrawRectangleEnabled(true);
        this.setDrawTextEnabled(true);
        this.setUndoEnabled(!itModel.undoQueue.isEmpty());
        this.setRedoEnabled(!itModel.redoQueue.isEmpty());
        // this.setUndoEnabled(true);
        // this.setRedoEnabled(true);

        // force a re-layout
        this.getRootPane().validate();

        // fix size - this causes the frame to be a large as display
        // this.getFrame().pack(); // leave same size for now

        // show frame
        mainFrame.setVisible(true);

    }

//    protected void addNewImage(BufferedImage bi) {
//
//        // ImageArea imageArea = new ImageArea();
//
//        imageArea.setImage(itModel.getImage());
//
//        JScrollPane scrollPane = new JScrollPane(imageArea);
//
//        // switch to new panel with image
//        this.setComponent(scrollPane);
//
//        // force a re-layout
//        this.getRootPane().validate();
//
//        // fix size
//        this.getFrame().pack();

    // show frame
    // this.mainFrame.setVisible(true);

    //   }
    @Action(enabledProperty = "cropEnabled", selectedProperty = "cropSelected")
    public void cropImage() {

        // in case we were drawing
        drawButtonGroup.clearSelection();

        // setup the mouse event for rectangle
        imageArea.setMouseEvtType(ImageArea.DRAW_CROP_RECTANGLE);

        if (imageArea.isReadyToCrop()) {
            boolean succeeded = false;


            succeeded = imageArea.crop();

            if (succeeded) {
                // added 2009-03-14 for undo/redo
                // ImageToolsModel itModel = ImageToolsApp.getApplication().getItModel();

                // listener handles it now
                // itModel.setImage((BufferedImage) imageArea.getImage());

                this.setUndoEnabled(!itModel.undoQueue.isEmpty());
                this.setRedoEnabled(!itModel.redoQueue.isEmpty());

                statusMessageLabel.setText("Save image.");

                // force a re-layout
                this.getRootPane().validate();
                // fix size
                this.getFrame().pack();

            } else {

                showError("Error during crop operation.");
                return;

            }



        } else {
            statusMessageLabel.setText("");
            showInfo("Please select rectangular area and Crop again.");
        }


    } // end cropImage

    @Action(enabledProperty = "fileSaveEnabled", selectedProperty = "fileSaveSelected")
    public void fileSave() {
        // Disallow image saving if there is no image to save.
        if (itModel.getImage() == null) {
            showError("No captured image.");
            return;
        }

        // Present the "save" file chooser without any file selected.
        // If the user cancels this file chooser, exit this method.

        imageChooser.setSelectedFile(null);
        if (imageChooser.showSaveDialog(mainFrame) !=
                JFileChooser.APPROVE_OPTION) {
            return;
        }

        // Obtain the selected file. Validate its extension, which
        // must be .jpg or .jpeg. If extension not present, append
        // .jpg extension.

        File file = imageChooser.getSelectedFile();

        String path = file.getAbsolutePath();
        // temp path changed to lowercase
        String tempPath = path.toLowerCase();
        if (!tempPath.endsWith(".jpg") && !tempPath.endsWith(".jpeg")) {
            file = new File(path += ".jpg");
        }

        // If the file exists, inform the user, who might not want
        // to accidentally overwrite an existing file. Exit method
        // if the user specifies that it is not okay to overwrite
        // the file.

        if (file.exists()) {
            int choice = JOptionPane.showConfirmDialog(null,
                    "Overwrite file?",
                    "Capture",
                    JOptionPane.YES_NO_OPTION);
            if (choice == JOptionPane.NO_OPTION) {
                return;
            }
        }

        // If the file does not exist or the user gives permission,
        // save image to file.

        ImageWriter writer = null;
        ImageOutputStream ios = null;

        try {
            // Obtain a writer based on the jpeg format.

            Iterator iter;
            iter = ImageIO.getImageWritersByFormatName("jpeg");

            // Validate existence of writer.

            if (!iter.hasNext()) {
                showError("Unable to save image to jpeg file type.");
                return;
            }

            // Extract writer.

            writer = (ImageWriter) iter.next();

            // Configure writer output destination.

            ios = ImageIO.createImageOutputStream(file);
            writer.setOutput(ios);

            // Set JPEG compression quality to 95%.

            ImageWriteParam iwp = writer.getDefaultWriteParam();
            iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            iwp.setCompressionQuality(0.95f);

            // Write the image.

            writer.write(null,
                    new IIOImage((BufferedImage) imageArea.getImage(), null, null),
                    iwp);
        } catch (IOException e2) {
            showError(e2.getMessage());
        } finally {
            try {
                // Cleanup.

                if (ios != null) {
                    ios.flush();
                    ios.close();
                }

                if (writer != null) {
                    writer.dispose();
                }
            } catch (IOException e2) {
            }
        }
    }

    /**
     *  Present an error message via a dialog box.
     *
     *  @param message the message to be presented
     */
    public static void showError(String message) {

        JOptionPane.showMessageDialog(null, message, "Image Tools",
                JOptionPane.ERROR_MESSAGE, errorIcon);
    }

    /**
     *  Present an information message via a dialog box.
     *
     *  @param message the message to be presented
     */
    public static void showInfo(String message) {
        JOptionPane.showMessageDialog(null, message, "Image Tools",
                JOptionPane.INFORMATION_MESSAGE, infoIcon);
    }

    /**
     *  Present an information message via a dialog box.
     *
     *  @param message the message to be presented
     */
    public static void showWarning(String message) {
        JOptionPane.showMessageDialog(null, message, "Image Tools",
                JOptionPane.WARNING_MESSAGE);
    }

    @Action
    public void showUsingBox() {
        if (usingBox == null) {
            // JFrame mainFrame = ImageToolsApp.getApplication().getMainFrame();
            usingBox = new ImageToolsUsingBox(mainFrame);
            usingBox.setLocationRelativeTo(mainFrame);
        }
        ImageToolsApp.getApplication().show(usingBox);
    }

    @Action(enabledProperty = "drawLineEnabled", selectedProperty = "drawLineSelected")
    public void drawLine() {

        imageArea.setMouseEvtType(ImageArea.DRAW_LINE);
        // imageArea.setupLineMouseListeners(); done in setMouseEvtType
        statusMessageLabel.setText("Draw Line - ESC to cancel.");
    }

    @Action(enabledProperty = "drawTextEnabled", selectedProperty = "drawTextSelected")
    public void drawText() {


        // ImageToolsModel itModel = ImageToolsApp.getApplication().getItModel();
        itModel.setText("text goes here");

        if (drawTextBox == null) {
            // JFrame mainFrame = ImageToolsApp.getApplication().getMainFrame();
            drawTextBox = new DrawTextBox(mainFrame);
            drawTextBox.setLocationRelativeTo(mainFrame);
        }
        ImageToolsApp.getApplication().show(drawTextBox);

        // override the size saved by application
        drawTextBox.setPreferredSize(new Dimension(320, 200));
        drawTextBox.pack();

        imageArea.setMouseEvtType(ImageArea.DRAW_TEXT);
        // imageArea.setupTextMouseListeners(); done in setMouseEvtType
        statusMessageLabel.setText("Hold LMB to drag, release to place.");

    }

    @Action(enabledProperty = "drawRectangleEnabled", selectedProperty = "drawRectangleSelected")
    public void drawRectangle() {
        imageArea.setMouseEvtType(ImageArea.DRAW_RECTANGLE);
        statusMessageLabel.setText("Draw Rectangle - ESC to cancel.");
    }

    @Action(enabledProperty = "undoEnabled", selectedProperty = "undoSelected")
    public void undo() {

        // in case we were drawing
        drawButtonGroup.clearSelection();
        imageArea.tearDownMouseListeners();

        // ImageToolsModel itModel = ImageToolsApp.getApplication().getItModel();
        // itModel.setImage((BufferedImage) imageArea.getImage());
        itModel.undo();

        this.imageArea.setImage(itModel.getImage(), false);

        this.setUndoEnabled(!itModel.undoQueue.isEmpty());
        this.setRedoEnabled(!itModel.redoQueue.isEmpty());



    }

    @Action(enabledProperty = "redoEnabled", selectedProperty = "redoSelected")
    public void redo() {

        // in case we were drawing
        drawButtonGroup.clearSelection();
        imageArea.tearDownMouseListeners();

        // ImageToolsModel itModel = ImageToolsApp.getApplication().getItModel();
        // itModel.setImage((BufferedImage) imageArea.getImage());
        itModel.redo();
        this.imageArea.setImage(itModel.getImage(), false);

        this.setUndoEnabled(!itModel.undoQueue.isEmpty());
        this.setRedoEnabled(!itModel.redoQueue.isEmpty());



    }

    @Action(enabledProperty = "fileOpenEnabled", selectedProperty = "fileOpenSelected")
    public void fileOpen() {

        File file = null;
        FileImageInputStream inputStream = null;
        BufferedImage bi = null;

        Logger logger = Logger.getLogger(ImageToolsView.class.getName());

        // Present the "open" file chooser without any file selected.
        // If the user cancels this file chooser, exit this method.

        imageChooser.setSelectedFile(null);
        if (imageChooser.showOpenDialog(mainFrame) !=
                JFileChooser.APPROVE_OPTION) {
            return;
        }

        // Obtain the selected file. Validate its extension, which
        // must be .jpg or .jpeg. If extension not present, append
        // .jpg extension.

        file = imageChooser.getSelectedFile();

        // check if file exists and make sure it's an image(or .jpg)
        // if not show an error box
        if (file.exists()) {
            // open it
            try {

                inputStream = new FileImageInputStream(file);
            } catch (FileNotFoundException ex) {
                logger.log(Level.SEVERE, null, ex);
                showError("File not found " + ex);
            } catch (IOException ex) {
                logger.log(Level.SEVERE, null, ex);
                showError("IOException " + ex);
            }
            try {
                bi = ImageIO.read(inputStream);
            } catch (IOException ex) {
                logger.log(Level.SEVERE, null, ex);
                showError("IOException " + ex);
            }

            itModel.setImage(bi);

            imageArea.setImage(itModel.getImage(), false);

            JScrollPane scrollPane = new JScrollPane(imageArea);

            // switch to new panel with image
            this.setComponent(scrollPane);

            statusMessageLabel.setText("Select area to crop.");

            // setup button enabled status after a capture
            this.setFileOpenEnabled(false);
            this.setFileSaveEnabled(true);
            this.setFileCloseEnabled(true);
            this.setFilePrintEnabled(true);
            this.setCaptureEnabled(false);
            this.setCropEnabled(true);
            this.setDrawLineEnabled(true);
            this.setDrawRectangleEnabled(true);
            this.setDrawTextEnabled(true);
            this.setUndoEnabled(!itModel.undoQueue.isEmpty());
            this.setRedoEnabled(!itModel.redoQueue.isEmpty());

            // force a re-layout
            this.getRootPane().validate();

        } else {
            showError("File to open is not a usable image");
        }

    }

    @Action(enabledProperty = "fileCloseEnabled", selectedProperty = "fileCloseSelected")
    public void fileClose() {

        // in case we were drawing
        drawButtonGroup.clearSelection();
        imageArea.tearDownMouseListeners();

        // put the label back in
        this.setComponent(jLabel1);
        // empty the queues
        itModel.undoQueue.clear();
        itModel.redoQueue.clear();

        statusMessageLabel.setText("Open file or capture image.");

        // setup button enabled status after a capture
        this.setFileOpenEnabled(true);
        this.setFileSaveEnabled(false);
        this.setFileCloseEnabled(false);
        this.setFilePrintEnabled(false);
        this.setCaptureEnabled(true);
        this.setCropEnabled(false);
        this.setDrawLineEnabled(false);
        this.setDrawRectangleEnabled(false);
        this.setDrawTextEnabled(false);
        this.setUndoEnabled(!itModel.undoQueue.isEmpty());
        this.setRedoEnabled(!itModel.redoQueue.isEmpty());

        // force a re-layout
        this.getRootPane().validate();
        // resize the frame
        this.getFrame().pack();

    }

        @Action(enabledProperty = "filePrintEnabled", selectedProperty = "filePrintSelected")
    public void filePrint() throws PrinterException {



        ComponentPrintable cp = new ComponentPrintable(imageArea);

        // Graphics g = this.imageArea.getGraphics();
        PageFormat pf = new PageFormat();

        HashPrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();

        PrinterJob job = PrinterJob.getPrinterJob();

        // pf = job.pageDialog(pf);

        boolean ok = job.printDialog(attributes);

        pf = job.getPageFormat(attributes);

        if (ok) {
            try {
                job.setPrintable(cp, pf);
                job.print(attributes);
            } catch (PrinterException ex) {
                /* The job did not successfully complete */
                Logger logger = Logger.getLogger(ImageToolsView.class.getName());
                logger.log(Level.SEVERE, null, ex);
                showError("The print job did not complete " + ex);
            }
        }
    }

    @Action(enabledProperty = "testActionEnabled", selectedProperty = "testActionSelected")
    public void testAction() {
    }
    private boolean fileSaveEnabled = false;

    public boolean isFileSaveEnabled() {
        return fileSaveEnabled;
    }

    public void setFileSaveEnabled(boolean b) {
        boolean old = isFileSaveEnabled();
        this.fileSaveEnabled = b;
        firePropertyChange("fileSaveEnabled", old, isFileSaveEnabled());
    }
    private boolean fileSaveSelected = false;

    public boolean isFileSaveSelected() {
        return fileSaveSelected;
    }

    public void setFileSaveSelected(boolean b) {
        boolean old = isFileSaveSelected();
        this.fileSaveSelected = b;
        firePropertyChange("fileSaveSelected", old, isFileSaveSelected());
    }
    private boolean testActionEnabled = false;

    public boolean isTestActionEnabled() {
        return testActionEnabled;
    }

    public void setTestActionEnabled(boolean b) {
        boolean old = isTestActionEnabled();
        this.testActionEnabled = b;
        firePropertyChange("testActionEnabled", old, isTestActionEnabled());
    }
    private boolean testActionSelected = false;

    public boolean isTestActionSelected() {
        return testActionSelected;
    }

    public void setTestActionSelected(boolean b) {
        boolean old = isTestActionSelected();
        this.testActionSelected = b;
        firePropertyChange("testActionSelected", old, isTestActionSelected());
    }
    private boolean drawLineEnabled = false;

    public boolean isDrawLineEnabled() {
        return drawLineEnabled;
    }

    public void setDrawLineEnabled(boolean b) {
        boolean old = isDrawLineEnabled();
        this.drawLineEnabled = b;
        firePropertyChange("drawLineEnabled", old, isDrawLineEnabled());
    }
    private boolean drawLineSelected = false;

    public boolean isDrawLineSelected() {
        return drawLineSelected;
    }

    public void setDrawLineSelected(boolean b) {
        boolean old = isDrawLineSelected();
        this.drawLineSelected = b;
        firePropertyChange("drawLineSelected", old, isDrawLineSelected());
    }
    private boolean drawRectangleEnabled = false;

    public boolean isDrawRectangleEnabled() {
        return drawRectangleEnabled;
    }

    public void setDrawRectangleEnabled(boolean b) {
        boolean old = isDrawRectangleEnabled();
        this.drawRectangleEnabled = b;
        firePropertyChange("drawRectangleEnabled", old, isDrawRectangleEnabled());
    }
    private boolean drawRectangleSelected = false;

    public boolean isDrawRectangleSelected() {
        return drawRectangleSelected;
    }

    public void setDrawRectangleSelected(boolean b) {
        boolean old = isDrawRectangleSelected();
        this.drawRectangleSelected = b;
        firePropertyChange("drawRectangleSelected", old, isDrawRectangleSelected());
    }
    private boolean drawTextEnabled = false;

    public boolean isDrawTextEnabled() {
        return drawTextEnabled;
    }

    public void setDrawTextEnabled(boolean b) {
        boolean old = isDrawTextEnabled();
        this.drawTextEnabled = b;
        firePropertyChange("drawTextEnabled", old, isDrawTextEnabled());
    }
    private boolean drawTextSelected = false;

    public boolean isDrawTextSelected() {
        return drawTextSelected;
    }

    public void setDrawTextSelected(boolean b) {
        boolean old = isDrawTextSelected();
        this.drawTextSelected = b;
        firePropertyChange("drawTextSelected", old, isDrawTextSelected());
    }
    private boolean fileCloseEnabled = false;

    public boolean isFileCloseEnabled() {
        return fileCloseEnabled;
    }

    public void setFileCloseEnabled(boolean b) {
        boolean old = isFileCloseEnabled();
        this.fileCloseEnabled = b;
        firePropertyChange("fileCloseEnabled", old, isFileCloseEnabled());
    }
    private boolean fileCloseSelected = false;

    public boolean isFileCloseSelected() {
        return fileCloseSelected;
    }

    public void setFileCloseSelected(boolean b) {
        boolean old = isFileCloseSelected();
        this.fileCloseSelected = b;
        firePropertyChange("fileCloseSelected", old, isFileCloseSelected());
    }
    private boolean undoEnabled = false;

    public boolean isUndoEnabled() {
        return undoEnabled;
    }

    public void setUndoEnabled(boolean b) {
        boolean old = isUndoEnabled();
        this.undoEnabled = b;
        firePropertyChange("undoEnabled", old, isUndoEnabled());
    }
    private boolean undoSelected = false;

    public boolean isUndoSelected() {
        return undoSelected;
    }

    public void setUndoSelected(boolean b) {
        boolean old = isUndoSelected();
        this.undoSelected = b;
        firePropertyChange("undoSelected", old, isUndoSelected());
    }
    private boolean redoEnabled = false;

    public boolean isRedoEnabled() {
        return redoEnabled;
    }

    public void setRedoEnabled(boolean b) {
        boolean old = isRedoEnabled();
        this.redoEnabled = b;
        firePropertyChange("redoEnabled", old, isRedoEnabled());
    }
    private boolean redoSelected = false;

    public boolean isRedoSelected() {
        return redoSelected;
    }

    public void setRedoSelected(boolean b) {
        boolean old = isRedoSelected();
        this.redoSelected = b;
        firePropertyChange("redoSelected", old, isRedoSelected());
    }
    private boolean fileOpenEnabled = false;

    public boolean isFileOpenEnabled() {
        return fileOpenEnabled;
    }

    public void setFileOpenEnabled(boolean b) {
        boolean old = isFileOpenEnabled();
        this.fileOpenEnabled = b;
        firePropertyChange("fileOpenEnabled", old, isFileOpenEnabled());
    }
    private boolean fileOpenSelected = false;

    public boolean isFileOpenSelected() {
        return fileOpenSelected;
    }

    public void setFileOpenSelected(boolean b) {
        boolean old = isFileOpenSelected();
        this.fileOpenSelected = b;
        firePropertyChange("fileOpenSelected", old, isFileOpenSelected());
    }
    private boolean captureEnabled = false;

    public boolean isCaptureEnabled() {
        return captureEnabled;
    }

    public void setCaptureEnabled(boolean b) {
        boolean old = isCaptureEnabled();
        this.captureEnabled = b;
        firePropertyChange("captureEnabled", old, isCaptureEnabled());
    }
    private boolean captureSelected = false;

    public boolean isCaptureSelected() {
        return captureSelected;
    }

    public void setCaptureSelected(boolean b) {
        boolean old = isCaptureSelected();
        this.captureSelected = b;
        firePropertyChange("captureSelected", old, isCaptureSelected());
    }
    private boolean cropEnabled = false;

    public boolean isCropEnabled() {
        return cropEnabled;
    }

    public void setCropEnabled(boolean b) {
        boolean old = isCropEnabled();
        this.cropEnabled = b;
        firePropertyChange("cropEnabled", old, isCropEnabled());
    }
    private boolean cropSelected = false;

    public boolean isCropSelected() {
        return cropSelected;
    }

    public void setCropSelected(boolean b) {
        boolean old = isCropSelected();
        this.cropSelected = b;
        firePropertyChange("cropSelected", old, isCropSelected());
    }

    @Action(enabledProperty = "colorRedEnabled", selectedProperty = "colorRedSelected")
    public void setColorRed() {
        itModel.setColor(java.awt.Color.RED);
    }

    @Action(enabledProperty = "colorBlueEnabled", selectedProperty = "colorBlueSelected")
    public void setColorBlue() {
        itModel.setColor(java.awt.Color.BLUE);
    }

    private boolean colorBlueEnabled = true;

    public boolean isColorBlueEnabled() {
        return colorBlueEnabled;
    }

    public void setColorBlueEnabled(boolean b) {
        boolean old = isColorBlueEnabled();
        this.colorBlueEnabled = b;
        firePropertyChange("colorBlueEnabled", old, isColorBlueEnabled());
    }

    private boolean colorBlueSelected = false;

    public boolean isColorBlueSelected() {
        return colorBlueSelected;
    }

    public void setColorBlueSelected(boolean b) {
        boolean old = isColorBlueSelected();
        this.colorBlueSelected = b;
        firePropertyChange("colorBlueSelected", old, isColorBlueSelected());
    }

    private boolean colorRedEnabled = true;

    public boolean isColorRedEnabled() {
        return colorRedEnabled;
    }

    public void setColorRedEnabled(boolean b) {
        boolean old = isColorRedEnabled();
        this.colorRedEnabled = b;
        firePropertyChange("colorRedEnabled", old, isColorRedEnabled());
    }

    private boolean colorRedSelected = false;

    public boolean isColorRedSelected() {
        return colorRedSelected;
    }

    public void setColorRedSelected(boolean b) {
        boolean old = isColorRedSelected();
        this.colorRedSelected = b;
        firePropertyChange("colorRedSelected", old, isColorRedSelected());
    }

    @Action(enabledProperty = "fontSerifEnabled", selectedProperty = "fontSerifSelected")
    public void setFontSerif() {
        itModel.setFontName(java.awt.Font.SERIF);
    }

    private boolean fontSerifEnabled = true;

    public boolean isFontSerifEnabled() {
        return fontSerifEnabled;
    }

    public void setFontSerifEnabled(boolean b) {
        boolean old = isFontSerifEnabled();
        this.fontSerifEnabled = b;
        firePropertyChange("fontSerifEnabled", old, isFontSerifEnabled());
    }

    private boolean fontSerifSelected = false;

    public boolean isFontSerifSelected() {
        return fontSerifSelected;
    }

    public void setFontSerifSelected(boolean b) {
        boolean old = isFontSerifSelected();
        this.fontSerifSelected = b;
        firePropertyChange("fontSerifSelected", old, isFontSerifSelected());
    }

    @Action(enabledProperty = "fontSansSerifEnabled", selectedProperty = "fontSansSerifSelected")
    public void setFontSansSerif() {
        itModel.setFontName(java.awt.Font.SANS_SERIF);
    }

    private boolean fontSansSerifEnabled = true;

    public boolean isFontSansSerifEnabled() {
        return fontSansSerifEnabled;
    }

    public void setFontSansSerifEnabled(boolean b) {
        boolean old = isFontSansSerifEnabled();
        this.fontSansSerifEnabled = b;
        firePropertyChange("fontSansSerifEnabled", old, isFontSansSerifEnabled());
    }

    private boolean fontSansSerifSelected = false;

    public boolean isFontSansSerifSelected() {
        return fontSansSerifSelected;
    }

    public void setFontSansSerifSelected(boolean b) {
        boolean old = isFontSansSerifSelected();
        this.fontSansSerifSelected = b;
        firePropertyChange("fontSansSerifSelected", old, isFontSansSerifSelected());
    }
   
    private boolean filePrintEnabled = false;
    public boolean isFilePrintEnabled() {
        return filePrintEnabled;
    }

    public void setFilePrintEnabled(boolean b) {
        boolean old = isFilePrintEnabled();
        this.filePrintEnabled = b;
        firePropertyChange("filePrintEnabled", old, isFilePrintEnabled());
    }

    private boolean filePrintSelected = false;
    public boolean isFilePrintSelected() {
        return filePrintSelected;
    }

    public void setFilePrintSelected(boolean b) {
        boolean old = isFilePrintSelected();
        this.filePrintSelected = b;
        firePropertyChange("filePrintSelected", old, isFilePrintSelected());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton captureButton;
    private javax.swing.JButton closeButton;
    private javax.swing.JRadioButtonMenuItem colorBlueItem;
    private javax.swing.ButtonGroup colorButtonGroup;
    private javax.swing.JRadioButtonMenuItem colorRedItem;
    private javax.swing.JButton cropButton;
    private javax.swing.ButtonGroup drawButtonGroup;
    private javax.swing.JMenuItem drawLineItem;
    private javax.swing.JMenu drawMenu;
    private javax.swing.JMenuItem drawRectangleItem;
    private javax.swing.JMenuItem drawTextItem;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenuItem editRedoItem;
    private javax.swing.JMenuItem editUndoItem;
    private javax.swing.JMenuItem fileCloseItem;
    private javax.swing.JMenuItem fileOpenItem;
    private javax.swing.JMenuItem filePrintItem;
    private javax.swing.JMenuItem fileSaveItem;
    private javax.swing.ButtonGroup fontButtonGroup;
    private javax.swing.JRadioButtonMenuItem fontSansSerifItem;
    private javax.swing.JRadioButtonMenuItem fontSerifItem;
    private javax.swing.JMenuItem imageCaptureItem;
    private javax.swing.JMenuItem imageCropItem;
    private javax.swing.JMenu imageMenu;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JToggleButton lineButton;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JButton openButton;
    private javax.swing.JMenu optionsMenu;
    private javax.swing.JButton printButton;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JToggleButton rectangleButton;
    private javax.swing.JButton redoButton;
    private javax.swing.JButton saveButton;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JToggleButton textButton;
    private javax.swing.JToolBar toolBar;
    private javax.swing.JButton undoButton;
    private javax.swing.JMenuItem usingMenuItem;
    // End of variables declaration//GEN-END:variables
    // more variables
    private static Icon errorIcon;
    private static Icon infoIcon;
    private static Icon warningIcon;
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
    private JDialog usingBox;
    private JDialog drawTextBox;
    // private ImageToolsModel itModel; ref from app
    private JFrame mainFrame;
    private ImageArea imageArea;
    private final JFileChooser imageChooser;
    // added to test new events 2009-03-20
    private ImageToolsModel itModel;
}
TOP

Related Classes of net.codebuilders.desktop.imagetools.ImageToolsView

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.