add Boook Search menu, disable Browser tab before loaded
authorNiki Roo <niki@nikiroo.be>
Tue, 28 Apr 2020 12:28:57 +0000 (14:28 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 28 Apr 2020 12:28:57 +0000 (14:28 +0200)
src/be/nikiroo/fanfix_swing/gui/BrowserTab.java
src/be/nikiroo/fanfix_swing/gui/MainFrame.java
src/be/nikiroo/fanfix_swing/gui/SearchBar.java
src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java
src/be/nikiroo/fanfix_swing/gui/utils/CoverImager.java

index a55a2df8a41930612c81838f0d8dfae32cd99487..1f605937079ed6d28d32249cd10b6a58a82cda85 100644 (file)
@@ -6,12 +6,10 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Date;
 import java.util.List;
 
 import javax.swing.JTree;
-import javax.swing.SwingUtilities;
-import javax.swing.SwingWorker;
+import javax.swing.UIManager;
 import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
 import javax.swing.plaf.basic.BasicTreeUI;
@@ -63,6 +61,10 @@ public class BrowserTab extends ListenerPanel {
                treeListener = new TreeSelectionListener() {
                        @Override
                        public void valueChanged(TreeSelectionEvent e) {
+                               tree.setBackground(UIManager.getColor("Tree.background"));
+                               tree.setEnabled(true);
+                               searchBar.setEnabled(true);
+
                                List<String> elements = new ArrayList<String>();
                                TreePath[] paths = tree.getSelectionPaths();
                                if (paths != null) {
@@ -120,6 +122,10 @@ public class BrowserTab extends ListenerPanel {
                                filter(true);
                        }
                });
+
+               tree.setBackground(UIManager.getColor("Tree.disabled"));
+               tree.setEnabled(false);
+               searchBar.setEnabled(false);
        }
 
        public void filter(final boolean fireActionPerformed) {
index efd3000634ee427bd2564c668ed71413a7ff4496..ae5c76fb6ed32f29e411c7e8452db837b6632ddb 100644 (file)
@@ -25,6 +25,7 @@ import be.nikiroo.fanfix.bundles.StringIdGui;
 import be.nikiroo.fanfix.bundles.UiConfig;
 import be.nikiroo.fanfix_swing.gui.book.BookInfo;
 import be.nikiroo.fanfix_swing.gui.importer.ImporterFrame;
+import be.nikiroo.fanfix_swing.gui.search.SearchFrame;
 import be.nikiroo.utils.Version;
 import be.nikiroo.utils.ui.ConfigEditor;
 
@@ -181,8 +182,20 @@ public class MainFrame extends JFrame {
                        }
                });
 
+               // TODO: un-beta it
+               JMenuItem mnuSearch = new JMenuItem("Find a book (EARLY BETA)",
+                               KeyEvent.VK_F);
+               mnuSearch.addActionListener(new ActionListener() {
+                       @Override
+                       public void actionPerformed(ActionEvent e) {
+                               new SearchFrame(Instance.getInstance().getLibrary())
+                                               .setVisible(true);
+                       }
+               });
+
                file.add(mnuDownload);
                file.add(mnuImprtFile);
+               file.add(mnuSearch);
 
                // EDIT
 
@@ -336,4 +349,8 @@ public class MainFrame extends JFrame {
                        }
                });
        }
+
+       static public String trans(StringIdGui id, Object... values) {
+               return Instance.getInstance().getTransGui().getString(id, values);
+       }
 }
index 76fb2a7411dbd96fd677d34d8f14ec9495ec5de9..88c2dc29b08f61d02f796e2b60dbdc1c178222a0 100644 (file)
@@ -37,7 +37,8 @@ public class SearchBar extends ListenerPanel {
        public SearchBar() {
                setLayout(new BorderLayout());
 
-               // TODO: option for this
+               // TODO: make an option to change the default setting here:
+               // (can already be manually toggled by the user)
                realTime = true;
 
                search = new JButton(IconGenerator.get(Icon.search, Size.x16));
@@ -112,4 +113,12 @@ public class SearchBar extends ListenerPanel {
                String text = this.text.getText();
                return text == null ? "" : text;
        }
+
+       @Override
+       public void setEnabled(boolean enabled) {
+               search.setEnabled(enabled);
+               clear.setEnabled(enabled);
+               text.setEnabled(enabled);
+               super.setEnabled(enabled);
+       }
 }
index 6e515768c550bfe09369581a6f812a58ac0a4012..195c908ba8e1a9aed2f8e07f408ab94e6dd2608d 100644 (file)
@@ -19,6 +19,7 @@ import be.nikiroo.fanfix.library.BasicLibrary.Status;
 import be.nikiroo.fanfix.library.MetaResultList;
 import be.nikiroo.fanfix_swing.gui.BooksPanelActions;
 import be.nikiroo.fanfix_swing.gui.BooksPanelActions.ChangeAction;
+import be.nikiroo.fanfix_swing.gui.MainFrame;
 import be.nikiroo.fanfix_swing.gui.utils.UiHelper;
 
 public class BookPopup extends JPopupMenu {
@@ -110,8 +111,8 @@ public class BookPopup extends JPopupMenu {
         * @return the item
         */
        private JMenuItem createMenuItemExport() {
-               JMenuItem export = new JMenuItem(trans(StringIdGui.MENU_FILE_EXPORT),
-                               KeyEvent.VK_S);
+               JMenuItem export = new JMenuItem(
+                               MainFrame.trans(StringIdGui.MENU_FILE_EXPORT), KeyEvent.VK_S);
                export.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -129,7 +130,8 @@ public class BookPopup extends JPopupMenu {
         */
        private JMenuItem createMenuItemClearCache() {
                JMenuItem refresh = new JMenuItem(
-                               trans(StringIdGui.MENU_EDIT_CLEAR_CACHE), KeyEvent.VK_C);
+                               MainFrame.trans(StringIdGui.MENU_EDIT_CLEAR_CACHE),
+                               KeyEvent.VK_C);
                refresh.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -151,11 +153,12 @@ public class BookPopup extends JPopupMenu {
                        groupedSources = new HashMap<String, List<String>>();
                }
 
-               JMenu changeTo = new JMenu(trans(StringIdGui.MENU_FILE_MOVE_TO));
+               JMenu changeTo = new JMenu(
+                               MainFrame.trans(StringIdGui.MENU_FILE_MOVE_TO));
                changeTo.setMnemonic(KeyEvent.VK_M);
 
                JMenuItem item = new JMenuItem(
-                               trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_TYPE));
+                               MainFrame.trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_TYPE));
                item.addActionListener(createMoveAction(ChangeAction.SOURCE, null));
                changeTo.add(item);
                changeTo.addSeparator();
@@ -200,12 +203,13 @@ public class BookPopup extends JPopupMenu {
                        groupedAuthors = new HashMap<String, List<String>>();
                }
 
-               JMenu changeTo = new JMenu(trans(StringIdGui.MENU_FILE_SET_AUTHOR));
+               JMenu changeTo = new JMenu(
+                               MainFrame.trans(StringIdGui.MENU_FILE_SET_AUTHOR));
                changeTo.setMnemonic(KeyEvent.VK_A);
 
                // New author
                JMenuItem newItem = new JMenuItem(
-                               trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_AUTHOR));
+                               MainFrame.trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_AUTHOR));
                changeTo.add(newItem);
                changeTo.addSeparator();
                newItem.addActionListener(createMoveAction(ChangeAction.AUTHOR, null));
@@ -216,7 +220,7 @@ public class BookPopup extends JPopupMenu {
                                JMenu group = new JMenu(key);
                                for (String value : groupedAuthors.get(key)) {
                                        JMenuItem item = new JMenuItem(value.isEmpty()
-                                                       ? trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+                                                       ? MainFrame.trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
                                                        : value);
                                        item.addActionListener(
                                                        createMoveAction(ChangeAction.AUTHOR, value));
@@ -227,7 +231,7 @@ public class BookPopup extends JPopupMenu {
                } else if (groupedAuthors.size() == 1) {
                        for (String value : groupedAuthors.values().iterator().next()) {
                                JMenuItem item = new JMenuItem(value.isEmpty()
-                                               ? trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+                                               ? MainFrame.trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
                                                : value);
                                item.addActionListener(
                                                createMoveAction(ChangeAction.AUTHOR, value));
@@ -244,7 +248,8 @@ public class BookPopup extends JPopupMenu {
         * @return the item
         */
        private JMenuItem createMenuItemRename() {
-               JMenuItem changeTo = new JMenuItem(trans(StringIdGui.MENU_FILE_RENAME));
+               JMenuItem changeTo = new JMenuItem(
+                               MainFrame.trans(StringIdGui.MENU_FILE_RENAME));
                changeTo.setMnemonic(KeyEvent.VK_R);
                changeTo.addActionListener(createMoveAction(ChangeAction.TITLE, null));
                return changeTo;
@@ -267,7 +272,8 @@ public class BookPopup extends JPopupMenu {
         */
        private JMenuItem createMenuItemRedownload() {
                JMenuItem refresh = new JMenuItem(
-                               trans(StringIdGui.MENU_EDIT_REDOWNLOAD), KeyEvent.VK_R);
+                               MainFrame.trans(StringIdGui.MENU_EDIT_REDOWNLOAD),
+                               KeyEvent.VK_R);
                refresh.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -285,7 +291,8 @@ public class BookPopup extends JPopupMenu {
         */
        private JMenuItem createMenuItemDownloadToCache() {
                JMenuItem refresh = new JMenuItem(
-                               trans(StringIdGui.MENU_EDIT_DOWNLOAD_TO_CACHE), KeyEvent.VK_T);
+                               MainFrame.trans(StringIdGui.MENU_EDIT_DOWNLOAD_TO_CACHE),
+                               KeyEvent.VK_T);
                refresh.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -302,8 +309,8 @@ public class BookPopup extends JPopupMenu {
         * @return the item
         */
        private JMenuItem createMenuItemDelete() {
-               JMenuItem delete = new JMenuItem(trans(StringIdGui.MENU_EDIT_DELETE),
-                               KeyEvent.VK_D);
+               JMenuItem delete = new JMenuItem(
+                               MainFrame.trans(StringIdGui.MENU_EDIT_DELETE), KeyEvent.VK_D);
                delete.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -321,7 +328,8 @@ public class BookPopup extends JPopupMenu {
         */
        private JMenuItem createMenuItemProperties() {
                JMenuItem delete = new JMenuItem(
-                               trans(StringIdGui.MENU_FILE_PROPERTIES), KeyEvent.VK_P);
+                               MainFrame.trans(StringIdGui.MENU_FILE_PROPERTIES),
+                               KeyEvent.VK_P);
                delete.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -338,8 +346,8 @@ public class BookPopup extends JPopupMenu {
         * @return the item
         */
        public JMenuItem createMenuItemOpenBook() {
-               JMenuItem open = new JMenuItem(trans(StringIdGui.MENU_FILE_OPEN),
-                               KeyEvent.VK_O);
+               JMenuItem open = new JMenuItem(
+                               MainFrame.trans(StringIdGui.MENU_FILE_OPEN), KeyEvent.VK_O);
                open.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -358,7 +366,7 @@ public class BookPopup extends JPopupMenu {
         */
        private JMenuItem createMenuItemSetCoverForSource() {
                JMenuItem open = new JMenuItem(
-                               trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_SOURCE),
+                               MainFrame.trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_SOURCE),
                                KeyEvent.VK_C);
                open.addActionListener(new ActionListener() {
                        @Override
@@ -378,7 +386,7 @@ public class BookPopup extends JPopupMenu {
         */
        private JMenuItem createMenuItemSetCoverForAuthor() {
                JMenuItem open = new JMenuItem(
-                               trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_AUTHOR),
+                               MainFrame.trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_AUTHOR),
                                KeyEvent.VK_A);
                open.addActionListener(new ActionListener() {
                        @Override
@@ -389,8 +397,4 @@ public class BookPopup extends JPopupMenu {
 
                return open;
        }
-
-       static private String trans(StringIdGui id, Object... values) {
-               return Instance.getInstance().getTransGui().getString(id, values);
-       }
 }
index 93df707a276290f5046935ee4647c44f99b5b525..fc80f6991ab53583ee00bbce5ecf8273ec65ca9e 100644 (file)
@@ -77,12 +77,12 @@ public class CoverImager {
        }
 
        /**
-        * Generate a cover icon based upon the given {@link GuiReaderBookInfo}.
+        * Generate a cover icon based upon the given {@link BookInfo}.
         * 
         * @param lib
         *            the library the meta comes from (can be NULL)
         * @param info
-        *            the {@link GuiReaderBookInfo}
+        *            the {@link BookInfo}
         * 
         * @return the image
         */
@@ -167,8 +167,8 @@ public class CoverImager {
        }
 
        /**
-        * Get a unique ID from this {@link GuiReaderBookInfo} (note that it can be
-        * a story, a fake item for a source/type or a fake item for an author).
+        * Get a unique ID from this {@link BookInfo} (note that it can be a story,
+        * a fake item for a source/type or a fake item for an author).
         * 
         * @param info
         *            the info or NULL for a generic (non unique!) ID