Skip to content

Commit

Permalink
Merge pull request #177 from Idrinth/adding-progress-bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Idrinth authored Jul 4, 2021
2 parents a1c0879 + 8a98ec4 commit 319e97d
Show file tree
Hide file tree
Showing 20 changed files with 618 additions and 102 deletions.
2 changes: 1 addition & 1 deletion arch-pkgbuild
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.idrinth</groupId>
<artifactId>WARAddonClient</artifactId>
<version>1.13.0</version>
<version>1.14.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -175,7 +175,7 @@
<plugin>
<artifactId>jdeb</artifactId>
<groupId>org.vafer</groupId>
<version>1.9</version>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/idrinth/waraddonclient/CliMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.idrinth.waraddonclient.cli.AliasOption;
import de.idrinth.waraddonclient.cli.AliasParser;
import de.idrinth.waraddonclient.cli.Progress;
import de.idrinth.waraddonclient.service.*;
import de.idrinth.waraddonclient.model.CmdAddonList;
import de.idrinth.waraddonclient.service.logger.CliLogger;
Expand Down Expand Up @@ -55,7 +56,7 @@ protected void main(MultiLogger logger, Config config, Request client, FileSyste
logger.info("Set location to "+config.getWARPath());
}
file.checkPosition();
CmdAddonList addonList = new CmdAddonList(client, logger, new XmlParser(), config);
CmdAddonList addonList = new CmdAddonList(client, logger, new XmlParser(), config, new Progress());
addonList.run();
if (cli.hasOption("update-all")) {
addonList.update();
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/de/idrinth/waraddonclient/GuiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.idrinth.waraddonclient.service.Config;
import de.idrinth.waraddonclient.gui.FrameRestorer;
import de.idrinth.waraddonclient.gui.Progress;
import de.idrinth.waraddonclient.gui.ThemeManager;
import de.idrinth.waraddonclient.gui.Window;
import de.idrinth.waraddonclient.model.GuiAddonList;
Expand Down Expand Up @@ -35,8 +36,11 @@ protected void main(MultiLogger logger, Config config, Request client, FileSyste
schedule.register(30, watcher);
java.awt.EventQueue.invokeLater(() -> {
Version version = new Version(client, logger);
Window window = new Window(addonList, version, themes, logger, schedule, config, new Backup(config), restarter);
new FrameRestorer(config).restore(window);
Progress progress = new Progress(config);
FrameRestorer restorer = new FrameRestorer(config);
Window window = new Window(addonList, version, themes, logger, schedule, config, new Backup(config), restarter, progress);
restorer.restore(window);
restorer.restore(progress);
window.setVisible(true);
});
}
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/de/idrinth/waraddonclient/cli/Progress.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package de.idrinth.waraddonclient.cli;

import de.idrinth.waraddonclient.service.ProgressReporter;

public class Progress implements ProgressReporter {

private int current=0;

private int max=0;

private Runnable callback;

private boolean stopped;

private void finish()
{
max = 0;
current = 0;
stopped = false;
callback.run();
}

@Override
public synchronized void incrementCurrent() {
current++;
if (current == max && stopped) {
finish();
}
}

@Override
public synchronized void incrementMax(int amount) {
max += amount;
}

@Override
public synchronized void start(String title, Runnable callback) {
max=0;
current=0;
this.callback = callback;
stopped=false;
}

@Override
public synchronized void stop() {
stopped = true;
if (current == max) {
finish();
}
}

}
17 changes: 17 additions & 0 deletions src/main/java/de/idrinth/waraddonclient/gui/BaseFrame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.idrinth.waraddonclient.gui;

import de.idrinth.waraddonclient.service.Config;
import javax.swing.JFrame;

abstract class BaseFrame extends JFrame {
private Config config;

protected BaseFrame(Config config) {
this.config = config;
}

@Override
public void setTitle(String title) {
super.setTitle(title + " - Idrinth's WAR Addon Client " + config.getVersion());
}
}
20 changes: 14 additions & 6 deletions src/main/java/de/idrinth/waraddonclient/gui/FrameRestorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,25 @@ public FrameRestorer(Config config) {

public void restore(Window frame) {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(getProcessedLocation(screen));
frame.setSize(getProcessedSize(screen));
frame.setLocation(getProcessedLocation(screen, config.getWindowPosition()));
frame.setSize(getProcessedSize(screen, config.getWindowDimension()));
frame.addComponentListener(new Adapter(new DelayedRunner(400, () -> {
config.setWindowDimension(frame.getSize());
config.setWindowPosition(frame.getLocation());
})));
}

private Dimension getProcessedSize(Dimension screen) {
Dimension dimension = config.getWindowDimension();
public void restore(Progress frame) {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(getProcessedLocation(screen, config.getProgressPosition()));
frame.setSize(getProcessedSize(screen, config.getProgressDimension()));
frame.addComponentListener(new Adapter(new DelayedRunner(400, () -> {
config.setProgressDimension(frame.getSize());
config.setProgressPosition(frame.getLocation());
})));
}

private Dimension getProcessedSize(Dimension screen, Dimension dimension) {
int width = dimension.width;
int height = dimension.height;
if (width <= 0 || width > screen.width) {
Expand All @@ -39,8 +48,7 @@ private Dimension getProcessedSize(Dimension screen) {
return new java.awt.Dimension(width, height);
}

private Point getProcessedLocation(Dimension screen) {
Point point = config.getWindowPosition();
private Point getProcessedLocation(Dimension screen, Point point) {
int x = point.x;
int y = point.y;
if (x < 0 || x > screen.width) {
Expand Down
73 changes: 73 additions & 0 deletions src/main/java/de/idrinth/waraddonclient/gui/Progress.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="header" pref="300" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="closeButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="113" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="progressBar" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="header" min="-2" pref="16" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="progressBar" min="-2" pref="15" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="closeButton" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="header">
<Properties>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="Title"/>
</Properties>
</Component>
<Component class="javax.swing.JProgressBar" name="progressBar">
<Properties>
<Property name="value" type="int" value="50"/>
<Property name="stringPainted" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="closeButton">
<Properties>
<Property name="text" type="java.lang.String" value="Close"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="closeButtonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
Loading

0 comments on commit 319e97d

Please sign in to comment.