import java.net.URISyntaxException;
import javax.swing.JEditorPane;
+import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.event.HyperlinkEvent;
@Override
public void browse(String type) {
+ final Boolean[] done = new Boolean[] { false };
+
// TODO: improve presentation of update message
final VersionCheck updates = VersionCheck.check();
StringBuilder builder = new StringBuilder();
- final Boolean[] done = new Boolean[] { false };
final JEditorPane updateMessage = new JEditorPane("text/html", "");
if (updates.isNewVersionAvailable()) {
}
}
- try {
- GuiReaderFrame gui = new GuiReaderFrame(GuiReader.this,
- typeFinal);
- gui.setVisible(true);
- gui.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosed(WindowEvent e) {
- super.windowClosed(e);
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ GuiReaderFrame gui = new GuiReaderFrame(
+ GuiReader.this, typeFinal);
+ sync(gui);
+ } catch (Exception e) {
+ Instance.getTraceHandler().error(e);
+ } finally {
done[0] = true;
}
- });
- } catch (Exception e) {
- Instance.getTraceHandler().error(e);
- done[0] = true;
- }
+
+ }
+ }).start();
}
});
void read(String luid, boolean sync, Progress pg) throws IOException {
File file = cacheLib.getFile(luid, pg);
- // TODO: show a special page for the chapter?
- // We could also implement an internal viewer, both for image and
- // non-image documents
- openExternal(getLibrary().getInfo(luid), file, sync);
+ GuiReaderViewer viewer = new GuiReaderViewer(cacheLib,
+ cacheLib.getStory(luid, null));
+
+ // TODO: testing internal story viewer:
+ if (false) {
+ if (sync) {
+ sync(viewer);
+ } else {
+ viewer.setVisible(true);
+ }
+ } else {
+ openExternal(getLibrary().getInfo(luid), file, sync);
+ }
}
/**
Instance.getTraceHandler().error(e);
}
}
+
+ /**
+ * Change the title of the given {@link Story}.
+ *
+ * @param luid
+ * the luid of the {@link Story} to change
+ * @param newTitle
+ * the new title
+ */
+ void changeTitle(String luid, String newTitle) {
+ try {
+ cacheLib.changeTitle(luid, newTitle, null);
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ }
+ }
+
+ /**
+ * Change the author of the given {@link Story}.
+ * <p>
+ * The author can be a new one, it needs not exist before hand.
+ *
+ * @param luid
+ * the luid of the {@link Story} to change
+ * @param newAuthor
+ * the new author
+ */
+ void changeAuthor(String luid, String newAuthor) {
+ try {
+ cacheLib.changeAuthor(luid, newAuthor, null);
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ }
+ }
+
+ /**
+ * Start a frame and wait until it is closed before returning.
+ *
+ * @param frame
+ * the frame to start
+ */
+ static private void sync(final JFrame frame) {
+ if (EventQueue.isDispatchThread()) {
+ throw new IllegalStateException(
+ "Cannot call a sync method in the dispatch thread");
+ }
+
+ final Boolean[] done = new Boolean[] { false };
+ try {
+ Runnable run = new Runnable() {
+ @Override
+ public void run() {
+ try {
+ frame.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ super.windowClosing(e);
+ done[0] = true;
+ }
+ });
+
+ frame.setVisible(true);
+ } catch (Exception e) {
+ done[0] = true;
+ }
+ }
+ };
+
+ if (EventQueue.isDispatchThread()) {
+ run.run();
+ } else {
+ EventQueue.invokeLater(run);
+ }
+ } catch (Exception e) {
+ Instance.getTraceHandler().error(e);
+ done[0] = true;
+ }
+
+ // This action must be synchronous, so wait until the frame is closed
+ while (!done[0]) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
}