Skip to content

Commit 64dee36

Browse files
authored
Merge pull request #115 from fransjacobs/103-gui-performance
103 gui performance
2 parents f5b0313 + 120d574 commit 64dee36

31 files changed

+701
-4827
lines changed

nb-configuration.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ Any value defined here will override the pom.xml file value but is only applicab
3939
<com-junichi11-netbeans-changelf.use-project>true</com-junichi11-netbeans-changelf.use-project>
4040
<com-junichi11-netbeans-changelf.lf-kind>LF</com-junichi11-netbeans-changelf.lf-kind>
4141
<com-junichi11-netbeans-changelf.use-global>false</com-junichi11-netbeans-changelf.use-global>
42+
<netbeans.hint.jdkPlatform>JDK_21_Temurin</netbeans.hint.jdkPlatform>
4243
</properties>
4344
</project-shared-configuration>

src/main/java/jcs/JCS.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ public class JCS extends Thread {
6868

6969
private static UICallback uiCallback;
7070

71-
//private final List<RefreshEventListener> refreshEventListeners;
7271
private JCS() {
73-
//refreshEventListeners = new ArrayList<>();
7472
}
7573

7674
public static void logProgress(String message) {
@@ -237,6 +235,12 @@ public static void main(String[] args) {
237235
JCS jcs = JCS.getInstance();
238236

239237
jcs.startGui();
238+
239+
//check the connection to the command station
240+
if (!JCS.getJcsCommandStation().isConnected()) {
241+
JCS.getJcsCommandStation().connectInBackground();
242+
}
243+
240244
} else {
241245
Logger.error("Could not obtain a Persistent store. Quitting....");
242246
logProgress("Error! Can't Obtain a Persistent store!");
@@ -286,8 +290,6 @@ private void startGui() {
286290
jcsFrame.setVisible(true);
287291
jcsFrame.toFront();
288292
jcsFrame.showOverviewPanel();
289-
boolean con = "true".equalsIgnoreCase(System.getProperty("controller.autoconnect", "true"));
290-
jcsFrame.connect(con);
291293
});
292294

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

src/main/java/jcs/commandStation/JCSCommandStation.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,27 +118,36 @@ private JCSCommandStation(boolean autoConnectController) {
118118
}
119119
}
120120

121-
public final boolean connectInBackground() {
122-
executor.execute(() -> connect());
123-
121+
public final synchronized boolean connectInBackground() {
124122
long now = System.currentTimeMillis();
125-
long timemax = now + 2000;
123+
long start = now;
124+
long timemax = now + 3000;
125+
126+
executor.execute(() -> connect());
126127

127-
boolean con;
128-
synchronized (this) {
128+
boolean con = false;
129+
if (decoderController != null) {
129130
con = decoderController.isConnected();
130-
while (!con && timemax < now) {
131-
try {
132-
wait(500);
133-
} catch (InterruptedException ex) {
134-
Logger.trace(ex);
135-
}
136-
now = System.currentTimeMillis();
137-
}
138-
if (!(timemax < now)) {
139-
Logger.trace("Timeout connecting...");
131+
} else {
132+
Logger.trace("Can't connect as there is no DecoderController configured !");
133+
}
134+
135+
while (!con && now < timemax) {
136+
try {
137+
wait(500);
138+
} catch (InterruptedException ex) {
139+
Logger.trace(ex);
140140
}
141+
now = System.currentTimeMillis();
142+
con = decoderController.isConnected();
141143
}
144+
145+
if (con) {
146+
Logger.trace("Connected to " + decoderController.getCommandStationBean().getDescription() + " in " + (now - start) + " ms");
147+
} else {
148+
Logger.trace("Timeout connecting...");
149+
}
150+
142151
return con;
143152
}
144153

@@ -439,7 +448,7 @@ public boolean isPowerOn() {
439448
}
440449

441450
public void changeLocomotiveDirection(Direction newDirection, LocomotiveBean locomotive) {
442-
Logger.debug("Changing direction to " + newDirection + " for: " + locomotive.getName() + " id: " + locomotive.getId());
451+
Logger.debug("Changing direction to " + newDirection + " for: " + locomotive.getName() + " id: " + locomotive.getId() + " velocity: "+ locomotive.getVelocity());
443452

444453
int address;
445454
if ("marklin.cs".equals(locomotive.getCommandStationId()) || "esu-ecos".equals(locomotive.getCommandStationId())) {

src/main/java/jcs/commandStation/esu/ecos/net/EcosTCPConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public void run() {
264264
Logger.trace("Event has no END tag " + sb.toString() + " in " + (now - start) + " ms");
265265
} else {
266266
EcosMessage emsg = new EcosMessage(sb.toString());
267-
Logger.trace("Complete: " + emsg.isResponseComplete() + "\n" + emsg.getMessage() + "\n" + emsg.getResponse());
267+
Logger.trace("Complete: " + emsg.isResponseComplete() + ((emsg.getMessage() != null) ? " -> " + emsg.getMessage() + " -> " : "") + emsg.getResponse());
268268

269269
eventQueue.offer(emsg);
270270
}

src/main/java/jcs/entities/LocomotiveBean.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public class LocomotiveBean implements Serializable {
5454
private String dispatcherDirection;
5555
private String locomotiveDirection;
5656

57+
private Integer speedOne;
58+
private Integer speedTwo;
59+
private Integer speedThree;
60+
private Integer speedFour;
61+
5762
private Image locIcon;
5863
private CommandStationBean commandStationBean;
5964

@@ -321,6 +326,42 @@ public void setCommandStationId(String commandStationId) {
321326
this.commandStationId = commandStationId;
322327
}
323328

329+
@Column(name = "speed_1")
330+
public Integer getSpeedOne() {
331+
return speedOne;
332+
}
333+
334+
public void setSpeedOne(Integer speedOne) {
335+
this.speedOne = speedOne;
336+
}
337+
338+
@Column(name = "speed_2")
339+
public Integer getSpeedTwo() {
340+
return speedTwo;
341+
}
342+
343+
public void setSpeedTwo(Integer speedTwo) {
344+
this.speedTwo = speedTwo;
345+
}
346+
347+
@Column(name = "speed_3")
348+
public Integer getSpeedThree() {
349+
return speedThree;
350+
}
351+
352+
public void setSpeedThree(Integer speedThree) {
353+
this.speedThree = speedThree;
354+
}
355+
356+
@Column(name = "speed_4")
357+
public Integer getSpeedFour() {
358+
return speedFour;
359+
}
360+
361+
public void setSpeedFour(Integer speedFour) {
362+
this.speedFour = speedFour;
363+
}
364+
324365
@Transient
325366
public CommandStationBean getCommandStationBean() {
326367
return commandStationBean;

src/main/java/jcs/entities/SensorBean.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,18 +371,11 @@ public boolean equalsId(Object obj) {
371371

372372
@Override
373373
public String toString() {
374-
//return name;
375-
return toLogString();
374+
return name;
375+
//return toLogString();
376376
}
377377

378378
public String toLogString() {
379-
// String ids;
380-
// if (id == null) {
381-
// ids = "(" + generateId() + ")";
382-
// } else {
383-
// ids = id;
384-
// }
385-
386379
return "SensorBean{"
387380
+ "id="
388381
+ id

src/main/java/jcs/persistence/H2PersistenceService.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public FunctionBean getLocomotiveFunction(LocomotiveBean locomotive, Integer num
251251

252252
@Override
253253
public FunctionBean getLocomotiveFunction(Long locomotiveId, Integer number) {
254-
String commandStationId = getDefaultCommandStation().getId();
254+
//String commandStationId = getDefaultCommandStation().getId();
255255

256256
FunctionBean fb = database.where("locomotive_id=? and f_number=?", locomotiveId, number).first(FunctionBean.class);
257257
if (fb != null) {
@@ -970,15 +970,15 @@ public synchronized BlockBean persist(BlockBean block) {
970970
database.insert(block);
971971
}
972972

973-
changeSupport.firePropertyChange("data.blockr", prev, block);
973+
changeSupport.firePropertyChange("data.block", prev, block);
974974
return block;
975975
}
976976

977977
@Override
978978
public synchronized void remove(BlockBean block) {
979-
int rows = this.database.delete(block).getRowsAffected();
979+
int rows = database.delete(block).getRowsAffected();
980980
Logger.trace(rows + " rows deleted");
981-
changeSupport.firePropertyChange("data.sblock.deleted", block, null);
981+
changeSupport.firePropertyChange("data.block.deleted", block, null);
982982
}
983983

984984
@Override
@@ -990,7 +990,6 @@ public synchronized void removeAllBlocks() {
990990

991991
@Override
992992
public List<CommandStationBean> getCommandStations() {
993-
//List<CommandStationBean> commandStationBeans = database.where("enabled=true").results(CommandStationBean.class);
994993
List<CommandStationBean> commandStationBeans = database.results(CommandStationBean.class);
995994
return commandStationBeans;
996995
}

src/main/java/jcs/ui/DispatcherStatusPanel.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717

1818
import javax.swing.JPanel;
1919
import jcs.commandStation.events.RefreshEvent;
20-
import jcs.commandStation.events.RefreshEventListener;
2120
import jcs.ui.util.LocomotiveSelectionChangedListener;
2221

2322
/**
2423
*
2524
*/
26-
public class DispatcherStatusPanel extends JPanel implements RefreshEventListener {
25+
public class DispatcherStatusPanel extends JPanel { //implements RefreshEventListener {
2726

2827
private static final long serialVersionUID = 6158244271104499799L;
2928

@@ -43,15 +42,14 @@ public void refresh() {
4342
locomotiveTablePanel.refresh();
4443
}
4544

46-
@Override
47-
public void onChange(RefreshEvent event) {
48-
locomotiveTablePanel.onChange(event);
49-
}
45+
// @Override
46+
// public void onChange(RefreshEvent event) {
47+
// locomotiveTablePanel.onChange(event);
48+
// }
5049

5150
public void addLocomotiveSelectionChangeListener(LocomotiveSelectionChangedListener listener) {
5251
locomotiveTablePanel.addLocomotiveSelectionChangeListener(listener);
5352
dispatcherTablePanel.addLocomotiveSelectionChangeListener(listener);
54-
5553
}
5654

5755
public void removeLocomotiveSelectionChangeListener(LocomotiveSelectionChangedListener listener) {

src/main/java/jcs/ui/DriverCabPanel.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.concurrent.ExecutorService;
1919
import java.util.concurrent.Executors;
20+
import javax.swing.JPanel;
2021
import javax.swing.JSlider;
2122
import javax.swing.event.ChangeListener;
2223
import jcs.JCS;
@@ -34,7 +35,7 @@
3435
*
3536
* @author frans
3637
*/
37-
public class DriverCabPanel extends javax.swing.JPanel implements LocomotiveDirectionEventListener, LocomotiveSpeedEventListener, PowerEventListener {
38+
public class DriverCabPanel extends JPanel implements LocomotiveDirectionEventListener, LocomotiveSpeedEventListener, PowerEventListener {
3839

3940
private static final long serialVersionUID = 8833627645563021982L;
4041

@@ -53,7 +54,7 @@ public DriverCabPanel() {
5354
}
5455

5556
public DriverCabPanel(LocomotiveBean locomotiveBean) {
56-
executor = Executors.newFixedThreadPool(3);
57+
executor = Executors.newCachedThreadPool();
5758
initComponents();
5859
postInit();
5960
setLocomotiveBean(locomotiveBean);
@@ -416,20 +417,21 @@ public void onDirectionChange(LocomotiveDirectionEvent event) {
416417

417418
if (event.isEventFor(locomotiveBean)) {
418419
Logger.trace(lb.getName() + " direction changed from " + this.locomotiveBean.getDirection() + " to " + lb.getDirection());
420+
disableListener = true;
419421

420-
//locomotiveBean.setRichtung(lb.getRichtung());
421422
locomotiveBean.setDirection(lb.getDirection());
422423

423-
disableListener = true;
424424
if (Direction.BACKWARDS.equals(lb.getDirection())) {
425425
this.reverseButton.setSelected(true);
426426
} else {
427427
this.forwardButton.setSelected(true);
428428
}
429-
disableListener = false;
429+
430430
if (this.directionListener != null) {
431431
this.directionListener.onDirectionChange(event);
432432
}
433+
434+
disableListener = false;
433435
}
434436
}
435437

src/main/java/jcs/ui/JCSFrame.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ private void showLocomotives() {
220220
locomotiveDialog.setLocationRelativeTo(null);
221221
}
222222
locomotiveDialog.setVisible(true);
223+
224+
//Should add a listener here?
223225
}
224226

225227
private void showAccessories() {
@@ -969,20 +971,16 @@ public void connect(boolean connect) {
969971
if (JCS.getJcsCommandStation() != null) {
970972
if (connect) {
971973
String ip = JCS.getJcsCommandStation().getCommandStationBean().getIpAddress();
974+
String name = JCS.getJcsCommandStation().getCommandStationBean().getDescription();
972975
if (Ping.IsReachable(ip)) {
973976
if ("AWT-EventQueue-0".equals(Thread.currentThread().getName())) {
974977
JCS.getJcsCommandStation().connectInBackground();
975978
} else {
976-
977979
JCS.getJcsCommandStation().connect();
978980
}
979981
} else {
980982
Logger.debug("Can't reach ip " + ip + "...");
981-
982-
983-
JOptionPane.showMessageDialog(this, "Can't connect. "+ip+" is not reachable.", "Can't Connect", JOptionPane.ERROR_MESSAGE, null);
984-
985-
983+
JOptionPane.showMessageDialog(this, "Can't connect to " + name + ", " + ip + " is not reachable.", "Can't Connect", JOptionPane.ERROR_MESSAGE, null);
986984
}
987985

988986
InfoBean info = JCS.getJcsCommandStation().getCommandStationInfo();
@@ -1147,7 +1145,7 @@ private void startAllLocomotives() {
11471145
private String getTitleString() {
11481146
String jcsVersion = VersionInfo.getVersion();
11491147

1150-
if (JCS.getJcsCommandStation() != null && JCS.getJcsCommandStation().getCommandStationInfo() != null) {
1148+
if (JCS.getJcsCommandStation() != null && JCS.getJcsCommandStation().getCommandStationInfo() != null && JCS.getJcsCommandStation().getCommandStationInfo().getProductName() != null) {
11511149
InfoBean info = JCS.getJcsCommandStation().getCommandStationInfo();
11521150
return "JCS " + "Connected to " + info.getProductName();
11531151
} else {
@@ -1207,6 +1205,14 @@ public void powerChanged(PowerEvent event) {
12071205
powerButton.setSelected(event.isPower());
12081206
}
12091207

1208+
public void refreshData() {
1209+
Logger.trace("Refresh data due to settings change...");
1210+
}
1211+
1212+
public void refreshLocomotives() {
1213+
this.dispatcherStatusPanel.refresh();
1214+
}
1215+
12101216

12111217
// Variables declaration - do not modify//GEN-BEGIN:variables
12121218
private JMenuItem aboutMI;

src/main/java/jcs/ui/KeyboardSensorPanel.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import javax.swing.BorderFactory;
2525
import javax.swing.ImageIcon;
2626
import javax.swing.JFrame;
27-
import javax.swing.JLabel;
2827
import javax.swing.JPanel;
2928
import javax.swing.UIManager;
3029
import javax.swing.UnsupportedLookAndFeelException;

0 commit comments

Comments
 (0)