X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=inline;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fui%2FGuiReader.java;h=f4a932b3b899ef3fc48826bbe0b3aaa913a68d90;hb=596ed3d65b2585c4358935d6fbb130f50e237787;hp=02f153cdf82d47dc8f2486f7e3a72cff94a75903;hpb=350bc060516184774f8116e61696a8c3c45ba85d;p=nikiroo-utils.git
diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReader.java b/src/be/nikiroo/fanfix/reader/ui/GuiReader.java
index 02f153c..f4a932b 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;
@@ -16,6 +17,8 @@ import javax.swing.event.HyperlinkListener;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.VersionCheck;
+import be.nikiroo.fanfix.bundles.StringIdGui;
+import be.nikiroo.fanfix.bundles.UiConfig;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.library.BasicLibrary;
@@ -106,18 +109,22 @@ class GuiReader extends BasicReader {
@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()) {
- builder.append("A new version of the program is available at https://github.com/nikiroo/fanfix/releases");
+ builder.append(trans(StringIdGui.NEW_VERSION_AVAILABLE,
+ "https://github.com/nikiroo/fanfix/releases"));
builder.append("
");
builder.append("
");
for (Version v : updates.getNewer()) {
- builder.append("\tVersion " + v + "");
+ builder.append("\t"
+ + trans(StringIdGui.NEW_VERSION_VERSION, v.toString())
+ + "");
builder.append("
");
builder.append("
+ * 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); + } + } + + /** + * Simple shortcut method to call {link Instance#getTransGui()#getString()}. + * + * @param id + * the ID to translate + * + * @return the translated result + */ + static String trans(StringIdGui id, Object... params) { + return Instance.getTransGui().getString(id, params); + } + + /** + * 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) { + } + } + } }