Annotation of edoc-applet/Console.java, revision 1.1.1.1

1.1       rogo        1: import javax.swing.*;
                      2: import java.awt.event.*;
                      3: import java.awt.*;
                      4: import java.text.*;
                      5: import java.util.Locale;
                      6: import javax.swing.event.*;
                      7: import java.io.*;
                      8: 
                      9: public class Console extends JDialog implements ActionListener
                     10: {
                     11: 
                     12:   static JTextField field = new JTextField("0.00", 6);
                     13:   JLabel label = new JLabel("Load step: ", JLabel.RIGHT);
                     14:   JButton clear = new JButton("Clear Console");
                     15:   JButton save = new JButton("Save Console");
                     16:   JCheckBox logMode = new JCheckBox("Logging on",true);
                     17:   JCheckBox debugMode = new JCheckBox("Debug on",false); 
                     18:   JPanel panel = new JPanel();
                     19:   static JTextArea console = new JTextArea();
                     20:   static JScrollPane scroll = new JScrollPane(console);
                     21:   JFileChooser saveChooser;
                     22:   JPanel content;
                     23:   JFrame frame;
                     24:   String file;
                     25:   static PrintStream print;
                     26:   boolean append = false;
                     27:   public Console(JFrame frame)
                     28:   {
                     29:     super(frame);
                     30:     this.frame = frame;
                     31:     label = new JLabel("Load step: ", JLabel.RIGHT);
                     32:     clear = new JButton("Clear Console");
                     33:     save = new JButton("Save Console");
                     34:     logMode = new JCheckBox("Logging on",true);
                     35:     debugMode =  new JCheckBox("Debug on",false);
                     36:     console = new JTextArea();
                     37:     scroll = new JScrollPane(console);
                     38:     setSize(500, 400);
                     39:     setTitle("Archimedes Console");
                     40:     console.setBackground(new Color(230, 240, 250));
                     41:     Font actFont = new Font("Courier", 0, 15);
                     42:     console.setFont(actFont);
                     43:     setLocation(new Point(500, 70));
                     44:     content = (JPanel) getContentPane();
                     45:     content.add(scroll, "Center");
                     46:     panel.add(clear);
                     47:     panel.add(save);
                     48:     panel.add(logMode);
                     49:     panel.add(debugMode);
                     50:     content.add(panel, "South");
                     51:     clear.addActionListener(this);
                     52:     save.addActionListener(this);
                     53:     debugMode.addActionListener(this);
                     54:     setSaveChooser();
                     55:     add("Archimedes Console\n");
                     56:     if(print==null)
                     57:     {
                     58:       print = new PrintStream(System.out)
                     59:       {
                     60:         public PrintStream myOut = System.out;
                     61:         public void print(String a)
                     62:         {
                     63:           myOut.print(a);
                     64:           if (logMode.isSelected())
                     65:             Console.add(a);
                     66:         }
                     67:         public void print(char a)
                     68:         {
                     69:           myOut.print(a);
                     70:           if (logMode.isSelected())
                     71:             Console.add(a+"");
                     72:         }
                     73:     
                     74:         public void println(String a)
                     75:         {
                     76:           myOut.println(a);
                     77:           if (logMode.isSelected())
                     78:             Console.add(a + "\n");
                     79:         }
                     80:         public void println(Object a)
                     81:         {
                     82:           myOut.println(a);
                     83:           if (logMode.isSelected())
                     84:             Console.add(a + "\n");
                     85:         }
                     86:         public void write(byte[] b ) throws IOException
                     87:         {
                     88:           myOut.write(b);
                     89:           if (logMode.isSelected())
                     90:           Console.add(new String(b) + "\n");
                     91:             
                     92:         }
                     93:         public void write(byte[] b,int start,int end ) 
                     94:         {
                     95:           myOut.write(b,start,end);
                     96:           if (logMode.isSelected())
                     97:           Console.add(new String(b,start,end) + "\n");
                     98:             
                     99:         }
                    100:   
                    101:   
                    102:       };
                    103:       System.setOut(print);
                    104:       System.setErr(System.out);
                    105:     }
                    106:     addWindowListener(new WindowAdapter()
                    107:     {
                    108:       public void windowClosing(WindowEvent e)
                    109:       {
                    110:         //jife.showConsole.setState(false);
                    111:       }
                    112:     });
                    113: 
                    114:     //console.setEditable(false);
                    115:   }
                    116:   public void actionPerformed(ActionEvent e)
                    117:   {
                    118:     String command = e.getActionCommand();
                    119:     if (command == "Clear Console")
                    120:       clear();
                    121:     if (command == "Save Console")
                    122:     {
                    123:       saveChooser.rescanCurrentDirectory();
                    124:       saveChooser.setDialogType(JFileChooser.OPEN_DIALOG);
                    125:       saveChooser.showDialog(frame, "Save");
                    126:     }
                    127:    Upload.debug=debugMode.isSelected();
                    128:   
                    129:   
                    130:   }
                    131:   public static void clear()
                    132:   {
                    133:     console.setText("");
                    134:   }
                    135: 
                    136:   public static void add(String text)
                    137:   {
                    138:     console.append(text);
                    139:     scroll.getVerticalScrollBar().setValue(scroll.getVerticalScrollBar().getMaximum());
                    140:   }
                    141:   public void setSaveChooser()
                    142:   {
                    143:     // file Dialog
                    144:     saveChooser = new JFileChooser(".");
                    145:    // ExampleFileFilter filefilter = new ExampleFileFilter();
                    146:    // filefilter.addExtension("txt");
                    147:     //filefilter.setDescription("Txt File");
                    148:     //saveChooser.setFileFilter(filefilter);
                    149: 
                    150:     saveChooser.addActionListener(new ActionListener()
                    151:     {
                    152: 
                    153:       public void actionPerformed(ActionEvent e2)
                    154:       {
                    155:         //System.out.println(e2.getActionCommand());
                    156:         if (e2.getActionCommand().toString().equals("ApproveSelection"))
                    157:         {
                    158:           file = saveChooser.getSelectedFile().toString();
                    159:           //setTitle("Jife - Java Application for Structural Analysis - "+"<File: "+new File(file).getAbsolutePath()+">");
                    160:           if (file == null || file == "")
                    161:             file = "." + File.separator + "untitled.txt";
                    162:           if (file.endsWith(".txt") || file.endsWith(".TXT"));
                    163:           else
                    164:             file += ".txt";
                    165:           System.out.println("File" + file);
                    166:           try
                    167:           {
                    168: 
                    169:             FileOutputStream fout = new FileOutputStream(file);
                    170:             fout.write(console.getText().getBytes());
                    171:             fout.close();
                    172:           } catch (Exception e3)
                    173:           {
                    174:             System.out.println("Serial errror:" + e3);
                    175:           }
                    176: 
                    177:         }
                    178:       }
                    179:     });
                    180: 
                    181:   }
                    182: 
                    183: } // to class

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>