mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2024-12-21 01:30:34 +00:00
Adjusting font colors for BASIC listings based on dark mode (or not). #115.
This commit is contained in:
parent
d174f2341d
commit
9a300d1241
@ -34,12 +34,7 @@ import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.ToolBar;
|
||||
import org.eclipse.swt.widgets.ToolItem;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import com.webcodepro.applecommander.storage.FileEntry;
|
||||
import com.webcodepro.applecommander.storage.FileFilter;
|
||||
@ -102,10 +97,7 @@ public class FileViewerWindow {
|
||||
private Optional<ToolItem> shapeTableToolItem = Optional.empty();
|
||||
|
||||
private Font courier;
|
||||
private Color black;
|
||||
private Color blue;
|
||||
private Color green;
|
||||
|
||||
|
||||
private ContentTypeAdapter contentTypeAdapter;
|
||||
private Map<Class<?>,FilterAdapter> nativeFilterAdapterMap;
|
||||
private FilterAdapter nativeFilterAdapter;
|
||||
@ -159,12 +151,9 @@ public class FileViewerWindow {
|
||||
gridData = new GridData(GridData.FILL_BOTH);
|
||||
content.setLayoutData(gridData);
|
||||
content.addListener(SWT.KeyUp, createToolbarCommandHandler());
|
||||
|
||||
|
||||
courier = new Font(shell.getDisplay(), "Courier", 10, SWT.NORMAL); //$NON-NLS-1$
|
||||
black = new Color(shell.getDisplay(), 0, 0, 0);
|
||||
blue = new Color(shell.getDisplay(), 0, 0, 192);
|
||||
green = new Color(shell.getDisplay(), 0, 192, 0);
|
||||
|
||||
|
||||
nativeFilterAdapter.display();
|
||||
|
||||
shell.open();
|
||||
@ -249,9 +238,6 @@ public class FileViewerWindow {
|
||||
*/
|
||||
protected void dispose(DisposeEvent event) {
|
||||
courier.dispose();
|
||||
black.dispose();
|
||||
blue.dispose();
|
||||
green.dispose();
|
||||
if (nativeFilterAdapter != null) nativeFilterAdapter.dispose();
|
||||
hexFilterAdapter.dispose();
|
||||
rawDumpFilterAdapter.dispose();
|
||||
@ -435,16 +421,7 @@ public class FileViewerWindow {
|
||||
public Font getCourierFont() {
|
||||
return courier;
|
||||
}
|
||||
public Color getBlackColor() {
|
||||
return black;
|
||||
}
|
||||
public Color getGreenColor() {
|
||||
return green;
|
||||
}
|
||||
public Color getBlueColor() {
|
||||
return blue;
|
||||
}
|
||||
public void setFilterToolItemSelection(boolean nativeSelected, boolean hexSelected, boolean dumpSelected,
|
||||
public void setFilterToolItemSelection(boolean nativeSelected, boolean hexSelected, boolean dumpSelected,
|
||||
boolean disassemblySelected, boolean shapeTableSelected) {
|
||||
if (nativeToolItem != null) nativeToolItem.setSelection(nativeSelected);
|
||||
hexDumpToolItem.setSelection(hexSelected);
|
||||
|
@ -22,6 +22,7 @@ package com.webcodepro.applecommander.ui.swt.filteradapter;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
||||
@ -29,6 +30,7 @@ import com.webcodepro.applecommander.ui.swt.FileViewerWindow;
|
||||
import com.webcodepro.applecommander.ui.swt.util.contentadapter.StyledTextAdapter;
|
||||
import com.webcodepro.applecommander.util.ApplesoftToken;
|
||||
import com.webcodepro.applecommander.util.ApplesoftTokenizer;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
/**
|
||||
* Provides a view of a syntax-colored Applesoft program listing.
|
||||
@ -37,6 +39,9 @@ import com.webcodepro.applecommander.util.ApplesoftTokenizer;
|
||||
*/
|
||||
public class ApplesoftFilterAdapter extends FilterAdapter {
|
||||
private StyledText styledText;
|
||||
private Color separatorColor;
|
||||
private Color stringColor;
|
||||
private Color tokenColor;
|
||||
|
||||
public ApplesoftFilterAdapter(FileViewerWindow window, String text, String toolTipText, Image image) {
|
||||
super(window, text, toolTipText, image);
|
||||
@ -59,12 +64,25 @@ public class ApplesoftFilterAdapter extends FilterAdapter {
|
||||
|
||||
public void dispose() {
|
||||
styledText.dispose();
|
||||
separatorColor.dispose();
|
||||
tokenColor.dispose();
|
||||
stringColor.dispose();
|
||||
}
|
||||
|
||||
|
||||
protected void createStyledText() {
|
||||
if (Display.isSystemDarkTheme()) {
|
||||
separatorColor = new Color(getComposite().getDisplay(), 255, 128, 128);
|
||||
tokenColor = new Color(getComposite().getDisplay(), 192, 192, 255);
|
||||
stringColor = new Color(getComposite().getDisplay(), 128, 255, 128);
|
||||
} else {
|
||||
separatorColor = new Color(getComposite().getDisplay(), 192, 0, 0);
|
||||
tokenColor = new Color(getComposite().getDisplay(), 0, 0, 192);
|
||||
stringColor = new Color(getComposite().getDisplay(), 0, 192, 0);
|
||||
}
|
||||
|
||||
styledText = new StyledText(getComposite(), SWT.NONE);
|
||||
styledText.setForeground(getBlackColor());
|
||||
styledText.setForeground(getComposite().getForeground());
|
||||
styledText.setFont(getCourierFont());
|
||||
styledText.setEditable(false);
|
||||
|
||||
@ -83,7 +101,13 @@ public class ApplesoftFilterAdapter extends FilterAdapter {
|
||||
styledText.append(Integer.toString(token.getLineNumber()));
|
||||
styledText.append(" "); //$NON-NLS-1$
|
||||
} else if (token.isCommandSeparator() || token.isExpressionSeparator()) {
|
||||
int caretOffset = styledText.getCharCount();
|
||||
styledText.append(token.getStringValue());
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = caretOffset;
|
||||
styleRange.length = token.getStringValue().length();
|
||||
styleRange.foreground = separatorColor;
|
||||
styledText.setStyleRange(styleRange);
|
||||
} else if (token.isEndOfCommand()) {
|
||||
styledText.append("\n"); //$NON-NLS-1$
|
||||
} else if (token.isString()) {
|
||||
@ -92,7 +116,7 @@ public class ApplesoftFilterAdapter extends FilterAdapter {
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = caretOffset;
|
||||
styleRange.length = token.getStringValue().length();
|
||||
styleRange.foreground = getGreenColor();
|
||||
styleRange.foreground = stringColor;
|
||||
styledText.setStyleRange(styleRange);
|
||||
} else if (token.isToken()) {
|
||||
int caretOffset = styledText.getCharCount();
|
||||
@ -100,8 +124,7 @@ public class ApplesoftFilterAdapter extends FilterAdapter {
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = caretOffset;
|
||||
styleRange.length = token.getTokenString().length();
|
||||
//styleRange.fontStyle = SWT.BOLD;
|
||||
styleRange.foreground = getBlueColor();
|
||||
styleRange.foreground = tokenColor;
|
||||
styledText.setStyleRange(styleRange);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package com.webcodepro.applecommander.ui.swt.filteradapter;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
||||
@ -37,7 +38,10 @@ import com.webcodepro.applecommander.util.BusinessBASICTokenizer;
|
||||
*/
|
||||
public class BusinessBASICFilterAdapter extends FilterAdapter {
|
||||
private StyledText styledText;
|
||||
|
||||
private Color separatorColor;
|
||||
private Color stringColor;
|
||||
private Color tokenColor;
|
||||
|
||||
public BusinessBASICFilterAdapter(FileViewerWindow window, String text, String toolTipText, Image image) {
|
||||
super(window, text, toolTipText, image);
|
||||
}
|
||||
@ -59,12 +63,19 @@ public class BusinessBASICFilterAdapter extends FilterAdapter {
|
||||
|
||||
public void dispose() {
|
||||
styledText.dispose();
|
||||
separatorColor.dispose();
|
||||
tokenColor.dispose();
|
||||
stringColor.dispose();
|
||||
}
|
||||
|
||||
|
||||
protected void createStyledText() {
|
||||
separatorColor = new Color(getComposite().getDisplay(), 192, 0, 0);
|
||||
tokenColor = new Color(getComposite().getDisplay(), 0, 0, 192);
|
||||
stringColor = new Color(getComposite().getDisplay(), 0, 192, 0);
|
||||
|
||||
styledText = new StyledText(getComposite(), SWT.NONE);
|
||||
styledText.setForeground(getBlackColor());
|
||||
styledText.setForeground(getComposite().getForeground());
|
||||
styledText.setFont(getCourierFont());
|
||||
styledText.setEditable(false);
|
||||
|
||||
@ -90,7 +101,13 @@ public class BusinessBASICFilterAdapter extends FilterAdapter {
|
||||
styledText.append(" "); //$NON-NLS-1$
|
||||
}
|
||||
} else if (token.isCommandSeparator() || token.isExpressionSeparator()) {
|
||||
int caretOffset = styledText.getCharCount();
|
||||
styledText.append(token.getStringValue());
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = caretOffset;
|
||||
styleRange.length = token.getStringValue().length();
|
||||
styleRange.foreground = separatorColor;
|
||||
styledText.setStyleRange(styleRange);
|
||||
firstData = true;
|
||||
} else if (token.isEndOfCommand()) {
|
||||
styledText.append("\n"); //$NON-NLS-1$
|
||||
@ -103,7 +120,7 @@ public class BusinessBASICFilterAdapter extends FilterAdapter {
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = caretOffset;
|
||||
styleRange.length = token.getStringValue().trim().length();
|
||||
styleRange.foreground = getGreenColor();
|
||||
styleRange.foreground = stringColor;
|
||||
styledText.setStyleRange(styleRange);
|
||||
firstData = false;
|
||||
} else if (token.isToken()) {
|
||||
@ -114,8 +131,7 @@ public class BusinessBASICFilterAdapter extends FilterAdapter {
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = caretOffset;
|
||||
styleRange.length = token.getTokenString().length();
|
||||
//styleRange.fontStyle = SWT.BOLD;
|
||||
styleRange.foreground = getBlueColor();
|
||||
styleRange.foreground = tokenColor;
|
||||
styledText.setStyleRange(styleRange);
|
||||
firstData = false;
|
||||
if (token.isIndenter()) {
|
||||
|
@ -120,15 +120,6 @@ public abstract class FilterAdapter {
|
||||
protected ToolItem getToolItem() {
|
||||
return toolItem;
|
||||
}
|
||||
protected Color getBlackColor() {
|
||||
return window.getBlackColor();
|
||||
}
|
||||
protected Color getGreenColor() {
|
||||
return window.getGreenColor();
|
||||
}
|
||||
protected Color getBlueColor() {
|
||||
return window.getBlueColor();
|
||||
}
|
||||
public void setDumpSelected() {
|
||||
nativeSelected = false;
|
||||
hexSelected = false;
|
||||
|
Loading…
Reference in New Issue
Block a user