home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / CFJava.cab / CFJavaRuntime.cab / allaire / controls / cfslider.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-03-31  |  5.7 KB  |  268 lines

  1. package allaire.controls;
  2.  
  3. import allaire.util.FontUtils;
  4. import allaire.util.netHelpers;
  5. import java.applet.Applet;
  6. import java.awt.Component;
  7. import java.awt.Dimension;
  8. import java.util.StringTokenizer;
  9. import netscape.application.AWTCompatibility;
  10. import netscape.application.Application;
  11. import netscape.application.Bitmap;
  12. import netscape.application.Border;
  13. import netscape.application.Color;
  14. import netscape.application.ExternalWindow;
  15. import netscape.application.Font;
  16. import netscape.application.Size;
  17. import netscape.application.Slider;
  18. import netscape.application.Target;
  19. import netscape.application.TextField;
  20.  
  21. public class cfslider extends Application implements Target {
  22.    public static final int HEIGHT = 0;
  23.    public static final int WIDTH = 1;
  24.    public static final int MINIMUM = 2;
  25.    public static final int MAXIMUM = 3;
  26.    public static final int VALUE = 4;
  27.    public static final int SCALE = 5;
  28.    public static final int LABEL_PREFIX = 6;
  29.    public static final int LABEL_SUFFIX = 7;
  30.    public static final int LABEL_DISPLAY = 8;
  31.    public static final int LABEL_STATIC = 9;
  32.    public static final int TEXT_COLOR = 10;
  33.    public static final int BACKGROUND = 11;
  34.    public static final int COLOR = 12;
  35.    public static final int FONT_SIZE = 13;
  36.    public static final int FONT_TYPE = 14;
  37.    public static final int FONT_WEIGHT = 15;
  38.    public static final int IMAGE_NAME = 16;
  39.    public static final int IMAGE_STYLE = 17;
  40.    public static final int MAX_PARAMETERS = 18;
  41.    private Slider slider;
  42.    private TextField statusField;
  43.    private String label_prefix;
  44.    private String label_suffix;
  45.    private boolean bStaticLabel;
  46.    private boolean bDisplayLabel;
  47.    private int iscale;
  48.  
  49.    public void sliderWasMoved(Object var1) {
  50.       if (!this.bStaticLabel) {
  51.          this.showStatus(this.label_prefix + this.slider.value() * this.iscale + this.label_suffix);
  52.       }
  53.  
  54.    }
  55.  
  56.    public static void main(String[] var0) {
  57.       cfslider var1 = new cfslider();
  58.       ExternalWindow var2 = new ExternalWindow();
  59.       ((Application)var1).setMainRootView(var2.rootView());
  60.       Size var3 = var2.windowSizeForContentSize(320, 200);
  61.       var2.sizeTo(var3.width, var3.height);
  62.       var2.show();
  63.       ((Application)var1).run();
  64.       System.exit(0);
  65.    }
  66.  
  67.    public void performCommand(String var1, Object var2) {
  68.       if ("sliderWasMoved".equals(var1) && this.bDisplayLabel) {
  69.          this.sliderWasMoved(var2);
  70.       }
  71.  
  72.    }
  73.  
  74.    public void showStatus(String var1) {
  75.       this.statusField.setStringValue(var1);
  76.    }
  77.  
  78.    public String cf_getSlider() {
  79.       return Integer.toString(this.slider.value() * this.iscale);
  80.    }
  81.  
  82.    public void init() {
  83.       super.init();
  84.       int var7 = 0;
  85.       Font var8 = Font.defaultFont();
  86.       String var10 = ((Application)this).parameterNamed("sliderparm");
  87.       String[] var11 = new String[18];
  88.       CFSliderApplet var12 = (CFSliderApplet)AWTCompatibility.awtApplet();
  89.       Dimension var13 = ((Component)var12).size();
  90.       if (var10 != null) {
  91.          var10 = netHelpers.URLDecode(var10);
  92.          StringTokenizer var14 = new StringTokenizer(var10, "\u0002");
  93.  
  94.          while(var14.hasMoreTokens()) {
  95.             for(int var15 = 0; var15 < 18 && var14.hasMoreTokens(); ++var15) {
  96.                String var16 = var14.nextToken();
  97.                if (var16.compareTo("\u0003") != 0) {
  98.                   var11[var15] = var16;
  99.                }
  100.             }
  101.          }
  102.       }
  103.  
  104.       int var5 = var13.width - 4;
  105.       int var4 = var13.height - 2;
  106.       int var1;
  107.       if (var11[2] == null) {
  108.          var1 = 0;
  109.       } else {
  110.          var1 = Integer.parseInt(var11[2]);
  111.       }
  112.  
  113.       int var2;
  114.       if (var11[3] == null) {
  115.          var2 = 100;
  116.       } else {
  117.          var2 = Integer.parseInt(var11[3]);
  118.       }
  119.  
  120.       int var3;
  121.       if (var11[4] == null) {
  122.          var3 = var1;
  123.          var11[4] = var11[2] == null ? "0" : var11[2];
  124.       } else {
  125.          var3 = Integer.parseInt(var11[4]);
  126.       }
  127.  
  128.       if (var11[5] == null) {
  129.          this.iscale = 1;
  130.       } else {
  131.          this.iscale = Integer.parseInt(var11[5]);
  132.          if (this.iscale < 1) {
  133.             this.iscale = 1;
  134.          }
  135.       }
  136.  
  137.       if (this.iscale > 1) {
  138.          var1 /= this.iscale;
  139.          var2 /= this.iscale;
  140.          var3 /= this.iscale;
  141.       }
  142.  
  143.       Color var9;
  144.       if (var11[11] == null) {
  145.          var9 = Color.lightGray;
  146.       } else {
  147.          Color var18 = Color.lightGray;
  148.          int var22 = FontUtils.getColorRGB(var11[11], var18.rgb());
  149.          var9 = new Color(var22);
  150.       }
  151.  
  152.       ((Application)this).mainRootView().setColor(var9);
  153.       if (var11[8] == null) {
  154.          this.bDisplayLabel = true;
  155.       } else if (var11[8].equalsIgnoreCase("no")) {
  156.          this.bDisplayLabel = false;
  157.       } else {
  158.          this.bDisplayLabel = true;
  159.       }
  160.  
  161.       if (this.bDisplayLabel) {
  162.          if (var11[9] == null) {
  163.             this.bStaticLabel = false;
  164.          } else if (var11[9].equalsIgnoreCase("yes")) {
  165.             this.bStaticLabel = true;
  166.          } else {
  167.             this.bStaticLabel = false;
  168.          }
  169.  
  170.          if (var11[14] == null) {
  171.             var11[14] = var8.name();
  172.          }
  173.  
  174.          int var6;
  175.          if (var11[13] == null) {
  176.             var6 = var8.size();
  177.          } else {
  178.             var6 = Integer.parseInt(var11[13]);
  179.          }
  180.  
  181.          if (var11[15] == null) {
  182.             var7 = var8.style();
  183.          } else {
  184.             if (var11[15].indexOf("BOLD") >= 0) {
  185.                ++var7;
  186.             }
  187.  
  188.             if (var11[15].indexOf("ITALIC") >= 0) {
  189.                var7 += 2;
  190.             }
  191.          }
  192.  
  193.          var4 /= 2;
  194.          if (var11[6] == null) {
  195.             this.label_prefix = "";
  196.          } else {
  197.             this.label_prefix = var11[6];
  198.          }
  199.  
  200.          if (var11[7] == null) {
  201.             this.label_suffix = "";
  202.          } else {
  203.             this.label_suffix = var11[7];
  204.          }
  205.  
  206.          this.statusField = new TextField(2, 1, var5, var4);
  207.          this.statusField.setBorder((Border)null);
  208.          this.statusField.setEditable(false);
  209.          this.statusField.setBackgroundColor(var9);
  210.          this.statusField.setFont(Font.fontNamed(var11[14], var7, var6));
  211.          this.statusField.setBuffered(true);
  212.          if (this.bStaticLabel) {
  213.             this.statusField.setStringValue(this.label_prefix + this.label_suffix);
  214.          } else {
  215.             this.statusField.setStringValue(this.label_prefix + var11[4] + this.label_suffix);
  216.          }
  217.  
  218.          this.statusField.setHorizResizeInstruction(2);
  219.          this.statusField.setVertResizeInstruction(4);
  220.          if (var11[10] != null) {
  221.             Color var19 = Color.black;
  222.             this.statusField.setTextColor(new Color(FontUtils.getColorRGB(var11[10], var19.rgb())));
  223.          }
  224.  
  225.          ((Application)this).mainRootView().addSubview(this.statusField);
  226.       } else {
  227.          this.bStaticLabel = true;
  228.       }
  229.  
  230.       this.slider = new Slider(2, this.bDisplayLabel ? var4 + 1 : 1, var5, var4);
  231.       this.slider.setLimits(var1, var2);
  232.       this.slider.setTarget(this);
  233.       this.slider.setCommand("sliderWasMoved");
  234.       this.slider.setBuffered(true);
  235.       this.slider.setHorizResizeInstruction(2);
  236.       this.slider.setVertResizeInstruction(4);
  237.       this.slider.setValue(var3);
  238.       this.slider.setGrooveHeight(var4 * 9 / 20);
  239.       this.slider.setKnobHeight(var4 * 7 / 10);
  240.       if (var11[16] != null) {
  241.          new Bitmap();
  242.          Bitmap var20 = Bitmap.bitmapNamed(var11[16]);
  243.          if (var20 != null) {
  244.             var11[12] = null;
  245.             this.slider.setImage(var20);
  246.             if (var11[17] != null) {
  247.                if (var11[17].equalsIgnoreCase("centered")) {
  248.                   this.slider.setImageDisplayStyle(0);
  249.                } else if (var11[17].equalsIgnoreCase("tiled")) {
  250.                   this.slider.setImageDisplayStyle(2);
  251.                } else {
  252.                   this.slider.setImageDisplayStyle(1);
  253.                }
  254.             }
  255.          }
  256.       }
  257.  
  258.       if (var11[12] != null) {
  259.          Color var21 = Color.darkGray;
  260.          this.slider.setBackgroundColor(new Color(FontUtils.getColorRGB(var11[12], var21.rgb())));
  261.       }
  262.  
  263.       ((Application)this).mainRootView().addSubview(this.slider);
  264.       var12.m_sliderControl = this;
  265.       ((Applet)var12).showStatus("");
  266.    }
  267. }
  268.