⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultlistselectionmodel.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* DefaultListSelectionModel.java --   Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.io.Serializable;import java.util.BitSet;import java.util.EventListener;import javax.swing.event.EventListenerList;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;/** * The default implementation of {@link ListSelectionModel}, * which is used by {@link javax.swing.JList} and * similar classes to manage the selection status of a number of data * elements. * * <p>The class is organized <em>abstractly</em> as a set of intervals of * integers. Each interval indicates an inclusive range of indices in a * list -- held by some other object and unknown to this class -- which is * considered "selected". There are various accessors for querying and * modifying the set of intervals, with simplified forms accepting a single * index, representing an interval with only one element. </p> */public class DefaultListSelectionModel implements Cloneable,                                                  ListSelectionModel,                                                  Serializable{  private static final long serialVersionUID = -5718799865110415860L;  /** The list of ListSelectionListeners subscribed to this selection model. */  protected EventListenerList listenerList = new EventListenerList();  /**    * The current list selection mode. Must be one of the numeric constants   * <code>SINGLE_SELECTION</code>, <code>SINGLE_INTERVAL_SELECTION</code>   * or <code>MULTIPLE_INTERVAL_SELECTION</code> from {@link   * ListSelectionModel}. The default value is   * <code>MULTIPLE_INTERVAL_SELECTION</code>.   */  int selectionMode = MULTIPLE_INTERVAL_SELECTION;  /**   * The index of the "lead" of the most recent selection. The lead is the   * second argument in any call to {@link #setSelectionInterval}, {@link   * #addSelectionInterval} or {@link #removeSelectionInterval}. Generally   * the lead refers to the most recent position a user dragged their mouse   * over.   */  int leadSelectionIndex = -1;  /**   * The index of the "anchor" of the most recent selection. The anchor is   * the first argument in any call to {@link #setSelectionInterval},   * {@link #addSelectionInterval} or {@link   * #removeSelectionInterval}. Generally the anchor refers to the first   * recent position a user clicks when they begin to drag their mouse over   * a list.   *   * @see #getAnchorSelectionIndex   * @see #setAnchorSelectionIndex   */  int anchorSelectionIndex = -1;  /**   * controls the range of indices provided in any {@link   * ListSelectionEvent} fired by the selectionModel. Let   * <code>[A,L]</code> be the range of indices between {@link   * #anchorSelectionIndex} and {@link #leadSelectionIndex} inclusive, and   * let <code>[i0,i1]</code> be the range of indices changed in a given   * call which generates a {@link ListSelectionEvent}. Then when this   * property is <code>true</code>, the {@link ListSelectionEvent} contains   * the range <code>[A,L] union [i0,i1]</code>; when <code>false</code> it   * will contain only <code>[i0,i1]</code>. The default is   * <code>true</code>.   *   * @see #isLeadAnchorNotificationEnabled   * @see #setLeadAnchorNotificationEnabled   */  protected boolean leadAnchorNotificationEnabled = true;  /**   * Whether the selection is currently "adjusting". Any {@link   * ListSelectionEvent} events constructed in response to changes in this   * list selection model will have their {@link   * ListSelectionEvent#isAdjusting} field set to this value.   *   * @see #getValueIsAdjusting   * @see #setValueIsAdjusting   */  boolean valueIsAdjusting = false;  /**    * The current set of "intervals", represented simply by a {@link   * java.util.BitSet}. A set bit indicates a selected index, whereas a   * cleared bit indicates a non-selected index.   */  BitSet sel = new BitSet();  /**   * A variable to store the previous value of sel.   * Used to make sure we only fireValueChanged when the BitSet   * actually does change.   */  Object oldSel;  /**   * Whether this call of setLeadSelectionInterval was called locally   * from addSelectionInterval   */  boolean setLeadCalledFromAdd = false;  /**   * Gets the value of the {@link #selectionMode} property.   *   * @return The current value of the property   */  public int getSelectionMode()  {    return selectionMode;  }  /**   * Sets the value of the {@link #selectionMode} property.   *   * @param a The new value of the property   */  public void setSelectionMode(int a)  {    selectionMode = a;  }  /**   * Gets the value of the {@link #anchorSelectionIndex} property.   *    * @return The current property value   *   * @see #setAnchorSelectionIndex   */  public int getAnchorSelectionIndex()  {    return anchorSelectionIndex;  }  /**   * Sets the value of the {@link #anchorSelectionIndex} property.   *    * @param anchorIndex The new property value   *   * @see #getAnchorSelectionIndex   */  public void setAnchorSelectionIndex(int anchorIndex)  {    anchorSelectionIndex = anchorIndex;  }    /**   * Gets the value of the {@link #leadSelectionIndex} property.   *    * @return The current property value   *   * @see #setLeadSelectionIndex   */  public int getLeadSelectionIndex()  {    return leadSelectionIndex;  }  /**   * <p>Sets the value of the {@link #anchorSelectionIndex} property. As a   * side effect, alters the selection status of two ranges of indices. Let   * <code>OL</code> be the old lead selection index, <code>NL</code> be   * the new lead selection index, and <code>A</code> be the anchor   * selection index. Then if <code>A</code> is a valid selection index,   * one of two things happens depending on the seleciton status of   * <code>A</code>:</p>   *   * <ul>   *   * <li><code>isSelectedIndex(A) == true</code>: set <code>[A,OL]</code>   * to <em>deselected</em>, then set <code>[A,NL]</code> to   * <em>selected</em>.</li>   *   * <li><code>isSelectedIndex(A) == false</code>: set <code>[A,OL]</code>   * to <em>selected</em>, then set <code>[A,NL]</code> to   * <em>deselected</em>.</li>   *   * </ul>   *   * <p>This method generates at most a single {@link ListSelectionEvent}   * despite changing multiple ranges. The range of values provided to the   * {@link ListSelectionEvent} includes only the minimum range of values   * which changed selection status between the beginning and end of the   * method.</p>   *    * @param leadIndex The new property value   *   * @see #getAnchorSelectionIndex   */  public void setLeadSelectionIndex(int leadIndex)  {    // Only set the lead selection index to < 0 if anchorSelectionIndex < 0.    if (leadIndex < 0)      {        if (anchorSelectionIndex < 0)          leadSelectionIndex = -1;        else          return;      }    // Only touch the lead selection index if the anchor is >= 0.    if (anchorSelectionIndex < 0)      return;    if (selectionMode == SINGLE_SELECTION)      setSelectionInterval (leadIndex, leadIndex);        int oldLeadIndex = leadSelectionIndex;    if (oldLeadIndex == -1)      oldLeadIndex = leadIndex;    if (setLeadCalledFromAdd == false)      oldSel = sel.clone();    leadSelectionIndex = leadIndex;    if (anchorSelectionIndex == -1)      return;            int R1 = Math.min(anchorSelectionIndex, oldLeadIndex);    int R2 = Math.max(anchorSelectionIndex, oldLeadIndex);    int S1 = Math.min(anchorSelectionIndex, leadIndex);    int S2 = Math.max(anchorSelectionIndex, leadIndex);    int lo = Math.min(R1, S1);    int hi = Math.max(R2, S2);    if (isSelectedIndex(anchorSelectionIndex))      {        sel.clear(R1, R2+1);        sel.set(S1, S2+1);      }    else      {        sel.set(R1, R2+1);        sel.clear(S1, S2+1);      }        int beg = sel.nextSetBit(0), end = -1;    for(int i=beg; i >= 0; i=sel.nextSetBit(i+1))       end = i;    if (sel.equals(oldSel) == false)      fireValueChanged(beg, end, valueIsAdjusting);      }  /**   * Moves the lead selection index to <code>leadIndex</code> without    * changing the selection values.   *    * If leadAnchorNotificationEnabled is true, send a notification covering the   * old and new lead cells.   *    * @param leadIndex the new lead selection index   * @since 1.5   */  public void moveLeadSelectionIndex (int leadIndex)  {    if (leadSelectionIndex == leadIndex)      return;        leadSelectionIndex = leadIndex;    if (isLeadAnchorNotificationEnabled())      fireValueChanged(Math.min(leadSelectionIndex, leadIndex),                       Math.max(leadSelectionIndex, leadIndex));  }    /**   * Gets the value of the {@link #leadAnchorNotificationEnabled} property.   *    * @return The current property value   *   * @see #setLeadAnchorNotificationEnabled   */  public boolean isLeadAnchorNotificationEnabled()  {    return leadAnchorNotificationEnabled;  }  /**   * Sets the value of the {@link #leadAnchorNotificationEnabled} property.   *    * @param l The new property value   *   * @see #isLeadAnchorNotificationEnabled   */  public void setLeadAnchorNotificationEnabled(boolean l)  {    leadAnchorNotificationEnabled = l;  }  /**   * Gets the value of the {@link #valueIsAdjusting} property.   *   * @return The current property value   *   * @see #setValueIsAdjusting   */  public boolean getValueIsAdjusting()  {    return valueIsAdjusting;  }  /**   * Sets the value of the {@link #valueIsAdjusting} property.   *   * @param v The new property value   *   * @see #getValueIsAdjusting   */  public void setValueIsAdjusting(boolean v)  {    valueIsAdjusting = v;  }  /**   * Determines whether the selection is empty.   *   * @return <code>true</code> if the selection is empty, otherwise   * <code>false</code>   */  public boolean isSelectionEmpty()  {    return sel.isEmpty();  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -