controller.setSaved(true);
    private void buildGUI()    {        setTitle("Edit Image Annotation");        Container container = getContentPane();        container.setLayout(new BorderLayout());                JPanel targetPanel = new JPanel();        targetPanel.setLayout(new FlowLayout(FlowLayout.LEFT));        JLabel editingLabel = new JLabel("Editing: ");        editingLabel.setFont(new Font(null,Font.BOLD,12));        JLabel targetLabel = new JLabel(controller.getTargetDescription());        targetPanel.add(editingLabel);        targetPanel.add(targetLabel);        container.add(targetPanel,BorderLayout.NORTH);        annotationArea = new JTextArea();        annotationArea.setLineWrap(true);        annotationArea.setWrapStyleWord(true);        annotationArea.getDocument().addDocumentListener(this);                JScrollPane scrollPane = new JScrollPane(annotationArea);        scrollPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));        scrollPane.setPreferredSize(new Dimension(300,150));        container.add(scrollPane,BorderLayout.CENTER);                JPanel buttonPanel = new JPanel();        buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));        reloadButton = new JButton("Reload");                reloadButton.addActionListener(new ActionListener()        {            public void actionPerformed(ActionEvent ae)            {                if(isNewAnnotation)                {                    annotationArea.setText("");                }                else                {                    annotationArea.setText(controller.getAnnotation(annotationIndex));                }            }        });        saveButton = new JButton("Save");        saveButton.setEnabled(false);                saveButton.addActionListener(new ActionListener()        {            public void actionPerformed(ActionEvent ae)            {                if(isNewAnnotation)                {                    controller.newAnnotation(annotationArea.getText());                    isNewAnnotation = false;                    annotationIndex = 0;                }                else                {                    controller.setAnnotation(annotationIndex,                                             annotationArea.getText());                }                controller.save();                dispose();            }        });                buttonPanel.add(reloadButton);        buttonPanel.add(saveButton);        container.add(buttonPanel, BorderLayout.SOUTH);                setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);        final Component refCopy = this;        addWindowListener(new WindowAdapter()        {            public void windowClosing(WindowEvent arg0)            {                if(controller.isSaved())                {                    setVisible(false);                    dispose();                    controller.close();                }                else                {                    Object[] options = {"Save","Don't Save","Cancel"};                    int status = JOptionPane.showOptionDialog(refCopy,                                    "Would you like to keep the changes?",                                    "Save Annotation",                                    JOptionPane.YES_NO_CANCEL_OPTION,                                    JOptionPane.QUESTION_MESSAGE,                                    null,                                    options,                                    options[0]);                    if(status == JOptionPane.YES_OPTION)                    {                        // TODO add extraction from text area -> controller                        controller.save();                        setVisible(false);                        dispose();                        controller.close();                    }                    else if(status == JOptionPane.NO_OPTION)                    {                        setVisible(false);                        dispose();                        controller.close();                    }                    else if(status == JOptionPane.CANCEL_OPTION)                    {                        // do nothing                    }                }            }        });                // ok, now check to see if there are any annotations (single-annotation        // use case here)        List annotations = controller.getTextAnnotations();        if(annotations.size() == 0)        {            isNewAnnotation = true;            annotationArea.setText("(no annotation)");        }        else        {            String annotation = controller.getAnnotation(0);            annotationArea.setText(annotation);        }                pack();    }