import java.awt.*; import java.applet.*; import java.util.*; import java.io.*; import java.awt.event.*; /** * An applet to provide an editor of text. * @author matth3wbishopyahoo!com */ public class SimpleEditPanel extends Panel implements ActionListener { //-------------------------------------------- private StringBuffer sbFileContents; //-------------------------------------------- private Button btnSave; //-------------------------------------------- /** a button for loading a file */ private Button btnLoad; //-------------------------------------------- /** the main area for editing text */ private TextArea taEditArea; //-------------------------------------------- private TextField tfLoadFile; //-------------------------------------------- private TextField tfPassword; //-------------------------------------------- private TextField tfRemoteSavePath; //-------------------------------------------- private WindMillLabel lblMessages; //-------------------------------------------- private Font displayFont; //------------------------------------------------- /** a panel to hold some components */ private Panel pnlTop; //------------------------------------------------- private Date startTime; //------------------------------------------------- private Date initializeTime; //------------------------------------------------- private Date stopTime; //------------------------------------------------- private Date destroyDate; //------------------------------------------------- Color backgroundColour; //------------------------------------------------- private String sServer = "bumble.sf.net"; //------------------------------------------------- private String sUserName = "matth3wbishop"; //------------------------------------------------- private String sServerWebRoot = "/home/groups/b/bu/bumble/htdocs"; //------------------------------------------------- private String sCurrentFileLocalName; //------------------------------------------------- private String sCurrentFileUrl; //------------------------------------------------- private WindMillLabel statusLabel; //------------------------------------------------- /** */ public SimpleEditPanel() { //super(); //this.statusLabel = new WindMillLabel("edit"); this.sCurrentFileLocalName = ""; this.sCurrentFileUrl = ""; sbFileContents = new StringBuffer(); this.displayFont = new Font("Monospaced", Font.PLAIN, 16); this.pnlTop = new Panel(); Color WHITE = new Color(255, 255, 255); Color DEEP_GREEN = new Color(0, 33, 0); Color BLACK = new Color(0, 0, 0); this.setBackground(DEEP_GREEN); this.initializeTime = new Date(); System.out.println("init method of applet"); this.btnSave = new Button("save"); this.btnSave.addActionListener(this); this.btnLoad = new Button("load"); this.btnLoad.addActionListener(this); this.tfLoadFile = new TextField("http://bumble.sf.net/", 30); this.tfLoadFile.addActionListener(this); this.tfLoadFile.setFont(displayFont); this.tfLoadFile.setBackground(WHITE); this.tfPassword = new TextField("..", 10); this.tfPassword.setFont(displayFont); this.tfPassword.setBackground(WHITE); this.tfRemoteSavePath = new TextField(this.sServerWebRoot, 15); this.tfRemoteSavePath.setFont(displayFont); this.tfRemoteSavePath.setBackground(WHITE); this.lblMessages = new WindMillLabel(); this.lblMessages.setForeground(WHITE); this.lblMessages.setFont(displayFont); this.taEditArea = new TextArea("hello text area"); this.taEditArea.setEditable(true); this.taEditArea.setFont(this.displayFont); this.taEditArea.setForeground(WHITE); this.taEditArea.setBackground(BLACK); //this.setLayout(new java.awt.GridLayout(1,0)); this.setLayout(new java.awt.BorderLayout()); this.pnlTop.add(this.tfLoadFile); this.pnlTop.add(this.btnLoad); this.pnlTop.add(this.btnSave); this.pnlTop.add(this.tfPassword); this.pnlTop.add(this.tfRemoteSavePath); this.add("North", this.pnlTop); this.add("South", this.lblMessages); this.add("Center", this.taEditArea); //add(taEditArea); //validate(); } //-- const:() //-------------------------------------------- public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == this.btnSave) { this.lblMessages.setText("file saved " + (new Date())); } //-- if save button if (source == this.tfLoadFile) { this.lblMessages.setText("loading "); } if (source == this.btnLoad) { StringBuffer sbMessages = new StringBuffer(""); //taEditArea.appendText(sbMessages.toString()); this.lblMessages.setLabel( "Trying to load file " + tfLoadFile.getText()); this.lblMessages.spin(); WebDownload wdLoad = new WebDownload(tfLoadFile.getText()); wdLoad.download(); this.taEditArea.append(wdLoad.printStatistics()); BufferedReader brReader; FileReader frTextFile; try { frTextFile = new FileReader(wdLoad.getFileName()); } catch (FileNotFoundException ex) { this.taEditArea.append("a problem loading the local file"); return; } this.sCurrentFileLocalName = new File(wdLoad.getFileName()).getAbsolutePath(); this.sCurrentFileUrl = wdLoad.getUrl(); brReader = new BufferedReader(frTextFile); int ii; try { ii = brReader.read(); while (ii != -1) { this.sbFileContents.append((char)ii); ii = brReader.read(); } this.taEditArea.append(sbFileContents.toString()); brReader.close(); frTextFile.close(); this.lblMessages.setLabel("File loaded"); this.lblMessages.stopSpinning(); } catch (IOException ex) { } } //-- if } //-- method: actionPerformed //-------------------------------------------- //-------------------------------------------- /** A main method to test */ public static void main(String[] args) throws Exception { StringBuffer sbUsageMessage = new StringBuffer(""); sbUsageMessage.append("usage: java SimpleEditPanel ."); //sbUsageMessage.append(NEWLINE); if (args.length == 0) { System.out.println(sbUsageMessage); System.exit(-1); } Frame frame = new Frame("Testing SimpleEditPanel"); SimpleEditPanel epTest = new SimpleEditPanel(); frame.add("Center", epTest); //-- exit when the window is closed //-- frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ee) { System.exit(0); } }); frame.pack(); frame.show(); } //-- main() } //-- class: EditPanel