import be.nikiroo.utils.Progress;
public class Actions {
- static public void openExternal(final BasicLibrary lib, MetaData meta, final Container parent,
- final Runnable onDone) {
+ static public void openExternal(final BasicLibrary lib, MetaData meta,
+ final Container parent, final Runnable onDone) {
Container parentWindow = parent;
while (!(parentWindow instanceof Window) && parentWindow != null) {
parentWindow = parentWindow.getParent();
openExternal(target, isImageDocument);
} catch (Exception e) {
// TODO: i18n
- UiHelper.error(parent, e.getLocalizedMessage(), "Cannot open the story", e);
+ UiHelper.error(parent, e.getLocalizedMessage(),
+ "Cannot open the story", e);
}
synchronized (waitLock) {
}
/**
- * Open the {@link Story} with an external reader (the program will be passed
- * the given target file).
+ * Open the {@link Story} with an external reader (the program will be
+ * passed the given target file).
*
- * @param target the target {@link File}
- * @param isImageDocument TRUE for image documents, FALSE for not-images
- * documents
+ * @param target
+ * the target {@link File}
+ * @param isImageDocument
+ * TRUE for image documents, FALSE for not-images documents
*
- * @throws IOException in case of I/O error
+ * @throws IOException
+ * in case of I/O error
*/
- static public void openExternal(File target, boolean isImageDocument) throws IOException {
+ static public void openExternal(File target, boolean isImageDocument)
+ throws IOException {
String program = null;
if (isImageDocument) {
- program = Instance.getInstance().getUiConfig().getString(UiConfig.IMAGES_DOCUMENT_READER);
+ program = Instance.getInstance().getUiConfig()
+ .getString(UiConfig.IMAGES_DOCUMENT_READER);
} else {
- program = Instance.getInstance().getUiConfig().getString(UiConfig.NON_IMAGES_DOCUMENT_READER);
+ program = Instance.getInstance().getUiConfig()
+ .getString(UiConfig.NON_IMAGES_DOCUMENT_READER);
}
if (program != null && program.trim().isEmpty()) {
}
/**
- * Start a file and open it with the given program if given or the first default
- * system starter we can find.
+ * Start a file and open it with the given program if given or the first
+ * default system starter we can find.
*
- * @param target the target to open
- * @param program the program to use or NULL for the default system starter
- * @param sync execute the process synchronously (wait until it is terminated
- * before returning)
+ * @param target
+ * the target to open
+ * @param program
+ * the program to use or NULL for the default system starter
+ * @param sync
+ * execute the process synchronously (wait until it is terminated
+ * before returning)
*
- * @throws IOException in case of I/O error
+ * @throws IOException
+ * in case of I/O error
*/
- static protected void start(File target, String program, boolean sync) throws IOException {
+ static protected void start(File target, String program, boolean sync)
+ throws IOException {
Process proc = null;
if (program == null) {
boolean ok = false;
- for (String starter : new String[] { "xdg-open", "open", "see", "start", "run" }) {
+ for (String starter : new String[] { "xdg-open", "open", "see",
+ "start", "run" }) {
try {
- Instance.getInstance().getTraceHandler().trace("starting external program");
- proc = Runtime.getRuntime().exec(new String[] { starter, target.getAbsolutePath() });
+ Instance.getInstance().getTraceHandler()
+ .trace("starting external program");
+ proc = Runtime.getRuntime().exec(
+ new String[] { starter, target.getAbsolutePath() });
ok = true;
break;
} catch (IOException e) {
}
}
if (!ok) {
- throw new IOException("Cannot find a program to start the file");
+ throw new IOException(
+ "Cannot find a program to start the file");
}
} else {
- Instance.getInstance().getTraceHandler().trace("starting external program");
- proc = Runtime.getRuntime().exec(new String[] { program, target.getAbsolutePath() });
+ Instance.getInstance().getTraceHandler()
+ .trace("starting external program");
+ proc = Runtime.getRuntime()
+ .exec(new String[] { program, target.getAbsolutePath() });
}
if (proc != null && sync) {
* <p>
* Should be called inside the UI thread.
*
- * @param askUrl TRUE for an {@link URL}, false for a {@link File}
+ * @param askUrl
+ * TRUE for an {@link URL}, false for a {@link File}
*/
- static public void imprt(final Container parent, boolean askUrl, final Runnable onSuccess) {
+ static public void imprt(final Container parent, boolean askUrl,
+ final Runnable onSuccess) {
JFileChooser fc = new JFileChooser();
Object url;
if (askUrl) {
String clipboard = "";
try {
- clipboard = ("" + Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor))
- .trim();
+ clipboard = ("" + Toolkit.getDefaultToolkit()
+ .getSystemClipboard().getData(DataFlavor.stringFlavor))
+ .trim();
} catch (Exception e) {
// No data will be handled
}
}
url = JOptionPane.showInputDialog(parent,
- Instance.getInstance().getTransGui().getString(StringIdGui.SUBTITLE_IMPORT_URL),
- Instance.getInstance().getTransGui().getString(StringIdGui.TITLE_IMPORT_URL),
+ Instance.getInstance().getTransGui()
+ .getString(StringIdGui.SUBTITLE_IMPORT_URL),
+ Instance.getInstance().getTransGui()
+ .getString(StringIdGui.TITLE_IMPORT_URL),
JOptionPane.QUESTION_MESSAGE, null, null, clipboard);
} else if (fc.showOpenDialog(parent) != JFileChooser.CANCEL_OPTION) {
url = fc.getSelectedFile().getAbsolutePath();
* <p>
* Should be called inside the UI thread.
*
- * @param url the {@link Story} to import by {@link URL}
- * @param onSuccess Action to execute on success
- * @param onSuccessPgName the name to use for the onSuccess progress bar
+ * @param url
+ * the {@link Story} to import by {@link URL}
+ * @param onSuccess
+ * Action to execute on success
+ * @param onSuccessPgName
+ * the name to use for the onSuccess progress bar
*/
- static public void imprt(final Container parent, final String url, final Runnable onSuccess,
- String onSuccessPgName) {
+ static public void imprt(final Container parent, final String url,
+ final Runnable onSuccess, String onSuccessPgName) {
final Progress pg = new Progress();
final Progress pgImprt = new Progress();
final Progress pgOnSuccess = new Progress(onSuccessPgName);
Exception ex = null;
MetaData meta = null;
try {
- meta = Instance.getInstance().getLibrary().imprt(BasicReader.getUrl(url), pgImprt);
+ meta = Instance.getInstance().getLibrary()
+ .imprt(BasicReader.getUrl(url), pgImprt);
} catch (IOException e) {
e.printStackTrace();
ex = e;
if (!ok) {
if (e instanceof UnknownHostException) {
UiHelper.error(parent,
- Instance.getInstance().getTransGui().getString(StringIdGui.ERROR_URL_NOT_SUPPORTED,
+ Instance.getInstance().getTransGui().getString(
+ StringIdGui.ERROR_URL_NOT_SUPPORTED,
url),
- Instance.getInstance().getTransGui().getString(StringIdGui.TITLE_ERROR), null);
+ Instance.getInstance().getTransGui().getString(
+ StringIdGui.TITLE_ERROR),
+ null);
} else {
UiHelper.error(parent,
- Instance.getInstance().getTransGui().getString(StringIdGui.ERROR_URL_IMPORT_FAILED, url,
- e.getMessage()),
- Instance.getInstance().getTransGui().getString(StringIdGui.TITLE_ERROR), e);
+ Instance.getInstance().getTransGui().getString(
+ StringIdGui.ERROR_URL_IMPORT_FAILED,
+ url, e.getMessage()),
+ Instance.getInstance().getTransGui()
+ .getString(StringIdGui.TITLE_ERROR),
+ e);
}
} else {
if (onSuccess != null) {
}
}
pgOnSuccess.done();
-
+
return null;
}
}.execute();
@Override
public DataLoader getCache() {
if (cache == null) {
- cache = new DataLoader(getConfig().getString(Config.NETWORK_USER_AGENT));
+ cache = new DataLoader(getConfig()
+ .getString(Config.NETWORK_USER_AGENT));
}
return cache;
/**
* The {@link ActionEvent} you receive from
- * {@link BrowserPanel#addActionListener(ActionListener)} can return this as a
- * command (see {@link ActionEvent#getActionCommand()}) if they were created in
- * the scope of a source.
+ * {@link BrowserPanel#addActionListener(ActionListener)} can return this as
+ * a command (see {@link ActionEvent#getActionCommand()}) if they were
+ * created in the scope of a source.
*/
static public final String SOURCE_SELECTION = "source_selection";
/**
* The {@link ActionEvent} you receive from
- * {@link BrowserPanel#addActionListener(ActionListener)} can return this as a
- * command (see {@link ActionEvent#getActionCommand()}) if they were created in
- * the scope of an author.
+ * {@link BrowserPanel#addActionListener(ActionListener)} can return this as
+ * a command (see {@link ActionEvent#getActionCommand()}) if they were
+ * created in the scope of an author.
*/
static public final String AUTHOR_SELECTION = "author_selection";
/**
* The {@link ActionEvent} you receive from
- * {@link BrowserPanel#addActionListener(ActionListener)} can return this as a
- * command (see {@link ActionEvent#getActionCommand()}) if they were created in
- * the scope of a tag.
+ * {@link BrowserPanel#addActionListener(ActionListener)} can return this as
+ * a command (see {@link ActionEvent#getActionCommand()}) if they were
+ * created in the scope of a tag.
*/
static public final String TAGS_SELECTION = "tags_selection";
/**
* The {@link ActionEvent} you receive from
- * {@link BrowserPanel#addActionListener(ActionListener)} can return this as a
- * command (see {@link ActionEvent#getActionCommand()}) if they were created in
- * the scope of a tab change.
+ * {@link BrowserPanel#addActionListener(ActionListener)} can return this as
+ * a command (see {@link ActionEvent#getActionCommand()}) if they were
+ * created in the scope of a tab change.
*/
static public final String TAB_CHANGE = "tab_change";
}
}
- private void configureTab(JTabbedPane tabs, @SuppressWarnings("rawtypes") BasicTab tab, String name,
+ private void configureTab(JTabbedPane tabs,
+ @SuppressWarnings("rawtypes") BasicTab tab, String name,
String tooltip) {
tab.setBaseTitle(name);
tabs.setTitleAt(tab.getIndex(), tab.getTitle());
listenTabs(tabs, tab);
}
- private void listenTabs(final JTabbedPane tabs, @SuppressWarnings("rawtypes") final BasicTab tab) {
+ private void listenTabs(final JTabbedPane tabs,
+ @SuppressWarnings("rawtypes") final BasicTab tab) {
tab.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
* Get the {@link BookInfo} to highlight, even if none or more than one are
* selected.
* <p>
- * Return a special "all" {@link BookInfo} of the correct type when nothing is
- * selected.
+ * Return a special "all" {@link BookInfo} of the correct type when nothing
+ * is selected.
*
* @return the {@link BookInfo} to highlight, can be NULL
*/
Component selectedTab = tabs.getSelectedComponent();
if (selectedTab instanceof BasicTab) {
@SuppressWarnings({ "unchecked", "rawtypes" })
- List<String> selectedAll = ((BasicTab) selectedTab).getSelectedElements();
+ List<String> selectedAll = ((BasicTab) selectedTab)
+ .getSelectedElements();
if (!selectedAll.isEmpty()) {
selected1 = selectedAll.get(0);
}
/**
* Configure a {@link JLabel} with the given colour.
*
- * @param label the label to configure
- * @param color the colour to use
+ * @param label
+ * the label to configure
+ * @param color
+ * the colour to use
*
* @return the (same) configured label
*/
/**
* Set the {@link BookInfo} you want to see displayed here.
*
- * @param info the {@link BookInfo} to display
+ * @param info
+ * the {@link BookInfo} to display
*/
public void setBook(final BookInfo info) {
this.info = info;
name.setText(null);
opt.setText(null);
} else if (info.getMainInfo() == null) {
- name.setText("All the " + info.getType().toString().toLowerCase() + "s");
+ name.setText(
+ "All the " + info.getType().toString().toLowerCase() + "s");
opt.setText(info.getSecondaryInfo(true));
} else {
final String myId = info.getId();
BookInfo current = DetailsPanel.this.info;
if (current != null && current.getId().equals(myId)) {
- return BookBlock.generateCoverImage(Instance.getInstance().getLibrary(), info);
+ return BookBlock.generateCoverImage(
+ Instance.getInstance().getLibrary(), info);
}
return null;
browser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- books.load(browser.getSelectedSources(), browser.getSelectedAuthors(), browser.getSelectedTags());
+ books.load(browser.getSelectedSources(),
+ browser.getSelectedAuthors(),
+ browser.getSelectedTags());
details.setBook(browser.getHighlight());
}
});
this.add(split);
}
- private JSplitPane split(JComponent leftTop, JComponent rightBottom, boolean horizontal, double ratio,
- double weight) {
- JSplitPane split = new JSplitPane(horizontal ? JSplitPane.HORIZONTAL_SPLIT : JSplitPane.VERTICAL_SPLIT, leftTop,
- rightBottom);
+ private JSplitPane split(JComponent leftTop, JComponent rightBottom,
+ boolean horizontal, double ratio, double weight) {
+ JSplitPane split = new JSplitPane(
+ horizontal ? JSplitPane.HORIZONTAL_SPLIT
+ : JSplitPane.VERTICAL_SPLIT,
+ leftTop, rightBottom);
split.setOneTouchExpandable(true);
split.setResizeWeight(weight);
split.setContinuousLayout(true);
@Override
public void run() {
browser.reloadData();
- books.load(browser.getSelectedSources(), browser.getSelectedAuthors(),
+ books.load(browser.getSelectedSources(),
+ browser.getSelectedAuthors(),
browser.getSelectedTags());
details.setBook(browser.getHighlight());
}
@Override
public void run() {
browser.reloadData();
- books.load(browser.getSelectedSources(), browser.getSelectedAuthors(),
+ books.load(browser.getSelectedSources(),
+ browser.getSelectedAuthors(),
browser.getSelectedTags());
details.setBook(browser.getHighlight());
}
*/
public class BookBlock extends BookLine {
static private final long serialVersionUID = 1L;
- static private Image empty = BookCoverImager.generateCoverImage(null, (BookInfo) null);
+ static private Image empty = BookCoverImager.generateCoverImage(null,
+ (BookInfo) null);
private JLabel title;
private Image coverImage;
/**
* Create a new {@link BookBlock} item for the given {@link Story}.
*
- * @param info the information about the story to represent
- * @param seeWordCount TRUE to see word counts, FALSE to see authors
+ * @param info
+ * the information about the story to represent
+ * @param seeWordCount
+ * TRUE to see word counts, FALSE to see authors
*/
public BookBlock(BookInfo info, boolean seeWordCount) {
super(info, seeWordCount);
updateMeta();
JPanel filler = new JPanel();
- filler.setPreferredSize(new Dimension(BookCoverImager.getCoverWidth(), BookCoverImager.getCoverHeight()));
+ filler.setPreferredSize(new Dimension(BookCoverImager.getCoverWidth(),
+ BookCoverImager.getCoverHeight()));
filler.setOpaque(false);
setLayout(new BorderLayout(10, 10));
* the cover image to use a base (see
* {@link BookCoverImager#generateCoverImage(BasicLibrary, BookInfo)})
*
- * @param coverImage the image
+ * @param coverImage
+ * the image
*/
public void setCoverImage(Image coverImage) {
this.coverImage = coverImage;
@Override
public void paint(Graphics g) {
super.paint(g);
- g.drawImage(coverImage, BookCoverImager.TEXT_WIDTH - BookCoverImager.COVER_WIDTH, 0, null);
- BookCoverImager.paintOverlay(g, isEnabled(), isSelected(), isHovered(), getInfo().isCached());
+ g.drawImage(coverImage,
+ BookCoverImager.TEXT_WIDTH - BookCoverImager.COVER_WIDTH, 0,
+ null);
+ BookCoverImager.paintOverlay(g, isEnabled(), isSelected(), isHovered(),
+ getInfo().isCached());
}
@Override
protected void updateMeta() {
String main = getInfo().getMainInfo();
String optSecondary = getInfo().getSecondaryInfo(isSeeWordCount());
- String color = String.format("#%X%X%X", AUTHOR_COLOR.getRed(), AUTHOR_COLOR.getGreen(), AUTHOR_COLOR.getBlue());
- title.setText(String.format(
- "<html>" + "<body style='width: %d px; height: %d px; text-align: center;'>" + "%s" + "<br>"
- + "<span style='color: %s;'>" + "%s" + "</span>" + "</body>" + "</html>",
- BookCoverImager.TEXT_WIDTH, BookCoverImager.TEXT_HEIGHT, main, color, optSecondary));
+ String color = String.format("#%X%X%X", AUTHOR_COLOR.getRed(),
+ AUTHOR_COLOR.getGreen(), AUTHOR_COLOR.getBlue());
+ title.setText(String.format("<html>"
+ + "<body style='width: %d px; height: %d px; text-align: center;'>"
+ + "%s" + "<br>" + "<span style='color: %s;'>" + "%s" + "</span>"
+ + "</body>" + "</html>", BookCoverImager.TEXT_WIDTH,
+ BookCoverImager.TEXT_HEIGHT, main, color, optSecondary));
- setBackground(BookCoverImager.getBackground(isEnabled(), isSelected(), isHovered()));
+ setBackground(BookCoverImager.getBackground(isEnabled(), isSelected(),
+ isHovered()));
}
/**
* Generate a cover icon based upon the given {@link BookInfo}.
*
- * @param lib the library the meta comes from
- * @param info the {@link BookInfo}
+ * @param lib
+ * the library the meta comes from
+ * @param info
+ * the {@link BookInfo}
*
* @return the image
*/
- static public java.awt.Image generateCoverImage(BasicLibrary lib, BookInfo info) {
+ static public java.awt.Image generateCoverImage(BasicLibrary lib,
+ BookInfo info) {
return BookCoverImager.generateCoverImage(lib, info);
}
}
static final Color SPINE_COLOR_RIGHT = new Color(100, 100, 100);
static final Color BORDER = Color.black;
- public static final Color UNCACHED_ICON_COLOR = Color.green.darker();
- // new Color(0, 80, 220);
+ public static final Color UNCACHED_ICON_COLOR = Color.green.darker();
+ // new Color(0, 80, 220);
public static final int TEXT_HEIGHT = 50;
public static final int TEXT_WIDTH = COVER_WIDTH + 40;
//
- static public Color getBackground(boolean enabled, boolean selected, boolean hovered) {
+ static public Color getBackground(boolean enabled, boolean selected,
+ boolean hovered) {
Color color = new Color(255, 255, 255, 0);
if (!enabled) {
} else if (selected && !hovered) {
}
/**
- * Draw a partially transparent overlay if needed depending upon the selection
- * and mouse-hover states on top of the normal component, as well as a possible
- * "cached" icon if the item is cached.
+ * Draw a partially transparent overlay if needed depending upon the
+ * selection and mouse-hover states on top of the normal component, as well
+ * as a possible "cached" icon if the item is cached.
*
- * @param g the {@link Graphics} to paint onto
- * @param enabled draw an enabled overlay
- * @param selected draw a selected overlay
- * @param hovered draw a hovered overlay
- * @param cached draw a non-cached overlay if needed
+ * @param g
+ * the {@link Graphics} to paint onto
+ * @param enabled
+ * draw an enabled overlay
+ * @param selected
+ * draw a selected overlay
+ * @param hovered
+ * draw a hovered overlay
+ * @param cached
+ * draw a non-cached overlay if needed
*/
- static public void paintOverlay(Graphics g, boolean enabled, boolean selected, boolean hovered, boolean cached) {
+ static public void paintOverlay(Graphics g, boolean enabled,
+ boolean selected, boolean hovered, boolean cached) {
Rectangle clip = g.getClipBounds();
if (clip.getWidth() <= 0 || clip.getHeight() <= 0) {
return;
yOffset++;
}
- int[] xs = new int[] { xOffset, xOffset + SPINE_WIDTH, xOffset + w + SPINE_WIDTH, xOffset + w };
- int[] ys = new int[] { yOffset + h, yOffset + h + SPINE_HEIGHT, yOffset + h + SPINE_HEIGHT, yOffset + h };
+ int[] xs = new int[] { xOffset, xOffset + SPINE_WIDTH,
+ xOffset + w + SPINE_WIDTH, xOffset + w };
+ int[] ys = new int[] { yOffset + h, yOffset + h + SPINE_HEIGHT,
+ yOffset + h + SPINE_HEIGHT, yOffset + h };
g.setColor(SPINE_COLOR_BOTTOM);
g.fillPolygon(new Polygon(xs, ys, xs.length));
- xs = new int[] { xOffset + w, xOffset + w + SPINE_WIDTH, xOffset + w + SPINE_WIDTH, xOffset + w };
- ys = new int[] { yOffset, yOffset + SPINE_HEIGHT, yOffset + h + SPINE_HEIGHT, yOffset + h };
+ xs = new int[] { xOffset + w, xOffset + w + SPINE_WIDTH,
+ xOffset + w + SPINE_WIDTH, xOffset + w };
+ ys = new int[] { yOffset, yOffset + SPINE_HEIGHT,
+ yOffset + h + SPINE_HEIGHT, yOffset + h };
g.setColor(SPINE_COLOR_RIGHT);
g.fillPolygon(new Polygon(xs, ys, xs.length));
g.setColor(color);
g.fillRect(clip.x, clip.y, clip.width, clip.height);
- UIUtils.drawEllipse3D(g, UNCACHED_ICON_COLOR, COVER_WIDTH + HOFFSET + 30, 10, 20, 20, cached);
+ UIUtils.drawEllipse3D(g, UNCACHED_ICON_COLOR,
+ COVER_WIDTH + HOFFSET + 30, 10, 20, 20, cached);
}
/**
/**
* Generate a cover icon based upon the given {@link GuiReaderBookInfo}.
*
- * @param lib the library the meta comes from (can be NULL)
- * @param info the {@link GuiReaderBookInfo}
+ * @param lib
+ * the library the meta comes from (can be NULL)
+ * @param info
+ * the {@link GuiReaderBookInfo}
*
* @return the image
*/
- static public java.awt.Image generateCoverImage(BasicLibrary lib, BookInfo info) {
+ static public java.awt.Image generateCoverImage(BasicLibrary lib,
+ BookInfo info) {
BufferedImage resizedImage = null;
String id = getIconId(info);
cover = info.getBaseImage(lib);
}
- resizedImage = new BufferedImage(getCoverWidth(), getCoverHeight(), BufferedImage.TYPE_4BYTE_ABGR);
+ resizedImage = new BufferedImage(getCoverWidth(),
+ getCoverHeight(), BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g = resizedImage.createGraphics();
try {
if (info != null && info.supportsCover()) {
g.setColor(Color.white);
g.fillRect(0, HOFFSET, COVER_WIDTH, COVER_HEIGHT);
-
+
if (cover != null) {
- BufferedImage coverb = ImageUtilsAwt.fromImage(cover);
- g.drawImage(coverb, 0, HOFFSET, COVER_WIDTH, COVER_HEIGHT, null);
+ BufferedImage coverb = ImageUtilsAwt
+ .fromImage(cover);
+ g.drawImage(coverb, 0, HOFFSET, COVER_WIDTH,
+ COVER_HEIGHT, null);
} else {
g.setColor(Color.black);
- g.drawLine(0, HOFFSET, COVER_WIDTH, HOFFSET + COVER_HEIGHT);
- g.drawLine(COVER_WIDTH, HOFFSET, 0, HOFFSET + COVER_HEIGHT);
+ g.drawLine(0, HOFFSET, COVER_WIDTH,
+ HOFFSET + COVER_HEIGHT);
+ g.drawLine(COVER_WIDTH, HOFFSET, 0,
+ HOFFSET + COVER_HEIGHT);
}
}
} finally {
/**
* Manually clear the icon set for this item.
*
- * @param info the info about the story or source/type or author
+ * @param info
+ * the info about the story or source/type or author
*/
static public void clearIcon(BookInfo info) {
String id = getIconId(info);
}
/**
- * Get a unique ID from this {@link GuiReaderBookInfo} (note that it can be a
- * story, a fake item for a source/type or a fake item for an author).
+ * Get a unique ID from this {@link GuiReaderBookInfo} (note that it can be
+ * a story, a fake item for a source/type or a fake item for an author).
*
- * @param info the info or NULL for a generic (non unique!) ID
+ * @param info
+ * the info or NULL for a generic (non unique!) ID
* @return the unique ID
*/
static private String getIconId(BookInfo info) {
- return (info == null ? "" : info.getId() + ".") + "book-thumb_" + SPINE_WIDTH + "x" + COVER_WIDTH + "+"
- + SPINE_HEIGHT + "+" + COVER_HEIGHT + "@" + HOFFSET;
+ return (info == null ? "" : info.getId() + ".") + "book-thumb_"
+ + SPINE_WIDTH + "x" + COVER_WIDTH + "+" + SPINE_HEIGHT + "+"
+ + COVER_HEIGHT + "@" + HOFFSET;
}
}
*/
public class BookInfo {
/**
- * The type of {@link Book} (i.e., related to a story or to something else that
- * can encompass stories).
+ * The type of {@link Book} (i.e., related to a story or to something else
+ * that can encompass stories).
*
* @author niki
*/
/** A normal story, which can be "read". */
STORY,
/**
- * A special, empty story that represents a source/type common to one or more
- * normal stories.
+ * A special, empty story that represents a source/type common to one or
+ * more normal stories.
*/
SOURCE,
/** A special, empty story that represents an author. */
/**
* For private use; see the "fromXXX" constructors instead for public use.
*
- * @param type the type of book
- * @param id the main id, which must uniquely identify this book and will be
- * used as a unique ID later on
- * @param value the main value to show (see {@link BookInfo#getMainInfo()})
+ * @param type
+ * the type of book
+ * @param id
+ * the main id, which must uniquely identify this book and will
+ * be used as a unique ID later on
+ * @param value
+ * the main value to show (see {@link BookInfo#getMainInfo()})
*/
protected BookInfo(Type type, String id, String value) {
this.type = type;
}
/**
- * Get the main info to display for this book (a title, an author, a source/type
- * name...).
+ * Get the main info to display for this book (a title, an author, a
+ * source/type name...).
* <p>
- * Note that when {@link MetaData} about the book are present, the title inside
- * is returned instead of the actual value (that way, we can update the
- * {@link MetaData} and see the changes here).
+ * Note that when {@link MetaData} about the book are present, the title
+ * inside is returned instead of the actual value (that way, we can update
+ * the {@link MetaData} and see the changes here).
*
* @return the main info, usually the title
*/
/**
* Get the secondary info, of the given type.
*
- * @param seeCount TRUE for word/image/story count, FALSE for author name
+ * @param seeCount
+ * TRUE for word/image/story count, FALSE for author name
*
* @return the secondary info, never NULL
*/
/**
* This item library cache state.
*
- * @param cached TRUE if it is present in the {@link CacheLibrary} cache
+ * @param cached
+ * TRUE if it is present in the {@link CacheLibrary} cache
*/
public void setCached(boolean cached) {
this.cached = cached;
* <p>
* It can be NULL if no image can be found for this book.
*
- * @param lib the {@link BasicLibrary} to use to fetch the image (can be NULL)
+ * @param lib
+ * the {@link BasicLibrary} to use to fetch the image (can be
+ * NULL)
*
* @return the base image, or NULL if no library or no image
*
- * @throws IOException in case of I/O error
+ * @throws IOException
+ * in case of I/O error
*/
public Image getBaseImage(BasicLibrary lib) throws IOException {
if (lib != null) {
return null;
}
-
+
/**
* This {@link BookInfo} could have a cover (so we need to somehow represent
* that to the user).
/**
* Create a new book describing the given {@link Story}.
*
- * @param lib the {@link BasicLibrary} to use to retrieve some more information
- * about the source
- * @param meta the {@link MetaData} representing the {@link Story}
+ * @param lib
+ * the {@link BasicLibrary} to use to retrieve some more
+ * information about the source
+ * @param meta
+ * the {@link MetaData} representing the {@link Story}
*
* @return the book
*/
info.count = StringUtils.formatNumber(meta.getWords());
if (!info.count.isEmpty()) {
info.count = Instance.getInstance().getTransGui().getString(
- meta.isImageDocument() ? StringIdGui.BOOK_COUNT_IMAGES : StringIdGui.BOOK_COUNT_WORDS,
+ meta.isImageDocument() ? StringIdGui.BOOK_COUNT_IMAGES
+ : StringIdGui.BOOK_COUNT_WORDS,
new Object[] { info.count });
}
/**
* Create a new book describing the given source/type.
*
- * @param lib the {@link BasicLibrary} to use to retrieve some more
- * information about the source
- * @param source the source name
+ * @param lib
+ * the {@link BasicLibrary} to use to retrieve some more
+ * information about the source
+ * @param source
+ * the source name
*
* @return the book
*/
static public BookInfo fromSource(BasicLibrary lib, String source) {
- BookInfo info = new BookInfo(Type.SOURCE, "source_" + (source == null ? "" : source), source);
+ BookInfo info = new BookInfo(Type.SOURCE,
+ "source_" + (source == null ? "" : source), source);
int size = 0;
try {
info.count = StringUtils.formatNumber(size);
if (!info.count.isEmpty()) {
- info.count = Instance.getInstance().getTransGui().getString(StringIdGui.BOOK_COUNT_STORIES,
+ info.count = Instance.getInstance().getTransGui().getString(
+ StringIdGui.BOOK_COUNT_STORIES,
new Object[] { info.count });
}
/**
* Create a new book describing the given author.
*
- * @param lib the {@link BasicLibrary} to use to retrieve some more
- * information about the author
- * @param author the author name
+ * @param lib
+ * the {@link BasicLibrary} to use to retrieve some more
+ * information about the author
+ * @param author
+ * the author name
*
* @return the book
*/
static public BookInfo fromAuthor(BasicLibrary lib, String author) {
- BookInfo info = new BookInfo(Type.AUTHOR, "author_" + (author == null ? "" : author), author);
+ BookInfo info = new BookInfo(Type.AUTHOR,
+ "author_" + (author == null ? "" : author), author);
int size = 0;
try {
info.count = StringUtils.formatNumber(size);
if (!info.count.isEmpty()) {
- info.count = Instance.getInstance().getTransGui().getString(StringIdGui.BOOK_COUNT_STORIES,
+ info.count = Instance.getInstance().getTransGui().getString(
+ StringIdGui.BOOK_COUNT_STORIES,
new Object[] { info.count });
}
/**
* Create a new book describing the given tag.
*
- * @param lib the {@link BasicLibrary} to use to retrieve some more information
- * about the tag
- * @param tag the tag name
+ * @param lib
+ * the {@link BasicLibrary} to use to retrieve some more
+ * information about the tag
+ * @param tag
+ * the tag name
*
* @return the book
*/
static public BookInfo fromTag(BasicLibrary lib, String tag) {
- BookInfo info = new BookInfo(Type.TAG, "tag_" + (tag == null ? "" : tag), tag);
+ BookInfo info = new BookInfo(Type.TAG,
+ "tag_" + (tag == null ? "" : tag), tag);
int size = 0;
try {
info.count = StringUtils.formatNumber(size);
if (!info.count.isEmpty()) {
- info.count = Instance.getInstance().getTransGui().getString(StringIdGui.BOOK_COUNT_STORIES,
+ info.count = Instance.getInstance().getTransGui().getString(
+ StringIdGui.BOOK_COUNT_STORIES,
new Object[] { info.count });
}
/**
* Create a new {@link BookLine} item for the given {@link Story}.
*
- * @param info the information about the story to represent
- * @param seeWordCount TRUE to see word counts, FALSE to see authors
+ * @param info
+ * the information about the story to represent
+ * @param seeWordCount
+ * TRUE to see word counts, FALSE to see authors
*/
public BookLine(BookInfo info, boolean seeWordCount) {
this.info = info;
/**
* The book current selection state,
*
- * @param selected TRUE if it is selected
+ * @param selected
+ * TRUE if it is selected
*/
public void setSelected(boolean selected) {
if (this.selected != selected) {
/**
* The item mouse-hover state.
*
- * @param hovered TRUE if it is mouse-hovered
+ * @param hovered
+ * TRUE if it is mouse-hovered
*/
public void setHovered(boolean hovered) {
if (this.hovered != hovered) {
/**
* The secondary value content: word count or author.
*
- * @param seeWordCount TRUE to see word counts, FALSE to see authors
+ * @param seeWordCount
+ * TRUE to see word counts, FALSE to see authors
*/
public void setSeeWordCount(boolean seeWordCount) {
if (this.seeWordCount != seeWordCount) {
title.setText(main);
secondary.setText(optSecondary + " ");
- setBackground(BookCoverImager.getBackground(isEnabled(), isSelected(), isHovered()));
+ setBackground(BookCoverImager.getBackground(isEnabled(), isSelected(),
+ isHovered()));
remove(iconCached);
remove(iconNotCached);
- add(getInfo().isCached() ? iconCached : iconNotCached, BorderLayout.WEST);
+ add(getInfo().isCached() ? iconCached : iconNotCached,
+ BorderLayout.WEST);
validate();
}
}
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- ConfigEditor<Config> ed = new ConfigEditor<Config>(Config.class, Instance.getInstance().getConfig(),
+ ConfigEditor<Config> ed = new ConfigEditor<Config>(Config.class,
+ Instance.getInstance().getConfig(),
trans(StringIdGui.SUBTITLE_CONFIG));
JFrame frame = new JFrame(title);
frame.add(ed);
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- ConfigEditor<UiConfig> ed = new ConfigEditor<UiConfig>(UiConfig.class,
- Instance.getInstance().getUiConfig(), trans(StringIdGui.SUBTITLE_CONFIG_UI));
+ ConfigEditor<UiConfig> ed = new ConfigEditor<UiConfig>(
+ UiConfig.class, Instance.getInstance().getUiConfig(),
+ trans(StringIdGui.SUBTITLE_CONFIG_UI));
JFrame frame = new JFrame(title);
frame.add(ed);
frame.setSize(800, 600);
}
//
- JMenuItem export = new JMenuItem(trans(StringIdGui.MENU_FILE_EXPORT), KeyEvent.VK_S);
+ JMenuItem export = new JMenuItem(trans(StringIdGui.MENU_FILE_EXPORT),
+ KeyEvent.VK_S);
export.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final BookInfo book = informer.getUniqueSelected();
if (book != null) {
- fc.showDialog(BookPopup.this.getParent(), trans(StringIdGui.TITLE_SAVE));
+ fc.showDialog(BookPopup.this.getParent(),
+ trans(StringIdGui.TITLE_SAVE));
if (fc.getSelectedFile() != null) {
- final OutputType type = otherFilters.get(fc.getFileFilter());
- final String path = fc.getSelectedFile().getAbsolutePath() + type.getDefaultExtension(false);
+ final OutputType type = otherFilters
+ .get(fc.getFileFilter());
+ final String path = fc.getSelectedFile()
+ .getAbsolutePath()
+ + type.getDefaultExtension(false);
final Progress pg = new Progress();
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
- lib.export(book.getMeta().getLuid(), type, path, pg);
+ lib.export(book.getMeta().getLuid(), type, path,
+ pg);
return null;
}
try {
get();
} catch (Exception e) {
- UiHelper.error(BookPopup.this.getParent(), e.getLocalizedMessage(), "IOException",
- e);
+ UiHelper.error(BookPopup.this.getParent(),
+ e.getLocalizedMessage(),
+ "IOException", e);
}
}
}.execute();
* Create a {@link FileFilter} that accepts all files and return the given
* description.
*
- * @param desc the description
+ * @param desc
+ * the description
*
* @return the filter
*/
* @return the item
*/
private JMenuItem createMenuItemClearCache() {
- JMenuItem refresh = new JMenuItem(trans(StringIdGui.MENU_EDIT_CLEAR_CACHE), KeyEvent.VK_C);
+ JMenuItem refresh = new JMenuItem(
+ trans(StringIdGui.MENU_EDIT_CLEAR_CACHE), KeyEvent.VK_C);
refresh.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
informer.setCached(book, false);
}
} catch (Exception e) {
- UiHelper.error(BookPopup.this.getParent(), e.getLocalizedMessage(), "IOException", e);
+ UiHelper.error(BookPopup.this.getParent(),
+ e.getLocalizedMessage(), "IOException",
+ e);
}
}
}.execute();
try {
groupedSources = lib.getSourcesGrouped();
} catch (IOException e) {
- UiHelper.error(BookPopup.this.getParent(), e.getLocalizedMessage(), "IOException", e);
+ UiHelper.error(BookPopup.this.getParent(), e.getLocalizedMessage(),
+ "IOException", e);
}
- JMenuItem item = new JMenuItem(trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_TYPE));
+ JMenuItem item = new JMenuItem(
+ trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_TYPE));
item.addActionListener(createMoveAction(ChangeAction.SOURCE, null));
changeTo.add(item);
changeTo.addSeparator();
List<String> list = groupedSources.get(type);
if (list.size() == 1 && list.get(0).isEmpty()) {
item = new JMenuItem(type);
- item.addActionListener(createMoveAction(ChangeAction.SOURCE, type));
+ item.addActionListener(
+ createMoveAction(ChangeAction.SOURCE, type));
changeTo.add(item);
} else {
JMenu dir = new JMenu(type);
}
item = new JMenuItem(itemName);
- item.addActionListener(createMoveAction(ChangeAction.SOURCE, actualType));
+ item.addActionListener(
+ createMoveAction(ChangeAction.SOURCE, actualType));
dir.add(item);
}
changeTo.add(dir);
changeTo.setMnemonic(KeyEvent.VK_A);
// New author
- JMenuItem newItem = new JMenuItem(trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_AUTHOR));
+ JMenuItem newItem = new JMenuItem(
+ trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_AUTHOR));
changeTo.add(newItem);
changeTo.addSeparator();
newItem.addActionListener(createMoveAction(ChangeAction.AUTHOR, null));
try {
groupedAuthors = lib.getAuthorsGrouped();
} catch (IOException e) {
- UiHelper.error(BookPopup.this.getParent(), e.getLocalizedMessage(), "IOException", e);
+ UiHelper.error(BookPopup.this.getParent(), e.getLocalizedMessage(),
+ "IOException", e);
groupedAuthors = new HashMap<String, List<String>>();
}
for (String key : groupedAuthors.keySet()) {
JMenu group = new JMenu(key);
for (String value : groupedAuthors.get(key)) {
- JMenuItem item = new JMenuItem(value.isEmpty() ? trans(StringIdGui.MENU_AUTHORS_UNKNOWN) : value);
- item.addActionListener(createMoveAction(ChangeAction.AUTHOR, value));
+ JMenuItem item = new JMenuItem(value.isEmpty()
+ ? trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+ : value);
+ item.addActionListener(
+ createMoveAction(ChangeAction.AUTHOR, value));
group.add(item);
}
changeTo.add(group);
}
} else if (groupedAuthors.size() == 1) {
for (String value : groupedAuthors.values().iterator().next()) {
- JMenuItem item = new JMenuItem(value.isEmpty() ? trans(StringIdGui.MENU_AUTHORS_UNKNOWN) : value);
- item.addActionListener(createMoveAction(ChangeAction.AUTHOR, value));
+ JMenuItem item = new JMenuItem(value.isEmpty()
+ ? trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+ : value);
+ item.addActionListener(
+ createMoveAction(ChangeAction.AUTHOR, value));
changeTo.add(item);
}
}
return changeTo;
}
- private ActionListener createMoveAction(final ChangeAction what, final String type) {
+ private ActionListener createMoveAction(final ChangeAction what,
+ final String type) {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
}
- Object rep = JOptionPane.showInputDialog(BookPopup.this.getParent(),
- trans(StringIdGui.SUBTITLE_MOVE_TO), trans(StringIdGui.TITLE_MOVE_TO),
+ Object rep = JOptionPane.showInputDialog(
+ BookPopup.this.getParent(),
+ trans(StringIdGui.SUBTITLE_MOVE_TO),
+ trans(StringIdGui.TITLE_MOVE_TO),
JOptionPane.QUESTION_MESSAGE, null, null, init);
if (rep == null) {
@Override
protected void done() {
try {
- // this can create new sources/authors, so a simple fireElementChanged is not
- // enough, we need to clear the whole cache (for BrowserPanel for instance)
+ // this can create new sources/authors, so a
+ // simple fireElementChanged is not
+ // enough, we need to clear the whole cache (for
+ // BrowserPanel for instance)
informer.invalidateCache();
- // TODO: also refresh the Sources/Authors(/Tags?) list
+ // TODO: also refresh the
+ // Sources/Authors(/Tags?) list
- // Even if problems occurred, still invalidate the cache
+ // Even if problems occurred, still invalidate
+ // the cache
get();
} catch (Exception e) {
- UiHelper.error(BookPopup.this.getParent(), e.getLocalizedMessage(), "IOException", e);
+ UiHelper.error(BookPopup.this.getParent(),
+ e.getLocalizedMessage(), "IOException",
+ e);
}
}
}.execute();
* @return the item
*/
private JMenuItem createMenuItemRedownload() {
- JMenuItem refresh = new JMenuItem(trans(StringIdGui.MENU_EDIT_REDOWNLOAD), KeyEvent.VK_R);
+ JMenuItem refresh = new JMenuItem(
+ trans(StringIdGui.MENU_EDIT_REDOWNLOAD), KeyEvent.VK_R);
refresh.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
-// final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
-// if (selectedBook != null) {
-// final MetaData meta = selectedBook.getInfo().getMeta();
-// mainPanel.imprt(meta.getUrl(), new MetaDataRunnable() {
-// @Override
-// public void run(MetaData newMeta) {
-// if (!newMeta.getSource().equals(meta.getSource())) {
-// reader.changeSource(newMeta.getLuid(), meta.getSource());
-// }
-// }
-// }, trans(StringIdGui.PROGRESS_CHANGE_SOURCE));
-// }
+ // final GuiReaderBook selectedBook =
+ // mainPanel.getSelectedBook();
+ // if (selectedBook != null) {
+ // final MetaData meta = selectedBook.getInfo().getMeta();
+ // mainPanel.imprt(meta.getUrl(), new MetaDataRunnable() {
+ // @Override
+ // public void run(MetaData newMeta) {
+ // if (!newMeta.getSource().equals(meta.getSource())) {
+ // reader.changeSource(newMeta.getLuid(), meta.getSource());
+ // }
+ // }
+ // }, trans(StringIdGui.PROGRESS_CHANGE_SOURCE));
+ // }
}
});
* @return the item
*/
private JMenuItem createMenuItemDownloadToCache() {
- JMenuItem refresh = new JMenuItem(trans(StringIdGui.MENU_EDIT_DOWNLOAD_TO_CACHE), KeyEvent.VK_T);
+ JMenuItem refresh = new JMenuItem(
+ trans(StringIdGui.MENU_EDIT_DOWNLOAD_TO_CACHE), KeyEvent.VK_T);
refresh.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
luids.add(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)) {
luids.add(meta.getLuid());
}
break;
case AUTHOR:
- for (MetaData meta : lib.getList().filter(null, book.getMainInfo(), null)) {
+ for (MetaData meta : lib.getList().filter(null,
+ book.getMainInfo(), null)) {
luids.add(meta.getLuid());
}
break;
case TAG:
- for (MetaData meta : lib.getList().filter(null, null, book.getMainInfo())) {
+ for (MetaData meta : lib.getList().filter(null,
+ null, book.getMainInfo())) {
luids.add(meta.getLuid());
}
break;
informer.setCached(book, true);
}
} catch (Exception e) {
- UiHelper.error(BookPopup.this.getParent(), e.getLocalizedMessage(), "IOException", e);
+ UiHelper.error(BookPopup.this.getParent(),
+ e.getLocalizedMessage(), "IOException", e);
}
}
}.execute();
* @return the item
*/
private JMenuItem createMenuItemDelete() {
- JMenuItem delete = new JMenuItem(trans(StringIdGui.MENU_EDIT_DELETE), KeyEvent.VK_D);
+ JMenuItem delete = new JMenuItem(trans(StringIdGui.MENU_EDIT_DELETE),
+ KeyEvent.VK_D);
delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
-// final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
-// if (selectedBook != null && selectedBook.getInfo().getMeta() != null) {
-//
-// final MetaData meta = selectedBook.getInfo().getMeta();
-// int rep = JOptionPane.showConfirmDialog(GuiReaderFrame.this,
-// trans(StringIdGui.SUBTITLE_DELETE, meta.getLuid(), meta.getTitle()),
-// trans(StringIdGui.TITLE_DELETE), JOptionPane.OK_CANCEL_OPTION);
-//
-// if (rep == JOptionPane.OK_OPTION) {
-// mainPanel.outOfUi(null, true, new Runnable() {
-// @Override
-// public void run() {
-// reader.delete(meta.getLuid());
-// mainPanel.unsetSelectedBook();
-// }
-// });
-// }
-// }
+ // final GuiReaderBook selectedBook =
+ // mainPanel.getSelectedBook();
+ // if (selectedBook != null && selectedBook.getInfo().getMeta()
+ // != null) {
+ //
+ // final MetaData meta = selectedBook.getInfo().getMeta();
+ // int rep = JOptionPane.showConfirmDialog(GuiReaderFrame.this,
+ // trans(StringIdGui.SUBTITLE_DELETE, meta.getLuid(),
+ // meta.getTitle()),
+ // trans(StringIdGui.TITLE_DELETE),
+ // JOptionPane.OK_CANCEL_OPTION);
+ //
+ // if (rep == JOptionPane.OK_OPTION) {
+ // mainPanel.outOfUi(null, true, new Runnable() {
+ // @Override
+ // public void run() {
+ // reader.delete(meta.getLuid());
+ // mainPanel.unsetSelectedBook();
+ // }
+ // });
+ // }
+ // }
}
});
* @return the item
*/
private JMenuItem createMenuItemProperties() {
- JMenuItem delete = new JMenuItem(trans(StringIdGui.MENU_FILE_PROPERTIES), KeyEvent.VK_P);
+ JMenuItem delete = new JMenuItem(
+ trans(StringIdGui.MENU_FILE_PROPERTIES), KeyEvent.VK_P);
delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
-// final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
-// if (selectedBook != null) {
-// mainPanel.outOfUi(null, false, new Runnable() {
-// @Override
-// public void run() {
-// new GuiReaderPropertiesFrame(lib, selectedBook.getInfo().getMeta())
-// .setVisible(true);
-// }
-// });
-// }
+ // final GuiReaderBook selectedBook =
+ // mainPanel.getSelectedBook();
+ // if (selectedBook != null) {
+ // mainPanel.outOfUi(null, false, new Runnable() {
+ // @Override
+ // public void run() {
+ // new GuiReaderPropertiesFrame(lib,
+ // selectedBook.getInfo().getMeta())
+ // .setVisible(true);
+ // }
+ // });
+ // }
}
});
* @return the item
*/
public JMenuItem createMenuItemOpenBook() {
- JMenuItem open = new JMenuItem(trans(StringIdGui.MENU_FILE_OPEN), KeyEvent.VK_O);
+ JMenuItem open = new JMenuItem(trans(StringIdGui.MENU_FILE_OPEN),
+ KeyEvent.VK_O);
open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final BookInfo book = informer.getUniqueSelected();
if (book != null) {
- Actions.openExternal(lib, book.getMeta(), BookPopup.this.getParent(), new Runnable() {
- @Override
- public void run() {
- informer.setCached(book, true);
- }
- });
+ Actions.openExternal(lib, book.getMeta(),
+ BookPopup.this.getParent(), new Runnable() {
+ @Override
+ public void run() {
+ informer.setCached(book, true);
+ }
+ });
}
}
});
}
/**
- * Create the SetCover menu item for a book to change the linked source cover.
+ * Create the SetCover menu item for a book to change the linked source
+ * cover.
*
* @return the item
*/
private JMenuItem createMenuItemSetCoverForSource() {
- JMenuItem open = new JMenuItem(trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_SOURCE), KeyEvent.VK_C);
+ JMenuItem open = new JMenuItem(
+ trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_SOURCE),
+ KeyEvent.VK_C);
open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
-// final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
-// if (selectedBook != null) {
-// BasicLibrary lib = lib;
-// String luid = selectedBook.getInfo().getMeta().getLuid();
-// String source = selectedBook.getInfo().getMeta().getSource();
-//
-// try {
-// lib.setSourceCover(source, luid);
-// } catch (IOException e) {
-// error(e.getLocalizedMessage(), "IOException", e);
-// }
-//
-// GuiReaderBookInfo sourceInfo = GuiReaderBookInfo.fromSource(lib, source);
-// GuiReaderCoverImager.clearIcon(sourceInfo);
-// }
+ // final GuiReaderBook selectedBook =
+ // mainPanel.getSelectedBook();
+ // if (selectedBook != null) {
+ // BasicLibrary lib = lib;
+ // String luid = selectedBook.getInfo().getMeta().getLuid();
+ // String source = selectedBook.getInfo().getMeta().getSource();
+ //
+ // try {
+ // lib.setSourceCover(source, luid);
+ // } catch (IOException e) {
+ // error(e.getLocalizedMessage(), "IOException", e);
+ // }
+ //
+ // GuiReaderBookInfo sourceInfo =
+ // GuiReaderBookInfo.fromSource(lib, source);
+ // GuiReaderCoverImager.clearIcon(sourceInfo);
+ // }
}
});
}
/**
- * Create the SetCover menu item for a book to change the linked source cover.
+ * Create the SetCover menu item for a book to change the linked source
+ * cover.
*
* @return the item
*/
private JMenuItem createMenuItemSetCoverForAuthor() {
- JMenuItem open = new JMenuItem(trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_AUTHOR), KeyEvent.VK_A);
+ JMenuItem open = new JMenuItem(
+ trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_AUTHOR),
+ KeyEvent.VK_A);
open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
-// final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
-// if (selectedBook != null) {
-// String luid = selectedBook.getInfo().getMeta().getLuid();
-// String author = selectedBook.getInfo().getMeta().getAuthor();
-//
-// try {
-// lib.setAuthorCover(author, luid);
-// } catch (IOException e) {
-// error(e.getLocalizedMessage(), "IOException", e);
-// }
-//
-// GuiReaderBookInfo authorInfo = GuiReaderBookInfo.fromAuthor(lib, author);
-// GuiReaderCoverImager.clearIcon(authorInfo);
-// }
+ // final GuiReaderBook selectedBook =
+ // mainPanel.getSelectedBook();
+ // if (selectedBook != null) {
+ // String luid = selectedBook.getInfo().getMeta().getLuid();
+ // String author = selectedBook.getInfo().getMeta().getAuthor();
+ //
+ // try {
+ // lib.setAuthorCover(author, luid);
+ // } catch (IOException e) {
+ // error(e.getLocalizedMessage(), "IOException", e);
+ // }
+ //
+ // GuiReaderBookInfo authorInfo =
+ // GuiReaderBookInfo.fromAuthor(lib, author);
+ // GuiReaderCoverImager.clearIcon(authorInfo);
+ // }
}
});
@Override
protected void fillData(List<String> data) {
try {
- List<String> authors = Instance.getInstance().getLibrary().getAuthors();
+ List<String> authors = Instance.getInstance().getLibrary()
+ .getAuthors();
for (String author : authors) {
data.add(author);
}
@Override
protected String keyToDisplay(String key) {
if (key.trim().isEmpty()) {
- key = Instance.getInstance().getTransGui().getString(StringIdGui.MENU_AUTHORS_UNKNOWN);
+ key = Instance.getInstance().getTransGui()
+ .getString(StringIdGui.MENU_AUTHORS_UNKNOWN);
}
-
+
return key;
}
@Override
- protected int loadData(DefaultMutableTreeNode root, List<String> authors, String filter) {
+ protected int loadData(DefaultMutableTreeNode root, List<String> authors,
+ String filter) {
for (String author : authors) {
if (checkFilter(filter, author)) {
- DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode(author);
+ DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode(
+ author);
root.add(sourceNode);
}
}
tree = new JTree(root);
tree.setUI(new BasicTreeUI());
- TreeCellSpanner spanner = new TreeCellSpanner(tree, generateCellRenderer());
+ TreeCellSpanner spanner = new TreeCellSpanner(tree,
+ generateCellRenderer());
tree.setCellRenderer(spanner);
tree.setRootVisible(false);
tree.setShowsRootHandles(false);
protected boolean isSamePath(TreePath oldPath, TreePath newPath) {
String oldString = oldPath.toString();
if (oldString.endsWith("/]"))
- oldString = oldString.substring(0, oldString.length() - 2) + "]";
+ oldString = oldString.substring(0, oldString.length() - 2)
+ + "]";
String newString = newPath.toString();
if (newString.endsWith("/]"))
- newString = newString.substring(0, newString.length() - 2) + "]";
+ newString = newString.substring(0, newString.length() - 2)
+ + "]";
return oldString.equals(newString);
}
};
SwingWorker<Map<String, List<String>>, Integer> worker = new SwingWorker<Map<String, List<String>>, Integer>() {
@Override
- protected Map<String, List<String>> doInBackground() throws Exception {
+ protected Map<String, List<String>> doInBackground()
+ throws Exception {
fillData(data);
return null;
}
String count = "";
if (totalCount > 0) {
int selected = selectedElements.size();
- count = " (" + (selected > 0 ? selected + "/" : "") + totalCount + ")";
+ count = " (" + (selected > 0 ? selected + "/" : "") + totalCount
+ + ")";
}
return title + count;
}
protected boolean checkFilter(String filter, String value) {
- return (filter == null || filter.isEmpty() || value.toLowerCase().contains(filter.toLowerCase()));
+ return (filter == null || filter.isEmpty()
+ || value.toLowerCase().contains(filter.toLowerCase()));
}
protected boolean checkFilter(String filter, List<String> list) {
protected abstract String keyToDisplay(String key);
- protected abstract int loadData(DefaultMutableTreeNode root, T data, String filter);
+ protected abstract int loadData(DefaultMutableTreeNode root, T data,
+ String filter);
private TreeCellRenderer generateCellRenderer() {
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
@Override
- public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
+ public Component getTreeCellRendererComponent(JTree tree,
+ Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
if (value instanceof DefaultMutableTreeNode) {
if (((DefaultMutableTreeNode) value).getLevel() > 1) {
String display = value == null ? "" : value.toString();
display = keyToDisplay(display);
- return super.getTreeCellRendererComponent(tree, display, selected, expanded, leaf, row, hasFocus);
+ return super.getTreeCellRendererComponent(tree, display,
+ selected, expanded, leaf, row, hasFocus);
}
};
@Override
protected void fillData(Map<String, List<String>> data) {
try {
- Map<String, List<String>> sourcesGrouped = Instance.getInstance().getLibrary().getSourcesGrouped();
+ Map<String, List<String>> sourcesGrouped = Instance.getInstance()
+ .getLibrary().getSourcesGrouped();
for (String group : sourcesGrouped.keySet()) {
data.put(group, sourcesGrouped.get(group));
}
}
@Override
- protected int loadData(DefaultMutableTreeNode root, Map<String, List<String>> sourcesGrouped, String filter) {
+ protected int loadData(DefaultMutableTreeNode root,
+ Map<String, List<String>> sourcesGrouped, String filter) {
int count = 0;
for (String source : sourcesGrouped.keySet()) {
- if (checkFilter(filter, source) || checkFilter(filter, sourcesGrouped.get(source))) {
+ if (checkFilter(filter, source)
+ || checkFilter(filter, sourcesGrouped.get(source))) {
List<String> children = sourcesGrouped.get(source);
boolean hasChildren = (children.size() > 1)
- || (children.size() == 1 && !children.get(0).trim().isEmpty());
- DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode(">" + source + (hasChildren ? "/" : ""));
+ || (children.size() == 1
+ && !children.get(0).trim().isEmpty());
+ DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode(
+ ">" + source + (hasChildren ? "/" : ""));
root.add(sourceNode);
for (String subSource : children) {
- if (checkFilter(filter, source) || checkFilter(filter, subSource)) {
+ if (checkFilter(filter, source)
+ || checkFilter(filter, subSource)) {
count = count + 1;
- if (subSource.isEmpty() && sourcesGrouped.get(source).size() > 1) {
- sourceNode.add(new DefaultMutableTreeNode(" " + source));
+ if (subSource.isEmpty()
+ && sourcesGrouped.get(source).size() > 1) {
+ sourceNode.add(
+ new DefaultMutableTreeNode(" " + source));
} else if (!subSource.isEmpty()) {
- sourceNode.add(new DefaultMutableTreeNode(" " + source + "/" + subSource));
+ sourceNode.add(new DefaultMutableTreeNode(
+ " " + source + "/" + subSource));
}
}
}
@Override
protected void fillData(List<String> data) {
try {
- MetaResultList metas = Instance.getInstance().getLibrary().getList();
+ MetaResultList metas = Instance.getInstance().getLibrary()
+ .getList();
// TODO: getTagList, getAuthorList... ?
for (MetaData meta : metas.getMetas()) {
List<String> tags = meta.getTags();
protected String keyToDisplay(String key) {
if (key.trim().isEmpty()) {
// TODO: new TAG_UNKNOWN needed
- key = Instance.getInstance().getTransGui().getString(StringIdGui.MENU_AUTHORS_UNKNOWN);
+ key = Instance.getInstance().getTransGui()
+ .getString(StringIdGui.MENU_AUTHORS_UNKNOWN);
}
return key;
}
@Override
- protected int loadData(DefaultMutableTreeNode root, List<String> tags, String filter) {
+ protected int loadData(DefaultMutableTreeNode root, List<String> tags,
+ String filter) {
for (String tag : tags) {
if (checkFilter(filter, tag)) {
- DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode(tag);
+ DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode(
+ tag);
root.add(sourceNode);
}
}
static public JComponent scroll(JComponent pane) {
JScrollPane scroll = new JScrollPane(pane);
scroll.getVerticalScrollBar().setUnitIncrement(16);
- scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ scroll.setHorizontalScrollBarPolicy(
+ JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
return scroll;
}
/**
* Display an error message and log the linked {@link Exception}.
*
- * @param owner the owner of the error (to link the messagebox to it)
- * @param message the message
- * @param title the title of the error message
- * @param e the exception to log if any
+ * @param owner
+ * the owner of the error (to link the messagebox to it)
+ * @param message
+ * the message
+ * @param title
+ * the title of the error message
+ * @param e
+ * the exception to log if any
*/
- static public void error(final Component owner, final String message, final String title, Exception e) {
+ static public void error(final Component owner, final String message,
+ final String title, Exception e) {
Instance.getInstance().getTraceHandler().error(title + ": " + message);
if (e != null) {
Instance.getInstance().getTraceHandler().error(e);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
- JOptionPane.showMessageDialog(owner, message, title, JOptionPane.ERROR_MESSAGE);
+ JOptionPane.showMessageDialog(owner, message, title,
+ JOptionPane.ERROR_MESSAGE);
}
});
}
/**
* Generate a new image.
*
- * @param name the name of the resource
- * @param size the requested size
+ * @param name
+ * the name of the resource
+ * @param size
+ * the requested size
*
* @return the image, or NULL if it does not exist or does not exist at that
* 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 = String.format("%s-%dx%d.png", name.name(), size.getSize(),
+ size.getSize());
if (!map.containsKey(key)) {
map.put(key, generate(key));
}
/**
* Generate a new image.
*
- * @param filename the file name of the resource (no directory)
+ * @param filename
+ * the file name of the resource (no directory)
*
* @return the image, or NULL if it does not exist or does not exist at that
* size
*/
static private ImageIcon generate(String filename) {
try {
- InputStream in = IOUtils.openResource(IconGenerator.class, filename);
+ InputStream in = IOUtils.openResource(IconGenerator.class,
+ filename);
if (in != null) {
try {
return new ImageIcon(IOUtils.toByteArray(in));