java.awt.event.WindowEvent Java Examples

The following examples show how to use java.awt.event.WindowEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Application.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 7 votes vote down vote up
private void setupUI() {
    frame = new JFrame("Gradle");

    JPanel mainPanel = new JPanel(new BorderLayout());
    frame.getContentPane().add(mainPanel);

    mainPanel.add(singlePaneUIInstance.getComponent());
    mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    singlePaneUIInstance.aboutToShow();

    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            close();
        }
    });

    frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    frame.setLocationByPlatform(true);
}
 
Example #2
Source File: MapLayout.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Show measurment form
 */
public void showMeasurementForm() {
    if (_frmMeasure == null) {
        _frmMeasure = new FrmMeasurement((JFrame) SwingUtilities.getWindowAncestor(this), false);
        _frmMeasure.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                _currentLayoutMap.getMapFrame().getMapView().setDrawIdentiferShape(false);
                //repaint();
                repaintOld();
            }
        });
        _frmMeasure.setLocationRelativeTo(this);
        _frmMeasure.setVisible(true);
    } else if (!_frmMeasure.isVisible()) {
        _frmMeasure.setVisible(true);
    }
}
 
Example #3
Source File: Util.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean trackEvent(int eventID, Component comp, Runnable action, int time, boolean printEvent) {
    EventListener listener = null;

    switch (eventID) {
    case WindowEvent.WINDOW_GAINED_FOCUS:
        listener = wgfListener;
        break;
    case FocusEvent.FOCUS_GAINED:
        listener = fgListener;
        break;
    case ActionEvent.ACTION_PERFORMED:
        listener = apListener;
        break;
    }

    listener.listen(comp, printEvent);
    action.run();
    return Util.waitForCondition(listener.getNotifier(), time);
}
 
Example #4
Source File: ProfileSelectWindow.java    From amidst with GNU General Public License v3.0 6 votes vote down vote up
@CalledOnlyBy(AmidstThread.EDT)
private JFrame createFrame() {
	JFrame frame = new JFrame("Profile Selector");
	frame.setIconImages(metadata.getIcons());
	frame.getContentPane().setLayout(new MigLayout());
	frame.add(createTitleLabel(), "h 20!,w :400:, growx, pushx, wrap");
	frame.add(createScrollPanel(), getScrollPaneLayoutString());
	frame.pack();
	frame.addKeyListener(profileSelectPanel.createKeyListener());
	frame.addWindowListener(new WindowAdapter() {
		@Override
		public void windowClosing(WindowEvent e) {
			application.exitGracefully();
		}
	});
	frame.setLocation(200, 200);
	frame.setVisible(true);
	return frame;
}
 
Example #5
Source File: EditPad.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    JFrame jframe = new JFrame(windowLabel == null
            ? getResourceString("editpad.name")
            : windowLabel);
    Runnable closer = () -> {
        jframe.setVisible(false);
        jframe.dispose();
        closeMark.run();
    };
    jframe.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            closer.run();
        }
    });
    jframe.setLocationRelativeTo(null);
    jframe.setLayout(new BorderLayout());
    JTextArea textArea = new JTextArea(initialText);
    textArea.setFont(new Font("monospaced", Font.PLAIN, 13));
    jframe.add(new JScrollPane(textArea), BorderLayout.CENTER);
    jframe.add(buttons(closer, textArea), BorderLayout.SOUTH);

    jframe.setSize(800, 600);
    jframe.setVisible(true);
}
 
Example #6
Source File: NumberingWizard.java    From Digital with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance
 *
 * @param parent           the parent frame
 * @param circuitComponent the component used to select the inputs and outputs
 */
public NumberingWizard(JFrame parent, CircuitComponent circuitComponent) {
    super(parent, Lang.get("msg_numberingWizard"), false);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    this.circuitComponent = circuitComponent;
    label = new JLabel();
    label.setFont(Screen.getInstance().getFont(1.5f));
    int b = Screen.getInstance().getFontSize();
    label.setBorder(BorderFactory.createEmptyBorder(b, b, b, b));
    setPinNumber(999);
    getContentPane().add(label);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent windowEvent) {
            circuitComponent.deactivateWizard();
        }
    });
    pack();

    pinNumber = 1;
    setPinNumber(pinNumber);
    setLocation(parent.getLocation());
}
 
Example #7
Source File: Font2DTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void loadComparisonPNG( String fileName ) {
    try {
        BufferedImage image =
            javax.imageio.ImageIO.read(new File(fileName));
        JFrame f = new JFrame( "Comparison PNG" );
        ImagePanel ip = new ImagePanel( image );
        f.setResizable( false );
        f.getContentPane().add( ip );
        f.addWindowListener( new WindowAdapter() {
            public void windowClosing( WindowEvent e ) {
                ( (JFrame) e.getSource() ).dispose();
            }
        });
        f.pack();
        f.show();
    }
    catch ( Exception ex ) {
        fireChangeStatus( "ERROR: Failed to Load PNG File; See Stack Trace", true );
        ex.printStackTrace();
    }
}
 
Example #8
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void actionPerformed(ActionEvent e) {
  Component root;
  Container parent = SwingUtilities.getUnwrappedParent((Component) e.getSource());
  if (parent instanceof JPopupMenu) {
    JPopupMenu popup = (JPopupMenu) parent;
    root = SwingUtilities.getRoot(popup.getInvoker());
  } else if (parent instanceof JToolBar) {
    JToolBar toolbar = (JToolBar) parent;
    if (((BasicToolBarUI) toolbar.getUI()).isFloating()) {
      root = SwingUtilities.getWindowAncestor(toolbar).getOwner();
    } else {
      root = SwingUtilities.getRoot(toolbar);
    }
  } else {
    root = SwingUtilities.getRoot(parent);
  }
  if (root instanceof Window) {
    Window window = (Window) root;
    window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
  }
}
 
Example #9
Source File: JFrame.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Processes window events occurring on this component.
 * Hides the window or disposes of it, as specified by the setting
 * of the <code>defaultCloseOperation</code> property.
 *
 * @param  e  the window event
 * @see    #setDefaultCloseOperation
 * @see    java.awt.Window#processWindowEvent
 */
protected void processWindowEvent(final WindowEvent e) {
    super.processWindowEvent(e);

    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
        switch (defaultCloseOperation) {
            case HIDE_ON_CLOSE:
                setVisible(false);
                break;
            case DISPOSE_ON_CLOSE:
                dispose();
                break;
            case EXIT_ON_CLOSE:
                // This needs to match the checkExit call in
                // setDefaultCloseOperation
                System.exit(0);
                break;
            case DO_NOTHING_ON_CLOSE:
            default:
        }
    }
}
 
Example #10
Source File: JFontChooser.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Show font selection dialog.
 * 
 * @param parent Dialog's Parent component.
 * @return OK_OPTION, CANCEL_OPTION or ERROR_OPTION
 *
 * @see #OK_OPTION
 * @see #CANCEL_OPTION
 * @see #ERROR_OPTION
 **/
public int showDialog(Component parent) {
	dialogResultValue = ERROR_OPTION;
	JDialog dialog = createDialog(parent);
	dialog.addWindowListener(new WindowAdapter() {
		@Override
		public void windowClosing(WindowEvent e) {
			dialogResultValue = CANCEL_OPTION;
		}
	});

	dialog.setVisible(true);
	dialog.dispose();
	dialog = null;

	return dialogResultValue;
}
 
Example #11
Source File: DesktopIdeFrameImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setupCloseAction() {
  myJFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  myJFrame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(@Nonnull final WindowEvent e) {
      if (isTemporaryDisposed()) return;

      final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
      if (openProjects.length > 1 || openProjects.length == 1 && TopApplicationMenuUtil.isMacSystemMenu) {
        if (myProject != null && myProject.isOpen()) {
          ProjectUtil.closeAndDispose(myProject);
        }
        ApplicationManager.getApplication().getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).projectFrameClosed();
        WelcomeFrame.showIfNoProjectOpened();
      }
      else {
        Application.get().exit();
      }
    }
  });
}
 
Example #12
Source File: FileViewerFactory.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
/**
		 * Viewer has been closed so allow it to be garbage collected.
		 */
//		public void internalFrameClosed(InternalFrameEvent evt)
		public void windowClosed(WindowEvent evt)
		{
//			removeViewer((HtmlViewerSheet)evt.getInternalFrame());
			removeViewer((HtmlViewerSheet)evt.getWindow());
//			super.internalFrameClosed(evt);
		}
 
Example #13
Source File: CustomizerProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void windowClosing( WindowEvent e ) {
    //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
    //may not be called
    Dialog dialog = (Dialog)project2Dialog.get( project );
    if ( dialog != null ) {
        dialog.setVisible(false);
        dialog.dispose();
    }
}
 
Example #14
Source File: TargetFileListFrame.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void initGUI(Point location) {
    this.setLocation(location);
    this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            TargetFileListFrame.this.dispose();
        }
    });
    this.add(new Panel().add(list));
    this.pack();
    this.setVisible(true);
}
 
Example #15
Source File: EditableDisplayerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void windowOpened(WindowEvent e) {
    shown = true;
    synchronized(this) {
        //System.err.println("window opened");
        notifyAll();
        ((JFrame) e.getSource()).removeWindowListener(this);
    }
}
 
Example #16
Source File: ProjectCustomizerProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void windowClosing (WindowEvent e) {
    //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
    //may not be called
    Dialog dialog = project2Dialog.get( project );
    if ( dialog != null ) {
        dialog.setVisible(false);
        dialog.dispose();
    }
}
 
Example #17
Source File: FilePathRepair.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
private final Runnable makeGUI() {
	return new Runnable() { public void run() {
		JScrollPane jsp = new JScrollPane(table);
		jsp.setPreferredSize(new Dimension(500, 500));
		table.addMouseListener(listener);
		JLabel label = new JLabel("Double-click any to repair file path:");
		JLabel label2 = new JLabel("(Any listed with identical parent folder will be fixed as well.)");
		JPanel plabel = new JPanel();
		BoxLayout pbl = new BoxLayout(plabel, BoxLayout.Y_AXIS);
		plabel.setLayout(pbl);
		//plabel.setBorder(new LineBorder(Color.black, 1, true));
		plabel.setMinimumSize(new Dimension(400, 40));
		plabel.add(label);
		plabel.add(label2);
		JPanel all = new JPanel();
		BoxLayout bl = new BoxLayout(all, BoxLayout.Y_AXIS);
		all.setLayout(bl);
		all.add(plabel);
		all.add(jsp);
		frame.getContentPane().add(all);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent we) {
				synchronized (projects) {
					if (data.vpath.size() > 0 ) {
						Utils.logAll("WARNING: Some images remain associated to inexistent file paths.");
					}
					projects.remove(project);
				}
			}
		});
		frame.pack();
		ij.gui.GUI.center(frame);
		frame.setVisible(true);
	}};
}
 
Example #18
Source File: SunToolkit.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void postEvent(AppContext appContext, AWTEvent event) {
    if (event == null) {
        throw new NullPointerException();
    }

    AWTAccessor.SequencedEventAccessor sea = AWTAccessor.getSequencedEventAccessor();
    if (sea != null && sea.isSequencedEvent(event)) {
        AWTEvent nested = sea.getNested(event);
        if (nested.getID() == WindowEvent.WINDOW_LOST_FOCUS &&
            nested instanceof TimedWindowEvent)
        {
            TimedWindowEvent twe = (TimedWindowEvent)nested;
            ((SunToolkit)Toolkit.getDefaultToolkit()).
                setWindowDeactivationTime((Window)twe.getSource(), twe.getWhen());
        }
    }

    // All events posted via this method are system-generated.
    // Placing the following call here reduces considerably the
    // number of places throughout the toolkit that would
    // otherwise have to be modified to precisely identify
    // system-generated events.
    setSystemGenerated(event);
    AppContext eventContext = targetToAppContext(event.getSource());
    if (eventContext != null && !eventContext.equals(appContext)) {
        throw new RuntimeException("Event posted on wrong app context : " + event);
    }
    PostEventQueue postEventQueue =
        (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
    if (postEventQueue != null) {
        postEventQueue.postEvent(event);
    }
}
 
Example #19
Source File: ElementaryCA.java    From aifh with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void windowActivated(WindowEvent arg0) {
    // TODO Auto-generated method stub

}
 
Example #20
Source File: ByoYomiAutoPlayDialog.java    From mylizzie with GNU General Public License v3.0 5 votes vote down vote up
private void thisWindowClosing(WindowEvent e) {
    countdownSystemStop();
    stopCountdown();
    Lizzie.board.unregisterBoardStateChangeObserver(boardStateChangeObserver);

    OptionSetting.ByoYomiSetting byoYomiSetting = Lizzie.optionSetting.getByoYomiSetting();
    byoYomiSetting.setByoYomiTime((Integer) spinnerCountdownTime.getValue());
    byoYomiSetting.setStopThinkingWhenCountingDown(checkBoxStopThinkingWhenCountDown.isSelected());
}
 
Example #21
Source File: StopTask.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
private void stop() {
    JFrame jf = MainWindowManager.mainWindowManager().getMainWindow();
    
    WindowEvent wev = new WindowEvent(jf, WindowEvent.WINDOW_CLOSING);
    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);

    writeAck("Shutting down");
}
 
Example #22
Source File: NonBrokerageAccountDialogHandler.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean filterEvent(Window window, int eventId) {
    switch (eventId) {
        case WindowEvent.WINDOW_OPENED:
            return true;
        default:
            return false;
    }
}
 
Example #23
Source File: SettingsDialog.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Sets up the related {@link SettingsTabs} and buttons for the Studio settings. This uses {@link #getDefaultStudioHandler()}
 * and {@link SettingsItems#INSTANCE} for initialization.
 *
 * Selects the specified selected tab.
 *
 * @param initialSelectedTab
 *            A key of a preferences group to identify the initial selected tab.
 */
public SettingsDialog(String initialSelectedTab) {
	this(getDefaultStudioHandler(), SettingsItems.INSTANCE, initialSelectedTab);
	// add listener to remove parameter handler when dialog is closed
	addWindowListener(new WindowAdapter() {
		@Override
		public void windowClosed(WindowEvent e) {
			parameterHandler.getParameters().getParameterTypes().stream()
					.flatMap(pt -> pt.getConditions().stream()).forEach(pc -> pc.setParameterHandler(null));
		}
	});
}
 
Example #24
Source File: TargetFileListFrame.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void initGUI(Point location) {
    this.setLocation(location);
    this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            TargetFileListFrame.this.dispose();
        }
    });
    this.add(new Panel().add(list));
    this.pack();
    this.setVisible(true);
}
 
Example #25
Source File: AbstractLoginHandler.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean filterEvent(Window window, int eventId) {
    switch (eventId) {
        case WindowEvent.WINDOW_OPENED:
            return true;
        default:
            return false;
    }
}
 
Example #26
Source File: ContainerFocusAutoTransferTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #27
Source File: ContainerFocusAutoTransferTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #28
Source File: MultimonFullscreenTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void windowClosing(WindowEvent we) {
    done = true;
    Window w = (Window)we.getSource();
    if (setNullOnDispose) {
        w.getGraphicsConfiguration().getDevice().setFullScreenWindow(null);
    }
    w.dispose();
}
 
Example #29
Source File: KeyboardFocusManager.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static AWTEvent retargetFocusEvent(AWTEvent event) {
    if (clearingCurrentLightweightRequests) {
        return event;
    }

    KeyboardFocusManager manager = getCurrentKeyboardFocusManager();
    if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
        if (event instanceof FocusEvent || event instanceof WindowEvent) {
            focusLog.finer(">>> {0}", String.valueOf(event));
        }
        if (focusLog.isLoggable(PlatformLogger.Level.FINER) && event instanceof KeyEvent) {
            focusLog.finer("    focus owner is {0}",
                           String.valueOf(manager.getGlobalFocusOwner()));
            focusLog.finer(">>> {0}", String.valueOf(event));
        }
    }

    synchronized(heavyweightRequests) {
        /*
         * This code handles FOCUS_LOST event which is generated by
         * DefaultKeyboardFocusManager for FOCUS_GAINED.
         *
         * This code based on knowledge of DefaultKeyboardFocusManager's
         * implementation and might be not applicable for another
         * KeyboardFocusManager.
         *
         * Fix for 4472032
         */
        if (newFocusOwner != null &&
            event.getID() == FocusEvent.FOCUS_LOST)
        {
            FocusEvent fe = (FocusEvent)event;

            if (manager.getGlobalFocusOwner() == fe.getComponent() &&
                fe.getOppositeComponent() == newFocusOwner)
            {
                newFocusOwner = null;
                return event;
            }
        }
    }

    processCurrentLightweightRequests();

    switch (event.getID()) {
        case FocusEvent.FOCUS_GAINED: {
            event = retargetFocusGained((FocusEvent)event);
            break;
        }
        case FocusEvent.FOCUS_LOST: {
            event = retargetFocusLost((FocusEvent)event);
            break;
        }
        default:
            /* do nothing */
    }
    return event;
}
 
Example #30
Source File: InteractiveIntegral.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
      public void windowClosing (WindowEvent e) 
{ 
	close( parent, sliceObserver, imp );
}