Example usage for java.awt.event ActionEvent ACTION_PERFORMED

List of usage examples for java.awt.event ActionEvent ACTION_PERFORMED

Introduction

In this page you can find the example usage for java.awt.event ActionEvent ACTION_PERFORMED.

Prototype

int ACTION_PERFORMED

To view the source code for java.awt.event ActionEvent ACTION_PERFORMED.

Click Source Link

Document

This event id indicates that a meaningful action occurred.

Usage

From source file:com.openbravo.pos.sales.JRetailPanelTicket.java

protected void fireSelectedProduct(ProductInfoExt prod) {
    kotaction = 1;/*from ww w .  j  ava2 s  .  co  m*/
    EventListener[] l = listeners.getListeners(ActionListener.class);
    ActionEvent e = null;
    for (int i = 0; i < l.length; i++) {
        if (e == null) {
            e = new ActionEvent(prod, ActionEvent.ACTION_PERFORMED, prod.getID());
        }
        ((ActionListener) l[i]).actionPerformed(e);
    }
    incProduct(prod);
}

From source file:com.openbravo.pos.sales.JRetailPanelTakeAway.java

protected void fireSelectedProduct(ProductInfoExt prod) {
    System.out.println(" fireSelectedProduct for popular item");
    kotaction = 1;/*  ww w.ja  v a2 s  .  c o  m*/
    EventListener[] l = listeners.getListeners(ActionListener.class);
    ActionEvent e = null;
    for (int i = 0; i < l.length; i++) {
        if (e == null) {
            e = new ActionEvent(prod, ActionEvent.ACTION_PERFORMED, prod.getID());
        }
        ((ActionListener) l[i]).actionPerformed(e);
    }
    incProduct(prod);
}

From source file:op.tools.SYSTools.java

public static BigDecimal checkBigDecimal(javax.swing.event.CaretEvent evt, boolean nees2BePositive) {
    BigDecimal bd = null;//from  w w w.j a v a  2  s  .c  o  m
    JTextComponent txt = (JTextComponent) evt.getSource();
    Action toolTipAction = txt.getActionMap().get("hideTip");
    if (toolTipAction != null) {
        ActionEvent hideTip = new ActionEvent(txt, ActionEvent.ACTION_PERFORMED, "");
        toolTipAction.actionPerformed(hideTip);
    }
    try {
        OPDE.debug(txt.getText());
        OPDE.debug(assimilateDecimalSeparators(txt.getText()));

        bd = parseDecimal(txt.getText());

        //            bd = BigDecimal.valueOf(Double.parseDouble(assimilateDecimalSeparators(txt.getText())));
        OPDE.debug(bd);
        if (nees2BePositive && bd.compareTo(BigDecimal.ZERO) <= 0) {
            txt.setToolTipText("<html><font color=\"red\"><b>" + SYSTools.xx("misc.msg.invalidnumber")
                    + "</b></font></html>");
            toolTipAction = txt.getActionMap().get("postTip");
            bd = BigDecimal.ONE;
        } else {
            txt.setToolTipText("");
        }

    } catch (NumberFormatException ex) {
        if (nees2BePositive) {
            bd = BigDecimal.ONE;
        } else {
            bd = BigDecimal.ZERO;
        }
        txt.setToolTipText(
                "<html><font color=\"red\"><b>" + SYSTools.xx("misc.msg.invalidnumber") + "</b></font></html>");
        toolTipAction = txt.getActionMap().get("postTip");
        if (toolTipAction != null) {
            ActionEvent postTip = new ActionEvent(txt, ActionEvent.ACTION_PERFORMED, "");
            toolTipAction.actionPerformed(postTip);
        }
    }
    return bd;
}

From source file:org.apache.jmeter.gui.MainFrame.java

public boolean openJmxFilesFromDragAndDrop(Transferable tr) throws UnsupportedFlavorException, IOException {
    @SuppressWarnings("unchecked")
    List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
    if (files.isEmpty()) {
        return false;
    }//  ww w .ja v  a2  s.  c o  m
    File file = files.get(0);
    if (!file.getName().endsWith(".jmx")) {
        log.warn("Importing file:" + file.getName()
                + "from DnD failed because file extension does not end with .jmx");
        return false;
    }

    ActionEvent fakeEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, ActionNames.OPEN);
    LoadDraggedFile.loadProject(fakeEvent, file);

    return true;
}

From source file:org.apache.log4j.chainsaw.LogUI.java

/**
 * Using the current thread, calls the registed Shutdown action's
 * actionPerformed(...) method.//from w  w w. j  a v  a  2 s .  co m
 *
 */
private void performShutdownAction() {
    MessageCenter.getInstance().getLogger().debug("Calling the shutdown Action. Goodbye!");

    shutdownAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Shutting Down"));
}

From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java

public static void addDoubleClickAction(JComponent component, final Action action) {
    component.addMouseListener(new MouseAdapter() {
        @Override/*from  ww  w . j av  a2 s. c om*/
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == DOUBLE_CLICK_COUNT && e.getButton() == MouseEvent.BUTTON1) {
                action.actionPerformed(new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED,
                        (String) action.getValue(Action.ACTION_COMMAND_KEY), e.getWhen(), e.getModifiers()));
            }
        }
    });
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.view.ImporterControl.java

/**
 * Handles a PropertyChangedEvent/*  ww w  .  j  a  v a  2  s  .c  o  m*/
 * @param evt The event
 */
private void handlePropertyChangedEvent(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();
    if (ImportDialog.IMPORT_PROPERTY.equals(name)) {
        actionsMap.get(CANCEL_BUTTON).setEnabled(true);
        model.importData((ImportableObject) evt.getNewValue());
    } else if (ImportDialog.LOAD_TAGS_PROPERTY.equals(name)) {
        model.loadExistingTags();
    } else if (ImportDialog.CANCEL_SELECTION_PROPERTY.equals(name)) {
        model.close();
    } else if (ClosableTabbedPane.CLOSE_TAB_PROPERTY.equals(name)) {
        model.removeImportElement(evt.getNewValue());
    } else if (FileImportComponent.SUBMIT_ERROR_PROPERTY.equals(name)) {
        submitFiles((FileImportComponent) evt.getNewValue());
    } else if (ImportDialog.REFRESH_LOCATION_PROPERTY.equals(name)) {
        model.refreshContainers((ImportLocationDetails) evt.getNewValue());
    } else if (ImportDialog.CREATE_OBJECT_PROPERTY.equals(name)) {
        ObjectToCreate l = (ObjectToCreate) evt.getNewValue();
        model.createDataObject(l);
    } else if (StatusLabel.DEBUG_TEXT_PROPERTY.equals(name)) {
        view.appendDebugText((String) evt.getNewValue());
    } else if (MacOSMenuHandler.QUIT_APPLICATION_PROPERTY.equals(name)) {
        Action a = getAction(EXIT);
        ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "");
        a.actionPerformed(event);
    } else if (ImportDialog.PROPERTY_GROUP_CHANGED.equals(name)) {
        GroupData newGroup = (GroupData) evt.getNewValue();
        model.setUserGroup(newGroup);
    } else if (StatusLabel.FILE_IMPORT_STARTED_PROPERTY.equals(name)
            || FileImportComponent.CANCEL_IMPORT_PROPERTY.equals(name)) {
        checkDisableCancelAllButtons();
    } else if (StatusLabel.IMPORT_DONE_PROPERTY.equals(name)) {
        model.onImportComplete((FileImportComponent) evt.getNewValue());
    } else if (StatusLabel.UPLOAD_DONE_PROPERTY.equals(name)) {
        model.onUploadComplete((FileImportComponent) evt.getNewValue());
    }
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewerControl.java

/**
 * Reacts to property changed. //from  www. j  a  va  2 s.  c  o  m
 * @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
 */
public void propertyChange(PropertyChangeEvent pce) {
    String name = pce.getPropertyName();
    if (name == null)
        return;
    if (TreeViewer.CANCEL_LOADING_PROPERTY.equals(name)) {
        Browser browser = model.getSelectedBrowser();
        if (browser != null)
            browser.cancel();
    } else if (Browser.POPUP_MENU_PROPERTY.equals(name)) {
        Integer c = (Integer) pce.getNewValue();
        Browser browser = model.getSelectedBrowser();
        if (browser != null)
            view.showPopup(c.intValue(), browser.getClickComponent(), browser.getClickPoint());
    } else if (Browser.CLOSE_PROPERTY.equals(name)) {
        Browser browser = (Browser) pce.getNewValue();
        if (browser != null)
            view.removeBrowser(browser);
    } else if (TreeViewer.FINDER_VISIBLE_PROPERTY.equals(name)) {
        Boolean b = (Boolean) pce.getNewValue();
        if (!b.booleanValue()) {
            model.clearFoundResults();
            model.onComponentStateChange(true);
        }
    } else if (TreeViewer.SELECTED_BROWSER_PROPERTY.equals(name)) {
        Browser b = model.getSelectedBrowser();
        Iterator i = model.getBrowsers().values().iterator();
        Browser browser;
        while (i.hasNext()) {
            browser = (Browser) i.next();
            browser.setSelected(browser.equals(b));
        }
    } else if (Browser.SELECTED_TREE_NODE_DISPLAY_PROPERTY.equals(name)) {
        model.onSelectedDisplay();
        view.updateMenuItems();
    } else if (TreeViewer.HIERARCHY_ROOT_PROPERTY.equals(name)) {
        /*
         Map browsers = model.getBrowsers();
         Iterator i = browsers.values().iterator();
         Browser browser;
         while (i.hasNext()) {
            browser = (Browser) i.next();
            //browser.cleanFilteredNodes();
            //browser.switchUser();
         }
         */
    } else if (AddExistingObjectsDialog.EXISTING_ADD_PROPERTY.equals(name)) {
        model.addExistingObjects((Set) pce.getNewValue());
    } else if (UserManagerDialog.USER_SWITCH_PROPERTY.equals(name)) {
        Map m = (Map) pce.getNewValue();
        Iterator i = m.entrySet().iterator();
        Long groupID;
        List<ExperimenterData> users;
        Entry entry;
        while (i.hasNext()) {
            entry = (Entry) i.next();
            groupID = (Long) entry.getKey();
            users = (List<ExperimenterData>) entry.getValue();
            model.setHierarchyRoot(groupID, users);
        }
    } else if (UserManagerDialog.NO_USER_SWITCH_PROPERTY.equals(name)) {
        UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier();
        un.notifyInfo("User Selection", "Please select a user first.");
    } else if (EditorDialog.CREATE_PROPERTY.equals(name)) {
        DataObject data = (DataObject) pce.getNewValue();
        model.createObject(data, true);
    } else if (EditorDialog.CREATE_NO_PARENT_PROPERTY.equals(name)) {
        DataObject data = (DataObject) pce.getNewValue();
        model.createObject(data, false);
    } else if (MetadataViewer.ON_DATA_SAVE_PROPERTY.equals(name)) {
        Object object = pce.getNewValue();
        if (object != null) {
            if (object instanceof DataObject)
                model.onDataObjectSave((DataObject) object, TreeViewer.UPDATE_OBJECT);
            else
                model.onDataObjectSave((List) object, TreeViewer.UPDATE_OBJECT);
        }
    } else if (DataBrowser.SELECTED_NODE_DISPLAY_PROPERTY.equals(name)) {
        model.setSelectedNode(pce.getNewValue());
    } else if (DataBrowser.UNSELECTED_NODE_DISPLAY_PROPERTY.equals(name)) {
        model.setUnselectedNode(pce.getNewValue());
    } else if (DataBrowser.DATA_OBJECT_CREATED_PROPERTY.equals(name)) {
        Map map = (Map) pce.getNewValue();
        if (map != null && map.size() == 1) {
            DataObject data = null;
            Set set = map.entrySet();
            Entry entry;
            Iterator i = set.iterator();
            Object o;
            DataObject parent = null;
            while (i.hasNext()) {
                entry = (Entry) i.next();
                data = (DataObject) entry.getKey();
                o = entry.getValue();
                if (o != null)
                    parent = (DataObject) o;
                break;
            }
            if (parent == null)
                model.onOrphanDataObjectCreated(data);
            else
                model.onDataObjectSave(data, parent, TreeViewer.CREATE_OBJECT);
        }
    } else if (DataBrowser.ADDED_TO_DATA_OBJECT_PROPERTY.equals(name)) {
        //Browser browser =  model.getSelectedBrowser();
        //if (browser != null) browser.refreshLoggedExperimenterData();
        model.refreshTree();
    } else if (DataBrowser.COPY_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        if (data != null)
            model.copyRndSettings((ImageData) data);
        else
            model.copyRndSettings(null);
    } else if (DataBrowser.PASTE_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        PasteRndSettingsCmd cmd;
        if (data instanceof Collection)
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.PASTE, (Collection) data);
        else
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.PASTE);
        cmd.execute();
    } else if (DataBrowser.RESET_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        PasteRndSettingsCmd cmd;
        if (data instanceof Collection)
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.RESET, (Collection) data);
        else
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.RESET);
        cmd.execute();
    } else if (DataBrowser.SET__ORIGINAL_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        PasteRndSettingsCmd cmd;
        if (data instanceof Collection)
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_MIN_MAX, (Collection) data);
        else
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_MIN_MAX);
        cmd.execute();
    } else if (DataBrowser.SET__ORIGINAL_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        PasteRndSettingsCmd cmd;
        if (data instanceof Collection)
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_OWNER, (Collection) data);
        else
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_OWNER);
        cmd.execute();
    } else if (DataBrowser.CUT_ITEMS_PROPERTY.equals(name)) {
        CutCmd cmd = new CutCmd(model);
        cmd.execute();
    } else if (DataBrowser.COPY_ITEMS_PROPERTY.equals(name)) {
        CopyCmd cmd = new CopyCmd(model);
        cmd.execute();
    } else if (DataBrowser.PASTE_ITEMS_PROPERTY.equals(name)) {
        PasteCmd cmd = new PasteCmd(model);
        cmd.execute();
    } else if (DataBrowser.REMOVE_ITEMS_PROPERTY.equals(name)) {
        DeleteCmd cmd = new DeleteCmd(model.getSelectedBrowser());
        cmd.execute();
    } else if (DataBrowser.VIEW_IMAGE_NODE_PROPERTY.equals(name)) {
        //view.get
        Browser browser = model.getSelectedBrowser();
        if (browser != null) {
            TreeImageDisplay node = browser.getLastSelectedDisplay();
            model.browse(node, (DataObject) pce.getNewValue(), false);
        }
    } else if (DataBrowser.INTERNAL_VIEW_NODE_PROPERTY.equals(name)) {
        ViewCmd cmd = new ViewCmd(model, true);
        cmd.execute();
    } else if (Finder.RESULTS_FOUND_PROPERTY.equals(name)) {
        model.setSearchResult(pce.getNewValue());
    } else if (GenericDialog.SAVE_GENERIC_PROPERTY.equals(name)) {
        Object parent = pce.getNewValue();
        if (parent instanceof MetadataViewer) {
            MetadataViewer mv = (MetadataViewer) parent;
            mv.saveData();
        }
    } else if (Browser.DATA_REFRESHED_PROPERTY.equals(name)) {
        model.onSelectedDisplay();
    } else if (MetadataViewer.ADMIN_UPDATED_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        Map browsers = model.getBrowsers();
        Set set = browsers.entrySet();
        Entry entry;
        Iterator i = set.iterator();
        Browser browser;
        while (i.hasNext()) {
            entry = (Entry) i.next();
            browser = (Browser) entry.getValue();
            browser.refreshAdmin(data);
        }
        view.createTitle();
    } else if (DataBrowser.TAG_WIZARD_PROPERTY.equals(name)) {
        model.showTagWizard();
    } else if (DataBrowser.FIELD_SELECTED_PROPERTY.equals(name)) {
        model.setSelectedField(pce.getNewValue());
    } else if (MetadataViewer.RENDER_THUMBNAIL_PROPERTY.equals(name)) {
        long imageID = ((Long) pce.getNewValue()).longValue();
        List<Long> ids = new ArrayList<Long>(1);
        ids.add(imageID);
        view.reloadThumbnails(ids);
    } else if (MetadataViewer.APPLY_SETTINGS_PROPERTY.equals(name)) {
        Object object = pce.getNewValue();
        if (object instanceof ImageData) {
            ImageData img = (ImageData) object;
            model.copyRndSettings((ImageData) object);
            List<Long> ids = new ArrayList<Long>(1);
            ids.add(img.getId());
            view.reloadThumbnails(ids);

            //improve code to speed it up
            List l = model.getSelectedBrowser().getSelectedDataObjects();
            Collection toUpdate;
            if (l.size() > 1)
                toUpdate = l;
            else
                toUpdate = model.getDisplayedImages();
            if (toUpdate != null) {
                PasteRndSettingsCmd cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.PASTE, toUpdate);
                cmd.execute();
            }
        } else if (object instanceof Object[]) {
            Object[] objects = (Object[]) object;
            WellSampleData wsd = (WellSampleData) objects[0];
            WellData well = (WellData) objects[1];
            ImageData img = wsd.getImage();
            model.copyRndSettings(img);
            List<Long> ids = new ArrayList<Long>(1);
            ids.add(img.getId());
            view.reloadThumbnails(ids);
            ids = new ArrayList<Long>(1);
            ids.add(well.getPlate().getId());
            model.pasteRndSettings(ids, PlateData.class);
        }
    } else if (JXTaskPaneContainerSingle.SELECTED_TASKPANE_PROPERTY.equals(name)) {
        handleTaskPaneSelection((JXTaskPane) pce.getNewValue());
    } else if (MetadataViewer.GENERATE_FIGURE_PROPERTY.equals(name)) {
        Object object = pce.getNewValue();
        if (!(object instanceof FigureParam))
            return;
        UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier();
        IconManager icons = IconManager.getInstance();
        Icon icon = icons.getIcon(IconManager.SPLIT_VIEW_FIGURE_22);
        FigureActivityParam activity;
        List<Long> ids = new ArrayList<Long>();
        Iterator i;
        DataObject obj;
        FigureParam param = (FigureParam) object;
        Collection l;
        if (param.isSelectedObjects()) {
            Browser b = model.getSelectedBrowser();
            if (b != null)
                l = b.getSelectedDataObjects();
            else {
                l = new ArrayList<DataObject>();
                Collection<DataObject> nodes = model.getSelectedObjectsFromBrowser();
                if (nodes != null) {
                    l.addAll(nodes);
                }
            }
        } else {
            l = model.getDisplayedImages();
        }
        if (CollectionUtils.isEmpty(l))
            return;
        Class klass = null;
        Object p = null;
        if (param.getIndex() == FigureParam.THUMBNAILS) {
            Browser browser = model.getSelectedBrowser();
            if (browser != null) {
                TreeImageDisplay[] nodes = browser.getSelectedDisplays();
                if (nodes != null && nodes.length > 0) {
                    TreeImageDisplay node = nodes[0];
                    Object ho = node.getUserObject();
                    TreeImageDisplay pNode;
                    if (ho instanceof DatasetData) {
                        klass = ho.getClass();
                        p = ho;
                    } else if (ho instanceof ImageData) {
                        klass = ho.getClass();
                        pNode = node.getParentDisplay();
                        if (pNode != null) {
                            p = pNode.getUserObject();
                            if (!(p instanceof DatasetData))
                                p = null;
                        }
                        if (p == null)
                            p = ho;
                    }
                    if (p != null)
                        param.setAnchor((DataObject) p);
                }
            }
        }

        i = l.iterator();
        int n = 0;
        List<Long> groupIds = new ArrayList<Long>();
        boolean canRun = true;
        while (i.hasNext()) {
            obj = (DataObject) i.next();
            if (groupIds.size() == 0)
                groupIds.add(obj.getGroupId());
            if (groupIds.contains(obj.getGroupId())) {
                ids.add(obj.getId());
                if (n == 0)
                    p = obj;
                n++;
            } else {
                canRun = false;
                break;
            }
        }
        if (!canRun) {
            un.notifyInfo("Script", "You can run the script only\non " + "objects from the same group");
            return;
        }
        if (ids.size() == 0)
            return;
        // not set
        if (param.getIndex() != FigureParam.THUMBNAILS)
            param.setAnchor((DataObject) p);

        activity = new FigureActivityParam(object, ids, klass, FigureActivityParam.SPLIT_VIEW_FIGURE);
        activity.setIcon(icon);
        un.notifyActivity(new SecurityContext(groupIds.get(0)), activity);
    } else if (MetadataViewer.HANDLE_SCRIPT_PROPERTY.equals(name)) {
        UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier();
        ScriptActivityParam p = (ScriptActivityParam) pce.getNewValue();
        int index = p.getIndex();
        ScriptObject script = p.getScript();
        if (index == ScriptActivityParam.VIEW) {
            Environment env = (Environment) TreeViewerAgent.getRegistry().lookup(LookupNames.ENV);
            String path = env.getOmeroFilesHome();
            path += File.separator + script.getName();
            File f = new File(path);
            DownloadAndLaunchActivityParam activity = new DownloadAndLaunchActivityParam(
                    p.getScript().getScriptID(), DownloadAndLaunchActivityParam.ORIGINAL_FILE, f, null);

            un.notifyActivity(model.getSecurityContext(), activity);
        } else if (index == ScriptActivityParam.DOWNLOAD) {
            downloadScript(p);
        }
    } else if (OpenWithDialog.OPEN_DOCUMENT_PROPERTY.equals(name)) {
        ApplicationData data = (ApplicationData) pce.getNewValue();
        //Register 
        if (data == null)
            return;
        String format = view.getObjectMimeType();
        //if (format == null) return;
        if (format != null)
            TreeViewerFactory.register(data, format);
        model.openWith(data);
    } else if (DataBrowser.OPEN_EXTERNAL_APPLICATION_PROPERTY.equals(name)) {
        model.openWith((ApplicationData) pce.getNewValue());
    } else if (AdminDialog.CREATE_ADMIN_PROPERTY.equals(name)) {
        AdminObject object = (AdminObject) pce.getNewValue();
        model.administrate(object);
    } else if (MetadataViewer.REGISTER_PROPERTY.equals(name)) {
        model.register((DataObjectRegistration) pce.getNewValue());
    } else if (MetadataViewer.RESET_PASSWORD_PROPERTY.equals(name)) {
        model.resetPassword((String) pce.getNewValue());
    } else if (MetadataViewer.UPLOAD_SCRIPT_PROPERTY.equals(name)) {
        TreeViewerAction action = getAction(UPLOAD_SCRIPT);
        action.actionPerformed(new ActionEvent(this, 1, ""));
    } else if (SelectionWizard.SELECTED_ITEMS_PROPERTY.equals(name)) {
        Map m = (Map) pce.getNewValue();
        if (m == null || m.size() != 1)
            return;
        Entry entry;
        Iterator i = m.entrySet().iterator();
        Class klass;
        TreeImageDisplay node;
        Collection<ExperimenterData> list;
        Object uo;
        AdminObject object;
        while (i.hasNext()) {
            entry = (Entry) i.next();
            klass = (Class) entry.getKey();
            if (ExperimenterData.class.equals(klass)) {
                list = (Collection<ExperimenterData>) entry.getValue();
                node = model.getSelectedBrowser().getLastSelectedDisplay();
                if (node != null) {
                    uo = node.getUserObject();
                    if (uo instanceof GroupData) {
                        object = new AdminObject((GroupData) uo, list);
                        model.administrate(object);
                    }
                }
            }
        }
    } else if (DataBrowser.SET__OWNER_RND_SETTINGS_PROPERTY.equals(name)) {
        Object data = pce.getNewValue();
        PasteRndSettingsCmd cmd;
        if (data instanceof Collection)
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_OWNER, (Collection) data);
        else
            cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_OWNER);
        cmd.execute();
    } else if (ScriptingDialog.RUN_SELECTED_SCRIPT_PROPERTY.equals(name)) {
        handleScript((ScriptObject) pce.getNewValue(), ScriptActivityParam.RUN);
    } else if (ScriptingDialog.DOWNLOAD_SELECTED_SCRIPT_PROPERTY.equals(name)) {
        Object value = pce.getNewValue();
        if (value instanceof ScriptObject)
            handleScript((ScriptObject) value, ScriptActivityParam.DOWNLOAD);
        else if (value instanceof String) {
            ScriptObject script = view.getScriptFromName((String) value);
            if (script != null)
                handleScript(script, ScriptActivityParam.DOWNLOAD);
        }
    } else if (ScriptingDialog.VIEW_SELECTED_SCRIPT_PROPERTY.equals(name)) {
        Object value = pce.getNewValue();
        if (value instanceof ScriptObject)
            handleScript((ScriptObject) value, ScriptActivityParam.VIEW);
        else if (value instanceof String) {
            ScriptObject script = view.getScriptFromName((String) value);
            if (script != null)
                handleScript(script, ScriptActivityParam.VIEW);
        }
    } else if (TreeViewer.SCRIPTS_LOADING_PROPERTY.equals(name)) {
        view.setScriptsLoadingStatus(true);
    } else if (TreeViewer.SCRIPTS_LOADED_PROPERTY.equals(name)) {
        view.setScriptsLoadingStatus(false);
    } else if (DataBrowser.SELECTED_DATA_BROWSER_NODES_DISPLAY_PROPERTY.equals(name)) {
        model.setSelectedNodes(pce.getNewValue());
    } else if (TreeViewer.GROUP_CHANGED_PROPERTY.equals(name)) {
        view.setPermissions();
    } else if (MacOSMenuHandler.QUIT_APPLICATION_PROPERTY.equals(name)) {
        Action a = getAction(EXIT);
        ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "");
        a.actionPerformed(event);
    } else if (GroupManagerDialog.GROUP_SWITCH_PROPERTY.equals(name)) {
        List<GroupData> groups = (List<GroupData>) pce.getNewValue();
        if (groups.size() == 0) {
            UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier();
            un.notifyInfo(GroupManagerDialog.TITLE, "At least one group " + "must be selected.");
            return;
        }
        model.setUserGroup(groups);
    } else if (DataBrowser.ACTIVATE_USER_PROPERTY.equals(name)) {
        ExperimenterData exp = (ExperimenterData) pce.getNewValue();
        if (exp != null)
            model.activateUser(exp);
    } else if (DataBrowser.RESET_PASSWORD_PROPERTY.equals(name)) {
        getAction(RESET_PASSWORD).actionPerformed(new ActionEvent(pce.getNewValue(), 0, "Reset Password"));
    }
}

From source file:org.openuat.apps.BedaApp.java

/**
 * Creates a new instance of this class and launches the
 * actual application./*w  w w . j  a v  a2s .  com*/
 */
public BedaApp() {
    random = new SecureRandom();
    devices = new RemoteDevice[0];
    currentPeerUrl = null;
    currentChannel = null;
    isInitiator = false;

    // Initialize the logger. Use a wrapper around the log4j framework.
    /*LogFactory.init(new Log4jFactory());
    logger = LogFactory.getLogger(BedaApp.class.getName());
    logger.finer("Logger initiated!");*/

    mainWindow = new JFrame("Beda App");
    mainWindow.setSize(new Dimension(FRAME_WIDTH, FRAME_HIGHT));
    mainWindow.setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HIGHT));
    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainWindow.getContentPane().setLayout(new FlowLayout());
    URL imgURL = getClass().getResource("/resources/Button_Icon_Blue_beda.png");
    ImageIcon icon = imgURL != null ? new ImageIcon(imgURL)
            : new ImageIcon("resources/Button_Icon_Blue_beda.png");
    mainWindow.setIconImage(icon.getImage());

    // prepare the button channels
    ActionListener abortHandler = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (e.getID() == ActionEvent.ACTION_PERFORMED) {
                logger.warning("Protocol run aborted by user");
                BluetoothRFCOMMChannel.shutdownAllChannels();
                alertError("Protocol run aborted.");
            }
        }
    };
    buttonChannels = new HashMap<String, OOBChannel>();
    ButtonChannelImpl impl = new AWTButtonChannelImpl(mainWindow.getContentPane(), abortHandler);
    OOBChannel c = new ButtonToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);
    c = new FlashDisplayToButtonChannel(impl, false);
    buttonChannels.put(c.toString(), c);
    c = new TrafficLightToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);
    c = new ProgressBarToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);
    c = new PowerBarToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);
    c = new ShortVibrationToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);
    c = new LongVibrationToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);

    // set up the menu bar
    menuBar = new JMenuBar();
    JMenu menu = new JMenu("Menu");
    final JMenuItem homeEntry = new JMenuItem("Home");
    final JMenuItem testEntry = new JMenuItem("Test channels");

    ActionListener menuListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JMenuItem menuItem = (JMenuItem) event.getSource();
            if (menuItem == homeEntry) {
                showHomeScreen();
            } else if (menuItem == testEntry) {
                showTestScreen();
            }
        }
    };
    homeEntry.addActionListener(menuListener);
    testEntry.addActionListener(menuListener);

    menu.add(homeEntry);
    menu.add(testEntry);
    menuBar.add(menu);
    mainWindow.setJMenuBar(menuBar);

    // set up channel list
    OOBChannel[] channels = { new ButtonToButtonChannel(impl), new FlashDisplayToButtonChannel(impl, false),
            new TrafficLightToButtonChannel(impl), new ProgressBarToButtonChannel(impl),
            new PowerBarToButtonChannel(impl), new ShortVibrationToButtonChannel(impl),
            new LongVibrationToButtonChannel(impl) };
    channelList = new JList(channels);
    channelList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    channelList.setVisibleRowCount(15);
    channelList.setPreferredSize(new Dimension(LIST_WIDTH, LIST_HIGHT));

    // set up device list
    deviceList = new JList();
    deviceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    deviceList.setVisibleRowCount(15);
    deviceList.setPreferredSize(new Dimension(LIST_WIDTH, LIST_HIGHT));

    // enable double clicks on the two lists
    doubleClickListener = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent event) {
            // react on double clicks
            if (event.getButton() == MouseEvent.BUTTON1 && event.getClickCount() == 2) {
                JList source = (JList) event.getSource();
                if (source == channelList && channelList.isEnabled()) {
                    currentChannel = (OOBChannel) channelList.getSelectedValue();
                    startAuthentication();
                } else if (source == deviceList) {
                    int index = deviceList.getSelectedIndex();
                    if (index > -1) {
                        String peerAddress = devices[index].getBluetoothAddress();
                        searchForService(peerAddress);
                    }
                }
            }
            event.consume();
        }
    };
    deviceList.addMouseListener(doubleClickListener);
    // note: this listener will be set on the channelList in the showHomeScreen method

    ListSelectionListener selectionListener = new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent event) {
            channelList.setEnabled(false);
        }
    };
    deviceList.addListSelectionListener(selectionListener);

    // create refresh button
    refreshButton = new JButton("Refresh list");
    ActionListener buttonListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if ((JButton) event.getSource() == refreshButton) {
                refreshButton.setEnabled(false);
                statusLabel.setText("Please wait... scanning for devices...");
                peerManager.startInquiry(false);
            }
        }
    };
    refreshButton.addActionListener(buttonListener);

    // set up the bluetooth peer manager
    BluetoothPeerManager.PeerEventsListener listener = new BluetoothPeerManager.PeerEventsListener() {
        public void inquiryCompleted(Vector newDevices) {
            refreshButton.setEnabled(true);
            statusLabel.setText("");
            updateDeviceList();
        }

        public void serviceSearchCompleted(RemoteDevice remoteDevice, Vector services, int errorReason) {
            // ignore
        }
    };

    try {
        peerManager = new BluetoothPeerManager();
        peerManager.addListener(listener);
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Could not initiate BluetoothPeerManager.", e);
    }

    // set up the bluetooth rfcomm server
    try {
        btServer = new BluetoothRFCOMMServer(null, SERVICE_UUID, SERVICE_NAME, 30000, true, false);
        btServer.addAuthenticationProgressHandler(this);
        btServer.start();
        if (logger.isLoggable(Level.INFO)) {
            logger.info("Finished starting SDP service at " + btServer.getRegisteredServiceURL());
        }
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Could not create bluetooth server.", e);
    }
    ProtocolCommandHandler inputProtocolHandler = new ProtocolCommandHandler() {
        @Override
        public boolean handleProtocol(String firstLine, RemoteConnection remote) {
            if (logger.isLoggable(Level.FINER)) {
                logger.finer("Handle protocol command: " + firstLine);
            }
            if (firstLine.equals(UACAPProtocolConstants.PRE_AUTH)) {
                inputProtocol(false, remote, null);
                return true;
            }
            return false;
        }
    };
    btServer.addProtocolCommandHandler(UACAPProtocolConstants.PRE_AUTH, inputProtocolHandler);

    // build staus bar
    statusLabel = new JLabel("");
    statusLabel.setPreferredSize(new Dimension(FRAME_WIDTH - 40, LABEL_HIGHT));

    // build initial screen (the home screen)
    showHomeScreen();

    // launch window
    mainWindow.pack();
    mainWindow.setVisible(true);
}

From source file:org.photovault.swingui.tag.TagEditor2.java

private void fireActionEvent(String command) {
    ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, command);
    for (ActionListener l : actionListeners) {
        l.actionPerformed(e);//from w ww  .j  a va 2  s . co m
    }
}