X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fui%2FGuiReader.java;h=55701b1ad7b727d94470c449c368569e2aac3c5f;hb=12b9873f37c28e7f68b2bd1e03c1380f63cbe3ab;hp=02f153cdf82d47dc8f2486f7e3a72cff94a75903;hpb=350bc060516184774f8116e61696a8c3c45ba85d;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReader.java b/src/be/nikiroo/fanfix/reader/ui/GuiReader.java index 02f153c..55701b1 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReader.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReader.java @@ -9,6 +9,7 @@ import java.io.IOException; 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; @@ -109,7 +110,6 @@ class GuiReader extends BasicReader { // 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()) { @@ -168,28 +168,12 @@ class GuiReader extends BasicReader { try { GuiReaderFrame gui = new GuiReaderFrame(GuiReader.this, typeFinal); - gui.setVisible(true); - gui.addWindowListener(new WindowAdapter() { - @Override - public void windowClosed(WindowEvent e) { - super.windowClosed(e); - done[0] = true; - } - }); + sync(gui); } 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) { - } - } } @Override @@ -292,4 +276,81 @@ class GuiReader extends BasicReader { 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}. + *

+ * 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) { + final Boolean[] done = new Boolean[1]; + done[0] = false; + + try { + EventQueue.invokeLater(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; + } + } + }); + } 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) { + } + } + } }