home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Instance.sea / XML Instance / Required / plugins / HTMLWindow.jar / horst / HRView.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-03-18  |  3.1 KB  |  85 lines

  1. package horst;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Rectangle;
  6. import java.awt.Shape;
  7.  
  8. public class HRView extends BlockView {
  9.    int m_size;
  10.    int m_borderSize;
  11.    int m_width;
  12.    boolean m_bNoShade;
  13.    float m_pctWidth;
  14.  
  15.    public HRView(View parent, Element e, HTMLPane container) {
  16.       super(parent, e, container);
  17.    }
  18.  
  19.    protected int getPreferredSpan(int axis) {
  20.       if (axis == 0) {
  21.          return this.m_size + 2 * this.m_borderSize + super.m_insets.top + super.m_insets.bottom;
  22.       } else {
  23.          return this.m_width > 0 ? this.m_width : this.m_size + 2 * this.m_borderSize;
  24.       }
  25.    }
  26.  
  27.    protected void init() {
  28.       this.m_borderSize = 1;
  29.       ((View)this).setInsets(2, 0, 2, 0);
  30.       this.m_bNoShade = super.m_elem.isAttributeDefined("noshade");
  31.       this.m_size = Utilities.setIntegerProperty(1, "size", super.m_elem.getAttributes());
  32.       this.m_pctWidth = Utilities.setPercentageProperty(-1.0F, "width", super.m_elem.getAttributes());
  33.       super.m_alignment = Utilities.setAlignmentProperty(false, 1, "align", super.m_elem.getAttributes());
  34.       this.m_width = Utilities.setIntegerProperty(-1, "width", super.m_elem.getAttributes());
  35.    }
  36.  
  37.    protected boolean isContainerView() {
  38.       return false;
  39.    }
  40.  
  41.    protected Rectangle layout(int x, int y, int width, LayoutInfo info) {
  42.       int viewWidth = Math.max(0, width - info.leftMargin - info.rightMargin);
  43.       if (this.m_width > 0 && this.m_width < viewWidth) {
  44.          viewWidth = this.m_width;
  45.       }
  46.  
  47.       super.m_bounds = new Rectangle(x, y, viewWidth, this.m_size + 2 * this.m_borderSize + super.m_insets.top + super.m_insets.bottom);
  48.       return super.m_bounds;
  49.    }
  50.  
  51.    public void paint(Graphics g, Shape alloc) {
  52.       Color oldColor = g.getColor();
  53.       Color c = Color.lightGray;
  54.       g.setColor(c);
  55.       int x = super.m_bounds.x;
  56.       int y = super.m_bounds.y + super.m_insets.top;
  57.       int w = super.m_bounds.width - 2 * this.m_borderSize;
  58.       int h = this.m_size + 1;
  59.       if (this.m_pctWidth > 0.0F && this.m_pctWidth <= 1.0F) {
  60.          w = (int)(this.m_pctWidth * (float)w);
  61.       } else if (this.m_width > 0) {
  62.          w = this.m_width;
  63.       }
  64.  
  65.       if (w > super.m_bounds.width) {
  66.          w = super.m_bounds.width;
  67.       }
  68.  
  69.       if (super.m_alignment == 1) {
  70.          x += (super.m_bounds.width - 2 * this.m_borderSize - w) / 2;
  71.       } else if (super.m_alignment == 2) {
  72.          x += super.m_bounds.width - 2 * this.m_borderSize - w;
  73.       }
  74.  
  75.       if (this.m_bNoShade) {
  76.          g.setColor(c.darker());
  77.          g.fillRect(x, y, w, this.m_size);
  78.       } else {
  79.          Utilities.drawBorder(g, new Rectangle(x, y, w + 1, h + 1));
  80.       }
  81.  
  82.       g.setColor(oldColor);
  83.    }
  84. }
  85.