Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to JFileChooser on Mac with VAqua #88

Merged
merged 17 commits into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
lib/ant.jar;
lib/ant-launcher.jar;
lib/jna.jar;
lib/jna-platform.jar"
lib/jna-platform.jar;
lib/vaqua7.jar"
debug="on"
nowarn="true">
<src path="src" />
Expand Down
Binary file added app/lib/vaqua7.jar
Binary file not shown.
7 changes: 6 additions & 1 deletion app/src/processing/app/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,12 @@ public boolean saveAs() throws IOException {
// TODO rewrite this to use shared version from PApplet (But because that
// specifies a callback function, this needs to wait until the refactoring)
final String PROMPT = Language.text("save");
if (Preferences.getBoolean("chooser.files.native")) {

// https://github.com/processing/processing4/issues/77
boolean useNative = Preferences.getBoolean("chooser.files.native");
useNative = useNative && !Platform.isMacOS();
sampottinger marked this conversation as resolved.
Show resolved Hide resolved

if (useNative) {
// get new name for folder
FileDialog fd = new FileDialog(editor, PROMPT, FileDialog.SAVE);
if (isReadOnly() || isUntitled()) {
Expand Down
121 changes: 120 additions & 1 deletion app/src/processing/app/platform/DefaultPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@

package processing.app.platform;

import java.awt.Color;
import java.awt.Component;
import java.awt.Desktop;
import java.awt.Graphics;
import java.io.File;
import java.net.URI;

import javax.swing.Icon;
import javax.swing.UIManager;

import com.sun.jna.Library;
import com.sun.jna.Native;
import org.violetlib.aqua.AquaLookAndFeel;

import processing.app.Base;
import processing.app.Preferences;
Expand Down Expand Up @@ -75,7 +80,20 @@ public void initBase(Base base) {
public void setLookAndFeel() throws Exception {
String laf = Preferences.get("editor.laf");
if (laf == null || laf.length() == 0) { // normal situation
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
if (shouldUseVaqua()) {
UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");

Icon collapse = new MacTreeIcon(true);
Icon open = new MacTreeIcon(false);
Icon leaf = new MacEmptyIcon();
UIManager.put("Tree.closedIcon", leaf);
UIManager.put("Tree.openIcon", leaf);
UIManager.put("Tree.collapsedIcon", open);
UIManager.put("Tree.expandedIcon", collapse);
UIManager.put("Tree.leafIcon", leaf);
} else {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
} else {
UIManager.setLookAndFeel(laf);
}
Expand Down Expand Up @@ -188,4 +206,105 @@ public float getSystemZoom() {
return ZOOM_DEFAULT_SIZING;
}

/**
* Spacer icon for mac when using Vaqua.
*
* <p>
* Due to potential rendering issues, this small spacer is used to ensure that rendering is stable
* while using Vaqua with non-standard swing components. Without this, some sizing calculations
* non-standard components may fail or become unreliable.
* </p>
*/
class MacEmptyIcon implements Icon {
private final int SIZE = 1;

/**
* Create a new single pixel spacer icon.
*/
public MacEmptyIcon() {}

@Override
public int getIconWidth() {
return SIZE;
}

@Override
public int getIconHeight() {
return SIZE;
}

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {}
}

/**
* Replacement tree icon for mac when using Vaqua.
*
* <p>
* Due to potential rendering issues with the regular tree icon set, this replacement tree icon
* for mac ensures stable rendering when using Vaqua with non-standard swing components. Without
* this, some sizing calculations within non-standard components may fail or become unreliable.
* </p>
*/
private class MacTreeIcon implements Icon {
private final int SIZE = 12;
private final boolean isOpen;

/**
* Create a new tree icon.
*
* @param newIsOpen Flag indicating if the icon should be in the open or closed state at
* construction. True if open false otherwise.
*/
public MacTreeIcon(boolean newIsOpen) {
isOpen = newIsOpen;
}

@Override
public int getIconWidth() {
return SIZE;
}

@Override
public int getIconHeight() {
return SIZE;
}

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
g.setColor(Color.GRAY);

g.drawLine(x + SIZE / 2 - 3, y + SIZE / 2, x + SIZE / 2 + 3, y + SIZE / 2);

if (!isOpen) {
g.drawLine(x + SIZE / 2, y + SIZE / 2 - 3, x + SIZE / 2, y + SIZE / 2 + 3);
}
}
}

/**
* Determine if Vaqua swing modifications for OS X should be used.
*
* @return True if the system is compatible with Vaqua and it is preferred. False otherwise.
*/
private boolean shouldUseVaqua() {
sampottinger marked this conversation as resolved.
Show resolved Hide resolved
boolean isMac = System.getProperty("os.name", "").startsWith("Mac OS");
if (!isMac) {
return false;
}

String fullMacVersion = System.getProperty("os.version", "NOT_AVAILABLE");
if ("NOT_AVAILABLE".equals(fullMacVersion)) {
return false;
}

String[] components = fullMacVersion.split("\\.");
if (components.length < 2) {
return false;
}

int macTrain = Integer.parseInt(components[1]);
return macTrain >= 10;
}

}
3 changes: 2 additions & 1 deletion app/src/processing/app/ui/EditorConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ protected void updateMode() {
StyleConstants.setBold(errStyle, font.isBold());
StyleConstants.setItalic(errStyle, font.isItalic());

if (UIManager.getLookAndFeel().getID().equals("Nimbus")) {
String lookAndFeel = UIManager.getLookAndFeel().getID();
if (lookAndFeel.equals("Nimbus") || lookAndFeel.equals("VAqua")) {
getViewport().setBackground(bgColor);
consoleTextPane.setOpaque(false);
consoleTextPane.setBackground(new Color(0, 0, 0, 0));
Expand Down
2 changes: 2 additions & 0 deletions build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@
<include name="app/lib/jna-platform.jar" />
<include name="app/lib/ant.jar" />
<include name="app/lib/ant-launcher.jar" />
<include name="app/lib/vaqua7.jar" />
sampottinger marked this conversation as resolved.
Show resolved Hide resolved
</fileset>

<target name="build" description="Build Processing.">
Expand Down Expand Up @@ -721,6 +722,7 @@
<classpath file="../app/lib/jna-platform.jar" />
<classpath file="../app/lib/ant.jar" />
<classpath file="../app/lib/ant-launcher.jar" />
<classpath file="../app/lib/vaqua7.jar" />

<!-- plus core.jar... note that this is no longer shared -->
<classpath file="../core/library/core.jar" />
Expand Down
1 change: 1 addition & 0 deletions java/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<pathelement location="../app/lib/apple.jar" />
<pathelement location="../app/lib/jna.jar" />
<pathelement location="../app/lib/jna-platform.jar" />
<pathelement location="../app/lib/vaqua7.jar" />

<pathelement location="mode/antlr-4.7.2-complete.jar" />
<pathelement location="mode/classpath-explorer-1.0.jar" />
Expand Down
2 changes: 1 addition & 1 deletion java/src/processing/mode/java/debug/VariableInspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ protected void setItalic(boolean on) {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
setForeground(tree.isEnabled() ? Color.BLACK : Color.GRAY);
//setForeground(tree.isEnabled() ? Color.BLACK : Color.GRAY);

if (value instanceof VariableNode) {
VariableNode var = (VariableNode) value;
Expand Down