Skip to content

Commit

Permalink
Merge branch 'feature/default-button'
Browse files Browse the repository at this point in the history
  • Loading branch information
Revivius committed Jan 30, 2016
2 parents bcf85c8 + 1eee4e0 commit aa46792
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions src/main/java/com/revivius/nb/darcula/DarculaLFCustoms.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.KeyEvent;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
Expand All @@ -15,6 +16,8 @@
import java.util.prefs.Preferences;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.InputMap;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.border.MatteBorder;
import javax.swing.plaf.ColorUIResource;
Expand Down Expand Up @@ -244,9 +247,10 @@ public Object[] createLookAndFeelCustomizationKeysAndValues() {

"Tree.font", controlFont,
"Viewport.font", controlFont,

};

removeEnterFromTreeInputMap();

replaceSearchNotFoundColor();
replaceGlyphGutterLineColor();
replaceFormDesignerGapBorderColors();
Expand Down Expand Up @@ -438,9 +442,9 @@ ERROR_FOREGROUND, new Color(255, 102, 102),
"textHighlight", new Color(240, 119, 70),

};
if (NbPreferences.forModule(DarculaLAFPanel.class).getBoolean("invertIcons", false)) {
result = appendToArray(result, "nb.imageicon.filter", new DarkIconFilter());
}

result = maybeEnableIconFilter(result);

return result;
}

Expand Down Expand Up @@ -509,6 +513,36 @@ PROPSHEET_DISABLED_FOREGROUND, new Color(161, 161, 146),
}
}

/**
* Enables invert filter for icons if user requested.
*/
private Object[] maybeEnableIconFilter(Object[] defaults) {
if (NbPreferences.forModule(DarculaLAFPanel.class).getBoolean("invertIcons", false)) {
return appendToArray(defaults, "nb.imageicon.filter", new DarkIconFilter());
}
return defaults;
}

private Object[] appendToArray(Object[] result, final String key, final Object value) {
result = Arrays.copyOf(result, result.length + 2);
result[result.length - 2] = key;
result[result.length - 1] = value;
return result;
}

/**
* DarculaLaf:L354-L358 registers ENTER to invoke 'toggle' action. This seems
* to cause problems as reported in #14 because enter key can not invoke
* default button in dialogs.
*/
private void removeEnterFromTreeInputMap() {
// Make ENTER work in JTrees
InputMap treeInputMap = (InputMap) UIManager.get("Tree.focusInputMap");
if (treeInputMap != null) { // it's really possible. For example, GTK+ doesn't have such map
treeInputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
}
}

/**
* NOT_FOUND color is hardcoded, should be taken from UIManager.
* Use reflection as in DefaultOutlineCellRenderer.
Expand Down Expand Up @@ -645,12 +679,5 @@ private void replaceFieldValue(Class<?> clazz, String fieldName, Object value) {
"Can not replace field...", ex);
}
}

private Object[] appendToArray(Object[] result, final String key, final Object value) {
result = Arrays.copyOf(result, result.length + 2);
result[result.length - 2] = key;
result[result.length - 1] = value;
return result;
}


}

0 comments on commit aa46792

Please sign in to comment.