Skip to content
This repository was archived by the owner on Nov 26, 2019. It is now read-only.

Commit 665b2ec

Browse files
committed
# Bugfixes
- Context Menu in Table now works like it should - Version Changer notifies if GTA can't be found - Server List now loads in a seperate Thread - Changelog Dialog at first startup after update - Minor API changes
1 parent 1c30895 commit 665b2ec

File tree

11 files changed

+259
-133
lines changed

11 files changed

+259
-133
lines changed

Client/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ bin/*
55
/bin/*
66
/target/
77
/cleanup.xml
8+
/.gradle/
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

Client/src/main/java/application/Client.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
public class Client extends Application
4242
{
43-
private static final Image applicationIcon = new Image(Client.class.getResourceAsStream("/icons/icon.png"));
43+
public static final Image APPLICATION_ICON = new Image(Client.class.getResourceAsStream("/icons/icon.png"));
4444

4545
public static final String APPLICATION_NAME = "SA-MP Client Extension";
4646

@@ -62,15 +62,10 @@ public static Client getInstance()
6262
public void start(final Stage primaryStage)
6363
{
6464
instance = this;
65-
6665
checkOperatingSystemCompatibility();
67-
6866
initClient();
69-
7067
establishConnection();
71-
7268
loadUI(primaryStage);
73-
7469
checkVersion();
7570
}
7671

@@ -92,6 +87,14 @@ private void establishConnection()
9287
}
9388
}
9489

90+
/**
91+
* @return {@link #stage}
92+
*/
93+
public Stage getStage()
94+
{
95+
return stage;
96+
}
97+
9598
/**
9699
* Loads the main UI.
97100
*
@@ -110,7 +113,7 @@ private void loadUI(final Stage primaryStage)
110113
final Scene scene = new Scene(root);
111114
scene.getStylesheets().add(getClass().getResource("/views/stylesheets/mainStyle.css").toExternalForm());
112115
primaryStage.setScene(scene);
113-
primaryStage.getIcons().add(applicationIcon);
116+
primaryStage.getIcons().add(APPLICATION_ICON);
114117
primaryStage.setTitle(APPLICATION_NAME);
115118
primaryStage.show();
116119
primaryStage.setMinWidth(primaryStage.getWidth());
@@ -125,6 +128,27 @@ private void loadUI(final Stage primaryStage)
125128
});
126129

127130
stage = primaryStage;
131+
132+
if (ClientProperties.getPropertyAsBoolean(PropertyIds.SHOW_CHANGELOG))
133+
{
134+
final Alert alert = new Alert(AlertType.INFORMATION);
135+
setAlertIcon(alert);
136+
alert.initOwner(stage);
137+
alert.initModality(Modality.APPLICATION_MODAL);
138+
alert.setTitle(APPLICATION_NAME);
139+
alert.setHeaderText("Your client has been updated");
140+
141+
final StringBuilder updateText = new StringBuilder();
142+
updateText.append("- Selection in Server Table has been fixed");
143+
updateText.append(System.lineSeparator());
144+
updateText.append("- Version Changer now gives info if there is no SA-MP installed / it can't be found");
145+
updateText.append(System.lineSeparator());
146+
updateText.append("- New Changelog Dialog ;D");
147+
148+
alert.setContentText(updateText.toString());
149+
alert.show();
150+
ClientProperties.setProperty(PropertyIds.SHOW_CHANGELOG, false);
151+
}
128152
}
129153
catch (final Exception e)
130154
{
@@ -162,9 +186,9 @@ public void displayNoConnectionDialog()
162186
alert.showAndWait();
163187
}
164188

165-
private void setAlertIcon(final Alert alert)
189+
public static void setAlertIcon(final Alert alert)
166190
{
167-
((Stage) alert.getDialogPane().getScene().getWindow()).getIcons().add(applicationIcon);
191+
((Stage) alert.getDialogPane().getScene().getWindow()).getIcons().add(APPLICATION_ICON);
168192
}
169193

170194
/**
@@ -257,6 +281,7 @@ private void updateLauncher()
257281
{
258282
final URI url = new URI(remoteUpdateService.getLatestVersionURL());
259283
FileUtility.downloadFile(url.toString(), getOwnJarFile().getPath().toString());
284+
ClientProperties.setProperty(PropertyIds.SHOW_CHANGELOG, true);
260285
selfRestart();
261286

262287
}

Client/src/main/java/data/properties/PropertyIds.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public enum PropertyIds
44
{
55
LAST_VIEW(0, 1, Integer.class),
66
MAXIMIZED(2, false, Boolean.class),
7-
FULLSCREEN(3, false, Boolean.class); // Not yet supported, but who knows.
7+
FULLSCREEN(3, false, Boolean.class), // Not yet supported, but who knows.
8+
SHOW_CHANGELOG(4, true, Boolean.class);
89

910
private int value;
1011

Client/src/main/java/gui/controllers/implementations/ServerListAllController.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import application.Client;
1414
import entities.SampServer;
1515
import entities.SampServerSerializeable;
16+
import javafx.application.Platform;
1617
import javafx.scene.control.Label;
1718
import logging.Logging;
1819

@@ -40,29 +41,35 @@ public void initialize()
4041
{
4142
super.initialize();
4243

43-
if (Objects.nonNull(Client.remoteDataService))
44+
serverTable.setPlaceholder(new Label("Loading server list, please wait a moment."));
45+
46+
final Thread thread = new Thread(() ->
4447
{
45-
try
48+
if (Objects.nonNull(Client.remoteDataService))
4649
{
47-
final byte[] serializedData = Client.remoteDataService.getAllServers();
48-
final List<SampServerSerializeable> serializedServers = (List<SampServerSerializeable>) deserialzieAndDecompress(serializedData);
50+
try
51+
{
52+
final byte[] serializedData = Client.remoteDataService.getAllServers();
53+
final List<SampServerSerializeable> serializedServers = (List<SampServerSerializeable>) deserialzieAndDecompress(serializedData);
4954

50-
servers.addAll(serializedServers.stream()
51-
.map(server -> new SampServer(server))
52-
.collect(Collectors.toSet()));
55+
servers.addAll(serializedServers.stream()
56+
.map(server -> new SampServer(server))
57+
.collect(Collectors.toSet()));
58+
}
59+
catch (final RemoteException e)
60+
{
61+
Logging.logger.log(Level.SEVERE, "Couldn't retrieve data from server.", e);
62+
Platform.runLater(() -> serverTable.setPlaceholder(new Label("Server connection couldn't be established.")));
63+
}
5364
}
54-
catch (final RemoteException e)
65+
else
5566
{
56-
Logging.logger.log(Level.SEVERE, "Couldn't retrieve data from server.", e);
57-
serverTable.setPlaceholder(new Label("Server connection couldn't be established."));
67+
Platform.runLater(() -> serverTable.setPlaceholder(new Label("Server connection couldn't be established.")));
5868
}
59-
}
60-
else
61-
{
62-
serverTable.setPlaceholder(new Label("Server connection couldn't be established."));
63-
}
6469

65-
updateGlobalInfo();
70+
Platform.runLater(() -> updateGlobalInfo());
71+
});
72+
thread.start();
6673
}
6774

6875
@Override

Client/src/main/java/gui/controllers/implementations/ServerListControllerMain.java

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.awt.datatransfer.StringSelection;
66
import java.net.InetAddress;
77
import java.net.UnknownHostException;
8+
import java.util.Arrays;
89
import java.util.List;
910
import java.util.Objects;
1011
import java.util.Optional;
@@ -36,6 +37,7 @@
3637
import javafx.scene.control.SelectionMode;
3738
import javafx.scene.control.SeparatorMenuItem;
3839
import javafx.scene.control.TableColumn;
40+
import javafx.scene.control.TableRow;
3941
import javafx.scene.control.TableView;
4042
import javafx.scene.control.TextField;
4143
import javafx.scene.control.TextInputDialog;
@@ -127,6 +129,44 @@ public void initialize()
127129
return p1 < p2 ? -1 : p1 == p2 ? 0 : 1;
128130
});
129131

132+
serverTable.setRowFactory(facotry ->
133+
{
134+
final TableRow<SampServer> row = new TableRow<>();
135+
136+
row.setOnMouseClicked(clicked ->
137+
{
138+
menu.hide();
139+
final List<SampServer> serverList = serverTable.getSelectionModel().getSelectedItems();
140+
final SampServer rowItem = row.getItem();
141+
142+
if (!serverTable.getSelectionModel().getSelectedIndices().contains(row.getIndex()))
143+
{
144+
if (rowItem != null)
145+
{
146+
serverTable.getSelectionModel().select(rowItem);
147+
if (clicked.getButton().equals(MouseButton.SECONDARY))
148+
{
149+
displayMenu(Arrays.asList(rowItem), clicked.getScreenX(), clicked.getScreenY());
150+
}
151+
}
152+
else
153+
{
154+
serverTable.getSelectionModel().clearSelection();
155+
}
156+
}
157+
else
158+
{
159+
if (!serverList.isEmpty() && clicked.getButton().equals(MouseButton.SECONDARY))
160+
{
161+
displayMenu(serverList, clicked.getScreenX(), clicked.getScreenY());
162+
}
163+
}
164+
165+
});
166+
167+
return row;
168+
});
169+
130170
serverTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
131171

132172
serverTable.setItems(sortedServers);
@@ -223,18 +263,13 @@ protected void onTableViewMouseReleased(final MouseEvent clicked)
223263
{
224264
updateServerInfo(serverList.get(0));
225265
}
226-
else if (clicked.getButton().equals(MouseButton.SECONDARY))
227-
{
228-
displayMenu(serverList, clicked.getScreenX(), clicked.getScreenY());
229-
}
230266
}
231267
}
232268

233269
@FXML
234270
protected void onTableViewKeyReleased(final KeyEvent released)
235271
{
236272
final SampServer server = serverTable.getSelectionModel().getSelectedItem();
237-
238273
final KeyCode usedKey = released.getCode();
239274

240275
if (usedKey.equals(KeyCode.DOWN) || usedKey.equals(KeyCode.KP_DOWN) || usedKey.equals(KeyCode.KP_UP) || usedKey.equals(KeyCode.UP))
@@ -335,17 +370,11 @@ protected void displayMenu(final List<SampServer> serverList, final double posX,
335370
}
336371
else if (clickedItem == addToFavouritesMenuItem)
337372
{
338-
for (final SampServer serverItem : serverList)
339-
{
340-
Favourites.addServerToFavourites(serverItem);
341-
}
373+
serverList.forEach(Favourites::addServerToFavourites);
342374
}
343375
else if (clickedItem == removeFromFavouritesMenuItem)
344376
{
345-
for (final SampServer serverItem : serverList)
346-
{
347-
Favourites.removeServerFromFavourites(serverItem);
348-
}
377+
serverList.forEach(Favourites::removeServerFromFavourites);
349378
servers.removeAll(serverList);
350379
}
351380
else if (clickedItem == copyIpAddressAndPortMenuItem)

0 commit comments

Comments
 (0)