1 19 20 21 package org.netbeans.modules.debugger.jpda.ui.actions; 22 23 24 import java.awt.event.ActionEvent ; 25 import java.util.Iterator ; 26 import javax.swing.Action ; 27 import javax.swing.AbstractAction ; 28 import javax.swing.ImageIcon ; 29 30 import org.netbeans.modules.debugger.jpda.ui.views.SourcesView; 31 32 import org.openide.util.NbBundle; 33 import org.openide.util.Utilities; 34 import org.openide.windows.Mode; 35 import org.openide.windows.TopComponent; 36 import org.openide.windows.WindowManager; 37 38 39 44 public class SourcesViewAction extends AbstractAction { 45 46 public SourcesViewAction () { 47 putValue ( 48 Action.NAME, 49 NbBundle.getMessage ( 50 SourcesViewAction.class, 51 "CTL_SourcesViewAction" 52 ) 53 ); 54 putValue ( 55 Action.SMALL_ICON, 56 new ImageIcon (Utilities.loadImage ("org/netbeans/modules/debugger/jpda/resources/root.gif")) ); 58 } 59 60 public void actionPerformed (ActionEvent evt) { 61 if (activateComponent (SourcesView.class)) return; 62 SourcesView v = new SourcesView (); 63 v.open (); 64 v.requestActive (); 65 } 66 static boolean activateComponent (Class componentClass) { 68 Iterator it = WindowManager.getDefault ().getModes ().iterator (); 69 while (it.hasNext ()) { 70 Mode m = (Mode) it.next (); 71 TopComponent[] tcs = m.getTopComponents (); 72 int i, k = tcs.length; 73 for (i = 0; i < k; i++) 74 if (tcs [i].getClass ().equals (componentClass)) { 75 tcs [i].open (); 76 tcs [i].requestActive (); 77 return true; 78 } 79 } 80 return false; 81 } 82 } 83 84 | Popular Tags |