From: Ben Soares Date: Wed, 24 May 2023 16:28:25 +0000 (+0100) Subject: JAL-4186 fix dialog. broken in JalviewJS X-Git-Tag: Release_2_11_4_0~293^2^2~3 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b81011230fbb6ed9286b4d1a7136a4535978e3db;p=jalview.git JAL-4186 fix dialog. broken in JalviewJS --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 006886f..1a24ed1 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -702,7 +702,7 @@ label.sequence_details_for = Sequence Details for {0} label.sequence_name = Sequence Name label.sequence_description = Sequence Description label.edit_sequence_name_description = Edit Sequence Name/Description -label.spaces_converted_to_underscores = Spaces have been converted to _ +label.spaces_converted_to_underscores = Spaces have been converted to underscores (_) label.no_spaces_allowed_sequence_name = No spaces allowed in Sequence Name label.select_outline_colour = Select Outline Colour label.web_browser_not_found_unix = Unixers\: Couldn't find default web browser.\nAdd the full path to your browser in Preferences." diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 4ac298f..b3c6988 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -640,7 +640,7 @@ label.sequence_details_for = Detalles de la secuencia para {0} label.sequence_name = Nombre de la secuencia label.sequence_description = Descripción de la secuencia label.edit_sequence_name_description = Editar el nombre/descripción de la secuencia -label.spaces_converted_to_underscores = Los espacios se han convertido en _ +label.spaces_converted_to_underscores = Los espacios se han convertido en guión bajos (_) label.no_spaces_allowed_sequence_name = No se permiten espacios en el nombre de la secuencia label.select_outline_colour = Seleccionar el color del límite label.web_browser_not_found_unix = Unixers\: No es posible encontrar el navegador web por defecto.\nA\u00F1ada la ruta completa de su navegador en la pesta\u00F1a de Preferencias. diff --git a/src/jalview/gui/JvOptionPane.java b/src/jalview/gui/JvOptionPane.java index 020890b..99ab26f 100644 --- a/src/jalview/gui/JvOptionPane.java +++ b/src/jalview/gui/JvOptionPane.java @@ -60,6 +60,7 @@ import javax.swing.event.InternalFrameListener; import jalview.bin.Console; import jalview.util.ChannelProperties; +import jalview.util.MessageManager; import jalview.util.Platform; import jalview.util.dialogrunner.DialogRunnerI; @@ -1553,11 +1554,24 @@ public class JvOptionPane extends JOptionPane } public static JvOptionPane frameDialog(String message, String title, - int messageType, String[] buttonsText, String defaultButton, + int messageType, String[] buttonsTextS, String defaultButtonS, Callable[] handlers, boolean modal) { JFrame parent = new JFrame(); JvOptionPane jvop = JvOptionPane.newOptionDialog(); + final String[] buttonsText; + final String defaultButton; + if (buttonsTextS == null) + { + String ok = MessageManager.getString("action.ok"); + buttonsText = new String[] { ok }; + defaultButton = ok; + } + else + { + buttonsText = buttonsTextS; + defaultButton = defaultButtonS; + } JButton[] buttons = new JButton[buttonsText.length]; for (int i = 0; i < buttonsText.length; i++) { @@ -1581,15 +1595,24 @@ public class JvOptionPane extends JOptionPane { dialogType = JOptionPane.YES_NO_CANCEL_OPTION; } - jvop.setResponseHandler(JOptionPane.YES_OPTION, handlers[0]); + Callable nullCallable = () -> { + return null; + }; + jvop.setResponseHandler(JOptionPane.YES_OPTION, + (handlers != null && handlers.length > 0) ? handlers[0] + : nullCallable); if (dialogType == JOptionPane.YES_NO_OPTION || dialogType == JOptionPane.YES_NO_CANCEL_OPTION) { - jvop.setResponseHandler(JOptionPane.NO_OPTION, handlers[1]); + jvop.setResponseHandler(JOptionPane.NO_OPTION, + (handlers != null && handlers.length > 1) ? handlers[1] + : nullCallable); } if (dialogType == JOptionPane.YES_NO_CANCEL_OPTION) { - jvop.setResponseHandler(JOptionPane.CANCEL_OPTION, handlers[2]); + jvop.setResponseHandler(JOptionPane.CANCEL_OPTION, + (handlers != null && handlers.length > 2) ? handlers[2] + : nullCallable); } final int dt = dialogType; diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 1c03d6a..9d62976 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -2028,12 +2028,13 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { if (dialog.getName().indexOf(" ") > -1) { - JvOptionPane.showMessageDialog(ap, + JvOptionPane.frameDialog( MessageManager.getString( "label.spaces_converted_to_underscores"), MessageManager.getString( "label.no_spaces_allowed_sequence_name"), - JvOptionPane.WARNING_MESSAGE); + JvOptionPane.WARNING_MESSAGE, null, null, null, + false); } sequence.setName(dialog.getName().replace(' ', '_')); ap.paintAlignment(false, false);