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; package org.sleuthkit.autopsy.actions;
import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.HashMap; import java.util.HashMap;
@ -28,9 +29,7 @@ import javax.swing.ActionMap;
import javax.swing.InputMap; import javax.swing.InputMap;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.windows.WindowManager; import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.Case; 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() { public static TagNameAndComment doDialog() {
GetTagNameAndCommentDialog dialog = new GetTagNameAndCommentDialog(); return doDialog(WindowManager.getDefault().getMainWindow());
return dialog.tagNameAndComment;
} }
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"), NbBundle.getMessage(GetTagNameAndCommentDialog.class, "GetTagNameAndCommentDialog.createTag"),
true); ModalityType.APPLICATION_MODAL);
initComponents(); initComponents();
// Set up the dialog to close when Esc is pressed. // Set up the dialog to close when Esc is pressed.
@ -231,7 +255,7 @@ public class GetTagNameAndCommentDialog extends JDialog {
}//GEN-LAST:event_closeDialog }//GEN-LAST:event_closeDialog
private void newTagButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newTagButtonActionPerformed private void newTagButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newTagButtonActionPerformed
TagName newTagName = GetTagNameDialog.doDialog(); TagName newTagName = GetTagNameDialog.doDialog(this);
if (newTagName != null) { if (newTagName != null) {
tagNames.put(newTagName.getDisplayName(), newTagName); tagNames.put(newTagName.getDisplayName(), newTagName);
tagCombo.addItem(newTagName.getDisplayName()); tagCombo.addItem(newTagName.getDisplayName());

View File

@ -18,6 +18,7 @@
*/ */
package org.sleuthkit.autopsy.actions; package org.sleuthkit.autopsy.actions;
import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.ArrayList; import java.util.ArrayList;
@ -29,7 +30,6 @@ import javax.swing.ActionMap;
import javax.swing.InputMap; import javax.swing.InputMap;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
@ -48,15 +48,36 @@ public class GetTagNameDialog extends JDialog {
private final HashMap<String, TagName> tagNames = new HashMap<>(); private final HashMap<String, TagName> tagNames = new HashMap<>();
private TagName tagName = null; 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() { public static TagName doDialog() {
GetTagNameDialog dialog = new GetTagNameDialog(); return doDialog(WindowManager.getDefault().getMainWindow());
return dialog.tagName;
} }
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"), NbBundle.getMessage(GetTagNameDialog.class, "GetTagNameDialog.createTag"),
true); ModalityType.APPLICATION_MODAL);
setIconImage(ImageUtilities.loadImage(TAG_ICON_PATH)); setIconImage(ImageUtilities.loadImage(TAG_ICON_PATH));
initComponents(); initComponents();
@ -68,7 +89,7 @@ public class GetTagNameDialog extends JDialog {
actionMap.put(cancelName, new AbstractAction() { actionMap.put(cancelName, new AbstractAction() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
dispose(); cancelButtonActionPerformed(e);
} }
}); });
@ -97,7 +118,7 @@ public class GetTagNameDialog extends JDialog {
tagsTable.setRowHeight(tagsTable.getRowHeight() + 5); tagsTable.setRowHeight(tagsTable.getRowHeight() + 5);
// Center and show the dialog box. // Center and show the dialog box.
this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow()); this.setLocationRelativeTo(owner);
setVisible(true); setVisible(true);
} }

View File

@ -18,15 +18,19 @@
*/ */
package org.sleuthkit.autopsy.imagegallery.actions; package org.sleuthkit.autopsy.imagegallery.actions;
import java.awt.Window;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.scene.control.Menu; import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
import javax.swing.SwingUtilities; 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.GetTagNameAndCommentDialog;
import org.sleuthkit.autopsy.actions.GetTagNameDialog; import org.sleuthkit.autopsy.actions.GetTagNameDialog;
import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController;
import org.sleuthkit.autopsy.imagegallery.ImageGalleryTopComponent;
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager;
import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TagName;
@ -35,16 +39,16 @@ import org.sleuthkit.datamodel.TagName;
* model objects. * model objects.
* *
* //TODO: this class started as a cut and paste from * //TODO: this class started as a cut and paste from
* org.sleuthkit.autopsy.actions.AddTagAction and needs to be * org.sleuthkit.autopsy.actions.AddTagAction and needs to be refactored or
* refactored or reintegrated to the AddTagAction hierarchy of Autopysy. * reintegrated to the AddTagAction hierarchy of Autopysy.
*/ */
abstract class AddTagAction { abstract class AddTagAction {
protected static final String NO_COMMENT = ""; protected static final String NO_COMMENT = "";
/** /**
* Template method to allow derived classes to provide a string for a * Template method to allow derived classes to provide a string for a menu
* menu item label. * item label.
*/ */
abstract protected String getActionDisplayName(); abstract protected String getActionDisplayName();
@ -76,9 +80,11 @@ abstract class AddTagAction {
Menu quickTagMenu = new Menu("Quick Tag"); Menu quickTagMenu = new Menu("Quick Tag");
getItems().add(quickTagMenu); 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 * 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(); Collection<TagName> tagNames = controller.getTagsManager().getNonCategoryTagNames();
if (tagNames.isEmpty()) { if (tagNames.isEmpty()) {
MenuItem empty = new MenuItem("No tags"); 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 * 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..."); MenuItem newTagMenuItem = new MenuItem("New Tag...");
newTagMenuItem.setOnAction((ActionEvent t) -> { newTagMenuItem.setOnAction((ActionEvent t) -> {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
TagName tagName = GetTagNameDialog.doDialog(); TagName tagName = GetTagNameDialog.doDialog(getIGWindow());
if (tagName != null) { if (tagName != null) {
addTag(tagName, NO_COMMENT); addTag(tagName, NO_COMMENT);
} }
@ -108,14 +116,16 @@ abstract class AddTagAction {
}); });
quickTagMenu.getItems().add(newTagMenuItem); 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 * 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 with an optional comment and adds a tag with the resulting
* name. */ * name.
*/
MenuItem tagAndCommentItem = new MenuItem("Tag and Comment..."); MenuItem tagAndCommentItem = new MenuItem("Tag and Comment...");
tagAndCommentItem.setOnAction((ActionEvent t) -> { tagAndCommentItem.setOnAction((ActionEvent t) -> {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
GetTagNameAndCommentDialog.TagNameAndComment tagNameAndComment = GetTagNameAndCommentDialog.doDialog(); GetTagNameAndCommentDialog.TagNameAndComment tagNameAndComment = GetTagNameAndCommentDialog.doDialog(getIGWindow());
if (null != tagNameAndComment) { if (null != tagNameAndComment) {
if (CategoryManager.isCategoryTagName(tagNameAndComment.getTagName())) { if (CategoryManager.isCategoryTagName(tagNameAndComment.getTagName())) {
new CategorizeAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment()); new CategorizeAction(controller).addTag(tagNameAndComment.getTagName(), tagNameAndComment.getComment());
@ -127,5 +137,14 @@ abstract class AddTagAction {
}); });
getItems().add(tagAndCommentItem); 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);
} }
} }