Issue 16574 - Add Rhino & Beanshell jarfiles to external project
Summary: Add Rhino & Beanshell jarfiles to external project
Status: CLOSED FIXED
Alias: None
Product: General
Classification: Code
Component: scripting (show other issues)
Version: OOo 1.1 Beta2
Hardware: All All
: P2 Trivial (vote)
Target Milestone: OOo 2.0
Assignee: duncan.foster
QA Contact: issues@framework
URL:
Keywords:
Depends on:
Blocks: 15986 23008
  Show dependency tree
 
Reported: 2003-07-08 15:08 UTC by duncan.foster
Modified: 2005-01-06 11:41 UTC (History)
1 user (show)

See Also:
Issue Type: FEATURE
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description duncan.foster 2003-07-08 15:08:26 UTC
Need to add Rhino jarfile for JavaScript runtime & debug support.
jarfile has been manually added to scriptingf1 solver as a temporary workaround
to allow work on i15986 to continue.
Comment 1 duncan.foster 2003-07-08 15:09:27 UTC
Retarget to OOo2.0.
Comment 2 duncan.foster 2003-09-23 13:57:05 UTC
In progress awaiting Sun Legal approval.
Comment 3 duncan.foster 2003-09-23 14:05:21 UTC
Legal have approved this. Have provided MH with details. Reassigning.
Comment 4 duncan.foster 2003-11-03 14:45:40 UTC
Received commit access from MH.

I will also use this issue to add the BeanShell jar file, and update
the Netbeans openide.jar.
Comment 5 duncan.foster 2003-11-03 16:10:47 UTC
Renaming bsh-1.2b7.jar -> bsh.jar and adding the key
"BeanShellVersion" to the manifest. Added in CVS module "external".

Patching of Rhino's js.jar moved from CVS module scripting -> external 
Comment 6 noel.power 2003-11-10 15:31:17 UTC
Completed p.p dfoster
Comment 7 noel.power 2003-11-10 15:31:56 UTC
change state.
Comment 8 joerg.skottke 2003-11-13 10:53:15 UTC
fixed/verified
Comment 9 tomaisoc 2003-11-27 14:02:40 UTC
For the record, this is the patch that was applied to the Main.java
source file of the Rhino debugger to allow us to start the debugger
with a file loaded, and to disable certain menu items that we did
not want to appear due to the workflow of script editing.

% diff -ur mozilla mozilla.changed
diff -ur
mozilla/js/rhino/toolsrc/org/mozilla/javascript/tools/debugger/Main.java
mozilla.changed/js/rhino/toolsrc/org/mozilla/javascript/tools/debugger/Main.java
---
mozilla/js/rhino/toolsrc/org/mozilla/javascript/tools/debugger/Main.java
  2003-01-26 18:33:30.000000000 +0000
+++
mozilla.changed/js/rhino/toolsrc/org/mozilla/javascript/tools/debugger/Main.java
   2003-11-27 13:53:05.000000000 +0000
@@ -469,15 +469,21 @@
         case KeyEvent.VK_BACK_SPACE:
         case KeyEvent.VK_ENTER:
         case KeyEvent.VK_DELETE:
-            e.consume();
+            if (w.isEditable() == false) {
+                e.consume();
+            }
             break;
         }
     }
     public void keyTyped(KeyEvent e) {
-        e.consume();
+        if (w.isEditable() == false) {
+            e.consume();
+        }
     }
     public void keyReleased(KeyEvent e) {
-        e.consume();
+        if (w.isEditable() == false) {
+            e.consume();
+        }
     }
 }
  
@@ -818,6 +824,7 @@
         if (dummy.length() < 2) {
             dummy = "99";
         }
+
         int maxWidth = metrics.stringWidth(dummy);
         int startLine = clip.y / h;
         int endLine = (clip.y + clip.height) / h + 1;
@@ -881,11 +888,11 @@
     public void actionPerformed(ActionEvent e) {
         String cmd = e.getActionCommand();
         if (cmd.equals("Cut")) {
-            // textArea.cut();
+            textArea.cut();
         } else if (cmd.equals("Copy")) {
             textArea.copy();
         } else if (cmd.equals("Paste")) {
-            // textArea.paste();
+            textArea.paste();
         }
     }
  
@@ -905,11 +912,31 @@
         } else {
             String url = getUrl();
             if (url != null) {
-                new Thread(new LoadFile(db,scope,url)).start();
+                new Thread(new LoadFile(db,scope, url, new
StringReader(textArea.getText()))).start();
             }
         }
     }
  
+    void save() {
+        if (getUrl() != null) {
+            try {
+                File f = new File(getUrl());
+                FileOutputStream fos = new FileOutputStream(f);
+                String s = textArea.getText();
+                fos.write(s.getBytes(), 0, s.length());
+            }
+            catch (IOException ioe) {
+                JOptionPane.showMessageDialog(this,
+                    "Error saving file: " + ioe.getMessage(),
+                    "Error", JOptionPane.ERROR_MESSAGE);
+            }
+        }
+    }
+
+    public boolean isEditable() {
+        return db.isSourceEditingEnabled();
+    }
+
    public int getPosition(int line) {
         int result = -1;
         try {
@@ -1601,7 +1628,7 @@
         if (line != -1) {
             db.currentWindow = w;
         }
-        db.menubar.addFile(url);
+        // db.menubar.addFile(url);
         w.setVisible(true);
         if (activate) {
             try {
@@ -1735,8 +1762,10 @@
     Menubar(Main db) {
         super();
         this.db = db;
-        String[] fileItems  = {"Open...", "Run...", "", "Exit"};
-        String[] fileCmds  = {"Open", "Load", "", "Exit"};
+        // String[] fileItems  = {"Open...", "Run...", "", "Exit"};
+        // String[] fileCmds  = {"Open", "Load", "", "Exit"};
+        String[] fileItems  = {"Run", "Save", "", "Exit"};
+        String[] fileCmds  = {"Run", "Save", "", "Exit"};
         char[] fileShortCuts = {'0', 'N', '\0', 'X'};
         int[] fileAccelerators = {KeyEvent.VK_O,
                                   KeyEvent.VK_N,
@@ -1778,6 +1807,9 @@
                     KeyStroke k =
KeyStroke.getKeyStroke(fileAccelerators[i], Event.CTRL_MASK);
                     item.setAccelerator(k);
                 }
+                if (fileItems[i].equals("Save")) {
+                    saveItem = item;
+                }
             }
         }
         for (int i = 0; i < editItems.length; ++i) {
@@ -1827,15 +1859,15 @@
         add(editMenu);
         //add(plafMenu);
         add(debugMenu);
-        JMenuItem item;
-        windowMenu.add(item = new JMenuItem("Cascade", 'A'));
-        item.addActionListener(this);
-        windowMenu.add(item = new JMenuItem("Tile", 'T'));
-        item.addActionListener(this);
-        windowMenu.addSeparator();
-        windowMenu.add(item = new JMenuItem("Console", 'C'));
-        item.addActionListener(this);
-        add(windowMenu);
+        // JMenuItem item;
+        // windowMenu.add(item = new JMenuItem("Cascade", 'A'));
+        // item.addActionListener(this);
+        // windowMenu.add(item = new JMenuItem("Tile", 'T'));
+        // item.addActionListener(this);
+        // windowMenu.addSeparator();
+        // windowMenu.add(item = new JMenuItem("Console", 'C'));
+        // item.addActionListener(this);
+        // add(windowMenu);
  
     }
  
@@ -1908,11 +1940,16 @@
         item.addActionListener(this);
     }
  
+    public void setSaveEnabled(boolean state) {
+        saveItem.setEnabled(state);
+    }
+
     Main db;
     JMenu windowMenu;
     JCheckBoxMenuItem breakOnExceptions;
     JCheckBoxMenuItem breakOnEnter;
     JCheckBoxMenuItem breakOnReturn;
+    JMenuItem saveItem;
 };
  
 class EnterInterrupt implements Runnable {
@@ -1925,6 +1962,13 @@
     public void run() {
         JMenu menu = db.getJMenuBar().getMenu(0);
         //menu.getItem(0).setEnabled(false); // File->Load
+
+        // disable Edit menu Cut, Copy, Paste items
+        menu = db.getJMenuBar().getMenu(1);
+        for (int i = 0; i < 3; i++) {
+            menu.getItem(i).setEnabled(false);
+        }
+
         menu = db.getJMenuBar().getMenu(2);
         menu.getItem(0).setEnabled(false); // Debug->Break
         int count = menu.getItemCount();
@@ -1937,6 +1981,10 @@
             b = true;
         }
         db.toolBar.setEnabled(true);
+
+        // set flag to disable source editing
+        db.setSourceEditingEnabled(false);
+
         // raise the debugger window
         db.toFront();
     }
@@ -1950,6 +1998,13 @@
     public void run() {
         JMenu menu = db.getJMenuBar().getMenu(0);
         menu.getItem(0).setEnabled(true); // File->Load
+
+        // enable Edit menu items
+        menu = db.getJMenuBar().getMenu(1);
+        for (int i = 0; i < 3; i++) {
+            menu.getItem(i).setEnabled(true);
+        }
+
         menu = db.getJMenuBar().getMenu(2);
         menu.getItem(0).setEnabled(true); // Debug->Break
         int count = menu.getItemCount() - 1;
@@ -1963,6 +2018,9 @@
             db.toolBar.getComponent(ci).setEnabled(b);
             b = false;
         }
+        // set flag to enable source editing
+        db.setSourceEditingEnabled(true);
+
         //db.console.consoleTextArea.requestFocus();
     }
 };
@@ -1971,18 +2029,25 @@
     Scriptable scope;
     String fileName;
     Main db;
+    Reader reader = null;
+
     OpenFile(Main db, Scriptable scope, String fileName) {
         this.scope = scope;
         this.fileName = fileName;
         this.db = db;
     }
+    OpenFile(Main db, Scriptable scope, String fileName, Reader reader) {
+        this(db, scope, fileName);
+        this.reader = reader;
+    }
     public void run() {
         Context cx = Context.enter();
         ContextData contextData = ContextData.get(cx);
         contextData.breakNextLine = true;
         try {
-            cx.compileReader(scope, new FileReader(fileName),
-                             fileName, 1, null);
+            cx.compileReader(scope,
+                reader == null ? new FileReader(fileName) : reader,
+                fileName, 1, null);
         } catch (Exception exc) {
             String msg = exc.getMessage();
             if (exc instanceof EcmaError) {
@@ -2003,18 +2068,27 @@
     Scriptable scope;
     String fileName;
     Main db;
+    Reader reader = null;
+
     LoadFile(Main db, Scriptable scope, String fileName) {
         this.scope = scope;
         this.fileName = fileName;
         this.db = db;
     }
+
+    LoadFile(Main db, Scriptable scope, String fileName, Reader reader) {
+        this(db, scope, fileName);
+        this.reader = reader;
+    }
+
     public void run() {
         Context cx = Context.enter();
         ContextData contextData = ContextData.get(cx);
         contextData.breakNextLine = true;
         try {
-            cx.evaluateReader(scope, new FileReader(fileName),
-                              fileName, 1, null);
+            cx.evaluateReader(scope,
+                reader == null ? new FileReader(fileName) : reader,
+                fileName, 1, null);
         } catch (Exception exc) {
             String msg = exc.getMessage();
             if (exc instanceof EcmaError) {
@@ -2400,13 +2474,13 @@
         super.setVisible(b);
         if (b) {
             // this needs to be done after the window is visible
-            console.consoleTextArea.requestFocus();
+            // console.consoleTextArea.requestFocus();
             context.split.setDividerLocation(0.5);
             try {
-                console.setMaximum(true);
-                console.setSelected(true);
-                console.show();
-                console.consoleTextArea.requestFocus();
+                // console.setMaximum(true);
+                // console.setSelected(true);
+                // console.show();
+                // console.consoleTextArea.requestFocus();
             } catch (Exception exc) {
             }
         }
@@ -2474,7 +2548,7 @@
  
     String getNormilizedUrl(DebuggableScript fnOrScript) {
         String url = fnOrScript.getSourceName();
-        if (url == null) { url = "<stdin>"; }
+        if (url == null) { url = "document"; }
         else {
             // Not to produce window for eval from different lines,
             // strip line numbers, i.e. replace all #[0-9]+\(eval\)
by (eval)
@@ -2586,6 +2660,8 @@
                 si = new SourceInfo(sourceUrl, source);
                 sourceNames.put(sourceUrl, si);
             }
+            else if (!source.equals(si.getSource()))
+                si.setSource(source);
         }
         return si;
     }
@@ -2760,7 +2836,7 @@
         desk = new JDesktopPane();
         desk.setPreferredSize(new Dimension(600, 300));
         desk.setMinimumSize(new Dimension(150, 50));
-        desk.add(console = new JSInternalConsole("JavaScript Console"));
+        // desk.add(console = new JSInternalConsole("JavaScript
Console"));
         context = new ContextWindow(this);
         context.setPreferredSize(new Dimension(600, 120));
         context.setMinimumSize(new Dimension(50, 50));
@@ -2869,7 +2945,7 @@
             FrameHelper frame = contextData.getFrame(frameIndex);
             String sourceName = frame.getUrl();
             if (sourceName == null || sourceName.equals("<stdin>")) {
-                console.show();
+                // console.show();
                 helper.reset();
                 return;
             }
@@ -2893,6 +2969,19 @@
     int dispatcherIsWaiting = 0;
     Context currentContext = null;
  
+    // Flag used to establish whether source code editing is allowed in
+    // the debugger, switched on and off depending on whether a debug
session
+    // is active
+    boolean sourceEditingEnabled = true;
+
+    public boolean isSourceEditingEnabled() {
+        return sourceEditingEnabled;
+    }
+
+    void setSourceEditingEnabled(boolean b) {
+        sourceEditingEnabled = b;
+    }
+
     Context getCurrentContext() {
         return currentContext;
     }
@@ -3026,14 +3115,14 @@
                     swingInvoke(CreateFileWindow.action(this, si, line));
                 }
             } else {
-                if (console.isVisible()) {
+                /* if (console.isVisible()) {
                     final JSInternalConsole finalConsole = console;
                     swingInvoke(new Runnable() {
                             public void run() {
                                 finalConsole.show();
                             }
                         });
-                }
+                } */
             }
             swingInvoke(new EnterInterrupt(this, cx));
             swingInvoke(new UpdateContext(this, cx));
@@ -3221,6 +3310,14 @@
                                             fileName)).start();
                 }
             }
+        } else if (cmd.equals("Run")) {
+            FileWindow w = (FileWindow)getSelectedFrame();
+            if (w != null)
+                w.load();
+        } else if (cmd.equals("Save")) {
+            FileWindow w = (FileWindow)getSelectedFrame();
+            if (w != null)
+                w.save();
         } else if (cmd.equals("More Windows...")) {
             MoreWindows dlg = new MoreWindows(this, fileWindows,
                                               "Window", "Files");
@@ -3600,6 +3697,35 @@
         return console.getErr();
     }
  
+    public void openFile(String fileName) {
+        Scriptable scope = getScope();
+        if (scope == null) {
+            MessageDialogWrapper.showMessageDialog(this,
+                "Can't compile scripts: no scope available",
+                "Open", JOptionPane.ERROR_MESSAGE);
+        } else {
+            if (fileName != null) {
+                new Thread(new OpenFile(this, scope, fileName)).start();
+            }
+        }
+        split1.setDividerLocation(1.0);
+    }
+
+    public void openStream(InputStream in) {
+        Scriptable scope = getScope();
+        if (scope == null) {
+            MessageDialogWrapper.showMessageDialog(this,
+                "Can't compile scripts: no scope available",
+                "Open", JOptionPane.ERROR_MESSAGE);
+        } else {
+            if (in != null) {
+                new Thread(new OpenFile(this, scope, null, new
InputStreamReader(in))).start();
+            }
+        }
+        split1.setDividerLocation(1.0);
+        menubar.setSaveEnabled(false);
+    }
+
     public static void main(String[] args) {
         try {
             mainThread = Thread.currentThread();
Comment 10 duncan.foster 2003-11-28 15:10:52 UTC
This issue should have been marked as a Feature rather than a Task.
Updating summary to mention BeanShell.
Comment 11 tomaisoc 2003-11-28 15:13:22 UTC
The Rhino and BeanShell jar files have now been committed to the
OpenOffice.org external project in external/rhino and
external/beanshell.

The modified Main.java file has been added to the rhino directory
and is rebuilt and repackaged into the Rhino jar file before the
jar is delivered.
Comment 12 duncan.foster 2005-01-06 11:41:04 UTC
closing.