|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.examples.modules.minicomposer; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.IOException; import org.netbeans.api.registry.Context; import org.netbeans.api.registry.ObjectRef; import org.netbeans.spi.looks.DefaultLook; import org.netbeans.spi.looks.Look; import org.openide.execution.NbProcessDescriptor; import org.openide.nodes.Node; import org.openide.nodes.PropertySupport; import org.openide.nodes.Sheet; import org.openide.util.HelpCtx; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.datatransfer.ExTransferable; /** * An appearance for an {@link ExternalPlayer}. * @author Jesse Glick */ public class ExternalPlayerLook extends DefaultLook { public ExternalPlayerLook() { super("ExternalPlayerLook"); } public String getDisplayName() { return NbBundle.getMessage(ExternalPlayerLook.class, "LBL_ExternalPlayer"); } public String getName(Object o, Lookup l) { // XXX could e.g. check for it in Context.default and return path... return getDisplayName(o, l); } public String getDisplayName(Object o, Lookup l) { ExternalPlayer p = (ExternalPlayer) ((ObjectRef) o).getObject(); String lab = p.getLabel(); if (lab != null) { return lab; } else { NbProcessDescriptor pc = p.getPlayerCommand(); return pc.getProcessName() + " " + pc.getArguments(); } } public String getShortDescription(Object o, Lookup l) { return NbBundle.getMessage(ExternalPlayerLook.class, "HINT_ExternalPlayer"); } protected String iconBase(Object o, Lookup l) { return "org/netbeans/examples/modules/minicomposer/ExternalPlayerIcon"; } public HelpCtx getHelpCtx(Object o, Lookup l) { return new HelpCtx("org.netbeans.examples.modules.minicomposer.playing"); } public boolean isLeaf(Object o, Lookup l) { // XXX this should be the default return true; } public Node.PropertySet[] getPropertySets(Object o, Lookup l) { Sheet.Set ss = Sheet.createPropertiesSet(); ss.put(new PlayerCommandProperty((ObjectRef)o)); return new Node.PropertySet[] {ss}; } public boolean canCopy(Object o, Lookup l) { return true; } public Transferable clipboardCopy(final Object o, Lookup l) { String mime = DataFlavor.javaJVMLocalObjectMimeType + ";class=" + ObjectRef.class.getName(); try { return new ExTransferable.Single(new DataFlavor(mime)) { protected Object getData() { return o; } }; } catch (ClassNotFoundException e) { assert false : e; return null; } } public boolean canDestroy(Object o, Lookup l) { ExternalPlayer p = (ExternalPlayer) ((ObjectRef) o).getObject(); return p != null && p.getLabel() == null; } public void destroy(Object o, Lookup l) throws IOException { Context ctx = ((ObjectRef) o).getContext(); ctx.putObject(((ObjectRef) o).getBindingName(), null); } private final class PlayerCommandProperty extends PropertySupport.ReadWrite { private final ObjectRef pRef; public PlayerCommandProperty(ObjectRef pRef) { super("playerCommand", NbProcessDescriptor.class, // XXX I18N "Player Command", "What command to use to play the score"); this.pRef = pRef; } public Object getValue() { ExternalPlayer p = (ExternalPlayer) pRef.getObject(); return p.getPlayerCommand(); } public void setValue(Object val) { ExternalPlayer p = (ExternalPlayer) pRef.getObject(); p.setPlayerCommand((NbProcessDescriptor) val); Context ctx = pRef.getContext(); ctx.putObject(pRef.getBindingName(), pRef.getObject()); fireChange(pRef, Look.GET_NAME | Look.GET_DISPLAY_NAME); } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.