@Override public Value eval(EvalContext ctx, Value[] args, Type resultType) { ScriptEngineManager m = new ScriptEngineManager(); ScriptEngine rubyEngine = m.getEngineByName("jruby"); if (rubyEngine == null) throw new RuntimeException("Did not find the ruby engine. Please verify your classpath"); ScriptContext context = rubyEngine.getContext(); context.setErrorWriter(new NullWriter()); context.setAttribute( "self", RubyHelper.useValueToRubyValue(args[0]), ScriptContext.ENGINE_SCOPE); for (int i = 0; i < parameter.size(); i++) { context.setAttribute( parameter.get(i).getName(), RubyHelper.useValueToRubyValue(args[i + 1]), ScriptContext.ENGINE_SCOPE); } try { Object result = rubyEngine.eval(operationBody, context); Value resultValue = RubyHelper.rubyValueToUseValue(result, resultType); // Wrong result type! if (!resultValue.type().isSubtypeOf(this.resultType)) { Log.warn( "Extension method `" + name + "' returned wrong type! Expected `" + this.resultType.toString() + "' got `" + resultValue.type().toString() + "'"); return UndefinedValue.instance; } else { return resultValue; } } catch (ScriptException e) { Log.error(e.getMessage()); } catch (EvalFailedException e) { Log.error(e.getMessage()); } return UndefinedValue.instance; }
/** Draws the panel. */ public void paintComponent(Graphics g) { super.paintComponent(g); Log.setTrace(true); // Log.trace(this, getBounds().toString()); // Log.trace(this, getInsets().toString()); // respect borders Insets insets = getInsets(); Rectangle r = getBounds(); r.x += insets.left; r.y += insets.top; r.width -= insets.left + insets.right; r.height -= insets.top + insets.bottom; // System.out.println("paintComponent" + count++); g.setColor(Color.black); DirectedGraph<LayoutNode, DirectedEdge<LayoutNode>> graph = fLayout.graph(); // draw edges Iterator<DirectedEdge<LayoutNode>> edgeIter = graph.edgeIterator(); while (edgeIter.hasNext()) { DirectedEdge<LayoutNode> edge = edgeIter.next(); // Log.trace(this, edge.toString()); LayoutNode source = (LayoutNode) edge.source(); LayoutNode target = (LayoutNode) edge.target(); int x1 = source.getX() * 80 + 30; int y1 = 50 + source.fLayer * 50; // if (source.isDummy() ) // x1 += 5; int x2 = target.getX() * 80 + 30; int y2 = 50 + target.fLayer * 50; // if (target.isDummy() ) // x2 += 5; g.drawLine(x1, y1, x2, y2); } // draw nodes Iterator<LayoutNode> nodeIter = graph.iterator(); while (nodeIter.hasNext()) { LayoutNode node = nodeIter.next(); if (node.isDummy()) continue; int x = node.getX() * 80 + 30; int y = 50 + node.fLayer * 50; g.setColor(Color.white); g.fillRect(x - 10, y - 10, 20, 20); g.setColor(Color.black); g.drawRect(x - 10, y - 10, 20, 20); g.drawString(node.toString(), x - 7, y + 8); } }
/** * Executes command and stores undo information. * * @exception CommandFailedException if the command failed. */ public void execute() throws CommandFailedException { fSystemState.system().enterOperation(fOpCall, new PrintWriter(Log.out())); }