Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

103 gui performance #106

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1de426f
Refactor Tiles, WIP
fransjacobs Jan 18, 2025
e198c52
Fix persistance, WIP Commit for the weekend
fransjacobs Jan 19, 2025
fe9aa69
Fix rotating of Block
fransjacobs Jan 20, 2025
8db4c87
More refactoring for Block
fransjacobs Jan 22, 2025
14df7ec
More refactoring, Still issue with Block, it is continuously painting
fransjacobs Jan 24, 2025
4bab147
Slowly restoring the Edit functionality, but now a lot faster
fransjacobs Jan 25, 2025
cbcf078
Cross Tile working again
fransjacobs Jan 26, 2025
c95c95f
More refactoring issue with rotation of Cross
fransjacobs Jan 26, 2025
11edd00
Fix Cross
Jan 27, 2025
7b2ca1d
Tiles can be moved, extra check is needed for Block and Cross WIP
fransjacobs Jan 28, 2025
1cbd14c
Adding tests for checking Tile occupancy in the edit screen
Jan 29, 2025
0a9560e
Fix moving of tile in edit screen
fransjacobs Jan 30, 2025
0b4cff3
Multiple fixes
fransjacobs Jan 30, 2025
93ecce4
Refactored the UI code to make each tile following the MVC pattern.
fransjacobs Feb 7, 2025
80e933d
Cleanup code, minor fix in Crossing
fransjacobs Feb 8, 2025
0f83722
More cleanup
fransjacobs Feb 8, 2025
2f2ca21
The Sensor dispaly is now working again. Clicking on a Sensor will tr…
fransjacobs Feb 9, 2025
461ee52
Restored the control of Switches using the Command screen
fransjacobs Feb 9, 2025
138b012
Fixed draging, added Restored Signal Control
fransjacobs Feb 10, 2025
f499240
Autopilot is working more or less with some issues
fransjacobs Feb 12, 2025
f7ffd04
More refactoring TileFactory and duplicate TileCache removed
fransjacobs Feb 13, 2025
f0de294
Experiment for idle state
fransjacobs Feb 13, 2025
82c018c
Most of the issues are now solved
fransjacobs Feb 19, 2025
dd93284
GUI minor changes
fransjacobs Feb 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 1 addition & 39 deletions nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.license>apache20</netbeans.hint.license>
<netbeans.checkstyle.format>true</netbeans.checkstyle.format>
<org-netbeans-modules-editor-indent.text.x-antlr3.CodeStyle.project.indent-shift-width>4</org-netbeans-modules-editor-indent.text.x-antlr3.CodeStyle.project.indent-shift-width>
<org-netbeans-modules-editor-indent.text.x-yaml.CodeStyle.project.indent-shift-width>2</org-netbeans-modules-editor-indent.text.x-yaml.CodeStyle.project.indent-shift-width>
<org-netbeans-modules-editor-indent.text.x-antlr4.CodeStyle.project.indent-shift-width>4</org-netbeans-modules-editor-indent.text.x-antlr4.CodeStyle.project.indent-shift-width>
<org-netbeans-modules-editor-indent.text.x-toml.CodeStyle.project.indent-shift-width>2</org-netbeans-modules-editor-indent.text.x-toml.CodeStyle.project.indent-shift-width>
<org-netbeans-modules-editor-indent.text.x-toml.CodeStyle.project.spaces-per-tab>2</org-netbeans-modules-editor-indent.text.x-toml.CodeStyle.project.spaces-per-tab>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-line-wrap>none</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-line-wrap>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indent-shift-width>2</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indent-shift-width>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaces-per-tab>2</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaces-per-tab>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.enable-indent>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.enable-indent>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.tab-size>2</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.tab-size>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-limit-width>200</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-limit-width>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.expand-tabs>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.expand-tabs>
<org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap>none</org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap>
<org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width>4</org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width>
<org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab>4</org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab>
<org-netbeans-modules-editor-indent.CodeStyle.project.tab-size>8</org-netbeans-modules-editor-indent.CodeStyle.project.tab-size>
<org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width>80</org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width>
<org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs>true</org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs>
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
<netbeans.compile.on.save>all</netbeans.compile.on.save>
</properties>
</project-shared-configuration>
<?xml version="1.0" encoding="UTF-8"?><project-shared-configuration> <!--This file contains additional configuration written by modules in the NetBeans IDE.The configuration is intended to be shared among all the users of project andtherefore it is assumed to be part of version control checkout.Without this configuration present, some functionality in the IDE may be limited or fail altogether.--> <properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1"> <!--Properties that influence various parts of the IDE, especially code formatting and the like. You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.That way multiple projects can share the same settings (useful for formatting rules for example).Any value defined here will override the pom.xml file value but is only applicable to the current project.--> <netbeans.hint.license>apache20</netbeans.hint.license> <netbeans.checkstyle.format>true</netbeans.checkstyle.format> <org-netbeans-modules-editor-indent.text.x-antlr3.CodeStyle.project.indent-shift-width>4</org-netbeans-modules-editor-indent.text.x-antlr3.CodeStyle.project.indent-shift-width> <org-netbeans-modules-editor-indent.text.x-yaml.CodeStyle.project.indent-shift-width>2</org-netbeans-modules-editor-indent.text.x-yaml.CodeStyle.project.indent-shift-width> <org-netbeans-modules-editor-indent.text.x-antlr4.CodeStyle.project.indent-shift-width>4</org-netbeans-modules-editor-indent.text.x-antlr4.CodeStyle.project.indent-shift-width> <org-netbeans-modules-editor-indent.text.x-toml.CodeStyle.project.indent-shift-width>2</org-netbeans-modules-editor-indent.text.x-toml.CodeStyle.project.indent-shift-width> <org-netbeans-modules-editor-indent.text.x-toml.CodeStyle.project.spaces-per-tab>2</org-netbeans-modules-editor-indent.text.x-toml.CodeStyle.project.spaces-per-tab> <org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-line-wrap>none</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-line-wrap> <org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indent-shift-width>2</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indent-shift-width> <org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaces-per-tab>2</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaces-per-tab> <org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.enable-indent>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.enable-indent> <org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.tab-size>2</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.tab-size> <org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-limit-width>200</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-limit-width> <org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.expand-tabs>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.expand-tabs> <org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap>none</org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap> <org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width>4</org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width> <org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab>4</org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab> <org-netbeans-modules-editor-indent.CodeStyle.project.tab-size>8</org-netbeans-modules-editor-indent.CodeStyle.project.tab-size> <org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width>80</org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width> <org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs>true</org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs> <org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile> <netbeans.compile.on.save>all</netbeans.compile.on.save> <com-junichi11-netbeans-changelf.enable>true</com-junichi11-netbeans-changelf.enable> <com-junichi11-netbeans-changelf.use-project>true</com-junichi11-netbeans-changelf.use-project> <com-junichi11-netbeans-changelf.lf-kind>LF</com-junichi11-netbeans-changelf.lf-kind> <com-junichi11-netbeans-changelf.use-global>false</com-junichi11-netbeans-changelf.use-global> </properties></project-shared-configuration>
Expand Down
9 changes: 9 additions & 0 deletions nbproject/private/profiler/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="org.netbeans.modules.profiler.v2.features.ObjectsFeature_SelectedClassesMode_LIMIT_ALLOCATIONS_FLAG">10</entry>
<entry key="ACTIVATED_FEATURES">#org.netbeans.modules.profiler.v2.features.LocksFeature@#org.netbeans.modules.profiler.v2.features.MethodsFeature@#org.netbeans.modules.profiler.v2.features.MonitorFeature@</entry>
<entry key="org.netbeans.modules.profiler.v2.features.ObjectsFeature_SETTINGS_FLAG">true</entry>
<entry key="org.netbeans.modules.profiler.v2.features.ObjectsFeature_MODE_FLAG">ProjectClassesMode</entry>
<entry key="SINGLE_FEATURE">false</entry>
</properties>
Binary file not shown.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@
<artifactId>logback-classic</artifactId>
<version>1.2.13</version>
</dependency>
<!--dependency>
<groupId>com.sshtools</groupId>
<artifactId>two-slices</artifactId>
<version>0.9.4</version>
</dependency-->
<dependency>
<groupId>org.netbeans.external</groupId>
<artifactId>AbsoluteLayout</artifactId>
Expand Down
107 changes: 69 additions & 38 deletions src/main/java/jcs/JCS.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
package jcs;

import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import jcs.commandStation.JCSCommandStation;
Expand All @@ -46,41 +49,41 @@
*
*/
public class JCS extends Thread {

private static JCS instance = null;
private static JCSSplash splashScreen;
private static PersistenceService persistentStore;
private static JCSCommandStation jcsCommandStation;

private static MacOsAdapter osAdapter;
private static JCSFrame jcsFrame;
private static String version;

private final List<RefreshEventListener> refreshEventListeners;

private JCS() {
refreshEventListeners = new ArrayList<>();
}

public static void logProgress(String message) {
if (splashScreen != null) {
splashScreen.logProgress(message);
} else {
Logger.info(message);
}
}

public static JCSFrame getParentFrame() {
return jcsFrame;
}

public static PersistenceService getPersistenceService() {
if (persistentStore == null) {
persistentStore = PersistenceFactory.getService();
}
return persistentStore;
}

public static JCSCommandStation getJcsCommandStation() {
if (jcsCommandStation == null) {
if (getPersistenceService() != null) {
Expand All @@ -91,18 +94,18 @@ public static JCSCommandStation getJcsCommandStation() {
}
return jcsCommandStation;
}

private void startGui() {
JCS.logProgress("Check OS...");

if (RunUtil.isMacOSX()) {
MacOsAdapter.setMacOsProperties();
osAdapter = new MacOsAdapter();
}

java.awt.EventQueue.invokeLater(() -> {
jcsFrame = new JCSFrame();

if (RunUtil.isMacOSX()) {
osAdapter.setUiCallback(jcsFrame);
}
Expand All @@ -112,22 +115,22 @@ private void startGui() {
if (iconUrl != null) {
jcsFrame.setIconImage(new ImageIcon(iconUrl).getImage());
}

FrameMonitor.registerFrame(jcsFrame, JCS.class.getName());

jcsFrame.setVisible(true);
jcsFrame.toFront();
jcsFrame.showOverviewPanel();
if ("true".equalsIgnoreCase(System.getProperty("controller.autoconnect", "true"))) {
jcsFrame.connect(true);
}
});

JCS.logProgress("JCS started...");

int mb = 1024 * 1024;
Runtime runtime = Runtime.getRuntime();

StringBuilder sb = new StringBuilder();
sb.append("Used Memory: ");
sb.append((runtime.totalMemory() - runtime.freeMemory()) / mb);
Expand All @@ -138,7 +141,7 @@ private void startGui() {
sb.append(" [MB]. Max Memory: ");
sb.append(runtime.maxMemory() / mb);
sb.append(" [MB].");

Logger.info(sb);
splashScreen.hideSplash(200);
splashScreen.close();
Expand All @@ -155,21 +158,21 @@ public void run() {
ProcessFactory.getInstance().shutdown();
Logger.info("JCS " + VersionInfo.getVersion() + " session finished");
}

public static void addRefreshListener(RefreshEventListener refreshListener) {
instance.refreshEventListeners.add(refreshListener);
}

public static void removeRefreshListener(RefreshEventListener refreshListener) {
instance.refreshEventListeners.remove(refreshListener);
}

public static void settingsChanged(RefreshEvent refreshEvent) {
for (RefreshEventListener rel : instance.refreshEventListeners) {
rel.onChange(refreshEvent);
}
}

public static JCS getInstance() {
if (instance == null) {
instance = new JCS();
Expand All @@ -179,21 +182,38 @@ public static JCS getInstance() {
}
return instance;
}


private static boolean lockAppInstance() {
try {
String lockFilePath = System.getProperty("user.home") + File.separator + "jcs" + File.separator + "jcs.lock";

final File file = new File(lockFilePath);
if (file.createNewFile()) {
file.deleteOnExit();
return true;
}
return false;
} catch (IOException e) {
return false;
}
}

public static void main(String[] args) {
System.setProperty("fazecast.jSerialComm.appid", "JCS");
version = VersionInfo.getVersion();
Logger.info("Starting JCS Version " + version + "...");

if (GraphicsEnvironment.isHeadless()) {
Logger.error("This JDK environment is headless, can't start a GUI!");
//Quit....
System.exit(1);
}

//Load properties
RunUtil.loadProperties();

RunUtil.loadExternalProperties();

try {
String plaf = System.getProperty("jcs.plaf", "com.formdev.flatlaf.FlatLightLaf");
if (plaf != null) {
Expand All @@ -204,11 +224,19 @@ public static void main(String[] args) {
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
Logger.error(ex);
}


if (!lockAppInstance()) {
Logger.warn("Can not obtain a lock. Check if an other instance of JCS is running");
JOptionPane.showMessageDialog(null, "There is another instance of JCS running.", "JCS allready running", JOptionPane.INFORMATION_MESSAGE, null);
System.exit(0);
}

splashScreen = new JCSSplash();

splashScreen.showSplash();

splashScreen.setProgressMax(25);

logProgress("JCS is Starting...");

//Check the persistent properties, prepare environment
Expand All @@ -221,24 +249,27 @@ public static void main(String[] args) {

//Database file exist check whether an update is needed
String dbVersion = H2DatabaseUtil.getDataBaseVersion();

if (!H2DatabaseUtil.DB_VERSION.equals(dbVersion)) {
Logger.trace("Current DB Version " + dbVersion + " need to be updated to: " + H2DatabaseUtil.DB_VERSION + "...");
logProgress("Updating JCS Database to version " + H2DatabaseUtil.DB_VERSION + "...");
dbVersion = H2DatabaseUtil.updateDatabase();
}

logProgress("Connecting to existing Database version " + dbVersion + "...");

logProgress("Starting JCS Command Station...");
persistentStore = getPersistenceService();
jcsCommandStation = getJcsCommandStation();

if (persistentStore != null) {

if (persistentStore
!= null) {
if ("true".equalsIgnoreCase(System.getProperty("commandStation.autoconnect", "true"))) {
if (jcsCommandStation != null) {
boolean connected = jcsCommandStation.connect();
if (connected) {
logProgress("Connected with Command Station...");

boolean power = jcsCommandStation.isPowerOn();
logProgress("Track Power is " + (power ? "on" : "off"));
Logger.info("Track Power is " + (power ? "on" : "off"));
Expand All @@ -250,9 +281,9 @@ public static void main(String[] args) {
logProgress("NO Default Command Station found...");
}
}

logProgress("Starting UI...");

JCS jcs = JCS.getInstance();
jcs.startGui();
} else {
Expand All @@ -263,20 +294,20 @@ public static void main(String[] args) {
System.exit(0);
}
}

private static class Powerlistener implements PowerEventListener {

Powerlistener() {
}

@Override
public void onPowerChange(PowerEvent event) {
Logger.info("Track Power is " + (event.isPower() ? "on" : "off"));

if (JCS.jcsFrame != null) {
JCS.jcsFrame.powerChanged(event);
}
}
}

}
2 changes: 2 additions & 0 deletions src/main/java/jcs/commandStation/JCSCommandStationImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,13 @@ private class SensorChangeEventListener implements SensorEventListener {
@Override
public void onSensorChange(SensorEvent event) {
SensorBean sb = event.getSensorBean();
boolean newValue = event.isActive();
SensorBean dbsb = PersistenceFactory.getService().getSensor(sb.getDeviceId(), sb.getContactId());

if (dbsb != null) {
sb.setId(dbsb.getId());
sb.setName(dbsb.getName());
sb.setActive(newValue);
PersistenceFactory.getService().persist(sb);
}

Expand Down
Loading
Loading