KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > actions > CloneDocumentAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.core.windows.actions;
22
23
24 import org.netbeans.core.windows.Constants;
25 import org.netbeans.core.windows.ModeImpl;
26 import org.netbeans.core.windows.WindowManagerImpl;
27 import org.openide.util.NbBundle;
28 import org.openide.util.WeakListeners;
29 import org.openide.windows.TopComponent;
30
31 import javax.swing.*;
32 import java.beans.PropertyChangeEvent JavaDoc;
33 import java.beans.PropertyChangeListener JavaDoc;
34
35
36 /**
37  * @author Peter Zavadsky
38  */

39 public class CloneDocumentAction extends AbstractAction
40 implements PropertyChangeListener JavaDoc {
41
42     public CloneDocumentAction() {
43         putValue(NAME, NbBundle.getMessage(CloneDocumentAction.class, "CTL_CloneDocumentAction"));
44         TopComponent.getRegistry().addPropertyChangeListener(
45             WeakListeners.propertyChange(this, TopComponent.getRegistry()));
46         updateEnabled();
47     }
48     
49     /** Perform the action. Sets/unsets maximzed mode. */
50     public void actionPerformed(java.awt.event.ActionEvent JavaDoc ev) {
51         TopComponent tc = TopComponent.getRegistry().getActivated();
52         if(tc == null || !(tc instanceof TopComponent.Cloneable)) {
53             return;
54         }
55         
56         ModeImpl mode = (ModeImpl)WindowManagerImpl.getInstance().findMode(tc);
57         if(mode == null) {
58             return;
59         }
60         
61         if(mode.getKind() == Constants.MODE_KIND_EDITOR) {
62             ActionUtils.cloneWindow(tc);
63         }
64     }
65
66     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
67         if(TopComponent.Registry.PROP_ACTIVATED.equals(evt.getPropertyName())) {
68             updateEnabled();
69         }
70     }
71     
72     private void updateEnabled() {
73         TopComponent tc = TopComponent.getRegistry().getActivated();
74         ModeImpl mode = (ModeImpl)WindowManagerImpl.getInstance().findMode(tc);
75         setEnabled(tc instanceof TopComponent.Cloneable
76             && mode != null && mode.getKind() == Constants.MODE_KIND_EDITOR);
77     }
78     
79 }
80
81
Popular Tags