home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2002 June / INTERNET92.ISO / pc / software / windows / building / visual_dhtml / visualdhtmlwin2000.exe / OCicodis.___ (.txt) < prev    next >
Encoding:
Java Class File  |  2001-10-19  |  6.8 KB  |  393 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. public class OCicodis extends Panel {
  16.    int realHeight;
  17.    boolean paint_called = false;
  18.    public Color bgColor = new Color(153, 153, 153);
  19.    int h_space;
  20.    int v_space;
  21.    Event the_e;
  22.    private int desc_index = 0;
  23.    // $FF: renamed from: d java.awt.Dimension
  24.    Dimension field_0;
  25.    // $FF: renamed from: ts java.awt.Image
  26.    Image field_1;
  27.    Graphics g_ts;
  28.    Font font = new Font("Helvetica", 0, 11);
  29.    // $FF: renamed from: fm java.awt.FontMetrics
  30.    FontMetrics field_2;
  31.    boolean[] simg_status;
  32.    boolean[] icoimg_status;
  33.    boolean[] cimg_status;
  34.    boolean tag = false;
  35.    boolean first_run = true;
  36.    boolean mouse_in = false;
  37.    private Color m_page_bgcolor;
  38.    private String[] m_iconfile;
  39.    private String[] m_switchfile;
  40.    private String[] m_clickfile;
  41.    private int[] m_pic_xcord;
  42.    private int[] m_pic_ycord;
  43.    private int[] m_menu_xcord;
  44.    private int[] m_menu_ycord;
  45.    private String[][] m_desc;
  46.    int manip_image;
  47.    int num_images;
  48.    int[] pic_width;
  49.    int[] pic_height;
  50.    private Image[] i_picture;
  51.    private Image[] s_picture;
  52.    private Image[] c_picture;
  53.    private String[] def_pn;
  54.    private String[] def_pv;
  55.    private String[] spe_pn;
  56.    private Vector spe_pv;
  57.    int sb_width;
  58.    // $FF: renamed from: sb java.awt.Scrollbar
  59.    Scrollbar field_3;
  60.    int scroll_y;
  61.    int sb_linedist;
  62.    boolean first_sb_run;
  63.    boolean use_sb;
  64.    int last_scroll_y;
  65.    int sbImgHeight;
  66.  
  67.    private String getParameterSpecific(String var1, int var2) {
  68.       for(int var3 = 0; var3 < this.spe_pn.length; ++var3) {
  69.          if (this.spe_pn[var3].equals(var1)) {
  70.             String var4 = ((String[])this.spe_pv.elementAt(var2))[var3];
  71.             if (var4 != null && !var4.equals("") && !var4.equalsIgnoreCase("<default>")) {
  72.                return var4;
  73.             }
  74.  
  75.             return null;
  76.          }
  77.       }
  78.  
  79.       return null;
  80.    }
  81.  
  82.    private void figureSizing() {
  83.       this.h_space = 10;
  84.       this.v_space = 10;
  85.       int var1 = 0;
  86.       int var2 = 0;
  87.  
  88.       for(int var3 = 0; var3 < this.num_images; ++var3) {
  89.          if (var1 < this.pic_width[var3]) {
  90.             var1 = this.pic_width[var3];
  91.          }
  92.  
  93.          if (var2 < this.pic_height[var3]) {
  94.             var2 = this.pic_height[var3];
  95.          }
  96.       }
  97.  
  98.       this.h_space += var1;
  99.       this.v_space += var2;
  100.       int var6 = 0;
  101.       int var4 = 0;
  102.  
  103.       for(int var5 = 0; var5 < this.num_images; ++var5) {
  104.          this.m_pic_xcord[var5] = var6 + (this.h_space - var1) / 2;
  105.          this.m_pic_ycord[var5] = var4 + (this.v_space - var2) / 2;
  106.          var6 += this.h_space;
  107.          if (var6 > this.field_0.width) {
  108.             var6 = 0;
  109.             var4 += this.v_space;
  110.             this.m_pic_xcord[var5] = var6 + (this.h_space - var1) / 2;
  111.             this.m_pic_ycord[var5] = var4 + (this.v_space - var2) / 2;
  112.          }
  113.       }
  114.  
  115.       if (var4 + this.v_space > this.field_0.height) {
  116.          this.realHeight = var4 + this.v_space;
  117.       } else {
  118.          this.realHeight = this.field_0.height;
  119.       }
  120.    }
  121.  
  122.    OCicodis() {
  123.       this.m_page_bgcolor = Color.white;
  124.       this.manip_image = -1;
  125.       this.num_images = 0;
  126.       this.sb_width = 12;
  127.       this.sb_linedist = 1;
  128.       this.first_sb_run = true;
  129.       this.use_sb = false;
  130.       this.the_e = new Event(this, 960, this);
  131.       ((Container)this).setLayout((LayoutManager)null);
  132.    }
  133.  
  134.    public void paint(Graphics var1) {
  135.       this.paint_called = true;
  136.       this.paintIt();
  137.    }
  138.  
  139.    public void reDraw() {
  140.       boolean var1 = false;
  141.       this.g_ts.setColor(this.m_page_bgcolor);
  142.       this.g_ts.fillRect(0, 0, this.field_0.width, this.realHeight);
  143.  
  144.       for(int var2 = 0; var2 < this.num_images; ++var2) {
  145.          if (this.icoimg_status[var2]) {
  146.             var1 = true;
  147.             this.g_ts.drawImage(this.i_picture[var2], this.m_pic_xcord[var2], this.m_pic_ycord[var2], this);
  148.          }
  149.       }
  150.  
  151.       if (!var1) {
  152.          this.g_ts.setColor(Color.black);
  153.          this.g_ts.setFont(this.font);
  154.          this.field_2 = ((Component)this).getFontMetrics(this.font);
  155.          String var8 = "(No icon imges are currently defined.)";
  156.          byte var3 = 10;
  157.          String[] var4 = ocwordw.WrapText(var8, this.field_0.width - var3, this.field_2);
  158.          int var5 = this.field_2.getHeight() * var4.length + this.field_2.getAscent() / 2;
  159.          int var6 = this.field_0.height / 2 - var5 / 2;
  160.  
  161.          for(int var7 = 0; var7 < var4.length; ++var7) {
  162.             this.g_ts.drawString(var4[var7], this.field_0.width / 2 - this.field_2.stringWidth(var4[var7]) / 2, var6 + (var7 + 1) * this.field_2.getHeight());
  163.          }
  164.       }
  165.  
  166.       if (this.manip_image > -1 && this.manip_image <= this.num_images && this.icoimg_status[this.manip_image]) {
  167.          this.g_ts.setColor(Color.lightGray);
  168.          this.g_ts.drawRect(this.m_pic_xcord[this.manip_image] - 2, this.m_pic_ycord[this.manip_image] - 2, this.pic_width[this.manip_image] + 3, this.pic_height[this.manip_image] + 3);
  169.       }
  170.  
  171.    }
  172.  
  173.    public void addSpecifics(String[] var1, Vector var2) {
  174.       this.spe_pn = var1;
  175.       this.spe_pv = var2;
  176.       this.initSpecifics();
  177.    }
  178.  
  179.    private String getParameterDefault(String var1) {
  180.       for(int var2 = 0; var2 < this.def_pn.length; ++var2) {
  181.          if (this.def_pn[var2].equals(var1)) {
  182.             return this.def_pv[var2];
  183.          }
  184.       }
  185.  
  186.       return null;
  187.    }
  188.  
  189.    public void initDefault() {
  190.    }
  191.  
  192.    private synchronized void paintIt() {
  193.       if (this.paint_called) {
  194.          Graphics var1 = ((Component)this).getGraphics();
  195.          if (this.first_run) {
  196.             ((Component)this).setBackground(this.bgColor);
  197.             this.field_1 = ((Component)this).createImage(this.field_0.width, this.realHeight);
  198.             this.g_ts = this.field_1.getGraphics();
  199.             this.first_run = false;
  200.             this.reDraw();
  201.             this.paintIt();
  202.             if (this.first_sb_run) {
  203.                if (this.use_sb) {
  204.                   this.field_3 = new Scrollbar();
  205.                   this.field_3.reshape(this.field_0.width - this.sb_width, 0, this.sb_width, this.field_0.height);
  206.                   this.field_3.setBackground(Color.gray);
  207.                   ((Container)this).add(this.field_3);
  208.                   this.first_sb_run = false;
  209.                }
  210.             } else if (!this.use_sb) {
  211.                ((Container)this).remove(this.field_3);
  212.                this.field_3 = null;
  213.                this.first_sb_run = true;
  214.             } else {
  215.                this.field_3.reshape(this.field_0.width - this.sb_width, 0, this.sb_width, this.field_0.height);
  216.             }
  217.  
  218.             if (this.use_sb) {
  219.                this.field_3.setValues(this.field_3.getValue(), 1, 0, this.sbImgHeight - this.field_0.height);
  220.                return;
  221.             }
  222.          } else {
  223.             var1.drawImage(this.field_1, 0, this.scroll_y, this);
  224.          }
  225.  
  226.       }
  227.    }
  228.  
  229.    public void LoadImages() {
  230.       ACutil var1 = new ACutil();
  231.  
  232.       for(int var2 = 0; var2 < this.num_images; ++var2) {
  233.          if ((this.i_picture[var2] = var1.getDGImage(this.m_iconfile[var2])) != null) {
  234.             this.icoimg_status[var2] = true;
  235.             this.pic_width[var2] = this.i_picture[var2].getWidth(this);
  236.             this.pic_height[var2] = this.i_picture[var2].getHeight(this);
  237.          }
  238.       }
  239.  
  240.    }
  241.  
  242.    public void resize(Dimension var1) {
  243.       if (var1.width * var1.height > 0) {
  244.          this.centerAppArea();
  245.          super.resize(var1);
  246.       }
  247.    }
  248.  
  249.    public void resize(int var1, int var2) {
  250.       if (var1 * var2 > 0) {
  251.          this.field_0 = new Dimension(var1, var2);
  252.          this.centerAppArea();
  253.          super.resize(var1, var2);
  254.       }
  255.    }
  256.  
  257.    public void initSpecifics() {
  258.       boolean var2 = false;
  259.       this.num_images = this.spe_pv.size();
  260.       this.m_iconfile = new String[this.num_images];
  261.       this.m_switchfile = new String[this.num_images];
  262.       this.m_clickfile = new String[this.num_images];
  263.       this.m_pic_xcord = new int[this.num_images];
  264.       this.m_pic_ycord = new int[this.num_images];
  265.       this.pic_width = new int[this.num_images];
  266.       this.pic_height = new int[this.num_images];
  267.       this.i_picture = new Image[this.num_images];
  268.       this.s_picture = new Image[this.num_images];
  269.       this.c_picture = new Image[this.num_images];
  270.       this.simg_status = new boolean[this.num_images];
  271.       this.icoimg_status = new boolean[this.num_images];
  272.       this.cimg_status = new boolean[this.num_images];
  273.  
  274.       for(int var5 = 0; var5 < this.num_images; ++var5) {
  275.          String var1 = this.getParameterSpecific("iconimage", var5);
  276.          if (var1 != null) {
  277.             this.m_iconfile[var5] = new String(var1);
  278.          } else {
  279.             this.m_iconfile[var5] = new String("-1");
  280.          }
  281.  
  282.          var1 = this.getParameterSpecific("switchimage", var5);
  283.          if (var1 != null) {
  284.             this.m_switchfile[var5] = new String(var1);
  285.          } else {
  286.             this.m_switchfile[var5] = new String("-1");
  287.          }
  288.  
  289.          var1 = this.getParameterSpecific("iconclickfile", var5);
  290.          if (var1 != null) {
  291.             this.m_clickfile[var5] = new String(var1);
  292.          } else {
  293.             this.m_clickfile[var5] = new String("-1");
  294.          }
  295.       }
  296.  
  297.    }
  298.  
  299.    public boolean mouseDown(Event var1, int var2, int var3) {
  300.       ((Component)this).requestFocus();
  301.  
  302.       for(int var4 = 0; var4 < this.num_images; ++var4) {
  303.          if (var3 > this.m_pic_ycord[var4] + this.scroll_y && var3 < this.m_pic_ycord[var4] + this.pic_height[var4] + this.scroll_y && var2 > this.m_pic_xcord[var4] && var2 < this.m_pic_xcord[var4] + this.pic_width[var4]) {
  304.             if (this.manip_image != var4) {
  305.                this.manip_image = var4;
  306.                this.the_e.id = 9202;
  307.                this.the_e.arg = new Integer(this.manip_image);
  308.                super.postEvent(this.the_e);
  309.                this.reDraw();
  310.                this.paintIt();
  311.             }
  312.  
  313.             return true;
  314.          }
  315.       }
  316.  
  317.       this.manip_image = -1;
  318.       return true;
  319.    }
  320.  
  321.    private void centerAppArea() {
  322.       this.LoadImages();
  323.       this.figureSizing();
  324.       if (this.realHeight > this.field_0.height) {
  325.          this.use_sb = true;
  326.          this.realHeight += this.sb_width;
  327.       } else {
  328.          this.use_sb = false;
  329.       }
  330.  
  331.       this.scroll_y = 0;
  332.       if (this.use_sb) {
  333.          this.scroll_y = this.last_scroll_y;
  334.       }
  335.  
  336.       this.first_run = true;
  337.       this.paintIt();
  338.    }
  339.  
  340.    public void updateDisplay(int var1) {
  341.       this.desc_index = var1;
  342.       this.manip_image = this.desc_index;
  343.       this.centerAppArea();
  344.    }
  345.  
  346.    public void addDefaults(String[] var1, String[] var2) {
  347.       this.def_pn = var1;
  348.       this.def_pv = var2;
  349.       this.initDefault();
  350.    }
  351.  
  352.    public boolean handleEvent(Event var1) {
  353.       boolean var2 = false;
  354.       if (var1.target != this.field_3) {
  355.          return super.handleEvent(var1);
  356.       } else {
  357.          if (var1.id != 602 && var1.id != 601 && var1.id != 605) {
  358.             if (var1.id == 604 || var1.id == 603) {
  359.                this.scroll_y = -(this.field_3.getValue() * this.sb_linedist);
  360.                this.field_3.setValue(this.field_3.getValue());
  361.                var2 = true;
  362.             }
  363.          } else {
  364.             this.scroll_y = -(this.field_3.getValue() * this.sb_linedist);
  365.             this.field_3.setValue(this.field_3.getValue());
  366.             var2 = true;
  367.          }
  368.  
  369.          if (var2) {
  370.             if (this.scroll_y >= 0) {
  371.                this.scroll_y = 0;
  372.             } else if (this.scroll_y + this.sbImgHeight < this.field_0.height) {
  373.                this.scroll_y = -this.sbImgHeight + this.field_0.height;
  374.             }
  375.  
  376.             this.last_scroll_y = this.scroll_y;
  377.             this.paintIt();
  378.             var2 = false;
  379.          }
  380.  
  381.          return true;
  382.       }
  383.    }
  384.  
  385.    public void reshape(int var1, int var2, int var3, int var4) {
  386.       if (var3 * var4 > 0) {
  387.          this.field_0 = new Dimension(var3, var4);
  388.          this.centerAppArea();
  389.          super.reshape(var1, var2, var3, var4);
  390.       }
  391.    }
  392. }
  393.