From: Niki Roo Date: Fri, 1 May 2020 21:09:49 +0000 (+0200) Subject: remember show panels/thumbs mode X-Git-Tag: fanfix-swing-1.1.0~12 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=2df14f145b10d118fe1d2b28ddb3715b0d7373f8;p=fanfix-swing.git remember show panels/thumbs mode --- diff --git a/src/be/nikiroo/fanfix/bundles/UiConfig.java b/src/be/nikiroo/fanfix/bundles/UiConfig.java index dd7bbc70..37d4f0b7 100644 --- a/src/be/nikiroo/fanfix/bundles/UiConfig.java +++ b/src/be/nikiroo/fanfix/bundles/UiConfig.java @@ -31,7 +31,23 @@ public enum UiConfig { @Meta(description = "The external viewer for non-images documents (or empty to use the system default program for the given file type)",// format = Format.STRING) NON_IMAGES_DOCUMENT_READER, // + // + // GUI settings (hidden in config) + // + @Meta(description = "Show the side panel by default",// + format = Format.BOOLEAN, def = "true") + SHOW_SIDE_PANEL, // + @Meta(description = "Show the details panel by default",// + format = Format.BOOLEAN, def = "true") + SHOW_DETAILS_PANEL, // + @Meta(description = "Show thumbnails by default in the books view",// + format = Format.BOOLEAN, def = "false") + SHOW_THUMBNAILS, // + // + // Deprecated + // @Meta(description = "The background colour of the library if you don't like the default system one",// hidden = true, format = Format.COLOR) + @Deprecated BACKGROUND_COLOR, // } diff --git a/src/be/nikiroo/fanfix_swing/Main.java b/src/be/nikiroo/fanfix_swing/Main.java index 91f65fce..ab0b6c6f 100644 --- a/src/be/nikiroo/fanfix_swing/Main.java +++ b/src/be/nikiroo/fanfix_swing/Main.java @@ -24,7 +24,7 @@ public class Main { UIUtils.setLookAndFeel(); Instance.init(); - JFrame main = new MainFrame(true, true); + JFrame main = new MainFrame(); main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); main.setVisible(true); } diff --git a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java index def75821..a2e140c2 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java @@ -76,7 +76,7 @@ public class BooksPanel extends ListenerPanel { private Map books = new HashMap(); private boolean seeWordCount; - private boolean listMode; + private boolean showThumbnails; private JList6 list; private ListModel data; @@ -89,7 +89,7 @@ public class BooksPanel extends ListenerPanel { private ReloadData lastLoad = new ReloadData(); - public BooksPanel(boolean listMode) { + public BooksPanel(boolean showThumbnails) { setLayout(new BorderLayout()); final SearchBar search = new SearchBar(); @@ -107,7 +107,7 @@ public class BooksPanel extends ListenerPanel { bookCoverUpdater.start(); list = initList(); - setListMode(listMode); + setShowThumbnails(showThumbnails); add(UIUtils.scroll(list, false), BorderLayout.CENTER); } @@ -346,7 +346,7 @@ public class BooksPanel extends ListenerPanel { boolean cellHasFocus) { BookLine book = books.get(value); if (book == null) { - if (listMode) { + if (!showThumbnails) { book = new BookLine(value, seeWordCount); } else { book = new BookBlock(value, seeWordCount); @@ -384,22 +384,22 @@ public class BooksPanel extends ListenerPanel { }); } - public boolean isListMode() { - return listMode; + public boolean isShowThumbnails() { + return showThumbnails; } - public void setListMode(boolean listMode) { - this.listMode = listMode; + public void setShowThumbnails(boolean showThumbnails) { + this.showThumbnails = showThumbnails; books.clear(); list.setLayoutOrientation( - listMode ? JList6.VERTICAL : JList6.HORIZONTAL_WRAP); + showThumbnails ? JList6.HORIZONTAL_WRAP : JList6.VERTICAL); StringBuilder longString = new StringBuilder(); for (int i = 0; i < 20; i++) { longString.append( "Some long string, which is 50 chars long itself..."); } - if (listMode) { + if (!showThumbnails) { bookCoverUpdater.clear(); Dimension sz = new BookLine( BookInfo.fromSource(null, longString.toString()), true) diff --git a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java index ae5c76fb..7dd0760e 100644 --- a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java @@ -5,6 +5,7 @@ import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -42,7 +43,7 @@ public class MainFrame extends JFrame { private boolean detailsPanel; private Runnable onCrumbsbreadChange; - public MainFrame(boolean sidePanel, boolean detailsPanel) { + public MainFrame() { super("Fanfix " + Version.getCurrentVersion()); if (importer == null) { @@ -62,7 +63,8 @@ public class MainFrame extends JFrame { }); browser = new BrowserPanel(); - books = new BooksPanel(true); // TODO: very slow here!! + books = new BooksPanel(Instance.getInstance().getUiConfig() + .getBoolean(UiConfig.SHOW_THUMBNAILS, false)); details = new DetailsPanel(); goBack = new BreadCrumbsPanel(); @@ -123,6 +125,12 @@ public class MainFrame extends JFrame { } }); + // Check config + boolean sidePanel = Instance.getInstance().getUiConfig() + .getBoolean(UiConfig.SHOW_SIDE_PANEL, true); + boolean detailsPanel = Instance.getInstance().getUiConfig() + .getBoolean(UiConfig.SHOW_DETAILS_PANEL, true); + // To force an update this.sidePanel = !sidePanel; this.detailsPanel = !detailsPanel; @@ -235,12 +243,15 @@ public class MainFrame extends JFrame { final JMenuItem mnuListMode = new JCheckBoxMenuItem("Show thumbnails"); mnuListMode.setMnemonic(KeyEvent.VK_T); - mnuListMode.setSelected(!books.isListMode()); + mnuListMode.setSelected(books.isShowThumbnails()); mnuListMode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - books.setListMode(!books.isListMode()); - mnuListMode.setSelected(!books.isListMode()); + boolean newValue = !books.isShowThumbnails(); + books.setShowThumbnails(newValue); + mnuListMode.setSelected(newValue); + + saveConfig(UiConfig.SHOW_THUMBNAILS, newValue); } }); @@ -251,8 +262,11 @@ public class MainFrame extends JFrame { mnuSidePane.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - setSidePanel(!sidePanel); - mnuSidePane.setSelected(sidePanel); + boolean newValue = !sidePanel; + setSidePanel(newValue); + mnuSidePane.setSelected(newValue); + + saveConfig(UiConfig.SHOW_SIDE_PANEL, newValue); } }); @@ -263,8 +277,11 @@ public class MainFrame extends JFrame { mnuDetailsPane.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - setDetailsPanel(!detailsPanel); - mnuDetailsPane.setSelected(detailsPanel); + boolean newValue = !detailsPanel; + setDetailsPanel(newValue); + mnuDetailsPane.setSelected(newValue); + + saveConfig(UiConfig.SHOW_DETAILS_PANEL, newValue); } }); @@ -281,6 +298,16 @@ public class MainFrame extends JFrame { return bar; } + private void saveConfig(UiConfig option, boolean value) { + Instance.getInstance().getUiConfig().setBoolean(option, value); + try { + Instance.getInstance().getUiConfig().updateFile(); + } catch (IOException ioe) { + Instance.getInstance().getTraceHandler().error( + new IOException("Cannot save configuration file", ioe)); + } + } + private void setMode(boolean sidePanel, boolean detailsPanel) { if (this.sidePanel == sidePanel && this.detailsPanel == detailsPanel) { return;