Skip to content

Commit

Permalink
Info dialogs refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
maccasoft committed Mar 4, 2024
1 parent bc95511 commit 55e4b2d
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 194 deletions.
123 changes: 87 additions & 36 deletions modules/spin-tools/src/com/maccasoft/propeller/P1MemoryDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
package com.maccasoft.propeller;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.text.NumberFormat;
import java.util.List;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
Expand Down Expand Up @@ -45,11 +48,13 @@
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;

import com.maccasoft.propeller.internal.ColorRegistry;
import com.maccasoft.propeller.spin1.Spin1Object;

public class P1MemoryDialog extends Dialog {
Expand Down Expand Up @@ -110,46 +115,46 @@ public void setTheme(String id) {
listBackground = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);

if (Display.isSystemDarkTheme()) {
codeBackground = new Color(121, 0, 0);
variablesBackground = new Color(121, 121, 0);
stackFreeBackground = new Color(0, 121, 121);
codeBackground = ColorRegistry.getColor(121, 0, 0);
variablesBackground = ColorRegistry.getColor(121, 121, 0);
stackFreeBackground = ColorRegistry.getColor(0, 121, 121);
}
else {
codeBackground = new Color(255, 191, 191);
variablesBackground = new Color(255, 248, 192);
stackFreeBackground = new Color(191, 223, 255);
codeBackground = ColorRegistry.getColor(255, 191, 191);
variablesBackground = ColorRegistry.getColor(255, 248, 192);
stackFreeBackground = ColorRegistry.getColor(191, 223, 255);
}
}
else if ("dark".equals(id)) {
widgetForeground = new Color(0xF0, 0xF0, 0xF0);
widgetBackground = new Color(0x50, 0x55, 0x57);
listForeground = new Color(0xA7, 0xA7, 0xA7);
listBackground = new Color(0x2B, 0x2B, 0x2B);
tabfolderBackground = new Color(0x43, 0x44, 0x47);
labelForeground = new Color(0xD7, 0xD7, 0xD7);
buttonBackground = new Color(0x50, 0x55, 0x57);

codeBackground = new Color(121, 0, 0);
variablesBackground = new Color(121, 121, 0);
stackFreeBackground = new Color(0, 121, 121);
widgetForeground = ColorRegistry.getColor(0xF0, 0xF0, 0xF0);
widgetBackground = ColorRegistry.getColor(0x50, 0x55, 0x57);
listForeground = ColorRegistry.getColor(0xA7, 0xA7, 0xA7);
listBackground = ColorRegistry.getColor(0x2B, 0x2B, 0x2B);
tabfolderBackground = ColorRegistry.getColor(0x43, 0x44, 0x47);
labelForeground = ColorRegistry.getColor(0xD7, 0xD7, 0xD7);
buttonBackground = ColorRegistry.getColor(0x50, 0x55, 0x57);

codeBackground = ColorRegistry.getColor(121, 0, 0);
variablesBackground = ColorRegistry.getColor(121, 121, 0);
stackFreeBackground = ColorRegistry.getColor(0, 121, 121);
}
else if ("light".equals(id)) {
widgetForeground = new Color(0x00, 0x00, 0x00);
widgetForeground = ColorRegistry.getColor(0x00, 0x00, 0x00);
if ("win32".equals(Platform.PLATFORM)) {
widgetBackground = new Color(0xF0, 0xF0, 0xF0);
widgetBackground = ColorRegistry.getColor(0xF0, 0xF0, 0xF0);
}
else {
widgetBackground = new Color(0xFA, 0xFA, 0xFA);
widgetBackground = ColorRegistry.getColor(0xFA, 0xFA, 0xFA);
}
listForeground = new Color(0x00, 0x00, 0x00);
listBackground = new Color(0xFE, 0xFE, 0xFE);
listForeground = ColorRegistry.getColor(0x00, 0x00, 0x00);
listBackground = ColorRegistry.getColor(0xFE, 0xFE, 0xFE);
tabfolderBackground = widgetBackground;
labelForeground = new Color(0x00, 0x00, 0x00);
buttonBackground = new Color(0xFA, 0xFA, 0xFA);
labelForeground = ColorRegistry.getColor(0x00, 0x00, 0x00);
buttonBackground = ColorRegistry.getColor(0xFA, 0xFA, 0xFA);

codeBackground = new Color(255, 191, 191);
variablesBackground = new Color(255, 248, 192);
stackFreeBackground = new Color(191, 223, 255);
codeBackground = ColorRegistry.getColor(255, 191, 191);
variablesBackground = ColorRegistry.getColor(255, 248, 192);
stackFreeBackground = ColorRegistry.getColor(191, 223, 255);
}
}

Expand Down Expand Up @@ -193,7 +198,7 @@ protected Control createDialogArea(Composite parent) {

createInfoGroup(content);

tabFolder = new CTabFolder(content, SWT.BORDER);
tabFolder = new CTabFolder(content, SWT.BORDER | SWT.FLAT);
tabFolder.setMaximizeVisible(false);
tabFolder.setMinimizeVisible(false);
tabFolder.setTabHeight(24);
Expand Down Expand Up @@ -284,7 +289,7 @@ public void createInfoGroup(Composite parent) {
label.setForeground(labelForeground);
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
label = new Label(group, SWT.NONE);
label.setText("$7FFF");
label.setText(String.format("$%X", data.length - 1));
label.setForeground(labelForeground);

label = new Label(group, SWT.BORDER);
Expand All @@ -302,8 +307,8 @@ public void handleEvent(Event e) {
e.gc.setBackground(stackFreeBackground);
e.gc.fillRectangle(0, 0, bounds.width, bounds.height);

int codePixels = (int) (bounds.width * (vbase - pbase) / 32768.0);
int variablesPixels = (int) (bounds.width * (dbase - vbase) / 32768.0);
int codePixels = (int) (bounds.width * (vbase - pbase) / (double) data.length);
int variablesPixels = (int) (bounds.width * (dbase - vbase) / (double) data.length);

int x = 0;
e.gc.setBackground(codeBackground);
Expand Down Expand Up @@ -761,10 +766,7 @@ public void setObject(Spin1Object object, ObjectTree tree, boolean topObject) {
this.object = object;

try {
byte[] binaryData = object.getBinary();

data = new byte[32 * 1024];
System.arraycopy(binaryData, 0, data, 0, Math.min(data.length, binaryData.length));
data = object.getEEprom();

clkfreq = object.getClkFreq();
clkmode = object.getClkMode();
Expand Down Expand Up @@ -803,11 +805,60 @@ protected void buttonPressed(int buttonId) {
}

protected void doSaveBinary() {

File fileToSave = getFileToWrite();
try {
FileOutputStream os = new FileOutputStream(fileToSave);
os.write(object.getBinary());
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}

protected void doSaveListing() {
File fileToSave = getFileToWrite();
try {
PrintStream os = new PrintStream(new FileOutputStream(fileToSave));
object.generateListing(os);
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}

protected File getFileToWrite() {
FileDialog dlg = new FileDialog(getShell(), SWT.SAVE);
dlg.setOverwrite(true);
dlg.setText("Save Binary File");
String[] filterNames = new String[] {
"Binary Files"
};
String[] filterExtensions = new String[] {
"*.bin;*.binary"
};
dlg.setFilterNames(filterNames);
dlg.setFilterExtensions(filterExtensions);

String name = tree.getName();
int i = name.lastIndexOf('.');
dlg.setFileName(name.substring(0, i) + ".binary");

List<String> lru = Preferences.getInstance().getLru();

File filterPath = tree.getFile();
if (filterPath == null && lru.size() != 0) {
filterPath = new File(lru.get(0));
}
if (filterPath != null) {
dlg.setFilterPath(filterPath.getParent());
}

String fileName = dlg.open();
if (fileName != null) {
return new File(fileName);
}

return null;
}

}
103 changes: 77 additions & 26 deletions modules/spin-tools/src/com/maccasoft/propeller/P2MemoryDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
package com.maccasoft.propeller;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.text.NumberFormat;
import java.util.List;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
Expand Down Expand Up @@ -45,6 +48,7 @@
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar;
Expand Down Expand Up @@ -113,9 +117,9 @@ public void setTheme(String id) {
listBackground = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);

if (Display.isSystemDarkTheme()) {
codeBackground = new Color(121, 0, 0);
variablesBackground = new Color(121, 121, 0);
stackFreeBackground = new Color(0, 121, 121);
codeBackground = ColorRegistry.getColor(121, 0, 0);
variablesBackground = ColorRegistry.getColor(121, 121, 0);
stackFreeBackground = ColorRegistry.getColor(0, 121, 121);
}
else {
codeBackground = ColorRegistry.getColor(255, 191, 191);
Expand All @@ -124,31 +128,31 @@ public void setTheme(String id) {
}
}
else if ("dark".equals(id)) {
widgetForeground = new Color(0xF0, 0xF0, 0xF0);
widgetBackground = new Color(0x50, 0x55, 0x57);
listForeground = new Color(0xA7, 0xA7, 0xA7);
listBackground = new Color(0x2B, 0x2B, 0x2B);
tabfolderBackground = new Color(0x43, 0x44, 0x47);
labelForeground = new Color(0xD7, 0xD7, 0xD7);
buttonBackground = new Color(0x50, 0x55, 0x57);

codeBackground = new Color(121, 0, 0);
variablesBackground = new Color(121, 121, 0);
stackFreeBackground = new Color(0, 121, 121);
widgetForeground = ColorRegistry.getColor(0xF0, 0xF0, 0xF0);
widgetBackground = ColorRegistry.getColor(0x50, 0x55, 0x57);
listForeground = ColorRegistry.getColor(0xA7, 0xA7, 0xA7);
listBackground = ColorRegistry.getColor(0x2B, 0x2B, 0x2B);
tabfolderBackground = ColorRegistry.getColor(0x43, 0x44, 0x47);
labelForeground = ColorRegistry.getColor(0xD7, 0xD7, 0xD7);
buttonBackground = ColorRegistry.getColor(0x50, 0x55, 0x57);

codeBackground = ColorRegistry.getColor(121, 0, 0);
variablesBackground = ColorRegistry.getColor(121, 121, 0);
stackFreeBackground = ColorRegistry.getColor(0, 121, 121);
}
else if ("light".equals(id)) {
widgetForeground = new Color(0x00, 0x00, 0x00);
widgetForeground = ColorRegistry.getColor(0x00, 0x00, 0x00);
if ("win32".equals(Platform.PLATFORM)) {
widgetBackground = new Color(0xF0, 0xF0, 0xF0);
widgetBackground = ColorRegistry.getColor(0xF0, 0xF0, 0xF0);
}
else {
widgetBackground = new Color(0xFA, 0xFA, 0xFA);
widgetBackground = ColorRegistry.getColor(0xFA, 0xFA, 0xFA);
}
listForeground = new Color(0x00, 0x00, 0x00);
listBackground = new Color(0xFE, 0xFE, 0xFE);
listForeground = ColorRegistry.getColor(0x00, 0x00, 0x00);
listBackground = ColorRegistry.getColor(0xFE, 0xFE, 0xFE);
tabfolderBackground = widgetBackground;
labelForeground = new Color(0x00, 0x00, 0x00);
buttonBackground = new Color(0xFA, 0xFA, 0xFA);
labelForeground = ColorRegistry.getColor(0x00, 0x00, 0x00);
buttonBackground = ColorRegistry.getColor(0xFA, 0xFA, 0xFA);

codeBackground = ColorRegistry.getColor(255, 191, 191);
variablesBackground = ColorRegistry.getColor(255, 248, 192);
Expand Down Expand Up @@ -771,10 +775,7 @@ public void setObject(Spin2Object object, ObjectTree tree, boolean topObject) {
this.object = object;

try {
byte[] binaryData = object.getBinary();

data = new byte[512 * 1024];
System.arraycopy(binaryData, 0, data, 0, Math.min(data.length, binaryData.length));
data = object.getFlash();

clkfreq = object.getClkFreq();
clkmode = object.getClkMode();
Expand Down Expand Up @@ -822,11 +823,61 @@ protected void buttonPressed(int buttonId) {
}

protected void doSaveBinary() {

File fileToSave = getFileToWrite();
try {
FileOutputStream os = new FileOutputStream(fileToSave);
object.setClockSetter(Preferences.getInstance().getSpin2ClockSetter());
os.write(object.getBinary());
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}

protected void doSaveListing() {
File fileToSave = getFileToWrite();
try {
PrintStream os = new PrintStream(new FileOutputStream(fileToSave));
object.generateListing(os);
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}

protected File getFileToWrite() {
FileDialog dlg = new FileDialog(getShell(), SWT.SAVE);
dlg.setOverwrite(true);
dlg.setText("Save Binary File");
String[] filterNames = new String[] {
"Binary Files"
};
String[] filterExtensions = new String[] {
"*.bin;*.binary"
};
dlg.setFilterNames(filterNames);
dlg.setFilterExtensions(filterExtensions);

String name = tree.getName();
int i = name.lastIndexOf('.');
dlg.setFileName(name.substring(0, i) + ".binary");

List<String> lru = Preferences.getInstance().getLru();

File filterPath = tree.getFile();
if (filterPath == null && lru.size() != 0) {
filterPath = new File(lru.get(0));
}
if (filterPath != null) {
dlg.setFilterPath(filterPath.getParent());
}

String fileName = dlg.open();
if (fileName != null) {
return new File(fileName);
}

return null;
}

}
Loading

0 comments on commit 55e4b2d

Please sign in to comment.