ActShowEventSource.java :  » Swing-Library » swingexplorer » org » swingexplorer » Java Open Source

Java Open Source » Swing Library » swingexplorer 
swingexplorer » org » swingexplorer » ActShowEventSource.java
/*
 *   Swing Explorer. Tool for developers exploring Java/Swing-based application internals. 
 *   Copyright (C) 2008, Maxim Zakharenkov
 *
 *   This program 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 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program 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, write to the Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 *  $Header: /cvs/swingexplorer/src/org/swingexplorer/ActShowEventSource.java,v 1.1 2008/02/13 21:52:11 maxz1 Exp $
 */
package org.swingexplorer;

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

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import org.swingexplorer.awt_events.PNLAwtEvents;



/**
 * 
 * @author Maxim Zakharenkov
 */
public class ActShowEventSource extends RichAction {
  
  MdlSwingExplorer mdlSwingExplorer;
  PNLAwtEvents pnlAwtEvents;

  public ActShowEventSource(MdlSwingExplorer _mdlSwingExplorer, PNLAwtEvents _pnlAwtEvents) {
    mdlSwingExplorer = _mdlSwingExplorer;
    pnlAwtEvents = _pnlAwtEvents;
    setName("Show event source");
    setTooltip("Select component the event comes from");
  }

  public void actionPerformed(ActionEvent e) {
    AWTEvent evt = pnlAwtEvents.getSelectedEvent();
    if(evt == null) {
      JOptionPane.showMessageDialog(pnlAwtEvents, "There is no event selected");
    } else {
      // update displayed component to source's ancestor
      Component evtSource = (Component)evt.getSource();
      
      // find topmost source's container and use it as displayed component
      Component sourceContainer = evtSource;
      while(sourceContainer.getParent() != null) {
        sourceContainer = sourceContainer.getParent();
      }
      
      mdlSwingExplorer.setDisplayedComponent(sourceContainer);
      
      // select event source component
      mdlSwingExplorer.setSelection(evtSource);
    }
  }
}
/*
 * $Log: ActShowEventSource.java,v $
 * Revision 1.1  2008/02/13 21:52:11  maxz1
 * Added event filtering functionality
 *
 * Revision 1.2  2008/02/06 08:36:08  maxz1
 * Changed license header
 *
 * Revision 1.1  2007/06/27 19:41:37  maxz1
 * new
 *
 */
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.