import java.awt.Window;
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
+import java.util.LinkedHashMap;
+import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingWorker;
-import org.jsoup.helper.DataUtil;
-import org.jsoup.nodes.Document;
-import org.jsoup.nodes.Element;
-
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.StringIdGui;
import be.nikiroo.fanfix.bundles.UiConfig;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.library.BasicLibrary;
import be.nikiroo.fanfix.library.LocalLibrary;
-import be.nikiroo.fanfix.reader.BasicReader;
import be.nikiroo.fanfix_swing.gui.book.BookInfo;
import be.nikiroo.fanfix_swing.gui.utils.CoverImager;
import be.nikiroo.fanfix_swing.gui.utils.UiHelper;
import be.nikiroo.fanfix_swing.gui.viewer.Viewer;
import be.nikiroo.utils.Progress;
+import be.nikiroo.utils.StringUtils;
public class Actions {
static public void openBook(final BasicLibrary lib, MetaData meta,
pg = new Progress();
try {
- Instance.getInstance().getLibrary()
- .imprt(BasicReader.getUrl(url), pg);
-
+ Instance.getInstance().getLibrary().imprt(getUrl(url), pg);
pg.done();
if (onSuccess != null) {
onSuccess.run();
}
}.execute();
}
+
+ /**
+ * Return an {@link URL} from this {@link String}, be it a file path or an
+ * actual {@link URL}.
+ *
+ * @param sourceString
+ * the source
+ *
+ * @return the corresponding {@link URL}
+ *
+ * @throws MalformedURLException
+ * if this is neither a file nor a conventional {@link URL}
+ */
+ static public URL getUrl(String sourceString) throws MalformedURLException {
+ if (sourceString == null || sourceString.isEmpty()) {
+ throw new MalformedURLException("Empty url");
+ }
+
+ URL source = null;
+ try {
+ source = new URL(sourceString);
+ } catch (MalformedURLException e) {
+ File sourceFile = new File(sourceString);
+ source = sourceFile.toURI().toURL();
+ }
+
+ return source;
+ }
+
+ /**
+ * Describe a {@link Story} from its {@link MetaData} and return a list of
+ * title/value that represent this {@link Story}.
+ *
+ * @param meta
+ * the {@link MetaData} to represent
+ *
+ * @return the information
+ */
+ static public Map<String, String> getMetaDesc(MetaData meta) {
+ Map<String, String> metaDesc = new LinkedHashMap<String, String>();
+
+ // TODO: i18n
+
+ StringBuilder tags = new StringBuilder();
+ for (String tag : meta.getTags()) {
+ if (tags.length() > 0) {
+ tags.append(", ");
+ }
+ tags.append(tag);
+ }
+
+ // TODO: i18n
+ metaDesc.put("Author", meta.getAuthor());
+ metaDesc.put("Published on", meta.getPublisher());
+ metaDesc.put("Publication date", meta.getDate());
+ metaDesc.put("Creation date", meta.getCreationDate());
+ String count = "";
+ if (meta.getWords() > 0) {
+ count = StringUtils.formatNumber(meta.getWords());
+ }
+ if (meta.isImageDocument()) {
+ metaDesc.put("Number of images", count);
+ } else {
+ metaDesc.put("Number of words", count);
+ }
+ metaDesc.put("Source", meta.getSource());
+ metaDesc.put("Subject", meta.getSubject());
+ metaDesc.put("Language", meta.getLang());
+ metaDesc.put("Tags", tags.toString());
+ metaDesc.put("URL", meta.getUrl());
+
+ return metaDesc;
+ }
}
MetaData meta = book == null ? null : book.getMeta();
if (meta != null) {
PropertiesFrame tooltip = new PropertiesFrame(
- Instance.getInstance().getLibrary(), meta);
- tooltip.setUndecorated(undecorated);
+ Instance.getInstance().getLibrary(), meta,
+ undecorated);
return tooltip;
}
/** Change its author. */
AUTHOR
}
-
+
private Container owner;
private Informer informer;
MainFrame.getImporter().imprt(owner, book.getMeta().getUrl());
}
}
-
+
public void export() {
// TODO: allow dir for multiple selection?
}
}
}
-
+
/**
* Create a {@link FileFilter} that accepts all files and return the given
* description.
}
};
}
-
+
public void clearCache() {
final List<BookInfo> selected = informer.getSelected();
if (!selected.isEmpty()) {
informer.setCached(book, false);
}
} catch (Exception e) {
- UiHelper.error(owner,
- e.getLocalizedMessage(), "IOException",
- e);
+ UiHelper.error(owner, e.getLocalizedMessage(),
+ "IOException", e);
}
}
}.execute();
}
}
- Object rep = JOptionPane.showInputDialog(
- owner,
+ Object rep = JOptionPane.showInputDialog(owner,
trans(StringIdGui.SUBTITLE_MOVE_TO),
trans(StringIdGui.TITLE_MOVE_TO),
JOptionPane.QUESTION_MESSAGE, null, null, init);
// the cache above
get();
} catch (Exception e) {
- UiHelper.error(owner,
- e.getLocalizedMessage(), "IOException",
- e);
+ UiHelper.error(owner, e.getLocalizedMessage(),
+ "IOException", e);
}
}
}.execute();
}
}
-
+
public void prefetch() {
final List<BookInfo> selected = informer.getSelected();
luid = book.getMeta().getLuid();
break;
case SOURCE:
- for (MetaData meta : lib.getList().filter(
- book.getMainInfo(), null, null)) {
+ for (MetaData meta : lib.getList()
+ .filter(book.getMainInfo(), null, null)) {
luid = meta.getLuid();
}
break;
}
break;
case TAG:
- for (MetaData meta : lib.getList().filter(null,
- null, book.getMainInfo())) {
+ for (MetaData meta : lib.getList().filter(null, null,
+ book.getMainInfo())) {
luid = meta.getLuid();
}
break;
try {
get();
} catch (Exception e) {
- UiHelper.error(owner,
- e.getLocalizedMessage(), "IOException", e);
+ UiHelper.error(owner, e.getLocalizedMessage(),
+ "IOException", e);
}
}
}.execute();
}
-
+
public void properties() {
BasicLibrary lib = Instance.getInstance().getLibrary();
BookInfo selected = informer.getUniqueSelected();
if (selected != null) {
- new PropertiesFrame(lib, selected.getMeta())
+ new PropertiesFrame(lib, selected.getMeta(), false)
.setVisible(true);
}
}
-
+
public void setCoverFor(final ChangeAction what) {
final BookInfo book = informer.getUniqueSelected();
if (book != null) {
}.execute();
}
}
-
+
static private String trans(StringIdGui id, Object... values) {
return Instance.getInstance().getTransGui().getString(id, values);
}
* the library to use for the cover image
* @param meta
* the meta to describe
+ * @param undecorated
+ * do not draw the usual window decorations
+ * (close/minimize/maximize)
*/
- public PropertiesFrame(BasicLibrary lib, MetaData meta) {
+ public PropertiesFrame(BasicLibrary lib, MetaData meta,
+ boolean undecorated) {
setTitle(MainFrame.trans(StringIdGui.TITLE_STORY, meta.getLuid(),
meta.getTitle()));
- desc = new PropertiesPanel(lib, meta);
+ desc = new PropertiesPanel(lib, meta, undecorated);
setLayout(new BorderLayout());
add(desc, BorderLayout.NORTH);
+ this.setUndecorated(undecorated);
this.setSize(600, desc.getHeight() + 0);
}
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
+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;
import be.nikiroo.utils.ui.UIUtils;
* the library to use for the cover image
* @param meta
* the meta to describe
+ * @param includeTitle
+ * TRUE to include the title on top
*/
- public PropertiesPanel(BasicLibrary lib, MetaData meta) {
+ public PropertiesPanel(BasicLibrary lib, MetaData meta,
+ boolean includeTitle) {
listenables = new ArrayList<Component>();
+ Color trans = new Color(0, 0, 0, 1);
+
// Image
ImageIcon img = new ImageIcon(CoverImager.generateCoverImage(lib,
BookInfo.fromMeta(lib, meta)));
setLayout(new BorderLayout());
+ // Title
+ JPanel title = null;
+ if (includeTitle) {
+ title = new JPanel(new BorderLayout());
+ JTextArea titleLabel = new JTextArea(
+ meta.getLuid() + ": " + meta.getTitle());
+ titleLabel.setEditable(false);
+ titleLabel.setLineWrap(true);
+ titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD));
+ titleLabel.setOpaque(false);
+ titleLabel.setFocusable(false);
+ titleLabel.setBorder(new EmptyBorder(3, 3, 3, 3));
+ titleLabel.setAlignmentY(JLabel.CENTER_ALIGNMENT);
+ title.add(titleLabel);
+ Color fg = new JLabel("dummy").getForeground();
+ Color bg = title.getBackground();
+ title.setForeground(bg);
+ title.setBackground(fg);
+ titleLabel.setForeground(bg);
+ titleLabel.setBackground(trans);
+ }
+
// Main panel
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel mainPanelKeys = new JPanel();
mainPanel.add(UIUtils.scroll(mainPanelValues, true, false),
BorderLayout.CENTER);
- Map<String, String> desc = BasicReader.getMetaDesc(meta);
-
- Color trans = new Color(0, 0, 0, 1);
+ Map<String, String> desc = Actions.getMetaDesc(meta);
for (String key : desc.keySet()) {
JTextArea jKey = new JTextArea(key);
jKey.setFont(new Font(jKey.getFont().getFontName(), Font.BOLD,
BorderFactory.createEmptyBorder(0, space, space + hscroll, 0));
// Add all
+ if (includeTitle)
+ add(title, BorderLayout.NORTH);
add(imgLabel, BorderLayout.WEST);
add(mainPanel, BorderLayout.CENTER);
Progress pg = new Progress();
String basename = null;
try {
- BasicSupport support = BasicSupport
- .getSupport(BasicReader.getUrl(url));
+ BasicSupport support = BasicSupport.getSupport(Actions.getUrl(url));
basename = support.getType().getSourceName();
} catch (Exception e) {
basename = "unknown website";