FileDocCategorySizeDatePackage
MainFrame.javaAPI DocAndroid 1.5 API5297Wed May 06 22:41:10 BST 2009com.android.draw9patch.ui

MainFrame

public class MainFrame extends JFrame

Fields Summary
private ActionMap
actionsMap
private JMenuItem
saveMenuItem
private ImageEditorPanel
imageEditor
Constructors Summary
public MainFrame(String path)

        super("Draw 9-patch");

        buildActions();
        buildMenuBar();
        buildContent();

        if (path == null) {
            showOpenFilePanel();
        } else {
            try {
                File file = new File(path);
                BufferedImage img = GraphicsUtilities.loadCompatibleImage(file.toURI().toURL());
                showImageEditor(img, file.getAbsolutePath());
            } catch (Exception ex) {
                showOpenFilePanel();
            }
        }

        // pack();
        setSize(1024, 600);
    
Methods Summary
private voidbuildActions()

        actionsMap = new ActionMap();
        actionsMap.put(OpenAction.ACTION_NAME, new OpenAction(this));
        actionsMap.put(SaveAction.ACTION_NAME, new SaveAction(this));
        actionsMap.put(ExitAction.ACTION_NAME, new ExitAction(this));
    
private voidbuildContent()

        setContentPane(new GradientPanel());
    
private voidbuildMenuBar()

        JMenu fileMenu = new JMenu("File");
        JMenuItem openMenuItem = new JMenuItem();
        saveMenuItem = new JMenuItem();
        JMenuItem exitMenuItem = new JMenuItem();

        openMenuItem.setAction(actionsMap.get(OpenAction.ACTION_NAME));
        fileMenu.add(openMenuItem);

        saveMenuItem.setAction(actionsMap.get(SaveAction.ACTION_NAME));
        saveMenuItem.setEnabled(false);
        fileMenu.add(saveMenuItem);

        exitMenuItem.setAction(actionsMap.get(ExitAction.ACTION_NAME));
        fileMenu.add(exitMenuItem);

        JMenuBar menuBar = new JMenuBar();
        menuBar.add(fileMenu);
        setJMenuBar(menuBar);
    
public org.jdesktop.swingworker.SwingWorkeropen(java.io.File file)

        if (file == null) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileFilter(new PngFileFilter());
            int choice = chooser.showOpenDialog(this);
            if (choice == JFileChooser.APPROVE_OPTION) {
                return new OpenTask(chooser.getSelectedFile());
            } else {
                return null;
            }
        } else {
            return new OpenTask(file);
        }
    
public org.jdesktop.swingworker.SwingWorkersave()

        if (imageEditor == null) {
            return null;
        }

        File file = imageEditor.chooseSaveFile();
        return file != null ? new SaveTask(file) : null;
    
voidshowImageEditor(java.awt.image.BufferedImage image, java.lang.String name)

        getContentPane().removeAll();
        imageEditor = new ImageEditorPanel(this, image, name);
        add(imageEditor);
        saveMenuItem.setEnabled(true);
        validate();
        repaint();
    
private voidshowOpenFilePanel()

        add(new OpenFilePanel(this));