home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2002 June / INTERNET92.ISO / pc / software / windows / building / visual_dhtml / visualdhtmlwin9x_nt.exe / OCmltext.___ (.txt) < prev    next >
Encoding:
Java Class File  |  1998-05-10  |  8.5 KB  |  435 lines

  1. import java.awt.Color;
  2. import java.awt.Component;
  3. import java.awt.Container;
  4. import java.awt.Dimension;
  5. import java.awt.Event;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.LayoutManager;
  11. import java.awt.Panel;
  12. import java.awt.Scrollbar;
  13. import java.util.Vector;
  14.  
  15. class OCmltext extends Panel {
  16.    public int appWidth;
  17.    public int appHeight;
  18.    public Color bgColor = new Color(153, 153, 153);
  19.    private Image off;
  20.    private Graphics g_off;
  21.    // $FF: renamed from: fm java.awt.FontMetrics
  22.    private FontMetrics field_0;
  23.    // $FF: renamed from: ds java.awt.Dimension
  24.    private Dimension field_1;
  25.    private int appx;
  26.    private int appy;
  27.    private boolean paint_called;
  28.    private boolean first_run = true;
  29.    private String[] def_pn;
  30.    private String[] def_pv;
  31.    private String[] spe_pn;
  32.    private Vector spe_pv;
  33.    private int desc_index;
  34.    private String[] m_desc;
  35.    private int[] m_align;
  36.    private int m_def_align;
  37.    private Color[] m_textcolor;
  38.    private Color m_def_textcolor;
  39.    private Font[] m_cur_font;
  40.    private Font m_font;
  41.    private int m_xoffset;
  42.    private Color m_bgcolor;
  43.    int num_descrips;
  44.    int sb_width;
  45.    // $FF: renamed from: sb java.awt.Scrollbar
  46.    Scrollbar field_2;
  47.    Scrollbar hsb;
  48.    int scroll_y;
  49.    int scroll_x;
  50.    int sb_linedist;
  51.    int hsb_linedist;
  52.    boolean first_sb_run;
  53.    boolean first_hsb_run;
  54.    boolean use_sb;
  55.    boolean use_hsb;
  56.    int last_scroll_y;
  57.    int last_scroll_x;
  58.    int sEdge;
  59.    int sbImgWidth;
  60.    int sbImgHeight;
  61.    int offimgx;
  62.    int offimgy;
  63.  
  64.    public void updateDisplay(int desci) {
  65.       this.desc_index = desci;
  66.       this.centerAppArea();
  67.    }
  68.  
  69.    private void initDefault() {
  70.       String param = this.getParameterDefault("font");
  71.       if (param != null) {
  72.          this.m_font = ocfontc.getFontSD(param, ",");
  73.       } else {
  74.          this.m_font = new Font("Helvetica", 0, 12);
  75.       }
  76.  
  77.       param = this.getParameterDefault("textcolor");
  78.       if (param != null) {
  79.          this.m_def_textcolor = occcolor.ConvertColor(param);
  80.       }
  81.  
  82.       param = this.getParameterDefault("bgcolor");
  83.       if (param != null) {
  84.          this.m_bgcolor = occcolor.ConvertColor(param);
  85.       }
  86.  
  87.       param = this.getParameterDefault("lrmargins");
  88.       if (param != null) {
  89.          this.m_xoffset = Integer.parseInt(param);
  90.       }
  91.  
  92.       param = this.getParameterDefault("halign");
  93.       if (param != null) {
  94.          this.m_def_align = Integer.parseInt(param);
  95.       }
  96.  
  97.    }
  98.  
  99.    public void reshape(int x, int y, int width, int height) {
  100.       if (width * height > 0) {
  101.          this.field_1 = new Dimension(width, height);
  102.          this.centerAppArea();
  103.          super.reshape(x, y, width, height);
  104.       }
  105.    }
  106.  
  107.    private void drawMessage() {
  108.       if (!this.first_run) {
  109.          this.g_off.setFont(this.m_cur_font[this.desc_index]);
  110.          this.field_0 = ((Component)this).getFontMetrics(this.m_cur_font[this.desc_index]);
  111.          int mx = this.sbImgWidth / 2 - this.field_0.stringWidth(this.m_desc[this.desc_index]) / 2;
  112.          int my = this.sbImgHeight / 2 + (this.field_0.getAscent() + this.field_0.getLeading()) / 2;
  113.          this.g_off.setColor(this.m_textcolor[this.desc_index]);
  114.          this.g_off.drawString(this.m_desc[this.desc_index], mx, my);
  115.          this.g_off = this.off.getGraphics();
  116.          this.paintIt();
  117.       }
  118.  
  119.    }
  120.  
  121.    private void centerAppArea() {
  122.       int sbx = 0;
  123.       int sby = 0;
  124.       if (this.appHeight > this.field_1.height) {
  125.          this.use_sb = true;
  126.          sby = this.sb_width;
  127.       } else {
  128.          this.use_sb = false;
  129.       }
  130.  
  131.       if (this.appWidth > this.field_1.width) {
  132.          this.use_hsb = true;
  133.          sbx = this.sb_width;
  134.       } else {
  135.          this.use_hsb = false;
  136.       }
  137.  
  138.       if (this.use_hsb) {
  139.          this.sbImgWidth = this.appWidth + this.sEdge * 2;
  140.       } else {
  141.          this.sbImgWidth = this.appWidth;
  142.       }
  143.  
  144.       if (this.use_sb) {
  145.          this.sbImgHeight = this.appHeight + this.sEdge * 2;
  146.       } else {
  147.          this.sbImgHeight = this.appHeight;
  148.       }
  149.  
  150.       this.offimgx = (this.field_1.width - (this.sbImgWidth - sbx)) / 2;
  151.       this.offimgy = (this.field_1.height - (this.sbImgHeight - sby)) / 2;
  152.       this.scroll_y = this.offimgy;
  153.       this.scroll_x = this.offimgx;
  154.       if (this.use_sb) {
  155.          this.scroll_y = this.last_scroll_y;
  156.       }
  157.  
  158.       if (this.use_hsb) {
  159.          this.scroll_x = this.last_scroll_x;
  160.       }
  161.  
  162.       this.first_run = true;
  163.       this.paintIt();
  164.    }
  165.  
  166.    private void paintIt() {
  167.       if (this.paint_called) {
  168.          Graphics g = ((Component)this).getGraphics();
  169.          if (this.first_run) {
  170.             ((Component)this).setBackground(this.bgColor);
  171.             if (this.field_1.width * this.field_1.height <= 0) {
  172.                return;
  173.             }
  174.  
  175.             this.off = ((Component)this).createImage(this.sbImgWidth, this.sbImgHeight);
  176.             this.g_off = this.off.getGraphics();
  177.             this.g_off.setColor(this.m_bgcolor);
  178.             this.g_off.fillRect(this.sEdge, this.sEdge, this.appWidth, this.appHeight);
  179.             this.first_run = false;
  180.             this.drawMessage();
  181.             if (this.first_sb_run) {
  182.                if (this.use_sb) {
  183.                   this.field_2 = new Scrollbar();
  184.                   if (this.use_sb && this.use_hsb) {
  185.                      this.field_2.reshape(this.field_1.width - this.sb_width, 0, this.sb_width, this.field_1.height - this.sb_width);
  186.                   } else {
  187.                      this.field_2.reshape(this.field_1.width - this.sb_width, 0, this.sb_width, this.field_1.height);
  188.                   }
  189.  
  190.                   this.field_2.setBackground(Color.gray);
  191.                   ((Container)this).add(this.field_2);
  192.                   this.first_sb_run = false;
  193.                }
  194.             } else if (!this.use_sb) {
  195.                ((Container)this).remove(this.field_2);
  196.                this.field_2 = null;
  197.                this.first_sb_run = true;
  198.             } else if (this.use_sb && this.use_hsb) {
  199.                this.field_2.reshape(this.field_1.width - this.sb_width, 0, this.sb_width, this.field_1.height - this.sb_width);
  200.             } else {
  201.                this.field_2.reshape(this.field_1.width - this.sb_width, 0, this.sb_width, this.field_1.height);
  202.             }
  203.  
  204.             if (this.use_sb) {
  205.                this.field_2.setValues(this.field_2.getValue(), 1, 0, this.sbImgHeight - this.field_1.height);
  206.             }
  207.  
  208.             if (this.first_hsb_run) {
  209.                if (this.use_hsb) {
  210.                   this.hsb = new Scrollbar(0);
  211.                   if (this.use_sb && this.use_hsb) {
  212.                      this.hsb.reshape(0, this.field_1.height - this.sb_width, this.field_1.width - this.sb_width, this.sb_width);
  213.                   } else {
  214.                      this.hsb.reshape(0, this.field_1.height - this.sb_width, this.field_1.width, this.sb_width);
  215.                   }
  216.  
  217.                   this.hsb.setBackground(Color.gray);
  218.                   ((Container)this).add(this.hsb);
  219.                   this.first_hsb_run = false;
  220.                }
  221.             } else if (!this.use_hsb) {
  222.                ((Container)this).remove(this.hsb);
  223.                this.hsb = null;
  224.                this.first_hsb_run = true;
  225.             } else if (this.use_sb && this.use_hsb) {
  226.                this.hsb.reshape(0, this.field_1.height - this.sb_width, this.field_1.width - this.sb_width, this.sb_width);
  227.             } else {
  228.                this.hsb.reshape(0, this.field_1.height - this.sb_width, this.field_1.width, this.sb_width);
  229.             }
  230.  
  231.             if (this.use_hsb) {
  232.                this.hsb.setValues(this.hsb.getValue(), 1, 0, this.sbImgWidth - this.field_1.width);
  233.                return;
  234.             }
  235.          } else {
  236.             g.drawImage(this.off, this.scroll_x, this.scroll_y, this);
  237.             if (this.use_sb && this.use_hsb) {
  238.                g.setColor(Color.lightGray);
  239.             } else {
  240.                g.setColor(new Color(153, 153, 153));
  241.             }
  242.  
  243.             g.fillRect(this.field_1.width - this.sb_width, this.field_1.height - this.sb_width, this.sb_width, this.sb_width);
  244.          }
  245.  
  246.       }
  247.    }
  248.  
  249.    private String getParameterDefault(String param) {
  250.       for(int i = 0; i < this.def_pn.length; ++i) {
  251.          if (this.def_pn[i].equals(param)) {
  252.             return this.def_pv[i];
  253.          }
  254.       }
  255.  
  256.       return null;
  257.    }
  258.  
  259.    public void initSpecifics() {
  260.       int i = 0;
  261.       this.num_descrips = this.spe_pv.size();
  262.       this.m_cur_font = new Font[this.num_descrips];
  263.       this.m_textcolor = new Color[this.num_descrips];
  264.       this.m_desc = new String[this.num_descrips];
  265.       this.m_align = new int[this.num_descrips];
  266.  
  267.       for(int var7 = 0; var7 < this.num_descrips; ++var7) {
  268.          String param = this.getParameterSpecific("desc", var7);
  269.          if (param != null) {
  270.             this.m_desc[var7] = param;
  271.          } else {
  272.             this.m_desc[var7] = " ";
  273.          }
  274.  
  275.          param = this.getParameterSpecific("font", var7);
  276.          if (param != null) {
  277.             this.m_cur_font[var7] = ocfontc.getFontSD(param, ",");
  278.          } else {
  279.             this.m_cur_font[var7] = this.m_font;
  280.          }
  281.  
  282.          param = this.getParameterSpecific("align", var7);
  283.          if (param != null) {
  284.             this.m_align[var7] = Integer.parseInt(param);
  285.          } else {
  286.             this.m_align[var7] = this.m_def_align;
  287.          }
  288.  
  289.          param = this.getParameterSpecific("textcolor", var7);
  290.          if (param != null) {
  291.             this.m_textcolor[var7] = occcolor.ConvertColor(param);
  292.          } else {
  293.             this.m_textcolor[var7] = this.m_def_textcolor;
  294.          }
  295.       }
  296.  
  297.    }
  298.  
  299.    public void resize(Dimension d) {
  300.       if (d.width * d.height > 0) {
  301.          this.field_1 = d;
  302.          this.centerAppArea();
  303.          super.resize(d);
  304.       }
  305.    }
  306.  
  307.    public void resize(int width, int height) {
  308.       if (width * height > 0) {
  309.          this.field_1 = new Dimension(width, height);
  310.          this.centerAppArea();
  311.          super.resize(width, height);
  312.       }
  313.    }
  314.  
  315.    public void addSpecifics(String[] pn, Vector pv) {
  316.       this.spe_pn = pn;
  317.       this.spe_pv = pv;
  318.       this.initSpecifics();
  319.    }
  320.  
  321.    public void setAppDimensions(int w, int h) {
  322.       if (w != this.appWidth || h != this.appHeight) {
  323.          this.appWidth = w;
  324.          this.appHeight = h;
  325.          Graphics g = ((Component)this).getGraphics();
  326.          ((Component)this).setBackground(this.bgColor);
  327.          ((Component)this).repaint();
  328.       }
  329.  
  330.       this.appWidth = w;
  331.       this.appHeight = h;
  332.       this.centerAppArea();
  333.    }
  334.  
  335.    OCmltext() {
  336.       this.m_def_textcolor = Color.black;
  337.       this.m_font = new Font("Helvetica", 0, 12);
  338.       this.m_xoffset = 4;
  339.       this.m_bgcolor = Color.white;
  340.       this.sb_width = 12;
  341.       this.sb_linedist = 1;
  342.       this.hsb_linedist = 1;
  343.       this.first_sb_run = true;
  344.       this.first_hsb_run = true;
  345.       this.sEdge = 5;
  346.       ((Container)this).setLayout((LayoutManager)null);
  347.    }
  348.  
  349.    public void addDefaults(String[] pn, String[] pv) {
  350.       this.def_pn = pn;
  351.       this.def_pv = pv;
  352.       this.initDefault();
  353.    }
  354.  
  355.    private String getParameterSpecific(String param, int index) {
  356.       for(int i = 0; i < this.spe_pn.length; ++i) {
  357.          if (this.spe_pn[i].equals(param)) {
  358.             String s = ((String[])this.spe_pv.elementAt(index))[i];
  359.             if (s != null && !s.equals("") && !s.equalsIgnoreCase("<default>")) {
  360.                return s;
  361.             }
  362.  
  363.             return null;
  364.          }
  365.       }
  366.  
  367.       return null;
  368.    }
  369.  
  370.    public void paint(Graphics g) {
  371.       this.paint_called = true;
  372.       this.paintIt();
  373.    }
  374.  
  375.    public boolean handleEvent(Event e) {
  376.       boolean go = false;
  377.       boolean hgo = false;
  378.       if (e.target == this.field_2) {
  379.          if (e.id != 602 && e.id != 601 && e.id != 605) {
  380.             if (e.id == 604 || e.id == 603) {
  381.                this.scroll_y = -(this.field_2.getValue() * this.sb_linedist);
  382.                this.field_2.setValue(this.field_2.getValue());
  383.                go = true;
  384.             }
  385.          } else {
  386.             this.scroll_y = -(this.field_2.getValue() * this.sb_linedist);
  387.             this.field_2.setValue(this.field_2.getValue());
  388.             go = true;
  389.          }
  390.  
  391.          if (go) {
  392.             if (this.scroll_y >= 0) {
  393.                this.scroll_y = 0;
  394.             } else if (this.scroll_y + this.sbImgHeight < this.field_1.height) {
  395.                this.scroll_y = -this.sbImgHeight + this.field_1.height;
  396.             }
  397.  
  398.             this.last_scroll_y = this.scroll_y;
  399.             this.paintIt();
  400.             go = false;
  401.          }
  402.  
  403.          return true;
  404.       } else if (e.target != this.hsb) {
  405.          return super.handleEvent(e);
  406.       } else {
  407.          if (e.id != 602 && e.id != 601 && e.id != 605) {
  408.             if (e.id == 604 || e.id == 603) {
  409.                this.scroll_x = -(this.hsb.getValue() * this.hsb_linedist);
  410.                this.hsb.setValue(this.hsb.getValue());
  411.                hgo = true;
  412.             }
  413.          } else {
  414.             this.scroll_x = -(this.hsb.getValue() * this.hsb_linedist);
  415.             this.hsb.setValue(this.hsb.getValue());
  416.             hgo = true;
  417.          }
  418.  
  419.          if (hgo) {
  420.             if (this.scroll_x >= 0) {
  421.                this.scroll_x = 0;
  422.             } else if (this.scroll_x + this.sbImgWidth < this.field_1.width) {
  423.                this.scroll_x = -this.sbImgWidth + this.field_1.width;
  424.             }
  425.  
  426.             this.last_scroll_x = this.scroll_x;
  427.             this.paintIt();
  428.             hgo = false;
  429.          }
  430.  
  431.          return true;
  432.       }
  433.    }
  434. }
  435.