Skip to content

Commit eecc399

Browse files
committed
Initial progress of new design, the theme isnt decided yet
1 parent 25c2ecd commit eecc399

21 files changed

Lines changed: 560 additions & 176 deletions

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@
6565
<artifactId>jackson-databind</artifactId>
6666
<version>2.19.2</version>
6767
</dependency>
68+
69+
<!-- FlatLaf dependency for modern UI look and feel -->
70+
<dependency>
71+
<groupId>com.formdev</groupId>
72+
<artifactId>flatlaf</artifactId>
73+
<version>3.6</version>
74+
</dependency>
6875
</dependencies>
6976

7077
<!-- Build configuration for the project -->

src/main/java/org/pwss/Start.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package org.pwss;
22

3-
import javax.swing.JFrame;
4-
import javax.swing.SwingUtilities;
3+
import javax.swing.*;
54

5+
import com.formdev.flatlaf.FlatDarculaLaf;
6+
import com.formdev.flatlaf.FlatDarkLaf;
7+
import com.formdev.flatlaf.FlatIntelliJLaf;
8+
import com.formdev.flatlaf.FlatLightLaf;
9+
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
610
import org.pwss.navigation.NavigationEvents;
711
import org.pwss.navigation.NavigationHandler;
812
import org.pwss.navigation.Screen;
@@ -11,27 +15,36 @@
1115

1216
public class Start {
1317
public static void main(String[] args) {
14-
SwingUtilities.invokeLater(() -> {
15-
// Create the main frame
16-
JFrame frame = new JFrame("Scan Integrity Scanner");
17-
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18-
frame.setSize(350, 250);
19-
frame.setLocationRelativeTo(null); // center on screen
18+
try {
19+
// Set FlatLaf Look and Feel
20+
UIManager.setLookAndFeel(new FlatDarkLaf());
2021

21-
// Create presenter factory
22-
PresenterFactory factory = new AppPresenterFactory();
22+
// Create Main UI of the application on the Event Dispatch Thread
23+
SwingUtilities.invokeLater(() -> {
24+
// Create the main frame
25+
JFrame frame = new JFrame("File Integrity Scanner");
26+
frame.setResizable(false);
27+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
28+
frame.setLocationRelativeTo(null); // center on screen
2329

24-
// Create navigation handler
25-
NavigationHandler navigator = new NavigationHandler(frame, factory);
30+
// Create presenter factory
31+
PresenterFactory factory = new AppPresenterFactory();
2632

27-
// Hook navigation listener so presenters can signal navigation
28-
NavigationEvents.setListener(navigator::navigateTo);
33+
// Create navigation handler
34+
NavigationHandler navigator = new NavigationHandler(frame, factory);
2935

30-
// Start with Login screen
31-
navigator.navigateTo(Screen.LOGIN);
36+
// Hook navigation listener so presenters can signal navigation
37+
NavigationEvents.setListener(navigator::navigateTo);
38+
39+
// Start with Login screen
40+
navigator.navigateTo(Screen.LOGIN);
41+
42+
// Finally, show the main frame hosting the screens :)
43+
frame.setVisible(true);
44+
});
45+
} catch( Exception ex ) {
46+
System.err.println( "Failed to initialize LaF" );
47+
}
3248

33-
// Finally, show the main frame hosting the screens :)
34-
frame.setVisible(true);
35-
});
3649
}
3750
}

src/main/java/org/pwss/model/entity/MonitoredDirectory.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@
22

33
import java.util.Date;
44

5-
/**
6-
* Represents a directory that is being monitored for changes.
7-
*
8-
* @param id Unique identifier for the monitored directory.
9-
* @param path Filesystem path of the monitored directory.
10-
* @param isActive Indicates if monitoring is currently active for this directory.
11-
* @param addedAt Timestamp when the directory was added for monitoring.
12-
* @param lastScanned Timestamp of the last scan performed on this directory.
13-
* @param notes Additional notes or comments about the monitored directory.
14-
* @param baselineEstablished Indicates if a baseline has been established for change detection.
15-
* @param includeSubdirectories Indicates if subdirectories should be included in monitoring.
16-
*/
17-
public record MonitoredDirectory(long id, String path, boolean isActive, Date addedAt, Date lastScanned, String notes,
5+
6+
public record MonitoredDirectory(long id, String path, boolean isActive, Time addedAt, Date lastScanned, Notes notes,
187
boolean baselineEstablished, boolean includeSubdirectories) {
198
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.pwss.model.entity;
2+
3+
public record Notes(long id, String notes, String prevNotes, String prevPrevNotes, Time time) {
4+
}

src/main/java/org/pwss/model/entity/Scan.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* @param status Status of the scan (e.g., "COMPLETED", "FAILED").
1111
* @param notes Additional notes or comments about the scan.
1212
* @param monitoredDirectory The monitored directory associated with this scan.
13+
* @param isBaselineScan Indicates if this scan is a baseline scan.
1314
*/
14-
public record Scan(long id, Date scanTime, String status, String notes, MonitoredDirectory monitoredDirectory) {
15+
public record Scan(long id, Time scanTime, String status, Notes notes, MonitoredDirectory monitoredDirectory,
16+
boolean isBaselineScan) {
1517
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.pwss.model.entity;
2+
3+
import java.util.Date;
4+
5+
public record Time(long id, Date created, Date updated) {
6+
}

src/main/java/org/pwss/model/service/ScanService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
import org.pwss.exception.scan.StartScanAllException;
77
import org.pwss.exception.scan.StartScanByIdException;
88
import org.pwss.exception.scan.StopScanException;
9+
import org.pwss.model.entity.Scan;
910
import org.pwss.model.service.network.Endpoint;
1011
import org.pwss.model.service.network.PwssHttpClient;
1112
import org.pwss.model.service.request.scan.StartSingleScanRequest;
1213

1314
import java.net.http.HttpResponse;
15+
import java.util.Collections;
16+
import java.util.List;
1417
import java.util.concurrent.ExecutionException;
1518

1619
/**
@@ -119,4 +122,15 @@ public boolean scanRunning() throws ScanStatusException, ExecutionException, Int
119122
default -> false;
120123
};
121124
}
125+
126+
public List<Scan> getMostRecentScans() throws ExecutionException, InterruptedException, JsonProcessingException {
127+
HttpResponse<String> response = PwssHttpClient.getInstance().request(Endpoint.MOST_RECENT_SCANS, null);
128+
129+
return switch (response.statusCode()) {
130+
case 200 -> List.of(objectMapper.readValue(response.body(), Scan[].class));
131+
case 401 -> throw new RuntimeException("Failed to fetch most recent scans: User not authorized to perform this action.");
132+
case 500 -> throw new RuntimeException("Failed to fetch most recent scans: Server error");
133+
default -> Collections.emptyList();
134+
};
135+
}
122136
}

src/main/java/org/pwss/model/service/network/Endpoint.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public enum Endpoint {
3838
* Endpoint for retrieving the status of a file integrity scan.
3939
*/
4040
SCAN_STATUS(HTTP_Method.GET, A.BASE_URL + A.SCAN + "status"),
41+
/**
42+
* Endpoint most recent scans for all active monitored directories.
43+
*/
44+
MOST_RECENT_SCANS(HTTP_Method.GET, A.BASE_URL + A.SCAN + "active-directory/most-recent"),
4145

4246
// Directory Endpoints
4347
/**
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.pwss.model.table;
2+
3+
import org.pwss.model.entity.MonitoredDirectory;
4+
import org.pwss.model.entity.Time;
5+
6+
import javax.swing.table.AbstractTableModel;
7+
import java.util.Date;
8+
import java.util.List;
9+
10+
public class MonitoredDirectoryTableModel extends AbstractTableModel {
11+
private final List<MonitoredDirectory> directories;
12+
private final String[] columnNames = {
13+
"ID", "Path", "Active", "Added At", "Last Scanned",
14+
"Notes", "Baseline Established", "Include Subdirectories"
15+
};
16+
17+
public MonitoredDirectoryTableModel(List<MonitoredDirectory> directories) {
18+
this.directories = directories;
19+
}
20+
21+
@Override
22+
public int getRowCount() {
23+
return directories.size();
24+
}
25+
26+
@Override
27+
public int getColumnCount() {
28+
return columnNames.length;
29+
}
30+
31+
@Override
32+
public String getColumnName(int column) {
33+
return columnNames[column];
34+
}
35+
36+
@Override
37+
public Class<?> getColumnClass(int columnIndex) {
38+
return switch (columnIndex) {
39+
case 0 -> Long.class;
40+
case 2, 6, 7 -> Boolean.class;
41+
case 3 -> Time.class;
42+
case 4 -> Date.class;
43+
default -> String.class;
44+
};
45+
}
46+
47+
@Override
48+
public Object getValueAt(int rowIndex, int columnIndex) {
49+
MonitoredDirectory dir = directories.get(rowIndex);
50+
return switch (columnIndex) {
51+
case 0 -> dir.id();
52+
case 1 -> dir.path();
53+
case 2 -> dir.isActive();
54+
case 3 -> dir.addedAt().created();
55+
case 4 -> dir.lastScanned();
56+
case 5 -> dir.notes() != null ? dir.notes().notes() : "";
57+
case 6 -> dir.baselineEstablished();
58+
case 7 -> dir.includeSubdirectories();
59+
default -> null;
60+
};
61+
}
62+
}
63+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.pwss.model.table;
2+
3+
import org.pwss.model.entity.Scan;
4+
5+
import javax.swing.table.AbstractTableModel;
6+
import java.util.List;
7+
8+
public class ScanTableModel extends AbstractTableModel {
9+
private final List<Scan> scans;
10+
private final String[] columnNames = {
11+
"ID", "Scan Time", "Status", "Notes", "Directory", "Baseline"
12+
};
13+
14+
public ScanTableModel(List<Scan> scans) {
15+
this.scans = scans;
16+
}
17+
18+
@Override
19+
public int getRowCount() {
20+
return scans.size();
21+
}
22+
23+
@Override
24+
public int getColumnCount() {
25+
return columnNames.length;
26+
}
27+
28+
@Override
29+
public String getColumnName(int column) {
30+
return columnNames[column];
31+
}
32+
33+
@Override
34+
public Object getValueAt(int rowIndex, int columnIndex) {
35+
Scan scan = scans.get(rowIndex);
36+
return switch (columnIndex) {
37+
case 0 -> scan.id();
38+
case 1 -> scan.scanTime().created();
39+
case 2 -> scan.status();
40+
case 3 -> scan.notes() != null ? scan.notes().notes() : "";
41+
case 4 -> scan.monitoredDirectory() != null ? scan.monitoredDirectory().path() : "";
42+
case 5 -> scan.isBaselineScan();
43+
default -> null;
44+
};
45+
}
46+
}

0 commit comments

Comments
 (0)