Skip to content

Commit 7f793ce

Browse files
committed
Fixes
1 parent 5e9bdf5 commit 7f793ce

File tree

8 files changed

+349
-53
lines changed

8 files changed

+349
-53
lines changed

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: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,29 +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();
123+
long start = now;
125124
long timemax = now + 3000;
126125

126+
executor.execute(() -> connect());
127+
127128
boolean con = false;
128-
synchronized (this) {
129-
if (decoderController != null) {
130-
con = decoderController.isConnected();
131-
}
132-
while (!con && timemax < now) {
133-
try {
134-
wait(500);
135-
} catch (InterruptedException ex) {
136-
Logger.trace(ex);
137-
}
138-
now = System.currentTimeMillis();
139-
}
140-
if (!(timemax < now)) {
141-
Logger.trace("Timeout connecting...");
129+
if (decoderController != null) {
130+
con = decoderController.isConnected();
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);
142140
}
141+
now = System.currentTimeMillis();
142+
con = decoderController.isConnected();
143143
}
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+
144151
return con;
145152
}
146153

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/ui/JCSFrame.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,8 @@ private void showLocomotives() {
220220
locomotiveDialog.setLocationRelativeTo(null);
221221
}
222222
locomotiveDialog.setVisible(true);
223-
223+
224224
//Should add a listener here?
225-
226-
227225
}
228226

229227
private void showAccessories() {
@@ -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 {
@@ -1210,11 +1208,11 @@ public void powerChanged(PowerEvent event) {
12101208
public void refreshData() {
12111209
Logger.trace("Refresh data due to settings change...");
12121210
}
1213-
1211+
12141212
public void refreshLocomotives() {
12151213
this.dispatcherStatusPanel.refresh();
12161214
}
1217-
1215+
12181216

12191217
// Variables declaration - do not modify//GEN-BEGIN:variables
12201218
private JMenuItem aboutMI;

0 commit comments

Comments
 (0)