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 all 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
15 changes: 13 additions & 2 deletions app/build.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<?xml version="1.0"?>
<project name="Processing PDE" default="build">

<property name="vaqua.url" value="https://violetlib.org/release/vaqua" />

<target name="clean" description="Clean the build directories">
<delete dir="bin" />
<delete file="pde.jar" />
</target>

<target name="compile" description="Compile sources">
<target name="download-vaqua">

<get dest="lib" usetimestamp="true">
<url url="${vaqua.url}/7/VAqua7.jar" />
</get>

</target>

<target name="compile" description="Compile sources" depends="download-vaqua">
<condition property="core-built">
<available file="../core/library/core.jar" />
</condition>
Expand Down Expand Up @@ -39,7 +49,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
5 changes: 4 additions & 1 deletion app/src/processing/app/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,10 @@ 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");
if (useNative) {
// get new name for folder
FileDialog fd = new FileDialog(editor, PROMPT, FileDialog.SAVE);
if (isReadOnly() || isUntitled()) {
Expand Down
97 changes: 96 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,21 @@ 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());
boolean isMac = System.getProperty("os.name", "").startsWith("Mac OS");
if (isMac && Preferences.getBoolean("editor.allow_vaqua")) {
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 +207,80 @@ 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);
}
}
}

}
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
5 changes: 4 additions & 1 deletion 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" />
</fileset>

<target name="build" description="Build Processing.">
Expand Down Expand Up @@ -704,7 +705,8 @@
copyright="© The Processing Foundation"
shortVersion="${version}"
version="${revision}"
mainClassName="processing.app.BaseSplash">
mainClassName="processing.app.BaseSplash"
minimumSystemVersion="10.10.0">

<!-- The appbundler task needs a couple files (the Info.plist and
anything else outside /jdk) from the full JDK, even though
Expand All @@ -721,6 +723,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
4 changes: 4 additions & 0 deletions build/shared/lib/defaults.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ recent.count = 10

# Default to the native (AWT) file selector where possible
chooser.files.native = true
chooser.files.native.macosx = false # except on mac where it's broken


# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand Down Expand Up @@ -167,6 +168,9 @@ editor.watcher.debug = false
# The window of time (in milliseconds) in which a change won't be counted
editor.watcher.window = 1500

# allow vaqua on mac
editor.allow_vaqua = true

# Format and search engine to use for online queries
search.format = https://google.com/search?q=%s

Expand Down
4 changes: 2 additions & 2 deletions java/application/Info.plist.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<string>@@sketch@@</string>

<key>LSMinimumSystemVersion</key>
<string>10.8.5</string>
<string>10.10.0</string>

<key>NSHighResolutionCapable</key>
<true/>
Expand All @@ -61,7 +61,7 @@
<array>
@@jvm_options_list@@
<string>-Xdock:icon=$APP_ROOT/Contents/Resources/sketch.icns</string>
<string>-Djava.library.path=$APP_ROOT/Contents/Java</string>
<string>-Djava.library.path=$APP_ROOT/Contents/Java</string>
<string>-Dapple.laf.useScreenMenuBar=true</string>
<string>-Dcom.apple.macos.use-file-dialog-packages=true</string>
<string>-Dcom.apple.macos.useScreenMenuBar=true</string>
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