JAL-1774 modifed warning dialog to use JVDialog rather than JOPtionPane
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 21 Sep 2015 15:29:24 +0000 (16:29 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 21 Sep 2015 15:29:24 +0000 (16:29 +0100)
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/AnnotationColumnChooser.java
src/jalview/appletgui/JVDialog.java

index 2a2fc81..0d1fd35 100644 (file)
@@ -75,6 +75,7 @@ import java.awt.BorderLayout;
 import java.awt.Canvas;
 import java.awt.CheckboxMenuItem;
 import java.awt.Color;
+import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Frame;
@@ -83,6 +84,7 @@ import java.awt.Label;
 import java.awt.Menu;
 import java.awt.MenuBar;
 import java.awt.MenuItem;
+import java.awt.Panel;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.FocusEvent;
@@ -105,8 +107,6 @@ import java.util.Map;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
-import javax.swing.JOptionPane;
-
 import org.jmol.viewer.Viewer;
 
 public class AlignFrame extends EmbmenuFrame implements ActionListener,
@@ -2065,19 +2065,25 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
     /*
      * If the cut affects all sequences, warn, remove highlighted columns
-     */if (sg.getSize() == viewport.getAlignment().getHeight())
+     */
+    if (sg.getSize() == viewport.getAlignment().getHeight())
     {
       boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
               .getAlignment().getWidth()) ? true : false;
       if (isEntireAlignWidth)
       {
-        int confirm = JOptionPane.showConfirmDialog(this,
-                MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
-                MessageManager.getString("label.delete_all"), // $NON-NLS-1$
-                JOptionPane.OK_CANCEL_OPTION);
 
-        if (confirm == JOptionPane.CANCEL_OPTION
-                || confirm == JOptionPane.CLOSED_OPTION)
+        String title = MessageManager.getString("label.delete_all");
+        Panel mp = new Panel();
+        mp.setLayout(new FlowLayout());
+        mp.add(new Label(MessageManager.getString("warn.delete_all")));
+
+        final JVDialog dialog = new JVDialog(this, title, true, 400,
+                200);
+        dialog.setMainPanel(mp);
+        dialog.setVisible(true);
+
+        if (!dialog.accept)
         {
           return;
         }
index 5cd95b6..e3def25 100644 (file)
@@ -49,7 +49,7 @@ import java.awt.event.TextListener;
 import java.util.Iterator;
 import java.util.Vector;
 
-import javax.swing.JPanel;
+//import javax.swing.JPanel;
 
 //import net.miginfocom.swing.MigLayout;
 
@@ -241,7 +241,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     actionPanel.add(ok);
     actionPanel.add(cancel);
 
-    JPanel staticPanel = new JPanel();
+    Panel staticPanel = new Panel();
     staticPanel.setLayout(new BorderLayout());
     staticPanel.setBackground(Color.white);
 
index 58c4feb..a7cc83f 100644 (file)
@@ -28,6 +28,8 @@ import java.awt.Frame;
 import java.awt.Panel;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
 
 public class JVDialog extends Dialog implements ActionListener
 {
@@ -56,6 +58,20 @@ public class JVDialog extends Dialog implements ActionListener
             width, height);
   }
 
+  public JVDialog(Frame owner, Panel mainPanel, String title,
+          boolean modal, int width, int height)
+  {
+    super(owner, title, modal);
+    this.owner = owner;
+
+    height += owner.getInsets().top + getInsets().bottom;
+
+    setBounds(owner.getBounds().x + (owner.getSize().width - width) / 2,
+            owner.getBounds().y + (owner.getSize().height - height) / 2,
+            width, height);
+    setMainPanel(mainPanel);
+  }
+
   void setMainPanel(Panel panel)
   {
     add(panel, BorderLayout.NORTH);
@@ -66,9 +82,17 @@ public class JVDialog extends Dialog implements ActionListener
     buttonPanel.add(cancel);
     ok.addActionListener(this);
     cancel.addActionListener(this);
-
     add(buttonPanel, BorderLayout.SOUTH);
 
+    addWindowListener(new WindowAdapter()
+    {
+      public void windowClosing(WindowEvent ev)
+      {
+        setVisible(false);
+        dispose();
+      }
+    });
+
     pack();
 
   }
@@ -81,6 +105,7 @@ public class JVDialog extends Dialog implements ActionListener
     }
 
     setVisible(false);
+    dispose();
   }
 
 }