001/*
002 *  $Source: /cvsroot2/open/projects/WebARTS/ca/bc/webarts/widgets/JCheckDropDown.java,v $
003 *  $Name:  $
004 *  $Revision: 584 $
005 *  $Date: 2012-11-24 16:46:56 -0800 (Sat, 24 Nov 2012) $
006 *  $Locker:  $
007 */
008/*
009 *  JCheckDropDown -- A Widget Class to mimic a toggle drop down box which has
010 *  JCheckBoxes inside its popup.
011 *
012 *  Copyright (C) 2001 WebARTS Design, North Vancouver Canada
013 *  http://www..webarts.bc.ca
014 *
015 *  This program is free software; you can redistribute it and/or modify
016 *  it under the terms of the GNU General Public License as published by
017 *  the Free Software Foundation; either version 2 of the License, or
018 *  (at your option) any later version.
019 *
020 *  This program is distributed in the hope that it will be useful,
021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023 *  GNU General Public License for more details.
024 *
025 *  You should have received a copy of the GNU General Public License
026 *  along with this program; if not, write to the Free Software
027 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
028
029 */
030package ca.bc.webarts.widgets;
031
032import ca.bc.webarts.tools.Log;
033import ca.bc.webarts.widgets.PopUpButton;
034
035import java.awt.BorderLayout;
036import java.awt.Color;
037import java.awt.Component;
038import java.awt.Font;
039import java.awt.Point;
040import java.awt.event.ActionEvent;
041import java.awt.event.ActionListener;
042import java.awt.event.MouseAdapter;
043import java.awt.event.MouseEvent;
044import java.awt.event.MouseListener;
045import java.awt.event.WindowAdapter;
046import java.awt.event.WindowEvent;
047import java.beans.PropertyChangeEvent;
048import java.beans.PropertyChangeListener;
049import java.io.File;
050import java.text.Collator;
051import java.util.Arrays;
052import java.util.Vector;
053import javax.swing.DefaultListModel;
054import javax.swing.JButton;
055import javax.swing.JCheckBox;
056import javax.swing.JFrame;
057import javax.swing.JLabel;
058import javax.swing.JList;
059import javax.swing.JPanel;
060import javax.swing.JScrollPane;
061import javax.swing.JWindow;
062import javax.swing.ListCellRenderer;
063import javax.swing.ListModel;
064import javax.swing.ListSelectionModel;
065import javax.swing.PopupFactory;
066import javax.swing.Popup;
067import javax.swing.SwingUtilities;
068
069import javax.swing.event.ListDataEvent;
070import javax.swing.event.ListDataListener;
071
072import kiwi.util.KiwiUtils;
073
074/**
075 * A custom Drop Down box that holds JCheckBox items in its list. It also requires
076 * the user to select the button to open and close the popup list.
077 *
078 * @author    Tom Gutwin P.Eng
079 * @created   October 15, 2001
080 */
081public class JCheckDropDown extends PopUpButton
082{
083
084  /**
085   * A Class holder for its name (used in Logging).
086   */
087  private static String className_ = "JCheckDropDown";
088  /**
089   * The Log Filename.
090   */
091  private static String logFile_ = "." + File.separator + className_+ "Log.txt";
092  /**
093   * The Log that will get used.
094   */
095  protected static Log log_ = Log.createLog(Log.DEBUG, logFile_);
096  /**
097   * The number of items in the list.
098   **/
099   private int numItems_ = 0;
100  /**
101   * The number of items in the list That Are Checked..
102   **/
103   private int numItemsChecked_ = 0;
104  /**
105   * A Cache of the Checked items.
106   **/
107  private Vector checkedItems_ = new Vector();
108
109
110  /**
111   * Constructor that instantiates the popup list using the passed in Array and
112   * basic renderer.
113   *
114   * @param jl  the array of JCheckboxes to add (make sure they are pre
115                selected)
116   */
117  public JCheckDropDown(JCheckBox[] jl)
118  {
119    super();
120    final String methodName = className_ + ": JCheckDropDown(JCheckBox[])";
121    //log_ = Log.createLog(Log.FULL, logFile_);
122    log_.startMethod(methodName);
123    if (jl != null && jl.length > 0)
124    {
125      numItems_ = jl.length;
126      for (int i=0 ;i < numItems_; i++)
127        listModel_.addElement(jl[i]);
128      popUpList_ = new JList(listModel_)/*
129      {
130        public String getToolTipText( MouseEvent e )
131        {
132          int index = locationToIndex( e.getPoint() );
133          if ( -1 < index )
134          {
135            JCheckBox jc = (JCheckBox)getModel().getElementAt( index );
136            return jc.getToolTipText();
137          }
138          else
139          {
140            return null;
141          }
142        }
143      }*/
144      ;
145    }
146    else
147    {
148      log_.minor("JCheckDropDown: The passed in Array is Null" +
149        " (or empty), initializing with an empty JList Popup.");
150      popUpList_ = new JList(listModel_);
151    }
152    //setHorizontalTextPosition(LEFT);
153    //setHorizontalAlignment(LEFT);
154    popUpList_.setSelectionBackground(Color.darkGray);
155    popUpList_.setCellRenderer(new CheckBoxRenderer());
156    popUpList_.addMouseListener(new ListCheckBoxMouseListsener());
157
158    popUpList_.setVisibleRowCount(6);
159    popUpList_.setBorder(null);
160    popUpScroller_.getViewport().setView(popUpList_);
161    popUpPanel_.add(popUpScroller_);
162    popUpWin_.getContentPane().add(popUpPanel_);
163
164    addActionListener(PopUpButtonActionListener_);
165    addAncestorListener(PopUpButtonAncestorListener_); // listens if parent(s) move or toggle visibility
166    log_.endMethod();
167  }
168
169
170  /**
171   * Constructor that instantiates the popup list using the passed in Array and
172   * basic renderer.
173   *
174   * @param items  Description of Parameter
175   */
176  public JCheckDropDown(String[] items)
177  {
178    super();
179    final String methodName = className_ + ": JCheckDropDown(String[])";
180    //log_ = Log.createLog(Log.FULL, logFile_);
181    log_.startMethod(methodName);
182
183    JCheckBox[] jl = null;
184    if (items != null && items.length > 0)
185    {
186      numItems_ = items.length;
187
188      /*System.out.println("\n UN-Sorted List:");
189      for (int i = 0; i < numItems_; i++)
190      {
191        System.out.println(" Item "+i+" "+items[i]);
192      }
193      System.out.println("\n Sorted List:");*/
194
195      Arrays.sort(items, String.CASE_INSENSITIVE_ORDER);
196
197      /*
198      for (int i = 0; i < numItems_; i++)
199      {
200        System.out.println(" Item "+i+" "+items[i]);
201      }
202      */
203
204      log_.debug("Adding " + numItems_ + " items.");
205      jl = new JCheckBox[numItems_];
206      for (int i = 0; i < numItems_; i++)
207      {
208        jl[i] = new JCheckBox(items[i], true);
209      }
210      numItemsChecked_ = numItems_;
211      for (int i = 0; i < numItems_; i++)
212      {
213        listModel_.addElement(jl[i]);
214      }
215    }
216    else
217    {
218      log_.minor("JCheckDropDown: The passed in Array is Null" +
219        " (or empty), initializing with an empty JList Popup.");
220    }
221    popUpList_ = new JList(listModel_)/*
222      {
223        public String getToolTipText( MouseEvent e )
224        {
225          int index = locationToIndex( e.getPoint() );
226          if ( -1 < index )
227          {
228            JCheckBox jc = (JCheckBox)getModel().getElementAt( index );
229            return jc.getToolTipText();
230          }
231          else
232          {
233            return null;
234          }
235        }
236      }*/
237      ;
238
239    //setHorizontalTextPosition(LEFT);
240    //setHorizontalAlignment(LEFT);
241    popUpList_.setSelectionBackground(Color.darkGray);
242    popUpList_.setCellRenderer(new CheckBoxRenderer());
243    popUpList_.addMouseListener(new ListCheckBoxMouseListsener());
244
245    popUpList_.setVisibleRowCount(6);
246    popUpList_.setBorder(null);
247    popUpScroller_.getViewport().setView(popUpList_);
248    popUpPanel_.add(popUpScroller_);
249    popUpWin_.getContentPane().add(popUpPanel_);
250
251    addActionListener(PopUpButtonActionListener_);
252    addAncestorListener(PopUpButtonAncestorListener_); // listens if parent(s) move or toggle visibility
253    log_.endMethod();
254  }
255
256
257  /**
258   * The main test program for the JCheckDropDown class
259   *
260   * @param args  The command line arguments
261   */
262  public static void main(String[] args)
263  {
264    appFrame_ = new JFrame();
265    appFrame_.getContentPane().setLayout(new BorderLayout());
266    appFrame_.setTitle("JCheckDropDown TEST Window.");
267    Arrays.sort(SAMPLE_LIST_DATA, String.CASE_INSENSITIVE_ORDER);
268    JCheckBox[] jc = new JCheckBox[SAMPLE_LIST_DATA.length];
269    for (int i = 0; i < jc.length; i++)
270    {
271      jc[i] = new JCheckBox(SAMPLE_LIST_DATA[i], true);
272    }
273    final JCheckDropDown myTestButton = new JCheckDropDown(jc);
274    appFrame_.addWindowListener(
275      new WindowAdapter()
276      {
277        public void windowClosing(WindowEvent e)
278        {
279          myTestButton.getLog().close();
280          System.exit(0);
281        }
282      });
283    myTestButton.setText("Press Me");
284    appFrame_.getContentPane().add(myTestButton);
285
286    appFrame_.pack();
287    KiwiUtils.centerWindow(appFrame_);
288    appFrame_.toFront();
289    appFrame_.setVisible(true);
290    appFrame_.repaint();
291  }
292
293
294  /**
295   * Gets the ItemChecked attribute of the JCheckDropDown object
296   *
297   * @param itemNum  Description of Parameter
298   * @return         The ItemChecked value
299   */
300  public boolean isItemChecked(int itemNum)
301  {
302    final String methodName = className_ + ": isItemChecked(int)";
303    log_.startMethod(methodName);
304    boolean retVal = false;
305
306    retVal = getItem(itemNum).isSelected();
307
308    log_.debug("Item " + itemNum + " is Checked?? " + retVal);
309    log_.endMethod();
310    return retVal;
311  }
312
313
314  /** Sets all the checkbox's font to this new font. **/
315  public void setFont(Font newFont)
316  {
317    super.setFont(newFont);
318    for (int i = 0; i < numItems_; i++)
319    {
320      getItemNonLogged(i).setFont(newFont);
321      getItemNonLogged(i).validate();
322    }
323    this.validate();
324  }
325
326
327  /**
328   * Checks the checkbox for th especified item
329   *
330   * @param itemNum  Description of Parameter
331   * @param checkit or not checkit
332   * @return         The ItemChecked value
333   */
334  public void checkItem(int itemNum, boolean checkIt)
335  {
336    final String methodName = className_ + ": checkItem(int,"+checkIt+")";
337    log_.startMethod(methodName);
338
339    getItemNonLogged(itemNum).setSelected(checkIt);
340    if (checkIt)
341      numItemsChecked_++;
342    else
343      numItemsChecked_--;
344
345    log_.endMethod();
346  }
347
348
349  /**
350   * Checks ALL the checkboxes with the specified value.
351   *
352   * @param checkit or not checkit
353   * @return         The ItemChecked value
354   */
355  public void checkAllItems(boolean checkIt)
356  {
357    final String methodName = className_ + ": checkItem("+checkIt+")";
358    log_.startMethod(methodName);
359
360    for (int i = 0; i < numItems_; i++)
361    {
362      getItemNonLogged(i).setSelected(checkIt);
363    }
364    if (checkIt)
365      numItemsChecked_ = numItems_;
366    else
367      numItemsChecked_ = 0;
368
369    log_.endMethod();
370  }
371
372
373  /**
374   * Gets the Item attribute of the JCheckDropDown object
375   *
376   * @param itemNum  Description of Parameter
377   * @return         The Item value or null if non-existant item
378   */
379  public JCheckBox getItem(int itemNum)
380  {
381    final String methodName = className_ + ": getItem(int)";
382    log_.startMethod(methodName);
383
384    JCheckBox retVal = null;
385    if (numItems_ > 0 && itemNum < numItems_)
386    {
387      retVal = ((JCheckBox) ((JList) popUpList_).getModel().
388      getElementAt(itemNum));
389    }
390    log_.endMethod();
391    return retVal;
392  }
393
394
395  /**
396   * Gets the Item attribute of the JCheckDropDown object without logging.
397   *
398   * @param itemNum  Description of Parameter
399   * @return         The Item value
400   */
401  private JCheckBox getItemNonLogged(int itemNum)
402  {
403    JCheckBox retVal = ((JCheckBox) ((JList) popUpList_).getModel().
404      getElementAt(itemNum));
405    return retVal;
406  }
407
408
409  /**
410   * Gets the ItemName attribute of the JCheckDropDown object
411   *
412   * @param itemNum  Description of Parameter
413   * @return         The ItemName value
414   */
415  public String getItemName(int itemNum)
416  {
417    final String methodName = className_ + ": getItemName(int)";
418    log_.startMethod(methodName);
419
420    String retVal = "";
421    if (numItems_ > 0 && itemNum < numItems_)
422    {
423      JCheckBox jc = getItemNonLogged(itemNum);
424      if (jc != null)
425      {
426        retVal = jc.getText();
427      }
428    }
429
430    log_.endMethod();
431    return retVal;
432  }
433
434
435  /**
436   * Returns the numItemsChecked_ field.
437   *
438   * @return   The numItemsChecked_ value
439   */
440  public int getNumItemsChecked()
441  {
442    final String methodName = className_ + ": getNumItemsChecked()";
443    //log_.startMethod(methodName);
444    //log_.endMethod();
445    return numItemsChecked_;
446  }
447
448
449  /**
450   * Returns the numItems_ field. The number of items in this object.
451   *
452   * @return   The numItems_ value
453   */
454  public int getNumItems()
455  {
456    final String methodName = className_ + ": getNumItems()";
457    //log_.startMethod(methodName);
458    //log_.endMethod();
459    return numItems_;
460  }
461
462
463  /**
464   * Iterates through the list checking to see how many of the contained
465   * JCheckBoxes are checked.
466   *
467   * @return   The NumItemsChecked value
468   */
469  private int reGetNumItemsChecked()
470  {
471    final String methodName = className_ + ": getNumItemsChecked()";
472    log_.startMethod(methodName);
473    int retVal = 0;
474    for (int i = 0; i < numItems_; i++)
475    {
476      if (isItemChecked(i))
477      {
478        retVal++;
479      }
480    }
481
482    log_.endMethod();
483    return retVal;
484  }
485
486
487  /**
488   * Gets the RandomCheckedItemNum attribute of the JCheckDropDown object
489   *
490   * @return   The RandomCheckedItemNum value
491   */
492  public int getRandomCheckedItemNum()
493  {
494    final String methodName = className_ + ": getRandomCheckedItem()";
495    log_.startMethod(methodName);
496    int retVal = -1;
497    boolean notDone = true;
498
499    log_.debug(methodName+"numItems_="+numItems_+
500      "numItemsChecked_="+numItemsChecked_);
501    if (numItemsChecked_ > 0)
502    {
503      while (notDone)
504      {
505        retVal = (int) (Math.random() * numItems_);
506        // go direct to the getItem method for speed (bypasses logging etc)
507        if (getItemNonLogged(retVal).isSelected()) //!isItemChecked(retVal))
508        {
509          notDone = false;
510        }
511      }
512    }
513
514    log_.endMethod();
515    return retVal;
516  }
517
518
519  /**
520   * Gets the NextCheckedItemNum attribute of the JCheckDropDown object
521   *
522   * @return   The NextCheckedItemNum value
523   */
524  public int getNextCheckedItemNum()
525  {
526    final String methodName = className_ + ": getNextCheckedItemNum()";
527    log_.startMethod(methodName);
528    int retVal = getSelectedIndex();
529    int numItems = getItemCount();
530    boolean firstTimeInLoop = true;
531
532    log_.debug("Current Selected Item Num="+retVal);
533    log_.debug("Current Selected Item Name="+getSelectedItemName());
534    if (numItemsChecked_ > 0)
535    {
536      while (firstTimeInLoop || !isItemChecked(retVal))
537      {
538        firstTimeInLoop = false;
539        if (retVal < numItems - 1)
540        {
541          retVal++;
542        }
543        else
544        {
545          retVal = 0;
546        }
547      }
548    }
549    log_.debug("NEXT Selected Item Num="+retVal);
550
551    log_.endMethod();
552    return retVal;
553  }
554
555
556  /**
557   * Gets the SelectedItemName attribute of the JCheckDropDown object
558   *
559   * @return   The SelectedItemName value
560   */
561  public String getSelectedItemName()
562  {
563    final String methodName = className_ + ": getSelectedItemName()";
564    log_.startMethod(methodName);
565    String retVal = "";
566    int sel = getSelectedIndex();
567    if (!(sel < 1))
568    {
569      retVal = ((JCheckBox) ((JList) popUpList_).getModel().
570        getElementAt(sel-1)).getText();
571    }
572    else if (sel==0)
573    {
574      retVal = ((JCheckBox) ((JList) popUpList_).getModel().
575        getElementAt(0)).getText();
576    }
577
578    log_.endMethod();
579    return retVal;
580  }
581
582
583  /**
584   * Gets the Index for the item that matches the name passedin.
585   *
586   * @param item  Description of Parameter
587   * @return      The JCheckBoxIndex value
588   */
589  public int getJCheckBoxIndex(String item)
590  {
591    final String methodName = className_ + ": getJCheckBoxIndex(String)";
592    log_.startMethod(methodName);
593
594    int index = 0;
595    int size = ((JList) popUpList_).getModel().getSize();
596    for (int i = 0; index == 0 && i < size; i++)
597    {
598      JCheckBox jc = (JCheckBox) ((JList) popUpList_).getModel().getElementAt(i);
599      if (jc.getText().equals(item))
600      {
601        index = i;
602      }
603    }
604    log_.endMethod();
605    return index;
606  }
607
608  /**
609   * Sets the SelectedIndex attribute of the PopUpButton object.
610   *
611   * @param index  The new SelectedIndex value
612   */
613  public void setSelectedIndex(int index)
614  {
615    super.setSelectedIndex(index);
616    final String methodName = className_ + ": setSelectedIndex("+index+")";
617    log_.startMethod(methodName);
618    setText(getItemName(index));
619    log_.endMethod();
620  }
621
622
623  public void sortDefaultList(DefaultListModel dlm)
624  {
625    final String methodName = className_ + ": sortDefaultList()";
626    log_.startMethod(methodName);
627
628    if (dlm != null)
629    {
630      try
631      {
632        int numItems = dlm.getSize();
633        JCheckBox[] a = new JCheckBox[numItems];
634        JCheckBox tmpCheckBox = null;
635        for (int i=0; i < numItems; i++)
636        {
637            a[i] = tmpCheckBox;
638        }
639        sortArray(Collator.getInstance(),a);
640        // Locale loc = Locale.FRENCH;
641        // sortArray(Collator.getInstance(loc), (String[])a);
642        for (int i=0; i < numItems; i++)
643        {
644          dlm.setElementAt(a[i], i);
645        }
646      }
647      catch (Exception ex)
648      {
649        log_.minor("Threw a:",ex);
650      }
651    }
652    log_.endMethod();
653  }
654
655
656  private void sortArray(Collator collator, JCheckBox[] checkedArray)
657  {
658    final String methodName = className_ + ": sortArray(Collator, JCheckBox[])";
659    log_.startMethod(methodName);
660    JCheckBox tmp;
661    int lengthOfArray = checkedArray.length;
662    log_.debug("Sorting " + lengthOfArray  + " items.");
663    if (lengthOfArray == 1) return;
664    for (int i = 0; i < lengthOfArray; i++)
665    {
666      for (int j = i + 1; j < lengthOfArray; j++)
667      {
668        if( collator.compare(checkedArray[i].getText(),
669                             checkedArray[j].getText() ) > 0 )
670        {
671          tmp = checkedArray[i];
672          checkedArray[i] = checkedArray[j];
673          checkedArray[j] = tmp;
674        }
675      }
676    }
677    log_.endMethod();
678  }
679
680
681   /**
682   * Adds a feature to the Item attribute of the JCheckDropDown object
683   *
684   * @param jc  The feature to be added to the Item attribute
685   */
686  public void addItem(JCheckBox jc)
687  {
688    final String methodName = className_ + ": addItem(JCheckBox)";
689    log_.startMethod(methodName);
690
691    listModel_.addElement(jc);
692    //((DefaultListModel)((JList) popUpList_).getModel()).addElement(jc);
693    numItems_++;
694    if (jc.isSelected())
695      numItemsChecked_++;
696    //sortDefaultList((DefaultListModel)popUpList_.getModel());
697    log_.endMethod();
698  }
699
700
701  /**
702   * Removes all Items from the DropDown List.
703   */
704  public void removeAllItems()
705  {
706    final String methodName = className_ + ": removeAllItems()";
707    log_.startMethod(methodName);
708
709    listModel_.removeAllElements();
710    numItems_ = 0;
711    numItemsChecked_=0;
712    log_.endMethod();
713  }
714
715
716  /**
717   * Removes the named item from the list of items.
718   *
719   * @param item  The name of the item to remove
720   */
721  public void removeItem(String item)
722  {
723    final String methodName = className_ + ": removeItem(): "+item;
724    log_.startMethod(methodName);
725
726    try
727    {
728      int index = getJCheckBoxIndex(item);
729      JCheckBox jc = getItemNonLogged(index);
730      if (jc.isSelected())
731        numItemsChecked_++;
732
733      listModel_.remove(index);
734      numItems_--;
735    }
736    catch (java.lang.Exception ex)
737    {
738      ex.printStackTrace();
739      log_.major("Exception Thrown: Delete from PlayList FAILED:"+item, ex);
740    }
741    log_.endMethod();
742  }
743
744
745  /**
746   * Listens for mouse clicks on the listbox. It then decides where the
747   * click happened so it can either work the checkbox or select an item.
748   *
749   * @author    Tom Gutwin P.Eng
750   * @created   October 15, 2001
751   */
752  class ListCheckBoxMouseListsener extends MouseAdapter
753  {
754    /**
755     * Listener for the mouse clickmethod
756     *
757     * @param e  Description of Parameter
758     */
759    public void mouseClicked(MouseEvent e)
760    {
761      Point pnt = e.getPoint();
762      double xLocation = pnt.getX();
763      int index = ((JList) popUpList_).locationToIndex(pnt);
764      int clkCount = e.getClickCount();
765      //System.out.println("  !Mouse Click: " + clkCount +
766      //  " click on Item " + index);
767      //System.out.println("  at point " + pnt);
768      JCheckBox jc = (JCheckBox) ((JList) e.getSource()).
769        getModel().getElementAt(index);
770      if (xLocation < 13)
771      {
772        if (!jc.isSelected())
773        {
774          //System.out.print("  CHECK it: ");
775          jc.setSelected(true);
776          numItemsChecked_++;
777        }
778        else
779        {
780          //System.out.print("  UNCHECK it: ");
781          jc.setSelected(false);
782          numItemsChecked_--;
783        }
784      }
785      else
786      {
787        //System.out.print("  Select it: ");
788        ((JList) popUpList_).setSelectionBackground(Color.red);
789        Color selectedBack = ((JList) popUpList_).getSelectionBackground();
790        Color selectedFront = ((JList) popUpList_).getSelectionForeground();
791        //System.out.println("  back = " + selectedBack + "  front = " + selectedFront);
792        jc.setBackground(Color.red);
793        jc.repaint();
794        //boolean isSelected = popUpList_.getSelectedIndex() == index;
795        //popUpList_.clearSelection();
796        //if(isSelected)
797        //{
798        //  System.out.println("DE-Selecting index "+ index);
799        //}
800        //else
801        //{
802        //  System.out.println("Selecting index "+ index);
803        //  popUpList_.setSelectedIndex(index);
804        //}
805        setText(getItemName(index));
806
807        // close the window
808        togglePopUp();
809      }
810      popUpList_.repaint();
811    }
812
813
814    /**
815     * Listener for a mouse press.
816     *
817     * @param e  Description of Parameter
818     */
819    public void mousePressed(MouseEvent e)
820    {
821      int index = popUpList_.locationToIndex(e.getPoint());
822      System.out.println("  Mouse Press on Item " + index);
823    }
824
825
826    /**
827     * Description of the Method
828     *
829     * @param e  Description of Parameter
830     */
831    public void mouseMoved(MouseEvent e)
832    {
833      int index = popUpList_.locationToIndex(e.getPoint());
834      System.out.println("  Mouse Moved Item " + index);
835    }
836
837
838    /**
839     * Description of the Method
840     *
841     * @param e  Description of Parameter
842     */
843    public void mouseExited(MouseEvent e)
844    {
845      /*
846      Point pnt = e.getPoint();
847      double xLocation = pnt.getX();
848      double yLocation = pnt.getY();
849      int index = ((JList) popUpList_).locationToIndex(pnt);
850      JCheckBox jc = (JCheckBox) ((JList) e.getSource()).
851                      getModel().getElementAt(index);
852      PopupFactory factory = PopupFactory.getSharedInstance();
853      Popup popup = factory.getPopup(popUpList_, jc, (int) xLocation,  (int)yLocation);
854      //popup.show();
855      popup.hide();
856      //int index = popUpList_.locationToIndex(e.getPoint());
857      System.out.println("  Mouse Xited Item " + index);
858      */
859    }
860
861
862    /**
863     * Description of the Method
864     *
865     * @param e  Description of Parameter
866     */
867    public void mouseEntered(MouseEvent e)
868    {
869      /*
870      Point pnt = e.getPoint();
871      double xLocation = pnt.getX();
872      double yLocation = pnt.getY();
873      int index = ((JList) popUpList_).locationToIndex(pnt);
874      int clkCount = e.getClickCount();
875      System.out.println("  !Mouse Click: " + clkCount +
876        " click on Item " + index);
877      System.out.println("  at point " + pnt);
878      JCheckBox jc = (JCheckBox) ((JList) e.getSource()).
879                      getModel().getElementAt(index);
880      PopupFactory factory = PopupFactory.getSharedInstance();
881      Popup popup = factory.getPopup(popUpList_, jc, (int) xLocation,  (int)yLocation);
882      popup.show();
883      //popup.hide();
884      //int index = popUpList_.locationToIndex(e.getPoint());
885      System.out.println("  Mouse Enter Item " + index);
886      */
887    }
888  }
889
890
891  /**
892   * Description of the Class
893   *
894   * @author    Tom Gutwin P.Eng
895   * @created   October 15, 2001
896   */
897  class ListListener implements ListDataListener
898  {
899    /**
900     * Description of the Method
901     *
902     * @param e  Description of Parameter
903     */
904    public void contentsChanged(ListDataEvent e)
905    {
906      int index0 = e.getIndex0();
907      int index1 = e.getIndex1();
908      log_.debug("List Item Changed " + index0 + " " + index1);
909      popUpList_.repaint();
910    }
911
912
913    /**
914     * Description of the Method
915     *
916     * @param e  Description of Parameter
917     */
918    public void intervalAdded(ListDataEvent e)
919    {
920      int index0 = e.getIndex0();
921      int index1 = e.getIndex1();
922      log_.debug("List intervalAdded " + index0 + " " + index1);
923      popUpList_.revalidate();
924    }
925
926
927    /**
928     * Description of the Method
929     *
930     * @param e  Description of Parameter
931     */
932    public void intervalRemoved(ListDataEvent e)
933    {
934      int index0 = e.getIndex0();
935      int index1 = e.getIndex1();
936      log_.debug("List intervalRemoved " + index0 + " " + index1);
937      //contentsChanged( e );
938    }
939
940  }
941
942
943  /**
944   * Description of the Class
945   *
946   * @author    Tom Gutwin P.Eng
947   * @created   October 15, 2001
948   */
949  class CheckBoxRenderer extends JCheckBox implements ListCellRenderer
950  {
951    /**
952     * Constructor for the CheckBoxRenderer object
953     */
954    public CheckBoxRenderer()
955    {
956      setOpaque(true);
957    }
958
959
960    /**
961     * Gets the ListCellRendererComponent attribute of the CheckBoxRenderer object
962     *
963     * @param list          Description of Parameter
964     * @param value         Description of Parameter
965     * @param index         Description of Parameter
966     * @param isSelected    Description of Parameter
967     * @param cellHasFocus  Description of Parameter
968     * @return              The ListCellRendererComponent value
969     */
970    public Component getListCellRendererComponent(
971      JList list,
972      Object value,  // value to display
973    int index,  // cell index
974    boolean isSelected,  // is the cell selected
975    boolean cellHasFocus)
976    { // the list and the cell have the focus
977
978      JCheckBox jc = (JCheckBox) value;
979      setText(jc.getText());
980      setSelected(jc.isSelected());
981      return (Component) this;
982    }
983  }
984
985}
986
987
988
989