home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / CFJava.cab / CFJavaRuntime.cab / netscape / application / ContainerView.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-10-01  |  9.2 KB  |  383 lines

  1. package netscape.application;
  2.  
  3. import netscape.util.ClassInfo;
  4. import netscape.util.CodingException;
  5. import netscape.util.Decoder;
  6. import netscape.util.Encoder;
  7. import netscape.util.InconsistencyException;
  8. import netscape.util.Vector;
  9.  
  10. public class ContainerView extends View implements FormElement {
  11.    private String title;
  12.    private Font titleFont;
  13.    private Image image;
  14.    private TextField titleField;
  15.    private Color backgroundColor;
  16.    private Color titleColor;
  17.    private Border border;
  18.    private int imageDisplayStyle;
  19.    private boolean transparent;
  20.    static Vector _fieldDescription = null;
  21.    static final String TITLE_KEY = "title";
  22.    static final String TITLE_FONT_KEY = "titleFont";
  23.    static final String BACKGROUND_COLOR_KEY = "backgroundColor";
  24.    static final String TITLE_COLOR_KEY = "titleColor";
  25.    static final String BORDER_KEY = "border";
  26.    static final String IMAGE_KEY = "image";
  27.    static final String IMAGE_DISPLAY_STYLE_KEY = "imageDisplayStyle";
  28.    static final String TRANSPARENT_KEY = "transparent";
  29.  
  30.    public ContainerView() {
  31.       this(0, 0, 0, 0);
  32.    }
  33.  
  34.    public ContainerView(Rect var1) {
  35.       this(var1.x, var1.y, var1.width, var1.height);
  36.    }
  37.  
  38.    public ContainerView(int var1, int var2, int var3, int var4) {
  39.       super(var1, var2, var3, var4);
  40.       this.title = "";
  41.       this.backgroundColor = Color.lightGray;
  42.       this.titleColor = Color.black;
  43.       this.border = BezelBorder.groovedBezel();
  44.       this.transparent = false;
  45.       this.titleField = new TextField(0, 0, 10, 18);
  46.       this.titleField.setBorder((Border)null);
  47.       this.titleField.setTransparent(true);
  48.       this.titleField.setEditable(false);
  49.       this.titleField.setVertResizeInstruction(4);
  50.       this.titleField.setHorizResizeInstruction(2);
  51.       this.titleField.setJustification(1);
  52.       this.titleFont = Font.fontNamed("Helvetica", 1, 12);
  53.       this.layoutParts();
  54.    }
  55.  
  56.    void layoutParts() {
  57.       this.titleField.removeFromSuperview();
  58.       this.titleField.setStringValue(this.title);
  59.       this.titleField.setFont(this.titleFont);
  60.       this.titleField.sizeToMinSize();
  61.       int var1;
  62.       int var2;
  63.       if (this.border != null) {
  64.          var1 = this.border.leftMargin();
  65.          var2 = this.border.rightMargin();
  66.       } else {
  67.          var1 = 0;
  68.          var2 = 0;
  69.       }
  70.  
  71.       if (!this.titleField.isEmpty()) {
  72.          this.titleField.moveTo(var1, 0);
  73.          this.titleField.sizeTo(((View)this).width() - var1 - var2, this.titleField.height());
  74.          ((View)this).addSubview(this.titleField);
  75.       }
  76.  
  77.    }
  78.  
  79.    public Size minSize() {
  80.       Size var1 = super.minSize();
  81.       Vector var2 = ((View)this).subviews();
  82.       int var3 = 0;
  83.       int var4 = 0;
  84.       if (var1.width == 0 && var1.height == 0) {
  85.          if (this.title != null && !"".equals(this.title)) {
  86.             this.titleField.setStringValue(this.title);
  87.             this.titleField.setFont(this.titleFont);
  88.             var3 = this.titleField.minSize().width + 6;
  89.             var4 = this.titleField.minSize().height + 2;
  90.          }
  91.  
  92.          this.layoutView(0, 0);
  93.          int var6 = var2.count();
  94.  
  95.          for(int var5 = 0; var5 < var6; ++var5) {
  96.             View var7 = (View)var2.elementAt(var5);
  97.             if (var7.bounds().maxX() > var3) {
  98.                var3 = var7.bounds().maxX();
  99.             }
  100.  
  101.             if (var7.bounds().maxY() > var4) {
  102.                var4 = var7.bounds().maxY();
  103.             }
  104.          }
  105.  
  106.          var1.width = var3;
  107.          var1.height = var4;
  108.          if (this.border != null) {
  109.             var1.width += this.border.rightMargin();
  110.             var1.height += this.border.bottomMargin();
  111.          }
  112.  
  113.          return var1;
  114.       } else {
  115.          return var1;
  116.       }
  117.    }
  118.  
  119.    public Rect interiorRect() {
  120.       Rect var1;
  121.       if (this.border != null) {
  122.          var1 = this.border.interiorRect(0, 0, ((View)this).width(), ((View)this).height());
  123.       } else {
  124.          var1 = new Rect(0, 0, ((View)this).width(), ((View)this).height());
  125.       }
  126.  
  127.       if (this.titleField._superview != null) {
  128.          var1.y += this.titleField.bounds.height;
  129.          var1.height -= this.titleField.bounds.height;
  130.       }
  131.  
  132.       return var1;
  133.    }
  134.  
  135.    public void setTitle(String var1) {
  136.       if (var1 != null) {
  137.          this.title = var1;
  138.       } else {
  139.          this.title = "";
  140.       }
  141.  
  142.       this.layoutParts();
  143.       ((View)this).setDirty(true);
  144.    }
  145.  
  146.    public String title() {
  147.       return this.title;
  148.    }
  149.  
  150.    public void setTitleColor(Color var1) {
  151.       if (var1 != null && !var1.equals(this.titleColor)) {
  152.          this.titleColor = var1;
  153.          this.titleField.setTextColor(var1);
  154.          ((View)this).setDirty(true);
  155.       }
  156.    }
  157.  
  158.    public Color titleColor() {
  159.       return this.titleColor;
  160.    }
  161.  
  162.    public void setTitleFont(Font var1) {
  163.       if (var1 == null) {
  164.          this.titleFont = Font.fontNamed("Helvetica", 1, 12);
  165.       } else {
  166.          this.titleFont = var1;
  167.       }
  168.  
  169.       this.layoutParts();
  170.       ((View)this).setDirty(true);
  171.    }
  172.  
  173.    public Font titleFont() {
  174.       return this.titleFont;
  175.    }
  176.  
  177.    public void setBackgroundColor(Color var1) {
  178.       this.backgroundColor = var1;
  179.       ((View)this).setDirty(true);
  180.    }
  181.  
  182.    public Color backgroundColor() {
  183.       return this.backgroundColor;
  184.    }
  185.  
  186.    public void setBorder(Border var1) {
  187.       if (var1 == null) {
  188.          var1 = EmptyBorder.emptyBorder();
  189.       }
  190.  
  191.       this.border = var1;
  192.       this.layoutParts();
  193.       ((View)this).setDirty(true);
  194.    }
  195.  
  196.    public Border border() {
  197.       return this.border;
  198.    }
  199.  
  200.    public void setImage(Image var1) {
  201.       this.image = var1;
  202.       ((View)this).setDirty(true);
  203.    }
  204.  
  205.    public Image image() {
  206.       return this.image;
  207.    }
  208.  
  209.    public void setImageDisplayStyle(int var1) {
  210.       if (var1 != 0 && var1 != 2 && var1 != 1) {
  211.          throw new InconsistencyException("Unknown image display style: " + var1);
  212.       } else {
  213.          this.imageDisplayStyle = var1;
  214.          ((View)this).setDirty(true);
  215.       }
  216.    }
  217.  
  218.    public int imageDisplayStyle() {
  219.       return this.imageDisplayStyle;
  220.    }
  221.  
  222.    public void setTransparent(boolean var1) {
  223.       this.transparent = var1;
  224.    }
  225.  
  226.    public boolean isTransparent() {
  227.       return this.transparent || !this.titleField.isEmpty();
  228.    }
  229.  
  230.    public void drawViewBackground(Graphics var1) {
  231.       if (!this.transparent && (this.image == null || this.imageDisplayStyle == 0 && this.backgroundColor != null)) {
  232.          Rect var2;
  233.          if (this.image == null) {
  234.             var2 = Rect.newRect();
  235.          } else {
  236.             var2 = Rect.newRect(0, 0, this.image.width(), this.image.height());
  237.          }
  238.  
  239.          if (!var2.contains(super.bounds)) {
  240.             var2.setBounds(0, 0, ((View)this).width(), ((View)this).height());
  241.             if (this.titleField.isInViewHierarchy()) {
  242.                var2.moveBy(0, this.titleField.bounds.height / 2);
  243.                var2.sizeBy(0, -this.titleField.bounds.height / 2);
  244.             }
  245.  
  246.             var1.setColor(this.backgroundColor);
  247.             var1.fillRect(var2);
  248.          }
  249.  
  250.          Rect.returnRect(var2);
  251.       }
  252.  
  253.       if (this.image != null) {
  254.          this.image.drawWithStyle(var1, 0, 0, ((View)this).width(), ((View)this).height(), this.imageDisplayStyle);
  255.       }
  256.  
  257.    }
  258.  
  259.    public void drawViewBorder(Graphics var1) {
  260.       if (this.border != null) {
  261.          Rect var2 = Rect.newRect(0, 0, ((View)this).width(), ((View)this).height());
  262.          if (this.titleField.isInViewHierarchy()) {
  263.             var2.moveBy(0, this.titleField.bounds.height / 2);
  264.             var2.sizeBy(0, -this.titleField.bounds.height / 2);
  265.          }
  266.  
  267.          if (!this.titleField.isInViewHierarchy()) {
  268.             this.border.drawInRect(var1, var2);
  269.             Rect.returnRect(var2);
  270.          } else {
  271.             Size var5 = this.titleField.minSize();
  272.             Rect var3 = Rect.newRect(this.titleField.bounds);
  273.             var3.x = var3.midX() - var5.width / 2 - 4;
  274.             var3.width = var5.width + 8;
  275.             Rect var4 = Rect.newRect(var2);
  276.             var4.width = var3.x - var2.x;
  277.             var1.pushState();
  278.             var1.setClipRect(var4);
  279.             this.border.drawInRect(var1, var2);
  280.             var1.popState();
  281.             var4.x = var3.maxX();
  282.             var4.width = var2.maxX() - var3.maxX();
  283.             var1.pushState();
  284.             var1.setClipRect(var4);
  285.             this.border.drawInRect(var1, var2);
  286.             var1.popState();
  287.             var4.x = var3.x;
  288.             var4.y = var3.maxY();
  289.             var4.width = var3.width;
  290.             var4.height = var2.maxY() - var3.maxY();
  291.             var1.pushState();
  292.             var1.setClipRect(var4);
  293.             this.border.drawInRect(var1, var2);
  294.             var1.popState();
  295.             Rect.returnRect(var4);
  296.             Rect.returnRect(var3);
  297.             Rect.returnRect(var2);
  298.          }
  299.       }
  300.    }
  301.  
  302.    public void drawView(Graphics var1) {
  303.       this.drawViewBackground(var1);
  304.    }
  305.  
  306.    public void drawSubviews(Graphics var1) {
  307.       super.drawSubviews(var1);
  308.       this.drawViewBorder(var1);
  309.    }
  310.  
  311.    public void layoutView(int var1, int var2) {
  312.       if (this.titleField.isInViewHierarchy()) {
  313.          this.titleField.removeFromSuperview();
  314.       }
  315.  
  316.       super.layoutView(var1, var2);
  317.       this.layoutParts();
  318.    }
  319.  
  320.    public void describeClassInfo(ClassInfo var1) {
  321.       super.describeClassInfo(var1);
  322.       var1.addClass("netscape.application.ContainerView", 1);
  323.       var1.addField("title", (byte)16);
  324.       var1.addField("titleFont", (byte)18);
  325.       var1.addField("backgroundColor", (byte)18);
  326.       var1.addField("titleColor", (byte)18);
  327.       var1.addField("image", (byte)18);
  328.       var1.addField("imageDisplayStyle", (byte)8);
  329.       var1.addField("border", (byte)18);
  330.       var1.addField("transparent", (byte)0);
  331.    }
  332.  
  333.    public void encode(Encoder var1) throws CodingException {
  334.       boolean var2 = false;
  335.       if (this.titleField.superview() != null) {
  336.          this.titleField.removeFromSuperview();
  337.          var2 = true;
  338.       }
  339.  
  340.       super.encode(var1);
  341.       var1.encodeString("title", this.title);
  342.       var1.encodeObject("titleFont", this.titleFont);
  343.       var1.encodeObject("backgroundColor", this.backgroundColor);
  344.       var1.encodeObject("titleColor", this.titleColor);
  345.       var1.encodeObject("image", this.image);
  346.       var1.encodeInt("imageDisplayStyle", this.imageDisplayStyle);
  347.       if (this.border instanceof EmptyBorder) {
  348.          var1.encodeObject("border", (Object)null);
  349.       } else {
  350.          var1.encodeObject("border", this.border);
  351.       }
  352.  
  353.       var1.encodeBoolean("transparent", this.transparent);
  354.       if (var2) {
  355.          ((View)this).addSubview(this.titleField);
  356.       }
  357.  
  358.    }
  359.  
  360.    public void decode(Decoder var1) throws CodingException {
  361.       super.decode(var1);
  362.       this.title = var1.decodeString("title");
  363.       this.setTitleFont((Font)var1.decodeObject("titleFont"));
  364.       this.backgroundColor = (Color)var1.decodeObject("backgroundColor");
  365.       this.setTitleColor((Color)var1.decodeObject("titleColor"));
  366.       this.image = (Image)var1.decodeObject("image");
  367.       this.imageDisplayStyle = var1.decodeInt("imageDisplayStyle");
  368.       this.setBorder((Border)var1.decodeObject("border"));
  369.       this.transparent = var1.decodeBoolean("transparent");
  370.    }
  371.  
  372.    public void finishDecoding() throws CodingException {
  373.       super.finishDecoding();
  374.       String var1 = this.title;
  375.       this.title = null;
  376.       this.setTitle(var1);
  377.    }
  378.  
  379.    public String formElementText() {
  380.       return this.titleField != null ? this.titleField.stringValue() : "";
  381.    }
  382. }
  383.