+
+ /**
+ * 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);
+ }
+ }
+
+ /**
+ * 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) {
+ }
+ }
+ }