Skip to content

Commit a48e8a8

Browse files
committed
removed illegal reflective access; sidebar of JFileChooser now filters out all the "Backups of" pseudo-volumes from TimeMachine.
1 parent a339306 commit a48e8a8

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

README.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,16 @@ Now that JavaFX is being spun out of Java, some may yet still find this useful.
1515

1616
Requirements/Dependencies
1717
------------
18-
- Java 8
18+
- Java 8, but tested with Java 11 and 17
1919
- TwelveMonkeys ImageIO 3.5-SNAPSHOT or newer, include these artifacts:
2020
- core
2121
- metadata
2222
- icns
2323

24-
Illegal Reflective Access Warnings in JDK9+
25-
-----------
26-
To hide the warnings about illegal reflective access, launch your app with the jvm parameter:
27-
28-
java --add-opens java.desktop/com.apple.laf=ALL-UNNAMED ...
29-
30-
This will hide the warnings, but this does not fix the issue. Future jdk could remove the ability to force allowing the reflective access if not explicity allowed by the library.
31-
3224

3325
Code notes:
3426
-----------
3527

36-
- There are variations of the UI for every version of macOS up through Mavericks, but the last one to not rely on native code was the QuaquaLeopardFileChooserUI, so that's where my effort is focused. The QuaquaManager only provides this option for UI now.
37-
- QuaquaFileSystemView picks a macOS version-specific implementation of a FileSystemView. Ever since Lion, they all use OSXLionFileSystemView, so that's also where I focus.
28+
- There are variations of the UI for every version of macOS up through Mavericks, but the last one to not rely on native code was the QuaquaLeopardFileChooserUI. The QuaquaManager only provides this option for UI now.
29+
- QuaquaFileSystemView picks a macOS version-specific implementation of a FileSystemView. Ever since Lion, they all use OSXLionFileSystemView.
3830

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.weirdkid</groupId>
77
<artifactId>quaqua-jfc</artifactId>
8-
<version>24.02</version>
8+
<version>25.6</version>
99

1010
<name>Quaqua-JFC</name>
1111
<description>Pure Java JFileChooser for Mac, forked from Quaqua LAF</description>

src/main/java/ch/randelshofer/quaqua/leopard/filechooser/SidebarTreeModel.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.ArrayList;
1616
import java.util.Comparator;
1717
import java.util.HashMap;
18+
import java.net.InetAddress;
1819

1920
import javax.swing.Icon;
2021
import javax.swing.JFileChooser;
@@ -79,6 +80,18 @@ public class SidebarTreeModel extends DefaultTreeModel implements TreeModelListe
7980
new File(QuaquaManager.getProperty("user.home"), "Desktop"),
8081
new File(QuaquaManager.getProperty("user.home"), "Documents") };
8182

83+
private final String backupPrefix = "Backups of ";
84+
// this is unreliable on macOS
85+
// {
86+
// String computerName;
87+
// try {
88+
// computerName = InetAddress.getLocalHost().getHostName();
89+
// } catch (Exception e) {
90+
// computerName = ""; // fallback if hostname can't be determined
91+
// }
92+
// backupPrefix = "Backups of " + computerName;
93+
// }
94+
8295
/** Creates a new instance. */
8396
public SidebarTreeModel(JFileChooser fileChooser, TreePath path, TreeModel model) {
8497
super(new DefaultMutableTreeNode(), true);
@@ -157,7 +170,8 @@ private void updateDevicesNode() {
157170
// in the view. Only add non-leaf nodes
158171
for (int i = 0, n = modelDevicesNode.getChildCount(); i < n; i++) {
159172
FileSystemTreeModel.Node modelNode = (FileSystemTreeModel.Node) modelDevicesNode.getChildAt(i);
160-
if (!modelNode.isLeaf()) {
173+
String deviceName = modelNode.getUserName();
174+
if (!modelNode.isLeaf() && !(deviceName != null && deviceName.startsWith(backupPrefix))) {
161175
boolean isInView = false;
162176
for (int j = 0, m = devicesNode.getChildCount(); j < m; j++) {
163177
SidebarViewToModelNode viewNode = (SidebarViewToModelNode) devicesNode.getChildAt(j);

src/main/java/ch/randelshofer/quaqua/subset/QuaquaLeopardFileChooserLAF.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,39 @@ public class QuaquaLeopardFileChooserLAF extends LookAndFeelProxy {
9696
/**
9797
* Creates a new instance.
9898
*/
99+
// public QuaquaLeopardFileChooserLAF() {
100+
// // System.out.println(UIManager.getSystemLookAndFeelClassName());
101+
// String targetClassName = "com.apple.laf.AquaLookAndFeel";
102+
// try {
103+
// setTarget((LookAndFeel) Class.forName(targetClassName).getDeclaredConstructor().newInstance());
104+
// } catch (Exception e) {
105+
// throw new InternalError(
106+
// "Unable to instanciate target Look and Feel \"" + targetClassName + "\". " + e.getMessage());
107+
// }
108+
// }
109+
99110
public QuaquaLeopardFileChooserLAF() {
100-
// System.out.println(UIManager.getSystemLookAndFeelClassName());
101-
String targetClassName = "com.apple.laf.AquaLookAndFeel";
111+
String targetClassName = UIManager.getSystemLookAndFeelClassName();
112+
113+
//System.out.println("QuaquaLeopardFileChooserLAF: Using target Look and Feel: " + targetClassName);
114+
// only install Quaqua on macOS/Aqua
115+
// if (!"com.apple.laf.AquaLookAndFeel".equals(targetClassName)) {
116+
// return;
117+
// }
102118
try {
103-
setTarget((LookAndFeel) Class.forName(targetClassName).getDeclaredConstructor().newInstance());
104-
} catch (Exception e) {
119+
// ask UIManager (inside java.desktop) to load it
120+
UIManager.setLookAndFeel(targetClassName);
121+
setTarget( UIManager.getLookAndFeel() );
122+
}
123+
catch (Exception e) {
105124
throw new InternalError(
106-
"Unable to instanciate target Look and Feel \"" + targetClassName + "\". " + e.getMessage());
125+
"Unable to instantiate system L&F \"" + targetClassName + "\": " + e
126+
);
107127
}
108128
}
109129

130+
131+
110132
/**
111133
* Return a one line description of this look and feel implementation, e.g. "The
112134
* CDE/Motif Look and Feel". This string is intended for the user, e.g. in the

0 commit comments

Comments
 (0)