summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dde66d7)
raw | patch | inline | side by side (parent: dde66d7)
author | ishmal <ishmal@users.sourceforge.net> | |
Tue, 1 Apr 2008 16:55:51 +0000 (16:55 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Tue, 1 Apr 2008 16:55:51 +0000 (16:55 +0000) |
diff --git a/src/bind/java/org/inkscape/cmn/Resource.java b/src/bind/java/org/inkscape/cmn/Resource.java
index a5a58a777aa2caeae47624171f6c25086f83b202..3ad139d8a63b4634dd7187754c38bb3aa318b468 100644 (file)
-
+/**
+ * This is a simple mechanism to bind Inkscape to Java, and thence
+ * to all of the nice things that can be layered upon that.
+ *
+ * Authors:
+ * Bob Jamison
+ *
+ * Copyright (C) 2007-2008 Bob Jamison
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.inkscape.cmn;
diff --git a/src/bind/java/org/inkscape/script/Editor.java b/src/bind/java/org/inkscape/script/Editor.java
index ba57465ca27e9cd033e94d08a880df0701a3758f..ac1c49aaf0f0b8346ade4ec3f6976733d6495de3 100644 (file)
+/**
+ * This is a simple mechanism to bind Inkscape to Java, and thence
+ * to all of the nice things that can be layered upon that.
+ *
+ * Authors:
+ * Bob Jamison
+ *
+ * Copyright (C) 2007-2008 Bob Jamison
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
package org.inkscape.script;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import java.awt.BorderLayout;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
/**
* A simple script editor for quick fixes.
*/
public class Editor extends JPanel
{
+ScriptConsole parent;
JTextPane textPane;
+//########################################################################
+//# MESSSAGES
+//########################################################################
+void err(String fmt, Object... arguments)
+{
+ parent.err("Editor err:" + fmt, arguments);
+}
+
+void msg(String fmt, Object... arguments)
+{
+ parent.msg("Editor:" + fmt, arguments);
+}
+
+void trace(String fmt, Object... arguments)
+{
+ parent.trace("Editor:" + fmt, arguments);
+}
/**
- *
+ * Returns the current text contained in this editor
*/
public String getText()
{
}
+String lastHash = null;
+
/**
- *
+ * Sets the text of this editor
*/
public void setText(String txt)
{
textPane.setText(txt);
+ lastHash = getHash(txt);
+ trace("hash:" + lastHash);
+}
+
+MessageDigest md = null;
+
+final String hex = "0123456789abcdef";
+
+String toHex(byte arr[])
+{
+ StringBuffer buf = new StringBuffer();
+ for (byte b : arr)
+ {
+ buf.append(hex.charAt((b>>4) & 15));
+ buf.append(hex.charAt((b ) & 15));
+ }
+ return buf.toString();
+}
+
+String getHash(String text)
+{
+ if (md == null)
+ {
+ try
+ {
+ md = MessageDigest.getInstance("MD5");
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ err("getHash: " + e);
+ return "";
+ }
+ }
+ byte hash[] = md.digest(text.getBytes());
+ return toHex(hash);
+}
+
+public boolean isDirty()
+{
+ String txt = getText();
+ String hash = getHash(txt);
+ if (lastHash != null && !lastHash.equals(hash))
+ return true;
+ return false;
}
/**
*
*/
-public Editor()
+public Editor(ScriptConsole par)
{
super();
+ parent = par;
setLayout(new BorderLayout());
textPane = new JTextPane();
add(textPane, BorderLayout.CENTER);
diff --git a/src/bind/java/org/inkscape/script/ScriptConsole.java b/src/bind/java/org/inkscape/script/ScriptConsole.java
index dc4b8dc34f7b0a1fcc15986d97ab73d08778ceea..6f95ddf50381f1e503723bea7d490636b8641e60 100644 (file)
-
+/**
+ * This is a simple mechanism to bind Inkscape to Java, and thence
+ * to all of the nice things that can be layered upon that.
+ *
+ * Authors:
+ * Bob Jamison
+ *
+ * Copyright (C) 2007-2008 Bob Jamison
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.inkscape.script;
import java.io.File;
import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
import java.util.List;
import java.util.HashMap;
//########################################################################
void err(String fmt, Object... arguments)
{
- terminal.errorf("ScriptConsole err:" + fmt, arguments);
+ terminal.errorf("ScriptConsole err:" + fmt + "\n", arguments);
}
void msg(String fmt, Object... arguments)
void trace(String fmt, Object... arguments)
{
- terminal.outputf("ScriptConsole:" + fmt, arguments);
+ terminal.outputf("ScriptConsole:" + fmt + "\n", arguments);
}
{
_chooser = new JFileChooser();
_chooser.setAcceptAllFileFilterUsed(false);
+ _chooser.setCurrentDirectory(new File("."));
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"Script Files", "js", "py", "r");
_chooser.setFileFilter(filter);
String engVersion = factory.getEngineVersion();
String langName = factory.getLanguageName();
String langVersion = factory.getLanguageVersion();
- trace("\tScript Engine: %s (%s)\n", engName, engVersion);
+ trace("\tScript Engine: %s (%s)", engName, engVersion);
List<String> engNames = factory.getNames();
for(String name: engNames)
{
- trace("\tEngine Alias: %s\n", name);
+ trace("\tEngine Alias: %s", name);
}
- trace("\tLanguage: %s (%s)\n", langName, langVersion);
+ trace("\tLanguage: %s (%s)", langName, langVersion);
ScriptEngineAction action = new ScriptEngineAction(factory);
JRadioButtonMenuItem item = new JRadioButtonMenuItem(action);
group.add(item);
return;
File f = chooser.getSelectedFile();
String fname = f.getName();
- alert("You selected : " + fname);
+ try
+ {
+ FileReader in = new FileReader(fname);
+ StringBuffer buf = new StringBuffer();
+ while (true)
+ {
+ int ch = in.read();
+ if (ch < 0)
+ break;
+ buf.append((char)ch);
+ }
+ in.close();
+ editor.setText(buf.toString());
+ }
+ catch (IOException e)
+ {
+ err("save file:" + e);
+ }
}
public OpenAction()
return;
File f = chooser.getSelectedFile();
String fname = f.getName();
- alert("You selected : " + fname);
+ try
+ {
+ FileWriter out = new FileWriter(fname);
+ out.write(editor.getText());
+ out.close();
+ }
+ catch (IOException e)
+ {
+ err("save file:" + e);
+ }
}
public SaveAction()
return;
File f = chooser.getSelectedFile();
String fname = f.getName();
- alert("You selected : " + fname);
+ if (f.exists())
+ {
+ ret = JOptionPane.showConfirmDialog(ScriptConsole.this,
+ "File '" + fname + "' already exists. Overwrite?");
+ if (ret != JOptionPane.YES_OPTION)
+ return;
+ }
+ try
+ {
+ FileWriter out = new FileWriter(fname);
+ out.write(editor.getText());
+ out.close();
+ }
+ catch (IOException e)
+ {
+ err("saveAs file:" + e);
+ }
}
public SaveAsAction()
terminal);
terminal.output("\nscript> ");
- editor = new Editor();
+ editor = new Editor(this);
tabPane.addTab("Script",
Resource.getIcon("accessories-text-editor.png"),
editor);
diff --git a/src/bind/java/org/inkscape/script/Terminal.java b/src/bind/java/org/inkscape/script/Terminal.java
index 05438248282b023790965825fb2e4a37e6d4a934..22d2cb2511990064cb0cf0a4be5331e70672d2fb 100644 (file)
+/**
+ * This is a simple mechanism to bind Inkscape to Java, and thence
+ * to all of the nice things that can be layered upon that.
+ *
+ * Authors:
+ * Bob Jamison
+ *
+ * Copyright (C) 2007-2008 Bob Jamison
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
package org.inkscape.script;
import java.awt.BorderLayout;