mirror of
https://github.com/DanilaFe/abacus
synced 2024-09-07 00:03:05 -07:00
Implement a cell that copies input when clicked, and add it to table.
This commit is contained in:
parent
4b57c7f67b
commit
942326f6f7
|
@ -3,15 +3,14 @@ package org.nwapw.abacus.fx;
|
|||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.util.Callback;
|
||||
import org.nwapw.abacus.Abacus;
|
||||
import org.nwapw.abacus.number.NumberInterface;
|
||||
import org.nwapw.abacus.tree.TreeNode;
|
||||
|
||||
|
||||
public class AbacusController {
|
||||
|
||||
private static final String ERR_SYNTAX = "Syntax Error";
|
||||
|
@ -38,12 +37,18 @@ public class AbacusController {
|
|||
|
||||
@FXML
|
||||
public void initialize(){
|
||||
Callback<TableColumn<HistoryModel, String>, TableCell<HistoryModel, String>> cellFactory =
|
||||
param -> new CopyableCell<>();
|
||||
|
||||
abacus = new Abacus();
|
||||
historyData = FXCollections.observableArrayList();
|
||||
historyTable.setItems(historyData);
|
||||
historyTable.getSelectionModel().setCellSelectionEnabled(true);
|
||||
inputColumn.setCellFactory(cellFactory);
|
||||
inputColumn.setCellValueFactory(cell -> cell.getValue().inputProperty());
|
||||
parsedColumn.setCellFactory(cellFactory);
|
||||
parsedColumn.setCellValueFactory(cell -> cell.getValue().parsedProperty());
|
||||
outputColumn.setCellFactory(cellFactory);
|
||||
outputColumn.setCellValueFactory(cell -> cell.getValue().outputProperty());
|
||||
}
|
||||
|
||||
|
|
26
src/main/java/org/nwapw/abacus/fx/CopyableCell.java
Normal file
26
src/main/java/org/nwapw/abacus/fx/CopyableCell.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package org.nwapw.abacus.fx;
|
||||
|
||||
import javafx.scene.control.TableCell;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
|
||||
public class CopyableCell<S, T> extends TableCell<S, T> {
|
||||
|
||||
public CopyableCell(){
|
||||
addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
|
||||
if(event.getClickCount() == 2){
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard()
|
||||
.setContents(new StringSelection(getText()), null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateItem(T item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText((empty || item == null) ? null : item.toString());
|
||||
setGraphic(null);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user