Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,8 @@ private void initializeLookAndFeel() {
// Force the Look & Feel to be instantiated.
UIDefaults defaults = UIManager.getDefaults();
if (lafClsName.equals(PlasticLookAndFeel.class.getName())) {
// Truly strange. If we don't do this then the LAF cannot be found.
PlasticLookAndFeel.setCurrentTheme(new ProtegePlasticTheme());
UIManager.put("ClassLoader", PlasticLookAndFeel.class.getClassLoader());
// For plastic this needs to be instantiated here - otherwise SwingUtilities uses the wrong class
// loaded.
LookAndFeel lookAndFeel = (LookAndFeel) Class.forName(lafClsName).newInstance();
UIManager.setLookAndFeel(lookAndFeel);
// Use ThemeManager to apply the correct theme (light or dark)
org.protege.editor.core.ui.util.ThemeManager.loadTheme();
}
else {
// Now set the class loader for Component UI loading to this one. Works for non Plastic LAFs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public class TextForegroundPreviewPanel extends JPanel
public TextForegroundPreviewPanel(JColorChooser chooser) {
chooser.getSelectionModel().addChangeListener(this);
setForeground(color);
setBackground(Color.WHITE);
Color panelBg = javax.swing.UIManager.getColor("Panel.background");
if (panelBg == null) {
panelBg = Color.WHITE;
}
setBackground(panelBg);
setOpaque(true);
setFont(new Font("monospaced", Font.PLAIN, 12));
text.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,39 @@ public class MList extends JList {

private Font sectionHeaderFont = new Font("Lucida Grande", Font.PLAIN, 10);

private static final Color itemBackgroundColor = Color.WHITE;
private static final Color DEFAULT_LIST_DIVIDER_COLOR = new Color(240, 240, 240);

private Color getListBackgroundColor() {
Color bg = getBackground();
if (bg == null) {
bg = UIManager.getColor("MList.background");
}
if (bg == null) {
bg = UIManager.getColor("List.background");
}
if (bg == null) {
bg = UIManager.getColor("Panel.background");
}
if (bg == null) {
bg = UIManager.getColor("control");
}
return bg != null ? bg : Color.WHITE;
}

private Color resolveBackground(Color candidate) {
return candidate != null ? candidate : getListBackgroundColor();
}

private Color getListDividerColor() {
Color divider = UIManager.getColor("Separator.foreground");
if (divider == null) {
divider = UIManager.getColor("controlShadow");
}
if (divider == null) {
divider = DEFAULT_LIST_DIVIDER_COLOR;
}
return divider;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -266,7 +297,7 @@ protected List<MListButton> getListItemButtons(MListItem item) {
}

protected Color getItemBackgroundColor(MListItem item) {
return itemBackgroundColor;
return getListBackgroundColor();
}

public class MListCellRenderer implements ListCellRenderer {
Expand Down Expand Up @@ -336,7 +367,7 @@ protected Border createPaddingBorder(JList list, Object value, int index, boolea
bottomMargin = getRowHeightPadding(index);
}
}
return BorderFactory.createMatteBorder(0, 0, bottomMargin, 0, Color.WHITE);
return BorderFactory.createMatteBorder(0, 0, bottomMargin, 0, resolveBackground(list.getBackground()));
}

private int getRowHeightPadding(int index) {
Expand All @@ -349,8 +380,8 @@ private int getRowHeightPadding(int index) {

protected Border createListItemBorder(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Border internalPadding = BorderFactory.createEmptyBorder(1, 1, 1, 1);
Border line = BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(240, 240, 240));
Border externalBorder = BorderFactory.createMatteBorder(0, 20, 0, 0, list.getBackground());
Border line = BorderFactory.createMatteBorder(0, 0, 1, 0, getListDividerColor());
Border externalBorder = BorderFactory.createMatteBorder(0, 20, 0, 0, resolveBackground(list.getBackground()));
return BorderFactory.createCompoundBorder(
externalBorder,
BorderFactory.createCompoundBorder(line, internalPadding)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class PreferencesDialogPanel extends JPanel implements Disposable {
public PreferencesDialogPanel(EditorKit editorKit) {
this.editorKit = editorKit;
setLayout(new BorderLayout());
setBackground(UIManager.getColor("Panel.background"));
setOpaque(true);
add(tabbedPane);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int margin = 300;
Expand All @@ -59,6 +61,8 @@ public PreferencesDialogPanel(EditorKit editorKit) {
private void reload() {
dispose();
tabbedPane.removeAll();
tabbedPane.setBackground(UIManager.getColor("Panel.background"));
tabbedPane.setOpaque(true);
PreferencesPanelPluginLoader loader = new PreferencesPanelPluginLoader(editorKit);
Set<PreferencesPanelPlugin> plugins = new TreeSet<>((o1, o2) -> {
String s1 = o1.getLabel();
Expand All @@ -73,6 +77,10 @@ private void reload() {
final String label = plugin.getLabel();
final JScrollPane sp = new JScrollPane(panel);
sp.setBorder(new EmptyBorder(0, 0, 0, 0));
sp.setBackground(UIManager.getColor("Panel.background"));
sp.setOpaque(true);
sp.getViewport().setBackground(UIManager.getColor("Panel.background"));
sp.getViewport().setOpaque(true);
map.put(label, panel);
componentMap.put(label, sp);
tabbedPane.addTab(label, sp);
Expand Down Expand Up @@ -130,6 +138,8 @@ public static void showPreferencesDialog(String selectedPanel, EditorKit editorK
final PreferencesDialogPanel preferencesPanel = new PreferencesDialogPanel(editorKit);

JPanel holder = new JPanel(new BorderLayout(4, 4));
holder.setBackground(UIManager.getColor("Panel.background"));
holder.setOpaque(true);
holder.add(preferencesPanel);

if (selectedPanel == null){
Expand All @@ -139,6 +149,8 @@ public static void showPreferencesDialog(String selectedPanel, EditorKit editorK
preferencesPanel.setSelectedPanel(selectedPanel);

JPanel resetPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
resetPanel.setBackground(UIManager.getColor("Panel.background"));
resetPanel.setOpaque(true);
JButton resetPreferencesButton = new JButton(new AbstractAction("Reset preferences...") {
public void actionPerformed(ActionEvent e) {
handleResetPreferences(preferencesPanel);
Expand All @@ -148,7 +160,14 @@ public void actionPerformed(ActionEvent e) {
holder.add(resetPanel, BorderLayout.SOUTH);

JOptionPane op = new JOptionPane(holder, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
op.setBackground(UIManager.getColor("Panel.background"));
op.setOpaque(true);
JDialog dlg = op.createDialog(editorKit.getWorkspace(), "Preferences");
dlg.getContentPane().setBackground(UIManager.getColor("Panel.background"));

// Recursively set background colors on all components in the dialog
setBackgroundRecursive(dlg, UIManager.getColor("Panel.background"));

dlg.setResizable(true);
dlg.setVisible(true);
Object o = op.getValue();
Expand All @@ -175,4 +194,30 @@ private static void handleResetPreferences(PreferencesDialogPanel panel) {
panel.reload();
panel.setSelectedPanel(selectedPanel);
}

/**
* Recursively sets the background color on all components in a container.
* This ensures that all nested components use the correct theme background.
*/
private static void setBackgroundRecursive(Container container, Color background) {
if (container == null || background == null) return;

// Set background on the container itself
container.setBackground(background);
if (container instanceof JComponent) {
((JComponent) container).setOpaque(true);
}

// Recursively set background on all child components
for (Component component : container.getComponents()) {
if (component instanceof Container) {
setBackgroundRecursive((Container) component, background);
} else {
component.setBackground(background);
if (component instanceof JComponent) {
((JComponent) component).setOpaque(true);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ public class PreferencesLayoutPanel extends JComponent {
public PreferencesLayoutPanel() {
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
Color panelBg = UIManager.getColor("Panel.background");
if (panelBg == null) {
panelBg = Color.WHITE;
}
setBackground(panelBg);
backingPanel = new JPanel(new GridBagLayout());
backingPanel.setBackground(panelBg);
backingPanel.setOpaque(true);
add(backingPanel, BorderLayout.NORTH);
}

Expand Down Expand Up @@ -165,7 +172,11 @@ private void handleComponentAdded(JComponent component) {
public void addHelpText(String helpText) {
JLabel label = new JLabel(helpText);
label.setFont(label.getFont().deriveFont(Font.PLAIN, 10f));
label.setForeground(Color.GRAY);
Color helpFg = UIManager.getColor("Label.disabledForeground");
if (helpFg == null) {
helpFg = Color.GRAY;
}
label.setForeground(helpFg);
label.setBorder(BorderFactory.createEmptyBorder(3, 20, 7, 0));
addGroupComponent(label);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public void setup(String label, EditorKit editorKit) {
this.editorKit = editorKit;
setBorder(BorderFactory.createEmptyBorder(30, 20, 20, 20));
setLayout(new PreferencesPanelLayoutManager(this));
Color panelBg = UIManager.getColor("Panel.background");
if (panelBg == null) {
panelBg = Color.WHITE;
}
setBackground(panelBg);
setOpaque(true);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ public static JComponent createExceptionComponent(String message, Throwable exce

public static JScrollPane createScrollPane(JComponent content) {
JScrollPane sp = new JScrollPane(content);
sp.getViewport().setBackground(Color.WHITE);
Color background = content != null ? content.getBackground() : null;
if (background == null) {
background = UIManager.getColor("ScrollPane.background");
}
if (background == null) {
background = UIManager.getColor("Panel.background");
}
if (background == null) {
background = UIManager.getColor("control");
}
sp.getViewport().setBackground(background != null ? background : Color.WHITE);
return sp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,40 @@
public class LinkLabel extends JLabel {

private Color linkColor;

private Color hoverColor;

private Cursor oldCursor;

private ActionListener linkListener;
private boolean hoverMode;
private boolean isClickable;


public LinkLabel(String text, ActionListener linkListener) {
super(text);
this.linkListener = linkListener;
linkColor = Color.BLACK;
hoverColor = Color.BLUE;

setForeground(linkColor);

addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
setHoverMode(true);
}


public void mouseExited(MouseEvent e) {
setHoverMode(false);
}


public void mouseReleased(MouseEvent e) {
activateLink();
}
});

this.isClickable = linkListener != null;
updateColorsFromUI();
if (isClickable) {
addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
setHoverMode(true);
}
public void mouseExited(MouseEvent e) {
setHoverMode(false);
}
public void mouseReleased(MouseEvent e) {
activateLink();
}
});
}
setFont(Fonts.getMediumDialogFont().deriveFont(Font.BOLD, 14f));
}


public void setLinkColor(Color color) {
linkColor = color;
if (!hoverMode) {
setForeground(linkColor);
}
}


Expand All @@ -70,11 +66,13 @@ public void setHoverColor(Color color) {

private void setHoverMode(boolean b) {
if (b && isEnabled()) {
hoverMode = true;
setForeground(hoverColor);
oldCursor = getCursor();
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
else {
hoverMode = false;
setForeground(linkColor);
if (oldCursor != null) {
setCursor(oldCursor);
Expand All @@ -89,4 +87,38 @@ private void activateLink() {
linkListener.actionPerformed(new ActionEvent(this, 0, getText()));
}
}

@Override
public void updateUI() {
super.updateUI();
updateColorsFromUI();
}

private void updateColorsFromUI() {
if (isClickable) {
Color uiLink = UIManager.getColor("Link.foreground");
Color uiHover = UIManager.getColor("Link.hoverForeground");
// Theme-aware fallback colors
if (uiLink == null) {
uiLink = ThemeManager.isDarkTheme() ?
new Color(0x80, 0x70, 0xFF) : new Color(0x00, 0x64, 0xC8); // Dark blue for light theme
}
if (uiHover == null) {
uiHover = ThemeManager.isDarkTheme() ?
uiLink.brighter() : uiLink.darker();
}
linkColor = uiLink;
hoverColor = uiHover;
if (!hoverMode) {
setForeground(linkColor);
}
} else {
// Use label foreground for non-clickable labels
Color labelColor = UIManager.getColor("Label.foreground");
if (labelColor == null) {
labelColor = ThemeManager.isDarkTheme() ? Color.WHITE : Color.BLACK;
}
setForeground(labelColor);
}
}
}
Loading