/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.sack.scratchpad;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import javax.swing.JEditorPane;
import org.openide.cookies.EditorCookie;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CookieAction;
public final class copy_scrap extends CookieAction {
protected void performAction(Node[] activatedNodes) {
EditorCookie editorCookie = activatedNodes[0].getLookup().lookup(EditorCookie.class);
// TODO use editorCookie
JEditorPane[] panes=editorCookie.getOpenedPanes();
System.out.println("sel"+panes[0].getSelectedText());
copy_new(panes[0].getSelectedText());
}
void copy_new(String text){
try {
System.out.println("text"+text);
int count = scratch_padTopComponent.count;
int current = scratch_padTopComponent.current;
Properties prop = scratch_padTopComponent.prop;
String[] str = (prop.getProperty("" + count)).split(":?");
prop.setProperty(count + "", str[0] + ":?" + (count+1) + ":?" + str[2]);
count++;
scratch_padTopComponent.count++;
prop.setProperty(count + "",(count-1) + ":?" + count + ":?"+text);
prop.setProperty("count", "" + count);
prop.store(new FileOutputStream("scratch_pad.properties"), null);
scratch_padTopComponent.current=count;
scratch_padTopComponent.display(count);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
protected int mode() {
return CookieAction.MODE_ALL;
}
public String getName() {
return NbBundle.getMessage(copy_scrap.class, "CTL_copy_scrap");
}
protected Class[] cookieClasses() {
return new Class[]{EditorCookie.class};
}
protected @Override
String iconResource() {
return "org/sack/sackscratchpad/icon.gif";
}
public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}
protected @Override
boolean asynchronous() {
return false;
}
}