home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / ed8n1t2i / optionsframe.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  5.7 KB  |  150 lines

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // OptionsFrame.java     v 1.00 b2
  5. // Written by:           I. van Rienen / E-mail ivr@bart.nl
  6. // URL:                  http://www/bart.nl/~ivr
  7. // Initial release:           v 1.00b1 01-03-1996
  8. //                            v 1.00b2 07-03-1996 Frame dimension adjusted
  9. // Released in public domain: v 1.00b1 01-03-1996
  10. //
  11. // ---- Description ----
  12. // Java class containing methods for the the options frame.
  13. //
  14. // This program and the Java source is in the public domain.
  15. // Permission to use, copy, modify, and distribute this software
  16. // and its documentation for NON-COMMERCIAL purposes and
  17. // without fee is hereby granted.
  18. //
  19. //    Copyright 1996
  20. //
  21. //    Iwan van Rienen
  22. //    Joan Maetsuyckerstr. 145
  23. //    2593 ZG  The Hague
  24. //    The Netherlands
  25. //
  26. // I am not responsible for any bugs in this program and
  27. // possible damage to hard- or software when using this program.
  28. //****************************************************************************
  29. import java.awt.*;
  30.  
  31. class OptionsFrame extends Frame {
  32.     DigSim applet;
  33.     Scrollbar slider;
  34.  
  35.     static final int MIN_SPEED = 0;
  36.     static final int MAX_SPEED = 1000;
  37.     static final int PAGE_SIZE = (MAX_SPEED - MIN_SPEED) / 10;
  38.     Checkbox ShortCircuitCheckbox;
  39.     Checkbox LoopCheckbox;
  40.     Checkbox AnalyzerCheckbox;
  41.  
  42. //----------------------------------------------------------------------------
  43. // The constructor of the Options Frame
  44. //----------------------------------------------------------------------------
  45.     public OptionsFrame(DigSim app) {
  46.         super("DigSim Options");
  47.         applet = app;
  48.         setLayout (new GridLayout(5,1,5,5));
  49.  
  50.         int SliderVal = 1010 - applet.SimulationSpeed;
  51.  
  52.         slider = new Scrollbar(Scrollbar.HORIZONTAL, SliderVal, PAGE_SIZE, MIN_SPEED, MAX_SPEED);
  53.         Panel SliderPanel = new Panel();
  54.         SliderPanel.setLayout (new BorderLayout());
  55.         SliderPanel.add ("Center", new Label ("Simulation speed", Label.CENTER));
  56.         SliderPanel.add ("West", new Label ("min", Label.LEFT));
  57.         SliderPanel.add ("East", new Label ("max", Label.RIGHT));
  58.         SliderPanel.add ("South", slider);
  59.         add (SliderPanel);
  60.  
  61.         Panel CheckBoxPanel1 = new Panel();
  62.         CheckBoxPanel1.setLayout (new BorderLayout());
  63.         CheckBoxPanel1.add ("North", ShortCircuitCheckbox = new Checkbox("Stop simulate at short-circuit"));
  64.         if (applet.StopAtShortCircuit) ShortCircuitCheckbox.setState(true);
  65.         add (CheckBoxPanel1);
  66.  
  67.         Panel CheckBoxPanel2 = new Panel();
  68.         CheckBoxPanel2.setLayout (new BorderLayout());
  69.         CheckBoxPanel2.add ("North", LoopCheckbox = new Checkbox("Stop simulate at loop"));
  70.         if (applet.StopAtLoop) LoopCheckbox.setState(true);
  71.         add (CheckBoxPanel2);
  72.  
  73.         Panel CheckBoxPanel3 = new Panel();
  74.         CheckBoxPanel3.setLayout (new BorderLayout());
  75.         CheckBoxPanel3.add ("North", AnalyzerCheckbox = new Checkbox("Auto pop-up analyzer"));
  76.         if (applet.AnalyzerAutoPopUp) AnalyzerCheckbox.setState(true);
  77.         add (CheckBoxPanel3);
  78.  
  79.         Panel ButtonPanel = new Panel();
  80.         ButtonPanel.setLayout (new FlowLayout());
  81.         ButtonPanel.add (new Button ("OK"));
  82.         ButtonPanel.add (new Button ("Default"));
  83.         ButtonPanel.add (new Button ("Cancel"));
  84.         add (ButtonPanel);
  85.  
  86.         resize(275, 225);
  87.         show();
  88.         resize(275, 225);
  89.     }
  90.  
  91. //----------------------------------------------------------------------------
  92. // Handle all events in this option frame.
  93. //----------------------------------------------------------------------------
  94.     public boolean handleEvent(Event ev) {
  95.         if (ev.id == Event.WINDOW_DESTROY) {
  96.             hide();
  97.             applet.MyOptionsFrame = null;
  98.             return true;
  99.         }
  100.         return super.handleEvent(ev);
  101.     }
  102.  
  103. //----------------------------------------------------------------------------
  104. // Set all sliders and checkboxes to the default values
  105. //----------------------------------------------------------------------------
  106.     public void SetDefaultValues() {
  107.         slider.setValue(1000);
  108.         ShortCircuitCheckbox.setState(true);
  109.         LoopCheckbox.setState(true);
  110.         AnalyzerCheckbox.setState(true);
  111.         repaint();
  112.     }
  113.  
  114. //----------------------------------------------------------------------------
  115. // Set new values
  116. //----------------------------------------------------------------------------
  117.     public void SetNewValues() {
  118.         int NewSpeed = 1010 - slider.getValue();
  119.         applet.SimulationSpeed = NewSpeed;
  120.         applet.StopAtShortCircuit = ShortCircuitCheckbox.getState();
  121.         applet.StopAtLoop = LoopCheckbox.getState();
  122.         applet.AnalyzerAutoPopUp = AnalyzerCheckbox.getState();
  123.     }
  124.  
  125. //----------------------------------------------------------------------------
  126. // Handle all actions in this Frame
  127. //----------------------------------------------------------------------------
  128.     public boolean action(Event ev, Object arg) {
  129.         String FileName;
  130.         int s;
  131.  
  132.         if (ev.target instanceof Button) {
  133.             String label = (String)arg;
  134.             if (arg.equals ("Default")) {
  135.                 SetDefaultValues();
  136.                 return true;
  137.             } else if (arg.equals ("Cancel")) {
  138.                 hide();
  139.                 applet.MyOptionsFrame = null;
  140.                 return true;
  141.             } else if (arg.equals ("OK")) {
  142.                 SetNewValues();
  143.                 hide();
  144.                 applet.MyOptionsFrame = null;
  145.                 return true;
  146.             }
  147.         }
  148.         return false;
  149.     }
  150. }