그루비 콘솔의 내용을 스윙 빌더의 Editor pane/textarea에 인쇄해야합니다. 내가 어떻게 해?편집기 창에 Groovy 콘솔 인쇄
이것을 달성 할 수있는 재사용 가능한 코드/클래스가 있습니까?
그루비 콘솔의 내용을 스윙 빌더의 Editor pane/textarea에 인쇄해야합니다. 내가 어떻게 해?편집기 창에 Groovy 콘솔 인쇄
이것을 달성 할 수있는 재사용 가능한 코드/클래스가 있습니까?
감사합니다. println을 새로운 인쇄 스트림으로 간단하게 리디렉션 할 수 있습니다. 여기에 코드가 있습니다. 이 클래스는 모든 sysout 및 syserr 문을 포함하는 텍스트 영역을 표시하는 내부 프레임을 작성합니다.
public class ConsoleFrame extends JInternalFrame
{
JTextArea outArea = new JTextArea(300,300);
static JInternalFrame cons;
public ConsoleFrame()
{
JScrollPane pain = new JScrollPane(outArea);
//pain.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
this.add(pain);
this.setVisible(true);
this.setSize(785,255);
this.setTitle("Groovy Console");
this.closable = false;
this.maximizable = false;
this.isSelected = true;
this.resizable = false;
BasicInternalFrameUI ui = (BasicInternalFrameUI)this.getUI();
Component north = ui.getNorthPane();
MouseMotionListener[] actions =
(MouseMotionListener[])north.getListeners(MouseMotionListener.class);
for (int i = 0; i < actions.length; i++)
north.removeMouseMotionListener(actions[i]);
this.setFocusable(false);
System.setOut(new PrintStream(new JTextAreaOutputStream(outArea)));
System.setErr(new PrintStream(new JTextAreaOutputStream(outArea)));
setConsole(this);
}
static public JInternalFrame getConsole(){
return cons;
}
public void setConsole(JInternalFrame console){
cons = console;
}
public class JTextAreaOutputStream extends OutputStream {
JTextArea ta;
public JTextAreaOutputStream(JTextArea t) {
super();
ta = t;
}
public void write(int i) {
ta.append(Character.toString((char)i));
}
public void write(char[] buf, int off, int len) {
String s = new String(buf, off, len);
ta.append(s);
}
}
}
귀하의 솔루션은 groovyConsole을 인스턴스화하는 방법과 방법 및 이유에 의존 할 것입니다.
내용을 말할 때 콘솔에서 스크립트를 실행하거나 콘솔의 편집기 영역에 표시된 스크립트를 실행 한 결과를 의미합니까?
그루비 콘솔 자체가 스윙 빌더가 인스턴스화 한 텍스트 영역과 편집기 창을 사용한다는 점에 유의하십시오. 소스 코드는 http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/main/groovy/ui/Console.groovy
콘솔 생성 방법을 참조하십시오. 자신의 코드에서 그렇게하고 콘솔 객체에 대한 참조를 유지한다면 다양한 텍스트 영역의 내용에 액세스 할 수 있어야합니다.