KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > diff > builtin > visualizer > SourceTranslatorAction


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 package org.netbeans.modules.diff.builtin.visualizer;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.beans.PropertyChangeSupport JavaDoc;
25 import javax.swing.Action JavaDoc;
26
27
28 /**
29  * Re-sources action to given source.
30  *
31  * @author Petr Kuzel
32  */

33 public class SourceTranslatorAction implements Action JavaDoc, PropertyChangeListener JavaDoc {
34
35     final Action JavaDoc scrollAction;
36     final Object JavaDoc source;
37     final PropertyChangeSupport JavaDoc support;
38
39     public SourceTranslatorAction(Action JavaDoc action, Object JavaDoc source) {
40         scrollAction = action;
41         this.source = source;
42         support = new PropertyChangeSupport JavaDoc(action);
43     }
44
45     public Object JavaDoc getValue(String JavaDoc key) {
46         return scrollAction.getValue(key);
47     }
48
49     public void putValue(String JavaDoc key, Object JavaDoc value) {
50         scrollAction.putValue(key, value);
51     }
52
53     public void setEnabled(boolean b) {
54         scrollAction.setEnabled(b);
55     }
56
57     public boolean isEnabled() {
58         return scrollAction.isEnabled();
59     }
60
61     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
62         if (support.hasListeners(null) == false) {
63             scrollAction.addPropertyChangeListener(this);
64         }
65         support.addPropertyChangeListener(listener);
66     }
67
68     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
69         support.removePropertyChangeListener(listener);
70         if (support.hasListeners(null) == false) {
71             scrollAction.removePropertyChangeListener(this);
72         }
73     }
74
75     public void actionPerformed(ActionEvent JavaDoc e) {
76         ActionEvent JavaDoc event = new ActionEvent JavaDoc(source, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers());
77         scrollAction.actionPerformed(event);
78     }
79
80     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
81         support.firePropertyChange(evt);
82     }
83 }
Popular Tags