RE: mouse clicking multiple cells

Hi Curtis,

I implemented the feature for a user to click on multiple cells and it is 
almost functioning correctly for my purposes. I can hold down the "control" 
button on the keyboard and click on a spreadsheet cell with the mouse for 
multiple cells. However, I can select multiple cells by not holding down 
"control" either.

I don?t want the user to be able to just click on the cells and have them 
selected unless they are pressing "control" simultaneously. I implemented the 
DisplayListener class with my own class called CellDisplayListener. In 
CellDisplayListener.java, I check if it was a mouse click event and "CONTROL" 
held down in the code below:  
e.getId() == DisplayEvent.MOUSE_PRESSED && !e.isRemote()) { ....

if (e.getModifiers() == InputEvent.CTRL_MASK) {  //is it a ....

The first if statement is true in printouts but it can't get past the 2nd if 
statement. Then, when I commented out the check for a control key, I can't 
click on control and select the cell obviously. This would mean that my 
CellDisplayListener *is* being used but it may not be the only class used 
because somewhere else in the package, it is allowing multiple cell clicking 
without holding down control. Do you know where else selectCell() would be 
called that would override my CellDisplayListener class?


FROM MY VISADAPI CLASS:
                        CellDisplayListener the_listener = new 
CellDisplayListener(mySS);  
//to detect mouse click events
                                
mySS.DisplayCells[width][height].addDisplayListener(the_listener); //add 
it to this cell

FROM SPREADSHEET CLASS:
  public void selectCell(int x, int y) {

        if (x < 0) x = 0;
    if (y < 0) y = 0;
    if (x >= NumVisX) x = NumVisX - 1;
    if (y >= NumVisY) y = NumVisY - 1;

    int cell_number = (x + (NumVisX * y));   //used as arg to 
getMappingForCell()
    Integer cellNum = new Integer(cell_number);

    // update borders of all cells
    //for (int j=0; j<NumVisY; j++) {
      //for (int i=0; i<NumVisX; i++) {
        //boolean selected = x == i && y == j;
        if (!DisplayCells[x][y].isSelectedAlready()) { //cell was not already 
selected, select cell
                DisplayCells[x][y].setSelected(true); //highlight cell
                userChoices.addElement(cellNum);   //add cellnum to vector
                // take off showing auto controls because a box pops up for 
every 
single cell.
                //DisplayCells[x][y].setAutoShowControls(true && 
AutoShowControls);
        }
        else { // cells was already selected, now deselect cell
                DisplayCells[x][y].setSelected(false);   //un-highlight cell
                userChoices.removeElement(cellNum); //remove this cellnum from 
vector 
holding user's choices
        }
      //}
    //}


    // update spreadsheet info, next 2 lines are questionable, cut out?
    // if user does not cut, copy, paste, edit...etc the cell, then I don't 
need to modify curX and curY
    CurX = x;
    CurY = y;

    FormulaText.getCaret().setVisible(true); // BIG HAMMER HACK
    refreshFormulaBar();
    refreshMenuCommands();
    refreshDisplayMenuItems();


FROM CELLDISPLAYLISTENER CLASS:

package visad;

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

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) {
                System.out.println("in CellDisplayLIstener constructor");
                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);
        }

                if (e.getInputEvent() != null) { //double check if it is a 
MouseEvent and we 
checked up above too
                        if (e.getModifiers() == InputEvent.CTRL_MASK) {  //is 
it a mouse click AND 
control button held down?
                        System.out.println("found it was CONTROL");
                                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();
      }
        }
}



-----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: