Skip to content

Commit 4063620

Browse files
committed
Merge remote-tracking branch 'origin/main' into modernize2
2 parents b6430cf + df0d173 commit 4063620

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎src/main/java/org/scijava/ui/swing/script/Icons.java‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ static Icon magnifier() {
249249
return new MagnifierIcon();
250250
}
251251

252+
/**
253+
* Foreground color with which to paint an icon. Note: The component may be
254+
* null, e.g. when macOS renders icons for its native screen menu bar.
255+
*/
256+
private static Color foreground(final Component c) {
257+
if (c != null) return c.getForeground();
258+
final Color color = UIManager.getColor("MenuItem.foreground");
259+
return color != null ? color : Color.GRAY;
260+
}
261+
252262
/**
253263
* Icon painted from SVG path data (absolute M, L, C and Z commands)
254264
*/
@@ -279,7 +289,7 @@ private static class GlyphIcon extends FlatAbstractIcon {
279289

280290
@Override
281291
protected void paintIcon(final Component c, final Graphics2D g) {
282-
Color color = light == null ? c.getForeground() : FlatLaf.isLafDark() ? dark : light;
292+
Color color = light == null ? foreground(c) : FlatLaf.isLafDark() ? dark : light;
283293
if (disabled) {
284294
final Color d = UIManager.getColor("Button.disabledText");
285295
color = (d != null) ? d : Color.GRAY;
@@ -345,7 +355,7 @@ private abstract static class WindowIcon extends FlatAbstractIcon {
345355

346356
@Override
347357
protected void paintIcon(final Component c, final Graphics2D g) {
348-
g.setColor(c.getForeground());
358+
g.setColor(foreground(c));
349359
g.drawRoundRect(1, 2, 13, 11, 3, 3);
350360
paintContent(g, c instanceof AbstractButton && ((AbstractButton) c).isSelected());
351361
}
@@ -374,7 +384,7 @@ public void paintIcon(final Component c, final Graphics g, final int x, final in
374384
final Graphics2D g2 = (Graphics2D) g.create();
375385
try {
376386
FlatUIUtils.setRenderingHints(g2);
377-
g2.setColor(c.getForeground());
387+
g2.setColor(foreground(c));
378388
g2.setStroke(new BasicStroke(UIScale.scale(1.3f), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
379389
final float s = getIconWidth();
380390
final float a = s * .3f; // inset
@@ -402,7 +412,7 @@ public void paintIcon(final Component c, final Graphics g, final int x, final in
402412
final Graphics2D g2 = (Graphics2D) g.create();
403413
try {
404414
FlatUIUtils.setRenderingHints(g2);
405-
g2.setColor(c.getForeground());
415+
g2.setColor(foreground(c));
406416
g2.setStroke(new BasicStroke(UIScale.scale(1.6f), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
407417
final float s = getIconWidth();
408418
FlatUIUtils.drawShapePure(g2, new Ellipse2D.Float(x + .1f * s, y + .1f * s, .6f * s, .6f * s));

‎src/main/java/org/scijava/ui/swing/script/ScriptEditor.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
package org.scijava.ui.swing.script;
3131

32+
import java.awt.EventQueue;
33+
3234
import org.scijava.Context;
3335
import org.scijava.command.Command;
3436
import org.scijava.plugin.Menu;
@@ -50,7 +52,9 @@ public class ScriptEditor implements Command {
5052

5153
@Override
5254
public void run() {
53-
new TextEditor(context).setVisible(true);
55+
// Note: Swing components must be built and shown on the EDT; otherwise
56+
// layout races with the EDT and can leave the window collapsed.
57+
EventQueue.invokeLater(() -> new TextEditor(context).setVisible(true));
5458
}
5559

5660
}

‎src/main/java/org/scijava/ui/swing/script/TextEditor.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,8 +974,7 @@ public void windowGainedFocus(final WindowEvent e) {
974974
});
975975
}
976976
catch (final Exception ie) {
977-
/* ignore */
978-
log.debug(ie);
977+
log.error("Failed to lay out Script Editor window", ie);
979978
}
980979
findDialog = new FindAndReplaceDialog(this);
981980

0 commit comments

Comments
 (0)