Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
   *
   * This Source Code Form is subject to the terms of the Mozilla Public
   * License, v. 2.0. If a copy of the MPL was not distributed with this
   * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  
  package org.mozilla.javascript.tools.debugger;
  
 
 
Rhino script debugger main class. This class links together a debugger object (Dim) and a debugger GUI object (SwingGui).
 
 public class Main {

    
The debugger.
 
     private Dim dim;

    
The debugger frame.
 
     private SwingGui debugGui;

    
Creates a new Main.
 
     public Main(String title) {
          = new Dim();
          = new SwingGui(title);
     }

    
Returns the debugger window javax.swing.JFrame.
 
     public JFrame getDebugFrame() {
         return ;
     }

    
Breaks execution of the script.
 
     public void doBreak() {
         .setBreak();
     }

    
Sets whether execution should break when a script exception is thrown.
 
     public void setBreakOnExceptions(boolean value) {
         .setBreakOnExceptions(value);
     }

    
Sets whether execution should break when a function is entered.
 
     public void setBreakOnEnter(boolean value) {
         .setBreakOnEnter(value);
         .getMenubar().getBreakOnEnter().setSelected(value);
     }

    
Sets whether execution should break when a function is left.
 
     public void setBreakOnReturn(boolean value) {
         .setBreakOnReturn(value);
         .getMenubar().getBreakOnReturn().setSelected(value);
     }

    
Removes all breakpoints.
 
     public void clearAllBreakpoints() {
         .clearAllBreakpoints();
     }

    
Resumes execution of the script.
 
     public void go() {
         .go();
     }

    
Sets the scope to be used for script evaluation.
 
     public void setScope(Scriptable scope) {
         setScopeProvider(IProxy.newScopeProvider(scope));
     }

    
Sets the ScopeProvider that provides a scope to be used for script evaluation.
    public void setScopeProvider(ScopeProvider p) {
        .setScopeProvider(p);
    }

    
Sets the SourceProvider that provides the source to be displayed for script evaluation.
    public void setSourceProvider(final SourceProvider sourceProvider) {
        .setSourceProvider(sourceProvider);
    }

    
Assign a Runnable object that will be invoked when the user selects "Exit..." or closes the Debugger main window.
    public void setExitAction(Runnable r) {
        .setExitAction(r);
    }

    
Returns an java.io.InputStream for stdin from the debugger's internal Console window.
    public InputStream getIn() {
        return .getConsole().getIn();
    }

    
Returns a java.io.PrintStream for stdout to the debugger's internal Console window.
    public PrintStream getOut() {
        return .getConsole().getOut();
    }

    
Returns a java.io.PrintStream for stderr in the Debugger's internal Console window.
    public PrintStream getErr() {
        return .getConsole().getErr();
    }

    
Packs the debugger GUI frame.
    public void pack() {
        .pack();
    }

    
Sets the debugger GUI frame dimensions.
    public void setSize(int wint h) {
        .setSize(wh);
    }

    
Sets the visibility of the debugger GUI frame.
    public void setVisible(boolean flag) {
        .setVisible(flag);
    }

    
Returns whether the debugger GUI frame is visible.
    public boolean isVisible() {
        return .isVisible();
    }

    
Frees any resources held by the debugger.
    public void dispose() {
        clearAllBreakpoints();
        .go();
        .dispose();
         = null;
    }

    
Attaches the debugger to the given org.mozilla.javascript.ContextFactory.
    public void attachTo(ContextFactory factory) {
        .attachTo(factory);
    }

    
Detaches from the current org.mozilla.javascript.ContextFactory.
    public void detach() {
        .detach();
    }

    
Main entry point. Creates a debugger attached to a Rhino org.mozilla.javascript.tools.shell.Main shell session.
    public static void main(String[] args) {
        Main main = new Main("Rhino JavaScript Debugger");
        main.doBreak();
        main.setExitAction(new IProxy(.));
        System.setIn(main.getIn());
        System.setOut(main.getOut());
        System.setErr(main.getErr());
        Global global = org.mozilla.javascript.tools.shell.Main.getGlobal();
        global.setIn(main.getIn());
        global.setOut(main.getOut());
        global.setErr(main.getErr());
        main.attachTo(
        main.setScope(global);
        main.pack();
        main.setSize(600, 460);
        main.setVisible(true);
        org.mozilla.javascript.tools.shell.Main.exec(args);
    }

    
Entry point for embedded applications. This method attaches to the global org.mozilla.javascript.ContextFactory with a scope of a newly created org.mozilla.javascript.tools.shell.Global object. No I/O redirection is performed as with main(java.lang.String[]).
    public static Main mainEmbedded(String title) {
        ContextFactory factory = ContextFactory.getGlobal();
        Global global = new Global();
        global.init(factory);
        return mainEmbedded(factoryglobaltitle);
    }

    
Entry point for embedded applications. This method attaches to the given org.mozilla.javascript.ContextFactory with the given scope. No I/O redirection is performed as with main(java.lang.String[]).
    public static Main mainEmbedded(ContextFactory factory,
                                    Scriptable scope,
                                    String title) {
        return mainEmbeddedImpl(factoryscopetitle);
    }

    
Entry point for embedded applications. This method attaches to the given org.mozilla.javascript.ContextFactory with the given scope. No I/O redirection is performed as with main(java.lang.String[]).
    public static Main mainEmbedded(ContextFactory factory,
                                    ScopeProvider scopeProvider,
                                    String title) {
        return mainEmbeddedImpl(factoryscopeProvidertitle);
    }

    
Helper method for mainEmbedded(java.lang.String), etc.
    private static Main mainEmbeddedImpl(ContextFactory factory,
                                         Object scopeProvider,
                                         String title) {
        if (title == null) {
            title = "Rhino JavaScript Debugger (embedded usage)";
        }
        Main main = new Main(title);
        main.doBreak();
        main.setExitAction(new IProxy(.));
        main.attachTo(factory);
        if (scopeProvider instanceof ScopeProvider) {
            main.setScopeProvider((ScopeProvider)scopeProvider);
        } else {
            Scriptable scope = (Scriptable)scopeProvider;
            if (scope instanceof Global) {
                Global global = (Global)scope;
                global.setIn(main.getIn());
                global.setOut(main.getOut());
                global.setErr(main.getErr());
            }
            main.setScope(scope);
        }
        main.pack();
        main.setSize(600, 460);
        main.setVisible(true);
        return main;
    }
    // Deprecated methods

    

Deprecated:
Use setSize(int,int) instead.
    public void setSize(java.awt.Dimension dimension) {
        .setSize(dimension.widthdimension.height);
    }

    

Deprecated:
The method does nothing and is only present for compatibility.
    public void setOptimizationLevel(int level) {
    }

    

Deprecated:
The method is only present for compatibility and should not be called.
    public void contextEntered(Context cx) {
        throw new IllegalStateException();
    }

    

Deprecated:
The method is only present for compatibility and should not be called.
    public void contextExited(Context cx) {
        throw new IllegalStateException();
    }

    

Deprecated:
The method is only present for compatibility and should not be called.
    public void contextCreated(Context cx) {
        throw new IllegalStateException();
    }

    

Deprecated:
The method is only present for compatibility and should not be called.
    public void contextReleased(Context cx)
    {
        throw new IllegalStateException();
    }

    
Class to consolidate all internal implementations of interfaces to avoid class generation bloat.
    private static class IProxy implements RunnableScopeProvider {
        // Constants for 'type'.
        public static final int EXIT_ACTION = 1;
        public static final int SCOPE_PROVIDER = 2;

        
The type of interface.
        private final int type;

        
The scope object to expose when type = SCOPE_PROVIDER.
        private Scriptable scope;

        
Creates a new IProxy.
        public IProxy(int type) {
            this. = type;
        }

        
Creates a new IProxy that acts as a ScopeProvider.
        public static ScopeProvider newScopeProvider(Scriptable scope) {
            IProxy scopeProvider = new IProxy();
            scopeProvider.scope = scope;
            return scopeProvider;
        }
        // ContextAction

        
Exit action.
        public void run() {
            if ( != ) Kit.codeBug();
            System.exit(0);
        }
        // ScopeProvider

        
Returns the scope for script evaluations.
        public Scriptable getScope() {
            if ( != ) Kit.codeBug();
            if ( == null) Kit.codeBug();
            return ;
        }
    }
New to GrepCode? Check out our FAQ X