Skip to content

Commit

Permalink
port/offset and UI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tobozo committed Mar 18, 2024
1 parent bc727ec commit 922e2ca
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 153 deletions.
31 changes: 15 additions & 16 deletions src/main/java/com/arduino/AppSettingsArduino.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,20 @@ public void clean() {
}

@Override
public void build(JProgressBar progressBar, Runnable onSuccess) {

public void build(JProgressBar progressBar, final AppSettings.EventCallback callbacks) {
CompileProgressListener progressListener = new CompileProgressListener(progressBar);
progressBar.setIndeterminate(true);
progressBar.setVisible(true);

EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
boolean success = build( progressListener );
progressBar.setIndeterminate(false);
progressBar.setVisible(false);
progressBar.getParent().repaint();
if( success ) onSuccess.run();

final Runnable buildRunner = () -> {
callbacks.onBefore();
if( build( progressListener ) ) {
callbacks.onSuccess();
} else {
callbacks.onFail();
}
});
callbacks.onAfter();
};

new Thread(buildRunner).start();
}

@Override
Expand All @@ -137,7 +135,7 @@ public void load() {
set("build.path", getBuildFolderPath() );
set("bootloader.path", getBootloaderImagePath() );
set("upload.speed", BaseNoGui.getBoardPreferences().get("upload.speed") );
set("serial.port", BaseNoGui.getBoardPreferences().get("serial.port") );
set("serial.port", PreferencesData.get("serial.port") );
set("build.bootloader_addr", BaseNoGui.getBoardPreferences().get("build.bootloader_addr") );
set("build.mcu", BaseNoGui.getBoardPreferences().get("build.mcu") );
set("flashMode", BaseNoGui.getBoardPreferences().get("build.flash_mode") );
Expand Down Expand Up @@ -279,11 +277,12 @@ private class CompileProgressListener implements CompilerProgressListener {
public CompileProgressListener(JProgressBar progressBar) {
this.progressBar = progressBar;
progressBar.setValue(0);
progressBar.setIndeterminate(true);
}
public void progress(int value) {
progressBar.setIndeterminate(false);
progressBar.setValue( value );
progressBar.repaint();
//System.out.printf("Progress: %d\n", value );
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/arduino/ESP32PartitionTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ public void keyPressed(KeyEvent e) {
frame.toFront();
}

fileManager.loadDefaultCSV();
// prevent repaint problem when reloading CSV
EventQueue.invokeLater( () -> fileManager.loadDefaultCSV() );

frame.setVisible(true);
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/platformio/ESP32PartitionToolStandalone.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ of this software and associated documentation files (the "Software"), to deal
// local implementation of rounded borders to overwrite global styles
@SuppressWarnings("serial")
final class CustomBorder extends AbstractBorder {
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
super.paintBorder(c, g, x, y, width, height);
Graphics2D g2d = (Graphics2D)g;
g2d.setPaint( new Color(0xcc, 0xcc, 0xcc) );
Shape shape = new RoundRectangle2D.Float(1, 1, c.getWidth()-2, c.getHeight()-2, 5, 5);
g2d.draw(shape);
}
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
super.paintBorder(c, g, x, y, width, height);
Graphics2D g2d = (Graphics2D)g;
g2d.setPaint( new Color(0xcc, 0xcc, 0xcc) );
Shape shape = new RoundRectangle2D.Float(1, 1, c.getWidth()-2, c.getHeight()-2, 5, 5);
g2d.draw(shape);
}
}


Expand Down
47 changes: 42 additions & 5 deletions src/main/java/com/serifpersia/esp32partitiontool/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,58 @@

public class AppSettings {

static final public class EventCallback {

public Runnable onBefore;
public Runnable onAfter;
public Runnable onSuccess;
public Runnable onFail;

public EventCallback() {
}

public EventCallback(Runnable onBefore, Runnable onAfter, Runnable onSuccess, Runnable onFail) {
this.onBefore = onBefore;
this.onAfter = onAfter;
this.onSuccess = onSuccess;
this.onFail = onFail;
}

public void onBefore () { if( this.onBefore != null ) this.onBefore.run(); }
public void onAfter () { if( this.onAfter != null ) this.onAfter.run(); }
public void onSuccess() { if( this.onSuccess != null ) this.onSuccess.run(); }
public void onFail () { if( this.onFail != null ) this.onFail.run(); }

public void onBefore( Runnable onBefore ) {
this.onBefore = onBefore;
}
public void onAfter( Runnable onAfter ) {
this.onAfter = onAfter;
}
public void onSuccess( Runnable onSuccess ) {
this.onSuccess = onSuccess;
}
public void onFail( Runnable onFail ) {
this.onFail = onFail;
}

}

public boolean debug_settings = true;
public boolean hasFSPanel = false;
private boolean changed = false;
public Map<String, String> prefs = new HashMap<>();

public String get( String key ) {
String value = prefs.get( key );
if( debug_settings && value == null ) {
String value = prefs.get( key );
if( debug_settings && value == null ) {
System.out.printf("[debug] settings.%s is null\n", key );
}
}
return value;
}

public String set( String key, String value ) {
String oldvalue = prefs.put( key, value );
String oldvalue = prefs.put( key, value );
if( debug_settings && oldvalue != null && value != null ) {
if( !oldvalue.equals(value) ) {
System.out.printf("[debug] Value change for settings.%s:\n [old] %s\n [new] %s\n", key, oldvalue, value );
Expand All @@ -46,7 +83,7 @@ public void load() {
}

// this method is overriden from AppSettingsArduino only
public void build(JProgressBar progressBar, Runnable runAfter) {
public void build(JProgressBar progressBar, AppSettings.EventCallback callbacks) {

}

Expand Down
44 changes: 25 additions & 19 deletions src/main/java/com/serifpersia/esp32partitiontool/FSPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void emitMessage(String msg, boolean is_error ) {
msgArea.setEditable(false); // Make the text area read-only
msgArea.setLineWrap(true); // Enable line wrapping
msgArea.setWrapStyleWord(true); // Wrap at word boundaries
msgArea.setText( msg +"\n" );
msgArea.setText( msg );
msgArea.setAlignmentY(JPanel.TOP_ALIGNMENT);
consoleLogPanel.add( msgArea, consoleGBC );
consoleLogPanel.revalidate();
Expand Down Expand Up @@ -269,36 +269,42 @@ public void actionPerformed(ActionEvent e) {
}
});

final Runnable onBefore = () -> {
getProgressBar().setVisible(true);
getProgressBar().setIndeterminate(true);
cleanLogsButton.setVisible(false);
};

final Runnable onAfter = () -> {
getProgressBar().setIndeterminate(false);
getProgressBar().setVisible(false);
cleanLogsButton.setVisible(true);
};

final AppSettings.EventCallback DefaultEventCallbacks = new AppSettings.EventCallback(onBefore, onAfter, null, null);

final Runnable onUploadSPIFFS = () -> fileManager.uploadSPIFFS( DefaultEventCallbacks );
final Runnable onCreateMergedBin = () -> fileManager.createMergedBin( DefaultEventCallbacks );
final Runnable onUploadMergedBin = () -> fileManager.uploadMergedBin( DefaultEventCallbacks );

getUploadFSBtn().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
fileManager.uploadSPIFFS();
}
});
ui.settings.clean();
new Thread(onUploadSPIFFS).start();
}
});

getMergeBinBtn().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
fileManager.createMergedBin(null);
}
});
ui.settings.clean();
new Thread(onCreateMergedBin).start();
}
});

getUploadMergedBinBtn().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
fileManager.uploadMergedBin();
}
});
ui.settings.clean();
new Thread(onUploadMergedBin).start();
}
});

Expand Down
Loading

0 comments on commit 922e2ca

Please sign in to comment.