RE: mouse clicking multiple cells

Hi Curtis,

I added a Vector to SpreadSheet.java so that when a user clicks on a cell,
that cell # is stored in the vector at SpreadSheet.selectCell(). I also
implemented DisplayListener.java with my class CellDisplayListener.java that
checks if the mouse was clicked and "control" was held down. In that case,
it calls selectCell() where it updates the vector of selected cells by
adding this one. 

The cell #'s seem to be added into the vector as I click on them, but
multiple cells cannot be highlighted at once. ie. I'll click on a cell and
then release the mouse to click on another cell but then the first cell is
no longer highlighted. Only the most recently selected cell is highlighted.
Is there a way to disable the de-selection of cells once the user clicks on
another cell? Below is CellDisplayListener.java:

package visad;

import java.util.EventListener;
import java.awt.*;
import java.awt.Event;
import java.awt.event.MouseEvent;



import java.rmi.*;
import visad.ss.*;

/**
   CellDisplayListener.java implements Visad's interface class:
DisplayListener.java
*/
public class CellDisplayListener implements DisplayListener {

        public SpreadSheet ss;
        
        public CellDisplayListener(SpreadSheet spread_sheet) {
                
                ss = spread_sheet;
                
        }

  /** send a DisplayEvent to this DisplayListener */
  public void displayChanged(DisplayEvent e) throws VisADException,
RemoteException {  
  try { 
        if (e.getId() == DisplayEvent.MOUSE_PRESSED && !e.isRemote()) {
                
                String name = null;
                Display d = e.getDisplay();
        name = d.getName();
        if (name.endsWith(".remote")) {
          // cloned cells need ".remote" stripped from their names
          name = name.substring(0, name.length() - 7);
        }       
                
                MouseEvent origEvent = (MouseEvent) e.getInputEvent(); 
                if (origEvent.isControlDown() == true) {  //is it a mouse
click AND control button held down?
                        FancySSCell fcell = (FancySSCell)
BasicSSCell.getSSCellByName(name);
                int ci = -1;
                int cj = -1;
                int height = ss.getHeight();
                int width = ss.getWidth();
                FancySSCell[][] displayCells = ss.getDisplayCells();
                
                for (int j=0; j< height; j++) {
                        for (int i=0; i< width; i++) {
                                if (fcell == displayCells[i][j]) {
                                ci = i;
                                cj = j;
                                }
                        }
                }
                if (BasicSSCell.DEBUG && (ci < 0 || cj < 0)) {
                        System.err.println("Warning: an unknown display
change occurred: " + "display (" + name + 
                         ") has changed, but there is no " +"corresponding
SSCell with that name!");
                }
        ss.selectCell(ci, cj);
        }
        }
 }
        
         catch (VisADException exc) {
        if (BasicSSCell.DEBUG) exc.printStackTrace();
      }
      catch (RemoteException exc) {
        if (BasicSSCell.DEBUG) exc.printStackTrace();
      }
        }


Thanks,
Michelle

Michelle Kam           (408) 742-2881
Lockheed Martin Space Systems Co. SSM/ATC/MSIS
B/153 O/L922 
1111 Lockheed Martin Way, Sunnyvale, CA 94089




-----Original Message-----
From: Curtis Rueden [mailto:curtis@xxxxxxxxxxxxx]
Sent: Wednesday, June 25, 2003 3:15 PM
To: Kam, Michelle C
Subject: RE: specifying fields from input file


Hi Michelle,

Add a DisplayListener to your displays, and in the
implementing displayChanged method, check for MOUSE_PRESSED
(and possibly other mouse-related) events. See
SpreadSheet.displayChanged for a basic example.

You can then access more information about these events by
calling e.getInputEvent() to obtain the original MouseEvent,
then probing the MouseEvent to find out which keyboard
modifiers were pressed for that event.

-Curtis

At 12:32 PM 6/24/2003, you wrote:
>Hi Curtis,
>
>I'm adding the capability for a user to select multiple cells by clicking
on
>control and the mouse button. Before I can add the vector class variable to
>SpreadSheet.java and add the selected cells to the vector in selectCell(),
I
>need to first allow the user to press "control" and click with the mouse
>button to select cells. In KeyboardBehaviorJ3D.java (I'm making the
>assumption that all cells will display the image in 3D), would it be
logical
>to call mapKeyToFunction(func, keycode, modifiers) and extend the
>functionKeys and functionMods arrays to store 1 more element, namely this
>control and mouse click? Then in execFunction(int function), add a case
>statement that will call SpreadSheet.selectCell()?
>
>I'm not sure if modifying KeyboardBehaviorJ3D.java is the right class to
>modify or if adding code to SpreadSheet.java under keyPressed(KeyEvent e){
>....
>  else if (keyCode == KeyEvent.VK_CONTROL) {
>        allow multiple cell selections...
>}
>
>would require fewer changes. 
>Do you have any recommendations?
>
>Thanks,
>Michelle


  • 2003 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: