KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > grapheditor > actions > HoverActionProvider


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.actions;
20
21 import org.netbeans.api.visual.action.ActionFactory;
22 import org.netbeans.api.visual.action.TwoStateHoverProvider;
23 import org.netbeans.api.visual.action.WidgetAction;
24 import org.netbeans.api.visual.model.ObjectState;
25 import org.netbeans.api.visual.widget.Scene;
26 import org.netbeans.api.visual.widget.Widget;
27
28 public class HoverActionProvider {
29
30     private WidgetAction mHoverAction;
31     private static HoverActionProvider mHoverActionProvider;
32     
33     private HoverActionProvider(Scene scene) {
34         if (mHoverAction == null) {
35             mHoverAction = ActionFactory.createHoverAction(new MyHoverProvider(scene));
36             scene.getActions().addAction(mHoverAction);
37         }
38     }
39
40     public static HoverActionProvider getDefault(Scene scene) {
41         if (mHoverActionProvider != null) return mHoverActionProvider;
42         mHoverActionProvider = new HoverActionProvider(scene);
43         return mHoverActionProvider;
44     }
45     
46     public WidgetAction getHoverAction() {
47         assert mHoverActionProvider != null : "Call getDefault before calling getHoverAction";
48         return mHoverAction;
49     }
50     private static class MyHoverProvider implements TwoStateHoverProvider {
51
52         private Scene scene;
53
54         public MyHoverProvider (Scene scene) {
55             this.scene = scene;
56         }
57
58         public void unsetHovering (Widget widget) {
59             if (widget != null) {
60                 widget.setBackground (scene.getLookFeel().getBackground (ObjectState.createNormal ()));
61                 widget.setForeground (scene.getLookFeel ().getForeground (ObjectState.createNormal ()));
62             }
63         }
64
65         public void setHovering (Widget widget) {
66             if (widget != null) {
67                 ObjectState state = ObjectState.createNormal ().deriveObjectHovered (true);
68                 widget.setBackground (scene.getLookFeel ().getBackground (state));
69                 widget.setForeground (scene.getLookFeel ().getForeground (state));
70             }
71         }
72     }
73 }
74
Popular Tags