Merge pull request #1564 from millmanorama/IG_in_front

add versions of doDialog that take a owner window as a paramater and …
This commit is contained in:
Richard Cordovano 2015-09-14 13:29:09 -04:00
commit 018a8acbc8
3 changed files with 92 additions and 28 deletions

View File

@ -18,6 +18,7 @@
*/
package org.sleuthkit.autopsy.actions;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.HashMap;
@ -28,9 +29,7 @@ import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import org.openide.util.NbBundle;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.Case;
@ -65,15 +64,40 @@ public class GetTagNameAndCommentDialog extends JDialog {
}
}
/**
* Show the Tag Name and Comment Dialog and return the TagNameAndContent
* chosen by the user. The dialog will be centered with the main autopsy
* window as its owner. To set another window as the owner use {@link #doDialog(java.awt.Window)
* }
*
* @return a TagNameAndComment instance containing the TagName selected by
* the user and the entered comment, or null if the user canceled
* the dialog.
*/
public static TagNameAndComment doDialog() {
GetTagNameAndCommentDialog dialog = new GetTagNameAndCommentDialog();
return dialog.tagNameAndComment;
return doDialog(WindowManager.getDefault().getMainWindow());
}
private GetTagNameAndCommentDialog() {
super((JFrame) WindowManager.getDefault().getMainWindow(),
/**
* Show the Tag Name and Comment Dialog and return the TagNameAndContent
* chosen by the user.
*
* @param owner the window that will be the owner of the dialog. The dialog
* will be centered over this window and will block the rest of
* the application.
*
* @return a TagNameAndComment instance containg the TagName selected by the
* user and the entered comment, or null if the user canceled the
* dialog.
*/
public static TagNameAndComment doDialog(Window owner) {
return new GetTagNameAndCommentDialog(owner).tagNameAndComment;
}
private GetTagNameAndCommentDialog(Window owner) {
super(owner,
NbBundle.getMessage(GetTagNameAndCommentDialog.class, "GetTagNameAndCommentDialog.createTag"),
true);
ModalityType.APPLICATION_MODAL);
initComponents();
// Set up the dialog to close when Esc is pressed.
@ -231,7 +255,7 @@ public class GetTagNameAndCommentDialog extends JDialog {
}//GEN-LAST:event_closeDialog
private void newTagButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newTagButtonActionPerformed
TagName newTagName = GetTagNameDialog.doDialog();
TagName newTagName = GetTagNameDialog.doDialog(this);
if (newTagName != null) {
tagNames.put(newTagName.getDisplayName(), newTagName);
tagCombo.addItem(newTagName.getDisplayName());

View File

@ -18,6 +18,7 @@
*/
package org.sleuthkit.autopsy.actions;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
@ -29,7 +30,6 @@ import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.table.AbstractTableModel;
@ -48,15 +48,36 @@ public class GetTagNameDialog extends JDialog {
private final HashMap<String, TagName> tagNames = new HashMap<>();
private TagName tagName = null;
/**
* Show the Tag Name Dialog and return the TagName selected by the user. The
* dialog will be centered with the main autopsy window as its owner. To set
* another window as the owner use {@link #doDialog(java.awt.Window) }
*
* @return a TagName instance selected by the user, or null if the user
* canceled the dialog.
*/
public static TagName doDialog() {
GetTagNameDialog dialog = new GetTagNameDialog();
return dialog.tagName;
return doDialog(WindowManager.getDefault().getMainWindow());
}
private GetTagNameDialog() {
super((JFrame) WindowManager.getDefault().getMainWindow(),
/**
* Show the Tag Name Dialog and return the TagName selected by the user.
*
* @param owner the window that will be the owner of the dialog. The dialog
* will be centered over this window and will block the rest of
* the application.
*
* @return a TagName instance selected by the user, or null if the user
* canceled the dialog.
*/
public static TagName doDialog(final Window owner) {
return new GetTagNameDialog(owner).tagName;
}
private GetTagNameDialog(final Window owner) {
super(owner,
NbBundle.getMessage(GetTagNameDialog.class, "GetTagNameDialog.createTag"),
true);
ModalityType.APPLICATION_MODAL);
setIconImage(ImageUtilities.loadImage(TAG_ICON_PATH));
initComponents();
@ -68,7 +89,7 @@ public class GetTagNameDialog extends JDialog {
actionMap.put(cancelName, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
cancelButtonActionPerformed(e);
}
});
@ -97,7 +118,7 @@ public class GetTagNameDialog extends JDialog {
tagsTable.setRowHeight(tagsTable.getRowHeight() + 5);
// Center and show the dialog box.
this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
this.setLocationRelativeTo(owner);
setVisible(true);
}

View File

@ -18,15 +18,19 @@
*/
package org.sleuthkit.autopsy.imagegallery.actions;
import java.awt.Window;
import java.util.Collection;
import java.util.Set;
import javafx.event.ActionEvent;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javax.swing.SwingUtilities;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.actions.GetTagNameAndCommentDialog;
import org.sleuthkit.autopsy.actions.GetTagNameDialog;
import org.sleuthkit.autopsy.imagegallery.ImageGalleryController;
import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent;
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager;
import org.sleuthkit.datamodel.TagName;
@ -35,16 +39,16 @@ import org.sleuthkit.datamodel.TagName;
* model objects.
*
* //TODO: this class started as a cut and paste from
* org.sleuthkit.autopsy.actions.AddTagAction and needs to be
* refactored or reintegrated to the AddTagAction hierarchy of Autopysy.
* org.sleuthkit.autopsy.actions.AddTagAction and needs to be refactored or
* reintegrated to the AddTagAction hierarchy of Autopysy.
*/
abstract class AddTagAction {
protected static final String NO_COMMENT = "";
/**
* Template method to allow derived classes to provide a string for a
* menu item label.
* Template method to allow derived classes to provide a string for a menu
* item label.
*/
abstract protected String getActionDisplayName();
@ -76,9 +80,11 @@ abstract class AddTagAction {
Menu quickTagMenu = new Menu("Quick Tag");
getItems().add(quickTagMenu);
/* Each non-Category tag name in the current set of tags gets its
/*
* Each non-Category tag name in the current set of tags gets its
* own menu item in the "Quick Tags" sub-menu. Selecting one of
* these menu items adds a tag with the associated tag name. */
* these menu items adds a tag with the associated tag name.
*/
Collection<TagName> tagNames = controller.getTagsManager().getNonCategoryTagNames();
if (tagNames.isEmpty()) {
MenuItem empty = new MenuItem("No tags");
@ -94,13 +100,15 @@ abstract class AddTagAction {
}
}
/* The "Quick Tag" menu also gets an "New Tag..." menu item.
/*
* The "Quick Tag" menu also gets an "New Tag..." menu item.
* Selecting this item initiates a dialog that can be used to create
* or select a tag name and adds a tag with the resulting name. */
* or select a tag name and adds a tag with the resulting name.
*/
MenuItem newTagMenuItem = new MenuItem("New Tag...");
newTagMenuItem.setOnAction((ActionEvent t) -> {
SwingUtilities.invokeLater(() -> {
TagName tagName = GetTagNameDialog.doDialog();
TagName tagName = GetTagNameDialog.doDialog(getIGWindow());
if (tagName != null) {
addTag(tagName, NO_COMMENT);
}
@ -108,14 +116,16 @@ abstract class AddTagAction {
});
quickTagMenu.getItems().add(newTagMenuItem);
/* Create a "Tag and Comment..." menu item. Selecting this item
/*
* Create a "Tag and Comment..." menu item. Selecting this item
* initiates a dialog that can be used to create or select a tag
* name with an optional comment and adds a tag with the resulting
* name. */
* name.
*/
MenuItem tagAndCommentItem = new MenuItem("Tag and Comment...");
tagAndCommentItem.setOnAction((ActionEvent t) -> {
SwingUtilities.invokeLater(() -> {
GetTagNameAndCommentDialog.TagNameAndComment tagNameAndComment = GetTagNameAndCommentDialog.doDialog();
GetTagNameAndCommentDialog.TagNameAndComment tagNameAndComment = GetTagNameAndCommentDialog.doDialog(getIGWindow());
if (null != tagNameAndComment) {
if (CategoryManager.isCategoryTagName(tagNameAndComment.getTagName())) {
new CategorizeAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment());
@ -127,5 +137,14 @@ abstract class AddTagAction {
});
getItems().add(tagAndCommentItem);
}
}
/**
* @return the Window containing the ImageGalleryTopComponent
*/
static private Window getIGWindow() {
TopComponent etc = WindowManager.getDefault().findTopComponent(ImageGalleryTopComponent.PREFERRED_ID);
return SwingUtilities.getWindowAncestor(etc);
}
}