PREFIX=/usr/local
PROGS="java javac jar make sed"
-CLI=be/nikiroo/fanfix/reader/CliReader
+CLI=be/nikiroo/fanfix/reader/cli/CliReader
TUI=
-GUI=be/nikiroo/fanfix/reader/GuiReader
+GUI=be/nikiroo/fanfix/reader/ui/GuiReader
JCLI=
JTUI=
JGUI=
--tui) #=yes Enable TUI support (Jexer, experimental)
[ "$val" = no -o "$val" = false ] && TUI= && JTUI=
if [ "$val" = yes -o "$val" = true ]; then
- TUI=be/nikiroo/fanfix/reader/TuiReader
+ TUI=be/nikiroo/fanfix/reader/tui/TuiReader
JTUI="-C bin/ jexer"
fi
;;
package be.nikiroo.fanfix;
-import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Map;
-import javax.imageio.ImageIO;
-
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.supported.BasicSupport;
import be.nikiroo.utils.Cache;
import be.nikiroo.utils.Downloader;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.ImageUtils;
/**
public DataLoader(File dir, String UA, int hoursChanging, int hoursStable)
throws IOException {
cache = new Cache(dir, hoursChanging, hoursStable);
+ cache.setTraceHandler(Instance.getTraceHandler());
downloader = new Downloader(UA);
+ downloader.setTraceHandler(Instance.getTraceHandler());
}
/**
/**
* Save the given resource as an image on disk using the default image
- * format for content.
+ * format for content or cover -- will automatically add the extension, too.
*
- * @param url
+ * @param img
* the resource
* @param target
- * the target file
+ * the target file without extension
+ * @param cover
+ * use the cover image format instead of the content image format
*
* @throws IOException
* in case of I/O error
*/
- public void saveAsImage(URL url, File target) throws IOException {
- InputStream in = open(url, null, true);
- try {
- saveAsImage(ImageUtils.fromStream(in), target);
- } finally {
- in.close();
+ public void saveAsImage(Image img, File target, boolean cover)
+ throws IOException {
+ String format;
+ if (cover) {
+ format = Instance.getConfig().getString(Config.IMAGE_FORMAT_COVER)
+ .toLowerCase();
+ } else {
+ format = Instance.getConfig()
+ .getString(Config.IMAGE_FORMAT_CONTENT).toLowerCase();
}
+ saveAsImage(img, new File(target.toString() + "." + format), format);
}
/**
- * Save the given resource as an image on disk using the default image
- * format for content.
+ * Save the given resource as an image on disk using the given image format
+ * for content, or with "png" format if it fails.
*
- * @param image
+ * @param img
* the resource
* @param target
* the target file
+ * @param format
+ * the file format ("png", "jpeg", "bmp"...)
*
* @throws IOException
* in case of I/O error
*/
- public void saveAsImage(BufferedImage image, File target)
+ public void saveAsImage(Image img, File target, String format)
throws IOException {
- try {
- String format = Instance.getConfig()
- .getString(Config.IMAGE_FORMAT_CONTENT).toLowerCase();
-
- boolean ok = false;
- try {
- ok = ImageIO.write(image, format, target);
- } catch (IOException e) {
- ok = false;
- }
-
- // Some formats are not reliable
- // Second change: PNG
- if (!ok && !format.equals("png")) {
- ok = ImageIO.write(image, "png", target);
- }
+ ImageUtils.getInstance().saveAsImage(img, target, format);
- if (!ok) {
- throw new IOException(
- "Cannot find a writer for this image and format: "
- + format);
- }
- } catch (IOException e) {
- throw new IOException("Cannot write image to " + target, e);
- }
}
/**
package be.nikiroo.fanfix.data;
-import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
+import be.nikiroo.utils.Image;
+
/**
* The meta data associated to a {@link Story} object.
*
private String date;
private Chapter resume;
private List<String> tags;
- private BufferedImage cover;
+ private Image cover;
private String subject;
private String source;
private String url;
*
* @return the cover
*/
- public BufferedImage getCover() {
+ public Image getCover() {
return cover;
}
* @param cover
* the cover to set
*/
- public void setCover(BufferedImage cover) {
+ public void setCover(Image cover) {
this.cover = cover;
}
package be.nikiroo.fanfix.data;
-import java.awt.image.BufferedImage;
+import be.nikiroo.utils.Image;
/**
* A paragraph in a chapter of the story.
private ParagraphType type;
private String content;
- private BufferedImage contentImage;
+ private Image contentImage;
private long words;
/**
* @param contentImage
* the image
*/
- public Paragraph(BufferedImage contentImage) {
+ public Paragraph(Image contentImage) {
this(ParagraphType.IMAGE, null, 1);
this.contentImage = contentImage;
}
*
* @return the content
*/
- public BufferedImage getContentImage() {
+ public Image getContentImage() {
return contentImage;
}
resume += "\n";
}
- String cover = (meta == null || meta.getCover() == null) ? "none"
- : meta.getCover().getWidth() + "x"
- + meta.getCover().getHeight();
+ String cover = "none";
+ if (meta != null && meta.getCover() != null) {
+ cover = " bytes";
+
+ int size = meta.getCover().getData().length;
+ if (size > 1000) {
+ size /= 1000;
+ cover = " kb";
+ if (size > 1000) {
+ size /= 1000;
+ cover = " mb";
+ }
+ }
+
+ cover = size + cover;
+ }
return String.format(
"Title: [%s]\nAuthor: [%s]\nDate: [%s]\nTags: [%s]\n"
+ "Resume: [%s]\nCover: [%s]", title, meta == null ? ""
package be.nikiroo.fanfix.library;
-import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import be.nikiroo.fanfix.output.BasicOutput.OutputType;
import be.nikiroo.fanfix.supported.BasicSupport;
import be.nikiroo.fanfix.supported.BasicSupport.SupportType;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
/**
*
* @return the cover image
*/
- public abstract BufferedImage getCover(String luid);
+ public abstract Image getCover(String luid);
/**
* Return the cover image associated to this source.
*
* @return the cover image or NULL
*/
- public BufferedImage getSourceCover(String source) {
+ public Image getSourceCover(String source) {
List<MetaData> metas = getListBySource(source);
if (metas.size() > 0) {
return getCover(metas.get(0).getLuid());
package be.nikiroo.fanfix.library;
-import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import be.nikiroo.fanfix.bundles.UiConfig;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
/**
}
@Override
- public BufferedImage getCover(final String luid) {
+ public Image getCover(final String luid) {
if (isCached(luid)) {
return cacheLib.getCover(luid);
}
}
@Override
- public BufferedImage getSourceCover(String source) {
+ public Image getSourceCover(String source) {
// no cache for the source cover
return lib.getSourceCover(source);
}
package be.nikiroo.fanfix.library;
-import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.util.List;
import java.util.Map;
-import javax.imageio.ImageIO;
-
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.output.InfoCover;
import be.nikiroo.fanfix.supported.InfoReader;
import be.nikiroo.utils.IOUtils;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.MarkableFileInputStream;
import be.nikiroo.utils.Progress;
public class LocalLibrary extends BasicLibrary {
private int lastId;
private Map<MetaData, File[]> stories; // Files: [ infoFile, TargetFile ]
- private Map<String, BufferedImage> sourceCovers;
+ private Map<String, Image> sourceCovers;
private File baseDir;
private OutputType text;
this.lastId = 0;
this.stories = null;
- this.sourceCovers = new HashMap<String, BufferedImage>();
+ this.sourceCovers = new HashMap<String, Image>();
baseDir.mkdirs();
}
}
@Override
- public BufferedImage getCover(String luid) {
+ public Image getCover(String luid) {
MetaData meta = getInfo(luid);
if (meta != null) {
File[] files = getStories(null).get(meta);
@Override
protected void invalidateInfo(String luid) {
stories = null;
- sourceCovers = new HashMap<String, BufferedImage>();
+ sourceCovers = new HashMap<String, Image>();
}
@Override
}
@Override
- public BufferedImage getSourceCover(String source) {
+ public Image getSourceCover(String source) {
if (!sourceCovers.containsKey(source)) {
sourceCovers.put(source, super.getSourceCover(source));
}
sourceCovers.put(source, getCover(luid));
File cover = new File(getExpectedDir(source), ".cover.png");
try {
- ImageIO.write(sourceCovers.get(source), "png", cover);
+ Instance.getCache().saveAsImage(sourceCovers.get(source), cover,
+ true);
} catch (IOException e) {
Instance.getTraceHandler().error(e);
sourceCovers.remove(source);
File cover = new File(dir, ".cover.png");
if (cover.exists()) {
try {
- InputStream in = new MarkableFileInputStream(
- new FileInputStream(cover));
+ InputStream in = new FileInputStream(cover);
try {
- sourceCovers.put(source, ImageUtils.fromStream(in));
+ sourceCovers.put(source, new Image(in));
} finally {
in.close();
}
* @param coverImage
* the cover image
*/
- void setSourceCover(String source, BufferedImage coverImage) {
+ void setSourceCover(String source, Image coverImage) {
sourceCovers.put(source, coverImage);
File cover = new File(getExpectedDir(source), ".cover.png");
try {
- ImageIO.write(sourceCovers.get(source), "png", cover);
+ Instance.getCache().saveAsImage(sourceCovers.get(source), cover,
+ true);
} catch (IOException e) {
Instance.getTraceHandler().error(e);
sourceCovers.remove(source);
package be.nikiroo.fanfix.library;
-import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.StringUtils;
import be.nikiroo.utils.Version;
}
@Override
- public BufferedImage getCover(final String luid) {
- final BufferedImage[] result = new BufferedImage[1];
+ public Image getCover(final String luid) {
+ final Image[] result = new Image[1];
try {
new ConnectActionClientObject(host, port, true) {
@Override
public void action(Version serverVersion) throws Exception {
Object rep = send(new Object[] { md5, "GET_COVER", luid });
- result[0] = (BufferedImage) rep;
+ result[0] = (Image) rep;
}
@Override
}
@Override
- public BufferedImage getSourceCover(final String source) {
- final BufferedImage[] result = new BufferedImage[1];
+ public Image getSourceCover(final String source) {
+ final Image[] result = new Image[1];
try {
new ConnectActionClientObject(host, port, true) {
public void action(Version serverVersion) throws Exception {
Object rep = send(new Object[] { md5, "GET_SOURCE_COVER",
source });
- result[0] = (BufferedImage) rep;
+ result[0] = (Image) rep;
}
@Override
int num = 0;
String paragraphNumber = String.format("%04d", num++);
- imageName = chapterNameNum + "_" + paragraphNumber + ".png";
+ imageName = chapterNameNum + "_" + paragraphNumber;
writeChapterHeader(chap);
int i = 1;
for (Paragraph para : chap) {
paragraphNumber = String.format("%04d", num++);
- imageName = chapterNameNum + "_" + paragraphNumber + ".png";
+ imageName = chapterNameNum + "_" + paragraphNumber;
writeParagraph(para);
if (chapPg != null) {
chapPg.setProgress(i++);
import java.io.InputStream;
import java.io.OutputStreamWriter;
-import javax.imageio.ImageIO;
-
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.bundles.StringId;
private boolean inDialogue = false;
private boolean inNormal = false;
private File images;
+ private boolean nextParaIsCover = true;
@Override
public File process(Story story, File targetDir, String targetName)
String format = Instance.getConfig()
.getString(Config.IMAGE_FORMAT_COVER).toLowerCase();
File file = new File(images, "cover." + format);
- ImageIO.write(story.getMeta().getCover(), format, file);
+ Instance.getCache().saveAsImage(story.getMeta().getCover(), file,
+ true);
}
// OPS/* except chapters
break;
case IMAGE:
File file = new File(images, getCurrentImageBestName(false));
- Instance.getCache().saveAsImage(para.getContentImage(), file);
+ Instance.getCache().saveAsImage(para.getContentImage(), file,
+ nextParaIsCover);
writer.write(" <img class='page-image' src='images/"
+ getCurrentImageBestName(false) + "'/>");
break;
}
+
+ nextParaIsCover = false;
}
@Override
import java.io.InputStream;
import java.io.OutputStreamWriter;
-import javax.imageio.ImageIO;
-
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.data.Chapter;
writer = null;
}
- String format = Instance.getConfig()
- .getString(Config.IMAGE_FORMAT_COVER).toLowerCase();
if (story.getMeta().getCover() != null) {
- ImageIO.write(story.getMeta().getCover(), format, new File(dir,
- "cover." + format));
+ Instance.getCache().saveAsImage(story.getMeta().getCover(),
+ new File(dir, "cover"), true);
}
return target;
import java.io.IOException;
import java.io.OutputStreamWriter;
-import javax.imageio.ImageIO;
-
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.data.MetaData;
MetaData meta) {
if (meta != null && meta.getCover() != null) {
try {
- String format = Instance.getConfig()
- .getString(Config.IMAGE_FORMAT_COVER).toLowerCase();
- ImageIO.write(meta.getCover(), format, new File(targetDir,
- targetName + "." + format));
+ Instance.getCache().saveAsImage(meta.getCover(),
+ new File(targetDir, targetName), true);
} catch (IOException e) {
// Allow to continue without cover
Instance.getTraceHandler().error(
class Text extends BasicOutput {
protected BufferedWriter writer;
protected File targetDir;
+ private boolean nextParaIsCover = true;
@Override
public File process(Story story, File targetDir, String targetName)
protected void writeParagraphHeader(Paragraph para) throws IOException {
if (para.getType() == ParagraphType.IMAGE) {
File file = new File(targetDir, getCurrentImageBestName(true));
- Instance.getCache().saveAsImage(para.getContentImage(), file);
+ Instance.getCache().saveAsImage(para.getContentImage(), file,
+ nextParaIsCover);
}
+
+ nextParaIsCover = false;
}
@Override
package be.nikiroo.fanfix.reader;
-import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
.getTypeName());
}
} catch (Exception e) {
- Instance.getTraceHandler().error(new Exception("Cannot create a reader of type: "
- + defaultType + " (Not compiled in?)", e));
+ Instance.getTraceHandler().error(
+ new Exception("Cannot create a reader of type: "
+ + defaultType + " (Not compiled in?)", e));
}
return null;
* @throws IOException
* in case of I/O error
*/
- public static void openExternal(BasicLibrary lib, String luid)
- throws IOException {
+ @Override
+ public void openExternal(BasicLibrary lib, String luid) throws IOException {
MetaData meta = lib.getInfo(luid);
File target = lib.getFile(luid, null);
* @throws IOException
* in case of I/O error
*/
- protected static void openExternal(MetaData meta, File target)
- throws IOException {
+ protected void openExternal(MetaData meta, File target) throws IOException {
String program = null;
if (meta.isImageDocument()) {
program = Instance.getUiConfig().getString(
program = null;
}
- if (program == null) {
- try {
- Desktop.getDesktop().browse(target.toURI());
- } catch (UnsupportedOperationException e) {
- Runtime.getRuntime().exec(
- new String[] { "xdg-open", target.getAbsolutePath() });
+ start(target, program);
+ }
+ /**
+ * 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
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ protected void start(File target, String program) throws IOException {
+ if (program == null) {
+ boolean ok = false;
+ for (String starter : new String[] { "xdg-open", "start", "run" }) {
+ try {
+ 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");
}
} else {
Runtime.getRuntime().exec(
String pkg = "be.nikiroo.fanfix.reader.";
switch (this) {
case CLI:
- return pkg + "CliReader";
+ return pkg + "cli.CliReader";
case TUI:
- return pkg + "TuiReader";
+ return pkg + "tui.TuiReader";
case GUI:
- return pkg + "GuiReader";
+ return pkg + "ui.GuiReader";
}
return null;
* all
*/
public void browse(String source);
+
+ /**
+ * Open the {@link Story} with an external reader (the program will be
+ * passed the main file associated with this {@link Story}).
+ *
+ * @param lib
+ * the {@link BasicLibrary} to select the {@link Story} from
+ * @param luid
+ * the {@link Story} LUID
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public void openExternal(BasicLibrary lib, String luid) throws IOException;
}
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.cli;
import java.io.IOException;
import java.util.List;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Paragraph;
import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.fanfix.reader.BasicReader;
/**
* Command line {@link Story} reader.
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.tui;
import java.io.IOException;
import jexer.TApplication;
import jexer.TApplication.BackendType;
import be.nikiroo.fanfix.Instance;
+import be.nikiroo.fanfix.reader.BasicReader;
+import be.nikiroo.fanfix.reader.Reader;
/**
* This {@link Reader}is based upon the TUI widget library 'jexer'
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.tui;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.library.BasicLibrary;
+import be.nikiroo.fanfix.reader.BasicReader;
+import be.nikiroo.fanfix.reader.Reader;
import be.nikiroo.utils.Progress;
/**
getChapter());
} else {
try {
- BasicReader.openExternal(getLibrary(), meta.getLuid());
+ openExternal(getLibrary(), meta.getLuid());
} catch (IOException e) {
messageBox("Error when trying to open the story",
e.getMessage(), TMessageBox.Type.OK);
return false;
}
}
+
+ @Override
+ public void openExternal(BasicLibrary lib, String luid) throws IOException {
+ reader.openExternal(lib, luid);
+ }
}
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.tui;
import java.io.IOException;
import java.util.ArrayList;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.library.BasicLibrary;
import be.nikiroo.fanfix.output.BasicOutput.OutputType;
+import be.nikiroo.fanfix.reader.Reader;
/**
* The library window, that will list all the (filtered) stories available in
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.tui;
import java.util.ArrayList;
import java.util.List;
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.ui;
import java.awt.Desktop;
import java.awt.EventQueue;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.library.BasicLibrary;
import be.nikiroo.fanfix.library.CacheLibrary;
+import be.nikiroo.fanfix.reader.BasicReader;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.Version;
import be.nikiroo.utils.ui.UIUtils;
});
}
+ @Override
+ public void start(File target, String program) throws IOException {
+ if (program == null) {
+ try {
+ Desktop.getDesktop().browse(target.toURI());
+ } catch (UnsupportedOperationException e) {
+ super.start(target, program);
+ }
+ } else {
+ super.start(target, program);
+ }
+ }
+
// delete from local reader library
void clearLocalReaderCache(String luid) {
try {
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.fanfix.reader.Reader;
+import be.nikiroo.utils.Image;
+import be.nikiroo.utils.ui.ImageUtilsAwt;
import be.nikiroo.utils.ui.UIUtils;
/**
InputStream in = Instance.getCache().getFromCache(id);
if (in != null) {
try {
- resizedImage = ImageUtils.fromStream(in);
+ resizedImage = ImageUtilsAwt.fromImage(new Image(in));
in.close();
in = null;
} catch (IOException e) {
if (resizedImage == null) {
try {
- BufferedImage cover = null;
+ Image cover = null;
if (meta.getLuid() == null) {
cover = reader.getLibrary()
.getSourceCover(meta.getSource());
cover = reader.getLibrary().getCover(meta.getLuid());
}
+ BufferedImage coverb = ImageUtilsAwt.fromImage(cover);
+
resizedImage = new BufferedImage(SPINE_WIDTH + COVER_WIDTH,
SPINE_HEIGHT + COVER_HEIGHT + HOFFSET,
BufferedImage.TYPE_4BYTE_ABGR);
g.setColor(Color.white);
g.fillRect(0, HOFFSET, COVER_WIDTH, COVER_HEIGHT);
if (cover != null) {
- g.drawImage(cover, 0, HOFFSET, COVER_WIDTH, COVER_HEIGHT,
+ g.drawImage(coverb, 0, HOFFSET, COVER_WIDTH, COVER_HEIGHT,
null);
} else {
g.setColor(Color.black);
}
}
- return new ImageIcon(resizedImage);
+ if (resizedImage != null) {
+ return new ImageIcon(resizedImage);
+ }
+
+ return null;
}
/**
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import be.nikiroo.fanfix.library.BasicLibrary.Status;
import be.nikiroo.fanfix.library.LocalLibrary;
import be.nikiroo.fanfix.output.BasicOutput.OutputType;
-import be.nikiroo.fanfix.reader.GuiReaderBook.BookActionListener;
+import be.nikiroo.fanfix.reader.BasicReader;
+import be.nikiroo.fanfix.reader.ui.GuiReaderBook.BookActionListener;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.Version;
import be.nikiroo.utils.ui.ConfigEditor;
pane = new JPanel();
pane.setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS));
- color = Instance.getUiConfig().getColor(UiConfig.BACKGROUND_COLOR);
- if (color != null) {
+ Integer icolor = Instance.getUiConfig().getColor(
+ UiConfig.BACKGROUND_COLOR);
+ if (icolor != null) {
+ color = new Color(icolor);
setBackground(color);
pane.setBackground(color);
}
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JPanel;
import be.nikiroo.fanfix.data.MetaData;
-import be.nikiroo.fanfix.reader.GuiReaderBook.BookActionListener;
+import be.nikiroo.fanfix.reader.ui.GuiReaderBook.BookActionListener;
import be.nikiroo.utils.ui.WrapLayout;
/**
package be.nikiroo.fanfix.supported;
-import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import be.nikiroo.fanfix.data.Paragraph;
import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
import be.nikiroo.fanfix.data.Story;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.StringUtils;
* @return the {@link Paragraph}
*/
private Paragraph makeParagraph(URL source, String line) {
- BufferedImage image = null;
+ Image image = null;
if (line.startsWith("[") && line.endsWith("]")) {
image = getImage(this, source, line.substring(1, line.length() - 1)
.trim());
*
* @return the cover if any, or NULL
*/
- static BufferedImage getDefaultCover(String subject) {
+ static Image getDefaultCover(String subject) {
if (subject != null && !subject.isEmpty()
&& Instance.getCoverDir() != null) {
try {
* @return the image if found, or NULL
*
*/
- static BufferedImage getImage(BasicSupport support, URL source, String line) {
+ static Image getImage(BasicSupport support, URL source, String line) {
URL url = getImageUrl(support, source, line);
if (url != null) {
+ if ("file".equals(url.getProtocol())) {
+ if (new File(url.getPath()).isDirectory()) {
+ return null;
+ }
+ }
InputStream in = null;
try {
in = Instance.getCache().open(url, getSupport(url), true);
- return ImageUtils.fromStream(in);
+ return new Image(in);
} catch (IOException e) {
} finally {
if (in != null) {
}
for (String ext : getImageExt(true)) {
- if (absPath != null && new File(absPath + ext).exists()) {
- url = new File(absPath + ext).toURI().toURL();
- } else if (relPath != null
- && new File(relPath + ext).exists()) {
- url = new File(relPath + ext).toURI().toURL();
+ File absFile = new File(absPath + ext);
+ File relFile = new File(relPath + ext);
+ if (absPath != null && absFile.exists()
+ && absFile.isFile()) {
+ url = absFile.toURI().toURL();
+ } else if (relPath != null && relFile.exists()
+ && relFile.isFile()) {
+ url = relFile.toURI().toURL();
}
}
} catch (Exception e) {
package be.nikiroo.fanfix.supported;
-import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import be.nikiroo.fanfix.data.Chapter;
import be.nikiroo.fanfix.data.Paragraph;
import be.nikiroo.fanfix.data.Story;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
/**
ZipInputStream zipIn = new ZipInputStream(getInput());
- Map<String, BufferedImage> images = new HashMap<String, BufferedImage>();
+ Map<String, Image> images = new HashMap<String, Image>();
for (ZipEntry entry = zipIn.getNextEntry(); entry != null; entry = zipIn
.getNextEntry()) {
if (!entry.isDirectory()
if (imageEntry) {
String uuid = meta.getUuid() + "_" + entry.getName();
try {
- images.put(uuid, ImageUtils.fromStream(zipIn));
+ images.put(uuid, new Image(zipIn));
} catch (Exception e) {
Instance.getTraceHandler().error(e);
}
package be.nikiroo.fanfix.supported;
-import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import be.nikiroo.fanfix.data.Chapter;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.StringUtils;
return true;
}
- private BufferedImage getCover(URL source) throws IOException {
+ private Image getCover(URL source) throws IOException {
InputStream in = Instance.getCache().open(source, this, true);
String images = getChapterContent(new URL(source.toString() + "?page="
+ 1), in, 1, null);
package be.nikiroo.fanfix.supported;
-import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import be.nikiroo.fanfix.data.Chapter;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.StringUtils;
return true;
}
- private BufferedImage getCover(URL source, InputStream in) {
- BufferedImage author = null;
+ private Image getCover(URL source, InputStream in) {
+ Image author = null;
String coverLine = getKeyLine(in, "<div id=\"gd1\"", " url(", ")");
if (coverLine != null) {
coverLine = StringUtils.unhtml(coverLine).trim();
try {
pages.add(new URL(line));
} catch (MalformedURLException e) {
- Instance.getTraceHandler().error(new IOException(
- "Parsing error, a link is not correctly parsed: "
- + line, e));
+ Instance.getTraceHandler().error(
+ new IOException(
+ "Parsing error, a link is not correctly parsed: "
+ + line, e));
}
}
}
package be.nikiroo.fanfix.supported;
-import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.utils.IOUtils;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.MarkableFileInputStream;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.StringUtils;
tmp = File.createTempFile("fanfic-reader-parser_", ".tmp");
File tmpInfo = new File(tmp + ".info");
fakeSource = tmp.toURI().toURL();
- BufferedImage cover = null;
+ Image cover = null;
String url = source.toString();
String title = null;
// Cover
if (getCover()) {
try {
- cover = ImageUtils.fromStream(zipIn);
+ cover = new Image(zipIn);
} catch (Exception e) {
Instance.getTraceHandler().error(e);
}
package be.nikiroo.fanfix.supported;
-import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.StringUtils;
return sdf
.format(new Date(1000 * Long.parseLong(line)));
} catch (NumberFormatException e) {
- Instance.getTraceHandler().error(new IOException(
- "Cannot convert publication date: " + line, e));
+ Instance.getTraceHandler().error(
+ new IOException(
+ "Cannot convert publication date: "
+ + line, e));
}
}
}
return getLine(in, "title=\"Send Private Message\"", 1);
}
- private BufferedImage getCover(URL url, InputStream in) {
+ private Image getCover(URL url, InputStream in) {
String key = "class='cimage";
String line = getLine(in, key, 0);
if (line != null) {
}
});
} catch (MalformedURLException e) {
- Instance.getTraceHandler().error(new IOException(
- "Cannot parse chapter " + i + " url: "
- + (base + i + suffix), e));
+ Instance.getTraceHandler()
+ .error(new IOException(
+ "Cannot parse chapter " + i
+ + " url: "
+ + (base + i + suffix), e));
}
}
}
package be.nikiroo.fanfix.supported;
-import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.StringUtils;
return getLine(in, "class=\"description-text bbcode\"", 1);
}
- private BufferedImage getCover(InputStream in) {
+ private Image getCover(InputStream in) {
// Note: the 'og:image' is the SMALL cover, not the full version
String cover = getLine(in, "class=\"story_container__story_image\"", 1);
if (cover != null) {
meta.setType(getInfoTag(in, "TYPE"));
meta.setImageDocument(getInfoTagBoolean(in, "IMAGES_DOCUMENT", false));
if (withCover) {
- meta.setCover(BasicSupport.getImage(null, sourceInfoFile,
- getInfoTag(in, "COVER")));
+ String infoTag = getInfoTag(in, "COVER");
+ if (infoTag != null && !infoTag.trim().isEmpty()) {
+ meta.setCover(BasicSupport.getImage(null, sourceInfoFile,
+ infoTag));
+ }
// Second chance: try to check for a cover next to the info file
if (meta.getCover() == null) {
String info = sourceInfoFile.getFile().toString();
package be.nikiroo.fanfix.supported;
-import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.data.MetaData;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.StringUtils;
return null;
}
- private BufferedImage getCover(InputStream in) {
+ private Image getCover(InputStream in) {
String line = getLine(in, " property=\"og:image\"", 0);
String cover = null;
if (line != null) {
try {
coverIn = openEx(cover);
try {
- return ImageUtils.fromStream(coverIn);
+ return new Image(coverIn);
} finally {
coverIn.close();
}
setCurrentReferer(url);
pg.setProgress((i++) % pg.getMax());
} catch (IOException e) {
- Instance.getTraceHandler().error(new IOException(
- "Cannot get the next manga page which is: "
- + linkNext, e));
+ Instance.getTraceHandler().error(
+ new IOException(
+ "Cannot get the next manga page which is: "
+ + linkNext, e));
}
}
package be.nikiroo.fanfix.supported;
-import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
/**
return getChapterContent(source, in, 0, null);
}
- private BufferedImage getCover(URL source) {
+ private Image getCover(URL source) {
String path;
try {
path = new File(source.toURI()).getPath();
package be.nikiroo.fanfix.supported;
-import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.StringUtils;
return tags;
}
- private BufferedImage getCover(URL source, InputStream in)
- throws IOException {
+ private Image getCover(URL source, InputStream in) throws IOException {
List<Entry<String, URL>> chaps = getChapters(source, in, null);
if (!chaps.isEmpty()) {