Skip to content

Commit 2cc8dae

Browse files
authored
Merge pull request #75 from tferr/laf-adjustments
L&F adjustments and improvements
2 parents 3c3317f + fdf2736 commit 2cc8dae

File tree

5 files changed

+56
-31
lines changed

5 files changed

+56
-31
lines changed

src/main/java/org/scijava/ui/swing/console/ConsolePanel.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import javax.swing.JScrollPane;
4242
import javax.swing.JTextArea;
4343
import javax.swing.JTextPane;
44-
import javax.swing.KeyStroke;
44+
import javax.swing.UIManager;
4545
import javax.swing.text.BadLocationException;
4646
import javax.swing.text.Style;
4747
import javax.swing.text.StyleConstants;
@@ -117,12 +117,12 @@ private synchronized void initGui() {
117117

118118
doc = textPane.getStyledDocument();
119119

120-
stdoutLocal = createStyle("stdoutLocal", null, Color.black, null, null);
121-
stderrLocal = createStyle("stderrLocal", null, Color.red, null, null);
120+
stdoutLocal = createStyle("stdoutLocal", null, defaultFontColor(), null, null);
121+
stderrLocal = createStyle("stderrLocal", null, Color.RED, null, null);
122122
stdoutGlobal = createStyle("stdoutGlobal", stdoutLocal, null, null, true);
123123
stderrGlobal = createStyle("stderrGlobal", stderrLocal, null, null, true);
124124

125-
// NB: We wrap the JTextPane in a JPanel to disable
125+
// NB: We wrap the JTextPane in a JPanel to disable
126126
// the text pane's intelligent line wrapping behavior.
127127
// I.e.: we want console lines _not_ to wrap, but instead
128128
// for the scroll pane to show a horizontal scroll bar.
@@ -147,18 +147,31 @@ private synchronized void initGui() {
147147
private JPopupMenu initMenu() {
148148
final JPopupMenu menu = new JPopupMenu();
149149
JMenuItem item = new JMenuItem("Copy");
150-
item.setAccelerator(KeyStroke.getKeyStroke("control C"));
151-
item.addActionListener( e-> textPane.copy());
150+
item.addActionListener(e -> textPane.copy());
152151
menu.add(item);
153152
item = new JMenuItem("Clear");
154-
item.setAccelerator(KeyStroke.getKeyStroke("alt C"));
155153
item.addActionListener(e -> clear());
156154
menu.add(item);
155+
item = new JMenuItem("Select All");
156+
item.addActionListener(e -> textPane.selectAll());
157+
menu.add(item);
157158
return menu;
158159
}
159160

161+
@Override
162+
public void updateUI() {
163+
if (stdoutLocal != null)
164+
StyleConstants.setForeground(stdoutLocal, defaultFontColor());
165+
super.updateUI();
166+
}
167+
160168
// -- Helper methods --
161169

170+
private static Color defaultFontColor() {
171+
final Color color = UIManager.getColor("TextPane.foreground");
172+
return (color == null) ? Color.BLACK : color;
173+
}
174+
162175
private Style createStyle(final String name, final Style parent,
163176
final Color foreground, final Boolean bold, final Boolean italic)
164177
{

src/main/java/org/scijava/ui/swing/console/LogSourcesPanel.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,22 @@ private void selectionChanged(TreeSelectionEvent treeSelectionEvent) {
146146
}
147147

148148
private JButton initVisibilityButton() {
149-
JButton button = new JButton("visibility");
149+
JButton button = new JButton("Visibility");
150150
button.addActionListener(a -> menu.show(button, 0, button.getHeight()));
151151
return button;
152152
}
153153

154154
private void initMenu() {
155155
EnumSet<Level> levels = EnumSet.range(Level.ERROR, Level.TRACE);
156-
addMenuItemPerLevel(EnumSet.of(Level.TRACE), level -> "show all",
156+
addMenuItemPerLevel(EnumSet.of(Level.TRACE), level -> "Show all",
157157
this::onShowErrorUpToClicked);
158-
addMenuItemPerLevel(EnumSet.of(Level.NONE), level -> "hide all",
158+
addMenuItemPerLevel(EnumSet.of(Level.NONE), level -> "Hide all",
159159
this::onShowNoneClicked);
160160
menu.addSeparator();
161-
addMenuItemPerLevel(levels, level -> "show " + level.toString(),
161+
addMenuItemPerLevel(levels, level -> "Show " + level.toString(),
162162
this::onShowLogLevelClicked);
163163
menu.addSeparator();
164-
addMenuItemPerLevel(levels, level -> "hide " + level.toString(),
164+
addMenuItemPerLevel(levels, level -> "Hide " + level.toString(),
165165
this::onHideLogLevelClicked);
166166
menu.addSeparator();
167167
addMenuItemPerLevel(levels, LogSourcesPanel::listLevelsErrorTo,

src/main/java/org/scijava/ui/swing/console/LoggingPanel.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,10 @@
4949
import javax.swing.JMenuItem;
5050
import javax.swing.JPanel;
5151
import javax.swing.JPopupMenu;
52-
import javax.swing.JSeparator;
5352
import javax.swing.JSplitPane;
5453
import javax.swing.JTextPane;
5554
import javax.swing.KeyStroke;
56-
import javax.swing.SwingConstants;
57-
import javax.swing.plaf.basic.BasicArrowButton;
55+
import javax.swing.UIManager;
5856
import javax.swing.text.AttributeSet;
5957
import javax.swing.text.MutableAttributeSet;
6058
import javax.swing.text.SimpleAttributeSet;
@@ -89,7 +87,7 @@ public class LoggingPanel extends JPanel implements LogListener
8987
{
9088
private static final AttributeSet STYLE_ERROR = normal(new Color(200, 0, 0));
9189
private static final AttributeSet STYLE_WARN = normal(new Color(200, 140, 0));
92-
private static final AttributeSet STYLE_INFO = normal(Color.BLACK);
90+
private static final AttributeSet STYLE_INFO = normal(defaultInfoColor());
9391
private static final AttributeSet STYLE_DEBUG = normal(new Color(0, 0, 200));
9492
private static final AttributeSet STYLE_TRACE = normal(Color.GRAY);
9593
private static final AttributeSet STYLE_OTHERS = normal(Color.GRAY);
@@ -173,6 +171,12 @@ public void clear() {
173171
updateFilter();
174172
}
175173

174+
@Override
175+
public void updateUI() {
176+
StyleConstants.setForeground((MutableAttributeSet) STYLE_INFO, defaultInfoColor());
177+
super.updateUI();
178+
}
179+
176180
// -- LogListener methods --
177181

178182
@Override
@@ -183,12 +187,17 @@ public void messageLogged(LogMessage message) {
183187

184188
// -- Helper methods --
185189

190+
private static Color defaultInfoColor() {
191+
final Color color = UIManager.getColor("TextPane.foreground");
192+
return (color == null) ? Color.BLACK : color;
193+
}
194+
186195
private void initGui() {
187196
textFilter.setChangeListener(this::updateFilter);
188197

189198
JPopupMenu menu = initMenu();
190199

191-
JButton menuButton = new BasicArrowButton(SwingConstants.SOUTH);
200+
JButton menuButton = new JButton("\u22EE");
192201
menuButton.addActionListener(a ->
193202
menu.show(menuButton, 0, menuButton.getHeight()));
194203

@@ -216,7 +225,7 @@ private void initGui() {
216225
}
217226

218227
private LogSourcesPanel initSourcesPanel() {
219-
JButton reloadButton = new JButton("reload");
228+
JButton reloadButton = new JButton("Reload");
220229
reloadButton.addActionListener(actionEvent -> reloadSources());
221230
return new LogSourcesPanel(reloadButton);
222231
}
@@ -254,20 +263,20 @@ private JPopupMenu initMenu() {
254263

255264
private JMenu initSettingsMenu() {
256265
JMenu menu = new JMenu("Settings");
257-
menu.add(checkboxItem(LogFormatter.Field.TIME, "show time stamp"));
258-
menu.add(checkboxItem(LogFormatter.Field.SOURCE, "show log source"));
259-
menu.add(checkboxItem(LogFormatter.Field.LEVEL, "show log level"));
260-
menu.add(checkboxItem(LogFormatter.Field.THROWABLE, "show exception"));
261-
menu.add(checkboxItem(LogFormatter.Field.ATTACHMENT, "show attached data"));
262-
menu.add(new JSeparator());
266+
menu.add(checkboxItem(LogFormatter.Field.TIME, "Show time stamp"));
267+
menu.add(checkboxItem(LogFormatter.Field.SOURCE, "Show log source"));
268+
menu.add(checkboxItem(LogFormatter.Field.LEVEL, "Show log level"));
269+
menu.add(checkboxItem(LogFormatter.Field.THROWABLE, "Show exception"));
270+
menu.add(checkboxItem(LogFormatter.Field.ATTACHMENT, "Show attached data"));
271+
menu.addSeparator();
263272
menu.add(recordCallingClassMenuItem());
264273
return menu;
265274
}
266275

267276
private JCheckBoxMenuItem recordCallingClassMenuItem() {
268277
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem();
269278
menuItem.setState(false);
270-
menuItem.setAction(new AbstractAction("record calling class") {
279+
menuItem.setAction(new AbstractAction("Record calling class") {
271280
@Override
272281
public void actionPerformed(ActionEvent e) {
273282
recorder.setRecordCallingClass(menuItem.getState());

src/main/java/org/scijava/ui/swing/console/SwingConsolePane.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private synchronized void initLoggingPanel() {
148148
consolePanel = new ConsolePanel(context);
149149
loggingPanel = new LoggingPanel(context, LOG_FORMATTING_SETTINGS_KEY);
150150
logService.addLogListener(loggingPanel);
151-
component = new JPanel(new MigLayout("", "[grow]", "[grow]"));
151+
component = new JPanel(new MigLayout("insets 0", "[grow]", "[grow]"));
152152
JTabbedPane tabs = new JTabbedPane();
153153
tabs.addTab("Console", consolePanel);
154154
tabs.addTab("Log", loggingPanel);

src/main/java/org/scijava/ui/swing/options/OptionsLookAndFeel.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.formdev.flatlaf.FlatLightLaf;
4545
import com.formdev.flatlaf.FlatDarkLaf;
4646
import com.formdev.flatlaf.FlatIntelliJLaf;
47+
import com.formdev.flatlaf.FlatLaf;
4748
import com.formdev.flatlaf.FlatDarculaLaf;
4849

4950
import org.scijava.display.Display;
@@ -236,24 +237,26 @@ private DisplayService displayService() {
236237
* ("javax.swing.plaf.metal.MetalLookAndFeel", etc.)
237238
*/
238239
public static void setupLookAndFeel(final String lookAndFeel) {
239-
switch (lookAndFeel) {
240+
switch (lookAndFeel) { // FIXME: should FlatLaf.updateUI() calls be replaced with updateUILater()?
240241
case FlatLightLaf.NAME:
241-
FlatLightLaf.setup();
242+
if (FlatLightLaf.setup()) FlatLightLaf.updateUI();
242243
return;
243244
case FlatDarkLaf.NAME:
244-
FlatDarkLaf.setup();
245+
if (FlatDarkLaf.setup()) FlatDarkLaf.updateUI();
245246
return;
246247
case FlatDarculaLaf.NAME:
247-
FlatDarculaLaf.setup();
248+
if (FlatDarculaLaf.setup()) FlatDarculaLaf.updateUI();
248249
return;
249250
case FlatIntelliJLaf.NAME:
250-
FlatIntelliJLaf.setup();
251+
if (FlatIntelliJLaf.setup()) FlatIntelliJLaf.updateUI();
251252
return;
252253
default:
253254
try {
254255
UIManager.setLookAndFeel(lookAndFeel);
256+
FlatLaf.updateUI();
255257
} catch (final Exception ex) {
256258
ex.printStackTrace();
259+
FlatLaf.revalidateAndRepaintAllFramesAndDialogs(); // Recover from possible ill-states
257260
}
258261
}
259262
}

0 commit comments

Comments
 (0)