import java.awt.*;
import java.awt.event.*;
import java.io.*; 
import javax.swing.*;

public class UniversalTextViewer extends JPanel { 
  
  public UniversalTextViewer(String filename, String enc) {
    setLayout(new BorderLayout());
    JTextArea textarea = new JTextArea(40, 80); 
    textarea.setEditable(false); 
    textarea.setFont(new Font("Monospaced", Font.BOLD, 16)); 
    add("Center", new JScrollPane(textarea)); 
    try {
      BufferedReader in = 
	  new BufferedReader(
          new InputStreamReader(new FileInputStream(filename), enc)); 
      String line; 
      while ((line = in.readLine()) != null) {
	textarea.append(line + "\n"); 
      }
    } catch (IOException e) {}
  }

  public static void main(String args[]) {
    if (args.length >= 2) {
      JFrame frame = new JFrame();
      frame.setTitle("Universal Text Viewer: " + 
		     args[0] + " [" + args[1] + "]");
      frame.setBackground(Color.lightGray);
      frame.getContentPane().setLayout(new BorderLayout());
      frame.getContentPane().add("Center", new UniversalTextViewer(args[0], args[1]));
      frame.addWindowListener(new AppCloser());
      frame.setSize(400, 300);
      frame.show();
    }
  }

  protected static final class AppCloser extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
      System.exit(0);
    }
  }
  
}