modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableRowBehaviorBase.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization
   1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.scene.control.behavior;
  27 
  28 import javafx.collections.ObservableList;
  29 import javafx.scene.control.Cell;
  30 import javafx.scene.control.Control;
  31 import javafx.scene.control.TableColumnBase;
  32 import javafx.scene.control.TablePositionBase;
  33 import javafx.scene.control.TableSelectionModel;
  34 import javafx.scene.input.MouseButton;
  35 import javafx.scene.input.MouseEvent;
  36 
  37 import java.util.Collections;
  38 import java.util.List;
  39 
  40 public abstract class TableRowBehaviorBase<T extends Cell> extends CellBehaviorBase<T> {
  41 
  42     /***************************************************************************
  43      *                                                                         *
  44      * Constructors                                                            *
  45      *                                                                         *
  46      **************************************************************************/
  47 
  48     public TableRowBehaviorBase(T control) {
  49         super(control, Collections.emptyList());
  50     }
  51 
  52 
  53 
  54     /***************************************************************************
  55      *                                                                         *
  56      * Public API                                                              *
  57      *                                                                         *
  58      **************************************************************************/
  59 
  60     @Override public void mousePressed(MouseEvent e) {
  61         // we only care about clicks to the right of the right-most column
  62         if (! isClickPositionValid(e.getX(), e.getY())) return;
  63 
  64         super.mousePressed(e);
  65     }
  66 
  67     @Override protected abstract TableSelectionModel<?> getSelectionModel();
  68 
  69     protected abstract TablePositionBase<?> getFocusedCell();


  92         final TableSelectionModel<?> sm = getSelectionModel();
  93         if (sm == null || sm.isCellSelectionEnabled()) return;
  94 
  95         final int index = getIndex();
  96         final boolean isAlreadySelected = sm.isSelected(index);
  97         if (clickCount == 1) {
  98             // we only care about clicks to the right of the right-most column
  99             if (! isClickPositionValid(x, y)) return;
 100 
 101             // In the case of clicking to the right of the rightmost
 102             // TreeTableCell, we should still support selection, so that
 103             // is what we are doing here.
 104             if (isAlreadySelected && shortcutDown) {
 105                 sm.clearSelection(index);
 106             } else {
 107                 if (shortcutDown) {
 108                     sm.select(getIndex());
 109                 } else if (shiftDown) {
 110                     // we add all rows between the current focus and
 111                     // this row (inclusive) to the current selection.
 112                     TablePositionBase<?> anchor = TableCellBehavior.getAnchor(table, getFocusedCell());
 113                     final int anchorRow = anchor.getRow();
 114                     selectRows(anchorRow, index);
 115                 } else {
 116                     simpleSelect(button, clickCount, shortcutDown);
 117                 }
 118             }
 119         } else {
 120             simpleSelect(button, clickCount, shortcutDown);
 121         }
 122     }
 123 
 124     @Override protected boolean isClickPositionValid(final double x, final double y) {
 125         // get width of all visible columns (we only care about clicks to the
 126         // right of the right-most column)
 127         List<TableColumnBase<T, ?>> columns = getVisibleLeafColumns();
 128         double width = 0.0;
 129         for (int i = 0; i < columns.size(); i++) {
 130             width += columns.get(i).getWidth();
 131         }
 132 
   1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.scene.control.behavior;
  27 
  28 import javafx.collections.ObservableList;
  29 import javafx.scene.control.Cell;
  30 import javafx.scene.control.Control;
  31 import javafx.scene.control.TableColumnBase;
  32 import javafx.scene.control.TablePositionBase;
  33 import javafx.scene.control.TableSelectionModel;
  34 import javafx.scene.input.MouseButton;
  35 import javafx.scene.input.MouseEvent;
  36 

  37 import java.util.List;
  38 
  39 public abstract class TableRowBehaviorBase<T extends Cell> extends CellBehaviorBase<T> {
  40 
  41     /***************************************************************************
  42      *                                                                         *
  43      * Constructors                                                            *
  44      *                                                                         *
  45      **************************************************************************/
  46 
  47     public TableRowBehaviorBase(T control) {
  48         super(control);
  49     }
  50 
  51 
  52 
  53     /***************************************************************************
  54      *                                                                         *
  55      * Public API                                                              *
  56      *                                                                         *
  57      **************************************************************************/
  58 
  59     @Override public void mousePressed(MouseEvent e) {
  60         // we only care about clicks to the right of the right-most column
  61         if (! isClickPositionValid(e.getX(), e.getY())) return;
  62 
  63         super.mousePressed(e);
  64     }
  65 
  66     @Override protected abstract TableSelectionModel<?> getSelectionModel();
  67 
  68     protected abstract TablePositionBase<?> getFocusedCell();


  91         final TableSelectionModel<?> sm = getSelectionModel();
  92         if (sm == null || sm.isCellSelectionEnabled()) return;
  93 
  94         final int index = getIndex();
  95         final boolean isAlreadySelected = sm.isSelected(index);
  96         if (clickCount == 1) {
  97             // we only care about clicks to the right of the right-most column
  98             if (! isClickPositionValid(x, y)) return;
  99 
 100             // In the case of clicking to the right of the rightmost
 101             // TreeTableCell, we should still support selection, so that
 102             // is what we are doing here.
 103             if (isAlreadySelected && shortcutDown) {
 104                 sm.clearSelection(index);
 105             } else {
 106                 if (shortcutDown) {
 107                     sm.select(getIndex());
 108                 } else if (shiftDown) {
 109                     // we add all rows between the current focus and
 110                     // this row (inclusive) to the current selection.
 111                     TablePositionBase<?> anchor = getAnchor(table, getFocusedCell());
 112                     final int anchorRow = anchor.getRow();
 113                     selectRows(anchorRow, index);
 114                 } else {
 115                     simpleSelect(button, clickCount, shortcutDown);
 116                 }
 117             }
 118         } else {
 119             simpleSelect(button, clickCount, shortcutDown);
 120         }
 121     }
 122 
 123     @Override protected boolean isClickPositionValid(final double x, final double y) {
 124         // get width of all visible columns (we only care about clicks to the
 125         // right of the right-most column)
 126         List<TableColumnBase<T, ?>> columns = getVisibleLeafColumns();
 127         double width = 0.0;
 128         for (int i = 0; i < columns.size(); i++) {
 129             width += columns.get(i).getWidth();
 130         }
 131