Skip to content

Commit f117638

Browse files
committed
Code cleanup (imports, etc.)
1 parent 0688a52 commit f117638

85 files changed

Lines changed: 298 additions & 455 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/main/java/sc/fiji/snt/BookmarkManager.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,7 @@ public void remove(final Path path, final int nodeIndex) {
15111511
* @param t the time position of the bookmark
15121512
*/
15131513
public void add(final int x, final int y, final int z, final int c, final int t) {
1514-
add((double) x, (double) y, (double) z, c, t, true);
1514+
add(x, y, z, c, t, true);
15151515
}
15161516

15171517
/**

‎src/main/java/sc/fiji/snt/ClarifyingKeyListener.java‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424

2525
import java.awt.Component;
2626
import java.awt.Container;
27-
import java.awt.event.ContainerEvent;
28-
import java.awt.event.ContainerListener;
29-
import java.awt.event.KeyEvent;
30-
import java.awt.event.KeyListener;
27+
import java.awt.event.*;
3128

3229
import ij.ImagePlus;
3330
import sc.fiji.snt.gui.GuiUtils;
@@ -37,7 +34,7 @@
3734
* It is used to capture special keys and to prevent the user from starting operations on the wrong window.
3835
* It has no scripting value.
3936
*/
40-
class ClarifyingKeyListener implements KeyListener, ContainerListener {
37+
class ClarifyingKeyListener extends KeyAdapter implements ContainerListener {
4138

4239
static { net.imagej.patcher.LegacyInjector.preinit(); } // required for _every_ class that imports ij. classes
4340

@@ -106,13 +103,7 @@ else if (e.isShiftDown() && e.isAltDown() && (keyCode == KeyEvent.VK_A)) {
106103

107104
}
108105

109-
@Override
110-
public void keyReleased(final KeyEvent e) {}
111-
112-
@Override
113-
public void keyTyped(final KeyEvent e) {}
114-
115-
private boolean isDoublePress(final KeyEvent ke) {
106+
private boolean isDoublePress(final KeyEvent ke) {
116107
if (lastKeyPressedCode == ke.getKeyCode() && ((ke.getWhen() -
117108
timeKeyDown) < DOUBLE_PRESS_INTERVAL)) return true;
118109
timeKeyDown = ke.getWhen();

‎src/main/java/sc/fiji/snt/PathAndFillManager.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@
6565
import java.nio.file.Files;
6666
import java.nio.file.Paths;
6767
import java.text.DecimalFormat;
68-
import java.time.LocalDate;
69-
import java.time.LocalDateTime;
70-
import java.time.LocalTime;
71-
import java.time.temporal.ChronoUnit;
7268
import java.util.List;
7369
import java.util.Map.Entry;
7470
import java.util.*;
@@ -599,7 +595,7 @@ private void error(final String msg) {
599595
protected void flushSWCPoints(final List<SWCPoint> swcPoints, final PrintWriter pw, final String commonFileHeader) {
600596
if (commonFileHeader == null || commonFileHeader.isBlank()) { // legacy header
601597
pw.println("# Exported from SNT v" + SNTUtils.VERSION + " on "
602-
+ LocalDateTime.of(LocalDate.now(), LocalTime.now().truncatedTo(ChronoUnit.SECONDS)));
598+
+ SNTUtils.nowTruncatedToSeconds());
603599
pw.println("# https://imagej.net/SNT");
604600
pw.println("#");
605601
if (plugin != null && plugin.accessToValidImageData()) {

‎src/main/java/sc/fiji/snt/PathDownsampler.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected static ArrayList<SimplePoint> downsample(
5252
final ArrayList<SimplePoint> points, final double permittedDeviation)
5353
{
5454
final int n = points.size();
55-
final SimplePoint startPoint = points.get(0);
55+
final SimplePoint startPoint = points.getFirst();
5656
final SimplePoint endPoint = points.get(n - 1);
5757
double vx = endPoint.x - startPoint.x;
5858
double vy = endPoint.y - startPoint.y;
@@ -90,7 +90,7 @@ protected static ArrayList<SimplePoint> downsample(
9090
secondPart.add(points.get(i));
9191
firstPart = downsample(firstPart, permittedDeviation);
9292
secondPart = downsample(secondPart, permittedDeviation);
93-
firstPart.remove(firstPart.size() - 1);
93+
firstPart.removeLast();
9494
firstPart.addAll(secondPart);
9595
return firstPart;
9696
}

‎src/main/java/sc/fiji/snt/PathManagerUI.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,7 @@ public void windowClosing(final WindowEvent e) {
26502650
}
26512651
}
26522652

2653-
private class JTreeMenuItem extends JMenuItem implements ActionListener {
2653+
private final class JTreeMenuItem extends JMenuItem implements ActionListener {
26542654

26552655
private static final long serialVersionUID = 1L;
26562656
private static final String COLLAPSE_ALL_CMD = "Collapse All";
@@ -2704,7 +2704,7 @@ public void actionPerformed(final ActionEvent e) {
27042704
}
27052705
}
27062706

2707-
private class JTreeCheckboxMenuItem extends JCheckBoxMenuItem implements ItemListener {
2707+
private final class JTreeCheckboxMenuItem extends JCheckBoxMenuItem implements ItemListener {
27082708

27092709
private static final long serialVersionUID = 1L;
27102710
private static final String TOGGLE_NAV_TOOLBAR = "Navigation Toolbar";
@@ -3006,7 +3006,7 @@ private void deselectAllTagsMenu() {
30063006
}
30073007

30083008
/** ActionListener for JCheckBoxMenuItem's "default tags" */
3009-
private class TagMenuItem extends JCheckBoxMenuItem implements ActionListener {
3009+
private final class TagMenuItem extends JCheckBoxMenuItem implements ActionListener {
30103010

30113011
private static final long serialVersionUID = 1L;
30123012

‎src/main/java/sc/fiji/snt/SNTPrefs.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class SNTPrefs { // TODO: Adopt PrefService
8383
public static final String BVV_RENDER_HEIGHT = "bvv.renderHeight";
8484
public static final String BVV_MAX_RENDER_MILLIS = "bvv.maxRenderMillis";
8585
public static final String BVV_MAX_STEP_IN_VOXELS = "bvv.maxStepInVoxels";
86-
public static int MAX_UNDO_STEPS = 20;
86+
public static final int MAX_UNDO_STEPS = 20;
8787

8888
/** Boolean identifiers */
8989
private static final int DRAW_DIAMETERS = 1;

‎src/main/java/sc/fiji/snt/SNTService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ public Viewer3D getRecViewer() {
502502
if (plugin != null) {
503503
final Viewer3D viewer = getInstanceViewer();
504504
if (viewer == null) {
505-
class SNTViewer3D extends Viewer3D {
505+
final class SNTViewer3D extends Viewer3D {
506506
private SNTViewer3D() {
507507
super(plugin);
508508
}

‎src/main/java/sc/fiji/snt/SNTUI.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7308,7 +7308,7 @@ protected boolean saveAllPathsToSwc(final String filePath, final String commonFi
73087308
return pathAndFillManager.exportAllPathsAsSWC(primaryPaths, filePath, commonFileHeader);
73097309
}
73107310

7311-
private class ImportAction {
7311+
private final class ImportAction {
73127312

73137313
private static final int TRACES = 0;
73147314
private static final int SWC = 1;

‎src/main/java/sc/fiji/snt/SNTUtils.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
import java.text.DecimalFormat;
6969
import java.text.NumberFormat;
7070
import java.text.SimpleDateFormat;
71+
import java.time.LocalDate;
72+
import java.time.LocalDateTime;
73+
import java.time.LocalTime;
74+
import java.time.temporal.ChronoUnit;
7175
import java.util.List;
7276
import java.util.*;
7377
import java.util.concurrent.ExecutionException;
@@ -676,6 +680,14 @@ private static void addMatchingBackups(final List<File> copies, final File dir,
676680
}
677681
}
678682

683+
/**
684+
* Returns the current date-time truncated to whole seconds, e.g., for stamping exported content with a
685+
* generation time.
686+
*/
687+
public static LocalDateTime nowTruncatedToSeconds() {
688+
return LocalDateTime.of(LocalDate.now(), LocalTime.now().truncatedTo(ChronoUnit.SECONDS));
689+
}
690+
679691
public static String getTimeStamp() {
680692
return new SimpleDateFormat(TIMESTAMP_PATTERN).format(new Date());
681693
}

‎src/main/java/sc/fiji/snt/SciViewSNT.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ private void assembleSoma(final List<PointInImage> somaPoints,
416416
return;
417417
case 1:
418418
// single point soma: http://neuromorpho.org/SomaFormat.html
419-
final PointInImage sCenter = somaPoints.get(0);
419+
final PointInImage sCenter = somaPoints.getFirst();
420420
somaSubShape = sciView.addSphere(convertPIIToVector3(sCenter), DEF_NODE_RADIUS, col);
421421
return;
422422
case 3:

0 commit comments

Comments
 (0)