home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- import netscape.util.ClassInfo;
- import netscape.util.CodingException;
- import netscape.util.Decoder;
- import netscape.util.Encoder;
- import netscape.util.InconsistencyException;
- import netscape.util.Vector;
-
- public class ContainerView extends View implements FormElement {
- private String title;
- private Font titleFont;
- private Image image;
- private TextField titleField;
- private Color backgroundColor;
- private Color titleColor;
- private Border border;
- private int imageDisplayStyle;
- private boolean transparent;
- static Vector _fieldDescription = null;
- static final String TITLE_KEY = "title";
- static final String TITLE_FONT_KEY = "titleFont";
- static final String BACKGROUND_COLOR_KEY = "backgroundColor";
- static final String TITLE_COLOR_KEY = "titleColor";
- static final String BORDER_KEY = "border";
- static final String IMAGE_KEY = "image";
- static final String IMAGE_DISPLAY_STYLE_KEY = "imageDisplayStyle";
- static final String TRANSPARENT_KEY = "transparent";
-
- public ContainerView() {
- this(0, 0, 0, 0);
- }
-
- public ContainerView(Rect var1) {
- this(var1.x, var1.y, var1.width, var1.height);
- }
-
- public ContainerView(int var1, int var2, int var3, int var4) {
- super(var1, var2, var3, var4);
- this.title = "";
- this.backgroundColor = Color.lightGray;
- this.titleColor = Color.black;
- this.border = BezelBorder.groovedBezel();
- this.transparent = false;
- this.titleField = new TextField(0, 0, 10, 18);
- this.titleField.setBorder((Border)null);
- this.titleField.setTransparent(true);
- this.titleField.setEditable(false);
- this.titleField.setVertResizeInstruction(4);
- this.titleField.setHorizResizeInstruction(2);
- this.titleField.setJustification(1);
- this.titleFont = Font.fontNamed("Helvetica", 1, 12);
- this.layoutParts();
- }
-
- void layoutParts() {
- this.titleField.removeFromSuperview();
- this.titleField.setStringValue(this.title);
- this.titleField.setFont(this.titleFont);
- this.titleField.sizeToMinSize();
- int var1;
- int var2;
- if (this.border != null) {
- var1 = this.border.leftMargin();
- var2 = this.border.rightMargin();
- } else {
- var1 = 0;
- var2 = 0;
- }
-
- if (!this.titleField.isEmpty()) {
- this.titleField.moveTo(var1, 0);
- this.titleField.sizeTo(((View)this).width() - var1 - var2, this.titleField.height());
- ((View)this).addSubview(this.titleField);
- }
-
- }
-
- public Size minSize() {
- Size var1 = super.minSize();
- Vector var2 = ((View)this).subviews();
- int var3 = 0;
- int var4 = 0;
- if (var1.width == 0 && var1.height == 0) {
- if (this.title != null && !"".equals(this.title)) {
- this.titleField.setStringValue(this.title);
- this.titleField.setFont(this.titleFont);
- var3 = this.titleField.minSize().width + 6;
- var4 = this.titleField.minSize().height + 2;
- }
-
- this.layoutView(0, 0);
- int var6 = var2.count();
-
- for(int var5 = 0; var5 < var6; ++var5) {
- View var7 = (View)var2.elementAt(var5);
- if (var7.bounds().maxX() > var3) {
- var3 = var7.bounds().maxX();
- }
-
- if (var7.bounds().maxY() > var4) {
- var4 = var7.bounds().maxY();
- }
- }
-
- var1.width = var3;
- var1.height = var4;
- if (this.border != null) {
- var1.width += this.border.rightMargin();
- var1.height += this.border.bottomMargin();
- }
-
- return var1;
- } else {
- return var1;
- }
- }
-
- public Rect interiorRect() {
- Rect var1;
- if (this.border != null) {
- var1 = this.border.interiorRect(0, 0, ((View)this).width(), ((View)this).height());
- } else {
- var1 = new Rect(0, 0, ((View)this).width(), ((View)this).height());
- }
-
- if (this.titleField._superview != null) {
- var1.y += this.titleField.bounds.height;
- var1.height -= this.titleField.bounds.height;
- }
-
- return var1;
- }
-
- public void setTitle(String var1) {
- if (var1 != null) {
- this.title = var1;
- } else {
- this.title = "";
- }
-
- this.layoutParts();
- ((View)this).setDirty(true);
- }
-
- public String title() {
- return this.title;
- }
-
- public void setTitleColor(Color var1) {
- if (var1 != null && !var1.equals(this.titleColor)) {
- this.titleColor = var1;
- this.titleField.setTextColor(var1);
- ((View)this).setDirty(true);
- }
- }
-
- public Color titleColor() {
- return this.titleColor;
- }
-
- public void setTitleFont(Font var1) {
- if (var1 == null) {
- this.titleFont = Font.fontNamed("Helvetica", 1, 12);
- } else {
- this.titleFont = var1;
- }
-
- this.layoutParts();
- ((View)this).setDirty(true);
- }
-
- public Font titleFont() {
- return this.titleFont;
- }
-
- public void setBackgroundColor(Color var1) {
- this.backgroundColor = var1;
- ((View)this).setDirty(true);
- }
-
- public Color backgroundColor() {
- return this.backgroundColor;
- }
-
- public void setBorder(Border var1) {
- if (var1 == null) {
- var1 = EmptyBorder.emptyBorder();
- }
-
- this.border = var1;
- this.layoutParts();
- ((View)this).setDirty(true);
- }
-
- public Border border() {
- return this.border;
- }
-
- public void setImage(Image var1) {
- this.image = var1;
- ((View)this).setDirty(true);
- }
-
- public Image image() {
- return this.image;
- }
-
- public void setImageDisplayStyle(int var1) {
- if (var1 != 0 && var1 != 2 && var1 != 1) {
- throw new InconsistencyException("Unknown image display style: " + var1);
- } else {
- this.imageDisplayStyle = var1;
- ((View)this).setDirty(true);
- }
- }
-
- public int imageDisplayStyle() {
- return this.imageDisplayStyle;
- }
-
- public void setTransparent(boolean var1) {
- this.transparent = var1;
- }
-
- public boolean isTransparent() {
- return this.transparent || !this.titleField.isEmpty();
- }
-
- public void drawViewBackground(Graphics var1) {
- if (!this.transparent && (this.image == null || this.imageDisplayStyle == 0 && this.backgroundColor != null)) {
- Rect var2;
- if (this.image == null) {
- var2 = Rect.newRect();
- } else {
- var2 = Rect.newRect(0, 0, this.image.width(), this.image.height());
- }
-
- if (!var2.contains(super.bounds)) {
- var2.setBounds(0, 0, ((View)this).width(), ((View)this).height());
- if (this.titleField.isInViewHierarchy()) {
- var2.moveBy(0, this.titleField.bounds.height / 2);
- var2.sizeBy(0, -this.titleField.bounds.height / 2);
- }
-
- var1.setColor(this.backgroundColor);
- var1.fillRect(var2);
- }
-
- Rect.returnRect(var2);
- }
-
- if (this.image != null) {
- this.image.drawWithStyle(var1, 0, 0, ((View)this).width(), ((View)this).height(), this.imageDisplayStyle);
- }
-
- }
-
- public void drawViewBorder(Graphics var1) {
- if (this.border != null) {
- Rect var2 = Rect.newRect(0, 0, ((View)this).width(), ((View)this).height());
- if (this.titleField.isInViewHierarchy()) {
- var2.moveBy(0, this.titleField.bounds.height / 2);
- var2.sizeBy(0, -this.titleField.bounds.height / 2);
- }
-
- if (!this.titleField.isInViewHierarchy()) {
- this.border.drawInRect(var1, var2);
- Rect.returnRect(var2);
- } else {
- Size var5 = this.titleField.minSize();
- Rect var3 = Rect.newRect(this.titleField.bounds);
- var3.x = var3.midX() - var5.width / 2 - 4;
- var3.width = var5.width + 8;
- Rect var4 = Rect.newRect(var2);
- var4.width = var3.x - var2.x;
- var1.pushState();
- var1.setClipRect(var4);
- this.border.drawInRect(var1, var2);
- var1.popState();
- var4.x = var3.maxX();
- var4.width = var2.maxX() - var3.maxX();
- var1.pushState();
- var1.setClipRect(var4);
- this.border.drawInRect(var1, var2);
- var1.popState();
- var4.x = var3.x;
- var4.y = var3.maxY();
- var4.width = var3.width;
- var4.height = var2.maxY() - var3.maxY();
- var1.pushState();
- var1.setClipRect(var4);
- this.border.drawInRect(var1, var2);
- var1.popState();
- Rect.returnRect(var4);
- Rect.returnRect(var3);
- Rect.returnRect(var2);
- }
- }
- }
-
- public void drawView(Graphics var1) {
- this.drawViewBackground(var1);
- }
-
- public void drawSubviews(Graphics var1) {
- super.drawSubviews(var1);
- this.drawViewBorder(var1);
- }
-
- public void layoutView(int var1, int var2) {
- if (this.titleField.isInViewHierarchy()) {
- this.titleField.removeFromSuperview();
- }
-
- super.layoutView(var1, var2);
- this.layoutParts();
- }
-
- public void describeClassInfo(ClassInfo var1) {
- super.describeClassInfo(var1);
- var1.addClass("netscape.application.ContainerView", 1);
- var1.addField("title", (byte)16);
- var1.addField("titleFont", (byte)18);
- var1.addField("backgroundColor", (byte)18);
- var1.addField("titleColor", (byte)18);
- var1.addField("image", (byte)18);
- var1.addField("imageDisplayStyle", (byte)8);
- var1.addField("border", (byte)18);
- var1.addField("transparent", (byte)0);
- }
-
- public void encode(Encoder var1) throws CodingException {
- boolean var2 = false;
- if (this.titleField.superview() != null) {
- this.titleField.removeFromSuperview();
- var2 = true;
- }
-
- super.encode(var1);
- var1.encodeString("title", this.title);
- var1.encodeObject("titleFont", this.titleFont);
- var1.encodeObject("backgroundColor", this.backgroundColor);
- var1.encodeObject("titleColor", this.titleColor);
- var1.encodeObject("image", this.image);
- var1.encodeInt("imageDisplayStyle", this.imageDisplayStyle);
- if (this.border instanceof EmptyBorder) {
- var1.encodeObject("border", (Object)null);
- } else {
- var1.encodeObject("border", this.border);
- }
-
- var1.encodeBoolean("transparent", this.transparent);
- if (var2) {
- ((View)this).addSubview(this.titleField);
- }
-
- }
-
- public void decode(Decoder var1) throws CodingException {
- super.decode(var1);
- this.title = var1.decodeString("title");
- this.setTitleFont((Font)var1.decodeObject("titleFont"));
- this.backgroundColor = (Color)var1.decodeObject("backgroundColor");
- this.setTitleColor((Color)var1.decodeObject("titleColor"));
- this.image = (Image)var1.decodeObject("image");
- this.imageDisplayStyle = var1.decodeInt("imageDisplayStyle");
- this.setBorder((Border)var1.decodeObject("border"));
- this.transparent = var1.decodeBoolean("transparent");
- }
-
- public void finishDecoding() throws CodingException {
- super.finishDecoding();
- String var1 = this.title;
- this.title = null;
- this.setTitle(var1);
- }
-
- public String formElementText() {
- return this.titleField != null ? this.titleField.stringValue() : "";
- }
- }
-