From 8a234bc588abca837b82044c5ae086091a995677 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 28 Apr 2020 14:28:57 +0200 Subject: [PATCH] add Boook Search menu, disable Browser tab before loaded --- .../nikiroo/fanfix_swing/gui/BrowserTab.java | 12 +++-- .../nikiroo/fanfix_swing/gui/MainFrame.java | 17 +++++++ .../nikiroo/fanfix_swing/gui/SearchBar.java | 11 +++- .../fanfix_swing/gui/book/BookPopup.java | 50 ++++++++++--------- .../fanfix_swing/gui/utils/CoverImager.java | 8 +-- 5 files changed, 67 insertions(+), 31 deletions(-) diff --git a/src/be/nikiroo/fanfix_swing/gui/BrowserTab.java b/src/be/nikiroo/fanfix_swing/gui/BrowserTab.java index a55a2df8..1f605937 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BrowserTab.java +++ b/src/be/nikiroo/fanfix_swing/gui/BrowserTab.java @@ -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 elements = new ArrayList(); 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) { diff --git a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java index efd30006..ae5c76fb 100644 --- a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java @@ -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); + } } diff --git a/src/be/nikiroo/fanfix_swing/gui/SearchBar.java b/src/be/nikiroo/fanfix_swing/gui/SearchBar.java index 76fb2a74..88c2dc29 100644 --- a/src/be/nikiroo/fanfix_swing/gui/SearchBar.java +++ b/src/be/nikiroo/fanfix_swing/gui/SearchBar.java @@ -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); + } } diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java b/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java index 6e515768..195c908b 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java @@ -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>(); } - 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>(); } - 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); - } } diff --git a/src/be/nikiroo/fanfix_swing/gui/utils/CoverImager.java b/src/be/nikiroo/fanfix_swing/gui/utils/CoverImager.java index 93df707a..fc80f699 100644 --- a/src/be/nikiroo/fanfix_swing/gui/utils/CoverImager.java +++ b/src/be/nikiroo/fanfix_swing/gui/utils/CoverImager.java @@ -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 -- 2.27.0