Skip to content

Commit

Permalink
Closes #418
Browse files Browse the repository at this point in the history
Paint the section headers darker if high contrast is set to on
  • Loading branch information
matthewhorridge committed May 11, 2016
1 parent 66505c5 commit 42eb57e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.protege.editor.core.ui.list;

import org.protege.editor.core.ui.util.UIUtil;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
Expand All @@ -25,6 +27,10 @@ public class MList extends JList {

private static final int BUTTON_MARGIN = 2;

private static final Color FRAME_SECTION_HEADER_FOREGROUND = Color.GRAY;

private static final Color FRAME_SECTION_HEADER_HIGH_CONTRAST_FOREGROUND = new Color(40, 40, 40);

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

private static final Color itemBackgroundColor = Color.WHITE;
Expand Down Expand Up @@ -433,15 +439,24 @@ private void paintSectionHeader(Graphics2D g2, int index, Rectangle rowBounds, i
g2.setColor(this.getSelectionForeground());
}
else {
g2.setColor(Color.GRAY);
g2.setColor(getSectionHeaderForeground());
}
int baseLine = rowBounds.y + (getButtonDimension() + BUTTON_MARGIN - g2.getFontMetrics().getHeight()) / 2 + g2.getFontMetrics().getAscent();
Font oldFont = g2.getFont();
g2.setFont(getSectionHeaderFont());
g2.drawString(header.getName(), 5, baseLine);
g2.setFont(oldFont);
}


private Color getSectionHeaderForeground() {
if(UIUtil.isHighContrastOn()) {
return FRAME_SECTION_HEADER_HIGH_CONTRAST_FOREGROUND;
}
else {
return FRAME_SECTION_HEADER_FOREGROUND;
}
}

private Font getSectionHeaderFont() {
Font font = getFont();
if(font != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.protege.editor.core.ui.tabbedpane;

import org.protege.editor.core.ui.util.UIUtil;

import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
Expand Down Expand Up @@ -113,14 +115,9 @@ protected void installDefaults() {
}
}

private boolean isHighContrast() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Optional<Boolean> highContrast = Optional.ofNullable((Boolean)toolkit.getDesktopProperty( "win.highContrast.on" ));
return highContrast.orElse(false);
}

private Color getTextColor() {
if(isHighContrast()) {
if(UIUtil.isHighContrastOn()) {
return HIGH_CONTRAST_TEXT_COLOR;
}
else {
Expand Down Expand Up @@ -383,7 +380,7 @@ protected void paintContentBorderTopEdge(Graphics g, int tabPlacement, int selec
}

private Color getTabBorderColor() {
if(isHighContrast()) {
if(UIUtil.isHighContrastOn()) {
return HIGH_CONTRAST_TAB_BORDER_COLOR;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;
import java.util.Set;


Expand Down Expand Up @@ -261,4 +262,15 @@ public static boolean isLocalFile(URI uri) {
return scheme != null && FILE_URI_SCHEME.equals(scheme.toLowerCase());
}

/**
* Determines whether the user is on Windows and if so whether the "high contrast" setting
* is set to on.
* @return {@code true} if on, otherwise {@code false}
*/
public static boolean isHighContrastOn() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Optional<Boolean> highContrast = Optional.ofNullable((Boolean)toolkit.getDesktopProperty( "win.highContrast.on" ));
return highContrast.orElse(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,9 @@ public void mouseDragged(MouseEvent e) {
createPopupMenu();

inferredRowButtons = new ArrayList<>();
inferredRowButtons.add(new ExplainButton(e -> {
invokeExplanationHandler();
}));
inferredRowButtons.add(new ExplainButton(e -> invokeExplanationHandler()));

axiomAnnotationButton = new AxiomAnnotationButton(event -> {
invokeAxiomAnnotationHandler();
});
axiomAnnotationButton = new AxiomAnnotationButton(event -> invokeAxiomAnnotationHandler());

changeListenerMediator = new ChangeListenerMediator();
addListSelectionListener(selListener);
Expand Down

0 comments on commit 42eb57e

Please sign in to comment.