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

Commit 16ddb81

Browse files
committed
UI Refactoring
1 parent 65565a8 commit 16ddb81

File tree

11 files changed

+510
-372
lines changed

11 files changed

+510
-372
lines changed

client/src/main/java/com/msc/serverbrowser/Client.java

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import javafx.beans.property.BooleanProperty;
3737
import javafx.beans.property.SimpleBooleanProperty;
3838
import javafx.fxml.FXMLLoader;
39+
import javafx.scene.Node;
3940
import javafx.scene.Parent;
4041
import javafx.scene.Scene;
4142
import javafx.scene.control.Alert;
@@ -54,25 +55,27 @@ public final class Client extends Application
5455
/**
5556
* Application icon that can be used everywhere where necessary.
5657
*/
57-
public static final Image APPLICATION_ICON = new Image(Client.class.getResourceAsStream(PathConstants.APP_ICON_PATH));
58+
public static final Image APPLICATION_ICON = new Image(
59+
Client.class.getResourceAsStream(PathConstants.APP_ICON_PATH));
5860
/**
5961
* Name of the application, as displayed to people.
6062
*/
61-
public static final String APPLICATION_NAME = "SA-MP Server Browser";
63+
public static final String APPLICATION_NAME = "SA-MP Server Browser";
6264

6365
/**
6466
* Default Dismiss-{@link Duration} that is used for TrayNotifications.
6567
*/
66-
public static final Duration DEFAULT_TRAY_DISMISS_TIME = Duration.seconds(10);
68+
public static final Duration DEFAULT_TRAY_DISMISS_TIME = Duration.seconds(10);
6769

68-
private static Client instance;
69-
private Stage stage;
70-
private MainController mainController;
70+
private static Client instance;
71+
private Stage stage;
72+
private MainController mainController;
7173

7274
/**
73-
* This property that indicates if an update check / download progress is ongoing.
75+
* This property that indicates if an update check / download progress is
76+
* ongoing.
7477
*/
75-
public final BooleanProperty updatingProperty = new SimpleBooleanProperty(false);
78+
public final BooleanProperty updatingProperty = new SimpleBooleanProperty(false);
7679

7780
/**
7881
* @return the clients singleton instance
@@ -138,7 +141,8 @@ private MainController loadUIAndGetController()
138141
}
139142

140143
/**
141-
* Deletes the scenes current stylesheets and reapplies either the dark theme or the default
144+
* Deletes the scenes current stylesheets and reapplies either the dark theme or
145+
* the default
142146
* theme.
143147
*/
144148
public void applyTheme()
@@ -147,6 +151,8 @@ public void applyTheme()
147151
final Scene scene = Objects.requireNonNull(stage.getScene());
148152

149153
scene.getStylesheets().clear();
154+
scene.getStylesheets().add(PathConstants.STYLESHEET_PATH + "mainStyleGeneral.css");
155+
150156
if (ClientPropertiesController.getPropertyAsBoolean(Property.USE_DARK_THEME))
151157
{
152158
scene.getStylesheets().add(PathConstants.STYLESHEET_PATH + "mainStyleDark.css");
@@ -210,20 +216,23 @@ private void loadUI(final Stage primaryStage)
210216
}
211217

212218
/**
213-
* Displays a dialog that tells the user that the server connection couldn't be established.
219+
* Displays a dialog that tells the user that the server connection couldn't be
220+
* established.
214221
*/
215222
public static void displayNoConnectionDialog()
216223
{
217224
new TrayNotificationBuilder()
218225
.type(NotificationTypeImplementations.ERROR)
219226
.title("Server connection could not be established")
220-
.message("The server connection doesn't seeem to be established, try again later, for more information check the log files.")
227+
.message(
228+
"The server connection doesn't seeem to be established, try again later, for more information check the log files.")
221229
.animation(Animations.SLIDE)
222230
.build().showAndDismiss(Client.DEFAULT_TRAY_DISMISS_TIME);
223231
}
224232

225233
/**
226-
* Creates files and folders that are necessary for the application to run properly and migrates
234+
* Creates files and folders that are necessary for the application to run
235+
* properly and migrates
227236
* old xml data.
228237
*/
229238
private static void initClient()
@@ -237,7 +246,8 @@ private static void initClient()
237246

238247
try
239248
{
240-
Files.copy(Client.class.getResourceAsStream("/com/msc/serverbrowser/tools/sampcmd.exe"), Paths.get(PathConstants.SAMP_CMD), StandardCopyOption.REPLACE_EXISTING);
249+
Files.copy(Client.class.getResourceAsStream("/com/msc/serverbrowser/tools/sampcmd.exe"),
250+
Paths.get(PathConstants.SAMP_CMD), StandardCopyOption.REPLACE_EXISTING);
241251
}
242252
catch (final IOException exception)
243253
{
@@ -249,7 +259,8 @@ private static void initClient()
249259
}
250260

251261
/**
252-
* Compares the local version number to the one lying on the server. If an update is available
262+
* Compares the local version number to the one lying on the server. If an
263+
* update is available
253264
* the user will be asked if he wants to update.
254265
*/
255266
public void checkForUpdates()
@@ -319,8 +330,9 @@ private static void displayUpdateNotification()
319330
private static void displayCantRetrieveUpdate()
320331
{
321332
final TrayNotification trayNotification = new TrayNotificationBuilder()
322-
.message("Latest version informations couldn't be retrieved, click to update manually.")
333+
.message("Couldn't retrieve the latest update, click to check manually.")
323334
.animation(Animations.POPUP)
335+
.type(NotificationTypeImplementations.ERROR)
324336
.title("Updating")
325337
.build();
326338

@@ -333,6 +345,11 @@ private static void displayCantRetrieveUpdate()
333345
trayNotification.showAndWait();
334346
}
335347

348+
public void addItemsToBottomBar(final Node... nodes)
349+
{
350+
mainController.addItemsToBottomBar(nodes);
351+
}
352+
336353
/**
337354
* Downloads the latest version and restarts the client.
338355
*/
@@ -347,7 +364,8 @@ private void downloadUpdate()
347364
final GHRelease release = releaseOptional.get();
348365
final String updateUrl = release.getAssets().get(0).getBrowserDownloadUrl();
349366
final URI url = new URI(updateUrl);
350-
FileUtility.downloadFile(url.toURL(), PathConstants.SAMPEX_TEMP_JAR, mainController.progressProperty(), (int) release.getAssets().get(0).getSize());
367+
FileUtility.downloadFile(url.toURL(), PathConstants.SAMPEX_TEMP_JAR, mainController.progressProperty(),
368+
(int) release.getAssets().get(0).getSize());
351369
}
352370
}
353371
catch (final IOException | URISyntaxException exception)
@@ -438,7 +456,8 @@ public static void main(final String[] args)
438456
{
439457
readApplicationArguments(args);
440458

441-
Thread.setDefaultUncaughtExceptionHandler((t, e) -> Logging.log(Level.SEVERE, "Uncaught exception in thread: " + t, e));
459+
Thread.setDefaultUncaughtExceptionHandler(
460+
(t, e) -> Logging.log(Level.SEVERE, "Uncaught exception in thread: " + t, e));
442461

443462
Application.launch(args);
444463
}

client/src/main/java/com/msc/serverbrowser/gui/controllers/implementations/MainController.java

Lines changed: 92 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,23 @@
99
import com.msc.serverbrowser.gui.View;
1010
import com.msc.serverbrowser.gui.controllers.interfaces.ViewController;
1111
import com.msc.serverbrowser.logging.Logging;
12+
import com.msc.serverbrowser.util.windows.OSUtility;
1213

1314
import javafx.application.Platform;
1415
import javafx.beans.property.DoubleProperty;
1516
import javafx.fxml.FXML;
1617
import javafx.fxml.FXMLLoader;
18+
import javafx.scene.Node;
1719
import javafx.scene.Parent;
20+
import javafx.scene.control.Hyperlink;
1821
import javafx.scene.control.Label;
1922
import javafx.scene.control.ProgressBar;
2023
import javafx.scene.control.ScrollPane;
21-
import javafx.scene.layout.StackPane;
24+
import javafx.scene.control.ToggleButton;
25+
import javafx.scene.control.ToggleGroup;
26+
import javafx.scene.control.Tooltip;
27+
import javafx.scene.layout.HBox;
28+
import javafx.scene.text.Font;
2229

2330
/**
2431
* Controller for the Main view, e.g. the view that contains the menu bar, the
@@ -30,30 +37,62 @@
3037
public class MainController implements ViewController
3138
{
3239
@FXML
33-
private StackPane menuItemFav;
40+
private ToggleButton menuItemFav;
3441
@FXML
35-
private StackPane menuItemAll;
42+
private ToggleButton menuItemAll;
3643
@FXML
37-
private StackPane menuItemUser;
44+
private ToggleButton menuItemUser;
3845
@FXML
39-
private StackPane menuItemVersion;
46+
private ToggleButton menuItemVersion;
4047
@FXML
41-
private StackPane menuItemFiles;
48+
private ToggleButton menuItemFiles;
4249
@FXML
43-
private StackPane menuItemSettings;
50+
private ToggleButton menuItemSettings;
4451

4552
@FXML
46-
private ScrollPane activeViewContainer;
47-
private View activeView;
53+
private ScrollPane activeViewContainer;
54+
private View activeView;
4855

4956
@FXML
50-
private Label globalProgressLabel;
57+
private Hyperlink hyperlinkGitHub;
5158
@FXML
52-
private ProgressBar globalProgressBar;
59+
private Hyperlink hyperlinkHelp;
60+
61+
@FXML
62+
private HBox bottomBarCustom;
63+
64+
@FXML
65+
private Label globalProgressLabel;
66+
@FXML
67+
private ProgressBar globalProgressBar;
5368

5469
@Override
5570
public void initialize()
5671
{
72+
Font.loadFont(MainController.class.getResource("/com/msc/serverbrowser/fonts/FontAwesome.otf").toExternalForm(),
73+
12);
74+
75+
final ToggleGroup menuToggleGroup = new ToggleGroup();
76+
menuItemFav.setToggleGroup(menuToggleGroup);
77+
menuItemAll.setToggleGroup(menuToggleGroup);
78+
menuItemUser.setToggleGroup(menuToggleGroup);
79+
menuItemVersion.setToggleGroup(menuToggleGroup);
80+
menuItemFiles.setToggleGroup(menuToggleGroup);
81+
menuItemSettings.setToggleGroup(menuToggleGroup);
82+
83+
menuItemFav.setText("\uf005");
84+
menuItemAll.setText("\uf0c9");
85+
menuItemUser.setText("\uf007");
86+
menuItemVersion.setText("\uf0ed");
87+
menuItemFiles.setText("\uf07b");
88+
menuItemSettings.setText("\uf013");
89+
90+
hyperlinkGitHub.setText("\uf09b");
91+
hyperlinkHelp.setText("\uf059");
92+
93+
hyperlinkGitHub.setTooltip(new Tooltip("Opens the GitHub project page."));
94+
hyperlinkHelp.setTooltip(new Tooltip("Opens the GitHub projects wiki page."));
95+
5796
if (ClientPropertiesController.getPropertyAsBoolean(Property.SAVE_LAST_VIEW))
5897
{
5998
loadView(View.valueOf(ClientPropertiesController.getPropertyAsInt(Property.LAST_VIEW)));
@@ -65,11 +104,43 @@ public void initialize()
65104

66105
}
67106

107+
@FXML
108+
private void openGitHub()
109+
{
110+
OSUtility.browse("https://github.com/Bios-Marcel/SererBrowser");
111+
}
112+
113+
@FXML
114+
private void openHelp()
115+
{
116+
OSUtility.browse("https://github.com/Bios-Marcel/SererBrowser/wiki");
117+
}
118+
119+
/**
120+
* Adds nodes to the Clients bottom bar.
121+
*
122+
* @param nodes
123+
* the node that will be added
124+
*/
125+
public void addItemsToBottomBar(final Node... nodes)
126+
{
127+
bottomBarCustom.getChildren().addAll(nodes);
128+
}
129+
130+
/**
131+
* @return the progress {@link DoubleProperty} of the {@link #globalProgressBar}
132+
*/
68133
public DoubleProperty progressProperty()
69134
{
70135
return globalProgressBar.progressProperty();
71136
}
72137

138+
/**
139+
* Sets the text infront of the global {@link ProgressBar} bar.
140+
*
141+
* @param text
142+
* the text tht appears infront of the global {@link ProgressBar}
143+
*/
73144
public void setGlobalProgressText(final String text)
74145
{
75146
globalProgressLabel.setText(text);
@@ -113,34 +184,27 @@ private void onSettingsMenuItemClicked()
113184

114185
private void loadView(final View view)
115186
{
116-
final String CLICKED_STYLE_CLASS = "clickedItem";
117-
118-
menuItemFav.getStyleClass().remove(CLICKED_STYLE_CLASS);
119-
menuItemSettings.getStyleClass().remove(CLICKED_STYLE_CLASS);
120-
menuItemUser.getStyleClass().remove(CLICKED_STYLE_CLASS);
121-
menuItemAll.getStyleClass().remove(CLICKED_STYLE_CLASS);
122-
menuItemVersion.getStyleClass().remove(CLICKED_STYLE_CLASS);
123-
menuItemFiles.getStyleClass().remove(CLICKED_STYLE_CLASS);
187+
bottomBarCustom.getChildren().clear();
124188

125189
switch (view)
126190
{
127191
case SERVERS_FAV:
128-
menuItemFav.getStyleClass().add(CLICKED_STYLE_CLASS);
192+
menuItemFav.setSelected(true);
129193
break;
130194
case SERVERS_ALL:
131-
menuItemAll.getStyleClass().add(CLICKED_STYLE_CLASS);
195+
menuItemAll.setSelected(true);
132196
break;
133197
case USERNAME_CHANGER:
134-
menuItemUser.getStyleClass().add(CLICKED_STYLE_CLASS);
198+
menuItemUser.setSelected(true);
135199
break;
136200
case VERSION_CHANGER:
137-
menuItemVersion.getStyleClass().add(CLICKED_STYLE_CLASS);
201+
menuItemVersion.setSelected(true);
138202
break;
139203
case FILES:
140-
menuItemFiles.getStyleClass().add(CLICKED_STYLE_CLASS);
204+
menuItemFiles.setSelected(true);
141205
break;
142206
case SETTINGS:
143-
menuItemSettings.getStyleClass().add(CLICKED_STYLE_CLASS);
207+
menuItemSettings.setSelected(true);
144208
break;
145209
default:
146210
throw new IllegalArgumentException("This View hasn't been implemented or is invalid: " + view);
@@ -156,6 +220,9 @@ private void loadFXML(final View view)
156220
{
157221
final FXMLLoader loader = new FXMLLoader();
158222
loader.setLocation(getClass().getResource(view.getFXMLPath()));
223+
224+
// Creating a new instance of the specified controller, controllers never have
225+
// constructor arguments, therefore this is supposedly fine.
159226
loader.setController(view.getControllerType().newInstance());
160227
final Parent toLoad = loader.load();
161228
toLoad.getStylesheets().setAll(view.getStylesheetPath());

0 commit comments

Comments
 (0)