Skip to content

Commit

Permalink
New progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
CoocooFroggy committed Mar 4, 2021
1 parent d9ed484 commit 5551bbe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
23 changes: 20 additions & 3 deletions src/main/java/FutureRestoreWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FutureRestoreWorker {
public static class ProcessWorker extends SwingWorker<Void, String> {
private JTextArea ta;
private String command;
private JTextArea ta;
private JProgressBar pb;

public ProcessWorker(String command, JTextArea ta) {
public ProcessWorker(String command, JTextArea ta, JProgressBar pb) {
this.command = command;
this.ta = ta;
this.pb = pb;
}

@Override
Expand All @@ -21,9 +25,22 @@ protected Void doInBackground() throws Exception {
p.getInputStream()));
String line;
while ((line = is.readLine()) != null) {
ta.append(line + "\n");
if (line.contains("[A")) {
System.out.println("Weird line");
Pattern pattern = Pattern.compile("\u001B\\[A\u001B\\[J([0-9]{3})");
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
pb.setValue(Integer.parseInt(matcher.group(1)));
}

// ta.append(line + "\n");
}
else
ta.append(line + "\n");
}
is.close();
p.destroy();
System.out.println("Killing futurerestore");
return null;
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/MainMenu.form
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@
<verticalTextPosition value="0"/>
</properties>
</component>
<component id="e0dd6" class="javax.swing.JProgressBar" binding="logProgressBar">
<constraints>
<grid row="14" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<buttonGroups>
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.plaf.FontUIResource;
import javax.swing.text.DefaultCaret;
import javax.swing.text.StyleContext;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
Expand Down Expand Up @@ -43,6 +42,7 @@ public class MainMenu {
private JComboBox sepComboBox;
private JTextField sepTextField;
private JScrollPane logScrollPane;
private JProgressBar logProgressBar;

private String futureRestoreFilePath;
private String blobName;
Expand Down Expand Up @@ -542,7 +542,7 @@ boolean chooseSep() {
void runCommand(String command) {

System.out.println("Going to run now");
new FutureRestoreWorker.ProcessWorker(futureRestoreFilePath + " " + command, logTextArea).execute();
new FutureRestoreWorker.ProcessWorker(futureRestoreFilePath + " " + command, logTextArea, logProgressBar).execute();

// Runtime runtime = Runtime.getRuntime();
// try {
Expand Down Expand Up @@ -854,6 +854,13 @@ String getLatestFutureRestore() throws IOException {
gbc.gridy = 12;
gbc.fill = GridBagConstraints.BOTH;
mainMenuView.add(exitRecoveryButton, gbc);
logProgressBar = new JProgressBar();
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 14;
gbc.gridwidth = 6;
gbc.fill = GridBagConstraints.HORIZONTAL;
mainMenuView.add(logProgressBar, gbc);
}

/**
Expand Down

0 comments on commit 5551bbe

Please sign in to comment.