durian/demo/codeViewer/java/CodeViewer.java

INDEX Java.use(better)
  1: //..+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
  2: /*
  3:  * Copyright (c) 2010-2011, KOTSUBU-chan and/or its affiliates.
  4:  * All rights reserved.
  5:  * @version 1.0
  6:  */ 
  7: package durian;
  8: 
  9: import java.awt.*;
 10: import java.awt.event.*;
 11: import javax.swing.*;
 12: 
 13: // ----------------------------------------
 14: public class CodeViewer extends JFrame
 15:   implements IViewer, ActionListener {
 16:   final private JTextField textField = new JTextField(80);
 17:   final private PlainTextView textView = new PlainTextView();
 18: 
 19:   // ----------------------------------------
 20:   public CodeViewer(String title, Dimension d, Font font) {
 21:     this.init(font);
 22:     this.initFrame(title, d);
 23:     this.initComponent();
 24:   }
 25: 
 26:   public CodeViewer(String title, Dimension d) {
 27:     this(title, d, new Font("Courier", Font.PLAIN, 12));
 28:   }
 29: 
 30:   // ----------------------------------------
 31:   private void init(Font font) {
 32:     this.textField.addActionListener(this);
 33:     this.textView.setFont_(font);
 34:   }
 35: 
 36:   private void initFrame(String title, Dimension d) {
 37:     this.setLocationRelativeTo(null);
 38:     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 39:     this.setTitle(title);
 40:     this.setSize(d);
 41:   }
 42: 
 43:   private void initComponent() {
 44:     JPanel panel = new JPanel(new BorderLayout());
 45:     this.getContentPane().add(panel);
 46:     panel.add(this.textField, BorderLayout.NORTH);
 47:     panel.add(this.textView, BorderLayout.CENTER);
 48:   }
 49: 
 50:   // ----------------------------------------
 51:   public void actionPerformed(ActionEvent evt) {
 52:     this.textView.clear();
 53:     new TextFile(this, this.textField.getText());
 54:   }
 55: 
 56:   // ----------------------------------------
 57:   public void println(Object obj) {
 58:     this.print(obj + "\n");
 59:   }
 60: 
 61:   void print(Object obj) {
 62:     this.textView.print(""+obj);
 63:   }
 64: 
 65:   public void reset() {
 66:     this.textView.reset();
  }
 67: 
 68:   // ----------------------------------------
 69:   private static void ex_File(String name, Dimension d) {
 70:     CodeViewer viewer = new CodeViewer(name, d);
 71:     new TextFile(viewer, name);
 72:     viewer.setVisible(true);
 73:   }
 74: 
 75:   // ----------------------------------------
 76:   static void tips() {
 77:     ex_File(
 78:       "CodeViewer.java",
 79:       new Dimension(580, 400));
 80:   }
 81: 
 82:   // ----------------------------------------
 83:   private CodeViewer() {}
 84:   static String version = new CodeViewer()
 85:     .getClass().getName()+": #1.0.01";
 86: }
 87: 
 88: // ========================================