001    package jagafa.util.dump;
002    
003    import java.awt.BorderLayout;
004    import java.awt.Color;
005    import java.awt.event.ActionEvent;
006    import java.awt.event.ActionListener;
007    
008    import javax.swing.BorderFactory;
009    import javax.swing.JButton;
010    import javax.swing.JPanel;
011    import javax.swing.JScrollPane;
012    import javax.swing.JTextArea;
013    import javax.swing.border.Border;
014    
015    public class DumpPanel extends JPanel implements ActionListener {
016            /**
017             * 
018             */
019            private static final long serialVersionUID = -9071344325150010684L;
020    
021            private static final String CLEAR_DUMP = "Clear";
022    
023            private JTextArea textArea_;
024    
025            public DumpPanel() {
026                    super();
027                    this.addTitleBorder("Dump");
028                    this.setLayout(new BorderLayout());
029                    textArea_ = new JTextArea();
030                    JButton clearButton = new JButton(CLEAR_DUMP);
031                    this.add(clearButton, BorderLayout.SOUTH);
032                    clearButton.addActionListener(this);
033    
034                    JScrollPane scroll = new JScrollPane(textArea_);
035                    scroll.setAutoscrolls(true);
036    
037                    this.add(scroll, BorderLayout.CENTER);
038                    //textArea_.requestFocus();
039    
040            }
041    
042            public void dump(String text) {
043                    //this.requestFocus();
044                    this.textArea_.append(text);
045    
046            }
047    
048            public void actionPerformed(ActionEvent arg0) {
049                    String command = arg0.getActionCommand();
050    
051                    if (command.equals(CLEAR_DUMP)) {
052                            clear();
053                    }
054    
055            }
056    
057            public void clear() {
058                    this.textArea_.setText("");
059            }
060    
061            private void addTitleBorder(String string) {
062                    Border b = BorderFactory.createLineBorder(Color.BLACK);
063    
064                    Border titleB = BorderFactory.createTitledBorder(b, string);
065                    this.setBorder(titleB);
066    
067            }
068    
069    }