Example usage for java.util Observer update

List of usage examples for java.util Observer update

Introduction

In this page you can find the example usage for java.util Observer update.

Prototype

void update(Observable o, Object arg);

Source Link

Document

This method is called whenever the observed object is changed.

Usage

From source file:com.t3.client.AppActions.java

private static void doSaveCampaign(final Campaign campaign, final File file, final Observer callback) {
    TabletopTool.getFrame()/*from  w ww  . j  a  v a2 s  .c  o  m*/
            .showFilledGlassPane(new StaticMessageDialog(I18N.getText("msg.info.campaignSaving")));
    new SwingWorker<Object, Object>() {
        @Override
        protected Object doInBackground() throws Exception {
            if (AppState.isSaving()) {
                return "Campaign currently being auto-saved.  Try again later."; // string error message
            }
            try {
                AppState.setIsSaving(true);
                TabletopTool.getAutoSaveManager().pause();

                long start = System.currentTimeMillis();
                PersistenceUtil.saveCampaign(campaign, file);
                AppMenuBar.getMruManager().addMRUCampaign(AppState.getCampaignFile());
                TabletopTool.getFrame().setStatusMessage(I18N.getString("msg.info.campaignSaved"));

                // Minimum display time so people can see the message
                try {
                    Thread.sleep(Math.max(0, 500 - (System.currentTimeMillis() - start)));
                } catch (InterruptedException e) {
                    // Nothing to do
                }
                return null; // 'null' means everything worked; no errors
            } catch (IOException ioe) {
                TabletopTool.showError("msg.error.failedSaveCampaign", ioe);
            } catch (Throwable t) {
                TabletopTool.showError("msg.error.failedSaveCampaign", t);
            } finally {
                AppState.setIsSaving(false);
                TabletopTool.getAutoSaveManager().restart();
            }
            return "Failed due to exception"; // string error message
        }

        @Override
        protected void done() {
            TabletopTool.getFrame().hideGlassPane();
            Object obj = null;
            try {
                obj = get();
                if (obj instanceof String)
                    TabletopTool.showWarning((String) obj);
            } catch (Exception e) {
                TabletopTool.showError("Exception during SwingWorker.get()?", e);
            }
            if (callback != null) {
                callback.update(null, obj);
            }
        }
    }.execute();
}

From source file:net.rptools.maptool.client.AppActions.java

private static void doSaveCampaign(final Campaign campaign, final File file, final Observer callback,
        final String campaignVersion) {
    new SwingWorker<Object, Object>() {
        @Override//  w  ww.jav  a 2s  .c  o m
        protected Object doInBackground() throws Exception {
            try {
                synchronized (AppState.class) {
                    if (AppState.isSaving()) {
                        return "Campaign currently being auto-saved.  Try again later."; // string error message
                    }
                    AppState.setIsSaving(true);
                    MapTool.getAutoSaveManager().pause();
                }
                MapTool.getFrame()
                        .showFilledGlassPane(new StaticMessageDialog(I18N.getText("msg.info.campaignSaving")));

                long start = System.currentTimeMillis();
                PersistenceUtil.saveCampaign(campaign, file);
                AppMenuBar.getMruManager().addMRUCampaign(AppState.getCampaignFile());
                MapTool.getFrame().setStatusMessage(I18N.getString("msg.info.campaignSaved"));

                // Minimum display time so people can see the message
                try {
                    Thread.sleep(Math.max(0, 500 - (System.currentTimeMillis() - start)));
                } catch (InterruptedException e) {
                    // Nothing to do
                }
                return null; // 'null' means everything worked; no errors
            } catch (IOException ioe) {
                MapTool.showError("msg.error.failedSaveCampaign", ioe);
            } catch (Throwable t) {
                MapTool.showError("msg.error.failedSaveCampaign", t);
            } finally {
                synchronized (AppState.class) {
                    AppState.setIsSaving(false);
                    MapTool.getAutoSaveManager().restart();
                }
            }
            return "Failed due to exception"; // string error message
        }

        @Override
        protected void done() {
            MapTool.getFrame().hideGlassPane();
            Object obj = null;
            try {
                obj = get();
                if (obj instanceof String)
                    MapTool.showWarning((String) obj);
            } catch (Exception e) {
                MapTool.showError("Exception during SwingWorker.get()?", e);
            }
            if (callback != null) {
                callback.update(null, obj);
            }
        }
    }.execute();
}

From source file:org.csploit.android.core.System.java

/**
 * notify that a specific target of the list has been changed
 * @param target  the changed target/*from www.java 2 s  . c  o m*/
 */
public static void notifyTargetListChanged(Target target) {
    Observer o;
    synchronized (System.class) {
        o = targetListObserver;
    }

    if (o == null)
        return;

    o.update(null, target);
}