home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 144 / DPCS0200.iso / Internet / Supanet / system / swing.jar / javax / swing / text / html / OptionListModel.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  7.1 KB  |  372 lines

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