Search in sources :

Example 6 with TablePosition

use of javafx.scene.control.TablePosition in project Gargoyle by callakrsos.

the class ClipboardKeyEventInstaller method install.

/********************************
	 * 작성일 :  2016. 9. 3. 작성자 : KYJ
	 *
	 *
	 * @param tb
	 ********************************/
public static void install(TableView<?> tb) {
    tb.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
        int type = -1;
        if (e.isControlDown() && e.getCode() == KeyCode.C) {
            if (e.isShiftDown()) {
                type = 2;
            } else {
                type = 1;
            }
            if (type == -1)
                return;
            ObservableList<TablePosition> selectedCells = tb.getSelectionModel().getSelectedCells();
            TablePosition tablePosition = selectedCells.get(0);
            TableColumn tableColumn = tablePosition.getTableColumn();
            int row = tablePosition.getRow();
            int col = tb.getColumns().indexOf(tableColumn);
            switch(type) {
                case 1:
                    StringBuilder sb = new StringBuilder();
                    for (TablePosition cell : selectedCells) {
                        if (row != cell.getRow()) {
                            sb.append("\n");
                            row++;
                        } else if (col != tb.getColumns().indexOf(cell.getTableColumn())) {
                            sb.append("\t");
                        }
                        Object cellData = getDisplayText(cell, row);
                        sb.append(ValueUtil.decode(cellData, cellData, "").toString());
                    }
                    FxClipboardUtil.putString(sb.toString());
                    break;
                case 2:
                    Object cellData = getDisplayText(tableColumn, row);
                    FxClipboardUtil.putString(ValueUtil.decode(cellData, cellData, "").toString());
                    break;
            }
            e.consume();
        }
    });
}
Also used : TablePosition(javafx.scene.control.TablePosition) TableColumn(javafx.scene.control.TableColumn)

Aggregations

TablePosition (javafx.scene.control.TablePosition)6 TableColumn (javafx.scene.control.TableColumn)4 ObservableList (javafx.collections.ObservableList)2 JavaTextArea (com.kyj.fx.voeditor.visual.component.text.JavaTextArea)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 ObservableValue (javafx.beans.value.ObservableValue)1 SelectionMode (javafx.scene.control.SelectionMode)1 TableCell (javafx.scene.control.TableCell)1 TableView (javafx.scene.control.TableView)1 TableViewSelectionModel (javafx.scene.control.TableView.TableViewSelectionModel)1 ComboBoxTableCell (javafx.scene.control.cell.ComboBoxTableCell)1 TextFieldTableCell (javafx.scene.control.cell.TextFieldTableCell)1 Image (javafx.scene.image.Image)1