1 19 package org.netbeans.modules.css.actions; 20 21 import java.awt.datatransfer.StringSelection ; 22 import java.net.*; 23 24 import org.openide.*; 25 import org.openide.awt.StatusDisplayer; 26 import org.openide.nodes.Node; 27 import org.openide.util.*; 28 import org.openide.util.datatransfer.ExClipboard; 29 import org.openide.util.actions.*; 30 import org.openide.filesystems.*; 31 32 import org.netbeans.modules.css.*; 33 34 40 public abstract class CopyStyleAction extends CookieAction { 41 42 protected static final String comment = Util.THIS.getString("Style-Comment") + "\n"; 44 45 private static final long serialVersionUID = -6638807099960633334L; 46 47 50 public int mode() { 51 return MODE_EXACTLY_ONE; 52 } 53 54 57 public Class [] cookieClasses() { 58 return new Class [] {CSSObject.class}; 59 } 60 61 63 protected void performAction(final Node[] nodes) { 64 if (nodes.length != 1) return; 65 if (nodes[0] == null) return; 66 67 CSSObject csso = (CSSObject) nodes[0].getCookie(CSSObject.class); 68 69 if (csso != null) { 70 String pi = createText(csso); 71 StringSelection ss = new StringSelection (pi); 72 ExClipboard clipboard = (ExClipboard) Lookup.getDefault().lookup(ExClipboard.class); 73 clipboard.setContents(ss, null); 74 StatusDisplayer.getDefault().setStatusText(Util.THIS.getString("MSG_Style_tag_in_clipboard")); } 76 77 } 78 79 82 protected abstract String createText(CSSObject node); 83 84 86 public HelpCtx getHelpCtx() { 87 return new HelpCtx(getClass()); 88 } 89 90 91 protected String getHref(FileObject fo) { 92 URL u = URLMapper.findURL(fo, URLMapper.NETWORK); 93 if (u != null) { 94 return u.toExternalForm(); 95 } else { 96 return fo.getPath(); 97 } 98 } 99 100 101 public final static class XML extends CopyStyleAction { 102 103 104 private static final long serialVersionUID = -6638807099960633335L; 105 106 protected String createText(CSSObject csso) { 107 return comment + "<?xml-stylesheet type=\"text/css\" HREF=\"" + this.getHref(csso.getPrimaryFile()) + "\" ?>"; } 109 110 public String getName() { 111 return Util.THIS.getString("Copy-XML-Style"); } 113 } 114 115 116 public final static class HTML extends CopyStyleAction { 117 118 119 private static final long serialVersionUID = -6638807099960633336L; 120 121 protected String createText(CSSObject csso) { 122 return comment + "<link rel=\"StyleSheet\" type=\"text/css\" HREF=\"" + this.getHref(csso.getPrimaryFile()) + "\" media=\"screen\" >"; } 124 125 public String getName() { 126 return Util.THIS.getString("Copy-HTML-Style"); } 128 } 129 } 130 | Popular Tags |