Skip to content

Commit 5fa22ad

Browse files
committed
Dragging table scrolling + mnemonic key combinations + emitters updated
1 parent 1d4cf5f commit 5fa22ad

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

emitters.bin

104 Bytes
Binary file not shown.

src/main/java/ru/shemplo/tbs/gfx/TBSBondsTable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public TBSBondsTable (TBSTableType type) {
4747
private Parent makeTable (TBSTableType type) {
4848
table = new TableView <> ();
4949
table.getStylesheets ().setAll (STYLE_TABLES);
50+
TBSUIUtils.enableTableDraggingScroll (table);
5051
table.setBackground (TBSStyles.BG_TABLE);
5152
VBox.setVgrow (table, Priority.ALWAYS);
5253
table.setSelectionModel (null);

src/main/java/ru/shemplo/tbs/gfx/TBSUIUtils.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
package ru.shemplo.tbs.gfx;
22

3+
import java.util.concurrent.atomic.AtomicReference;
34
import java.util.function.BiConsumer;
45
import java.util.function.BiFunction;
56
import java.util.function.Consumer;
67
import java.util.function.Function;
78
import java.util.function.Predicate;
89

910
import javafx.beans.property.ObjectProperty;
11+
import javafx.geometry.Orientation;
1012
import javafx.geometry.Pos;
13+
import javafx.scene.Cursor;
14+
import javafx.scene.control.ScrollBar;
1115
import javafx.scene.control.TableColumn;
1216
import javafx.scene.control.TableRow;
17+
import javafx.scene.control.TableView;
1318
import javafx.scene.control.TextField;
1419
import javafx.scene.control.Tooltip;
1520
import javafx.scene.input.MouseButton;
1621
import javafx.scene.input.MouseEvent;
22+
import javafx.util.Pair;
1723
import lombok.Builder;
1824
import ru.shemplo.tbs.TBSUtils;
1925
import ru.shemplo.tbs.entity.LinkedObject;
@@ -137,4 +143,40 @@ public static <F, S> TableColumn <F, S> makeTBSTableColumnBase (
137143
return column;
138144
}
139145

146+
public static void enableTableDraggingScroll (TableView <?> table) {
147+
final var startDragPosition = new AtomicReference <Pair <Double, Double>> ();
148+
149+
table.setOnMouseDragged (me -> {
150+
final var from = startDragPosition.get ();
151+
if (from == null) { return; }
152+
153+
final var bars = table.lookupAll (".scroll-bar").toArray (ScrollBar []::new);
154+
if (bars [0].getOrientation () != Orientation.HORIZONTAL) {
155+
final var tmp = bars [0];
156+
bars [0] = bars [1];
157+
bars [1] = tmp;
158+
}
159+
160+
final var vertical = bars [1].getValue () + 7.5 * (from.getValue () - me.getY ()) / table.getHeight ();
161+
bars [1].setValue (TBSUIUtils.makeValueInBetween (vertical, bars [1]));
162+
163+
final var horizontal = bars [0].getValue () + 1250 * (from.getKey () - me.getX ()) / table.getWidth ();
164+
bars [0].setValue (TBSUIUtils.makeValueInBetween (horizontal, bars [0]));
165+
166+
startDragPosition.set (new Pair <> (me.getX (), me.getY ()));
167+
});
168+
table.setOnMousePressed (me -> {
169+
startDragPosition.set (new Pair <> (me.getX (), me.getY ()));
170+
table.setCursor (Cursor.CLOSED_HAND);
171+
});
172+
table.setOnMouseReleased (me -> {
173+
table.setCursor (Cursor.DEFAULT);
174+
startDragPosition.set (null);
175+
});
176+
}
177+
178+
public static double makeValueInBetween (double value, ScrollBar scrollBar) {
179+
return Math.max (scrollBar.getMin (), Math.min (scrollBar.getMax (), value));
180+
}
181+
140182
}

src/main/java/ru/shemplo/tbs/gfx/launcher/TBSLauncher.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ private Parent makeOpenExistingSection () {
159159
final var line = new HBox (8.0);
160160
line.setAlignment (Pos.BASELINE_LEFT);
161161

162-
openScannedBondsButton = new Button ("Open scanned bonds");
162+
openScannedBondsButton = new Button ("Open scanned _bonds");
163+
openScannedBondsButton.setMnemonicParsing (true);
163164
line.getChildren ().add (openScannedBondsButton);
164165

165166
line.getChildren ().add (bondsDumpDateText = new Text ());
@@ -172,8 +173,9 @@ private Parent makeEmittersEditorSection () {
172173
final var line = new HBox (8.0);
173174
line.setAlignment (Pos.BASELINE_LEFT);
174175

175-
openEmittertEditorButton = new Button ("Open emitters editor");
176+
openEmittertEditorButton = new Button ("Open _emitters editor");
176177
openEmittertEditorButton.minWidthProperty ().bind (openScannedBondsButton.widthProperty ());
178+
openEmittertEditorButton.setMnemonicParsing (true);
177179
line.getChildren ().add (openEmittertEditorButton);
178180

179181
line.getChildren ().add (new Text ("Edit name or credit rating of emitters which bonds were scanned at least once"));
@@ -191,21 +193,25 @@ private Parent makeScanNewSection () {
191193
startNewScanningButton.minWidthProperty ().bind (openScannedBondsButton.widthProperty ());
192194
buttonsColumn.getChildren ().add (startNewScanningButton);
193195

194-
createProfileButton = new Button ("Create new profile");
196+
createProfileButton = new Button ("Create _new profile");
195197
createProfileButton.minWidthProperty ().bind (openScannedBondsButton.widthProperty ());
196198
createProfileButton.setOnMouseClicked (me -> openProfileForm (me, null));
199+
createProfileButton.setMnemonicParsing (true);
197200
buttonsColumn.getChildren ().add (createProfileButton);
198201

199-
cloneProfileButton = new Button ("Clone profile");
202+
cloneProfileButton = new Button ("C_lone profile");
200203
cloneProfileButton.minWidthProperty ().bind (openScannedBondsButton.widthProperty ());
204+
cloneProfileButton.setMnemonicParsing (true);
201205
buttonsColumn.getChildren ().add (cloneProfileButton);
202206

203-
deleteProfileButton = new Button ("Delete profile");
207+
deleteProfileButton = new Button ("_Delete profile");
204208
deleteProfileButton.minWidthProperty ().bind (openScannedBondsButton.widthProperty ());
209+
deleteProfileButton.setMnemonicParsing (true);
205210
buttonsColumn.getChildren ().add (deleteProfileButton);
206211

207-
openStatisticsButton = new Button ("Calculate statistics");
212+
openStatisticsButton = new Button ("Calculate _statistics");
208213
openStatisticsButton.minWidthProperty ().bind (openScannedBondsButton.widthProperty ());
214+
openStatisticsButton.setMnemonicParsing (true);
209215
VBox.setMargin (openStatisticsButton, new Insets (8.0, 0.0, 0.0, 0.0));
210216
buttonsColumn.getChildren ().add (openStatisticsButton);
211217

0 commit comments

Comments
 (0)