From: Niki Roo Date: Sun, 3 May 2020 16:02:17 +0000 (+0200) Subject: frame icons everywhere X-Git-Tag: fanfix-swing-1.1.1~11 X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=e5d9a02ac26d8df169e0d7725e45373ed9ae8552;p=fanfix-swing.git frame icons everywhere --- diff --git a/fanfix-swing.exe b/fanfix-swing.exe index 2b347191..c2fa6152 100755 Binary files a/fanfix-swing.exe and b/fanfix-swing.exe differ diff --git a/src/be/nikiroo/fanfix/bundles/UiConfig.java b/src/be/nikiroo/fanfix/bundles/UiConfig.java index 0f3142d3..2122ccf8 100644 --- a/src/be/nikiroo/fanfix/bundles/UiConfig.java +++ b/src/be/nikiroo/fanfix/bundles/UiConfig.java @@ -31,6 +31,9 @@ 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, // + @Meta(description = "The icon to use for the program",// + format = Format.FIXED_LIST, def = "default", list = { "default", "alternative", "magic-book", "pony-book", "pony-library" }) + PROGRAM_ICON, // // // GUI settings (hidden in config) // diff --git a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java index 5106d89e..7b749ef2 100644 --- a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java @@ -2,6 +2,7 @@ package be.nikiroo.fanfix_swing.gui; import java.awt.BorderLayout; +import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; @@ -19,6 +20,7 @@ import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.bundles.Config; @@ -28,8 +30,13 @@ import be.nikiroo.fanfix.bundles.UiConfigBundle; 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.fanfix_swing.gui.utils.UiHelper; +import be.nikiroo.fanfix_swing.images.IconGenerator; +import be.nikiroo.fanfix_swing.images.IconGenerator.Icon; +import be.nikiroo.fanfix_swing.images.IconGenerator.Size; import be.nikiroo.utils.Version; import be.nikiroo.utils.ui.ConfigEditor; +import be.nikiroo.utils.ui.UIUtils; public class MainFrame extends JFrame { static private ImporterFrame importer; @@ -142,6 +149,7 @@ public class MainFrame extends JFrame { setJMenuBar(createMenuBar()); setSize(800, 600); + UiHelper.setFrameIcon(this); } static public ImporterFrame getImporter() { diff --git a/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java b/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java index f741d69c..163b325e 100644 --- a/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java @@ -10,6 +10,7 @@ import be.nikiroo.fanfix.bundles.StringIdGui; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.fanfix_swing.gui.utils.UiHelper; /** * A frame displaying properties and other information of a {@link Story}. @@ -42,6 +43,10 @@ public class PropertiesFrame extends JDialog { this.setSize(600, desc.getHeight() + 0); this.setUndecorated(undecorated); + + if (!undecorated) { + UiHelper.setFrameIcon(this, lib, meta); + } } @Override diff --git a/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java b/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java index 70d2402a..496b0733 100644 --- a/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java @@ -20,7 +20,6 @@ import javax.swing.border.EmptyBorder; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.library.BasicLibrary; -import be.nikiroo.fanfix.reader.BasicReader; import be.nikiroo.fanfix_swing.Actions; import be.nikiroo.fanfix_swing.gui.book.BookInfo; import be.nikiroo.fanfix_swing.gui.utils.CoverImager; @@ -80,6 +79,9 @@ public class PropertiesPanel extends JPanel { title.setBackground(fg); titleLabel.setForeground(bg); titleLabel.setBackground(trans); + + listenables.add(title); + listenables.add(titleLabel); } // Main panel diff --git a/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java b/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java index bce1bcf7..6b228f61 100644 --- a/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java @@ -23,6 +23,7 @@ import be.nikiroo.fanfix.reader.BasicReader; import be.nikiroo.fanfix.supported.BasicSupport; import be.nikiroo.fanfix_swing.Actions; import be.nikiroo.fanfix_swing.gui.SearchBar; +import be.nikiroo.fanfix_swing.gui.utils.UiHelper; import be.nikiroo.utils.Progress; import be.nikiroo.utils.compat.JList6; import be.nikiroo.utils.ui.ListModel; @@ -90,6 +91,7 @@ public class ImporterFrame extends JFrame implements ListenerItem { root.add(top, BorderLayout.NORTH); setSize(800, 600); + UiHelper.setFrameIcon(this); } /** diff --git a/src/be/nikiroo/fanfix_swing/gui/search/SearchAction.java b/src/be/nikiroo/fanfix_swing/gui/search/SearchAction.java index cfe728b0..301d8a43 100644 --- a/src/be/nikiroo/fanfix_swing/gui/search/SearchAction.java +++ b/src/be/nikiroo/fanfix_swing/gui/search/SearchAction.java @@ -15,6 +15,7 @@ import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.library.BasicLibrary; import be.nikiroo.fanfix_swing.gui.PropertiesPanel; import be.nikiroo.fanfix_swing.gui.book.BookInfo; +import be.nikiroo.fanfix_swing.gui.utils.UiHelper; import be.nikiroo.fanfix_swing.gui.viewer.ViewerPanel; import be.nikiroo.utils.Progress; import be.nikiroo.utils.ui.ProgressBar; @@ -64,6 +65,8 @@ public class SearchAction extends JFrame { repaint(); } }); + + UiHelper.setFrameIcon(this); } private Component createImportButton(final BasicLibrary lib) { diff --git a/src/be/nikiroo/fanfix_swing/gui/search/SearchFrame.java b/src/be/nikiroo/fanfix_swing/gui/search/SearchFrame.java index a28ae92d..6b679494 100644 --- a/src/be/nikiroo/fanfix_swing/gui/search/SearchFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/search/SearchFrame.java @@ -22,6 +22,7 @@ import be.nikiroo.fanfix.searchable.SearchableTag; import be.nikiroo.fanfix.supported.SupportType; import be.nikiroo.fanfix_swing.gui.book.BookInfo; import be.nikiroo.fanfix_swing.gui.search.GRBook.BookActionListener; +import be.nikiroo.fanfix_swing.gui.utils.UiHelper; import be.nikiroo.fanfix_swing.gui.viewer.NavBar; import be.nikiroo.utils.ui.UIUtils; @@ -164,6 +165,8 @@ public class SearchFrame extends JFrame { }); add(navbar, BorderLayout.SOUTH); + + UiHelper.setFrameIcon(this); } /** diff --git a/src/be/nikiroo/fanfix_swing/gui/utils/UiHelper.java b/src/be/nikiroo/fanfix_swing/gui/utils/UiHelper.java index 7cc0a3d2..05cbdc01 100644 --- a/src/be/nikiroo/fanfix_swing/gui/utils/UiHelper.java +++ b/src/be/nikiroo/fanfix_swing/gui/utils/UiHelper.java @@ -2,12 +2,28 @@ package be.nikiroo.fanfix_swing.gui.utils; import java.awt.Color; import java.awt.Component; +import java.awt.Dimension; +import java.awt.Window; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.bundles.UiConfig; +import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.fanfix_swing.images.IconGenerator; +import be.nikiroo.fanfix_swing.images.IconGenerator.Icon; +import be.nikiroo.fanfix_swing.images.IconGenerator.Size; +import be.nikiroo.utils.Image; +import be.nikiroo.utils.ui.ImageUtilsAwt; +import be.nikiroo.utils.ui.ImageUtilsAwt.Rotation; public class UiHelper { static private Color buttonNormal; @@ -61,4 +77,74 @@ public class UiHelper { } }); } + + static public void setFrameIcon(final Window win, final Image img) { + setFrameIcon(win, null, new MetaData() { + @Override + public Image getCover() { + return img; + } + }); + } + + static public void setFrameIcon(final Window win, final BasicLibrary lib, + final MetaData meta) { + new SwingWorker, Void>() { + @Override + protected List doInBackground() throws Exception { + Image img = meta == null ? null : meta.getCover(); + if (img == null && meta != null && lib != null) { + img = lib.getCover(meta.getLuid()); + } + + if (img == null) { + return null; + } + + BufferedImage image = ImageUtilsAwt.fromImage(img, + Rotation.NONE); + boolean zoomSnapWidth = image.getWidth() >= image.getHeight(); + + List resizedImages = new ArrayList(); + for (int size : new Integer[] { 16, 20, 64, 400 }) { + resizedImages.add( + ImageUtilsAwt.scaleImage(new Dimension(size, size), + image, -1, zoomSnapWidth)); + } + + return resizedImages; + } + + @Override + protected void done() { + try { + List imgs = get(); + if (imgs != null) + win.setIconImages(imgs); + } catch (InterruptedException e) { + } catch (ExecutionException e) { + } + } + }.execute(); + } + + static public void setFrameIcon(final Window win) { + new SwingWorker() { + @Override + protected java.awt.Image doInBackground() throws Exception { + String iconName = Instance.getInstance().getUiConfig() + .getString(UiConfig.PROGRAM_ICON); + Icon icon = Icon.valueOf("icon_" + iconName.replace("-", "_")); + return IconGenerator.get(icon, Size.original).getImage(); + } + + @Override + protected void done() { + try { + win.setIconImage(get()); + } catch (Exception e) { + } + } + }.execute(); + } } diff --git a/src/be/nikiroo/fanfix_swing/gui/viewer/Viewer.java b/src/be/nikiroo/fanfix_swing/gui/viewer/Viewer.java index 7c7e09ad..1e5fb29a 100644 --- a/src/be/nikiroo/fanfix_swing/gui/viewer/Viewer.java +++ b/src/be/nikiroo/fanfix_swing/gui/viewer/Viewer.java @@ -20,6 +20,7 @@ import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.library.BasicLibrary; import be.nikiroo.fanfix_swing.gui.PropertiesPanel; +import be.nikiroo.fanfix_swing.gui.utils.UiHelper; /** * An internal, Swing-based {@link Story} viewer. @@ -63,6 +64,8 @@ public class Viewer extends JFrame { initGuiNavButtons(); setChapter(-1); + + UiHelper.setFrameIcon(this); } /** diff --git a/src/be/nikiroo/fanfix_swing/images/IconGenerator.java b/src/be/nikiroo/fanfix_swing/images/IconGenerator.java index c8d126a8..00677745 100644 --- a/src/be/nikiroo/fanfix_swing/images/IconGenerator.java +++ b/src/be/nikiroo/fanfix_swing/images/IconGenerator.java @@ -37,6 +37,16 @@ public class IconGenerator { arrow_down, /** An empty (transparent) icon */ empty, + /** An icon for the program */ + icon_default, + /** An icon for the program */ + icon_alternate, + /** An icon for the program */ + icon_magic_book, + /** An icon for the program */ + icon_pony_book, + /** An icon for the program */ + icon_pony_library, } /** @@ -56,7 +66,9 @@ public class IconGenerator { /** 32x32 pixels */ x32(32), /** 64x64 pixels */ - x64(64); + x64(64), + /** the original size */ + original(-1); private int size; @@ -88,8 +100,14 @@ public class IconGenerator { * size */ static public ImageIcon get(Icon name, Size size) { - String key = String.format("%s-%dx%d.png", name.name(), size.getSize(), - size.getSize()); + String key; + if (size.getSize() > 0) { + key = String.format("%s-%dx%d.png", name.name(), size.getSize(), + size.getSize()); + } else { + key = name.name() + ".png"; + } + if (!map.containsKey(key)) { map.put(key, generate(key)); } diff --git a/src/be/nikiroo/fanfix_swing/images/icon_alternative-16x16.png b/src/be/nikiroo/fanfix_swing/images/icon_alternative-16x16.png new file mode 100644 index 00000000..2b48ca24 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_alternative-16x16.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_alternative-24x24.png b/src/be/nikiroo/fanfix_swing/images/icon_alternative-24x24.png new file mode 100644 index 00000000..bd7a4fb4 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_alternative-24x24.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_alternative-32x32.png b/src/be/nikiroo/fanfix_swing/images/icon_alternative-32x32.png new file mode 100644 index 00000000..438f3e90 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_alternative-32x32.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_alternative-64x64.png b/src/be/nikiroo/fanfix_swing/images/icon_alternative-64x64.png new file mode 100644 index 00000000..4196418d Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_alternative-64x64.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_alternative-8x8.png b/src/be/nikiroo/fanfix_swing/images/icon_alternative-8x8.png new file mode 100644 index 00000000..f3c2fc1b Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_alternative-8x8.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_alternative.png b/src/be/nikiroo/fanfix_swing/images/icon_alternative.png new file mode 100644 index 00000000..4ab09577 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_alternative.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_default-16x16.png b/src/be/nikiroo/fanfix_swing/images/icon_default-16x16.png new file mode 100644 index 00000000..8435bc54 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_default-16x16.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_default-24x24.png b/src/be/nikiroo/fanfix_swing/images/icon_default-24x24.png new file mode 100644 index 00000000..6e3f9fed Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_default-24x24.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_default-32x32.png b/src/be/nikiroo/fanfix_swing/images/icon_default-32x32.png new file mode 100644 index 00000000..f9ff8e20 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_default-32x32.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_default-64x64.png b/src/be/nikiroo/fanfix_swing/images/icon_default-64x64.png new file mode 100644 index 00000000..85b794e3 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_default-64x64.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_default-8x8.png b/src/be/nikiroo/fanfix_swing/images/icon_default-8x8.png new file mode 100644 index 00000000..f86c8a10 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_default-8x8.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_default.png b/src/be/nikiroo/fanfix_swing/images/icon_default.png new file mode 100644 index 00000000..983b3440 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_default.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_magic_book-16x16.png b/src/be/nikiroo/fanfix_swing/images/icon_magic_book-16x16.png new file mode 100644 index 00000000..3e21113c Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_magic_book-16x16.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_magic_book-24x24.png b/src/be/nikiroo/fanfix_swing/images/icon_magic_book-24x24.png new file mode 100644 index 00000000..026eff66 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_magic_book-24x24.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_magic_book-32x32.png b/src/be/nikiroo/fanfix_swing/images/icon_magic_book-32x32.png new file mode 100644 index 00000000..538487dc Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_magic_book-32x32.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_magic_book-64x64.png b/src/be/nikiroo/fanfix_swing/images/icon_magic_book-64x64.png new file mode 100644 index 00000000..a71cabfa Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_magic_book-64x64.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_magic_book-8x8.png b/src/be/nikiroo/fanfix_swing/images/icon_magic_book-8x8.png new file mode 100644 index 00000000..b8e480d2 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_magic_book-8x8.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_magic_book.png b/src/be/nikiroo/fanfix_swing/images/icon_magic_book.png new file mode 100644 index 00000000..1798dd32 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_magic_book.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_book-16x16.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_book-16x16.png new file mode 100644 index 00000000..e94836c3 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_book-16x16.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_book-24x24.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_book-24x24.png new file mode 100644 index 00000000..4ebba1d4 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_book-24x24.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_book-32x32.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_book-32x32.png new file mode 100644 index 00000000..86f3d8be Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_book-32x32.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_book-64x64.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_book-64x64.png new file mode 100644 index 00000000..cbbe6ede Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_book-64x64.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_book-8x8.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_book-8x8.png new file mode 100644 index 00000000..cadd1ef5 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_book-8x8.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_book.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_book.png new file mode 100644 index 00000000..fb6fe0d3 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_book.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_library-16x16.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_library-16x16.png new file mode 100644 index 00000000..6af4357a Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_library-16x16.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_library-24x24.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_library-24x24.png new file mode 100644 index 00000000..3f2cd395 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_library-24x24.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_library-32x32.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_library-32x32.png new file mode 100644 index 00000000..6f433751 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_library-32x32.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_library-64x64.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_library-64x64.png new file mode 100644 index 00000000..d2dd2d9f Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_library-64x64.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_library-8x8.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_library-8x8.png new file mode 100644 index 00000000..af19fa0f Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_library-8x8.png differ diff --git a/src/be/nikiroo/fanfix_swing/images/icon_pony_library.png b/src/be/nikiroo/fanfix_swing/images/icon_pony_library.png new file mode 100644 index 00000000..a56a4d29 Binary files /dev/null and b/src/be/nikiroo/fanfix_swing/images/icon_pony_library.png differ