Skip to content

Commit bafbde1

Browse files
committed
Initial code commit
1 parent 1a4def4 commit bafbde1

15 files changed

+1662
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.class
2+
*.jar
3+
.settings
4+
.classpath
5+
.gradle
6+
build/
7+
bin/

Settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'GenericTable'

build.gradle

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Common Build file for Generic Table
2+
3+
// The below lines are passed from the common builds
4+
//plugins {
5+
// id 'org.openjfx.javafxplugin'
6+
//}
7+
// ext.jdkver = 11
8+
9+
project.version = '1.0.4.0'
10+
11+
12+
if (jdkver == 11) {
13+
javafx {
14+
modules = [ 'javafx.controls','javafx.fxml' ]
15+
16+
version = "11.0.2"
17+
}
18+
}
19+
20+
21+
22+
23+
24+
dependencies {
25+
26+
// controlsfx & jfoenix
27+
if (jdkver == 1.8) {
28+
compile group: 'org.controlsfx', name: 'controlsfx', version: '8.40.15'
29+
} else if (jdkver >= 11) {
30+
compile group: 'org.controlsfx', name: 'controlsfx', version: '11.0.0'
31+
}
32+
compile 'commons-lang:commons-lang:2.6'
33+
}
34+
35+
36+
tasks.withType(JavaCompile) {
37+
options.warnings = false
38+
}
39+
40+
build.dependsOn
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
CustomTableColumn.java
3+
Copyright (C) 2019 Sriram C.
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.gems.table;
20+
21+
import javafx.geometry.Pos;
22+
import javafx.scene.Node;
23+
import javafx.scene.control.ContentDisplay;
24+
import javafx.scene.control.Label;
25+
import javafx.scene.control.TableColumn;
26+
import javafx.scene.layout.StackPane;
27+
import javafx.scene.text.TextAlignment;
28+
29+
public class CustomTableColumn<S,T> extends TableColumn<S,T> {
30+
String headerString;
31+
Label label;
32+
StackPane stack;
33+
34+
35+
public CustomTableColumn() {
36+
super();
37+
label = new Label();
38+
stack = new StackPane();
39+
40+
headerString = new String(getText());
41+
customHeader();
42+
}
43+
44+
public CustomTableColumn(String s) {
45+
super(s);
46+
headerString = new String(s);
47+
48+
label = new Label();
49+
stack = new StackPane();
50+
customHeader();
51+
}
52+
53+
54+
55+
public void customHeader() {
56+
//label.setStyle("-fx-padding: 8px;");
57+
label.setText(headerString);
58+
label.setWrapText(true);
59+
label.setAlignment(Pos.CENTER);
60+
label.setTextAlignment(TextAlignment.CENTER);
61+
label.setContentDisplay(ContentDisplay.RIGHT);
62+
label.setGraphicTextGap(4);
63+
64+
if (stack.getChildren() !=null) {
65+
stack.getChildren().remove(label);
66+
}
67+
stack.getChildren().add(label);
68+
stack.prefWidthProperty().bind(this.widthProperty());
69+
label.prefWidthProperty().bind(stack.prefWidthProperty());
70+
this.setText(null);
71+
this.setGraphic(stack);
72+
}
73+
74+
public void setHeaderText(String s) {
75+
headerString = s;
76+
customHeader();
77+
}
78+
79+
public String getHeaderString() {
80+
return headerString;
81+
}
82+
83+
public void setHeaderGraphic(Node n) {
84+
label.setGraphic(n);
85+
}
86+
87+
public Node getHeaderGraphic() {
88+
return(label.getGraphic());
89+
}
90+
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
DragSelectionCell.java
3+
Copyright (C) 2019 Sriram C.
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.gems.table;
20+
21+
import javafx.collections.ObservableList;
22+
import javafx.event.EventHandler;
23+
import javafx.scene.control.SelectionMode;
24+
import javafx.scene.control.TableCell;
25+
import javafx.scene.control.TableColumn;
26+
import javafx.scene.control.cell.TextFieldTableCell;
27+
import javafx.scene.input.MouseDragEvent;
28+
import javafx.scene.input.MouseEvent;
29+
import javafx.util.Callback;
30+
import javafx.util.StringConverter;
31+
import javafx.util.converter.DefaultStringConverter;
32+
33+
public class DragSelectionCell<S,T> extends TextFieldTableCell<S, T> {
34+
35+
static int startRow;
36+
static int startCol;
37+
38+
static int lastIndex;
39+
40+
public DragSelectionCell(final StringConverter<T> converter) {
41+
super(converter);
42+
43+
dragEvent();
44+
45+
}
46+
47+
48+
public DragSelectionCell() {
49+
50+
dragEvent();
51+
52+
}
53+
54+
public static <S> Callback<TableColumn<S, String>, TableCell<S, String>> forTableColumn() {
55+
return forTableColumn(new DefaultStringConverter());
56+
}
57+
58+
public static <S, T> Callback<TableColumn<S, T>, TableCell<S, T>> forTableColumn(
59+
final StringConverter<T> converter) {
60+
return list -> new DragSelectionCell<S, T>(converter);
61+
}
62+
63+
// FIXME select rectangle doesnt extend above on scrollviews
64+
65+
public void selectRectangle() {
66+
67+
ObservableList<TableColumn <S,?>> list = getTableColumn().getTableView().getColumns();
68+
int endCol = list.indexOf(getTableColumn());
69+
int endRow = getIndex();
70+
71+
System.out.println("On Drag Detected " +endRow + " " + endCol);
72+
73+
// Clear old rectangle
74+
// FIXME - only the rectangle selection should be cleared and not the previous selection
75+
getTableColumn().getTableView().getSelectionModel().clearSelection();
76+
77+
// is the below two lines needed
78+
getTableColumn().getTableView().getSelectionModel().setCellSelectionEnabled(true);//
79+
getTableColumn().getTableView().getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
80+
81+
// Select Rectangle
82+
for (int i = (startRow <= endRow) ? startRow:endRow; i <= ((startRow < endRow)?endRow:startRow);i++) {
83+
for (int j = (startCol <= endCol) ? startCol:endCol; j <= ((startCol < endCol) ? endCol : startCol);j++) {
84+
85+
getTableColumn().getTableView().getSelectionModel().select(i, list.get(j));
86+
87+
}
88+
}
89+
90+
}
91+
92+
93+
public void dragEvent() {
94+
setOnDragDetected(new EventHandler<MouseEvent>() {
95+
@Override
96+
public void handle(MouseEvent event) {
97+
startFullDrag();
98+
getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
99+
100+
ObservableList<TableColumn <S,?>> columnList = getTableColumn().getTableView().getColumns();
101+
startCol = columnList.indexOf(getTableColumn());
102+
startRow = getIndex();
103+
104+
System.out.println("On Drag Entered " +startRow + " " + startCol);
105+
106+
}
107+
});
108+
109+
setOnMouseDragEntered(new EventHandler<MouseDragEvent>() {
110+
111+
@Override
112+
public void handle(MouseDragEvent event) {
113+
System.out.println("On Drag Entered " +getIndex() + " " + getTableColumn());
114+
115+
selectRectangle();
116+
117+
}
118+
119+
});
120+
121+
setOnMouseDragExited(new EventHandler<MouseDragEvent>() {
122+
123+
@Override
124+
public void handle(MouseDragEvent event) {
125+
//getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
126+
System.out.println("On Drag exited " +getIndex() + " " + getTableColumn());
127+
128+
}
129+
130+
});
131+
}
132+
133+
}

0 commit comments

Comments
 (0)