mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
Merge remote-tracking branch 'origin/GT-2891-dragonmacher-optiondialog-to-swing'
This commit is contained in:
commit
f3a7cb0490
16 changed files with 380 additions and 313 deletions
|
@ -19,6 +19,7 @@ import java.awt.Component;
|
|||
import java.awt.Window;
|
||||
import java.io.*;
|
||||
|
||||
import docking.widgets.OkDialog;
|
||||
import docking.widgets.OptionDialog;
|
||||
import ghidra.util.*;
|
||||
import ghidra.util.exception.MultipleCauses;
|
||||
|
@ -97,7 +98,7 @@ public class DockingErrorDisplay implements ErrorDisplay {
|
|||
dialog = createErrorDialog(title, message, throwable, messageString);
|
||||
}
|
||||
else {
|
||||
dialog = new OptionDialog(title, messageString, dialogType, null);
|
||||
dialog = new OkDialog(title, messageString, dialogType);
|
||||
}
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ public class DialogRememberOption {
|
|||
* Constructs a new DialogRememberOption for use in an OptionDialog for adding an
|
||||
* "Apply to all", "Remember my decision", etc. checkBox.
|
||||
* @param description the checkBox text (e.g. "Apply to all")
|
||||
* @param defaultState the default state of the checkBox. (This almost always false.)
|
||||
*/
|
||||
public DialogRememberOption(String description) {
|
||||
this.description = description;
|
||||
|
@ -57,8 +56,8 @@ public class DialogRememberOption {
|
|||
|
||||
/**
|
||||
* Returns true if a previous call to the dialog was remembered (The user selected the
|
||||
* checkBox.)
|
||||
* @return
|
||||
* checkBox)
|
||||
* @return true if a previous call to the dialog was remembered
|
||||
*/
|
||||
public boolean hasRememberedResult() {
|
||||
return hasRememberedResult;
|
||||
|
@ -72,12 +71,10 @@ public class DialogRememberOption {
|
|||
* "shown", if there is a saved result, it will be returned
|
||||
* instead of actually showing the dialog.
|
||||
*
|
||||
* @param choice the boolean state of the checkBox.
|
||||
* @param rememberedResult the users result from the OptionDialog.
|
||||
* @param choice the user's choice from the OptionDialog
|
||||
*/
|
||||
public void rememberResult(int rememberedResult) {
|
||||
public void rememberResult(int choice) {
|
||||
this.hasRememberedResult = true;
|
||||
this.rememberedResult = rememberedResult;
|
||||
this.rememberedResult = choice;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package docking.widgets;
|
||||
|
||||
import javax.swing.Icon;
|
||||
|
||||
import ghidra.util.Swing;
|
||||
|
||||
/**
|
||||
* A dialog with an OK button. The client can specify the message type in the constructor.
|
||||
*/
|
||||
public class OkDialog extends OptionDialog {
|
||||
|
||||
/**
|
||||
* Show a {@link OptionDialog#PLAIN_MESSAGE plain} {@link OkDialog} with the given title and message
|
||||
* @param title the title
|
||||
* @param message the message
|
||||
*/
|
||||
public static void show(String title, String message) {
|
||||
Swing.runNow(() -> {
|
||||
new OkDialog(title, message, OptionDialog.PLAIN_MESSAGE).show();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a {@link OptionDialog#INFORMATION_MESSAGE plain} {@link OkDialog} with the given
|
||||
* title and message
|
||||
*
|
||||
* @param title the title
|
||||
* @param message the message
|
||||
*/
|
||||
public static void showInfo(String title, String message) {
|
||||
Swing.runNow(() -> {
|
||||
new OkDialog(title, message, OptionDialog.INFORMATION_MESSAGE).show();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a {@link OptionDialog#ERROR_MESSAGE plain} {@link OkDialog} with the given
|
||||
* title and message
|
||||
*
|
||||
* @param title the title
|
||||
* @param message the message
|
||||
*/
|
||||
public static void showError(String title, String message) {
|
||||
Swing.runNow(() -> {
|
||||
new OkDialog(title, message, OptionDialog.ERROR_MESSAGE).show();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a simple informational dialog with a single OK button
|
||||
*
|
||||
* @param title The String to be placed in the dialogs title area
|
||||
* @param message The information message to be displayed in the dialog
|
||||
* @param messageType used to specify a default icon
|
||||
* <ul>
|
||||
* <li>ERROR_MESSAGE</li>
|
||||
* <li>INFORMATION_MESSAGE</li>
|
||||
* <li>WARNING_MESSAGE</li>
|
||||
* <li>QUESTION_MESSAGE</li>
|
||||
* <li>PLAIN_MESSAGE</li>
|
||||
* </ul>
|
||||
*/
|
||||
public OkDialog(String title, String message, int messageType) {
|
||||
super(title, message, messageType, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a simple informational dialog with a single OK button
|
||||
*
|
||||
* @param title The String to be placed in the dialogs title area
|
||||
* @param message The information message to be displayed in the dialog
|
||||
* @param icon allows the user to specify the icon to be used
|
||||
* If non-null, this will override the messageType
|
||||
*/
|
||||
public OkDialog(String title, String message, Icon icon) {
|
||||
super(title, message, PLAIN_MESSAGE, icon);
|
||||
}
|
||||
}
|
|
@ -28,8 +28,7 @@ import docking.widgets.checkbox.GCheckBox;
|
|||
import docking.widgets.dialogs.*;
|
||||
import docking.widgets.label.GHtmlLabel;
|
||||
import docking.widgets.label.GIconLabel;
|
||||
import ghidra.util.HTMLUtilities;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.*;
|
||||
import ghidra.util.exception.AssertException;
|
||||
|
||||
/**
|
||||
|
@ -37,6 +36,7 @@ import ghidra.util.exception.AssertException;
|
|||
*
|
||||
*
|
||||
* <h3>Option Dialogs</h3><br>
|
||||
* <blockquote>
|
||||
* <p>
|
||||
* The primary type of
|
||||
* dialog provided herein is the basic option dialog that allows the user to specify the buttons
|
||||
|
@ -50,39 +50,53 @@ import ghidra.util.exception.AssertException;
|
|||
* Each of the option dialog methods will return a result, which is a number indicating the
|
||||
* choice made by the user. See each method for more details.
|
||||
* </p>
|
||||
* </blockquote>
|
||||
*
|
||||
*
|
||||
* <h3>Data Input and Choice Dialogs</h3><br>
|
||||
* <p>
|
||||
* The methods listed here allow the user to either enter data from the keyboard or to choose
|
||||
* from a pre-populated list of data.
|
||||
* </p>
|
||||
* <blockquote>
|
||||
* {@link #showInputChoiceDialog(Component, String, String, String[], String, int)}<br>
|
||||
* {@link #showInputMultilineDialog(Component, String, String, String)}<br>
|
||||
* {@link #showInputSingleLineDialog(Component, String, String, String)}
|
||||
* <p>
|
||||
* The methods listed here allow the user to either enter data from the keyboard or to choose
|
||||
* from a pre-populated list of data.
|
||||
* </p>
|
||||
* <blockquote>
|
||||
* {@link #showInputChoiceDialog(Component, String, String, String[], String, int)}<br>
|
||||
* {@link #showInputMultilineDialog(Component, String, String, String)}<br>
|
||||
* {@link #showInputSingleLineDialog(Component, String, String, String)}
|
||||
* </blockquote>
|
||||
* </blockquote>
|
||||
*
|
||||
*
|
||||
* <h3>Yes/No Dialogs</h3><br>
|
||||
* <blockquote>
|
||||
* <p>
|
||||
* Finally, there are a series of methods that present <tt>Yes</tt> and <tt>No</tt> buttons in
|
||||
* a dialog. There are versions that do and do not have a <tt>Cancel</tt> button.
|
||||
* </p>
|
||||
* </blockquote>
|
||||
*
|
||||
*
|
||||
* <h3>Basic Message / Warning / Error Dialogs</h3><br>
|
||||
* <blockquote>
|
||||
* <p>
|
||||
* If you would like to display a simple message to the user, but do not require input from the
|
||||
* user, then you should use the various methods of {@link Msg}, such as
|
||||
* {@link Msg#showInfo(Object, Component, String, Object)}.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Note, the user will be unable to select any text shown in the message area of the dialog.
|
||||
* </p>
|
||||
* </blockquote>
|
||||
*
|
||||
* <h3>"Apply to All" / "Don't Show Again"</h3><br>
|
||||
* <blockquote>
|
||||
* <p>For more advanced input dialog usage, to include allowing the user to tell the dialog
|
||||
* to remember a particular decision, or to apply a given choice to all future request, see
|
||||
* {@link OptionDialogBuilder}.
|
||||
* </blockquote>
|
||||
*
|
||||
* @see Msg
|
||||
* @see OptionDialogBuilder
|
||||
*/
|
||||
public class OptionDialog extends DialogComponentProvider {
|
||||
private static final String MESSAGE_COMPONENT_NAME = "MESSAGE-COMPONENT";
|
||||
|
@ -141,7 +155,7 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
* @param icon allows the user to specify the icon to be used.
|
||||
* If non-null, this will override the messageType.
|
||||
*/
|
||||
public OptionDialog(String title, String message, int messageType, Icon icon) {
|
||||
protected OptionDialog(String title, String message, int messageType, Icon icon) {
|
||||
this(title, message, null, null, messageType, icon, false, null);
|
||||
}
|
||||
|
||||
|
@ -157,7 +171,7 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
* this will override the messageType.
|
||||
* @param addCancel true means add a Cancel button
|
||||
*/
|
||||
public OptionDialog(String title, String message, String option1, String option2,
|
||||
protected OptionDialog(String title, String message, String option1, String option2,
|
||||
int messageType, Icon icon, boolean addCancel) {
|
||||
super(title, true, false, true, false);
|
||||
buildMainPanel(message, messageType, icon, null);
|
||||
|
@ -175,12 +189,9 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
* @param icon allows the user to specify the icon to be used. If non-null,
|
||||
* this will override the messageType.
|
||||
* @param addCancel true means add a Cancel button
|
||||
* @param int The index of the button that should be the default button (the one that is
|
||||
* executed when the user presses the Enter key):<br>
|
||||
* 1 for button 1; 2 for button 2 and 3 for button 3 (if applicable)
|
||||
|
||||
* @param defaultButtonName The default button name
|
||||
*/
|
||||
public OptionDialog(String title, String message, String option1, String option2,
|
||||
protected OptionDialog(String title, String message, String option1, String option2,
|
||||
int messageType, Icon icon, boolean addCancel, String defaultButtonName) {
|
||||
super(title, true, false, true, false);
|
||||
buildMainPanel(message, messageType, icon, null);
|
||||
|
@ -197,7 +208,8 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
* @param icon allows the user to specify the icon to be used. If non-null,
|
||||
* this will override the messageType.
|
||||
*/
|
||||
public OptionDialog(String title, String message, String option1, int messageType, Icon icon) {
|
||||
protected OptionDialog(String title, String message, String option1, int messageType,
|
||||
Icon icon) {
|
||||
this(title, message, option1, null, messageType, icon, true, null);
|
||||
}
|
||||
|
||||
|
@ -212,14 +224,12 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
* this will override the messageType.
|
||||
* @param defaultButtonName the name of the button to be made the default.
|
||||
*/
|
||||
public OptionDialog(String title, String message, String option1, int messageType, Icon icon,
|
||||
protected OptionDialog(String title, String message, String option1, int messageType, Icon icon,
|
||||
String defaultButtonName) {
|
||||
this(title, message, option1, null, messageType, icon, true, defaultButtonName);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Special 3 button constructor */
|
||||
/* Special 3 button constructor */
|
||||
protected OptionDialog(String title, String message, String option1, String option2,
|
||||
String option3, int messageType, Icon icon, boolean addCancel) {
|
||||
super(title, true, false, true, false);
|
||||
|
@ -287,8 +297,6 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
return panel;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void buildButtons(List<String> options, boolean addCancel, String defaultButtonName) {
|
||||
List<JButton> buttons = new ArrayList<>();
|
||||
|
||||
|
@ -340,7 +348,7 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
"No button exists to make default for name: " + defaultButtonName);
|
||||
}
|
||||
|
||||
JButton createOptionButton(String optionName, final int callbackValue) {
|
||||
private JButton createOptionButton(String optionName, final int callbackValue) {
|
||||
int ampLoc = optionName.indexOf('&');
|
||||
char mnemonicKey = '\0';
|
||||
if (ampLoc >= 0 && ampLoc < optionName.length() - 1) {
|
||||
|
@ -375,6 +383,10 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dialog's message to the user
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage() {
|
||||
return dialogMessage;
|
||||
}
|
||||
|
@ -395,6 +407,13 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
//==================================================================================================
|
||||
// Show Option Dialog Methods
|
||||
//==================================================================================================
|
||||
|
||||
/**
|
||||
* A convenience method to create a {@link OptionDialogBuilder}
|
||||
* @param title the dialog title
|
||||
* @param message the dialog message
|
||||
* @return the builder
|
||||
*/
|
||||
public static OptionDialogBuilder createBuilder(String title, String message) {
|
||||
return new OptionDialogBuilder(title, message);
|
||||
}
|
||||
|
@ -439,9 +458,12 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
*/
|
||||
public static int showOptionDialogWithCancelAsDefaultButton(Component parent, String title,
|
||||
String message, String option1) {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, QUESTION_MESSAGE, null, "Cancel");
|
||||
return info.show(parent);
|
||||
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, QUESTION_MESSAGE, null, "Cancel");
|
||||
return info.show(parent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -466,10 +488,14 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
*/
|
||||
public static int showOptionDialogWithCancelAsDefaultButton(Component parent, String title,
|
||||
String message, String option1, int messageType) {
|
||||
|
||||
String defaultButton = option1.equals("Yes") ? "No" : "Cancel";
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, messageType, null, defaultButton);
|
||||
return info.show(parent);
|
||||
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, messageType, null, defaultButton);
|
||||
return info.show(parent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -491,8 +517,11 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
*/
|
||||
public static int showOptionDialog(Component parent, String title, String message,
|
||||
String option1, int messageType) {
|
||||
OptionDialog info = new OptionDialog(title, message, option1, messageType, null);
|
||||
return info.show(parent);
|
||||
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog info = new OptionDialog(title, message, option1, messageType, null);
|
||||
return info.show(parent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -516,9 +545,12 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
*/
|
||||
public static int showOptionDialog(Component parent, String title, String message,
|
||||
String option1, int messageType, String defaultButtonName) {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, messageType, null, defaultButtonName);
|
||||
return info.show(parent);
|
||||
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, messageType, null, defaultButtonName);
|
||||
return info.show(parent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -540,8 +572,11 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
*/
|
||||
public static int showOptionDialog(Component parent, String title, String message,
|
||||
String option1, Icon icon) {
|
||||
OptionDialog info = new OptionDialog(title, message, option1, PLAIN_MESSAGE, icon);
|
||||
return info.show(parent);
|
||||
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog info = new OptionDialog(title, message, option1, PLAIN_MESSAGE, icon);
|
||||
return info.show(parent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -563,9 +598,12 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
*/
|
||||
public static int showOptionDialog(Component parent, String title, String message,
|
||||
String option1, String option2, String option3, int messageType) {
|
||||
OptionDialog dialog =
|
||||
new OptionDialog(title, message, option1, option2, option3, messageType, null, true);
|
||||
return dialog.show(parent);
|
||||
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog dialog = new OptionDialog(title, message, option1, option2, option3,
|
||||
messageType, null, true);
|
||||
return dialog.show(parent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -609,9 +647,12 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
*/
|
||||
public static int showOptionDialog(Component parent, String title, String message,
|
||||
String option1, String option2, int messageType) {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, option2, messageType, null, true);
|
||||
return info.show(parent);
|
||||
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, option2, messageType, null, true);
|
||||
return info.show(parent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -634,9 +675,12 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
*/
|
||||
public static int showOptionDialog(Component parent, String title, String message,
|
||||
String option1, String option2, Icon icon) {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, option2, PLAIN_MESSAGE, icon, true);
|
||||
return info.show(parent);
|
||||
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, option2, PLAIN_MESSAGE, icon, true);
|
||||
return info.show(parent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -659,9 +703,12 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
*/
|
||||
public static int showOptionNoCancelDialog(Component parent, String title, String message,
|
||||
String option1, String option2, int messageType) {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, option2, messageType, null, false);
|
||||
return info.show(parent);
|
||||
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, option2, messageType, null, false);
|
||||
return info.show(parent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -685,9 +732,11 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
public static int showOptionNoCancelDialog(Component parent, String title, String message,
|
||||
String option1, String option2, Icon icon) {
|
||||
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, option2, PLAIN_MESSAGE, icon, false);
|
||||
return info.show();
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, option2, PLAIN_MESSAGE, icon, false);
|
||||
return info.show();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -713,9 +762,11 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
public static int showOptionNoCancelDialog(Component parent, String title, String message,
|
||||
String option1, String option2, String option3, int messageType) {
|
||||
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, option1, option2, option3, messageType, null, false);
|
||||
return info.show();
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog info = new OptionDialog(title, message, option1, option2, option3,
|
||||
messageType, null, false);
|
||||
return info.show();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -725,9 +776,11 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
* @param title The String to be placed in the dialogs title area.
|
||||
* @param message The information message to be displayed in the dialog.
|
||||
* @return The options selected by the user:
|
||||
* <pre>
|
||||
* 0 is returned if the operation is cancelled
|
||||
* 1 for <b>Yes</b>
|
||||
* 2 for <b>No</b>
|
||||
* </pre>
|
||||
*/
|
||||
public static int showYesNoDialog(Component parent, String title, String message) {
|
||||
return showOptionNoCancelDialog(parent, title, message, "&Yes", "&No", QUESTION_MESSAGE);
|
||||
|
@ -747,14 +800,19 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
* @param title The String to be placed in the dialogs title area.
|
||||
* @param message The information message to be displayed in the dialog.
|
||||
* @return The options selected by the user:
|
||||
* <pre>
|
||||
* 1 for <b>Yes</b>
|
||||
* 2 for <b>No</b>
|
||||
* </pre>
|
||||
*/
|
||||
public static int showYesNoDialogWithNoAsDefaultButton(Component parent, String title,
|
||||
String message) {
|
||||
OptionDialog info =
|
||||
new OptionDialog(title, message, "&Yes", "&No", QUESTION_MESSAGE, null, false, "No");
|
||||
return info.show(parent);
|
||||
|
||||
return Swing.runNow(() -> {
|
||||
OptionDialog info = new OptionDialog(title, message, "&Yes", "&No", QUESTION_MESSAGE,
|
||||
null, false, "No");
|
||||
return info.show(parent);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -768,9 +826,11 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
* @param title The String to be placed in the dialogs title area.
|
||||
* @param message The information message to be displayed in the dialog.
|
||||
* @return The options selected by the user:
|
||||
* <pre>
|
||||
* 0 is returned if the operation is cancelled
|
||||
* 1 for the first option
|
||||
* 2 for the second option
|
||||
* </pre>
|
||||
*/
|
||||
public static int showYesNoCancelDialog(Component parent, String title, String message) {
|
||||
return showOptionDialog(parent, title, message, "&Yes", "&No", QUESTION_MESSAGE);
|
||||
|
@ -787,18 +847,22 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
*/
|
||||
public static String showInputSingleLineDialog(Component parent, String title, String label,
|
||||
String initialValue) {
|
||||
InputDialog dialog = new InputDialog(title, label, initialValue, true);
|
||||
|
||||
// Apply similar settings to that of the OptionDialog, for consistency
|
||||
dialog.setRememberLocation(false);
|
||||
dialog.setRememberSize(false);
|
||||
return Swing.runNow(() -> {
|
||||
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
InputDialog dialog = new InputDialog(title, label, initialValue, true);
|
||||
|
||||
if (dialog.isCanceled()) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getValue();
|
||||
// Apply similar settings to that of the OptionDialog, for consistency
|
||||
dialog.setRememberLocation(false);
|
||||
dialog.setRememberSize(false);
|
||||
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
|
||||
if (dialog.isCanceled()) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getValue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -812,14 +876,19 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
*/
|
||||
public static String showInputMultilineDialog(Component parent, String title, String label,
|
||||
String initialValue) {
|
||||
Icon icon = getIconForMessageType(QUESTION_MESSAGE);
|
||||
MultiLineInputDialog dialog = new MultiLineInputDialog(title, label, initialValue, icon);
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
|
||||
if (dialog.isCanceled()) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getValue();
|
||||
return Swing.runNow(() -> {
|
||||
|
||||
Icon icon = getIconForMessageType(QUESTION_MESSAGE);
|
||||
MultiLineInputDialog dialog =
|
||||
new MultiLineInputDialog(title, label, initialValue, icon);
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
|
||||
if (dialog.isCanceled()) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getValue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -839,16 +908,19 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
public static String showInputChoiceDialog(Component parent, String title, String label,
|
||||
String[] selectableValues, String initialValue, int messageType) {
|
||||
|
||||
Icon icon = getIconForMessageType(messageType);
|
||||
return Swing.runNow(() -> {
|
||||
|
||||
InputWithChoicesDialog dialog =
|
||||
new InputWithChoicesDialog(title, label, selectableValues, initialValue, icon);
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
Icon icon = getIconForMessageType(messageType);
|
||||
|
||||
if (dialog.isCanceled()) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getValue();
|
||||
InputWithChoicesDialog dialog =
|
||||
new InputWithChoicesDialog(title, label, selectableValues, initialValue, icon);
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
|
||||
if (dialog.isCanceled()) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getValue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -871,14 +943,17 @@ public class OptionDialog extends DialogComponentProvider {
|
|||
|
||||
Icon icon = getIconForMessageType(messageType);
|
||||
|
||||
InputWithChoicesDialog dialog =
|
||||
new InputWithChoicesDialog(title, label, selectableValues, initialValue, true, icon);
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
return Swing.runNow(() -> {
|
||||
InputWithChoicesDialog dialog = new InputWithChoicesDialog(title, label,
|
||||
selectableValues, initialValue, true, icon);
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
|
||||
if (dialog.isCanceled()) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getValue();
|
||||
if (dialog.isCanceled()) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getValue();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.util.List;
|
|||
|
||||
import javax.swing.Icon;
|
||||
|
||||
import ghidra.util.Swing;
|
||||
|
||||
/**
|
||||
* Class for creating OptionDialogs using the builder pattern.
|
||||
*
|
||||
|
@ -45,8 +47,8 @@ import javax.swing.Icon;
|
|||
* "no" as the defaultOption.
|
||||
*
|
||||
* <P>You can also add a Cancel button, which will return a result of 0 if pressed. Note that this
|
||||
* is different than adding an option named "Cancel" which would return a result > 0, depending
|
||||
* on where in the order it was added.
|
||||
* is different than adding an option named "Cancel" which would return a result greater than
|
||||
* <code>0</code>, depending on where in the order it was added.
|
||||
*
|
||||
* <P><a name="RememberOption"></a>A "Remember Option" can be added to OptionDialog to
|
||||
* present the user with a choice for remembering a dialog result and automatically
|
||||
|
@ -82,9 +84,6 @@ public class OptionDialogBuilder {
|
|||
* this constructor is used, then both {@link #setTitle(String)} and the
|
||||
* {@link #setMessage(String)} methods must be called
|
||||
* or else the dialog will have no title or message.
|
||||
*
|
||||
* @param title the title of the dialog.
|
||||
* @param message the main message to be displayed in the dialog.
|
||||
*/
|
||||
public OptionDialogBuilder() {
|
||||
this(null, null);
|
||||
|
@ -95,8 +94,7 @@ public class OptionDialogBuilder {
|
|||
* this constructor is used, then the {@link #setMessage(String)} method must be called
|
||||
* or else the dialog will be blank.
|
||||
*
|
||||
* @param title the title of the dialog.
|
||||
* @param message the main message to be displayed in the dialog.
|
||||
* @param title the title of the dialog
|
||||
*/
|
||||
public OptionDialogBuilder(String title) {
|
||||
this(title, null);
|
||||
|
@ -243,8 +241,10 @@ public class OptionDialogBuilder {
|
|||
* @return an OptionDialog built based on the values set in this builder.
|
||||
*/
|
||||
public OptionDialog build() {
|
||||
return new OptionDialog(title, message, messageType, icon, addCancelButton,
|
||||
rememberOption, options, defaultOption);
|
||||
return Swing.runNow(() -> {
|
||||
return new OptionDialog(title, message, messageType, icon, addCancelButton,
|
||||
rememberOption, options, defaultOption);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -266,6 +266,7 @@ public class OptionDialogBuilder {
|
|||
if (rememberOption != null && rememberOption.hasRememberedResult()) {
|
||||
return rememberOption.getRememberedResult();
|
||||
}
|
||||
|
||||
OptionDialog dialog = build();
|
||||
dialog.show(parent);
|
||||
return dialog.getResult();
|
||||
|
|
|
@ -85,19 +85,8 @@ public class DefaultClientAuthenticator extends PopupKeyStorePasswordProvider
|
|||
@Override
|
||||
public boolean promptForReconnect(final Component parent, final String message) {
|
||||
|
||||
final boolean[] retVal = new boolean[] { false };
|
||||
|
||||
Runnable r = () -> {
|
||||
String msg = message;
|
||||
if (msg != null) {
|
||||
msg = msg + "\n";
|
||||
}
|
||||
msg = msg + "Do you want to reconnect to the server now?";
|
||||
retVal[0] = OptionDialog.showYesNoDialog(parent, "Lost Connection to Server",
|
||||
message) == OptionDialog.OPTION_ONE;
|
||||
};
|
||||
SystemUtilities.runSwingNow(r);
|
||||
return retVal[0];
|
||||
return OptionDialog.showYesNoDialog(parent, "Lost Connection to Server",
|
||||
message) == OptionDialog.OPTION_ONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.jdom.output.XMLOutputter;
|
|||
import docking.*;
|
||||
import docking.action.DockingAction;
|
||||
import docking.action.MenuData;
|
||||
import docking.widgets.OkDialog;
|
||||
import docking.widgets.OptionDialog;
|
||||
import docking.widgets.dialogs.InputDialog;
|
||||
import docking.widgets.filechooser.GhidraFileChooser;
|
||||
|
@ -369,23 +370,23 @@ public class FrontEndPlugin extends Plugin
|
|||
"\nserver may be forced to close as a result.";
|
||||
// @formatter:on
|
||||
|
||||
OptionDialog info = new OptionDialog("Ghidra Server Error", message,
|
||||
OptionDialog.PLAIN_MESSAGE, DISCONNECTED_ICON);
|
||||
OkDialog info = new OkDialog("Ghidra Server Error", message, DISCONNECTED_ICON);
|
||||
info.show(tool.getToolFrame());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the project manager; try to reopen the last project that was
|
||||
* opened.
|
||||
* @param pm
|
||||
* @param pm the project manager
|
||||
*/
|
||||
void setProjectManager(ProjectManager pm) {
|
||||
this.projectManager = pm;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the handle to the activeProject, as well as updating the
|
||||
* Sets the handle to the activeProject, as well as updating the
|
||||
* active data tree to show the new active project's data
|
||||
* @param project the active project
|
||||
*/
|
||||
void setActiveProject(Project project) {
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ package ghidra.util;
|
|||
|
||||
import java.awt.Component;
|
||||
|
||||
import docking.DockingWindowManager;
|
||||
import docking.widgets.OptionDialog;
|
||||
import ghidra.framework.model.DomainFile;
|
||||
import ghidra.util.exception.VersionException;
|
||||
|
@ -57,16 +56,14 @@ public class VersionExceptionHandler {
|
|||
|
||||
private static void showNeedExclusiveCheckoutDialog(final Component parent, String filename,
|
||||
String contentType, String actionName) {
|
||||
final OptionDialog dialog = new OptionDialog(actionName + " Failed!",
|
||||
|
||||
Msg.showError(VersionExceptionHandler.class, parent, actionName + " Failed!",
|
||||
"Unable to " + actionName + " " + contentType + ": " + filename + "\n \n" +
|
||||
"An upgrade of the " + contentType +
|
||||
" data is required, however, you must have an exclusive checkout\n" +
|
||||
"to upgrade a shared file!\n \n" +
|
||||
"NOTE: If you are unable to obtain an exclusive checkout, you may be able to " +
|
||||
actionName + "\nthe file with an older version of Ghidra.",
|
||||
OptionDialog.ERROR_MESSAGE,
|
||||
OptionDialog.getIconForMessageType(OptionDialog.ERROR_MESSAGE));
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
actionName + "\nthe file with an older version of Ghidra.");
|
||||
}
|
||||
|
||||
private static int showUpgradeDialog(final Component parent, VersionException ve,
|
||||
|
@ -74,28 +71,23 @@ public class VersionExceptionHandler {
|
|||
final String detailMessage =
|
||||
ve.getDetailMessage() == null ? "" : "\n" + ve.getDetailMessage();
|
||||
|
||||
OptionDialog dialog = new OptionDialog("Upgrade " + contentType + " Data? " + filename,
|
||||
"The " + contentType + " file you are attempting to " + actionName +
|
||||
" is an older version." + detailMessage + "\n \n" +
|
||||
"Would you like to Upgrade it now?",
|
||||
"Upgrade", "Cancel", OptionDialog.QUESTION_MESSAGE,
|
||||
OptionDialog.getIconForMessageType(OptionDialog.QUESTION_MESSAGE), false);
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
return dialog.getResult();
|
||||
String title = "Upgrade " + contentType + " Data? " + filename;
|
||||
String message = "The " + contentType + " file you are attempting to " + actionName +
|
||||
" is an older version." + detailMessage + "\n \n" + "Would you like to Upgrade it now?";
|
||||
return OptionDialog.showOptionDialog(parent, title, message, "Upgrade",
|
||||
OptionDialog.QUESTION_MESSAGE);
|
||||
}
|
||||
|
||||
private static int showWarningDialog(final Component parent, String filename,
|
||||
String contentType, String actionName) {
|
||||
final OptionDialog dialog = new OptionDialog(
|
||||
"Upgrade Shared " + contentType + " Data? " + filename,
|
||||
"This " + contentType +
|
||||
" file is shared with other users. If you upgrade this file,\n" +
|
||||
"other users will not be able to read the new version until they upgrade to \n" +
|
||||
"the same version of Ghidra. Do you want to continue?",
|
||||
"Upgrade", "Cancel", OptionDialog.WARNING_MESSAGE,
|
||||
OptionDialog.getIconForMessageType(OptionDialog.WARNING_MESSAGE), false);
|
||||
DockingWindowManager.showDialog(parent, dialog);
|
||||
return dialog.getResult();
|
||||
|
||||
String title = "Upgrade Shared " + contentType + " Data? " + filename;
|
||||
String message = "This " + contentType +
|
||||
" file is shared with other users. If you upgrade this file,\n" +
|
||||
"other users will not be able to read the new version until they upgrade to \n" +
|
||||
"the same version of Ghidra. Do you want to continue?";
|
||||
return OptionDialog.showOptionDialog(parent, title, message, "Upgrade",
|
||||
OptionDialog.WARNING_MESSAGE);
|
||||
}
|
||||
|
||||
public static void showVersionError(final Component parent, final String filename,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue