Java Swing Key Action makeCloseAction(final Window window)

Here you can find the source of makeCloseAction(final Window window)

Description

make Close Action

License

Open Source License

Declaration

@SuppressWarnings("serial")
    public static Action makeCloseAction(final Window window) 

Method Source Code

//package com.java2s;
/**************************************************************************
 OmegaT - Computer Assisted Translation (CAT) tool 
  with fuzzy matching, translation memory, keyword search, 
  glossaries, and translation leveraging into updated projects.
    //www  . j a va2 s . c  o m
 Copyright (C) 2006 Henry Pijffers
       2013 Yu Tang
       2014-2015 Aaron Madlon-Kay
       Home page: http://www.omegat.org/
       Support center: http://groups.yahoo.com/group/OmegaT/
    
 This file is part of OmegaT.
    
 OmegaT is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 OmegaT is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **************************************************************************/

import java.awt.Window;
import java.awt.event.ActionEvent;

import java.awt.event.WindowEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;

public class Main {
    @SuppressWarnings("serial")
    public static Action makeCloseAction(final Window window) {
        return new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                closeWindowByEvent(window);
            }
        };
    }

    /**
     * Send a {@link WindowEvent#WINDOW_CLOSING} event to the supplied window.
     * This mimics closing by clicking the window close button.
     */
    public static void closeWindowByEvent(Window window) {
        window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
    }
}

Related

  1. keyEventPressed(KeyEvent event, KeyStroke keyStroke)
  2. keyStrokeToString(final KeyStroke keyStroke)
  3. keyStrokeToString(KeyStroke key)
  4. keyStrokeToString(KeyStroke key)
  5. keyStrokeToString(KeyStroke key)
  6. matches(Action action, KeyEvent ke)
  7. parseKeyStroke(String keyStroke)
  8. parseKeyStroke(String keyStroke)
  9. pressKey(Component component, int keyCode, int modifier)