Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jruby.demo;
  
  import java.awt.Color;
  import java.awt.Font;
  import java.awt.Insets;
 
 
 import org.jruby.Ruby;
 
 public class IRBConsole extends JFrame {
     public IRBConsole(String title) {
         super(title);
     }
 
     public static void main(final String[] args) {
         final IRBConsole console = new IRBConsole("JRuby IRB Console");
         final ArrayList<Stringlist = new ArrayList(Arrays.asList(args));
 
         console.getContentPane().setLayout(new BorderLayout());
         console.setSize(700, 600);
 
         JEditorPane text = new JTextPane();
 
         text.setMargin(new Insets(8,8,8,8));
         text.setCaretColor(new Color(0xa4, 0x00, 0x00));
         text.setBackground(new Color(0xf2, 0xf2, 0xf2));
         text.setForeground(new Color(0xa4, 0x00, 0x00));
         Font font = console.findFont("Monospaced"., 14,
                 new String[] {"Monaco""Andale Mono"});
 
         text.setFont(font);
         JScrollPane pane = new JScrollPane();
         pane.setViewportView(text);
         pane.setBorder(BorderFactory.createLineBorder(.));
         console.getContentPane().add(pane);
         console.validate();
 
         final TextAreaReadline tar = new TextAreaReadline(text" Welcome to the JRuby IRB Console \n\n");
         console.addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent e) {
                 tar.shutdown();
             }
         });
 
         final RubyInstanceConfig config = new RubyInstanceConfig() {{
             CompatVersion compat = .;
             if (args.length > 0) {
                 if (args[0].equals("1.8")) {
                     list.remove(0);
                 } else if (args[0].equals("1.9")) {
                     compat = .;
                     list.remove(0);
                 }
             }
             setInput(tar.getInputStream());
             setOutput(new PrintStream(tar.getOutputStream()));
             setError(new PrintStream(tar.getOutputStream()));
             setArgv(list.toArray(new String[0]));
             setCompatVersion(compat);
         }};
         final Ruby runtime = Ruby.newInstance(config);
 
         runtime.getGlobalVariables().defineReadonly("$$"new ValueAccessor(runtime.newFixnum(System.identityHashCode(runtime))));
 
         tar.hookIntoRuntime(runtime);
 
         Thread t2 = new Thread() {
             public void run() {
                 console.setVisible(true);
                 runtime.evalScriptlet(
                         "ARGV << '--readline' << '--prompt' << 'inf-ruby';"
                         + "require 'irb'; require 'irb/completion';"
                         + "IRB.start");
             }
         };
         t2.start();
 
         try {
             t2.join();
         } catch (InterruptedException ie) {
             // ignore
         }
 
         System.exit(0);
    }
    private Font findFont(String otherwiseint styleint sizeString[] families) {
        String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
        Arrays.sort(fonts);
        Font font = null;
        for (int i = 0; i < families.lengthi++) {
            if (Arrays.binarySearch(fontsfamilies[i]) >= 0) {
                font = new Font(families[i], stylesize);
                break;
            }
        }
        if (font == null) {
            font = new Font(otherwisestylesize);
        }
        return font;
    }

    
    private static final long serialVersionUID = 3746242973444417387L;
New to GrepCode? Check out our FAQ X