mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 09:17:42 +00:00
Made filechooser remember selection, fixed some enable/disable bugs, removed tooltips
This commit is contained in:
parent
1741726732
commit
366e784a31
@ -46,6 +46,7 @@ MediaViewImagePanel.errorLabel.OOMText=Could not load file into Media View: insu
|
|||||||
MediaViewImagePanel.errorLabel.text=Could not load file into Media View.
|
MediaViewImagePanel.errorLabel.text=Could not load file into Media View.
|
||||||
MediaViewImagePanel.exportSaveText=Save
|
MediaViewImagePanel.exportSaveText=Save
|
||||||
MediaViewImagePanel.externalViewerButton.text=Open in External Viewer Ctrl+E
|
MediaViewImagePanel.externalViewerButton.text=Open in External Viewer Ctrl+E
|
||||||
|
MediaViewImagePanel.fileChooserTitle=Choose a directory to save the image
|
||||||
MediaViewImagePanel.successfulExport=Tagged image was successfully saved.
|
MediaViewImagePanel.successfulExport=Tagged image was successfully saved.
|
||||||
MediaViewImagePanel.unsuccessfulExport=Unable to export tagged image to disk.
|
MediaViewImagePanel.unsuccessfulExport=Unable to export tagged image to disk.
|
||||||
MediaViewVideoPanel.pauseButton.text=\u25ba
|
MediaViewVideoPanel.pauseButton.text=\u25ba
|
||||||
|
@ -65,6 +65,7 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
import javax.swing.JSeparator;
|
import javax.swing.JSeparator;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.SwingWorker;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.controlsfx.control.MaskerPane;
|
import org.controlsfx.control.MaskerPane;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
@ -121,6 +122,8 @@ class MediaViewImagePanel extends JPanel implements MediaFileViewer.MediaViewPan
|
|||||||
private final JMenuItem hideTags;
|
private final JMenuItem hideTags;
|
||||||
private final JMenuItem exportTags;
|
private final JMenuItem exportTags;
|
||||||
|
|
||||||
|
private final JFileChooser exportChooser;
|
||||||
|
|
||||||
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||||
|
|
||||||
private double zoomRatio;
|
private double zoomRatio;
|
||||||
@ -158,30 +161,31 @@ class MediaViewImagePanel extends JPanel implements MediaFileViewer.MediaViewPan
|
|||||||
public MediaViewImagePanel() {
|
public MediaViewImagePanel() {
|
||||||
initComponents();
|
initComponents();
|
||||||
fxInited = org.sleuthkit.autopsy.core.Installer.isJavaFxInited();
|
fxInited = org.sleuthkit.autopsy.core.Installer.isJavaFxInited();
|
||||||
|
|
||||||
|
exportChooser = new JFileChooser();
|
||||||
|
exportChooser.setDialogTitle(Bundle.MediaViewImagePanel_fileChooserTitle());
|
||||||
|
|
||||||
|
//Build popupMenu when Tags Menu button is pressed.
|
||||||
createTag = new JMenuItem("Create");
|
createTag = new JMenuItem("Create");
|
||||||
createTag.addActionListener((event) -> createTag());
|
createTag.addActionListener((event) -> createTag());
|
||||||
createTag.setToolTipText("You may drag anywhere on the image after selecting this option.");
|
|
||||||
popupMenu.add(createTag);
|
popupMenu.add(createTag);
|
||||||
|
|
||||||
popupMenu.add(new JSeparator()); // SEPARATOR
|
popupMenu.add(new JSeparator());
|
||||||
|
|
||||||
deleteTag = new JMenuItem("Delete");
|
deleteTag = new JMenuItem("Delete");
|
||||||
deleteTag.addActionListener((event) -> deleteTag());
|
deleteTag.addActionListener((event) -> deleteTag());
|
||||||
deleteTag.setToolTipText("Delete the selected tag.");
|
|
||||||
popupMenu.add(deleteTag);
|
popupMenu.add(deleteTag);
|
||||||
|
|
||||||
popupMenu.add(new JSeparator()); // SEPARATOR
|
popupMenu.add(new JSeparator());
|
||||||
|
|
||||||
hideTags = new JMenuItem("Hide");
|
hideTags = new JMenuItem("Hide");
|
||||||
hideTags.addActionListener((event) -> showOrHideTags());
|
hideTags.addActionListener((event) -> showOrHideTags());
|
||||||
hideTags.setToolTipText("Hide the tags on this image.");
|
|
||||||
popupMenu.add(hideTags);
|
popupMenu.add(hideTags);
|
||||||
|
|
||||||
popupMenu.add(new JSeparator()); // SEPARATOR
|
popupMenu.add(new JSeparator());
|
||||||
|
|
||||||
exportTags = new JMenuItem("Export");
|
exportTags = new JMenuItem("Export");
|
||||||
exportTags.addActionListener((event) -> exportTags());
|
exportTags.addActionListener((event) -> exportTags());
|
||||||
exportTags.setToolTipText("Save the image with tags applied.");
|
|
||||||
popupMenu.add(exportTags);
|
popupMenu.add(exportTags);
|
||||||
|
|
||||||
popupMenu.setPopupSize(300, 150);
|
popupMenu.setPopupSize(300, 150);
|
||||||
@ -201,6 +205,8 @@ class MediaViewImagePanel extends JPanel implements MediaFileViewer.MediaViewPan
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Respond to state events by enabling/disabling the correct
|
||||||
|
//buttons.
|
||||||
pcs.addPropertyChangeListener((event) -> {
|
pcs.addPropertyChangeListener((event) -> {
|
||||||
State currentState = (State) event.getNewValue();
|
State currentState = (State) event.getNewValue();
|
||||||
switch (currentState) {
|
switch (currentState) {
|
||||||
@ -265,8 +271,17 @@ class MediaViewImagePanel extends JPanel implements MediaFileViewer.MediaViewPan
|
|||||||
//Update buttons when users select (or unselect) image tags.
|
//Update buttons when users select (or unselect) image tags.
|
||||||
tagsGroup.addFocusChangeListener((event) -> {
|
tagsGroup.addFocusChangeListener((event) -> {
|
||||||
if (event.getPropertyName().equals(ImageTagControls.NOT_FOCUSED.getName())) {
|
if (event.getPropertyName().equals(ImageTagControls.NOT_FOCUSED.getName())) {
|
||||||
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
if (masterGroup.getChildren().contains(imageTagCreator)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tagsGroup.getChildren().isEmpty()) {
|
||||||
|
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
||||||
|
"state", null, State.EMPTY));
|
||||||
|
} else {
|
||||||
|
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
||||||
"state", null, State.CREATE));
|
"state", null, State.CREATE));
|
||||||
|
}
|
||||||
} else if (event.getPropertyName().equals(ImageTagControls.FOCUSED.getName())) {
|
} else if (event.getPropertyName().equals(ImageTagControls.FOCUSED.getName())) {
|
||||||
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
||||||
"state", null, State.SELECTED));
|
"state", null, State.SELECTED));
|
||||||
@ -374,9 +389,9 @@ class MediaViewImagePanel extends JPanel implements MediaFileViewer.MediaViewPan
|
|||||||
List<ContentViewerTag<ImageTagRegion>> contentViewerTags = getContentViewerTags(tags);
|
List<ContentViewerTag<ImageTagRegion>> contentViewerTags = getContentViewerTags(tags);
|
||||||
//Add all image tags
|
//Add all image tags
|
||||||
tagsGroup = buildImageTagsGroup(contentViewerTags);
|
tagsGroup = buildImageTagsGroup(contentViewerTags);
|
||||||
if(!tagsGroup.getChildren().isEmpty()) {
|
if (!tagsGroup.getChildren().isEmpty()) {
|
||||||
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
||||||
"state", null, State.NONEMPTY));
|
"state", null, State.NONEMPTY));
|
||||||
}
|
}
|
||||||
} catch (TskCoreException | NoCurrentCaseException ex) {
|
} catch (TskCoreException | NoCurrentCaseException ex) {
|
||||||
LOGGER.log(Level.WARNING, "Could not retrieve image tags for file in case db", ex); //NON-NLS
|
LOGGER.log(Level.WARNING, "Could not retrieve image tags for file in case db", ex); //NON-NLS
|
||||||
@ -687,7 +702,8 @@ class MediaViewImagePanel extends JPanel implements MediaFileViewer.MediaViewPan
|
|||||||
}//GEN-LAST:event_formComponentResized
|
}//GEN-LAST:event_formComponentResized
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Deletes the selected tag when the Delete button is pressed in the Tag
|
||||||
|
* Menu.
|
||||||
*/
|
*/
|
||||||
private void deleteTag() {
|
private void deleteTag() {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
@ -715,7 +731,8 @@ class MediaViewImagePanel extends JPanel implements MediaFileViewer.MediaViewPan
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Enables create tag logic when the Create button is pressed in the Tags
|
||||||
|
* Menu.
|
||||||
*/
|
*/
|
||||||
private void createTag() {
|
private void createTag() {
|
||||||
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
||||||
@ -791,15 +808,19 @@ class MediaViewImagePanel extends JPanel implements MediaFileViewer.MediaViewPan
|
|||||||
private ContentViewerTag<ImageTagRegion> storeImageTag(ImageTagRegion data, TagNameAndComment result)
|
private ContentViewerTag<ImageTagRegion> storeImageTag(ImageTagRegion data, TagNameAndComment result)
|
||||||
throws TskCoreException, SerializationException, NoCurrentCaseException {
|
throws TskCoreException, SerializationException, NoCurrentCaseException {
|
||||||
scrollPane.setCursor(Cursor.WAIT);
|
scrollPane.setCursor(Cursor.WAIT);
|
||||||
ContentTag contentTag = Case.getCurrentCaseThrows().getServices().getTagsManager()
|
try {
|
||||||
.addContentTag(file, result.getTagName(), result.getComment());
|
ContentTag contentTag = Case.getCurrentCaseThrows().getServices().getTagsManager()
|
||||||
ContentViewerTag<ImageTagRegion> contentViewerTag = ContentViewerTagManager.saveTag(contentTag, data);
|
.addContentTag(file, result.getTagName(), result.getComment());
|
||||||
scrollPane.setCursor(Cursor.DEFAULT);
|
ContentViewerTag<ImageTagRegion> contentViewerTag = ContentViewerTagManager.saveTag(contentTag, data);
|
||||||
return contentViewerTag;
|
return contentViewerTag;
|
||||||
|
} finally {
|
||||||
|
scrollPane.setCursor(Cursor.DEFAULT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Hides or show tags when the Hide or Show button is pressed in the Tags
|
||||||
|
* Menu.
|
||||||
*/
|
*/
|
||||||
private void showOrHideTags() {
|
private void showOrHideTags() {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
@ -809,13 +830,13 @@ class MediaViewImagePanel extends JPanel implements MediaFileViewer.MediaViewPan
|
|||||||
hideTags.setText(DisplayOptions.SHOW_TAGS.getName());
|
hideTags.setText(DisplayOptions.SHOW_TAGS.getName());
|
||||||
tagsGroup.clearFocus();
|
tagsGroup.clearFocus();
|
||||||
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
||||||
"state", null, State.HIDDEN));
|
"state", null, State.HIDDEN));
|
||||||
} else {
|
} else {
|
||||||
//Add tags group back in and update buttons
|
//Add tags group back in and update buttons
|
||||||
masterGroup.getChildren().add(tagsGroup);
|
masterGroup.getChildren().add(tagsGroup);
|
||||||
hideTags.setText(DisplayOptions.HIDE_TAGS.getName());
|
hideTags.setText(DisplayOptions.HIDE_TAGS.getName());
|
||||||
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
pcs.firePropertyChange(new PropertyChangeEvent(this,
|
||||||
"state", null, State.VISIBLE));
|
"state", null, State.VISIBLE));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -823,31 +844,36 @@ class MediaViewImagePanel extends JPanel implements MediaFileViewer.MediaViewPan
|
|||||||
@NbBundle.Messages({
|
@NbBundle.Messages({
|
||||||
"MediaViewImagePanel.exportSaveText=Save",
|
"MediaViewImagePanel.exportSaveText=Save",
|
||||||
"MediaViewImagePanel.successfulExport=Tagged image was successfully saved.",
|
"MediaViewImagePanel.successfulExport=Tagged image was successfully saved.",
|
||||||
"MediaViewImagePanel.unsuccessfulExport=Unable to export tagged image to disk."
|
"MediaViewImagePanel.unsuccessfulExport=Unable to export tagged image to disk.",
|
||||||
|
"MediaViewImagePanel.fileChooserTitle=Choose a directory to save the image"
|
||||||
})
|
})
|
||||||
private void exportTags() {
|
private void exportTags() {
|
||||||
tagsGroup.clearFocus();
|
tagsGroup.clearFocus();
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
exportChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||||
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
int returnVal = exportChooser.showDialog(this, Bundle.MediaViewImagePanel_exportSaveText());
|
||||||
int returnVal = fileChooser.showDialog(this, Bundle.MediaViewImagePanel_exportSaveText());
|
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||||
Platform.runLater(() -> {
|
exportChooser.setCurrentDirectory(exportChooser.getSelectedFile());
|
||||||
try {
|
new SwingWorker<Void, Void>() {
|
||||||
List<ContentTag> tags = Case.getCurrentCase().getServices()
|
@Override
|
||||||
.getTagsManager().getContentTagsByContent(file);
|
protected Void doInBackground() throws Exception {
|
||||||
List<ContentViewerTag<ImageTagRegion>> contentViewerTags = getContentViewerTags(tags);
|
try {
|
||||||
Collection<ImageTagRegion> regions = contentViewerTags.stream()
|
List<ContentTag> tags = Case.getCurrentCase().getServices()
|
||||||
.map(cvTag -> cvTag.getDetails()).collect(Collectors.toList());
|
.getTagsManager().getContentTagsByContent(file);
|
||||||
byte[] jpgImage = ImageTagsUtil.exportTags(file, regions, ".jpg");
|
List<ContentViewerTag<ImageTagRegion>> contentViewerTags = getContentViewerTags(tags);
|
||||||
Path output = Paths.get(fileChooser.getSelectedFile().getPath(),
|
Collection<ImageTagRegion> regions = contentViewerTags.stream()
|
||||||
FilenameUtils.getBaseName(file.getName()) + "-with_tags.jpg");
|
.map(cvTag -> cvTag.getDetails()).collect(Collectors.toList());
|
||||||
Files.write(output, jpgImage);
|
byte[] jpgImage = ImageTagsUtil.exportTags(file, regions, ".jpg");
|
||||||
JOptionPane.showMessageDialog(null, Bundle.MediaViewImagePanel_successfulExport());
|
Path output = Paths.get(exportChooser.getSelectedFile().getPath(),
|
||||||
} catch (TskCoreException | NoCurrentCaseException | IOException ex) {
|
FilenameUtils.getBaseName(file.getName()) + "-with_tags.jpg"); //NON-NLS
|
||||||
LOGGER.log(Level.WARNING, "Unable to export tagged image to disk", ex); //NON-NLS
|
Files.write(output, jpgImage);
|
||||||
JOptionPane.showMessageDialog(null, Bundle.MediaViewImagePanel_unsuccessfulExport());
|
JOptionPane.showMessageDialog(null, Bundle.MediaViewImagePanel_successfulExport());
|
||||||
|
} catch (TskCoreException | NoCurrentCaseException | IOException ex) {
|
||||||
|
LOGGER.log(Level.WARNING, "Unable to export tagged image to disk", ex); //NON-NLS
|
||||||
|
JOptionPane.showMessageDialog(null, Bundle.MediaViewImagePanel_unsuccessfulExport());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
});
|
}.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -873,6 +899,10 @@ class MediaViewImagePanel extends JPanel implements MediaFileViewer.MediaViewPan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Different states that the content viewer can be in. These states drive
|
||||||
|
* which buttons are enabled for tagging.
|
||||||
|
*/
|
||||||
enum State {
|
enum State {
|
||||||
HIDDEN,
|
HIDDEN,
|
||||||
VISIBLE,
|
VISIBLE,
|
||||||
|
@ -52,11 +52,11 @@ public final class ImageTagsGroup extends Group {
|
|||||||
if (currentFocus != null) {
|
if (currentFocus != null) {
|
||||||
currentFocus.getEventDispatcher().dispatchEvent(
|
currentFocus.getEventDispatcher().dispatchEvent(
|
||||||
new Event(ImageTagControls.NOT_FOCUSED), NO_OP_CHAIN);
|
new Event(ImageTagControls.NOT_FOCUSED), NO_OP_CHAIN);
|
||||||
currentFocus = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pcs.firePropertyChange(new PropertyChangeEvent(this,
|
this.pcs.firePropertyChange(new PropertyChangeEvent(this,
|
||||||
ImageTagControls.NOT_FOCUSED.getName(), currentFocus, null));
|
ImageTagControls.NOT_FOCUSED.getName(), currentFocus, null));
|
||||||
|
currentFocus = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
//Set the focus of selected tag
|
//Set the focus of selected tag
|
||||||
|
Loading…
x
Reference in New Issue
Block a user