Repository: workcraft/workcraft
Issue: Problem creating a new work while another work is maximised

- Work with an existing document
- Maximize it's editor window
- Create a new document

Now it is not possible to exit the maximized editor mode properly....

The error message is:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Can't maximize while different dockable is maximized
    at org.flexdock.docking.DockingManager.toggleMaximized(DockingManager.java:2732)
    at org.workcraft.gui.MainWindow.toggleDockableWindowMaximized(MainWindow.java:448)
    at org.workcraft.gui.DockableWindowContentPanel$ViewAction.run(DockableWindowContentPanel.java:71)
    at org.workcraft.gui.MainWindow$1.actionPerformed(MainWindow.java:109)
    at org.workcraft.gui.tabs.TabButton.mouseClicked(TabButton.java:62)
    at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)

---

This issue was imported from Launchpad bug.
- date created: 2010-10-21T16:37:09Z
- owner: sgaflv
- assignee: danilovesky
- the launchpad url was https://bugs.launchpad.net/bugs/664600


Changed files:
WorkcraftCore/src/org/workcraft/gui/tabs/DockableTab.java
WorkcraftCore/src/org/workcraft/gui/MainWindow.java
WorkcraftCore/src/org/workcraft/gui/DockableWindowTabListener.java
WorkcraftCore/src/org/workcraft/gui/DockableWindowContentPanel.java
MpsatVerificationPlugin/src/org/workcraft/plugins/mpsat/gui/MpsatSolutionPanel.java
WorkcraftCore/src/org/workcraft/gui/graph/GraphEditorPanelKeyListener.java
SonPlugin/src/org/workcraft/plugins/son/commands/ToolManager.java
WorkcraftCore/src/org/workcraft/gui/EditorWindowTabListener.java
WorkcraftCore/src/org/workcraft/gui/graph/GraphEditorPanel.java
WorkcraftCore/src/org/workcraft/gui/DockableWindow.java

diff --git a/MpsatVerificationPlugin/src/org/workcraft/plugins/mpsat/gui/MpsatSolutionPanel.java b/MpsatVerificationPlugin/src/org/workcraft/plugins/mpsat/gui/MpsatSolutionPanel.java
index 5186264cb..1e56a028f 100644
--- a/MpsatVerificationPlugin/src/org/workcraft/plugins/mpsat/gui/MpsatSolutionPanel.java
+++ b/MpsatVerificationPlugin/src/org/workcraft/plugins/mpsat/gui/MpsatSolutionPanel.java
@@ -2,7 +2,6 @@ package org.workcraft.plugins.mpsat.gui;
 
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.util.List;
 
 import javax.swing.BorderFactory;
 import javax.swing.BoxLayout;
@@ -75,20 +74,11 @@ public class MpsatSolutionPanel extends JPanel {
             public void actionPerformed(ActionEvent e) {
                 final Framework framework = Framework.getInstance();
                 final MainWindow mainWindow = framework.getMainWindow();
-                GraphEditorPanel currentEditor = mainWindow.getCurrentEditor();
-                if (currentEditor == null || currentEditor.getWorkspaceEntry() != we) {
-                    final List<GraphEditorPanel> editors = mainWindow.getEditors(we);
-                    if (editors.size() > 0) {
-                        currentEditor = editors.get(0);
-                        mainWindow.requestFocus(currentEditor);
-                    } else {
-                        currentEditor = mainWindow.createEditorWindow(we);
-                    }
-                }
-                final ToolboxPanel toolbox = currentEditor.getToolBox();
+                GraphEditorPanel editor = mainWindow.getEditor(we);
+                final ToolboxPanel toolbox = editor.getToolBox();
                 final SimulationTool tool = toolbox.getToolInstance(SimulationTool.class);
                 toolbox.selectTool(tool);
-                tool.setTrace(solution.getMainTrace(), solution.getBranchTrace(), currentEditor);
+                tool.setTrace(solution.getMainTrace(), solution.getBranchTrace(), editor);
                 String comment = solution.getComment();
                 if ((comment != null) && !comment.isEmpty()) {
                     comment = comment.replaceAll("\\\\<.*?>", "");
diff --git a/SonPlugin/src/org/workcraft/plugins/son/commands/ToolManager.java b/SonPlugin/src/org/workcraft/plugins/son/commands/ToolManager.java
index 6ed0d01a2..d73c7a702 100644
--- a/SonPlugin/src/org/workcraft/plugins/son/commands/ToolManager.java
+++ b/SonPlugin/src/org/workcraft/plugins/son/commands/ToolManager.java
@@ -1,7 +1,5 @@
 package org.workcraft.plugins.son.commands;
 
-import java.util.List;
-
 import org.workcraft.Framework;
 import org.workcraft.gui.MainWindow;
 import org.workcraft.gui.ToolboxPanel;
@@ -13,17 +11,8 @@ public class ToolManager {
     public static ToolboxPanel getToolboxPanel(WorkspaceEntry we) {
         final Framework framework = Framework.getInstance();
         final MainWindow mainWindow = framework.getMainWindow();
-        GraphEditorPanel currentEditor = mainWindow.getCurrentEditor();
-        if (currentEditor == null || currentEditor.getWorkspaceEntry() != we) {
-            final List<GraphEditorPanel> editors = mainWindow.getEditors(we);
-            if (editors.size() > 0) {
-                currentEditor = editors.get(0);
-                mainWindow.requestFocus(currentEditor);
-            } else {
-                currentEditor = mainWindow.createEditorWindow(we);
-            }
-        }
-        return currentEditor.getToolBox();
+        GraphEditorPanel editor = mainWindow.getEditor(we);
+        return editor.getToolBox();
     }
 
 }
diff --git a/WorkcraftCore/src/org/workcraft/gui/DockableWindow.java b/WorkcraftCore/src/org/workcraft/gui/DockableWindow.java
index ed64882c6..33333bdaa 100644
--- a/WorkcraftCore/src/org/workcraft/gui/DockableWindow.java
+++ b/WorkcraftCore/src/org/workcraft/gui/DockableWindow.java
@@ -1,6 +1,7 @@
 package org.workcraft.gui;
 
 import java.awt.Component;
+import java.awt.Container;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.util.ArrayList;
@@ -82,6 +83,15 @@ public class DockableWindow extends AbstractDockable {
     public void setMaximized(boolean maximized) {
         panel.setMaximized(maximized);
         updateHeaders(this.getDockingPort(), mainWindow.getDefaultActionListener());
+        if (maximized) {
+            for (DockableWindowTabListener l: tabListeners) {
+                l.windowMaximised();
+            }
+        } else {
+            for (DockableWindowTabListener l: tabListeners) {
+                l.windowRestored();
+            }
+        }
     }
 
     public boolean isClosed() {
@@ -121,7 +131,8 @@ public class DockableWindow extends AbstractDockable {
                 JTabbedPane tabbedPane = (JTabbedPane) dockable.getComponent().getParent();
                 for (int i = 0; i < tabbedPane.getComponentCount(); i++) {
                     if (dockable.getComponent() == tabbedPane.getComponentAt(i)) {
-                        tabbedPane.setTabComponentAt(i, new DockableTab(dockable, actionListener));
+                        DockableTab dockableTab = new DockableTab(dockable, actionListener);
+                        tabbedPane.setTabComponentAt(i, dockableTab);
                         break;
                     }
                 }
@@ -154,23 +165,23 @@ public class DockableWindow extends AbstractDockable {
     }
 
     public void processTabEvents() {
-        if (getComponent().getParent() instanceof JTabbedPane) {
-            JTabbedPane tabbedPane = (JTabbedPane) getComponent().getParent();
+        Container parent = getComponent().getParent();
+        if (parent instanceof JTabbedPane) {
+            JTabbedPane tabbedPane = (JTabbedPane) parent;
             if (!inTab) {
                 inTab = true;
                 for (DockableWindowTabListener l: tabListeners) {
                     l.dockedInTab(tabbedPane, getTabIndex(tabbedPane, this));
                 }
             }
-            if (!Arrays.asList(tabbedPane.getChangeListeners()).contains(tabChangeListener)) {
+            List<ChangeListener> tabbedPaneListeners = Arrays.asList(tabbedPane.getChangeListeners());
+            if (!tabbedPaneListeners.contains(tabChangeListener)) {
                 tabbedPane.addChangeListener(tabChangeListener);
             }
-        } else {
-            if (inTab) {
-                inTab = false;
-                for (DockableWindowTabListener l: tabListeners) {
-                    l.dockedStandalone();
-                }
+        } else if (inTab) {
+            inTab = false;
+            for (DockableWindowTabListener l: tabListeners) {
+                l.dockedStandalone();
             }
         }
     }
diff --git a/WorkcraftCore/src/org/workcraft/gui/DockableWindowContentPanel.java b/WorkcraftCore/src/org/workcraft/gui/DockableWindowContentPanel.java
index a95ba06f8..a44b390d4 100644
--- a/WorkcraftCore/src/org/workcraft/gui/DockableWindowContentPanel.java
+++ b/WorkcraftCore/src/org/workcraft/gui/DockableWindowContentPanel.java
@@ -43,18 +43,17 @@ public class DockableWindowContentPanel extends JPanel {
 
         @Override
         public void run() {
+            final Framework framework = Framework.getInstance();
+            MainWindow mainWindow = framework.getMainWindow();
             switch (actionType) {
             case CLOSE_ACTION:
                 try {
-                    final Framework framework = Framework.getInstance();
-                    framework.getMainWindow().closeDockableWindow(windowID);
+                    mainWindow.closeDockableWindow(windowID);
                 } catch (OperationCancelledException e) {
-
                 }
                 break;
             case MAXIMIZE_ACTION:
-                final Framework framework = Framework.getInstance();
-                framework.getMainWindow().toggleDockableWindowMaximized(windowID);
+                mainWindow.toggleDockableWindowMaximized(windowID);
                 break;
             case MINIMIZE_ACTION:
                 throw new NotSupportedException();
@@ -103,7 +102,8 @@ public class DockableWindowContentPanel extends JPanel {
             int iconCount = 0;
             if ((options & MINIMIZE_BUTTON) != 0) {
                 Icon minIcon = UIManager.getIcon("InternalFrame.minimizeIcon");
-                btnMin = createHeaderButton(minIcon, new ViewAction(id, ViewAction.MINIMIZE_ACTION), mainWindow.getDefaultActionListener());
+                ViewAction minAction = new ViewAction(id, ViewAction.MINIMIZE_ACTION);
+                btnMin = createHeaderButton(minIcon, minAction, mainWindow.getDefaultActionListener());
                 btnMin.setToolTipText("Toggle minimized");
                 buttonPanel.add(btnMin);
                 iconCount++;
@@ -111,21 +111,24 @@ public class DockableWindowContentPanel extends JPanel {
 
             if ((options & MAXIMIZE_BUTTON) != 0) {
                 Icon maxIcon = UIManager.getIcon("InternalFrame.maximizeIcon");
-                btnMax = createHeaderButton(maxIcon, new ViewAction(id, ViewAction.MAXIMIZE_ACTION), mainWindow.getDefaultActionListener());
+                ViewAction maxAction = new ViewAction(id, ViewAction.MAXIMIZE_ACTION);
+                btnMax = createHeaderButton(maxIcon, maxAction, mainWindow.getDefaultActionListener());
                 buttonPanel.add(btnMax);
                 iconCount++;
             }
 
             Icon closeIcon = UIManager.getIcon("InternalFrame.closeIcon");
             if ((options & CLOSE_BUTTON) != 0) {
-                btnClose = createHeaderButton(closeIcon, new ViewAction(id, ViewAction.CLOSE_ACTION), mainWindow.getDefaultActionListener());
+                ViewAction closeAction = new ViewAction(id, ViewAction.CLOSE_ACTION);
+                btnClose = createHeaderButton(closeIcon, closeAction, mainWindow.getDefaultActionListener());
                 btnClose.setToolTipText("Close window");
                 buttonPanel.add(btnClose);
                 iconCount++;
             }
 
             if (iconCount != 0) {
-                buttonPanel.setPreferredSize(new Dimension((closeIcon.getIconWidth() + 4) * iconCount, closeIcon.getIconHeight() + 4));
+                Dimension size = new Dimension((closeIcon.getIconWidth() + 4) * iconCount, closeIcon.getIconHeight() + 4);
+                buttonPanel.setPreferredSize(size);
             }
 
             titleLabel = new JLabel(title);
diff --git a/WorkcraftCore/src/org/workcraft/gui/DockableWindowTabListener.java b/WorkcraftCore/src/org/workcraft/gui/DockableWindowTabListener.java
index 6f3cad387..9e25d858f 100644
--- a/WorkcraftCore/src/org/workcraft/gui/DockableWindowTabListener.java
+++ b/WorkcraftCore/src/org/workcraft/gui/DockableWindowTabListener.java
@@ -8,4 +8,6 @@ public interface DockableWindowTabListener {
     void tabSelected(JTabbedPane pane, int index);
     void tabDeselected(JTabbedPane pane, int index);
     void headerClicked();
+    void windowMaximised();
+    void windowRestored();
 }
diff --git a/WorkcraftCore/src/org/workcraft/gui/EditorWindowTabListener.java b/WorkcraftCore/src/org/workcraft/gui/EditorWindowTabListener.java
index 7d5d15292..ccd7ec288 100644
--- a/WorkcraftCore/src/org/workcraft/gui/EditorWindowTabListener.java
+++ b/WorkcraftCore/src/org/workcraft/gui/EditorWindowTabListener.java
@@ -15,9 +15,8 @@ public class EditorWindowTabListener implements DockableWindowTabListener {
 
     @Override
     public void tabSelected(JTabbedPane tabbedPane, int tabIndex) {
-        final Framework framework = Framework.getInstance();
-        MainWindow mainWindow = framework.getMainWindow();
-        mainWindow.requestFocus(editor);
+        setNonFocusable(tabbedPane);
+        requestEditorFocus();
     }
 
     @Override
@@ -26,14 +25,36 @@ public class EditorWindowTabListener implements DockableWindowTabListener {
 
     @Override
     public void dockedStandalone() {
+        requestEditorFocus();
     }
 
     @Override
     public void dockedInTab(JTabbedPane tabbedPane, int tabIndex) {
+        setNonFocusable(tabbedPane);
+        requestEditorFocus();
     }
 
     @Override
     public void headerClicked() {
+        requestEditorFocus();
+    }
+
+    @Override
+    public void windowMaximised() {
+        requestEditorFocus();
+    }
+
+    @Override
+    public void windowRestored() {
+        requestEditorFocus();
+    }
+
+    private void setNonFocusable(JTabbedPane tabbedPane) {
+        // Set non-focusable, so that tab activation does not steal the focus form the included component.
+        tabbedPane.setFocusable(false);
+    }
+
+    private void requestEditorFocus() {
         final Framework framework = Framework.getInstance();
         MainWindow mainWindow = framework.getMainWindow();
         mainWindow.requestFocus(editor);
diff --git a/WorkcraftCore/src/org/workcraft/gui/MainWindow.java b/WorkcraftCore/src/org/workcraft/gui/MainWindow.java
index 7b85e3c8e..1d908c3df 100644
--- a/WorkcraftCore/src/org/workcraft/gui/MainWindow.java
+++ b/WorkcraftCore/src/org/workcraft/gui/MainWindow.java
@@ -225,10 +225,7 @@ public class MainWindow extends JFrame {
         final GraphEditorPanel editor = new GraphEditorPanel(we);
         String title = getTitle(we);
         final DockableWindow editorWindow;
-        int options = DockableWindowContentPanel.CLOSE_BUTTON;
-        // FIXME: Maximised tabs confuse EditorWindowTabListener that sets editorInFocus,
-        //        therefore the maximise button is temporary removed from the dockable windows.
-        // options |= DockableWindowContentPanel.MAXIMIZE_BUTTON;
+        int options = DockableWindowContentPanel.CLOSE_BUTTON | DockableWindowContentPanel.MAXIMIZE_BUTTON;
         if (editorWindows.isEmpty()) {
             editorWindow = createDockableWindow(editor, title, documentPlaceholder, options,
                     DockingConstants.CENTER_REGION, "Document" + we.getWorkspacePath());
@@ -236,11 +233,13 @@ public class MainWindow extends JFrame {
             DockingManager.unregisterDockable(documentPlaceholder);
             utilityWindows.remove(documentPlaceholder);
         } else {
+            unmaximiseAllDockableWindows();
             DockableWindow firstEditorWindow = editorWindows.values().iterator().next().iterator().next();
             editorWindow = createDockableWindow(editor, title, firstEditorWindow, options,
                     DockingConstants.CENTER_REGION, "Document" + we.getWorkspacePath());
         }
-        editorWindow.addTabListener(new EditorWindowTabListener(editor));
+        EditorWindowTabListener tabListener = new EditorWindowTabListener(editor);
+        editorWindow.addTabListener(tabListener);
         editorWindows.put(we, editorWindow);
         requestFocus(editor);
         setWorkActionsEnableness(true);
@@ -248,6 +247,17 @@ public class MainWindow extends JFrame {
         return editor;
     }
 
+    private void unmaximiseAllDockableWindows() {
+        for (LinkedList<DockableWindow> dockableWindows: editorWindows.values()) {
+            for (DockableWindow dockableWindow: dockableWindows) {
+                if (dockableWindow.isMaximized()) {
+                    DockingManager.toggleMaximized(dockableWindow);
+                    dockableWindow.setMaximized(false);
+                }
+            }
+        }
+    }
+
     private void registerUtilityWindow(DockableWindow dockableWindow) {
         if (!rootDockingPort.getDockables().contains(dockableWindow)) {
             dockableWindow.setClosed(true);
@@ -696,25 +706,24 @@ public class MainWindow extends JFrame {
         }
     }
 
-    public void requestFocus(GraphEditorPanel sender) {
-        sender.requestFocusInWindow();
-        if (editorInFocus != sender) {
-            editorInFocus = sender;
+    public void requestFocus(GraphEditorPanel editor) {
+        editor.requestFocusInWindow();
+        if (editorInFocus != editor) {
+            editorInFocus = editor;
 
             WorkspaceEntry we = editorInFocus.getWorkspaceEntry();
             mainMenu.setMenuForWorkspaceEntry(we);
 
-            ToolboxPanel toolBox = sender.getToolBox();
+            ToolboxPanel toolBox = editorInFocus.getToolBox();
             toolControlsWindow.setContent(toolBox);
             editorToolsWindow.setContent(toolBox.getControlPanel());
 
             GraphEditorTool selectedTool = toolBox.getSelectedTool();
             selectedTool.setup(editorInFocus);
-            sender.updatePropertyView();
+            editorInFocus.updatePropertyView();
 
             Framework.getInstance().updateJavaScript(we);
         }
-        editorInFocus.requestFocus();
     }
 
     private void printCause(Throwable e) {
diff --git a/WorkcraftCore/src/org/workcraft/gui/graph/GraphEditorPanel.java b/WorkcraftCore/src/org/workcraft/gui/graph/GraphEditorPanel.java
index 68e0ed17d..6d6e84609 100644
--- a/WorkcraftCore/src/org/workcraft/gui/graph/GraphEditorPanel.java
+++ b/WorkcraftCore/src/org/workcraft/gui/graph/GraphEditorPanel.java
@@ -72,37 +72,46 @@ public class GraphEditorPanel extends JPanel implements StateObserver, GraphEdit
     public static final String TITLE_SUFFIX_SELECTED_ELEMENTS = " selected elements";
     private static final int VIEWPORT_MARGIN = 25;
 
-    class Resizer implements ComponentListener {
+    public class GraphEditorFocusListener implements FocusListener {
+        private final GraphEditorPanel editor;
 
-        @Override
-        public void componentHidden(ComponentEvent e) {
+        public GraphEditorFocusListener(GraphEditorPanel editor) {
+            this.editor = editor;
         }
 
         @Override
-        public void componentMoved(ComponentEvent e) {
+        public void focusGained(FocusEvent e) {
+            final Framework framework = Framework.getInstance();
+            MainWindow mainWindow = framework.getMainWindow();
+            mainWindow.requestFocus(editor);
+            repaint();
         }
 
         @Override
-        public void componentResized(ComponentEvent e) {
-            reshape();
+        public void focusLost(FocusEvent e) {
             repaint();
         }
+    }
+
+    class Resizer implements ComponentListener {
 
         @Override
-        public void componentShown(ComponentEvent e) {
+        public void componentHidden(ComponentEvent e) {
         }
-    }
 
-    public class GraphEditorFocusListener implements FocusListener {
         @Override
-        public void focusGained(FocusEvent e) {
-            repaint();
+        public void componentMoved(ComponentEvent e) {
         }
 
         @Override
-        public void focusLost(FocusEvent e) {
+        public void componentResized(ComponentEvent e) {
+            reshape();
             repaint();
         }
+
+        @Override
+        public void componentShown(ComponentEvent e) {
+        }
     }
 
     private static final long serialVersionUID = 1L;
@@ -201,14 +210,14 @@ public class GraphEditorPanel extends JPanel implements StateObserver, GraphEdit
 
         GraphEditorPanelMouseListener mouseListener = new GraphEditorPanelMouseListener(this, toolboxPanel);
         GraphEditorPanelKeyListener keyListener = new GraphEditorPanelKeyListener(this, toolboxPanel);
+        GraphEditorFocusListener focusListener = new GraphEditorFocusListener(this);
 
         addMouseMotionListener(mouseListener);
         addMouseListener(mouseListener);
         addMouseWheelListener(mouseListener);
-        addFocusListener(new GraphEditorFocusListener());
-        addComponentListener(new Resizer());
-
         addKeyListener(keyListener);
+        addFocusListener(focusListener);
+        addComponentListener(new Resizer());
 
         add(overlay, BorderLayout.CENTER);
 
diff --git a/WorkcraftCore/src/org/workcraft/gui/graph/GraphEditorPanelKeyListener.java b/WorkcraftCore/src/org/workcraft/gui/graph/GraphEditorPanelKeyListener.java
index e2cae2928..633c858e1 100644
--- a/WorkcraftCore/src/org/workcraft/gui/graph/GraphEditorPanelKeyListener.java
+++ b/WorkcraftCore/src/org/workcraft/gui/graph/GraphEditorPanelKeyListener.java
@@ -8,8 +8,8 @@ import org.workcraft.gui.events.GraphEditorKeyEvent;
 import org.workcraft.gui.graph.tools.GraphEditorKeyListener;
 
 class GraphEditorPanelKeyListener implements KeyListener {
-    GraphEditorPanel editor;
-    GraphEditorKeyListener forwardListener;
+    private final GraphEditorPanel editor;
+    private final GraphEditorKeyListener forwardListener;
 
     GraphEditorPanelKeyListener(GraphEditorPanel editor, GraphEditorKeyListener forwardListener) {
         this.editor = editor;
diff --git a/WorkcraftCore/src/org/workcraft/gui/tabs/DockableTab.java b/WorkcraftCore/src/org/workcraft/gui/tabs/DockableTab.java
index 95fe0bf55..3fe556f8d 100644
--- a/WorkcraftCore/src/org/workcraft/gui/tabs/DockableTab.java
+++ b/WorkcraftCore/src/org/workcraft/gui/tabs/DockableTab.java
@@ -41,20 +41,22 @@ public class DockableTab extends JPanel {
         label.setFocusable(false);
         label.setOpaque(false);
 
-        TabButton close = null;
+        TabButton closeButton = null;
         if ((dockableWindow.getOptions() & DockableWindowContentPanel.MAXIMIZE_BUTTON) != 0) {
-            TabButton max = new TabButton("\\u2191", "Maximize window", new ViewAction(dockableWindow.getID(), ViewAction.MAXIMIZE_ACTION), actionListener);
-            buttonsPanel.add(max);
+            ViewAction viewAction = new ViewAction(dockableWindow.getID(), ViewAction.MAXIMIZE_ACTION);
+            TabButton maxButton = new TabButton("\\u2191", "Maximize window", viewAction, actionListener);
+            buttonsPanel.add(maxButton);
             buttonsPanel.add(Box.createRigidArea(new Dimension(2, 0)));
         }
 
         if ((dockableWindow.getOptions() & DockableWindowContentPanel.CLOSE_BUTTON) != 0) {
-            close = new TabButton("\\u00d7", "Close window", new ViewAction(dockableWindow.getID(), ViewAction.CLOSE_ACTION), actionListener);
-            buttonsPanel.add(close);
+            ViewAction viewAction = new ViewAction(dockableWindow.getID(), ViewAction.CLOSE_ACTION);
+            closeButton = new TabButton("\\u00d7", "Close window", viewAction, actionListener);
+            buttonsPanel.add(closeButton);
         }
 
         Dimension x = label.getPreferredSize();
-        Dimension y = (close != null) ? close.getPreferredSize() : x;
+        Dimension y = (closeButton != null) ? closeButton.getPreferredSize() : x;
 
         this.add(label, BorderLayout.CENTER);
         this.add(buttonsPanel, BorderLayout.EAST);