alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

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 Forte for Java, Community Edition. The Initial
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
 * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.mdrxml.looks;

import java.lang.ref.WeakReference;
import java.io.IOException;
import java.awt.datatransfer.Transferable;
import org.openide.actions.PropertiesAction;
import org.openide.nodes.*;
import org.openide.util.NbBundle;
import org.openide.util.actions.SystemAction;
import org.netbeans.api.looks.*;
import org.netbeans.spi.looks.*;
import org.netbeans.modules.mdrxml.looks.actions.DeleteAction;
import org.netbeans.modules.mdrxml.looks.actions.GenerateTextAction;
/**
 *
 * @author  Tomas Zezula
 */
public class NodeLook extends DefaultLook {
    
    private static class NameProperty extends PropertySupport.ReadWrite {
        
        private WeakReference ref;
        
        public NameProperty(Look.NodeSubstitute substitute) {
            super(NbBundle.getMessage(NodeLook.class,"TXT_Name"),String.class,NbBundle.getMessage(NodeLook.class,"TXT_Name"),NbBundle.getMessage(NodeLook.class,"TIP_Name"));
            this.ref = new WeakReference (substitute);
        }
        
        public Object getValue() {
	    Look.NodeSubstitute val = (Look.NodeSubstitute) this.ref.get ();
            if (val != null && (val.getRepresentedObject() instanceof xmlmodel.Node)) {
                return ((xmlmodel.Node)val.getRepresentedObject()).getName();
            }
            else {
                return null;
            }
        }
        
        public void setValue(Object value) {
	    Look.NodeSubstitute val = (Look.NodeSubstitute) this.ref.get ();
            if (value instanceof String && val != null && val.getRepresentedObject() instanceof xmlmodel.Node) {
                ((xmlmodel.Node)val.getRepresentedObject()).setName((String)value);
                val.fireNameChange(null,(String)value);
                val.fireDisplayNameChange(null,(String)value);
            }
        }
        
    }
    
    /** Creates a new instance of NodeLook */
    public NodeLook(String name) {
        super(name);
    }
    
    public String getName(Look.NodeSubstitute substitute) {
        try {
            xmlmodel.Node en = (xmlmodel.Node) substitute.getRepresentedObject();
            return en.getName();
        }catch (javax.jmi.reflect.InvalidObjectException ioe) {
            return new String ();
        }
    }
    
    public String getDisplayName(Look.NodeSubstitute substitute) {
        return this.getName(substitute);
    }
    
    public Node.PropertySet[] getPropertySets(Look.NodeSubstitute substitute) {
        Sheet.Set set = new Sheet.Set();
        String name = NbBundle.getMessage(NodeLook.class,"TXT_Properties");
        set.setName(name);
        set.setDisplayName(name);
        set.put(new NameProperty(substitute));
        return new Node.PropertySet[] {set};
    }
    
    public javax.swing.Action[] getActions(Look.NodeSubstitute substitute) {
        return new javax.swing.Action[] {
            SystemAction.get(DeleteAction.class),
            SystemAction.get(PropertiesAction.class),
            SystemAction.get(GenerateTextAction.class)
        };
    }
    
    public boolean canCopy (Look.NodeSubstitute substitute) {
      return true;  
    }
    
    public Transferable drag (Look.NodeSubstitute substitute) throws IOException {
        return this.clipboardCopy (substitute);
    }
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.