Skip to content

Commit 6bbab67

Browse files
committed
try to implement partial transparency
As implemented in Notepad++, a partially transparent search/replace window could make it easier to interact with the editor (particularly in fullscreen contexts, when the "always on top" window could hide the search results). Unfortunately, Java can only apply the transparency to undecorated window, so it's a no-go. Java gurus, please come to the rescue :D
1 parent 1ae2b10 commit 6bbab67

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

app/src/cc/arduino/view/findreplace/FindReplace.java

+19
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.HashMap;
4141
import java.util.Map;
4242

43+
import static java.awt.GraphicsDevice.WindowTranslucency.*;
4344
import static processing.app.I18n.tr;
4445

4546
public class FindReplace extends javax.swing.JFrame {
@@ -55,6 +56,7 @@ public class FindReplace extends javax.swing.JFrame {
5556
public FindReplace(Editor editor, Map<String, Object> state) {
5657
this.editor = editor;
5758

59+
isTranslucencySupported();
5860
initComponents();
5961

6062
if (OSUtils.isMacOS()) {
@@ -78,6 +80,10 @@ public void windowActivated(WindowEvent e) {
7880
findField.requestFocusInWindow();
7981
findField.selectAll();
8082
setAlwaysOnTop(true);
83+
if (useTranslucency) {
84+
// Window is decorated, so tranparency doesn't work :(
85+
//setOpacity(0.7f);
86+
}
8187
}
8288
public void windowDeactivated(WindowEvent e) {
8389
setAlwaysOnTop(false);
@@ -89,6 +95,10 @@ public void windowActivated(WindowEvent e) {
8995
findField.requestFocusInWindow();
9096
findField.selectAll();
9197
setAlwaysOnTop(true);
98+
if (useTranslucency) {
99+
// Window is decorated, so tranparency doesn't work :(
100+
//setOpacity(1.0f);
101+
}
92102
}
93103
public void windowDeactivated(WindowEvent e) {
94104
}
@@ -104,6 +114,15 @@ public void setVisible(boolean b) {
104114
super.setVisible(b);
105115
}
106116

117+
private boolean useTranslucency;
118+
119+
private void isTranslucencySupported() {
120+
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
121+
GraphicsDevice gd = ge.getDefaultScreenDevice();
122+
//If translucent windows aren't supported, exit.
123+
useTranslucency = gd.isWindowTranslucencySupported(TRANSLUCENT);
124+
}
125+
107126
private Map<String, Object> findDialogState() {
108127
Map<String, Object> state = new HashMap<>();
109128
state.put(FIND_TEXT, findField.getText());

0 commit comments

Comments
 (0)