home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / netscape / application / ListView.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-12  |  14.9 KB  |  794 lines

  1. package netscape.application;
  2.  
  3. import netscape.util.ClassInfo;
  4. import netscape.util.CodingException;
  5. import netscape.util.Decoder;
  6. import netscape.util.Encoder;
  7. import netscape.util.Vector;
  8.  
  9. public class ListView extends View implements Target, FormElement {
  10.    ListItem protoItem;
  11.    ListItem anchorItem;
  12.    ListItem origSelectedItem;
  13.    Vector items;
  14.    Vector selectedItems;
  15.    Vector dirtyItems;
  16.    String command;
  17.    String doubleCommand;
  18.    Target target;
  19.    Color backgroundColor;
  20.    int rowHeight;
  21.    boolean allowsMultipleSelection;
  22.    boolean allowsEmptySelection;
  23.    boolean tracksMouseOutsideBounds;
  24.    boolean tracking;
  25.    boolean enabled;
  26.    boolean transparent;
  27.    static final String PROTOITEM_KEY = "protoItem";
  28.    static final String ANCHORITEM_KEY = "anchorItem";
  29.    static final String ORIGSELECTED_KEY = "origSelectedItem";
  30.    static final String ITEMS_KEY = "items";
  31.    static final String SELECTEDITEMS_KEY = "selectedItems";
  32.    static final String DIRTYITEMS_KEY = "dirtyItems";
  33.    static final String COMMAND_KEY = "command";
  34.    static final String DOUBLECOMMAND_KEY = "doubleCommand";
  35.    static final String TARGET_KEY = "target";
  36.    static final String BACKGROUNDCOLOR_KEY = "backgroundColor";
  37.    static final String ROWHEIGHT_KEY = "rowHeight";
  38.    static final String MULTSELECTION_KEY = "allowsMultipleSelection";
  39.    static final String EMPTYSELECTION_KEY = "allowsEmptySelection";
  40.    static final String TRACKSMOUSE_KEY = "tracksMouseOutsideBounds";
  41.    static final String ENABLED_KEY = "enabled";
  42.    static final String TRANSPARENT_KEY = "isTransparent";
  43.    public static String SELECT_NEXT_ITEM = "selectNext";
  44.    public static String SELECT_PREVIOUS_ITEM = "selectPrevious";
  45.  
  46.    public ListView() {
  47.       this(0, 0, 0, 0);
  48.    }
  49.  
  50.    public ListView(Rect var1) {
  51.       this(var1.x, var1.y, var1.width, var1.height);
  52.    }
  53.  
  54.    public ListView(int var1, int var2, int var3, int var4) {
  55.       super(var1, var2, var3, var4);
  56.       this.items = new Vector();
  57.       this.selectedItems = new Vector();
  58.       this.dirtyItems = new Vector();
  59.       this.backgroundColor = Color.lightGray;
  60.       this.rowHeight = 17;
  61.       this.tracksMouseOutsideBounds = true;
  62.       this.enabled = true;
  63.       this.transparent = false;
  64.       this._setupKeyboard();
  65.    }
  66.  
  67.    public void setPrototypeItem(ListItem var1) {
  68.       if (var1 == null) {
  69.          this.protoItem = new ListItem();
  70.       } else {
  71.          this.protoItem = var1;
  72.       }
  73.  
  74.       if (this.protoItem.font() == null) {
  75.          this.protoItem.setFont(Font.fontNamed("Default"));
  76.       }
  77.  
  78.       this.protoItem.setListView(this);
  79.    }
  80.  
  81.    public ListItem prototypeItem() {
  82.       if (this.protoItem == null) {
  83.          this.setPrototypeItem((ListItem)null);
  84.       }
  85.  
  86.       return this.protoItem;
  87.    }
  88.  
  89.    public void setBackgroundColor(Color var1) {
  90.       this.backgroundColor = var1;
  91.    }
  92.  
  93.    public Color backgroundColor() {
  94.       return this.backgroundColor;
  95.    }
  96.  
  97.    public void setTransparent(boolean var1) {
  98.       this.transparent = var1;
  99.    }
  100.  
  101.    public boolean isTransparent() {
  102.       return this.transparent;
  103.    }
  104.  
  105.    public boolean wantsAutoscrollEvents() {
  106.       return true;
  107.    }
  108.  
  109.    public void setAllowsMultipleSelection(boolean var1) {
  110.       this.allowsMultipleSelection = var1;
  111.    }
  112.  
  113.    public boolean allowsMultipleSelection() {
  114.       return this.allowsMultipleSelection;
  115.    }
  116.  
  117.    public void setAllowsEmptySelection(boolean var1) {
  118.       this.allowsEmptySelection = var1;
  119.    }
  120.  
  121.    public boolean allowsEmptySelection() {
  122.       return this.allowsEmptySelection;
  123.    }
  124.  
  125.    public void setTracksMouseOutsideBounds(boolean var1) {
  126.       this.tracksMouseOutsideBounds = var1;
  127.    }
  128.  
  129.    public boolean tracksMouseOutsideBounds() {
  130.       return this.tracksMouseOutsideBounds;
  131.    }
  132.  
  133.    public void setEnabled(boolean var1) {
  134.       if (this.enabled != var1) {
  135.          this.enabled = var1;
  136.          ((View)this).setDirty(true);
  137.       }
  138.  
  139.    }
  140.  
  141.    public boolean isEnabled() {
  142.       return this.enabled;
  143.    }
  144.  
  145.    public void setRowHeight(int var1) {
  146.       if (var1 > 0) {
  147.          this.rowHeight = var1;
  148.       } else {
  149.          this.rowHeight = this.minItemHeight();
  150.       }
  151.    }
  152.  
  153.    public int rowHeight() {
  154.       if (this.rowHeight > 0) {
  155.          return this.rowHeight;
  156.       } else {
  157.          this.setRowHeight(this.minItemHeight());
  158.          return this.rowHeight;
  159.       }
  160.    }
  161.  
  162.    public int minItemHeight() {
  163.       int var3 = 0;
  164.       int var2 = this.items.size();
  165.  
  166.       for(int var1 = 0; var1 < var2; ++var1) {
  167.          ListItem var5 = (ListItem)this.items.elementAt(var1);
  168.          int var4 = var5.minHeight();
  169.          if (var4 > var3) {
  170.             var3 = var4;
  171.          }
  172.       }
  173.  
  174.       return var3;
  175.    }
  176.  
  177.    public int minItemWidth() {
  178.       int var3 = 0;
  179.       int var2 = this.items.size();
  180.  
  181.       for(int var1 = 0; var1 < var2; ++var1) {
  182.          ListItem var5 = (ListItem)this.items.elementAt(var1);
  183.          int var4 = var5.minWidth();
  184.          if (var4 > var3) {
  185.             var3 = var4;
  186.          }
  187.       }
  188.  
  189.       return var3;
  190.    }
  191.  
  192.    public Size minSize() {
  193.       return new Size(super.bounds.width, this.count() * this.rowHeight());
  194.    }
  195.  
  196.    public ListItem itemForPoint(int var1, int var2) {
  197.       int var4 = this.items.size();
  198.       if (this.rowHeight == 0) {
  199.          return null;
  200.       } else if (var4 == 0) {
  201.          return null;
  202.       } else if (!this.tracksMouseOutsideBounds && !Rect.contains(0, 0, ((View)this).width(), ((View)this).height(), var1, var2)) {
  203.          return null;
  204.       } else {
  205.          int var3 = var2 / this.rowHeight;
  206.          if (var3 < 0) {
  207.             var3 = 0;
  208.          } else if (var3 >= var4) {
  209.             var3 = var4 - 1;
  210.          }
  211.  
  212.          return this.itemAt(var3);
  213.       }
  214.    }
  215.  
  216.    public ListItem itemAt(int var1) {
  217.       return (ListItem)this.items.elementAt(var1);
  218.    }
  219.  
  220.    public int indexOfItem(ListItem var1) {
  221.       return this.items.indexOf(var1);
  222.    }
  223.  
  224.    public Rect rectForItem(ListItem var1) {
  225.       return var1 == null ? null : this.rectForItemAt(this.items.indexOf(var1));
  226.    }
  227.  
  228.    public Rect rectForItemAt(int var1) {
  229.       return var1 >= 0 && var1 < this.items.size() ? new Rect(0, this.rowHeight * var1, super.bounds.width, this.rowHeight) : null;
  230.    }
  231.  
  232.    public boolean multipleItemsSelected() {
  233.       return this.selectedItems.size() > 1;
  234.    }
  235.  
  236.    public int selectedIndex() {
  237.       ListItem var1 = this.selectedItem();
  238.       return var1 == null ? -1 : this.items.indexOf(var1);
  239.    }
  240.  
  241.    public ListItem selectedItem() {
  242.       return this.selectedItems.size() > 0 ? (ListItem)this.selectedItems.elementAt(0) : null;
  243.    }
  244.  
  245.    public Vector selectedItems() {
  246.       return this.selectedItems;
  247.    }
  248.  
  249.    public int count() {
  250.       return this.items.size();
  251.    }
  252.  
  253.    public ListItem addItem() {
  254.       return this.insertItemAt(this.items.size());
  255.    }
  256.  
  257.    public ListItem addItem(ListItem var1) {
  258.       if (var1.font() == null) {
  259.          var1.setFont(Font.defaultFont());
  260.       }
  261.  
  262.       var1.setListView(this);
  263.       return this.insertItemAt(var1, this.items.size());
  264.    }
  265.  
  266.    public ListItem insertItemAt(ListItem var1, int var2) {
  267.       if (var1.font() == null) {
  268.          var1.setFont(Font.defaultFont());
  269.       }
  270.  
  271.       var1.setListView(this);
  272.       this.items.insertElementAt(var1, var2);
  273.       if (!this.allowsEmptySelection && this.selectedItems.isEmpty()) {
  274.          this.selectItem(var1);
  275.       }
  276.  
  277.       return var1;
  278.    }
  279.  
  280.    public ListItem insertItemAt(int var1) {
  281.       ListItem var2 = (ListItem)this.prototypeItem().clone();
  282.       this.items.insertElementAt(var2, var1);
  283.       if (!this.allowsEmptySelection && this.selectedItems.isEmpty()) {
  284.          this.selectItem(var2);
  285.       }
  286.  
  287.       return var2;
  288.    }
  289.  
  290.    public void removeItemAt(int var1) {
  291.       ListItem var2 = (ListItem)this.items.elementAt(var1);
  292.       this.items.removeElementAt(var1);
  293.       this.selectedItems.removeElement(var2);
  294.       if (!this.allowsEmptySelection && this.selectedItems.size() == 0 && this.items.size() > 0) {
  295.          --var1;
  296.          if (var1 < 0) {
  297.             var1 = 0;
  298.          }
  299.  
  300.          this.selectItem(this.itemAt(var1));
  301.       }
  302.  
  303.    }
  304.  
  305.    public void removeItem(ListItem var1) {
  306.       this.removeItemAt(this.items.indexOf(var1));
  307.    }
  308.  
  309.    public void removeAllItems() {
  310.       this.items.removeAllElements();
  311.       this.selectItem((ListItem)null);
  312.    }
  313.  
  314.    public void selectItem(ListItem var1) {
  315.       if (var1 != null && !var1.isEnabled()) {
  316.          var1 = null;
  317.       }
  318.  
  319.       if (var1 == null) {
  320.          int var3 = this.selectedItems.size();
  321.          ListItem var5;
  322.          if (var3 > 0 && !this.allowsEmptySelection) {
  323.             var5 = (ListItem)this.selectedItems.elementAt(var3 - 1);
  324.             this.selectedItems.removeElementAt(var3 - 1);
  325.             --var3;
  326.          } else {
  327.             var5 = null;
  328.          }
  329.  
  330.          for(int var2 = 0; var2 < var3; ++var2) {
  331.             ListItem var4 = (ListItem)this.selectedItems.elementAt(var2);
  332.             var4.setSelected(false);
  333.             this.markDirty(var4);
  334.          }
  335.  
  336.          this.selectedItems.removeAllElements();
  337.          if (var5 != null) {
  338.             this.selectedItems.addElement(var5);
  339.          }
  340.       } else if (!this.selectedItems.contains(var1)) {
  341.          if (!this.allowsMultipleSelection) {
  342.             ListItem var6 = this.selectedItem();
  343.             if (var6 != null) {
  344.                var6.setSelected(false);
  345.                this.selectedItems.removeElement(var6);
  346.                this.markDirty(var6);
  347.             }
  348.          }
  349.  
  350.          var1.setSelected(true);
  351.          this.selectedItems.addElement(var1);
  352.          this.markDirty(var1);
  353.       }
  354.  
  355.       this.drawDirtyItems();
  356.    }
  357.  
  358.    public void selectItemAt(int var1) {
  359.       this.selectItem((ListItem)this.items.elementAt(var1));
  360.    }
  361.  
  362.    public void selectOnly(ListItem var1) {
  363.       boolean var5 = false;
  364.       if (var1.isEnabled()) {
  365.          int var3 = this.selectedItems.size();
  366.          if (var3 != 1 || var1 != this.selectedItems.elementAt(0)) {
  367.             for(int var2 = 0; var2 < var3; ++var2) {
  368.                ListItem var4 = (ListItem)this.selectedItems.elementAt(var2);
  369.                if (var4 != var1) {
  370.                   var4.setSelected(false);
  371.                   this.markDirty(var4);
  372.                } else {
  373.                   var5 = true;
  374.                }
  375.             }
  376.  
  377.             this.selectedItems.removeAllElements();
  378.             this.selectedItems.addElement(var1);
  379.             if (!var5) {
  380.                var1.setSelected(true);
  381.                this.markDirty(var1);
  382.             }
  383.  
  384.             this.drawDirtyItems();
  385.          }
  386.       }
  387.    }
  388.  
  389.    public void deselectItem(ListItem var1) {
  390.       if (var1 != null && (this.selectedItems.size() != 1 || this.allowsEmptySelection)) {
  391.          if (this.items.contains(var1) && this.selectedItems.contains(var1)) {
  392.             this.selectedItems.removeElement(var1);
  393.             var1.setSelected(false);
  394.             this.markDirty(var1);
  395.             this.drawDirtyItems();
  396.          }
  397.       }
  398.    }
  399.  
  400.    public void scrollItemAtToVisible(int var1) {
  401.       ((View)this).scrollRectToVisible(this.rectForItemAt(var1));
  402.    }
  403.  
  404.    public void scrollItemToVisible(ListItem var1) {
  405.       ((View)this).scrollRectToVisible(this.rectForItem(var1));
  406.    }
  407.  
  408.    public boolean mouseDown(MouseEvent var1) {
  409.       if (!this.enabled) {
  410.          return false;
  411.       } else {
  412.          this.tracking = true;
  413.          this.origSelectedItem = this.selectedItem();
  414.          ListItem var2 = this.itemForPoint(var1.x, var1.y);
  415.          if (var2 == null) {
  416.             return true;
  417.          } else {
  418.             if (this.anchorItem != var2 && var1.clickCount > 1) {
  419.                var1.setClickCount(1);
  420.             }
  421.  
  422.             this.selectOnly(var2);
  423.             this.anchorItem = var2;
  424.             if (var1.clickCount == 2) {
  425.                this.sendDoubleCommand();
  426.                return false;
  427.             } else {
  428.                return true;
  429.             }
  430.          }
  431.       }
  432.    }
  433.  
  434.    public void mouseDragged(MouseEvent var1) {
  435.       if (this.tracking) {
  436.          ((View)this).disableDrawing();
  437.          ListItem var2 = this.itemForPoint(var1.x, var1.y);
  438.          if (!this.tracksMouseOutsideBounds && !Rect.contains(0, 0, ((View)this).width(), ((View)this).height(), var1.x, var1.y)) {
  439.             var2 = null;
  440.          }
  441.  
  442.          if (!this.allowsMultipleSelection) {
  443.             if (var2 != this.selectedItem() && (this.allowsEmptySelection || var2 != null)) {
  444.                this.anchorItem = var2;
  445.                this.selectItem(var2);
  446.             }
  447.          } else {
  448.             int var7 = this.items.indexOf(this.anchorItem);
  449.             int var8;
  450.             if (var2 != null) {
  451.                var8 = this.items.indexOf(var2);
  452.             } else if (this.pointCompare(0, ((View)this).height(), var1.y) < 0) {
  453.                var8 = 0;
  454.             } else {
  455.                var8 = this.items.size() - 1;
  456.             }
  457.  
  458.             int var5;
  459.             int var6;
  460.             if (var7 < var8) {
  461.                var5 = var7;
  462.                var6 = var8;
  463.             } else {
  464.                var5 = var8;
  465.                var6 = var7;
  466.             }
  467.  
  468.             int var4 = this.selectedItems.size();
  469.  
  470.             while(var4-- > 0) {
  471.                ListItem var3 = (ListItem)this.selectedItems.elementAt(var4);
  472.                int var9 = this.items.indexOf(var3);
  473.                if (!var3.isSelected() || var9 >= var5 && var9 <= var6) {
  474.                   if (!var3.isSelected() && var9 >= var5 && var9 <= var6) {
  475.                      this.selectItem(var3);
  476.                   }
  477.                } else {
  478.                   this.deselectItem(var3);
  479.                }
  480.             }
  481.  
  482.             if (var5 != -1 && var6 != -1) {
  483.                for(int var11 = var5; var11 <= var6; ++var11) {
  484.                   ListItem var10 = (ListItem)this.items.elementAt(var11);
  485.                   if (!var10.isSelected()) {
  486.                      this.selectItem(var10);
  487.                   }
  488.                }
  489.             }
  490.          }
  491.  
  492.          ((View)this).reenableDrawing();
  493.          this.autoscroll(var1);
  494.       }
  495.    }
  496.  
  497.    public void mouseUp(MouseEvent var1) {
  498.       if (var1.clickCount == 1) {
  499.          this.sendCommand();
  500.       }
  501.  
  502.       this.tracking = false;
  503.    }
  504.  
  505.    private int pointCompare(int var1, int var2, int var3) {
  506.       if (var3 < var1) {
  507.          return -1;
  508.       } else {
  509.          return var3 >= var1 + var2 ? 1 : 0;
  510.       }
  511.    }
  512.  
  513.    private int rectCompare(Rect var1, Rect var2) {
  514.       if (var2.maxY() <= var1.y) {
  515.          return -1;
  516.       } else {
  517.          return var2.y >= var1.maxY() ? 1 : 0;
  518.       }
  519.    }
  520.  
  521.    private void autoscroll(MouseEvent var1) {
  522.       Rect var2 = Rect.newRect();
  523.       ((View)this).computeVisibleRect(var2);
  524.       this.drawDirtyItems();
  525.       if (!var2.contains(var1.x, var1.y)) {
  526.          if (var1.y < var2.y) {
  527.             Rect var3 = Rect.newRect(var2.x, var1.y, var2.width, this.rowHeight);
  528.             ((View)this).scrollRectToVisible(var3);
  529.             Rect.returnRect(var3);
  530.          } else if (var1.y > var2.maxY()) {
  531.             Rect var4 = Rect.newRect(var2.x, var1.y - this.rowHeight, var2.width, this.rowHeight);
  532.             ((View)this).scrollRectToVisible(var4);
  533.             Rect.returnRect(var4);
  534.          }
  535.       }
  536.  
  537.       Rect.returnRect(var2);
  538.    }
  539.  
  540.    private void markDirty(ListItem var1) {
  541.       if (!this.dirtyItems.contains(var1)) {
  542.          this.dirtyItems.addElement(var1);
  543.       }
  544.    }
  545.  
  546.    private void drawDirtyItems() {
  547.       if (((View)this).canDraw()) {
  548.          int var2 = this.dirtyItems.size();
  549.          if (var2 != 0) {
  550.             Vector var5 = this.dirtyItems;
  551.             this.dirtyItems = null;
  552.             Rect var6 = Rect.newRect(0, 0, super.bounds.width, this.rowHeight);
  553.             int var4 = this.count();
  554.  
  555.             for(int var1 = 0; var1 < var2; ++var1) {
  556.                int var3 = this.items.indexOf(var5.elementAt(var1));
  557.                if (var3 >= 0 && var3 < var4) {
  558.                   var6.y = var3 * this.rowHeight;
  559.                   var6.height = this.rowHeight;
  560.                   if (var1 < var2 - 1) {
  561.                      int var7 = this.items.indexOf(var5.elementAt(var1 + 1));
  562.                      if (var7 == var3 + 1) {
  563.                         var6.height += this.rowHeight;
  564.                         ++var1;
  565.                      } else if (var7 == var3 - 1) {
  566.                         var6.height += this.rowHeight;
  567.                         var6.y -= this.rowHeight;
  568.                         ++var1;
  569.                      }
  570.                   }
  571.  
  572.                   ((View)this).draw(var6);
  573.                }
  574.             }
  575.  
  576.             Rect.returnRect(var6);
  577.             this.dirtyItems = var5;
  578.             this.dirtyItems.removeAllElements();
  579.          }
  580.       }
  581.    }
  582.  
  583.    public void drawItemAt(int var1) {
  584.       Rect var2 = this.rectForItemAt(var1);
  585.       ((View)this).draw(var2);
  586.    }
  587.  
  588.    public void drawViewBackground(Graphics var1, int var2, int var3, int var4, int var5) {
  589.       if (!this.isTransparent() && this.backgroundColor != null) {
  590.          var1.setColor(this.backgroundColor);
  591.          var1.fillRect(var2, var3, var4, var5);
  592.       }
  593.  
  594.    }
  595.  
  596.    public void drawView(Graphics var1) {
  597.       if (this.dirtyItems != null) {
  598.          this.dirtyItems.removeAllElements();
  599.       }
  600.  
  601.       if (this.rowHeight <= 0) {
  602.          this.drawViewBackground(var1, 0, 0, super.bounds.width, super.bounds.height);
  603.       } else {
  604.          Rect var4 = Rect.newRect(var1.clipRect());
  605.          int var5 = this.items.size();
  606.          int var6 = var4.y / this.rowHeight;
  607.          if (var6 >= 0 && var6 < var5) {
  608.             Rect var3 = this.rectForItemAt(var6);
  609.  
  610.             boolean var7;
  611.             for(var7 = this.rectCompare(var4, var3) == 0; var6 < var5 && var7; var7 = this.rectCompare(var4, var3) == 0) {
  612.                var1.pushState();
  613.                var1.setClipRect(var3);
  614.                ListItem var2 = (ListItem)this.items.elementAt(var6);
  615.                if (!this.isTransparent() && var2.isTransparent()) {
  616.                   this.drawViewBackground(var1, var3.x, var3.y, super.bounds.width, this.rowHeight);
  617.                }
  618.  
  619.                var2.drawInRect(var1, var3);
  620.                var1.popState();
  621.                ++var6;
  622.                var3.moveBy(0, this.rowHeight);
  623.             }
  624.  
  625.             if (var7) {
  626.                int var8 = super.bounds.height - var3.y;
  627.                if (var8 > 0 && !this.isTransparent()) {
  628.                   this.drawViewBackground(var1, var3.x, var3.y, super.bounds.width, var8);
  629.                }
  630.             }
  631.  
  632.             Rect.returnRect(var4);
  633.          } else {
  634.             this.drawViewBackground(var1, 0, 0, super.bounds.width, super.bounds.height);
  635.             Rect.returnRect(var4);
  636.          }
  637.       }
  638.    }
  639.  
  640.    public void setTarget(Target var1) {
  641.       this.target = var1;
  642.    }
  643.  
  644.    public Target target() {
  645.       return this.target;
  646.    }
  647.  
  648.    public void setCommand(String var1) {
  649.       this.command = var1;
  650.    }
  651.  
  652.    public String command() {
  653.       return this.command;
  654.    }
  655.  
  656.    public void setDoubleCommand(String var1) {
  657.       this.doubleCommand = var1;
  658.    }
  659.  
  660.    public String doubleCommand() {
  661.       return this.doubleCommand;
  662.    }
  663.  
  664.    public void sendCommand() {
  665.       if (this.target != null) {
  666.          String var1 = null;
  667.          ListItem var2 = this.selectedItem();
  668.          if (var2 != null) {
  669.             var1 = var2.command();
  670.          }
  671.  
  672.          if (var1 == null) {
  673.             var1 = this.command;
  674.          }
  675.  
  676.          this.target.performCommand(var1, this);
  677.       }
  678.  
  679.    }
  680.  
  681.    public void sendDoubleCommand() {
  682.       if (this.target != null && this.doubleCommand != null) {
  683.          this.target.performCommand(this.doubleCommand, this);
  684.       }
  685.  
  686.    }
  687.  
  688.    public void performCommand(String var1, Object var2) {
  689.       if (SELECT_NEXT_ITEM.equals(var1)) {
  690.          this.selectNextItem(true);
  691.       } else {
  692.          if (SELECT_PREVIOUS_ITEM.equals(var1)) {
  693.             this.selectNextItem(false);
  694.          }
  695.  
  696.       }
  697.    }
  698.  
  699.    void selectNextItem(boolean var1) {
  700.       int var2 = this.selectedIndex();
  701.       int var3 = this.count();
  702.       if (var1) {
  703.          if (var2 < var3 - 1) {
  704.             this.selectItemAt(var2 + 1);
  705.             this.sendCommand();
  706.             return;
  707.          }
  708.       } else if (var2 > 0) {
  709.          this.selectItemAt(var2 - 1);
  710.          this.sendCommand();
  711.       }
  712.  
  713.    }
  714.  
  715.    public void describeClassInfo(ClassInfo var1) {
  716.       super.describeClassInfo(var1);
  717.       var1.addClass("netscape.application.ListView", 2);
  718.       var1.addField("protoItem", (byte)18);
  719.       var1.addField("anchorItem", (byte)18);
  720.       var1.addField("origSelectedItem", (byte)18);
  721.       var1.addField("items", (byte)18);
  722.       var1.addField("selectedItems", (byte)18);
  723.       var1.addField("dirtyItems", (byte)18);
  724.       var1.addField("command", (byte)16);
  725.       var1.addField("doubleCommand", (byte)16);
  726.       var1.addField("target", (byte)18);
  727.       var1.addField("backgroundColor", (byte)18);
  728.       var1.addField("rowHeight", (byte)8);
  729.       var1.addField("allowsMultipleSelection", (byte)0);
  730.       var1.addField("allowsEmptySelection", (byte)0);
  731.       var1.addField("tracksMouseOutsideBounds", (byte)0);
  732.       var1.addField("enabled", (byte)0);
  733.       var1.addField("isTransparent", (byte)0);
  734.    }
  735.  
  736.    public void encode(Encoder var1) throws CodingException {
  737.       super.encode(var1);
  738.       var1.encodeObject("protoItem", this.protoItem);
  739.       var1.encodeObject("anchorItem", this.anchorItem);
  740.       var1.encodeObject("origSelectedItem", this.origSelectedItem);
  741.       var1.encodeObject("items", this.items);
  742.       var1.encodeObject("selectedItems", this.selectedItems);
  743.       var1.encodeObject("dirtyItems", this.dirtyItems);
  744.       var1.encodeString("command", this.command);
  745.       var1.encodeString("doubleCommand", this.doubleCommand);
  746.       var1.encodeObject("target", this.target);
  747.       var1.encodeObject("backgroundColor", this.backgroundColor);
  748.       var1.encodeInt("rowHeight", this.rowHeight);
  749.       var1.encodeBoolean("allowsMultipleSelection", this.allowsMultipleSelection);
  750.       var1.encodeBoolean("allowsEmptySelection", this.allowsEmptySelection);
  751.       var1.encodeBoolean("tracksMouseOutsideBounds", this.tracksMouseOutsideBounds);
  752.       var1.encodeBoolean("enabled", this.enabled);
  753.       var1.encodeBoolean("isTransparent", this.transparent);
  754.    }
  755.  
  756.    public void decode(Decoder var1) throws CodingException {
  757.       super.decode(var1);
  758.       this.protoItem = (ListItem)var1.decodeObject("protoItem");
  759.       this.anchorItem = (ListItem)var1.decodeObject("anchorItem");
  760.       this.origSelectedItem = (ListItem)var1.decodeObject("origSelectedItem");
  761.       this.items = (Vector)var1.decodeObject("items");
  762.       this.selectedItems = (Vector)var1.decodeObject("selectedItems");
  763.       this.dirtyItems = (Vector)var1.decodeObject("dirtyItems");
  764.       this.command = var1.decodeString("command");
  765.       this.doubleCommand = var1.decodeString("doubleCommand");
  766.       this.target = (Target)var1.decodeObject("target");
  767.       this.backgroundColor = (Color)var1.decodeObject("backgroundColor");
  768.       this.rowHeight = var1.decodeInt("rowHeight");
  769.       this.allowsMultipleSelection = var1.decodeBoolean("allowsMultipleSelection");
  770.       this.allowsEmptySelection = var1.decodeBoolean("allowsEmptySelection");
  771.       this.tracksMouseOutsideBounds = var1.decodeBoolean("tracksMouseOutsideBounds");
  772.       this.enabled = var1.decodeBoolean("enabled");
  773.       if (var1.versionForClassName("netscape.application.ListView") > 1) {
  774.          this.transparent = var1.decodeBoolean("isTransparent");
  775.       } else {
  776.          this.transparent = false;
  777.       }
  778.    }
  779.  
  780.    void _setupKeyboard() {
  781.       ((View)this).removeAllCommandsForKeys();
  782.       ((View)this).setCommandForKey(SELECT_NEXT_ITEM, 1005, 0);
  783.       ((View)this).setCommandForKey(SELECT_PREVIOUS_ITEM, 1004, 0);
  784.    }
  785.  
  786.    public boolean canBecomeSelectedView() {
  787.       return this.isEnabled();
  788.    }
  789.  
  790.    public String formElementText() {
  791.       return this.selectedItem() != null ? this.selectedItem().title() : "";
  792.    }
  793. }
  794.