~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to graph/integration/src/org/netbeans/modules/visual/examples/shapes/palette/Utils.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
package org.netbeans.modules.visual.examples.shapes.palette;
 
42
 
 
43
import java.awt.datatransfer.DataFlavor;
 
44
import java.awt.datatransfer.UnsupportedFlavorException;
 
45
import java.io.IOException;
 
46
import javax.swing.Action;
 
47
import org.netbeans.modules.visual.examples.shapes.dataobject.MyItemData;
 
48
import org.netbeans.spi.palette.DragAndDropHandler;
 
49
import org.netbeans.spi.palette.PaletteActions;
 
50
import org.netbeans.spi.palette.PaletteController;
 
51
import org.netbeans.spi.palette.PaletteFactory;
 
52
import org.openide.util.Lookup;
 
53
import org.openide.util.datatransfer.ExTransferable;
 
54
 
 
55
/**
 
56
 *
 
57
 * @author Geert Wielenga
 
58
 */
 
59
public class Utils {
 
60
    
 
61
    public static final DataFlavor MY_DATA_FLAVOR = new DataFlavor( MyItemData.class, "My Item Data" );
 
62
    private static PaletteController thePalette;
 
63
    public static String MODE;
 
64
    
 
65
    /** Creates a new instance of Utils */
 
66
    private Utils() {
 
67
    }
 
68
    
 
69
    public static PaletteController getPalette() {
 
70
        //create the palette
 
71
        if( null == thePalette ) {
 
72
            try {
 
73
                //DND start
 
74
                //use custom DragAndDropHandler when creating the palette so that our custom
 
75
                //dataflavor gets added when an item is being dragged from the palette
 
76
                thePalette = PaletteFactory.createPalette( "NotePalette", new MyActions(), null, new MyDnDHandler() );
 
77
                //DND end
 
78
            } catch (IOException ex) {
 
79
                ex.printStackTrace();
 
80
            }
 
81
        }
 
82
        return thePalette;
 
83
    }
 
84
    
 
85
    private static class MyActions extends PaletteActions {
 
86
        public Action[] getImportActions() {
 
87
            return null;
 
88
        }
 
89
        
 
90
        public Action[] getCustomPaletteActions() {
 
91
            return null;
 
92
        }
 
93
        
 
94
        public Action[] getCustomCategoryActions(Lookup lookup) {
 
95
            return null;
 
96
        }
 
97
        
 
98
        public Action[] getCustomItemActions(Lookup lookup) {
 
99
            return null;
 
100
        }
 
101
        
 
102
        public Action getPreferredAction(Lookup lookup) {
 
103
            return null;
 
104
        }
 
105
        
 
106
    }
 
107
    
 
108
    //DND start
 
109
    private static class MyDnDHandler extends DragAndDropHandler {
 
110
        public void customize(ExTransferable exTransferable, Lookup lookup) {
 
111
            //check if MyItemData is availble in the lookup
 
112
            final MyItemData data = (MyItemData)lookup.lookup( MyItemData.class );
 
113
            if( null != data ) {
 
114
                //add our flavor to the list of dragged flavors because our dropPanel does not support anything else
 
115
                exTransferable.put( new ExTransferable.Single( MY_DATA_FLAVOR ) {
 
116
                    protected Object getData() throws IOException, UnsupportedFlavorException {
 
117
                        return data;
 
118
                    }
 
119
                });
 
120
            }
 
121
            
 
122
        }
 
123
    }
 
124
    //DND end
 
125
}