001: /*
002: * Created on 13/10/2004
003: *
004: * Swing Components - visit http://sf.net/projects/gfd
005: *
006: * Copyright (C) 2004 Igor Regis da Silva Simões
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022: package br.com.gfp.actions;
023:
024: import java.awt.Component;
025: import java.awt.event.ActionEvent;
026: import java.awt.event.ActionListener;
027: import java.beans.PropertyVetoException;
028:
029: import javax.swing.JDesktopPane;
030: import javax.swing.JInternalFrame;
031:
032: import br.com.gfp.dao.GFPController;
033: import br.com.gfp.util.SimpleLog;
034:
035: /**
036: * @author Igor Regis da Silva Simoes
037: */
038: public class FecharTodasTelasAction implements ActionListener {
039: private static FecharTodasTelasAction action = null;
040:
041: private JDesktopPane desktop = null;
042:
043: private Thread acao = new Thread("FecharTodasJanelas") {
044: {
045: setPriority(Thread.MAX_PRIORITY);
046: }
047:
048: @Override
049: public void run() {
050: if (desktop == null)
051: desktop = (JDesktopPane) GFPController
052: .getGFPController().getContexto().get(
053: GFPController.DESKTOP);
054: Component[] telas = desktop.getAllFrames();
055: for (int n = 0; n < telas.length; n++) {
056: try {
057: ((JInternalFrame) telas[n]).setClosed(true);
058: desktop.remove(telas[n]);
059: } catch (PropertyVetoException e) {
060: ((SimpleLog) GFPController.getGFPController()
061: .getContexto().get(GFPController.LOG))
062: .log("Erro ao fechar janelas!");
063: ((SimpleLog) GFPController.getGFPController()
064: .getContexto().get(GFPController.LOG))
065: .log(e.getLocalizedMessage());
066: ((SimpleLog) GFPController.getGFPController()
067: .getContexto().get(GFPController.LOG))
068: .log(e);
069: }
070: }
071: desktop.repaint();
072: acao = new Thread(this , "FecharTodasJanelas");
073: }
074: };
075:
076: /**
077: *
078: */
079: private FecharTodasTelasAction() {
080: super ();
081: }
082:
083: /**
084: * @return Retorna uma instancia desta action
085: */
086: public static FecharTodasTelasAction getAction() {
087: return action;
088: }
089:
090: /**
091: *
092: */
093: public static void initializeAction() {
094: if (action == null)
095: action = new FecharTodasTelasAction();
096: }
097:
098: /**
099: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
100: */
101: public void actionPerformed(ActionEvent e) {
102: acao.start();
103: }
104: }
|