home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import com.sun.java.swing.event.EventListenerList;
- import com.sun.java.swing.event.ListSelectionEvent;
- import com.sun.java.swing.event.ListSelectionListener;
- import java.io.Serializable;
- import java.util.BitSet;
-
- public class DefaultListSelectionModel implements ListSelectionModel, Cloneable, Serializable {
- private int selectionMode = 2;
- private int minIndex = -1;
- private int maxIndex = -1;
- private int anchorIndex = -1;
- private int leadIndex = -1;
- private int firstChangedIndex = -1;
- private int lastChangedIndex = -1;
- private boolean isAdjusting = false;
- protected BitSet value = new BitSet(32);
- protected EventListenerList listenerList = new EventListenerList();
- protected boolean leadAnchorNotificationEnabled = true;
- // $FF: synthetic field
- static Class class$com$sun$java$swing$event$ListSelectionListener;
-
- public int getMinSelectionIndex() {
- return this.minIndex;
- }
-
- public int getMaxSelectionIndex() {
- return this.maxIndex;
- }
-
- public boolean getValueIsAdjusting() {
- return this.isAdjusting;
- }
-
- public int getSelectionMode() {
- return this.selectionMode;
- }
-
- public void setSelectionMode(int var1) {
- switch (var1) {
- case 0:
- case 1:
- case 2:
- this.selectionMode = var1;
- return;
- default:
- throw new IllegalArgumentException("invalid selectionMode");
- }
- }
-
- public boolean isSelectedIndex(int var1) {
- return var1 != -1 && var1 >= this.minIndex && var1 <= this.maxIndex ? this.value.get(var1) : false;
- }
-
- public boolean isSelectionEmpty() {
- return this.minIndex == -1 && this.maxIndex == -1;
- }
-
- public void addListSelectionListener(ListSelectionListener var1) {
- this.listenerList.add(class$com$sun$java$swing$event$ListSelectionListener != null ? class$com$sun$java$swing$event$ListSelectionListener : (class$com$sun$java$swing$event$ListSelectionListener = class$("com.sun.java.swing.event.ListSelectionListener")), var1);
- }
-
- public void removeListSelectionListener(ListSelectionListener var1) {
- this.listenerList.remove(class$com$sun$java$swing$event$ListSelectionListener != null ? class$com$sun$java$swing$event$ListSelectionListener : (class$com$sun$java$swing$event$ListSelectionListener = class$("com.sun.java.swing.event.ListSelectionListener")), var1);
- }
-
- protected void fireValueChanged(boolean var1) {
- this.fireValueChanged(this.getMinSelectionIndex(), this.getMaxSelectionIndex(), var1);
- }
-
- protected void fireValueChanged(int var1, int var2) {
- this.fireValueChanged(var1, var2, this.getValueIsAdjusting());
- }
-
- protected void fireValueChanged(int var1, int var2, boolean var3) {
- Object[] var4 = this.listenerList.getListenerList();
- ListSelectionEvent var5 = null;
-
- for(int var6 = var4.length - 2; var6 >= 0; var6 -= 2) {
- if (var4[var6] == (class$com$sun$java$swing$event$ListSelectionListener != null ? class$com$sun$java$swing$event$ListSelectionListener : (class$com$sun$java$swing$event$ListSelectionListener = class$("com.sun.java.swing.event.ListSelectionListener")))) {
- if (var5 == null) {
- var5 = new ListSelectionEvent(this, var1, var2, var3);
- }
-
- ((ListSelectionListener)var4[var6 + 1]).valueChanged(var5);
- }
- }
-
- }
-
- public void clearSelection() {
- if (this.minIndex != -1 && this.maxIndex != -1) {
- boolean var1 = false;
-
- for(int var2 = this.minIndex; var2 <= this.maxIndex; ++var2) {
- if (this.value.get(var2)) {
- var1 = true;
- }
-
- this.value.clear(var2);
- }
-
- this.minIndex = this.maxIndex = this.anchorIndex = this.leadIndex = -1;
- if (var1) {
- this.fireValueChanged(this.minIndex, this.maxIndex);
- }
-
- }
- }
-
- public void setLeadAnchorNotificationEnabled(boolean var1) {
- this.leadAnchorNotificationEnabled = var1;
- }
-
- public boolean isLeadAnchorNotificationEnabled() {
- return this.leadAnchorNotificationEnabled;
- }
-
- private void updateLeadAnchorIndices(int var1, int var2) {
- if (this.leadAnchorNotificationEnabled) {
- if (this.anchorIndex != -1 && this.anchorIndex != var1) {
- int var3 = Math.min(this.anchorIndex, var1);
- int var4 = Math.max(this.anchorIndex, var1);
- this.firstChangedIndex = this.firstChangedIndex == -1 ? var4 : Math.min(var3, this.firstChangedIndex);
- this.lastChangedIndex = Math.max(var4, this.lastChangedIndex);
- }
-
- if (this.leadIndex != -1 && this.leadIndex != var2) {
- int var5 = Math.min(this.leadIndex, var2);
- int var6 = Math.max(this.leadIndex, var2);
- this.firstChangedIndex = this.firstChangedIndex == -1 ? var5 : Math.min(var5, this.firstChangedIndex);
- this.lastChangedIndex = Math.max(var6, this.lastChangedIndex);
- }
- }
-
- this.anchorIndex = var1;
- this.leadIndex = var2;
- }
-
- public void setSelectionInterval(int var1, int var2) {
- if (this.getSelectionMode() == 0) {
- var1 = var2;
- }
-
- if (var1 == -1 && var2 == -1) {
- this.clearSelection();
- } else {
- int var3 = Math.min(var1, var2);
- int var4 = Math.max(var1, var2);
- if (this.minIndex == -1 || var3 < this.minIndex) {
- this.minIndex = var3;
- }
-
- if (this.maxIndex == -1 || var4 > this.maxIndex) {
- this.maxIndex = var4;
- }
-
- this.firstChangedIndex = -1;
- this.lastChangedIndex = -1;
-
- for(int var5 = this.minIndex; var5 < var3; ++var5) {
- if (this.value.get(var5)) {
- if (this.firstChangedIndex == -1) {
- this.firstChangedIndex = this.lastChangedIndex = var5;
- } else if (var5 > this.lastChangedIndex) {
- this.lastChangedIndex = var5;
- }
- }
-
- this.value.clear(var5);
- }
-
- for(int var6 = var3; var6 <= var4; ++var6) {
- if (!this.value.get(var6)) {
- if (this.firstChangedIndex == -1) {
- this.firstChangedIndex = this.lastChangedIndex = var6;
- } else if (var6 > this.lastChangedIndex) {
- this.lastChangedIndex = var6;
- }
- }
-
- this.value.set(var6);
- }
-
- for(int var7 = var4 + 1; var7 <= this.maxIndex; ++var7) {
- if (this.value.get(var7)) {
- if (this.firstChangedIndex == -1) {
- this.firstChangedIndex = this.lastChangedIndex = var7;
- } else if (var7 > this.lastChangedIndex) {
- this.lastChangedIndex = var7;
- }
- }
-
- this.value.clear(var7);
- }
-
- this.updateLeadAnchorIndices(var1, var2);
- this.minIndex = var3;
- this.maxIndex = var4;
- if (this.firstChangedIndex != -1 && this.lastChangedIndex != -1) {
- this.fireValueChanged(this.firstChangedIndex, this.lastChangedIndex);
- }
-
- }
- }
-
- public void addSelectionInterval(int var1, int var2) {
- int var3 = this.getSelectionMode();
- if (var3 != 0 && var3 != 1) {
- if (var1 != -1 || var2 != -1) {
- int var4 = Math.min(var1, var2);
- int var5 = Math.max(var1, var2);
- if (this.minIndex == -1 || var4 < this.minIndex) {
- this.minIndex = var4;
- }
-
- if (this.maxIndex == -1 || var5 > this.maxIndex) {
- this.maxIndex = var5;
- }
-
- this.firstChangedIndex = -1;
- this.lastChangedIndex = -1;
-
- for(int var6 = var4; var6 <= var5; ++var6) {
- if (!this.value.get(var6)) {
- if (this.firstChangedIndex == -1) {
- this.firstChangedIndex = this.lastChangedIndex = var6;
- } else if (var6 > this.lastChangedIndex) {
- this.lastChangedIndex = var6;
- }
-
- this.value.set(var6);
- }
- }
-
- this.updateLeadAnchorIndices(var1, var2);
- if (this.firstChangedIndex != -1 && this.lastChangedIndex != -1) {
- this.fireValueChanged(this.firstChangedIndex, this.lastChangedIndex);
- }
-
- }
- } else {
- this.setSelectionInterval(var1, var2);
- }
- }
-
- public void removeSelectionInterval(int var1, int var2) {
- if (var1 != -1 || var2 != -1) {
- if (this.minIndex != -1 || this.maxIndex != -1) {
- int var3 = Math.min(var1, var2);
- int var4 = Math.max(var1, var2);
- int var5 = -1;
- int var6 = -1;
-
- for(int var7 = var3; var7 <= var4; ++var7) {
- if (this.value.get(var7)) {
- if (var5 == -1) {
- var6 = var7;
- var5 = var7;
- } else if (var7 > var6) {
- var6 = var7;
- }
-
- this.value.clear(var7);
- }
- }
-
- int var8 = -1;
- int var9 = -1;
-
- for(int var10 = this.minIndex; var10 <= this.maxIndex; ++var10) {
- if (this.value.get(var10)) {
- if (var8 == -1) {
- var9 = var10;
- var8 = var10;
- } else if (var10 > var9) {
- var9 = var10;
- }
- }
- }
-
- this.minIndex = var8;
- this.maxIndex = var9;
- if (var5 != -1 && var6 != -1) {
- this.fireValueChanged(var5, var6);
- }
-
- }
- }
- }
-
- public void insertIndexInterval(int var1, int var2, boolean var3) {
- int var4 = var3 ? Math.max(0, var1 - 1) : var1 + 1;
- int var5 = var4 + var2 - 1;
- boolean var6 = this.value.get(var1) && this.value.get(var4);
-
- for(int var7 = this.maxIndex; var7 >= var4; --var7) {
- if (this.value.get(var7)) {
- this.value.set(var7 + var2);
- } else {
- this.value.clear(var7 + var2);
- }
- }
-
- for(int var8 = var4; var8 <= var5; ++var8) {
- if (var6) {
- this.value.set(var8);
- } else {
- this.value.clear(var8);
- }
- }
-
- if (this.minIndex != -1 && (this.minIndex > var4 || this.minIndex == var4 && !var6)) {
- this.minIndex += var2;
- }
-
- if (this.maxIndex != -1 && this.maxIndex >= var4) {
- this.maxIndex += var2;
- }
-
- this.fireValueChanged(var4, this.maxIndex);
- }
-
- public void removeIndexInterval(int var1, int var2) {
- if (var1 >= 0 && var2 >= 0) {
- if (this.minIndex != -1 || this.maxIndex != -1) {
- int var3 = Math.min(var1, var2);
- int var4 = Math.max(var1, var2);
- int var5 = var4 - var3 + 1;
- if (var3 <= this.maxIndex && var4 >= this.minIndex) {
- if (var3 <= this.minIndex && var4 >= this.maxIndex) {
- this.clearSelection();
- } else {
- for(int var6 = var3; var6 <= var4; ++var6) {
- if (this.value.get(var6 + var5)) {
- this.value.set(var6);
- } else {
- this.value.clear(var6);
- }
- }
-
- for(int var7 = this.maxIndex; var7 > this.maxIndex - var5; --var7) {
- this.value.clear(var7);
- }
-
- int var8 = this.minIndex;
- int var9 = this.maxIndex;
- if (var8 >= var3) {
- this.minIndex = -1;
-
- for(int var10 = var3; var10 <= var9; ++var10) {
- if (this.value.get(var10)) {
- this.minIndex = var10;
- break;
- }
- }
- }
-
- if (this.minIndex == -1) {
- this.maxIndex = -1;
- } else if (var9 > var4) {
- this.maxIndex = var9 - var5;
- } else {
- for(int var11 = var9; var11 >= this.minIndex; --var11) {
- if (this.value.get(var11)) {
- this.maxIndex = var11;
- break;
- }
- }
- }
-
- if (this.maxIndex == -1 && this.minIndex == -1) {
- this.fireValueChanged(var3, var4);
- } else {
- this.firstChangedIndex = Math.min(var3, this.minIndex);
- this.lastChangedIndex = Math.max(var4, this.maxIndex);
- this.fireValueChanged(this.firstChangedIndex, this.lastChangedIndex);
- }
- }
- }
- }
- }
- }
-
- public void setValueIsAdjusting(boolean var1) {
- if (var1 != this.isAdjusting) {
- this.isAdjusting = var1;
- this.fireValueChanged(var1);
- }
-
- }
-
- public String toString() {
- String var1 = (this.getValueIsAdjusting() ? "~" : "=") + this.value.toString();
- return this.getClass().getName() + " " + Integer.toString(this.hashCode()) + " " + var1;
- }
-
- public Object clone() throws CloneNotSupportedException {
- DefaultListSelectionModel var1 = (DefaultListSelectionModel)super.clone();
- var1.value = (BitSet)this.value.clone();
- var1.listenerList = new EventListenerList();
- return var1;
- }
-
- public int getAnchorSelectionIndex() {
- return this.anchorIndex;
- }
-
- public int getLeadSelectionIndex() {
- return this.leadIndex;
- }
-
- public void setAnchorSelectionIndex(int var1) {
- this.anchorIndex = var1;
- }
-
- public void setLeadSelectionIndex(int var1) {
- this.updateLead(var1);
- this.leadIndex = var1;
- }
-
- private boolean contains(int var1, int var2, int var3) {
- if (var1 <= var2) {
- return var3 >= var1 && var3 < var2;
- } else {
- return var3 <= var1 && var3 > var2;
- }
- }
-
- private int sign(int var1, int var2) {
- if (var1 < var2) {
- return -1;
- } else {
- return var1 > var2 ? 1 : 0;
- }
- }
-
- private void updateLead(int var1) {
- if (this.anchorIndex == -1) {
- this.anchorIndex = var1;
- }
-
- boolean var2 = false;
- if (!var2 && this.contains(this.leadIndex, var1, this.anchorIndex)) {
- this.removeSelectionInterval(this.anchorIndex, this.leadIndex);
- this.addSelectionInterval(this.anchorIndex, var1);
- }
-
- if (!var2 && !this.contains(this.anchorIndex, this.leadIndex, var1)) {
- this.addSelectionInterval(this.anchorIndex, var1);
- } else {
- int var3 = this.sign(this.anchorIndex, this.leadIndex);
- this.removeSelectionInterval(var1 - var3, this.leadIndex);
- }
- }
-
- // $FF: synthetic method
- static Class class$(String var0) {
- try {
- return Class.forName(var0);
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
- }
- }
-