@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)
//
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;
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;
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;
setJMenuBar(createMenuBar());
setSize(800, 600);
+ UiHelper.setFrameIcon(this);
}
static public ImporterFrame getImporter() {
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}.
this.setSize(600, desc.getHeight() + 0);
this.setUndecorated(undecorated);
+
+ if (!undecorated) {
+ UiHelper.setFrameIcon(this, lib, meta);
+ }
}
@Override
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;
title.setBackground(fg);
titleLabel.setForeground(bg);
titleLabel.setBackground(trans);
+
+ listenables.add(title);
+ listenables.add(titleLabel);
}
// Main panel
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;
root.add(top, BorderLayout.NORTH);
setSize(800, 600);
+ UiHelper.setFrameIcon(this);
}
/**
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;
repaint();
}
});
+
+ UiHelper.setFrameIcon(this);
}
private Component createImportButton(final BasicLibrary lib) {
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;
});
add(navbar, BorderLayout.SOUTH);
+
+ UiHelper.setFrameIcon(this);
}
/**
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;
}
});
}
+
+ 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<List<BufferedImage>, Void>() {
+ @Override
+ protected List<BufferedImage> 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<BufferedImage> resizedImages = new ArrayList<BufferedImage>();
+ 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<BufferedImage> imgs = get();
+ if (imgs != null)
+ win.setIconImages(imgs);
+ } catch (InterruptedException e) {
+ } catch (ExecutionException e) {
+ }
+ }
+ }.execute();
+ }
+
+ static public void setFrameIcon(final Window win) {
+ new SwingWorker<java.awt.Image, Void>() {
+ @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();
+ }
}
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.
initGuiNavButtons();
setChapter(-1);
+
+ UiHelper.setFrameIcon(this);
}
/**
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,
}
/**
/** 32x32 pixels */
x32(32),
/** 64x64 pixels */
- x64(64);
+ x64(64),
+ /** the original size */
+ original(-1);
private int size;
* 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));
}