Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Fix SpotBugs errors

AuthorDaveJarvis <email>
Date2023-11-02 01:10:20 GMT-0700
Commit8771652256dc3cc1c5ef59f043bbbbefd7b91b1b
Parent11dfee5
Delta76 lines added, 2 lines removed, 74-line increase
src/test/java/com/keenwrite/io/downloads/DownloadManagerTest.java
}
- private static final String URL =
+ private static final String URL_BINARY =
"https://keenwrite.com/downloads/KeenWrite.exe";
file.deleteOnExit();
- final var token = open( URL );
+ final var token = open( URL_BINARY );
final var executor = Executors.newFixedThreadPool( 1 );
final var result = token.download( file, listener );
src/main/java/com/keenwrite/ui/clipboard/SystemClipboard.java
+/* Copyright 2023 White Magic Software, Ltd. -- All rights reserved.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+package com.keenwrite.ui.clipboard;
+
+import javafx.scene.control.TableView;
+import javafx.scene.input.ClipboardContent;
+
+import java.util.TreeSet;
+
+import static javafx.scene.input.Clipboard.getSystemClipboard;
+
+/**
+ * Responsible for pasting into the computer's clipboard.
+ */
+public class SystemClipboard {
+ /**
+ * Copies the given text into the clipboard, overwriting all data.
+ *
+ * @param text The text to insert into the clipboard.
+ */
+ public static void write( final String text ) {
+ final var contents = new ClipboardContent();
+ contents.putString( text );
+ getSystemClipboard().setContent( contents );
+ }
+
+ /**
+ * Delegates to {@link #write(String)}.
+ *
+ * @see #write(String)
+ */
+ public static void write( final StringBuilder text ) {
+ write( text.toString() );
+ }
+
+ /**
+ * Copies the contents of the selected rows into the clipboard; code is from
+ * <a href="https://stackoverflow.com/a/48126059/59087">StackOverflow</a>.
+ *
+ * @param table The {@link TableView} having selected rows to copy.
+ */
+ public static <T> void write( final TableView<T> table ) {
+ final var sb = new StringBuilder( 2048 );
+ final var rows = new TreeSet<Integer>();
+ final var cols = table.getColumns();
+
+ for( final var position : table.getSelectionModel().getSelectedCells() ) {
+ rows.add( position.getRow() );
+ }
+
+ String rSep = "";
+
+ for( final var row : rows ) {
+ sb.append( rSep );
+
+ String cSep = "";
+
+ for( final var column : cols ) {
+ sb.append( cSep );
+
+ final var data = column.getCellData( row );
+ sb.append( data == null ? "" : data.toString() );
+
+ cSep = "\t";
+ }
+
+ rSep = "\n";
+ }
+
+ write( sb );
+ }
+}