From: Niki Roo Date: Thu, 9 Apr 2020 16:41:31 +0000 (+0200) Subject: reformat X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=32ed608959c0dec74660388248831976b97e8c56;p=nikiroo-utils.git reformat --- diff --git a/src/be/nikiroo/fanfix_swing/Actions.java b/src/be/nikiroo/fanfix_swing/Actions.java index 5df9b2e..10c79dd 100644 --- a/src/be/nikiroo/fanfix_swing/Actions.java +++ b/src/be/nikiroo/fanfix_swing/Actions.java @@ -28,8 +28,8 @@ import be.nikiroo.fanfix_swing.gui.utils.UiHelper; 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(); @@ -82,7 +82,8 @@ public class Actions { 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) { @@ -102,21 +103,26 @@ public class Actions { } /** - * 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()) { @@ -127,35 +133,46 @@ public class Actions { } /** - * 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) { @@ -171,17 +188,20 @@ public class Actions { *

* 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 } @@ -192,8 +212,10 @@ public class Actions { } 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(); @@ -211,12 +233,15 @@ public class Actions { *

* 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); @@ -229,7 +254,8 @@ public class Actions { 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; @@ -243,14 +269,20 @@ public class Actions { 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) { @@ -258,7 +290,7 @@ public class Actions { } } pgOnSuccess.done(); - + return null; } }.execute(); diff --git a/src/be/nikiroo/fanfix_swing/Main.java b/src/be/nikiroo/fanfix_swing/Main.java index c3d87a1..cf83537 100644 --- a/src/be/nikiroo/fanfix_swing/Main.java +++ b/src/be/nikiroo/fanfix_swing/Main.java @@ -27,7 +27,8 @@ public class Main { @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; diff --git a/src/be/nikiroo/fanfix_swing/gui/BrowserPanel.java b/src/be/nikiroo/fanfix_swing/gui/BrowserPanel.java index c8b1713..ac7eaff 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BrowserPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/BrowserPanel.java @@ -34,30 +34,30 @@ public class BrowserPanel extends ListenerPanel { /** * 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"; @@ -131,7 +131,8 @@ public class BrowserPanel extends ListenerPanel { } } - 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()); @@ -139,7 +140,8 @@ public class BrowserPanel extends ListenerPanel { 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) { @@ -153,8 +155,8 @@ public class BrowserPanel extends ListenerPanel { * Get the {@link BookInfo} to highlight, even if none or more than one are * selected. *

- * 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 */ @@ -163,7 +165,8 @@ public class BrowserPanel extends ListenerPanel { Component selectedTab = tabs.getSelectedComponent(); if (selectedTab instanceof BasicTab) { @SuppressWarnings({ "unchecked", "rawtypes" }) - List selectedAll = ((BasicTab) selectedTab).getSelectedElements(); + List selectedAll = ((BasicTab) selectedTab) + .getSelectedElements(); if (!selectedAll.isEmpty()) { selected1 = selectedAll.get(0); } diff --git a/src/be/nikiroo/fanfix_swing/gui/DetailsPanel.java b/src/be/nikiroo/fanfix_swing/gui/DetailsPanel.java index 751e37f..e3185a6 100644 --- a/src/be/nikiroo/fanfix_swing/gui/DetailsPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/DetailsPanel.java @@ -60,8 +60,10 @@ public class DetailsPanel extends JPanel { /** * 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 */ @@ -76,7 +78,8 @@ public class DetailsPanel extends JPanel { /** * 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; @@ -86,7 +89,8 @@ public class DetailsPanel extends JPanel { 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(); @@ -101,7 +105,8 @@ public class DetailsPanel extends JPanel { 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; diff --git a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java index 39762a8..9d25169 100644 --- a/src/be/nikiroo/fanfix_swing/gui/MainFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/MainFrame.java @@ -52,7 +52,9 @@ public class MainFrame extends JFrame { 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()); } }); @@ -70,10 +72,12 @@ public class MainFrame extends JFrame { 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); @@ -96,7 +100,8 @@ public class MainFrame extends JFrame { @Override public void run() { browser.reloadData(); - books.load(browser.getSelectedSources(), browser.getSelectedAuthors(), + books.load(browser.getSelectedSources(), + browser.getSelectedAuthors(), browser.getSelectedTags()); details.setBook(browser.getHighlight()); } @@ -112,7 +117,8 @@ public class MainFrame extends JFrame { @Override public void run() { browser.reloadData(); - books.load(browser.getSelectedSources(), browser.getSelectedAuthors(), + books.load(browser.getSelectedSources(), + browser.getSelectedAuthors(), browser.getSelectedTags()); details.setBook(browser.getHighlight()); } diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookBlock.java b/src/be/nikiroo/fanfix_swing/gui/book/BookBlock.java index 8c83144..595f42b 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookBlock.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookBlock.java @@ -21,7 +21,8 @@ import be.nikiroo.fanfix_swing.gui.BooksPanel; */ 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; @@ -29,8 +30,10 @@ public class BookBlock extends BookLine { /** * 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); @@ -43,7 +46,8 @@ public class BookBlock extends BookLine { 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)); @@ -55,7 +59,8 @@ public class BookBlock extends BookLine { * 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; @@ -64,32 +69,41 @@ public class BookBlock extends BookLine { @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( - "" + "" + "%s" + "
" - + "" + "%s" + "" + "" + "", - 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("" + + "" + + "%s" + "
" + "" + "%s" + "" + + "" + "", 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); } } diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookCoverImager.java b/src/be/nikiroo/fanfix_swing/gui/book/BookCoverImager.java index 95e0aab..3c92694 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookCoverImager.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookCoverImager.java @@ -38,15 +38,16 @@ class BookCoverImager { 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) { @@ -61,17 +62,23 @@ class BookCoverImager { } /** - * 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; @@ -92,12 +99,16 @@ class BookCoverImager { 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)); @@ -106,7 +117,8 @@ class BookCoverImager { 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); } /** @@ -130,12 +142,15 @@ class BookCoverImager { /** * 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); @@ -157,21 +172,26 @@ class BookCoverImager { 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 { @@ -201,7 +221,8 @@ class BookCoverImager { /** * 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); @@ -209,14 +230,16 @@ class BookCoverImager { } /** - * 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; } } diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookInfo.java b/src/be/nikiroo/fanfix_swing/gui/book/BookInfo.java index 72aee90..bde9abb 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookInfo.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookInfo.java @@ -21,8 +21,8 @@ import be.nikiroo.utils.StringUtils; */ 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 */ @@ -30,8 +30,8 @@ public class BookInfo { /** 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. */ @@ -52,10 +52,13 @@ public class BookInfo { /** * 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; @@ -73,12 +76,12 @@ public class BookInfo { } /** - * 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...). *

- * 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 */ @@ -93,7 +96,8 @@ public class BookInfo { /** * 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 */ @@ -131,7 +135,8 @@ public class BookInfo { /** * 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; @@ -156,11 +161,14 @@ public class BookInfo { *

* 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) { @@ -186,7 +194,7 @@ public class BookInfo { return null; } - + /** * This {@link BookInfo} could have a cover (so we need to somehow represent * that to the user). @@ -200,9 +208,11 @@ public class BookInfo { /** * 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 */ @@ -221,7 +231,8 @@ public class BookInfo { 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 }); } @@ -237,14 +248,17 @@ public class BookInfo { /** * 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 { @@ -254,7 +268,8 @@ public class BookInfo { 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 }); } @@ -264,14 +279,17 @@ public class BookInfo { /** * 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 { @@ -281,7 +299,8 @@ public class BookInfo { 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 }); } @@ -291,14 +310,17 @@ public class BookInfo { /** * 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 { @@ -308,7 +330,8 @@ public class BookInfo { 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 }); } diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java b/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java index beb4c97..f7926a0 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookLine.java @@ -38,8 +38,10 @@ public class BookLine extends JPanel { /** * 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; @@ -92,7 +94,8 @@ public class BookLine extends JPanel { /** * 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) { @@ -113,7 +116,8 @@ public class BookLine extends JPanel { /** * 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) { @@ -134,7 +138,8 @@ public class BookLine extends JPanel { /** * 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) { @@ -172,11 +177,13 @@ public class BookLine extends JPanel { 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(); } } diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java b/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java index c99e273..eccdde5 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java @@ -113,7 +113,8 @@ public class BookPopup extends JPopupMenu { item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - ConfigEditor ed = new ConfigEditor(Config.class, Instance.getInstance().getConfig(), + ConfigEditor ed = new ConfigEditor(Config.class, + Instance.getInstance().getConfig(), trans(StringIdGui.SUBTITLE_CONFIG)); JFrame frame = new JFrame(title); frame.add(ed); @@ -138,8 +139,9 @@ public class BookPopup extends JPopupMenu { item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - ConfigEditor ed = new ConfigEditor(UiConfig.class, - Instance.getInstance().getUiConfig(), trans(StringIdGui.SUBTITLE_CONFIG_UI)); + ConfigEditor ed = new ConfigEditor( + UiConfig.class, Instance.getInstance().getUiConfig(), + trans(StringIdGui.SUBTITLE_CONFIG_UI)); JFrame frame = new JFrame(title); frame.add(ed); frame.setSize(800, 600); @@ -180,22 +182,28 @@ public class BookPopup extends JPopupMenu { } // - 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() { @Override protected Void doInBackground() throws Exception { - lib.export(book.getMeta().getLuid(), type, path, pg); + lib.export(book.getMeta().getLuid(), type, path, + pg); return null; } @@ -204,8 +212,9 @@ public class BookPopup extends JPopupMenu { try { get(); } catch (Exception e) { - UiHelper.error(BookPopup.this.getParent(), e.getLocalizedMessage(), "IOException", - e); + UiHelper.error(BookPopup.this.getParent(), + e.getLocalizedMessage(), + "IOException", e); } } }.execute(); @@ -221,7 +230,8 @@ public class BookPopup extends JPopupMenu { * Create a {@link FileFilter} that accepts all files and return the given * description. * - * @param desc the description + * @param desc + * the description * * @return the filter */ @@ -245,7 +255,8 @@ public class BookPopup extends JPopupMenu { * @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) { @@ -269,7 +280,9 @@ public class BookPopup extends JPopupMenu { 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(); @@ -293,10 +306,12 @@ public class BookPopup extends JPopupMenu { 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(); @@ -305,7 +320,8 @@ public class BookPopup extends JPopupMenu { List 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); @@ -318,7 +334,8 @@ public class BookPopup extends JPopupMenu { } item = new JMenuItem(itemName); - item.addActionListener(createMoveAction(ChangeAction.SOURCE, actualType)); + item.addActionListener( + createMoveAction(ChangeAction.SOURCE, actualType)); dir.add(item); } changeTo.add(dir); @@ -338,7 +355,8 @@ public class BookPopup extends JPopupMenu { 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)); @@ -349,7 +367,8 @@ public class BookPopup extends JPopupMenu { 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>(); } @@ -358,16 +377,22 @@ public class BookPopup extends JPopupMenu { 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); } } @@ -387,7 +412,8 @@ public class BookPopup extends JPopupMenu { 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) { @@ -408,8 +434,10 @@ public class BookPopup extends JPopupMenu { } } - 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) { @@ -440,16 +468,22 @@ public class BookPopup extends JPopupMenu { @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(); @@ -464,22 +498,24 @@ public class BookPopup extends JPopupMenu { * @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)); + // } } }); @@ -492,7 +528,8 @@ public class BookPopup extends JPopupMenu { * @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) { @@ -509,17 +546,20 @@ public class BookPopup extends JPopupMenu { 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; @@ -547,7 +587,8 @@ public class BookPopup extends JPopupMenu { 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(); @@ -563,28 +604,33 @@ public class BookPopup extends JPopupMenu { * @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(); + // } + // }); + // } + // } } }); @@ -597,20 +643,23 @@ public class BookPopup extends JPopupMenu { * @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); + // } + // }); + // } } }); @@ -623,18 +672,20 @@ public class BookPopup extends JPopupMenu { * @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); + } + }); } } }); @@ -643,30 +694,35 @@ public class BookPopup extends JPopupMenu { } /** - * 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); + // } } }); @@ -674,29 +730,34 @@ public class BookPopup extends JPopupMenu { } /** - * 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); + // } } }); diff --git a/src/be/nikiroo/fanfix_swing/gui/browser/AuthorTab.java b/src/be/nikiroo/fanfix_swing/gui/browser/AuthorTab.java index f93b1d4..0323b77 100644 --- a/src/be/nikiroo/fanfix_swing/gui/browser/AuthorTab.java +++ b/src/be/nikiroo/fanfix_swing/gui/browser/AuthorTab.java @@ -21,7 +21,8 @@ public class AuthorTab extends BasicTab> { @Override protected void fillData(List data) { try { - List authors = Instance.getInstance().getLibrary().getAuthors(); + List authors = Instance.getInstance().getLibrary() + .getAuthors(); for (String author : authors) { data.add(author); } @@ -39,17 +40,20 @@ public class AuthorTab extends BasicTab> { @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 authors, String filter) { + protected int loadData(DefaultMutableTreeNode root, List authors, + String filter) { for (String author : authors) { if (checkFilter(filter, author)) { - DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode(author); + DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode( + author); root.add(sourceNode); } } diff --git a/src/be/nikiroo/fanfix_swing/gui/browser/BasicTab.java b/src/be/nikiroo/fanfix_swing/gui/browser/BasicTab.java index 86b4a02..e89acc3 100644 --- a/src/be/nikiroo/fanfix_swing/gui/browser/BasicTab.java +++ b/src/be/nikiroo/fanfix_swing/gui/browser/BasicTab.java @@ -53,7 +53,8 @@ public abstract class BasicTab extends ListenerPanel { 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); @@ -103,18 +104,21 @@ public abstract class BasicTab extends ListenerPanel { 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>, Integer> worker = new SwingWorker>, Integer>() { @Override - protected Map> doInBackground() throws Exception { + protected Map> doInBackground() + throws Exception { fillData(data); return null; } @@ -165,7 +169,8 @@ public abstract class BasicTab extends ListenerPanel { String count = ""; if (totalCount > 0) { int selected = selectedElements.size(); - count = " (" + (selected > 0 ? selected + "/" : "") + totalCount + ")"; + count = " (" + (selected > 0 ? selected + "/" : "") + totalCount + + ")"; } return title + count; @@ -180,7 +185,8 @@ public abstract class BasicTab extends ListenerPanel { } 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 list) { @@ -199,12 +205,14 @@ public abstract class BasicTab extends ListenerPanel { 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) { @@ -218,7 +226,8 @@ public abstract class BasicTab extends ListenerPanel { 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); } }; diff --git a/src/be/nikiroo/fanfix_swing/gui/browser/SourceTab.java b/src/be/nikiroo/fanfix_swing/gui/browser/SourceTab.java index ffa5e41..8ac5c1e 100644 --- a/src/be/nikiroo/fanfix_swing/gui/browser/SourceTab.java +++ b/src/be/nikiroo/fanfix_swing/gui/browser/SourceTab.java @@ -21,7 +21,8 @@ public class SourceTab extends BasicTab>> { @Override protected void fillData(Map> data) { try { - Map> sourcesGrouped = Instance.getInstance().getLibrary().getSourcesGrouped(); + Map> sourcesGrouped = Instance.getInstance() + .getLibrary().getSourcesGrouped(); for (String group : sourcesGrouped.keySet()) { data.put(group, sourcesGrouped.get(group)); } @@ -62,22 +63,30 @@ public class SourceTab extends BasicTab>> { } @Override - protected int loadData(DefaultMutableTreeNode root, Map> sourcesGrouped, String filter) { + protected int loadData(DefaultMutableTreeNode root, + Map> 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 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)); } } } diff --git a/src/be/nikiroo/fanfix_swing/gui/browser/TagsTab.java b/src/be/nikiroo/fanfix_swing/gui/browser/TagsTab.java index 90c8219..49fcc27 100644 --- a/src/be/nikiroo/fanfix_swing/gui/browser/TagsTab.java +++ b/src/be/nikiroo/fanfix_swing/gui/browser/TagsTab.java @@ -23,7 +23,8 @@ public class TagsTab extends BasicTab> { @Override protected void fillData(List data) { try { - MetaResultList metas = Instance.getInstance().getLibrary().getList(); + MetaResultList metas = Instance.getInstance().getLibrary() + .getList(); // TODO: getTagList, getAuthorList... ? for (MetaData meta : metas.getMetas()) { List tags = meta.getTags(); @@ -50,17 +51,20 @@ public class TagsTab extends BasicTab> { 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 tags, String filter) { + protected int loadData(DefaultMutableTreeNode root, List tags, + String filter) { for (String tag : tags) { if (checkFilter(filter, tag)) { - DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode(tag); + DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode( + tag); root.add(sourceNode); } } diff --git a/src/be/nikiroo/fanfix_swing/gui/utils/UiHelper.java b/src/be/nikiroo/fanfix_swing/gui/utils/UiHelper.java index 5d23ab5..08a65b0 100644 --- a/src/be/nikiroo/fanfix_swing/gui/utils/UiHelper.java +++ b/src/be/nikiroo/fanfix_swing/gui/utils/UiHelper.java @@ -40,19 +40,25 @@ public class UiHelper { 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); @@ -61,7 +67,8 @@ public class UiHelper { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - JOptionPane.showMessageDialog(owner, message, title, JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(owner, message, title, + JOptionPane.ERROR_MESSAGE); } }); } diff --git a/src/be/nikiroo/fanfix_swing/images/IconGenerator.java b/src/be/nikiroo/fanfix_swing/images/IconGenerator.java index 780b1bb..c8d126a 100644 --- a/src/be/nikiroo/fanfix_swing/images/IconGenerator.java +++ b/src/be/nikiroo/fanfix_swing/images/IconGenerator.java @@ -79,14 +79,17 @@ public class IconGenerator { /** * 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)); } @@ -97,14 +100,16 @@ public class IconGenerator { /** * 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));