home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 22 / AMUG_22-1.ISO / Files / Internet / Java / jadi-1.0.sit / jadi-1.0 / jadiOptions.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-01  |  6.7 KB  |  234 lines  |  [TEXT/ttxt]

  1. import java.awt.BorderLayout;
  2. import java.awt.Button;
  3. import java.awt.Checkbox;
  4. import java.awt.CheckboxGroup;
  5. import java.awt.Color;
  6. import java.awt.Container;
  7. import java.awt.Event;
  8. import java.awt.FlowLayout;
  9. import java.awt.Font;
  10. import java.awt.Frame;
  11. import java.awt.GridBagLayout;
  12. import java.awt.Label;
  13. import java.awt.Panel;
  14. import java.awt.TextArea;
  15. import java.awt.TextField;
  16. import java.awt.Window;
  17. import java.io.FileOutputStream;
  18. import java.io.IOException;
  19. import java.io.PrintStream;
  20.  
  21. class jadiOptions extends Frame {
  22.    private Label titleLabel;
  23.    private Panel outputAreaPanel;
  24.    private Panel projectOptionsPanel;
  25.    private Panel HTMLSetupPanel;
  26.    private TextField appletHeight;
  27.    private TextField appletWidth;
  28.    private Button buttonCreate;
  29.    private CheckboxGroup checkbox_group;
  30.    private Checkbox[] checkboxes;
  31.    private TextField theArgs;
  32.    private TextField theFile;
  33.    private String ArgsOld;
  34.    private String FileOld;
  35.    private Button buttonApply;
  36.    private Button buttonCancel;
  37.    private Label Label1;
  38.    private Label Label2;
  39.    private TextField commandLineDisplay;
  40.    private TextArea outputWindow;
  41.    private GridBagLayout gridBag;
  42.    private JADI MainWindow;
  43.  
  44.    jadiOptions(JADI var1) {
  45.       super(new String("JADI: Program Options"));
  46.       this.MainWindow = var1;
  47.       this.gridBag = new GridBagLayout();
  48.       ((Container)this).setLayout(this.gridBag);
  49.       this.titleLabel = new Label("JADI: Program Options");
  50.       this.titleLabel.setFont(new Font("TimesRoman", 1, 24));
  51.       this.titleLabel.setAlignment(1);
  52.       JADI.constrain(this, this.titleLabel, 0, 0, 1, 1, 2, 10, (double)1.0F, (double)1.0F, 0, 0, 0, 0);
  53.       this.outputAreaPanel = new Panel();
  54.       this.outputAreaPanel.setLayout(new BorderLayout());
  55.       this.commandLineDisplay = new TextField(40);
  56.       this.commandLineDisplay.setEditable(false);
  57.       this.commandLineDisplay.setFont(new Font("Helvetica", 0, 12));
  58.       this.outputWindow = new TextArea(7, 40);
  59.       this.outputWindow.setEditable(false);
  60.       this.outputWindow.setFont(new Font("Helvetica", 0, 10));
  61.       this.outputAreaPanel.add("North", this.commandLineDisplay);
  62.       this.outputAreaPanel.add("Center", this.outputWindow);
  63.       JADI.constrain(this, this.outputAreaPanel, 0, 1, 1, 1, 2, 10, (double)1.0F, (double)1.0F, 0, 0, 0, 0);
  64.       this.projectOptionsPanel = new Panel();
  65.       this.projectOptionsPanel.setLayout(new BorderLayout());
  66.       Panel var2 = new Panel();
  67.       this.checkbox_group = new CheckboxGroup();
  68.       this.checkboxes = new Checkbox[2];
  69.       this.checkboxes[0] = new Checkbox("Applet", this.checkbox_group, true);
  70.       this.checkboxes[1] = new Checkbox("Application", this.checkbox_group, false);
  71.       ((Container)var2).setLayout(new FlowLayout(1, 25, 10));
  72.       ((Container)var2).add(this.checkboxes[0]);
  73.       ((Container)var2).add(this.checkboxes[1]);
  74.       Panel var3 = new Panel();
  75.       this.theArgs = new TextField(20);
  76.       this.theFile = new TextField(20);
  77.       this.theArgs.disable();
  78.       ((Container)var3).setLayout(new GridBagLayout());
  79.       Label var5 = this.Label1 = new Label("Command Line Args:");
  80.       JADI.constrain(var3, var5, 0, 0, 1, 1, 0, 18, (double)0.0F, (double)0.0F, 0, 0, 0, 0);
  81.       TextField var6 = this.theArgs;
  82.       JADI.constrain(var3, var6, 1, 0, 1, 1, 0, 18, (double)0.0F, (double)0.0F, 0, 0, 0, 0);
  83.       Label var7 = this.Label2 = new Label("HTML File:");
  84.       JADI.constrain(var3, var7, 0, 1, 1, 1, 0, 18, (double)0.0F, (double)0.0F, 0, 0, 0, 0);
  85.       TextField var8 = this.theFile;
  86.       JADI.constrain(var3, var8, 1, 1, 1, 1, 0, 18, (double)0.0F, (double)0.0F, 0, 0, 0, 0);
  87.       Panel var4 = new Panel();
  88.       ((Container)var4).setLayout(new FlowLayout(1, 20, 10));
  89.       this.buttonApply = new Button("Commit");
  90.       this.buttonCancel = new Button("Revert");
  91.       ((Container)var4).add(this.buttonApply);
  92.       ((Container)var4).add(this.buttonCancel);
  93.       this.projectOptionsPanel.add("North", var2);
  94.       this.projectOptionsPanel.add("Center", var3);
  95.       this.projectOptionsPanel.add("South", var4);
  96.       JADI.constrain(this, this.projectOptionsPanel, 0, 2, 1, 1, 2, 10, (double)1.0F, (double)1.0F, 0, 0, 0, 0);
  97.       this.HTMLSetupPanel = new Panel();
  98.       this.buttonCreate = new Button("Create HTML File");
  99.       this.HTMLSetupPanel.setLayout(new GridBagLayout());
  100.       this.appletHeight = new TextField(5);
  101.       this.appletWidth = new TextField(5);
  102.       JADI.constrain(this.HTMLSetupPanel, this.Label1 = new Label("Height:", 2), 0, 0, 1, 1, 0, 13, (double)1.0F, (double)1.0F, 0, 0, 0, 0);
  103.       JADI.constrain(this.HTMLSetupPanel, this.appletHeight, 1, 0, 1, 1, 0, 17, (double)1.0F, (double)1.0F, 0, 0, 0, 0);
  104.       JADI.constrain(this.HTMLSetupPanel, this.Label2 = new Label("Width:", 2), 0, 1, 1, 1, 0, 13, (double)1.0F, (double)1.0F, 0, 0, 0, 0);
  105.       JADI.constrain(this.HTMLSetupPanel, this.appletWidth, 1, 1, 1, 1, 0, 17, (double)1.0F, (double)1.0F, 0, 0, 0, 0);
  106.       JADI.constrain(this.HTMLSetupPanel, this.buttonCreate, 2, 0, 1, 2, 0, 10, (double)1.0F, (double)1.0F, 0, 0, 0, 0);
  107.       JADI.constrain(this, this.HTMLSetupPanel, 0, 3, 1, 1, 2, 10, (double)1.0F, (double)1.0F, 0, 0, 0, 0);
  108.       ((Window)this).pack();
  109.    }
  110.  
  111.    void setOutput(String var1, Color var2) {
  112.       this.outputWindow.setForeground(var2);
  113.       this.outputWindow.setText(var1);
  114.    }
  115.  
  116.    void setCommandLine(String var1, Color var2) {
  117.       this.commandLineDisplay.setForeground(var2);
  118.       this.commandLineDisplay.setText(var1);
  119.    }
  120.  
  121.    void clearOutputArea() {
  122.       this.outputWindow.setText("");
  123.       this.commandLineDisplay.setText("");
  124.    }
  125.  
  126.    public boolean handleEvent(Event var1) {
  127.       if (var1.target instanceof Button) {
  128.          if (var1.target == this.buttonApply) {
  129.             this.clickApply();
  130.          } else if (var1.target == this.buttonCancel) {
  131.             this.theArgs.setText(this.ArgsOld);
  132.             this.theFile.setText(this.FileOld);
  133.          } else if (var1.target == this.buttonCreate) {
  134.             this.createHTMLFile();
  135.          }
  136.       } else if (var1.target instanceof Checkbox) {
  137.          this.updateWindowOptions(var1.target);
  138.       }
  139.  
  140.       return super.handleEvent(var1);
  141.    }
  142.  
  143.    private void clickApply() {
  144.       this.ArgsOld = new String(this.theArgs.getText());
  145.       this.FileOld = new String(this.theFile.getText());
  146.    }
  147.  
  148.    private void revert() {
  149.       this.theArgs.setText(this.ArgsOld);
  150.       this.theFile.setText(this.FileOld);
  151.    }
  152.  
  153.    private void updateWindowOptions(Object var1) {
  154.       if (var1 == this.checkboxes[0]) {
  155.          this.theFile.enable();
  156.          this.theArgs.disable();
  157.          this.HTMLSetupPanel.show();
  158.       } else {
  159.          this.theFile.disable();
  160.          this.theArgs.enable();
  161.          this.HTMLSetupPanel.hide();
  162.       }
  163.    }
  164.  
  165.    private void createHTMLFile() {
  166.       if (this.MainWindow.CurrentDirectory == null) {
  167.          this.setCommandLine("Error: No File Open", Color.red);
  168.          this.setOutput("Please open a file first.", Color.red);
  169.       } else {
  170.          String var1 = new String(this.theFile.getText().trim());
  171.          String var2 = new String(this.appletHeight.getText().trim());
  172.          String var3 = new String(this.appletWidth.getText().trim());
  173.          this.clearOutputArea();
  174.          if (var1.equalsIgnoreCase(new String(""))) {
  175.             this.setCommandLine("Error: Need HTML File Name", Color.red);
  176.             this.setOutput("You have not chosen a file name for your HTML File.  \n Please fill in the HTML File Field, and try again.", Color.red);
  177.          } else {
  178.             if (var1.indexOf(System.getProperty("file.separator")) != -1) {
  179.                var1 = var1.substring(var1.lastIndexOf(System.getProperty("file.separator")) + 1);
  180.             }
  181.  
  182.             var1 = this.MainWindow.CurrentDirectory + var1.trim();
  183.  
  184.             try {
  185.                int var4 = Integer.parseInt(var2);
  186.                var4 = Integer.parseInt(var3);
  187.             } catch (NumberFormatException var9) {
  188.                this.setCommandLine("Error: Height and Width must be integer values", Color.red);
  189.                this.setOutput("The following error occured during the HTML Create\nProcess:\n\n" + ((Throwable)var9).toString() + "\n", Color.red);
  190.                System.out.println("Height and Width must be integer values");
  191.                return;
  192.             }
  193.  
  194.             String var5 = new String(this.MainWindow.CurrentFileName.substring(0, this.MainWindow.CurrentFileName.lastIndexOf(".")));
  195.             String var6 = new String(System.getProperty("line.separator"));
  196.  
  197.             try {
  198.                PrintStream var7 = new PrintStream(new FileOutputStream(var1));
  199.                var7.print("<HTML>" + var6 + "<HEAD>" + var6 + "<TITLE>JADI Generated HTML</TITLE>" + var6 + "</HEAD>" + var6 + "<BODY>" + var6 + "<APPLET CODE=\"" + var5 + ".class\" WIDTH=" + var3 + " HEIGHT=" + var2 + ">Your Browser Does Not Support Java</APPLET>" + var6 + "</BODY>" + var6 + "</HTML>");
  200.                var7.close();
  201.             } catch (IOException var8) {
  202.                this.setCommandLine("Error: Error occurred during HTML Create Process", Color.red);
  203.                this.setOutput("The following error occured during the HTML Create\nProcess:\n\n" + ((Throwable)var8).toString() + "\n" + ((Throwable)var8).getMessage(), Color.red);
  204.                System.out.println(var8);
  205.                return;
  206.             }
  207.  
  208.             this.setCommandLine("HTML File Created", Color.blue);
  209.             this.setOutput("HTML File has been created for your applet", Color.blue);
  210.          }
  211.       }
  212.    }
  213.  
  214.    public String getCmdLineArgs() {
  215.       return this.theArgs.getText().trim();
  216.    }
  217.  
  218.    public String getHTMLFileName() {
  219.       String var1 = new String(this.theFile.getText().trim());
  220.       if (var1.indexOf(System.getProperty("file.separator")) != -1) {
  221.          var1 = var1.substring(var1.lastIndexOf(System.getProperty("file.separator")) + 1);
  222.       }
  223.  
  224.       var1 = this.MainWindow.CurrentDirectory + var1.trim();
  225.       var1 = var1.replace(':', '|');
  226.       var1 = var1.replace('\\', '/');
  227.       return var1;
  228.    }
  229.  
  230.    public String getProjectType() {
  231.       return this.checkboxes[0].getState() ? "Applet" : "Application";
  232.    }
  233. }
  234.