remember show panels/thumbs mode
authorNiki Roo <niki@nikiroo.be>
Fri, 1 May 2020 21:09:49 +0000 (23:09 +0200)
committerNiki Roo <niki@nikiroo.be>
Fri, 1 May 2020 21:09:49 +0000 (23:09 +0200)
src/be/nikiroo/fanfix/bundles/UiConfig.java
src/be/nikiroo/fanfix_swing/Main.java
src/be/nikiroo/fanfix_swing/gui/BooksPanel.java
src/be/nikiroo/fanfix_swing/gui/MainFrame.java

index dd7bbc7032b4a1b2dfc4b9e29991fd131aeeafad..37d4f0b7d53c7d542783e7d00737c5c1b0975f96 100644 (file)
@@ -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, //
 }
index 91f65fce807adc315bec9a05d0353adaa08d3aa8..ab0b6c6f7ea4b48fac716e3401eb15ad477b8321 100644 (file)
@@ -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);
        }
index def758215ddccb8b2ea0455cd96beefe2a8cbaa1..a2e140c2e6ad477747514fd0f1e0989812c5b45a 100644 (file)
@@ -76,7 +76,7 @@ public class BooksPanel extends ListenerPanel {
 
        private Map<BookInfo, BookLine> books = new HashMap<BookInfo, BookLine>();
        private boolean seeWordCount;
-       private boolean listMode;
+       private boolean showThumbnails;
 
        private JList6<BookInfo> list;
        private ListModel<BookInfo> 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)
index ae5c76fb6ed32f29e411c7e8452db837b6632ddb..7dd0760eff39f4e7188c8e4279bbd11e264694d8 100644 (file)
@@ -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;