Skip to content

Commit 887c4bd

Browse files
committed
Optimize resolving JTable foreground color
1 parent 8fc6de2 commit 887c4bd

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

visualvm/heapviewer/nbproject/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<compile-dependency/>
5858
<run-dependency>
5959
<release-version>2</release-version>
60-
<specification-version>2.0</specification-version>
60+
<specification-version>2.1</specification-version>
6161
</run-dependency>
6262
</dependency>
6363
<dependency>

visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/java/ThreadNodeRenderer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,7 +34,7 @@
3434
import org.graalvm.visualvm.heapviewer.ui.HeapViewerRenderer;
3535
import java.awt.Color;
3636
import java.util.Objects;
37-
import javax.swing.JTable;
37+
import org.graalvm.visualvm.lib.ui.UIUtils;
3838

3939
/**
4040
*
@@ -44,8 +44,6 @@ public class ThreadNodeRenderer extends LabelRenderer implements HeapViewerRende
4444

4545
private static final Icon ICON = Icons.getIcon(ProfilerIcons.THREAD);
4646

47-
private static final Color REPLACEABLE_FOREGROUND = new JTable().getForeground();
48-
4947
protected final Heap heap;
5048

5149
private Color customForeground;
@@ -74,7 +72,7 @@ public String getShortName() {
7472

7573

7674
public void setForeground(Color foreground) {
77-
if (customForeground != null && Objects.equals(foreground, REPLACEABLE_FOREGROUND)) {
75+
if (customForeground != null && Objects.equals(foreground, UIUtils.getDefaultTableForeground())) {
7876
super.setForeground(customForeground);
7977
} else {
8078
super.setForeground(foreground);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Manifest-Version: 1.0
22
OpenIDE-Module: org.graalvm.visualvm.lib.ui/2
33
OpenIDE-Module-Localizing-Bundle: org/graalvm/visualvm/lib/ui/Bundle.properties
4-
OpenIDE-Module-Specification-Version: 2.0
4+
OpenIDE-Module-Specification-Version: 2.1
55

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/UIUtils.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright 1997-2020 Oracle and/or its affiliates. All rights reserved.
55
*
66
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
77
* Other names may be trademarks of their respective owners.
@@ -55,9 +55,12 @@
5555
import javax.swing.*;
5656
import javax.swing.border.Border;
5757
import javax.swing.border.CompoundBorder;
58+
import javax.swing.event.TableModelListener;
5859
import javax.swing.event.TreeExpansionEvent;
5960
import javax.swing.event.TreeExpansionListener;
61+
import javax.swing.plaf.TableUI;
6062
import javax.swing.table.JTableHeader;
63+
import javax.swing.table.TableModel;
6164
import javax.swing.tree.TreeModel;
6265
import javax.swing.tree.TreePath;
6366

@@ -344,6 +347,32 @@ public static Color getUnfocusedSelectionForeground() {
344347
return unfocusedSelFg;
345348
}
346349

350+
private static Color defaultTableForeground;
351+
352+
public static Color getDefaultTableForeground() {
353+
if (defaultTableForeground == null) {
354+
defaultTableForeground = new JTable() {
355+
@Override protected void initializeLocalVars() {}
356+
@Override protected void createDefaultRenderers() {}
357+
@Override protected void createDefaultEditors() {}
358+
@Override protected TableModel createDefaultDataModel() {
359+
return new TableModel() {
360+
@Override public int getRowCount() { return 0; }
361+
@Override public int getColumnCount() { return 0; }
362+
@Override public String getColumnName(int columnIndex) { throw new UnsupportedOperationException("Not supported."); } // NOI18N
363+
@Override public Class<?> getColumnClass(int columnIndex) { throw new UnsupportedOperationException("Not supported."); } // NOI18N
364+
@Override public boolean isCellEditable(int rowIndex, int columnIndex){ throw new UnsupportedOperationException("Not supported."); } // NOI18N
365+
@Override public Object getValueAt(int rowIndex, int columnIndex) { throw new UnsupportedOperationException("Not supported."); } // NOI18N
366+
@Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { throw new UnsupportedOperationException("Not supported."); } // NOI18N
367+
@Override public void addTableModelListener(TableModelListener l) {}
368+
@Override public void removeTableModelListener(TableModelListener l) {}
369+
};
370+
}
371+
@Override public void updateUI() { setUI((TableUI)UIManager.getUI(this)); }
372+
}.getForeground();
373+
}
374+
return defaultTableForeground;
375+
}
347376

348377
private static Color profilerResultsBackground;
349378

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/swing/renderer/NormalBoldGrayRenderer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright 1997-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright 1997-2020 Oracle and/or its affiliates. All rights reserved.
55
*
66
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
77
* Other names may be trademarks of their respective owners.
@@ -47,7 +47,6 @@
4747
import java.awt.Font;
4848
import java.util.Objects;
4949
import javax.swing.Icon;
50-
import javax.swing.JTable;
5150
import javax.swing.SwingConstants;
5251
import org.graalvm.visualvm.lib.ui.UIUtils;
5352

@@ -57,16 +56,14 @@
5756
*/
5857
public class NormalBoldGrayRenderer extends MultiRenderer {
5958

60-
private static final Color REPLACEABLE_FOREGROUND = new JTable().getForeground();
61-
6259
private final LabelRenderer normalRenderer;
6360
private final LabelRenderer boldRenderer;
6461
private final LabelRenderer grayRenderer;
6562

6663
private final ProfilerRenderer[] renderers;
6764

6865
private Color customForeground;
69-
private Color replaceableForeground = REPLACEABLE_FOREGROUND;
66+
private Color replaceableForeground = UIUtils.getDefaultTableForeground();
7067

7168

7269
public NormalBoldGrayRenderer() {

0 commit comments

Comments
 (0)