001package com.ganteater.ae.desktop.view; 002 003import java.awt.BorderLayout; 004import java.util.Properties; 005 006import javax.swing.JScrollBar; 007import javax.swing.JScrollPane; 008import javax.swing.JTextArea; 009 010import com.ganteater.ae.AEManager; 011import com.ganteater.ae.processor.annotation.CommandDescription; 012 013@CommandDescription("`Text` View Type example:\r\n" 014 + "\r\n" 015 + "```xml \r\n" 016 + "<View name=\"textView\" reuse=\"true\" type=\"Text\" /> \r\n" 017 + "<Out view=\"textView\" value=\"text\" /> \r\n" 018 + "```") 019public class Text extends View { 020 private static final long serialVersionUID = -6679978094828718987L; 021 private JTextArea fTextArrea = new JTextArea(); 022 JScrollPane scroll = new JScrollPane(fTextArrea); 023 024 public void init(Properties params, AEManager manager) { 025 super.init(params, null); 026 fTextArrea.setEditable(true); 027 add(scroll, BorderLayout.CENTER); 028 } 029 030 @Override 031 public void out(Object value, Properties properties) { 032 int length = fTextArrea.getText().length(); 033 boolean scrollOn = fTextArrea.getCaretPosition() == length || length == 0; 034 fTextArrea.append(value + "\n"); 035 if (scrollOn) { 036 length = fTextArrea.getText().length(); 037 fTextArrea.setCaretPosition(length); 038 JScrollBar verticalScrollBar = scroll.getVerticalScrollBar(); 039 verticalScrollBar.setValue(verticalScrollBar.getMaximum()); 040 } 041 } 042 043}