From 6519e872c282e5326adf4f1072dd1751bbad04e7 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 6 Oct 2013 14:54:43 +0000 Subject: [PATCH] * improve on FormatDialog usability --- .../filebot/resources/action.expand.png | Bin 0 -> 201 bytes .../filebot/ui/rename/FormatDialog.java | 43 ++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 source/net/sourceforge/filebot/resources/action.expand.png diff --git a/source/net/sourceforge/filebot/resources/action.expand.png b/source/net/sourceforge/filebot/resources/action.expand.png new file mode 100644 index 0000000000000000000000000000000000000000..14de2c5c97eb1f42ef887a027424fc7e0b011366 GIT binary patch literal 201 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~k!3HF)wbmE`DaPU;cPEB*=VV?2IV|apzK#qG z8~eHcB(j237I;J!Gca%qfiUBxyLEqnfviEBRU2M#bWmdKI;Vst0J-)$b^rhX literal 0 HcmV?d00001 diff --git a/source/net/sourceforge/filebot/ui/rename/FormatDialog.java b/source/net/sourceforge/filebot/ui/rename/FormatDialog.java index 60bf0d68..e680c5a9 100644 --- a/source/net/sourceforge/filebot/ui/rename/FormatDialog.java +++ b/source/net/sourceforge/filebot/ui/rename/FormatDialog.java @@ -10,9 +10,9 @@ import java.awt.Color; import java.awt.Component; import java.awt.Desktop; import java.awt.Font; +import java.awt.Rectangle; import java.awt.Window; import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.beans.PropertyChangeEvent; @@ -46,7 +46,6 @@ import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; -import javax.swing.KeyStroke; import javax.swing.SwingWorker; import javax.swing.Timer; import javax.swing.border.EmptyBorder; @@ -174,7 +173,8 @@ public class FormatDialog extends JDialog { editorScrollPane.setOpaque(true); content.add(editorScrollPane, "w 120px:min(pref, 420px), h 40px!, growx, wrap 4px, id editor"); - content.add(createImageButton(changeSampleAction), "w 25!, h 19!, pos n editor.y2+1 editor.x2 n"); + content.add(createImageButton(changeSampleAction), "sg action, w 25!, h 19!, pos n editor.y2+1 editor.x2 n"); + content.add(createImageButton(showRecentAction), "sg action, w 25!, h 19!, pos n editor.y2+1 editor.x2-27 n"); content.add(help, "growx, wrap 25px:push"); @@ -208,6 +208,11 @@ public class FormatDialog extends JDialog { // finish dialog and close window manually addWindowListener(new WindowAdapter() { + @Override + public void windowActivated(WindowEvent e) { + revalidate(); + } + @Override public void windowClosing(WindowEvent e) { finish(false); @@ -216,14 +221,6 @@ public class FormatDialog extends JDialog { // install editor suggestions popup editor.setComponentPopupMenu(createRecentFormatPopup()); - TunedUtilities.installAction(editor, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), new AbstractAction("Recent") { - - @Override - public void actionPerformed(ActionEvent evt) { - // display popup below format editor - editor.getComponentPopupMenu().show(editor, 0, editor.getHeight() + 3); - } - }); // episode mode by default setMode(Mode.Episode); @@ -247,7 +244,7 @@ public class FormatDialog extends JDialog { sample = restoreSample(mode); // restore editor state - editor.setText(mode.persistentFormatHistory().isEmpty() ? "" : mode.persistentFormatHistory().get(0)); + setFormatCode(mode.persistentFormatHistory().isEmpty() ? "" : mode.persistentFormatHistory().get(0)); // update examples fireSampleChanged(); @@ -265,6 +262,14 @@ public class FormatDialog extends JDialog { return help; } + public void setFormatCode(String text) { + editor.setText(text); + editor.requestFocusInWindow(); + + editor.scrollRectToVisible(new Rectangle(0, 0)); // reset scroll + editor.setCaretPosition(text.length()); // scroll to end of format + } + private RSyntaxTextArea createEditor() { final RSyntaxTextArea editor = new RSyntaxTextArea(new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_GROOVY) { @Override @@ -341,7 +346,7 @@ public class FormatDialog extends JDialog { @Override public void actionPerformed(ActionEvent e) { - editor.setText(format); + setFormatCode(format); } }); @@ -566,7 +571,7 @@ public class FormatDialog extends JDialog { @Override public void actionPerformed(ActionEvent evt) { - editor.setText(expression); + setFormatCode(expression); } }); @@ -618,6 +623,16 @@ public class FormatDialog extends JDialog { } }; + protected final Action showRecentAction = new AbstractAction("Recent", ResourceManager.getIcon("action.expand")) { + + @Override + public void actionPerformed(ActionEvent evt) { + // display popup below format editor + JComponent c = (JComponent) evt.getSource(); + editor.getComponentPopupMenu().show(c, 0, c.getHeight() + 3); + } + }; + protected final Action cancelAction = new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) { @Override