home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / JList.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  11.6 KB  |  552 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Dimension;
  7. import java.awt.Font;
  8. import java.awt.Insets;
  9. import java.awt.Point;
  10. import java.awt.Rectangle;
  11. import java.io.IOException;
  12. import java.io.ObjectOutputStream;
  13. import java.util.Vector;
  14. import javax.accessibility.Accessible;
  15. import javax.accessibility.AccessibleContext;
  16. import javax.swing.event.ListSelectionEvent;
  17. import javax.swing.event.ListSelectionListener;
  18. import javax.swing.plaf.ListUI;
  19.  
  20. public class JList extends JComponent implements Scrollable, Accessible {
  21.    private static final String uiClassID = "ListUI";
  22.    private int fixedCellWidth;
  23.    private int fixedCellHeight;
  24.    private int horizontalScrollIncrement;
  25.    private Object prototypeCellValue;
  26.    private int visibleRowCount;
  27.    private Color selectionForeground;
  28.    private Color selectionBackground;
  29.    private ListSelectionModel selectionModel;
  30.    private ListModel dataModel;
  31.    private ListCellRenderer cellRenderer;
  32.    private ListSelectionListener selectionListener;
  33.    // $FF: synthetic field
  34.    static Class class$javax$swing$event$ListSelectionListener;
  35.  
  36.    public JList(ListModel var1) {
  37.       this.fixedCellWidth = -1;
  38.       this.fixedCellHeight = -1;
  39.       this.horizontalScrollIncrement = -1;
  40.       this.visibleRowCount = 8;
  41.       if (var1 == null) {
  42.          throw new IllegalArgumentException("dataModel must be non null");
  43.       } else {
  44.          this.dataModel = var1;
  45.          this.selectionModel = this.createSelectionModel();
  46.          ((JComponent)this).setAutoscrolls(true);
  47.          ((JComponent)this).setOpaque(true);
  48.          this.updateUI();
  49.       }
  50.    }
  51.  
  52.    public JList(Object[] var1) {
  53.       this((ListModel)(new 1(var1)));
  54.    }
  55.  
  56.    public JList(Vector var1) {
  57.       this((ListModel)(new 2(var1)));
  58.    }
  59.  
  60.    public JList() {
  61.       this((ListModel)(new 3()));
  62.    }
  63.  
  64.    public ListUI getUI() {
  65.       return (ListUI)super.ui;
  66.    }
  67.  
  68.    public void setUI(ListUI var1) {
  69.       super.setUI(var1);
  70.    }
  71.  
  72.    public void updateUI() {
  73.       this.setUI((ListUI)UIManager.getUI(this));
  74.       ((Container)this).invalidate();
  75.    }
  76.  
  77.    public String getUIClassID() {
  78.       return "ListUI";
  79.    }
  80.  
  81.    private void updateFixedCellSize() {
  82.       ListCellRenderer var1 = this.getCellRenderer();
  83.       Object var2 = this.getPrototypeCellValue();
  84.       if (var1 != null && var2 != null) {
  85.          Component var3 = var1.getListCellRendererComponent(this, var2, 0, false, false);
  86.          Font var4 = var3.getFont();
  87.          var3.setFont(((Component)this).getFont());
  88.          Dimension var5 = var3.getPreferredSize();
  89.          this.fixedCellWidth = var5.width;
  90.          this.fixedCellHeight = var5.height;
  91.          var3.setFont(var4);
  92.       }
  93.  
  94.    }
  95.  
  96.    public Object getPrototypeCellValue() {
  97.       return this.prototypeCellValue;
  98.    }
  99.  
  100.    public void setPrototypeCellValue(Object var1) {
  101.       Object var2 = this.prototypeCellValue;
  102.       this.prototypeCellValue = var1;
  103.       if (var1 != null && !var1.equals(var2)) {
  104.          this.updateFixedCellSize();
  105.       }
  106.  
  107.       ((JComponent)this).firePropertyChange("prototypeCellValue", var2, var1);
  108.    }
  109.  
  110.    public int getFixedCellWidth() {
  111.       return this.fixedCellWidth;
  112.    }
  113.  
  114.    public void setFixedCellWidth(int var1) {
  115.       int var2 = this.fixedCellWidth;
  116.       this.fixedCellWidth = var1;
  117.       ((JComponent)this).firePropertyChange("fixedCellWidth", var2, this.fixedCellWidth);
  118.    }
  119.  
  120.    public int getFixedCellHeight() {
  121.       return this.fixedCellHeight;
  122.    }
  123.  
  124.    public void setFixedCellHeight(int var1) {
  125.       int var2 = this.fixedCellHeight;
  126.       this.fixedCellHeight = var1;
  127.       ((JComponent)this).firePropertyChange("fixedCellHeight", var2, this.fixedCellHeight);
  128.    }
  129.  
  130.    public ListCellRenderer getCellRenderer() {
  131.       return this.cellRenderer;
  132.    }
  133.  
  134.    public void setCellRenderer(ListCellRenderer var1) {
  135.       ListCellRenderer var2 = this.cellRenderer;
  136.       this.cellRenderer = var1;
  137.       if (var1 != null && !var1.equals(var2)) {
  138.          this.updateFixedCellSize();
  139.       }
  140.  
  141.       ((JComponent)this).firePropertyChange("cellRenderer", var2, var1);
  142.    }
  143.  
  144.    public Color getSelectionForeground() {
  145.       return this.selectionForeground;
  146.    }
  147.  
  148.    public void setSelectionForeground(Color var1) {
  149.       Color var2 = this.selectionForeground;
  150.       this.selectionForeground = var1;
  151.       ((JComponent)this).firePropertyChange("selectionForeground", var2, var1);
  152.    }
  153.  
  154.    public Color getSelectionBackground() {
  155.       return this.selectionBackground;
  156.    }
  157.  
  158.    public void setSelectionBackground(Color var1) {
  159.       Color var2 = this.selectionBackground;
  160.       this.selectionBackground = var1;
  161.       ((JComponent)this).firePropertyChange("selectionBackground", var2, var1);
  162.    }
  163.  
  164.    public int getVisibleRowCount() {
  165.       return this.visibleRowCount;
  166.    }
  167.  
  168.    public void setVisibleRowCount(int var1) {
  169.       int var2 = this.visibleRowCount;
  170.       this.visibleRowCount = Math.max(0, var1);
  171.       ((JComponent)this).firePropertyChange("visibleRowCount", var2, var1);
  172.    }
  173.  
  174.    public int getFirstVisibleIndex() {
  175.       Point var1 = ((JComponent)this).getVisibleRect().getLocation();
  176.       return this.locationToIndex(var1);
  177.    }
  178.  
  179.    public int getLastVisibleIndex() {
  180.       Rectangle var1 = ((JComponent)this).getVisibleRect();
  181.       Point var2 = new Point(var1.x + var1.width - 1, var1.y + var1.height - 1);
  182.       return this.locationToIndex(var2);
  183.    }
  184.  
  185.    public void ensureIndexIsVisible(int var1) {
  186.       Rectangle var2 = this.getCellBounds(var1, var1);
  187.       if (var2 != null) {
  188.          ((JComponent)this).scrollRectToVisible(var2);
  189.       }
  190.  
  191.    }
  192.  
  193.    public int locationToIndex(Point var1) {
  194.       ListUI var2 = this.getUI();
  195.       return var2 != null ? var2.locationToIndex(this, var1) : -1;
  196.    }
  197.  
  198.    public Point indexToLocation(int var1) {
  199.       ListUI var2 = this.getUI();
  200.       return var2 != null ? var2.indexToLocation(this, var1) : null;
  201.    }
  202.  
  203.    public Rectangle getCellBounds(int var1, int var2) {
  204.       ListUI var3 = this.getUI();
  205.       return var3 != null ? var3.getCellBounds(this, var1, var2) : null;
  206.    }
  207.  
  208.    public ListModel getModel() {
  209.       return this.dataModel;
  210.    }
  211.  
  212.    public void setModel(ListModel var1) {
  213.       if (var1 == null) {
  214.          throw new IllegalArgumentException("model must be non null");
  215.       } else {
  216.          ListModel var2 = this.dataModel;
  217.          this.dataModel = var1;
  218.          ((JComponent)this).firePropertyChange("model", var2, this.dataModel);
  219.          this.clearSelection();
  220.       }
  221.    }
  222.  
  223.    public void setListData(Object[] var1) {
  224.       this.setModel(new 4(this, var1));
  225.    }
  226.  
  227.    public void setListData(Vector var1) {
  228.       this.setModel(new 5(this, var1));
  229.    }
  230.  
  231.    protected ListSelectionModel createSelectionModel() {
  232.       return new DefaultListSelectionModel();
  233.    }
  234.  
  235.    public ListSelectionModel getSelectionModel() {
  236.       return this.selectionModel;
  237.    }
  238.  
  239.    protected void fireSelectionValueChanged(int var1, int var2, boolean var3) {
  240.       Object[] var4 = super.listenerList.getListenerList();
  241.       ListSelectionEvent var5 = null;
  242.  
  243.       for(int var6 = var4.length - 2; var6 >= 0; var6 -= 2) {
  244.          if (var4[var6] == (class$javax$swing$event$ListSelectionListener == null ? (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")) : class$javax$swing$event$ListSelectionListener)) {
  245.             if (var5 == null) {
  246.                var5 = new ListSelectionEvent(this, var1, var2, var3);
  247.             }
  248.  
  249.             ((ListSelectionListener)var4[var6 + 1]).valueChanged(var5);
  250.          }
  251.       }
  252.  
  253.    }
  254.  
  255.    public void addListSelectionListener(ListSelectionListener var1) {
  256.       if (this.selectionListener == null) {
  257.          this.selectionListener = new ListSelectionHandler(this, (1)null);
  258.          this.getSelectionModel().addListSelectionListener(this.selectionListener);
  259.       }
  260.  
  261.       super.listenerList.add(class$javax$swing$event$ListSelectionListener == null ? (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")) : class$javax$swing$event$ListSelectionListener, var1);
  262.    }
  263.  
  264.    public void removeListSelectionListener(ListSelectionListener var1) {
  265.       super.listenerList.remove(class$javax$swing$event$ListSelectionListener == null ? (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")) : class$javax$swing$event$ListSelectionListener, var1);
  266.    }
  267.  
  268.    public void setSelectionModel(ListSelectionModel var1) {
  269.       if (var1 == null) {
  270.          throw new IllegalArgumentException("selectionModel must be non null");
  271.       } else {
  272.          if (this.selectionListener != null) {
  273.             this.selectionModel.removeListSelectionListener(this.selectionListener);
  274.             var1.addListSelectionListener(this.selectionListener);
  275.          }
  276.  
  277.          ListSelectionModel var2 = this.selectionModel;
  278.          this.selectionModel = var1;
  279.          ((JComponent)this).firePropertyChange("selectionModel", var2, var1);
  280.       }
  281.    }
  282.  
  283.    public void setSelectionMode(int var1) {
  284.       this.getSelectionModel().setSelectionMode(var1);
  285.    }
  286.  
  287.    public int getSelectionMode() {
  288.       return this.getSelectionModel().getSelectionMode();
  289.    }
  290.  
  291.    public int getAnchorSelectionIndex() {
  292.       return this.getSelectionModel().getAnchorSelectionIndex();
  293.    }
  294.  
  295.    public int getLeadSelectionIndex() {
  296.       return this.getSelectionModel().getLeadSelectionIndex();
  297.    }
  298.  
  299.    public int getMinSelectionIndex() {
  300.       return this.getSelectionModel().getMinSelectionIndex();
  301.    }
  302.  
  303.    public int getMaxSelectionIndex() {
  304.       return this.getSelectionModel().getMaxSelectionIndex();
  305.    }
  306.  
  307.    public boolean isSelectedIndex(int var1) {
  308.       return this.getSelectionModel().isSelectedIndex(var1);
  309.    }
  310.  
  311.    public boolean isSelectionEmpty() {
  312.       return this.getSelectionModel().isSelectionEmpty();
  313.    }
  314.  
  315.    public void clearSelection() {
  316.       this.getSelectionModel().clearSelection();
  317.    }
  318.  
  319.    public void setSelectionInterval(int var1, int var2) {
  320.       this.getSelectionModel().setSelectionInterval(var1, var2);
  321.    }
  322.  
  323.    public void addSelectionInterval(int var1, int var2) {
  324.       this.getSelectionModel().addSelectionInterval(var1, var2);
  325.    }
  326.  
  327.    public void removeSelectionInterval(int var1, int var2) {
  328.       this.getSelectionModel().removeSelectionInterval(var1, var2);
  329.    }
  330.  
  331.    public void setValueIsAdjusting(boolean var1) {
  332.       this.getSelectionModel().setValueIsAdjusting(var1);
  333.    }
  334.  
  335.    public boolean getValueIsAdjusting() {
  336.       return this.getSelectionModel().getValueIsAdjusting();
  337.    }
  338.  
  339.    public int[] getSelectedIndices() {
  340.       ListSelectionModel var1 = this.getSelectionModel();
  341.       int var2 = var1.getMinSelectionIndex();
  342.       int var3 = var1.getMaxSelectionIndex();
  343.       if (var2 >= 0 && var3 >= 0) {
  344.          int[] var4 = new int[1 + (var3 - var2)];
  345.          int var5 = 0;
  346.  
  347.          for(int var6 = var2; var6 <= var3; ++var6) {
  348.             if (var1.isSelectedIndex(var6)) {
  349.                var4[var5++] = var6;
  350.             }
  351.          }
  352.  
  353.          int[] var7 = new int[var5];
  354.          System.arraycopy(var4, 0, var7, 0, var5);
  355.          return var7;
  356.       } else {
  357.          return new int[0];
  358.       }
  359.    }
  360.  
  361.    public void setSelectedIndex(int var1) {
  362.       this.getSelectionModel().setSelectionInterval(var1, var1);
  363.    }
  364.  
  365.    public void setSelectedIndices(int[] var1) {
  366.       ListSelectionModel var2 = this.getSelectionModel();
  367.       var2.clearSelection();
  368.  
  369.       for(int var3 = 0; var3 < var1.length; ++var3) {
  370.          var2.addSelectionInterval(var1[var3], var1[var3]);
  371.       }
  372.  
  373.    }
  374.  
  375.    public Object[] getSelectedValues() {
  376.       ListSelectionModel var1 = this.getSelectionModel();
  377.       ListModel var2 = this.getModel();
  378.       int var3 = var1.getMinSelectionIndex();
  379.       int var4 = var1.getMaxSelectionIndex();
  380.       if (var3 >= 0 && var4 >= 0) {
  381.          Object[] var5 = new Object[1 + (var4 - var3)];
  382.          int var6 = 0;
  383.  
  384.          for(int var7 = var3; var7 <= var4; ++var7) {
  385.             if (var1.isSelectedIndex(var7)) {
  386.                var5[var6++] = var2.getElementAt(var7);
  387.             }
  388.          }
  389.  
  390.          Object[] var8 = new Object[var6];
  391.          System.arraycopy(var5, 0, var8, 0, var6);
  392.          return var8;
  393.       } else {
  394.          return new Object[0];
  395.       }
  396.    }
  397.  
  398.    public int getSelectedIndex() {
  399.       return this.getMinSelectionIndex();
  400.    }
  401.  
  402.    public Object getSelectedValue() {
  403.       int var1 = this.getMinSelectionIndex();
  404.       return var1 == -1 ? null : this.getModel().getElementAt(var1);
  405.    }
  406.  
  407.    public void setSelectedValue(Object var1, boolean var2) {
  408.       if (var1 == null) {
  409.          this.setSelectedIndex(-1);
  410.       } else if (!var1.equals(this.getSelectedValue())) {
  411.          ListModel var5 = this.getModel();
  412.          int var3 = 0;
  413.  
  414.          for(int var4 = var5.getSize(); var3 < var4; ++var3) {
  415.             if (var1.equals(var5.getElementAt(var3))) {
  416.                this.setSelectedIndex(var3);
  417.                if (var2) {
  418.                   this.ensureIndexIsVisible(var3);
  419.                }
  420.  
  421.                ((Component)this).repaint();
  422.                return;
  423.             }
  424.          }
  425.  
  426.          this.setSelectedIndex(-1);
  427.       }
  428.  
  429.       ((Component)this).repaint();
  430.    }
  431.  
  432.    private void checkScrollableParameters(Rectangle var1, int var2) {
  433.       if (var1 == null) {
  434.          throw new IllegalArgumentException("visibleRect must be non-null");
  435.       } else {
  436.          switch (var2) {
  437.             case 0:
  438.             case 1:
  439.                return;
  440.             default:
  441.                throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
  442.          }
  443.       }
  444.    }
  445.  
  446.    public Dimension getPreferredScrollableViewportSize() {
  447.       Insets var1 = ((JComponent)this).getInsets();
  448.       int var2 = var1.left + var1.right;
  449.       int var3 = var1.top + var1.bottom;
  450.       int var4 = this.getVisibleRowCount();
  451.       int var5 = this.getFixedCellWidth();
  452.       int var6 = this.getFixedCellHeight();
  453.       if (var5 > 0 && var6 > 0) {
  454.          int var12 = var5 + var2;
  455.          int var13 = var4 * var6 + var3;
  456.          return new Dimension(var12, var13);
  457.       } else if (this.getModel().getSize() > 0) {
  458.          int var7 = ((JComponent)this).getPreferredSize().width;
  459.          Rectangle var8 = this.getCellBounds(0, 0);
  460.          int var9 = var4 * var8.height + var3;
  461.          return new Dimension(var7, var9);
  462.       } else {
  463.          var5 = var5 > 0 ? var5 : 256;
  464.          var6 = var6 > 0 ? var6 : 16;
  465.          return new Dimension(var5, var6 * var4);
  466.       }
  467.    }
  468.  
  469.    public int getScrollableUnitIncrement(Rectangle var1, int var2, int var3) {
  470.       this.checkScrollableParameters(var1, var2);
  471.       if (var2 == 0) {
  472.          Font var7 = ((Component)this).getFont();
  473.          return var7 != null ? var7.getSize() : 1;
  474.       } else {
  475.          int var4 = this.getFirstVisibleIndex();
  476.          if (var4 == -1) {
  477.             return 0;
  478.          } else if (var3 > 0) {
  479.             Rectangle var8 = this.getCellBounds(var4, var4);
  480.             return var8 == null ? 0 : var8.height - (var1.y - var8.y);
  481.          } else {
  482.             Rectangle var5 = this.getCellBounds(var4, var4);
  483.             if (var5.y == var1.y && var4 == 0) {
  484.                return 0;
  485.             } else if (var5.y == var1.y) {
  486.                Rectangle var6 = this.getCellBounds(var4 - 1, var4 - 1);
  487.                return var6 == null ? 0 : var6.height;
  488.             } else {
  489.                return var1.y - var5.y;
  490.             }
  491.          }
  492.       }
  493.    }
  494.  
  495.    public int getScrollableBlockIncrement(Rectangle var1, int var2, int var3) {
  496.       this.checkScrollableParameters(var1, var2);
  497.       return var2 == 1 ? var1.height : var1.width;
  498.    }
  499.  
  500.    public boolean getScrollableTracksViewportWidth() {
  501.       if (((Component)this).getParent() instanceof JViewport) {
  502.          return ((JViewport)((Component)this).getParent()).getWidth() > ((JComponent)this).getPreferredSize().width;
  503.       } else {
  504.          return false;
  505.       }
  506.    }
  507.  
  508.    public boolean getScrollableTracksViewportHeight() {
  509.       if (((Component)this).getParent() instanceof JViewport) {
  510.          return ((JViewport)((Component)this).getParent()).getHeight() > ((JComponent)this).getPreferredSize().height;
  511.       } else {
  512.          return false;
  513.       }
  514.    }
  515.  
  516.    private void writeObject(ObjectOutputStream var1) throws IOException {
  517.       var1.defaultWriteObject();
  518.       if (super.ui != null && this.getUIClassID().equals("ListUI")) {
  519.          super.ui.installUI(this);
  520.       }
  521.  
  522.    }
  523.  
  524.    protected String paramString() {
  525.       String var1 = this.selectionForeground != null ? this.selectionForeground.toString() : "";
  526.       String var2 = this.selectionBackground != null ? this.selectionBackground.toString() : "";
  527.       return super.paramString() + ",fixedCellHeight=" + this.fixedCellHeight + ",fixedCellWidth=" + this.fixedCellWidth + ",horizontalScrollIncrement=" + this.horizontalScrollIncrement + ",selectionBackground=" + var2 + ",selectionForeground=" + var1 + ",visibleRowCount=" + this.visibleRowCount;
  528.    }
  529.  
  530.    public AccessibleContext getAccessibleContext() {
  531.       if (super.accessibleContext == null) {
  532.          super.accessibleContext = new AccessibleJList(this);
  533.       }
  534.  
  535.       return super.accessibleContext;
  536.    }
  537.  
  538.    // $FF: synthetic method
  539.    static Class class$(String var0) {
  540.       try {
  541.          return Class.forName(var0);
  542.       } catch (ClassNotFoundException var2) {
  543.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  544.       }
  545.    }
  546.  
  547.    // $FF: synthetic method
  548.    static ListSelectionModel access$100(JList var0) {
  549.       return var0.selectionModel;
  550.    }
  551. }
  552.