2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
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]"
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.
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.
41
package org.netbeans.modules.visual.examples.shapes.palette;
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;
57
* @author Geert Wielenga
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;
65
/** Creates a new instance of Utils */
69
public static PaletteController getPalette() {
71
if( null == thePalette ) {
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() );
78
} catch (IOException ex) {
85
private static class MyActions extends PaletteActions {
86
public Action[] getImportActions() {
90
public Action[] getCustomPaletteActions() {
94
public Action[] getCustomCategoryActions(Lookup lookup) {
98
public Action[] getCustomItemActions(Lookup lookup) {
102
public Action getPreferredAction(Lookup lookup) {
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 );
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 {