Java源码示例:docking.widgets.OptionDialog
示例1
@Override
public void actionPerformed(ActionContext context) {
int userChoice = OptionDialog.showOptionDialog(listingPanel, "Reset All Formats?",
"There is no undo for this action.\n" +
"Are you sure you want to reset all formats?",
"Continue", OptionDialog.WARNING_MESSAGE);
if (userChoice == OptionDialog.CANCEL_OPTION) {
return;
}
FormatManager listingFormatManager = listingPanel.getFormatManager();
SaveState saveState = new SaveState();
defaultFormatManager.saveState(saveState);
// update the dialog's GUI (which will later be used as the new format if the
// user presses OK)
listingFormatManager.readState(saveState);
}
示例2
@Test
public void testChangeInitState2() throws Exception {
Rectangle rect = table.getCellRect(0, MemoryMapModel.INIT, true);
clickMouse(table, 1, rect.x, rect.y, 2, 0);
waitForPostedSwingRunnables();
OptionDialog dialog = waitForDialogComponent(null, OptionDialog.class, 1000);
assertNotNull(dialog);
invokeInstanceMethod("okCallback", dialog);
waitForPostedSwingRunnables();
waitForBusyTool(tool);
assertEquals(Boolean.FALSE, model.getValueAt(0, MemoryMapModel.INIT));
assertTrue(table.getModel().isCellEditable(0, MemoryMapModel.INIT));
}
示例3
protected ResourceFile chooseSaveAs() {
String title = GhidraScriptEditorComponentProvider.FILE_ON_DISK_CHANGED_TITLE;
OptionDialog fileChangedDialog = waitForDialogComponent(OptionDialog.class);
assertNotNull("Could not find dialog: " + title, fileChangedDialog);
final JButton keepChangesButton = findButtonByText(fileChangedDialog,
GhidraScriptEditorComponentProvider.KEEP_CHANGES_TEXT);
runSwing(() -> keepChangesButton.doClick());
OptionDialog optionDialog = waitForDialogComponent(OptionDialog.class);
assertEquals(GhidraScriptEditorComponentProvider.CHANGE_DESTINATION_TITLE,
optionDialog.getTitle());
final JButton saveAsButton = findButtonByText(optionDialog,
GhidraScriptEditorComponentProvider.SAVE_CHANGES_AS_TEXT);
runSwing(() -> saveAsButton.doClick());
return processSaveAsDialog();
}
示例4
@Override
public void actionPerformed(ActionContext context) {
int choice = OptionDialog.showYesNoDialogWithNoAsDefaultButton(null,
"Confirm Delete Operation", "Are you sure you want to delete selected\n categories " +
"and/or dataTypes?\n(Note: There is no undo for archives.)");
if (choice != OptionDialog.OPTION_ONE) {
return;
}
GTree gtree = (GTree) context.getContextObject();
TreePath[] selectionPaths = gtree.getSelectionPaths();
List<GTreeNode> nodeList = new ArrayList<>(selectionPaths.length);
for (TreePath path : selectionPaths) {
nodeList.add((GTreeNode) path.getLastPathComponent());
}
plugin.getTool().execute(new DataTypeTreeDeleteTask(plugin, nodeList), 250);
}
示例5
@Test
public void testDeleteTool() throws Exception {
// delete a tool from the tool chest
// verify delete menu is updated
// verify "open with" menu is updated
createTool();
DockingActionIf action = getAction("Untitled", "Delete Tool");
assertNotNull(action);
performAction(action, "Untitled", false);
OptionDialog d = waitForDialogComponent(OptionDialog.class);
assertNotNull(d);
assertEquals("Confirm Delete", d.getTitle());
pressButtonByText(d.getComponent(), "Delete");
waitForSwing();
assertNull(getAction("Untitled", "Delete Tool"));
assertNull(getAction("Untitled", "Run Tool"));
assertNull(getAction("Untitled", "Export Tool"));
}
示例6
/**
* Captures the info dialog that is shown when the user attempts to remove an
* equate on a selection.
*
* @throws Exception
*/
@Test
public void testRemoveSelection() throws Exception {
// Place the cursor on a known scalar.
Address addr = program.getMinAddress().getNewAddress(0x0040e00d);
fireOperandFieldLocationEvent(addr, 0);
// Make a selection containing the scalar above.
AddressFactory addressFactory = program.getAddressFactory();
AddressSet addressSet = new AddressSet();
addressSet.addRange(addressFactory.getAddress("0040e00d"),
addressFactory.getAddress("0040e00f"));
ProgramSelection programSelection = new ProgramSelection(addressSet);
tool.firePluginEvent(
new ProgramSelectionPluginEvent("Test Scalar Selection", programSelection, program));
// Call the action to remove the equates from the selection.
performAction(removeAction, cb.getProvider(), false);
// Capture the confirmation dialog.
waitForDialogComponent(OptionDialog.class);
captureDialog(OptionDialog.class);
}
示例7
private Component createRestoreDefaultsButton() {
JButton button = new JButton("Restore Defaults");
button.addActionListener(e -> {
Options currentOptions = getSelectedOptions();
int userChoice = OptionDialog.showOptionDialog(viewPanel, "Restore Defaults?",
"<html>Restore <b>" + HTMLUtilities.escapeHTML(currentOptions.getName()) +
"</b> to default option values <b>and erase current settings?</b>",
"Restore Defaults");
if (userChoice == OptionDialog.CANCEL_OPTION) {
return;
}
restoreDefaultOptionsForCurrentEditor();
});
return button;
}
示例8
@Override
public void actionPerformed(ActionEvent event) {
ComponentProvider provider = placeholder.getProvider();
JComponent component = provider.getComponent();
String currentTabText = provider.getTabText();
String newName = OptionDialog.showInputSingleLineDialog(component, "Rename Tab",
"New name:", currentTabText);
if (newName == null || newName.isEmpty()) {
return; // cancelled
}
// If the user changes the name, then we want to replace all of the
// parts of the title with that name. We skip the subtitle, as that
// doesn't make sense in that case.
provider.setTitle(newName); // title on window
provider.setSubTitle(""); // part after the title
provider.setTabText(newName); // text on the tab
placeholder.update();
}
示例9
@Override
public void actionPerformed(ActionContext context) {
VTMatchContext matchContext = (VTMatchContext) context;
List<VTMatch> matches = matchContext.getSelectedMatches();
if (matches.size() != 1) {
return;
}
VTMatch match = matches.get(0);
VTAssociation association = match.getAssociation();
VTAssociationStatus status = association.getStatus();
if (status != VTAssociationStatus.BLOCKED) {
return;
}
List<VTAssociation> conflicts = getConflictingMatches(match);
String conflictMessage = getConflictingMatchesDisplayString(match, conflicts);
int response = OptionDialog.showOptionDialog(null, "Clear Conflicting Matches and Apply?",
conflictMessage, "Clear and Apply", OptionDialog.QUESTION_MESSAGE);
if (response == OptionDialog.OPTION_ONE) {
ApplyBlockedMatchTask task = new ApplyBlockedMatchTask(controller, match, conflicts);
controller.runVTTask(task);
}
}
示例10
void cancelCallback(boolean force) {
boolean cancel = force;
if (!force) {
int choice =
OptionDialog.showYesNoDialogWithNoAsDefaultButton(null, "Confirm Cancel Merge",
"Warning! Cancel causes the entire merge process to be canceled.\n" +
"Do you want to cancel the Merge Process?");
cancel = choice == OptionDialog.OPTION_ONE;
}
if (cancel) {
wasCanceled = true;
MergeManager mergeManager = plugin.getMergeManager();
if (mergeManager != null) {
mergeManager.cancel();
}
}
}
示例11
@Override
public void handleEclipseError(String error, boolean askAboutOptions, Throwable t) {
if (askAboutOptions && !SystemUtilities.isInHeadlessMode()) {
SystemUtilities.runSwingNow(() -> {
int choice = OptionDialog.showYesNoDialog(null, "Failed to launch Eclipse",
error + "\nWould you like to verify your \"" +
EclipseIntegrationOptionsPlugin.PLUGIN_OPTIONS_NAME + "\" options now?");
if (choice == OptionDialog.YES_OPTION) {
AppInfo.getFrontEndTool().getService(OptionsService.class).showOptionsDialog(
EclipseIntegrationOptionsPlugin.PLUGIN_OPTIONS_NAME, null);
}
});
}
else {
Msg.showError(EclipseConnectorTask.class, null, "Failed to launch Eclipse", error, t);
}
}
示例12
private void issuePreferredDarkThemeLaFNotification() {
if (issuedPreferredDarkThemeLafNotification) {
return;
}
issuedPreferredDarkThemeLafNotification = true;
if (DockingWindowsLookAndFeelUtils.METAL_LOOK_AND_FEEL.equals(selectedLookAndFeel)) {
return;
}
int choice = OptionDialog.showYesNoDialog(null, "Change Look and Feel?", "The '" +
USE_INVERTED_COLORS_NAME + "' setting works best with the " +
"'Metal' Look and Feel.\nWould you like to switch to that Look and Feel upon restart?");
if (choice == OptionDialog.YES_OPTION) {
SystemUtilities.runSwingLater(() -> {
saveLookAndFeel(DockingWindowsLookAndFeelUtils.METAL_LOOK_AND_FEEL);
});
}
}
示例13
boolean removeScriptEditor(ResourceFile script, boolean checkForSave) {
GhidraScriptEditorComponentProvider editor = editorMap.get(script);
if (editor == null) {
return true;
}
if (checkForSave && editor.hasChanges()) {
JComponent parentComponent = getComponent();
if (plugin.getTool().isVisible(editor)) {
parentComponent = editor.getComponent();
}
int result = OptionDialog.showYesNoDialog(parentComponent, getName(),
"'" + script.getName() + "' has been modified. Discard changes?");
if (result != OptionDialog.OPTION_ONE) {
return false;
}
}
plugin.getTool().removeComponentProvider(editor);
editorMap.remove(script);
return true;
}
示例14
/**
* Tests that the user is prompted before attempting to remove an equate within
* a selection.
*
* @throws Exception
*/
@Test
public void testRemoveSelection() throws Exception {
// Place the cursor on a known scalar.
putCursorOnOperand(0x01006455, 1);
// Make a selection containing the scalar above.
makeSelection(tool, program, addr("1004bbd"), addr("1004bc5"));
// Call the action to remove the equate(s).
performAction(removeAction, cb.getProvider(), false);
// Wait for the confirmation dialog to pop up and verify.
OptionDialog d = waitForDialogComponent(tool.getToolFrame(), OptionDialog.class, 2000);
assertNotNull(d);
close(d);
}
示例15
private JPanel buildWorkPanel() {
JPanel panel = new JPanel(new BorderLayout());
String toolName = toolList.get(0).getToolName();
JLabel descriptionLabel = new GHtmlLabel(HTMLUtilities.toHTML(
"There are multiple changed instances of " + HTMLUtilities.escapeHTML(toolName) +
" running.<p>Which one would like to save to your tool chest?"));
descriptionLabel.setIconTextGap(15);
descriptionLabel.setIcon(OptionDialog.getIconForMessageType(OptionDialog.WARNING_MESSAGE));
descriptionLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
panel.add(descriptionLabel, BorderLayout.NORTH);
JScrollPane scrollPane = new JScrollPane(buildRadioButtonPanel());
scrollPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
panel.add(scrollPane);
return panel;
}
示例16
private void saveAs(Program currentProgram, DomainFolder folder, String name) {
DomainFile existingFile = folder.getFile(name);
if (existingFile == currentProgram.getDomainFile()) {
save(currentProgram);
return;
}
if (existingFile != null) {
String msg = "Program " + name + " already exists.\n" + "Do you want to overwrite it?";
if (OptionDialog.showOptionDialog(tool.getToolFrame(), "Duplicate Name", msg,
"Overwrite", OptionDialog.QUESTION_MESSAGE) == OptionDialog.CANCEL_OPTION) {
return;
}
}
tool.prepareToSave(currentProgram);
SaveAsTask task = new SaveAsTask(currentProgram, folder, name, existingFile != null);
new TaskLauncher(task, tool.getToolFrame());
}
示例17
private void clearCertPath() {
String path = ApplicationKeyManagerFactory.getKeyStore();
if (path == null) {
// unexpected
clearCertPathAction.setEnabled(false);
return;
}
if (OptionDialog.YES_OPTION != OptionDialog.showYesNoDialog(tool.getToolFrame(),
"Clear PKI Certificate", "Clear PKI certificate setting?\n(" + path + ")")) {
return;
}
try {
ApplicationKeyManagerFactory.setKeyStore(null, true);
clearCertPathAction.setEnabled(false);
}
catch (IOException e) {
Msg.error(this,
"Error occurred while clearing PKI certificate setting: " + e.getMessage());
}
}
示例18
private JPanel buildMainPanel() {
JPanel innerPanel = new JPanel();
innerPanel.setLayout(new BorderLayout());
innerPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
JPanel msgPanel = new JPanel(new BorderLayout());
msgPanel.add(
new GIconLabel(OptionDialog.getIconForMessageType(OptionDialog.QUESTION_MESSAGE)),
BorderLayout.WEST);
MultiLineLabel msgText = new MultiLineLabel("Checkout selected file(s)?");
msgText.setMaximumSize(msgText.getPreferredSize());
msgPanel.add(msgText, BorderLayout.CENTER);
innerPanel.add(msgPanel, BorderLayout.CENTER);
exclusiveCB = new GCheckBox("Request exclusive checkout");
JPanel cbPanel = new JPanel(new BorderLayout());
cbPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
cbPanel.add(exclusiveCB);
innerPanel.add(cbPanel, BorderLayout.SOUTH);
return innerPanel;
}
示例19
public boolean removeTextFile(TextEditorComponentProvider editor, String textFileName) {
if ( editor.isChanged() ) {
JComponent parentComponent = editor.getComponent();
if ( tool.isVisible( editor ) ) {
parentComponent = editor.getComponent();
}
int result = OptionDialog.showYesNoDialog( parentComponent, getName(),
"'"+textFileName+"' has been modified. Discard changes?");
if (result != OptionDialog.OPTION_ONE) {
return false;
}
}
tool.removeComponentProvider( editor );
editors.remove( editor );
return true;
}
示例20
@Test
public void testRenameFileInUse() throws Exception {
final GTreeNode npNode = rootNode.getChild("notepad");
DomainFile df = ((DomainFileNode) npNode).getDomainFile();
setInUse(df);
setSelectionPath(npNode.getTreePath());
DockingActionIf renameAction = getAction("Rename");
executeOnSwingWithoutBlocking(
() -> performAction(renameAction, getDomainFileActionContext(), true));
waitForSwing();
OptionDialog dlg = waitForDialogComponent(OptionDialog.class);
assertEquals("Rename Not Allowed", dlg.getTitle());
pressButtonByText(dlg.getComponent(), "OK");
assertNotNull(rootNode.getChild("notepad"));
}
示例21
private void showFileInUseDialog(DomainFile file) throws CancelledException {
if (fileInUseDialogBuilder == null) {
//@formatter:off
fileInUseDialogBuilder =
new OptionDialogBuilder("Delete Not Allowed")
.addOption("OK")
.setMessageType(OptionDialog.ERROR_MESSAGE)
.addCancel()
;
//@formatter:on
if (getFileCount() > 1) {
fileInUseDialogBuilder.addDontShowAgainOption();
}
}
String msg =
"The file \"" + file.getName() + "\" is currently in use. It can't \nbe deleted!";
fileInUseDialogBuilder.setMessage(msg);
if (fileInUseDialogBuilder.show(parent) == OptionDialog.CANCEL_OPTION) {
throw new CancelledException();
}
}
示例22
private int showConfirmReadOnlyDialog(DomainFile file) {
if (readOnlyDialogBuilder == null) {
//@formatter:off
readOnlyDialogBuilder =
new OptionDialogBuilder("Confirm Delete Read-only File")
.addOption("Yes")
.addOption("No")
.addCancel()
.setMessageType(OptionDialog.WARNING_MESSAGE)
.setDefaultButton("No")
;
//@formatter:on
if (getFileCount() > 1) {
readOnlyDialogBuilder.addApplyToAllOption();
}
}
String msg = "The file \"" + file.getName() +
"\" is marked as \"Read-Only\". \nAre you sure you want to delete it?";
readOnlyDialogBuilder.setMessage(msg);
return readOnlyDialogBuilder.show(parent);
}
示例23
@Test
public void testEquateTableDeleteCancel() throws Exception {
// select equate TWO
int rowCount = equatesModel.getRowCount();
setRowSelection(equatesTable, 5, 5);
Equate eq = equatesModel.getEquate(5);
assertEquals("TWO", eq.getName());
DockingActionIf pluginAction = getAction(plugin, "Delete Equate");
assertNotNull(pluginAction);
assertTrue(pluginAction.isEnabled());
performAction(pluginAction, false);
OptionDialog d = waitForDialogComponent(tool.getToolFrame(), OptionDialog.class, 2000);
assertNotNull(d);
assertEquals("Delete Equate?", d.getTitle());
pressButtonByText(d.getComponent(), "Cancel");
eq = equatesModel.getEquate(5);
assertEquals("TWO", eq.getName());
assertEquals(rowCount, equatesModel.getRowCount());
}
示例24
private void pressButtonOnOptionDialog(String buttonName) throws Exception {
OptionDialog d =
waitForDialogComponent(tool.getToolFrame(), OptionDialog.class, TASK_TIMEOUT);
assertNotNull(d);
final JButton button = findButtonByText(d, buttonName);
assertNotNull(button);
SwingUtilities.invokeAndWait(() -> button.doClick());
waitForProgram();
}
示例25
@Test
public void testReplaceLanguageFailure() throws Exception {
startSetLanguage(new LanguageID("8051:BE:16:default"), new CompilerSpecID("default"), true);
final OptionDialog errDlg = waitForDialogComponent(OptionDialog.class);
assertNotNull(errDlg);
MultiLineLabel msgLabel = findComponent(errDlg, MultiLineLabel.class);
assertNotNull(msgLabel);
assertTrue(msgLabel.getLabel().indexOf("Language translation not supported") >= 0);
pressButtonByText(errDlg, "OK");
closeAllWindows();
}
示例26
@Override
public void actionPerformed(ActionContext context) {
GTree gTree = (GTree) context.getContextObject();
TreePath[] selectionPaths = gTree.getSelectionPaths();
GTreeNode node = (GTreeNode) selectionPaths[0].getLastPathComponent();
if ((node instanceof ProgramArchiveNode) || (node instanceof ProjectArchiveNode) ||
(node instanceof FileArchiveNode)) {
ArchiveNode archiveNode = (ArchiveNode) node;
Archive archive = archiveNode.getArchive();
if (archive.isModifiable()) {
DataTypeManager dataTypeManager = archive.getDataTypeManager();
DataOrganization dataOrganization = dataTypeManager.getDataOrganization();
int result =
OptionDialog.showOptionDialog(
plugin.getTool().getToolFrame(),
"Align Data Types",
"Are you sure you want to align all of the data types in " +
dataTypeManager.getName() +
"?\nBoth structures and unions that are currently unaligned will become aligned.\n" +
"Do you want to continue?", "Continue", OptionDialog.WARNING_MESSAGE);
if (result == OptionDialog.CANCEL_OPTION) {
return;
}
alignDataTypes(dataTypeManager, dataOrganization);
}
else {
Msg.showWarn(this, gTree, "Alignment Not Allowed",
"The archive must be modifiable to align data types.");
}
}
}
示例27
@Test
public void testCloseEditorWithErrorNoSave() throws Exception {
Enum enummDt = editSampleEnum();
EnumEditorPanel panel = findEditorPanel(tool.getToolFrame());
final JTable table = panel.getTable();
final DockingActionIf deleteAction = getAction(plugin, "Delete Enum Value");
int count = enummDt.getCount();
table.setRowSelectionInterval(count - 1, count - 1);
for (int i = 0; i < count; i++) {
SwingUtilities.invokeAndWait(() -> deleteAction.actionPerformed(new ActionContext()));
waitForPostedSwingRunnables();
}
final ComponentProvider provider =
waitForComponentProvider(tool.getToolFrame(), EnumEditorProvider.class, 1500);
assertNotNull(provider);
SwingUtilities.invokeLater(() -> provider.closeComponent());
waitForPostedSwingRunnables();
OptionDialog d = waitForDialogComponent(tool.getToolFrame(), OptionDialog.class, 2000);
assertNotNull(d);
pressButtonByText(d.getComponent(), "No");
waitForPostedSwingRunnables();
assertTrue(!tool.isVisible(provider));
}
示例28
@Test
public void testConvertProjectFilesCheckedOut() throws Exception {
setErrorGUIEnabled(true); // we need the dialog below
// check-out testA
rootFolder = getProject().getProjectData().getRootFolder();
DomainFile df = rootFolder.getFile("testA");
assertTrue(df.checkout(false, TaskMonitor.DUMMY));
// make simple change to checked-out file
Program p = (Program) df.getDomainObject(this, false, false, TaskMonitor.DUMMY);
try {
int txId = p.startTransaction("test");
try {
p.setName("XYZ");
}
finally {
p.endTransaction(txId, true);
}
p.save(null, TaskMonitor.DUMMY);
}
finally {
p.release(this);
}
pressButtonByText(dialog, ProjectInfoDialog.CONVERT, false);
windowForComponent(dialog.getComponent());
stepThroughWizard(true);
OptionDialog opt = waitForDialogComponent(OptionDialog.class);
assertNotNull(opt);
assertEquals("Confirm Convert Project", opt.getTitle());
pressButtonByText(opt, "Convert");
}
示例29
@Test
public void testDeleteVersionCheckedOut() throws Exception {
// cannot delete a version that is checked out
setErrorGUIEnabled(true);// expect an error dialog
// create 3 versions of the program
doCreateVersions();
final GTreeNode node = getNode(PROGRAM_A);
selectNode(node);
final DockingActionIf historyAction = getAction("Show History");
runSwing(() -> historyAction.actionPerformed(getDomainFileActionContext(node)));
VersionHistoryDialog dialog = waitForDialogComponent(VersionHistoryDialog.class);
DockingActionIf deleteAction = getDeleteAction(dialog);
GTable table = findComponent(dialog, GTable.class);
runSwing(() -> table.selectRow(0));
performAction(deleteAction, false);
// cannot delete a file that is checked out
OptionDialog d = waitForDialogComponent(OptionDialog.class);
assertNotNull(d);
MultiLineLabel label = findComponent(d.getComponent(), MultiLineLabel.class);
assertNotNull(label);
assertEquals("File version has one or more checkouts.", label.getLabel());
runSwing(() -> d.close());
}
示例30
@Test
public void testDeleteVersionNotFirstOrLast() throws Exception {
// can delete only the first or last version of the file
setErrorGUIEnabled(true);// expect an error dialog
doCreateVersions();
final GTreeNode node = getNode(PROGRAM_A);
selectNode(node);
final DockingActionIf historyAction = getAction("Show History");
runSwing(() -> historyAction.actionPerformed(getDomainFileActionContext(node)));
VersionHistoryDialog dialog = waitForDialogComponent(VersionHistoryDialog.class);
DockingActionIf deleteAction = getDeleteAction(dialog);
GTable table = findComponent(dialog, GTable.class);
runSwing(() -> table.selectRow(1));
performAction(deleteAction, false);
// can delete only the first or last version of the file
OptionDialog d = waitForDialogComponent(OptionDialog.class);
assertNotNull(d);
MultiLineLabel label = findComponent(d.getComponent(), MultiLineLabel.class);
assertNotNull(label);
assertEquals("Only first and last version may be deleted.", label.getLabel());
runSwing(() -> {
d.close();
dialog.close();
});
}