Skip to content

Commit 319e97d

Browse files
authored
Merge pull request #177 from Idrinth/adding-progress-bar
2 parents a1c0879 + 8a98ec4 commit 319e97d

20 files changed

+618
-102
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>de.idrinth</groupId>
55
<artifactId>WARAddonClient</artifactId>
6-
<version>1.13.0</version>
6+
<version>1.14.0</version>
77
<packaging>jar</packaging>
88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -175,7 +175,7 @@
175175
<plugin>
176176
<artifactId>jdeb</artifactId>
177177
<groupId>org.vafer</groupId>
178-
<version>1.9</version>
178+
<version>1.8</version>
179179
<executions>
180180
<execution>
181181
<phase>package</phase>

src/main/java/de/idrinth/waraddonclient/CliMain.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import de.idrinth.waraddonclient.cli.AliasOption;
44
import de.idrinth.waraddonclient.cli.AliasParser;
5+
import de.idrinth.waraddonclient.cli.Progress;
56
import de.idrinth.waraddonclient.service.*;
67
import de.idrinth.waraddonclient.model.CmdAddonList;
78
import de.idrinth.waraddonclient.service.logger.CliLogger;
@@ -55,7 +56,7 @@ protected void main(MultiLogger logger, Config config, Request client, FileSyste
5556
logger.info("Set location to "+config.getWARPath());
5657
}
5758
file.checkPosition();
58-
CmdAddonList addonList = new CmdAddonList(client, logger, new XmlParser(), config);
59+
CmdAddonList addonList = new CmdAddonList(client, logger, new XmlParser(), config, new Progress());
5960
addonList.run();
6061
if (cli.hasOption("update-all")) {
6162
addonList.update();

src/main/java/de/idrinth/waraddonclient/GuiMain.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import de.idrinth.waraddonclient.service.Config;
44
import de.idrinth.waraddonclient.gui.FrameRestorer;
5+
import de.idrinth.waraddonclient.gui.Progress;
56
import de.idrinth.waraddonclient.gui.ThemeManager;
67
import de.idrinth.waraddonclient.gui.Window;
78
import de.idrinth.waraddonclient.model.GuiAddonList;
@@ -35,8 +36,11 @@ protected void main(MultiLogger logger, Config config, Request client, FileSyste
3536
schedule.register(30, watcher);
3637
java.awt.EventQueue.invokeLater(() -> {
3738
Version version = new Version(client, logger);
38-
Window window = new Window(addonList, version, themes, logger, schedule, config, new Backup(config), restarter);
39-
new FrameRestorer(config).restore(window);
39+
Progress progress = new Progress(config);
40+
FrameRestorer restorer = new FrameRestorer(config);
41+
Window window = new Window(addonList, version, themes, logger, schedule, config, new Backup(config), restarter, progress);
42+
restorer.restore(window);
43+
restorer.restore(progress);
4044
window.setVisible(true);
4145
});
4246
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package de.idrinth.waraddonclient.cli;
2+
3+
import de.idrinth.waraddonclient.service.ProgressReporter;
4+
5+
public class Progress implements ProgressReporter {
6+
7+
private int current=0;
8+
9+
private int max=0;
10+
11+
private Runnable callback;
12+
13+
private boolean stopped;
14+
15+
private void finish()
16+
{
17+
max = 0;
18+
current = 0;
19+
stopped = false;
20+
callback.run();
21+
}
22+
23+
@Override
24+
public synchronized void incrementCurrent() {
25+
current++;
26+
if (current == max && stopped) {
27+
finish();
28+
}
29+
}
30+
31+
@Override
32+
public synchronized void incrementMax(int amount) {
33+
max += amount;
34+
}
35+
36+
@Override
37+
public synchronized void start(String title, Runnable callback) {
38+
max=0;
39+
current=0;
40+
this.callback = callback;
41+
stopped=false;
42+
}
43+
44+
@Override
45+
public synchronized void stop() {
46+
stopped = true;
47+
if (current == max) {
48+
finish();
49+
}
50+
}
51+
52+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package de.idrinth.waraddonclient.gui;
2+
3+
import de.idrinth.waraddonclient.service.Config;
4+
import javax.swing.JFrame;
5+
6+
abstract class BaseFrame extends JFrame {
7+
private Config config;
8+
9+
protected BaseFrame(Config config) {
10+
this.config = config;
11+
}
12+
13+
@Override
14+
public void setTitle(String title) {
15+
super.setTitle(title + " - Idrinth's WAR Addon Client " + config.getVersion());
16+
}
17+
}

src/main/java/de/idrinth/waraddonclient/gui/FrameRestorer.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,25 @@ public FrameRestorer(Config config) {
1818

1919
public void restore(Window frame) {
2020
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
21-
frame.setLocation(getProcessedLocation(screen));
22-
frame.setSize(getProcessedSize(screen));
21+
frame.setLocation(getProcessedLocation(screen, config.getWindowPosition()));
22+
frame.setSize(getProcessedSize(screen, config.getWindowDimension()));
2323
frame.addComponentListener(new Adapter(new DelayedRunner(400, () -> {
2424
config.setWindowDimension(frame.getSize());
2525
config.setWindowPosition(frame.getLocation());
2626
})));
2727
}
2828

29-
private Dimension getProcessedSize(Dimension screen) {
30-
Dimension dimension = config.getWindowDimension();
29+
public void restore(Progress frame) {
30+
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
31+
frame.setLocation(getProcessedLocation(screen, config.getProgressPosition()));
32+
frame.setSize(getProcessedSize(screen, config.getProgressDimension()));
33+
frame.addComponentListener(new Adapter(new DelayedRunner(400, () -> {
34+
config.setProgressDimension(frame.getSize());
35+
config.setProgressPosition(frame.getLocation());
36+
})));
37+
}
38+
39+
private Dimension getProcessedSize(Dimension screen, Dimension dimension) {
3140
int width = dimension.width;
3241
int height = dimension.height;
3342
if (width <= 0 || width > screen.width) {
@@ -39,8 +48,7 @@ private Dimension getProcessedSize(Dimension screen) {
3948
return new java.awt.Dimension(width, height);
4049
}
4150

42-
private Point getProcessedLocation(Dimension screen) {
43-
Point point = config.getWindowPosition();
51+
private Point getProcessedLocation(Dimension screen, Point point) {
4452
int x = point.x;
4553
int y = point.y;
4654
if (x < 0 || x > screen.width) {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
4+
<Properties>
5+
<Property name="defaultCloseOperation" type="int" value="3"/>
6+
</Properties>
7+
<SyntheticProperties>
8+
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
9+
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
10+
</SyntheticProperties>
11+
<AuxValues>
12+
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
13+
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
14+
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
15+
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
16+
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
17+
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
18+
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
19+
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
20+
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
21+
</AuxValues>
22+
23+
<Layout>
24+
<DimensionLayout dim="0">
25+
<Group type="103" groupAlignment="0" attributes="0">
26+
<Component id="header" pref="300" max="32767" attributes="0"/>
27+
<Group type="102" alignment="1" attributes="0">
28+
<EmptySpace max="32767" attributes="0"/>
29+
<Component id="closeButton" min="-2" max="-2" attributes="0"/>
30+
<EmptySpace min="-2" pref="113" max="-2" attributes="0"/>
31+
</Group>
32+
<Group type="102" alignment="0" attributes="0">
33+
<EmptySpace max="-2" attributes="0"/>
34+
<Component id="progressBar" max="32767" attributes="0"/>
35+
<EmptySpace max="-2" attributes="0"/>
36+
</Group>
37+
</Group>
38+
</DimensionLayout>
39+
<DimensionLayout dim="1">
40+
<Group type="103" groupAlignment="0" attributes="0">
41+
<Group type="102" alignment="0" attributes="0">
42+
<Component id="header" min="-2" pref="16" max="-2" attributes="0"/>
43+
<EmptySpace max="-2" attributes="0"/>
44+
<Component id="progressBar" min="-2" pref="15" max="-2" attributes="0"/>
45+
<EmptySpace max="32767" attributes="0"/>
46+
<Component id="closeButton" min="-2" max="-2" attributes="0"/>
47+
</Group>
48+
</Group>
49+
</DimensionLayout>
50+
</Layout>
51+
<SubComponents>
52+
<Component class="javax.swing.JLabel" name="header">
53+
<Properties>
54+
<Property name="horizontalAlignment" type="int" value="0"/>
55+
<Property name="text" type="java.lang.String" value="Title"/>
56+
</Properties>
57+
</Component>
58+
<Component class="javax.swing.JProgressBar" name="progressBar">
59+
<Properties>
60+
<Property name="value" type="int" value="50"/>
61+
<Property name="stringPainted" type="boolean" value="true"/>
62+
</Properties>
63+
</Component>
64+
<Component class="javax.swing.JButton" name="closeButton">
65+
<Properties>
66+
<Property name="text" type="java.lang.String" value="Close"/>
67+
</Properties>
68+
<Events>
69+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="closeButtonActionPerformed"/>
70+
</Events>
71+
</Component>
72+
</SubComponents>
73+
</Form>

0 commit comments

Comments
 (0)