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.Vector;
-
- public class ScrollGroup extends View implements ScrollBarOwner {
- ScrollView scrollView;
- ScrollBar vertScrollBar;
- ScrollBar horizScrollBar;
- Border border;
- Border interiorBorder;
- Color cornerColor;
- int horizScrollDisplay;
- int vertScrollDisplay;
- private boolean ignoreScrollBars;
- private static final boolean debugScrollers = false;
- public static final int NEVER_DISPLAY = 0;
- public static final int ALWAYS_DISPLAY = 1;
- public static final int AS_NEEDED_DISPLAY = 2;
- static final String SCROLLVIEW_KEY = "scrollView";
- static final String VERTSCROLLBAR_KEY = "vertScrollBar";
- static final String HORIZSCROLLBAR_KEY = "horizScrollBar";
- static final String BORDER_KEY = "border";
- static final String HORIZDISPLAY_KEY = "horizScrollDisplay";
- static final String VERTDISPLAY_KEY = "vertScrollDisplay";
- static final String CORNER_COLOR_KEY = "cornerColor";
-
- public ScrollGroup() {
- this(0, 0, 0, 0);
- }
-
- public ScrollGroup(Rect var1) {
- this(var1.x, var1.y, var1.width, var1.height);
- }
-
- public ScrollGroup(int var1, int var2, int var3, int var4) {
- super(var1, var2, var3, var4);
- this.border = EmptyBorder.emptyBorder();
- this.interiorBorder = new ScrollViewLineBorder();
- this.scrollView = this.createScrollView();
- ((View)this).addSubview(this.scrollView);
- this.horizScrollBar = this.createScrollBar(true);
- this.horizScrollBar.setScrollableObject(this.scrollView);
- this.horizScrollBar.setScrollBarOwner(this);
- this.scrollView.addScrollBar(this.horizScrollBar);
- ((View)this).addSubview(this.horizScrollBar);
- this.vertScrollBar = this.createScrollBar(false);
- this.vertScrollBar.setScrollableObject(this.scrollView);
- this.vertScrollBar.setScrollBarOwner(this);
- this.scrollView.addScrollBar(this.vertScrollBar);
- ((View)this).addSubview(this.vertScrollBar);
- this.ignoreScrollBars = false;
- this.setCornerColor(Color.lightGray);
- this.layoutView(0, 0);
- }
-
- public Size minSize() {
- Size var1 = super.minSize();
- if (var1 == null || var1.width == 0 && var1.height == 0) {
- if (this.vertScrollDisplay == 0 && this.horizScrollDisplay == 0) {
- return new Size(this.border.widthMargin(), this.border.heightMargin());
- } else if (this.vertScrollDisplay != 0 && this.horizScrollDisplay != 0) {
- return new Size(this.border.widthMargin() + this.horizScrollBar().minSize().width + this.vertScrollBar().minSize().width, this.border.heightMargin() + this.horizScrollBar().minSize().height + this.vertScrollBar().minSize().height);
- } else if (this.horizScrollDisplay != 1 && this.horizScrollDisplay != 2) {
- return this.vertScrollDisplay != 1 && this.vertScrollDisplay != 2 ? super.minSize() : new Size(this.border.widthMargin() + this.vertScrollBar().minSize().width * 2, this.border.heightMargin() + this.vertScrollBar().minSize().height);
- } else {
- return new Size(this.border.widthMargin() + this.horizScrollBar().minSize().width, this.border.heightMargin() + this.horizScrollBar().minSize().height * 2);
- }
- } else {
- return var1;
- }
- }
-
- public boolean isTransparent() {
- Vector var1 = ((View)this).subviews();
- int var3 = var1.count();
-
- for(int var2 = 0; var2 < var3; ++var2) {
- if (((View)((View)this).subviews().elementAt(var2)).isTransparent()) {
- return true;
- }
- }
-
- return false;
- }
-
- public void setBorder(Border var1) {
- if (var1 == null) {
- var1 = EmptyBorder.emptyBorder();
- }
-
- this.interiorBorder = var1;
- this.layoutView(0, 0);
- }
-
- public Border border() {
- return this.interiorBorder;
- }
-
- protected ScrollView createScrollView() {
- return new ScrollView(0, 0, super.bounds.width, super.bounds.height);
- }
-
- public ScrollView scrollView() {
- return this.scrollView;
- }
-
- protected ScrollBar createScrollBar(boolean var1) {
- ScrollBar var2;
- if (var1) {
- var2 = new ScrollBar(0, 0, super.bounds.width, 1, 0);
- } else {
- var2 = new ScrollBar(0, 0, 1, super.bounds.height, 1);
- }
-
- return var2;
- }
-
- public void setHasVertScrollBar(boolean var1) {
- if (var1) {
- this.setVertScrollBarDisplay(1);
- } else {
- this.setVertScrollBarDisplay(0);
- }
- }
-
- public boolean hasVertScrollBar() {
- return this.vertScrollDisplay == 1;
- }
-
- public void setVertScrollBarDisplay(int var1) {
- this.vertScrollDisplay = var1;
- if (this.vertScrollBar == null) {
- this.vertScrollBar = this.createScrollBar(false);
- this.vertScrollBar.setScrollableObject(this.scrollView);
- this.vertScrollBar.setScrollBarOwner(this);
- this.scrollView.addScrollBar(this.vertScrollBar);
- ((View)this).addSubview(this.vertScrollBar);
- }
-
- this.layoutView(0, 0);
- }
-
- public int vertScrollBarDisplay() {
- return this.vertScrollDisplay;
- }
-
- public ScrollBar vertScrollBar() {
- return this.vertScrollBar;
- }
-
- public void setHasHorizScrollBar(boolean var1) {
- if (var1) {
- this.setHorizScrollBarDisplay(1);
- } else {
- this.setHorizScrollBarDisplay(0);
- }
- }
-
- public boolean hasHorizScrollBar() {
- return this.horizScrollDisplay == 1;
- }
-
- public void setHorizScrollBarDisplay(int var1) {
- this.horizScrollDisplay = var1;
- if (this.horizScrollBar == null) {
- this.horizScrollBar = this.createScrollBar(true);
- this.horizScrollBar.setScrollableObject(this.scrollView);
- this.horizScrollBar.setScrollBarOwner(this);
- this.scrollView.addScrollBar(this.horizScrollBar);
- ((View)this).addSubview(this.horizScrollBar);
- }
-
- this.layoutView(0, 0);
- }
-
- public int horizScrollBarDisplay() {
- return this.horizScrollDisplay;
- }
-
- public ScrollBar horizScrollBar() {
- return this.horizScrollBar;
- }
-
- private void putParts() {
- this.horizScrollBar.removeFromSuperview();
- this.vertScrollBar.removeFromSuperview();
- if (this.scrollView != null) {
- Rect var5 = new Rect(0, 0, 0, 0);
- if (this.horizScrollBar != null && this.horizScrollBar.scrollableObject() != null) {
- var5.width = this.horizScrollBar.scrollableObject().lengthOfContentViewForAxis(0);
- } else if (this.scrollView.contentView != null) {
- var5.width = this.scrollView.contentView.bounds.width;
- }
-
- if (this.vertScrollBar != null && this.vertScrollBar.scrollableObject() != null) {
- var5.height = this.vertScrollBar.scrollableObject().lengthOfContentViewForAxis(1);
- } else if (this.scrollView.contentView != null) {
- var5.height = this.scrollView.contentView.bounds.height;
- }
-
- int var1 = this.border.leftMargin() + this.interiorBorder.leftMargin();
- int var2 = this.border.topMargin() + this.interiorBorder.topMargin();
- int var3 = super.bounds.width - this.border.widthMargin() - this.interiorBorder.widthMargin();
- int var4 = super.bounds.height - this.border.heightMargin() - this.interiorBorder.heightMargin();
- this.ignoreScrollBars = true;
- this.scrollView.moveTo(var1, var2);
- this.scrollView.sizeTo(var3, var4);
- this.vertScrollBar.moveTo(var1 + var3 - this.vertScrollBar.bounds.width, var2);
- this.vertScrollBar.sizeTo(this.vertScrollBar.bounds.width, var4);
- this.horizScrollBar.moveTo(var1, var2 + var4 - this.horizScrollBar.bounds.height);
- this.horizScrollBar.sizeTo(var3, this.horizScrollBar.bounds.height);
- this.ignoreScrollBars = false;
- if ((this.vertScrollDisplay != 1 || this.horizScrollDisplay != 1) && (this.vertScrollDisplay != 2 || this.horizScrollDisplay != 2 || this.scrollView.bounds.width >= var5.width || this.scrollView.bounds.height >= var5.height)) {
- if (this.vertScrollDisplay == 1 || this.vertScrollDisplay == 2 && this.scrollView.bounds.height < var5.height) {
- if (this.horizScrollDisplay != 1 && (this.horizScrollDisplay != 2 || this.scrollView.bounds.width - var5.width >= this.vertScrollBar.bounds.width)) {
- this.horizScrollBar.removeFromSuperview();
- this.ignoreScrollBars = true;
- this.scrollView.moveTo(var1, var2);
- this.scrollView.sizeTo(var3 - this.vertScrollBar.bounds.width, var4);
- this.vertScrollBar.moveTo(super.bounds.width - this.border.rightMargin() - this.vertScrollBar.bounds.width, this.border.topMargin());
- this.vertScrollBar.sizeTo(this.vertScrollBar.bounds.width, super.bounds.height - this.border.heightMargin());
- ((View)this).addSubview(this.vertScrollBar);
- this.ignoreScrollBars = false;
- } else {
- this.setBothScrollersOn();
- }
- } else if (this.vertScrollDisplay == 2 && this.horizScrollDisplay == 2 && this.scrollView.bounds.height == var5.height) {
- this.ignoreScrollBars = true;
- this.vertScrollBar.removeFromSuperview();
- this.horizScrollBar.removeFromSuperview();
- this.scrollView.moveTo(var1, var2);
- this.scrollView.sizeTo(var3, var4);
- this.ignoreScrollBars = false;
- } else if (this.horizScrollDisplay == 1 || this.horizScrollDisplay == 2 && this.scrollView.bounds.width < var5.width) {
- if (this.vertScrollDisplay != 1 && (this.vertScrollDisplay != 2 || this.scrollView.bounds.height - var5.height >= this.horizScrollBar.bounds.height)) {
- this.vertScrollBar.removeFromSuperview();
- this.ignoreScrollBars = true;
- this.scrollView.moveTo(var1, var2);
- this.scrollView.sizeTo(var3, var4 - this.horizScrollBar.bounds.height);
- this.horizScrollBar.moveTo(this.border.leftMargin(), super.bounds.height - this.border.bottomMargin() - this.horizScrollBar.bounds.height);
- this.horizScrollBar.sizeTo(super.bounds.width - this.border.widthMargin(), this.horizScrollBar.bounds.height);
- ((View)this).addSubview(this.horizScrollBar);
- this.ignoreScrollBars = false;
- } else {
- this.setBothScrollersOn();
- }
- } else if (this.horizScrollDisplay == 2 && this.vertScrollDisplay == 2 && this.scrollView.bounds.width == var5.width) {
- this.ignoreScrollBars = true;
- this.horizScrollBar.removeFromSuperview();
- this.vertScrollBar.removeFromSuperview();
- this.scrollView.moveTo(var1, var2);
- this.scrollView.sizeTo(var3, var4);
- this.ignoreScrollBars = false;
- }
- } else {
- this.setBothScrollersOn();
- }
- }
- }
-
- void setBothScrollersOn() {
- int var1 = this.border.leftMargin() + this.interiorBorder.leftMargin();
- int var2 = this.border.topMargin() + this.interiorBorder.topMargin();
- int var3 = super.bounds.width - this.border.widthMargin() - this.interiorBorder.widthMargin();
- int var4 = super.bounds.height - this.border.heightMargin() - this.interiorBorder.heightMargin();
- this.ignoreScrollBars = true;
- this.scrollView.moveTo(var1, var2);
- this.scrollView.sizeTo(var3 - this.vertScrollBar.bounds.width, var4 - this.horizScrollBar.bounds.height);
- this.horizScrollBar.moveTo(this.border.leftMargin(), super.bounds.height - this.border.bottomMargin() - this.horizScrollBar.bounds.height);
- this.horizScrollBar.sizeTo(super.bounds.width - this.border.widthMargin() - this.vertScrollBar.bounds.width + 2, this.horizScrollBar.bounds.height);
- ((View)this).addSubview(this.horizScrollBar);
- this.vertScrollBar.moveTo(super.bounds.width - this.border.rightMargin() - this.vertScrollBar.bounds.width, this.border.topMargin());
- this.vertScrollBar.sizeTo(this.vertScrollBar.bounds.width, super.bounds.height - this.border.heightMargin() - this.horizScrollBar.bounds.height + 2);
- ((View)this).addSubview(this.vertScrollBar);
- this.ignoreScrollBars = false;
- }
-
- public void drawView(Graphics var1) {
- this.border.drawInRect(var1, 0, 0, super.bounds.width, super.bounds.height);
- this.interiorBorder.drawInRect(var1, this.border.leftMargin(), this.border.topMargin(), this.scrollView.bounds.width + this.interiorBorder.widthMargin(), this.scrollView.bounds.height + this.interiorBorder.heightMargin());
- if (this.cornerColor != null && this.horizScrollBarIsVisible() && this.vertScrollBarIsVisible()) {
- var1.setColor(this.cornerColor);
- var1.fillRect(this.horizScrollBar.bounds.maxX(), this.vertScrollBar.bounds.maxY(), this.vertScrollBar.bounds.width - 2, this.horizScrollBar.bounds.height - 2);
- }
-
- }
-
- public void drawContents() {
- this.scrollView.setDirty(true);
- }
-
- public void drawSubviews(Graphics var1) {
- super.drawSubviews(var1);
- this.drawView(var1);
- }
-
- public void setContentView(View var1) {
- this.scrollView.setContentView(var1);
- this.layoutView(0, 0);
- }
-
- public View contentView() {
- return this.scrollView.contentView();
- }
-
- public void setBackgroundColor(Color var1) {
- this.scrollView.setBackgroundColor(var1);
- }
-
- public void setCornerColor(Color var1) {
- this.cornerColor = var1;
- }
-
- public void describeClassInfo(ClassInfo var1) {
- super.describeClassInfo(var1);
- var1.addClass("netscape.application.ScrollGroup", 2);
- var1.addField("scrollView", (byte)18);
- var1.addField("vertScrollBar", (byte)18);
- var1.addField("horizScrollBar", (byte)18);
- var1.addField("border", (byte)18);
- var1.addField("horizScrollDisplay", (byte)8);
- var1.addField("vertScrollDisplay", (byte)8);
- var1.addField("cornerColor", (byte)18);
- }
-
- public void encode(Encoder var1) throws CodingException {
- super.encode(var1);
- var1.encodeObject("scrollView", this.scrollView);
- var1.encodeObject("vertScrollBar", this.vertScrollBar);
- var1.encodeObject("horizScrollBar", this.horizScrollBar);
- var1.encodeObject("border", this.interiorBorder);
- var1.encodeInt("horizScrollDisplay", this.horizScrollDisplay);
- var1.encodeInt("vertScrollDisplay", this.vertScrollDisplay);
- var1.encodeObject("cornerColor", this.cornerColor);
- }
-
- public void decode(Decoder var1) throws CodingException {
- int var2 = var1.versionForClassName("netscape.application.ScrollGroup");
- super.decode(var1);
- this.scrollView = (ScrollView)var1.decodeObject("scrollView");
- this.vertScrollBar = (ScrollBar)var1.decodeObject("vertScrollBar");
- this.horizScrollBar = (ScrollBar)var1.decodeObject("horizScrollBar");
- this.interiorBorder = (Border)var1.decodeObject("border");
- this.horizScrollDisplay = var1.decodeInt("horizScrollDisplay");
- this.vertScrollDisplay = var1.decodeInt("vertScrollDisplay");
- if (var2 >= 2) {
- this.cornerColor = (Color)var1.decodeObject("cornerColor");
- } else {
- this.cornerColor = Color.lightGray;
- }
- }
-
- public void scrollBarDidBecomeActive(ScrollBar var1) {
- if (!this.ignoreScrollBars) {
- if (var1 != this.horizScrollBar || this.horizScrollDisplay != 0) {
- if (var1 != this.vertScrollBar || this.vertScrollDisplay != 0) {
- this.layoutView(0, 0);
- }
- }
- }
- }
-
- public void scrollBarDidBecomeInactive(ScrollBar var1) {
- if (!this.ignoreScrollBars) {
- if (var1 != this.horizScrollBar || this.horizScrollDisplay != 0) {
- if (var1 != this.vertScrollBar || this.vertScrollDisplay != 0) {
- this.layoutView(0, 0);
- }
- }
- }
- }
-
- public void scrollBarWasEnabled(ScrollBar var1) {
- if (!this.ignoreScrollBars) {
- if (var1 != this.horizScrollBar || this.horizScrollDisplay != 0) {
- if (var1 != this.vertScrollBar || this.vertScrollDisplay != 0) {
- this.layoutView(0, 0);
- }
- }
- }
- }
-
- public void scrollBarWasDisabled(ScrollBar var1) {
- if (!this.ignoreScrollBars) {
- if (var1 != this.horizScrollBar || this.horizScrollDisplay != 0) {
- if (var1 != this.vertScrollBar || this.vertScrollDisplay != 0) {
- this.layoutView(0, 0);
- }
- }
- }
- }
-
- public boolean vertScrollBarIsVisible() {
- return this.vertScrollBar.isInViewHierarchy();
- }
-
- public boolean horizScrollBarIsVisible() {
- return this.horizScrollBar.isInViewHierarchy();
- }
-
- public void layoutView(int var1, int var2) {
- this.putParts();
- this.ignoreScrollBars = false;
- ((View)this).setDirty(true);
- }
- }
-