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 / DefaultListSelectionModel.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  5.8 KB  |  381 lines

  1. package javax.swing;
  2.  
  3. import java.io.Serializable;
  4. import java.util.BitSet;
  5. import java.util.EventListener;
  6. import javax.swing.event.EventListenerList;
  7. import javax.swing.event.ListSelectionEvent;
  8. import javax.swing.event.ListSelectionListener;
  9.  
  10. public class DefaultListSelectionModel implements ListSelectionModel, Cloneable, Serializable {
  11.    private static final int MIN = -1;
  12.    private static final int MAX = Integer.MAX_VALUE;
  13.    private int selectionMode = 2;
  14.    private int minIndex = Integer.MAX_VALUE;
  15.    private int maxIndex = -1;
  16.    private int anchorIndex = -1;
  17.    private int leadIndex = -1;
  18.    private int firstAdjustedIndex = Integer.MAX_VALUE;
  19.    private int lastAdjustedIndex = -1;
  20.    private boolean isAdjusting = false;
  21.    private int firstChangedIndex = Integer.MAX_VALUE;
  22.    private int lastChangedIndex = -1;
  23.    private BitSet value = new BitSet(32);
  24.    protected EventListenerList listenerList = new EventListenerList();
  25.    protected boolean leadAnchorNotificationEnabled = true;
  26.    // $FF: synthetic field
  27.    static Class class$javax$swing$event$ListSelectionListener;
  28.  
  29.    public int getMinSelectionIndex() {
  30.       return this.isSelectionEmpty() ? -1 : this.minIndex;
  31.    }
  32.  
  33.    public int getMaxSelectionIndex() {
  34.       return this.maxIndex;
  35.    }
  36.  
  37.    public boolean getValueIsAdjusting() {
  38.       return this.isAdjusting;
  39.    }
  40.  
  41.    public int getSelectionMode() {
  42.       return this.selectionMode;
  43.    }
  44.  
  45.    public void setSelectionMode(int var1) {
  46.       switch (var1) {
  47.          case 0:
  48.          case 1:
  49.          case 2:
  50.             this.selectionMode = var1;
  51.             return;
  52.          default:
  53.             throw new IllegalArgumentException("invalid selectionMode");
  54.       }
  55.    }
  56.  
  57.    public boolean isSelectedIndex(int var1) {
  58.       return var1 >= this.minIndex && var1 <= this.maxIndex ? this.value.get(var1) : false;
  59.    }
  60.  
  61.    public boolean isSelectionEmpty() {
  62.       return this.minIndex > this.maxIndex;
  63.    }
  64.  
  65.    public void addListSelectionListener(ListSelectionListener var1) {
  66.       this.listenerList.add(class$javax$swing$event$ListSelectionListener == null ? (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")) : class$javax$swing$event$ListSelectionListener, var1);
  67.    }
  68.  
  69.    public void removeListSelectionListener(ListSelectionListener var1) {
  70.       this.listenerList.remove(class$javax$swing$event$ListSelectionListener == null ? (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")) : class$javax$swing$event$ListSelectionListener, var1);
  71.    }
  72.  
  73.    protected void fireValueChanged(boolean var1) {
  74.       if (this.lastChangedIndex != -1) {
  75.          int var2 = this.firstChangedIndex;
  76.          int var3 = this.lastChangedIndex;
  77.          this.firstChangedIndex = Integer.MAX_VALUE;
  78.          this.lastChangedIndex = -1;
  79.          this.fireValueChanged(var2, var3, var1);
  80.       }
  81.    }
  82.  
  83.    protected void fireValueChanged(int var1, int var2) {
  84.       this.fireValueChanged(var1, var2, this.getValueIsAdjusting());
  85.    }
  86.  
  87.    protected void fireValueChanged(int var1, int var2, boolean var3) {
  88.       Object[] var4 = this.listenerList.getListenerList();
  89.       ListSelectionEvent var5 = null;
  90.  
  91.       for(int var6 = var4.length - 2; var6 >= 0; var6 -= 2) {
  92.          if (var4[var6] == (class$javax$swing$event$ListSelectionListener == null ? (class$javax$swing$event$ListSelectionListener = class$("javax.swing.event.ListSelectionListener")) : class$javax$swing$event$ListSelectionListener)) {
  93.             if (var5 == null) {
  94.                var5 = new ListSelectionEvent(this, var1, var2, var3);
  95.             }
  96.  
  97.             ((ListSelectionListener)var4[var6 + 1]).valueChanged(var5);
  98.          }
  99.       }
  100.  
  101.    }
  102.  
  103.    private void fireValueChanged() {
  104.       if (this.lastAdjustedIndex != -1) {
  105.          if (this.getValueIsAdjusting()) {
  106.             this.firstChangedIndex = Math.min(this.firstChangedIndex, this.firstAdjustedIndex);
  107.             this.lastChangedIndex = Math.max(this.lastChangedIndex, this.lastAdjustedIndex);
  108.          }
  109.  
  110.          int var1 = this.firstAdjustedIndex;
  111.          int var2 = this.lastAdjustedIndex;
  112.          this.firstAdjustedIndex = Integer.MAX_VALUE;
  113.          this.lastAdjustedIndex = -1;
  114.          this.fireValueChanged(var1, var2);
  115.       }
  116.    }
  117.  
  118.    public EventListener[] getListeners(Class var1) {
  119.       return this.listenerList.getListeners(var1);
  120.    }
  121.  
  122.    private void markAsDirty(int var1) {
  123.       this.firstAdjustedIndex = Math.min(this.firstAdjustedIndex, var1);
  124.       this.lastAdjustedIndex = Math.max(this.lastAdjustedIndex, var1);
  125.    }
  126.  
  127.    private void set(int var1) {
  128.       if (!this.value.get(var1)) {
  129.          this.value.set(var1);
  130.          this.markAsDirty(var1);
  131.          this.minIndex = Math.min(this.minIndex, var1);
  132.          this.maxIndex = Math.max(this.maxIndex, var1);
  133.       }
  134.    }
  135.  
  136.    private void clear(int var1) {
  137.       if (this.value.get(var1)) {
  138.          this.value.clear(var1);
  139.          this.markAsDirty(var1);
  140.          if (var1 == this.minIndex) {
  141.             ++this.minIndex;
  142.  
  143.             while(this.minIndex <= this.maxIndex && !this.value.get(this.minIndex)) {
  144.                ++this.minIndex;
  145.             }
  146.          }
  147.  
  148.          if (var1 == this.maxIndex) {
  149.             --this.maxIndex;
  150.  
  151.             while(this.minIndex <= this.maxIndex && !this.value.get(this.maxIndex)) {
  152.                --this.maxIndex;
  153.             }
  154.          }
  155.  
  156.          if (this.isSelectionEmpty()) {
  157.             this.minIndex = Integer.MAX_VALUE;
  158.             this.maxIndex = -1;
  159.          }
  160.  
  161.       }
  162.    }
  163.  
  164.    public void setLeadAnchorNotificationEnabled(boolean var1) {
  165.       this.leadAnchorNotificationEnabled = var1;
  166.    }
  167.  
  168.    public boolean isLeadAnchorNotificationEnabled() {
  169.       return this.leadAnchorNotificationEnabled;
  170.    }
  171.  
  172.    private void updateLeadAnchorIndices(int var1, int var2) {
  173.       if (this.leadAnchorNotificationEnabled) {
  174.          if (this.anchorIndex != var1) {
  175.             if (this.anchorIndex != -1) {
  176.                this.markAsDirty(this.anchorIndex);
  177.             }
  178.  
  179.             this.markAsDirty(var1);
  180.          }
  181.  
  182.          if (this.leadIndex != var2) {
  183.             if (this.leadIndex != -1) {
  184.                this.markAsDirty(this.leadIndex);
  185.             }
  186.  
  187.             this.markAsDirty(var2);
  188.          }
  189.       }
  190.  
  191.       this.anchorIndex = var1;
  192.       this.leadIndex = var2;
  193.    }
  194.  
  195.    private boolean contains(int var1, int var2, int var3) {
  196.       return var3 >= var1 && var3 <= var2;
  197.    }
  198.  
  199.    private void changeSelection(int var1, int var2, int var3, int var4, boolean var5) {
  200.       for(int var6 = Math.min(var3, var1); var6 <= Math.max(var4, var2); ++var6) {
  201.          boolean var7 = this.contains(var1, var2, var6);
  202.          boolean var8 = this.contains(var3, var4, var6);
  203.          if (var8 && var7) {
  204.             if (var5) {
  205.                var7 = false;
  206.             } else {
  207.                var8 = false;
  208.             }
  209.          }
  210.  
  211.          if (var8) {
  212.             this.set(var6);
  213.          }
  214.  
  215.          if (var7) {
  216.             this.clear(var6);
  217.          }
  218.       }
  219.  
  220.       this.fireValueChanged();
  221.    }
  222.  
  223.    private void changeSelection(int var1, int var2, int var3, int var4) {
  224.       this.changeSelection(var1, var2, var3, var4, true);
  225.    }
  226.  
  227.    public void clearSelection() {
  228.       this.removeSelectionInterval(this.minIndex, this.maxIndex);
  229.    }
  230.  
  231.    public void setSelectionInterval(int var1, int var2) {
  232.       if (var1 != -1 && var2 != -1) {
  233.          if (this.getSelectionMode() == 0) {
  234.             var1 = var2;
  235.          }
  236.  
  237.          this.updateLeadAnchorIndices(var1, var2);
  238.          int var3 = this.minIndex;
  239.          int var4 = this.maxIndex;
  240.          int var5 = Math.min(var1, var2);
  241.          int var6 = Math.max(var1, var2);
  242.          this.changeSelection(var3, var4, var5, var6);
  243.       }
  244.    }
  245.  
  246.    public void addSelectionInterval(int var1, int var2) {
  247.       if (var1 != -1 && var2 != -1) {
  248.          if (this.getSelectionMode() != 2) {
  249.             this.setSelectionInterval(var1, var2);
  250.          } else {
  251.             this.updateLeadAnchorIndices(var1, var2);
  252.             int var3 = Integer.MAX_VALUE;
  253.             byte var4 = -1;
  254.             int var5 = Math.min(var1, var2);
  255.             int var6 = Math.max(var1, var2);
  256.             this.changeSelection(var3, var4, var5, var6);
  257.          }
  258.       }
  259.    }
  260.  
  261.    public void removeSelectionInterval(int var1, int var2) {
  262.       if (var1 != -1 && var2 != -1) {
  263.          this.updateLeadAnchorIndices(var1, var2);
  264.          int var3 = Math.min(var1, var2);
  265.          int var4 = Math.max(var1, var2);
  266.          int var5 = Integer.MAX_VALUE;
  267.          byte var6 = -1;
  268.          if (this.getSelectionMode() != 2 && var3 > this.minIndex && var4 < this.maxIndex) {
  269.             var4 = this.maxIndex;
  270.          }
  271.  
  272.          this.changeSelection(var3, var4, var5, var6);
  273.       }
  274.    }
  275.  
  276.    private void setState(int var1, boolean var2) {
  277.       if (var2) {
  278.          this.set(var1);
  279.       } else {
  280.          this.clear(var1);
  281.       }
  282.  
  283.    }
  284.  
  285.    public void insertIndexInterval(int var1, int var2, boolean var3) {
  286.       int var4 = var3 ? var1 : var1 + 1;
  287.       int var5 = var4 + var2 - 1;
  288.  
  289.       for(int var6 = this.maxIndex; var6 >= var4; --var6) {
  290.          this.setState(var6 + var2, this.value.get(var6));
  291.       }
  292.  
  293.       boolean var7 = this.value.get(var1);
  294.  
  295.       for(int var8 = var4; var8 <= var5; ++var8) {
  296.          this.setState(var8, var7);
  297.       }
  298.  
  299.    }
  300.  
  301.    public void removeIndexInterval(int var1, int var2) {
  302.       int var3 = Math.min(var1, var2);
  303.       int var4 = Math.max(var1, var2);
  304.       int var5 = var4 - var3 + 1;
  305.  
  306.       for(int var6 = var3; var6 <= this.maxIndex; ++var6) {
  307.          this.setState(var6, this.value.get(var6 + var5));
  308.       }
  309.  
  310.    }
  311.  
  312.    public void setValueIsAdjusting(boolean var1) {
  313.       if (var1 != this.isAdjusting) {
  314.          this.isAdjusting = var1;
  315.          this.fireValueChanged(var1);
  316.       }
  317.  
  318.    }
  319.  
  320.    public String toString() {
  321.       String var1 = (this.getValueIsAdjusting() ? "~" : "=") + this.value.toString();
  322.       return this.getClass().getName() + " " + Integer.toString(this.hashCode()) + " " + var1;
  323.    }
  324.  
  325.    public Object clone() throws CloneNotSupportedException {
  326.       DefaultListSelectionModel var1 = (DefaultListSelectionModel)super.clone();
  327.       var1.value = (BitSet)this.value.clone();
  328.       var1.listenerList = new EventListenerList();
  329.       return var1;
  330.    }
  331.  
  332.    public int getAnchorSelectionIndex() {
  333.       return this.anchorIndex;
  334.    }
  335.  
  336.    public int getLeadSelectionIndex() {
  337.       return this.leadIndex;
  338.    }
  339.  
  340.    public void setAnchorSelectionIndex(int var1) {
  341.       this.updateLeadAnchorIndices(var1, this.leadIndex);
  342.       this.anchorIndex = var1;
  343.       this.fireValueChanged();
  344.    }
  345.  
  346.    public void setLeadSelectionIndex(int var1) {
  347.       int var2 = this.anchorIndex;
  348.       if (var2 != -1 && var1 != -1) {
  349.          if (this.leadIndex == -1) {
  350.             this.leadIndex = var1;
  351.          }
  352.  
  353.          if (this.getSelectionMode() == 0) {
  354.             var2 = var1;
  355.          }
  356.  
  357.          int var3 = Math.min(this.anchorIndex, this.leadIndex);
  358.          int var4 = Math.max(this.anchorIndex, this.leadIndex);
  359.          int var5 = Math.min(var2, var1);
  360.          int var6 = Math.max(var2, var1);
  361.          if (this.value.get(this.anchorIndex)) {
  362.             this.changeSelection(var3, var4, var5, var6);
  363.          } else {
  364.             this.changeSelection(var5, var6, var3, var4, false);
  365.          }
  366.  
  367.          this.anchorIndex = var2;
  368.          this.leadIndex = var1;
  369.       }
  370.    }
  371.  
  372.    // $FF: synthetic method
  373.    static Class class$(String var0) {
  374.       try {
  375.          return Class.forName(var0);
  376.       } catch (ClassNotFoundException var2) {
  377.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  378.       }
  379.    }
  380. }
  381.