[jsword-svn] bibledesktop/java/main/org/crosswire/bibledesktop/passage s

jswordcvs at crosswire.org jswordcvs at crosswire.org
Sun Jun 5 17:17:47 MST 2005


Update of /cvs/jsword/bibledesktop/java/main/org/crosswire/bibledesktop/passage
In directory www.crosswire.org:/tmp/cvs-serv5803/java/main/org/crosswire/bibledesktop/passage

Modified Files:
	KeySidebar.java 
Added Files:
	RangeListModel.java 
Removed Files:
	PassageListModel.java 
Log Message:
Optimized the KeySidebar.
Cleaned up some checkstyle reports.

Index: KeySidebar.java
===================================================================
RCS file: /cvs/jsword/bibledesktop/java/main/org/crosswire/bibledesktop/passage/KeySidebar.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** KeySidebar.java	5 Jun 2005 03:46:43 -0000	1.12
--- KeySidebar.java	6 Jun 2005 00:17:45 -0000	1.13
***************
*** 46,50 ****
  import org.crosswire.jsword.passage.Key;
  import org.crosswire.jsword.passage.Passage;
- import org.crosswire.jsword.passage.PassageListType;
  import org.crosswire.jsword.passage.RestrictionType;
  
--- 46,49 ----
***************
*** 75,81 ****
          setLayout(new BorderLayout());
  
!         model = new PassageListModel();
!         model.setMode(PassageListType.RANGES);
!         model.setRestriction(RestrictionType.CHAPTER);
  
          list = new JList(model);
--- 74,78 ----
          setLayout(new BorderLayout());
  
!         model = new RangeListModel(RestrictionType.CHAPTER);
  
          list = new JList(model);
***************
*** 176,180 ****
          {
              Key listedKey = (Key) model.getElementAt(i);
!             
              // As keys are found, remove them
              Iterator iter = selected.iterator();
--- 173,177 ----
          {
              Key listedKey = (Key) model.getElementAt(i);
! 
              // As keys are found, remove them
              Iterator iter = selected.iterator();
***************
*** 188,192 ****
                  }
              }
!             
              // If the list is empty then we are done.
              if (selected.size() == 0)
--- 185,189 ----
                  }
              }
! 
              // If the list is empty then we are done.
              if (selected.size() == 0)
***************
*** 392,396 ****
       */
      private JList list;
!     private PassageListModel model;
      private Action actDelete;
      private Action actBlur1;
--- 389,393 ----
       */
      private JList list;
!     private RangeListModel model;
      private Action actDelete;
      private Action actBlur1;

--- NEW FILE: RangeListModel.java ---
/**
 * Distribution License:
 * JSword is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, version 2 as published by
 * the Free Software Foundation. This program is distributed in the hope
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * The License is available on the internet at:
 *       http://www.gnu.org/copyleft/gpl.html
 * or by writing to:
 *      Free Software Foundation, Inc.
 *      59 Temple Place - Suite 330
 *      Boston, MA 02111-1307, USA
 *
 * Copyright: 2005
 *     The copyright to this program is held by it's authors.
 *
 * ID: $Id: RangeListModel.java,v 1.1 2005/06/06 00:17:45 dmsmith Exp $
 */
package org.crosswire.bibledesktop.passage;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.swing.AbstractListModel;

import org.crosswire.jsword.passage.Passage;
import org.crosswire.jsword.passage.RestrictionType;
import org.crosswire.jsword.passage.VerseRange;

/**
 * The RangeListModel class gives access to a Passage as a list of ranges
 * via a ListModel.
 *
 * @see gnu.gpl.License for license details.
 *      The copyright to this program is held by it's authors.
 * @author DM Smith [dmsmith555 at yahoo dot com]
 */
public class RangeListModel extends AbstractListModel
{
    /**
     * Create a RangeListModel specifying whether
     * to list the ranges bounded by Chapter or not at all.
     * @param theRestriction Do we chop at chapter boundries
     */
    public RangeListModel(RestrictionType theRestriction)
    {
        restrict = theRestriction;
        ranges = new ArrayList();
    }

    /**
     * Change the restrictions we are using.
     * Must be one of:
     * <code>RestrictType.NONE</code>, or
     * <code>RestrictType.CHAPTER</code>
     * @param restrict The new restrictions
     */
    public void setRestriction(RestrictionType restrict)
    {
        this.restrict = restrict;

        refresh();
    }

    /**
     * Return the current Range Restriction
     */
    public RestrictionType getRestriction()
    {
        return restrict;
    }

    /**
     * Returns the length of the list.
     * @return The number of verses/ranges in the list
     */
    public int getSize()
    {
        return ranges.size();
    }

    /**
     * Returns the value at the specified index.
     * @param index The index (based at 0) of the element to fetch
     * @return The required verse/range
     */
    public Object getElementAt(int index)
    {
        return ranges.get(index);
    }

    /**
     * Accessor for the current passage
     */
    public final void setPassage(Passage newRef)
    {
        fireIntervalRemoved(this, 0, getSize());

        ref = newRef;

        if (ref != null)
        {
            ref.optimizeReads();
        }

        refresh();

        fireIntervalAdded(this, 0, getSize());
    }

    /**
     * Accessor for the current passage
     */
    public Passage getPassage()
    {
        return ref;
    }

    private void refresh()
    {
        ranges.clear();
        if (ref != null)
        {
            Iterator iter = ref.rangeIterator(restrict);
            while (iter.hasNext())
            {
                VerseRange range = (VerseRange) iter.next();
                ranges.add(range);
            }
        }
    }

    /**
     * The Passage that we are modelling
     */
    private Passage ref;

    /**
     * The list of ranges in the passage.
     */
    private List ranges;

    /**
     * If we are modelling in groups, do we break at chapter/book boundries
     */
    private RestrictionType restrict;

    /**
     * Serialization ID
     */
    private static final long serialVersionUID = 3761692273179964725L;
}

--- PassageListModel.java DELETED ---



More information about the jsword-svn mailing list