Search in sources :

Example 11 with AWTEvent

use of java.awt.AWTEvent in project hackpad by dropbox.

the class RunProxy method dispatchNextGuiEvent.

/**
     * Processes the next GUI event.
     */
public void dispatchNextGuiEvent() throws InterruptedException {
    EventQueue queue = awtEventQueue;
    if (queue == null) {
        queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        awtEventQueue = queue;
    }
    AWTEvent event = queue.getNextEvent();
    if (event instanceof ActiveEvent) {
        ((ActiveEvent) event).dispatch();
    } else {
        Object source = event.getSource();
        if (source instanceof Component) {
            Component comp = (Component) source;
            comp.dispatchEvent(event);
        } else if (source instanceof MenuComponent) {
            ((MenuComponent) source).dispatchEvent(event);
        }
    }
}
Also used : ActiveEvent(java.awt.ActiveEvent) AWTEvent(java.awt.AWTEvent) EventObject(java.util.EventObject) MenuComponent(java.awt.MenuComponent) Component(java.awt.Component) MenuComponent(java.awt.MenuComponent) EventQueue(java.awt.EventQueue)

Example 12 with AWTEvent

use of java.awt.AWTEvent in project jodd by oblac.

the class CaddyDialog method setVisible.

@Override
public void setVisible(boolean visible) {
    boolean blockParent = (visible && modal);
    owner.setEnabled(!blockParent);
    owner.setFocusableWindowState(!blockParent);
    super.setVisible(visible);
    if (blockParent) {
        owner.addWindowListener(parentWindowListener);
        try {
            if (SwingUtilities.isEventDispatchThread()) {
                EventQueue theQueue = getToolkit().getSystemEventQueue();
                while (isVisible()) {
                    AWTEvent event = theQueue.getNextEvent();
                    Object src = event.getSource();
                    if (event instanceof ActiveEvent) {
                        ((ActiveEvent) event).dispatch();
                    } else if (src instanceof Component) {
                        ((Component) src).dispatchEvent(event);
                    }
                }
            } else {
                synchronized (getTreeLock()) {
                    while (isVisible()) {
                        try {
                            getTreeLock().wait();
                        } catch (InterruptedException e) {
                            break;
                        }
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else {
        owner.removeWindowListener(parentWindowListener);
        // added 2 lines
        owner.setEnabled(true);
        owner.setFocusableWindowState(true);
    }
}
Also used : ActiveEvent(java.awt.ActiveEvent) AWTEvent(java.awt.AWTEvent) Component(java.awt.Component) EventQueue(java.awt.EventQueue)

Example 13 with AWTEvent

use of java.awt.AWTEvent in project adempiere by adempiere.

the class VNumber method fireActionPerformed.

//	addActionListener
/**
	 * 	Fire Action Event to listeners
	 */
protected void fireActionPerformed() {
    int modifiers = 0;
    AWTEvent currentEvent = EventQueue.getCurrentEvent();
    if (currentEvent instanceof InputEvent)
        modifiers = ((InputEvent) currentEvent).getModifiers();
    else if (currentEvent instanceof ActionEvent)
        modifiers = ((ActionEvent) currentEvent).getModifiers();
    ActionEvent ae = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, currentEvent.getClass().getSimpleName(), EventQueue.getMostRecentEventTime(), modifiers);
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == ActionListener.class) {
            ((ActionListener) listeners[i + 1]).actionPerformed(ae);
        }
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) AWTEvent(java.awt.AWTEvent) InputEvent(java.awt.event.InputEvent)

Example 14 with AWTEvent

use of java.awt.AWTEvent in project GDSC-SMLM by aherbert.

the class BenchmarkFilterAnalysis method saveTemplate.

/**
	 * Save PeakFit configuration template using the current benchmark settings.
	 * 
	 * @param topFilterSummary
	 */
private void saveTemplate(String topFilterSummary) {
    FitEngineConfiguration config = new FitEngineConfiguration(new FitConfiguration());
    if (!updateAllConfiguration(config, true)) {
        IJ.log("Unable to create the template configuration");
        return;
    }
    // Remove the PSF width to make the template generic
    config.getFitConfiguration().setInitialPeakStdDev(0);
    String filename = getFilename("Template_File", templateFilename);
    if (filename != null) {
        templateFilename = filename;
        Prefs.set(KEY_TEMPLATE_FILENAME, filename);
        GlobalSettings settings = new GlobalSettings();
        settings.setNotes(getNotes(topFilterSummary));
        settings.setFitEngineConfiguration(config);
        if (!SettingsManager.saveSettings(settings, filename, true)) {
            IJ.log("Unable to save the template configuration");
            return;
        }
        // Save some random frames from the test image data
        ImagePlus imp = CreateData.getImage();
        if (imp == null)
            return;
        // Get the number of frames
        final ImageStack stack = imp.getImageStack();
        if (sampler == null || sampler.getResults() != results) {
            sampler = new ResultsImageSampler(results, stack, 32);
            sampler.analyse();
        }
        if (!sampler.isValid())
            return;
        // Iteratively show the example until the user is happy.
        // Yes = OK, No = Repeat, Cancel = Do not save
        String keyNo = "nNo";
        String keyLow = "nLower";
        String keyHigh = "nHigher";
        if (Utils.isMacro()) {
            // Collect the options if running in a macro
            String options = Macro.getOptions();
            nNo = Integer.parseInt(Macro.getValue(options, keyNo, Integer.toString(nNo)));
            nLow = Integer.parseInt(Macro.getValue(options, keyLow, Integer.toString(nLow)));
            nHigh = Integer.parseInt(Macro.getValue(options, keyHigh, Integer.toString(nHigh)));
        } else {
            if (nLow + nHigh == 0)
                nLow = nHigh = 1;
        }
        final ImagePlus[] out = new ImagePlus[1];
        out[0] = sampler.getSample(nNo, nLow, nHigh);
        if (!Utils.isMacro()) {
            // Show the template results
            final ConfigurationTemplate configTemplate = new ConfigurationTemplate();
            // Interactively show the sample image data
            final boolean[] close = new boolean[1];
            final ImagePlus[] outImp = new ImagePlus[1];
            if (out[0] != null) {
                outImp[0] = display(out[0]);
                if (Utils.isNewWindow()) {
                    close[0] = true;
                    // Zoom a bit
                    ImageWindow iw = outImp[0].getWindow();
                    for (int i = 7; i-- > 0 && Math.max(iw.getWidth(), iw.getHeight()) < 512; ) {
                        iw.getCanvas().zoomIn(0, 0);
                    }
                }
                configTemplate.createResults(outImp[0]);
            }
            // TODO - fix this when a second sample is made as the results are not updated.
            ImageListener listener = new ImageListener() {

                public void imageOpened(ImagePlus imp) {
                }

                public void imageClosed(ImagePlus imp) {
                }

                public void imageUpdated(ImagePlus imp) {
                    if (imp != null && imp == outImp[0]) {
                        configTemplate.updateResults(imp.getCurrentSlice());
                    }
                }
            };
            ImagePlus.addImageListener(listener);
            // For the dialog
            String msg = String.format("Showing image data for the template example.\n \nSample Frames:\nEmpty = %d\nLower density = %d\nHigher density = %d\n", sampler.getNumberOfEmptySamples(), sampler.getNumberOfLowDensitySamples(), sampler.getNumberOfHighDensitySamples());
            // Turn off the recorder when the dialog is showing
            boolean record = Recorder.record;
            Recorder.record = false;
            NonBlockingGenericDialog gd = new NonBlockingGenericDialog(TITLE);
            gd.addMessage(msg);
            //gd.enableYesNoCancel(" Save ", " Resample ");
            gd.addSlider(keyNo, 0, 10, nNo);
            gd.addSlider(keyLow, 0, 10, nLow);
            gd.addSlider(keyHigh, 0, 10, nHigh);
            gd.addDialogListener(new DialogListener() {

                public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
                    // image the user has not seen.
                    if (e == null)
                        return true;
                    nNo = (int) gd.getNextNumber();
                    nLow = (int) gd.getNextNumber();
                    nHigh = (int) gd.getNextNumber();
                    out[0] = sampler.getSample(nNo, nLow, nHigh);
                    if (out[0] != null) {
                        outImp[0] = display(out[0]);
                        if (Utils.isNewWindow()) {
                            close[0] = true;
                            // Zoom a bit
                            ImageWindow iw = outImp[0].getWindow();
                            for (int i = 7; i-- > 0 && Math.max(iw.getWidth(), iw.getHeight()) < 512; ) {
                                iw.getCanvas().zoomIn(0, 0);
                            }
                        }
                        configTemplate.createResults(outImp[0]);
                    }
                    return true;
                }
            });
            gd.showDialog();
            if (gd.wasCanceled()) {
                out[0] = null;
                // For the recorder
                nNo = nLow = nHigh = 0;
            }
            if (close[0]) {
                // Because closing the image sets the stack pixels array to null
                if (out[0] != null)
                    out[0] = out[0].duplicate();
                outImp[0].close();
            }
            configTemplate.closeResults();
            ImagePlus.removeImageListener(listener);
            if (record) {
                Recorder.record = true;
                Recorder.recordOption(keyNo, Integer.toString(nNo));
                Recorder.recordOption(keyLow, Integer.toString(nLow));
                Recorder.recordOption(keyHigh, Integer.toString(nHigh));
            }
        }
        if (out[0] == null)
            return;
        ImagePlus example = out[0];
        filename = Utils.replaceExtension(filename, ".tif");
        IJ.save(example, filename);
    }
}
Also used : ResultsImageSampler(gdsc.smlm.ij.results.ResultsImageSampler) ImageWindow(ij.gui.ImageWindow) ImageStack(ij.ImageStack) ImageListener(ij.ImageListener) FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog) ImagePlus(ij.ImagePlus) FitConfiguration(gdsc.smlm.fitting.FitConfiguration) DialogListener(ij.gui.DialogListener) GenericDialog(ij.gui.GenericDialog) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog) AWTEvent(java.awt.AWTEvent)

Example 15 with AWTEvent

use of java.awt.AWTEvent in project jdk8u_jdk by JetBrains.

the class TestErrorException method init.

public void init() {
    robot = Util.createRobot();
    kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

        public void eventDispatched(AWTEvent event) {
            System.out.println("--> " + event);
        }
    }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
}
Also used : AWTEventListener(java.awt.event.AWTEventListener) AWTEvent(java.awt.AWTEvent)

Aggregations

AWTEvent (java.awt.AWTEvent)25 MouseEvent (java.awt.event.MouseEvent)8 WakeupCriterion (javax.media.j3d.WakeupCriterion)8 WakeupOnAWTEvent (javax.media.j3d.WakeupOnAWTEvent)8 AWTEventListener (java.awt.event.AWTEventListener)6 ActionEvent (java.awt.event.ActionEvent)5 Component (java.awt.Component)4 InputEvent (java.awt.event.InputEvent)4 ActionListener (java.awt.event.ActionListener)3 ActiveEvent (java.awt.ActiveEvent)2 EventQueue (java.awt.EventQueue)2 Point (java.awt.Point)2 Transform3D (javax.media.j3d.Transform3D)2 JButton (javax.swing.JButton)2 SplashWindow (apps.SplashWindow)1 DatabaseWindowPanel (cbit.vcell.client.desktop.DatabaseWindowPanel)1 BioModelMetaDataPanel (cbit.vcell.desktop.BioModelMetaDataPanel)1 BioModelNode (cbit.vcell.desktop.BioModelNode)1 GeometryMetaDataPanel (cbit.vcell.desktop.GeometryMetaDataPanel)1 MathModelMetaDataPanel (cbit.vcell.desktop.MathModelMetaDataPanel)1