@Override
  public UIDefaults getDefaults() {
    try {
      final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
      superMethod.setAccessible(true);
      final UIDefaults metalDefaults = (UIDefaults) superMethod.invoke(new MetalLookAndFeel());

      final UIDefaults defaults = (UIDefaults) superMethod.invoke(base);
      if (SystemInfo.isLinux) {
        if (!Registry.is("darcula.use.native.fonts.on.linux")) {
          Font font = findFont("DejaVu Sans");
          if (font != null) {
            for (Object key : defaults.keySet()) {
              if (key instanceof String && ((String) key).endsWith(".font")) {
                defaults.put(key, new FontUIResource(font.deriveFont(13f)));
              }
            }
          }
        } else if (Arrays.asList("CN", "JP", "KR", "TW")
            .contains(Locale.getDefault().getCountry())) {
          for (Object key : defaults.keySet()) {
            if (key instanceof String && ((String) key).endsWith(".font")) {
              final Font font = defaults.getFont(key);
              if (font != null) {
                defaults.put(key, new FontUIResource("Dialog", font.getStyle(), font.getSize()));
              }
            }
          }
        }
      }

      LafManagerImpl.initInputMapDefaults(defaults);
      initIdeaDefaults(defaults);
      patchStyledEditorKit(defaults);
      patchComboBox(metalDefaults, defaults);
      defaults.remove("Spinner.arrowButtonBorder");
      defaults.put("Spinner.arrowButtonSize", JBUI.size(16, 5).asUIResource());
      MetalLookAndFeel.setCurrentTheme(createMetalTheme());
      if (SystemInfo.isWindows && Registry.is("ide.win.frame.decoration")) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
      }
      if (SystemInfo.isLinux && JBUI.isHiDPI()) {
        applySystemFonts(defaults);
      }
      defaults.put("EditorPane.font", defaults.getFont("TextField.font"));
      return defaults;
    } catch (Exception e) {
      log(e);
    }
    return super.getDefaults();
  }
  @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
  protected void loadDefaults(UIDefaults defaults) {
    final Properties properties = new Properties();
    final String osSuffix = SystemInfo.isMac ? "mac" : SystemInfo.isWindows ? "windows" : "linux";
    try {
      InputStream stream = getClass().getResourceAsStream(getPrefix() + ".properties");
      properties.load(stream);
      stream.close();

      stream = getClass().getResourceAsStream(getPrefix() + "_" + osSuffix + ".properties");
      properties.load(stream);
      stream.close();

      HashMap<String, Object> darculaGlobalSettings = new HashMap<String, Object>();
      final String prefix = getPrefix() + ".";
      for (String key : properties.stringPropertyNames()) {
        if (key.startsWith(prefix)) {
          darculaGlobalSettings.put(
              key.substring(prefix.length()), parseValue(key, properties.getProperty(key)));
        }
      }

      for (Object key : defaults.keySet()) {
        if (key instanceof String && ((String) key).contains(".")) {
          final String s = (String) key;
          final String darculaKey = s.substring(s.lastIndexOf('.') + 1);
          if (darculaGlobalSettings.containsKey(darculaKey)) {
            defaults.put(key, darculaGlobalSettings.get(darculaKey));
          }
        }
      }

      for (String key : properties.stringPropertyNames()) {
        final String value = properties.getProperty(key);
        defaults.put(key, parseValue(key, value));
      }
    } catch (IOException e) {
      log(e);
    }
  }
 protected void initResourceBundle(UIDefaults table) {
   // The following line of code does not work, when Quaqua has been loaded with
   // a custom class loader. That's why, we have to inject the labels
   // by ourselves:
   // table.addResourceBundle( "ch.randelshofer.quaqua.Labels" );
   ResourceBundle bundle =
       ResourceBundle.getBundle(
           "ch.randelshofer.quaqua.Labels", Locale.getDefault(), getClass().getClassLoader());
   for (Enumeration i = bundle.getKeys(); i.hasMoreElements(); ) {
     String key = (String) i.nextElement();
     table.put(key, bundle.getObject(key));
   }
 }
 @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
 private void patchStyledEditorKit(UIDefaults defaults) {
   URL url = getClass().getResource(getPrefix() + (JBUI.isHiDPI() ? "@2x.css" : ".css"));
   StyleSheet styleSheet = UIUtil.loadStyleSheet(url);
   defaults.put("StyledEditorKit.JBDefaultStyle", styleSheet);
   try {
     Field keyField = HTMLEditorKit.class.getDeclaredField("DEFAULT_STYLES_KEY");
     keyField.setAccessible(true);
     AppContext.getAppContext().put(keyField.get(null), UIUtil.loadStyleSheet(url));
   } catch (Exception e) {
     log(e);
   }
 }
 private static void applySystemFonts(UIDefaults defaults) {
   try {
     String fqn = UIUtil.getSystemLookAndFeelClassName();
     Object systemLookAndFeel = Class.forName(fqn).newInstance();
     final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
     superMethod.setAccessible(true);
     final UIDefaults systemDefaults = (UIDefaults) superMethod.invoke(systemLookAndFeel);
     for (Map.Entry<Object, Object> entry : systemDefaults.entrySet()) {
       if (entry.getValue() instanceof Font) {
         defaults.put(entry.getKey(), entry.getValue());
       }
     }
   } catch (Exception e) {
     log(e);
   }
 }
Example #6
0
  public void addCustomEntriesToTable(UIDefaults table) {

    Border blackLineBorder = new BorderUIResource(new LineBorder(getBlack()));
    Border whiteLineBorder = new BorderUIResource(new LineBorder(getWhite()));

    Object textBorder =
        new BorderUIResource(new CompoundBorder(blackLineBorder, new BasicBorders.MarginBorder()));

    table.put("ToolTip.border", blackLineBorder);
    table.put("TitledBorder.border", blackLineBorder);
    table.put("Table.focusCellHighlightBorder", whiteLineBorder);
    table.put("Table.focusCellForeground", getWhite());

    table.put("TextField.border", textBorder);
    table.put("PasswordField.border", textBorder);
    table.put("TextArea.border", textBorder);
    table.put("TextPane.font", textBorder);
  }
 @SuppressWarnings({"HardCodedStringLiteral"})
 protected void initIdeaDefaults(UIDefaults defaults) {
   loadDefaults(defaults);
   defaults.put(
       "Table.ancestorInputMap",
       new UIDefaults.LazyInputMap(
           new Object[] {
             "ctrl C", "copy",
             "meta C", "copy",
             "ctrl V", "paste",
             "meta V", "paste",
             "ctrl X", "cut",
             "meta X", "cut",
             "COPY", "copy",
             "PASTE", "paste",
             "CUT", "cut",
             "control INSERT", "copy",
             "shift INSERT", "paste",
             "shift DELETE", "cut",
             "RIGHT", "selectNextColumn",
             "KP_RIGHT", "selectNextColumn",
             "LEFT", "selectPreviousColumn",
             "KP_LEFT", "selectPreviousColumn",
             "DOWN", "selectNextRow",
             "KP_DOWN", "selectNextRow",
             "UP", "selectPreviousRow",
             "KP_UP", "selectPreviousRow",
             "shift RIGHT", "selectNextColumnExtendSelection",
             "shift KP_RIGHT", "selectNextColumnExtendSelection",
             "shift LEFT", "selectPreviousColumnExtendSelection",
             "shift KP_LEFT", "selectPreviousColumnExtendSelection",
             "shift DOWN", "selectNextRowExtendSelection",
             "shift KP_DOWN", "selectNextRowExtendSelection",
             "shift UP", "selectPreviousRowExtendSelection",
             "shift KP_UP", "selectPreviousRowExtendSelection",
             "PAGE_UP", "scrollUpChangeSelection",
             "PAGE_DOWN", "scrollDownChangeSelection",
             "HOME", "selectFirstColumn",
             "END", "selectLastColumn",
             "shift PAGE_UP", "scrollUpExtendSelection",
             "shift PAGE_DOWN", "scrollDownExtendSelection",
             "shift HOME", "selectFirstColumnExtendSelection",
             "shift END", "selectLastColumnExtendSelection",
             "ctrl PAGE_UP", "scrollLeftChangeSelection",
             "ctrl PAGE_DOWN", "scrollRightChangeSelection",
             "ctrl HOME", "selectFirstRow",
             "ctrl END", "selectLastRow",
             "ctrl shift PAGE_UP", "scrollRightExtendSelection",
             "ctrl shift PAGE_DOWN", "scrollLeftExtendSelection",
             "ctrl shift HOME", "selectFirstRowExtendSelection",
             "ctrl shift END", "selectLastRowExtendSelection",
             "TAB", "selectNextColumnCell",
             "shift TAB", "selectPreviousColumnCell",
             // "ENTER", "selectNextRowCell",
             "shift ENTER", "selectPreviousRowCell",
             "ctrl A", "selectAll",
             "meta A", "selectAll",
             "ESCAPE", "cancel",
             "F2", "startEditing"
           }));
 }
 private static void patchComboBox(UIDefaults metalDefaults, UIDefaults defaults) {
   defaults.remove("ComboBox.ancestorInputMap");
   defaults.remove("ComboBox.actionMap");
   defaults.put("ComboBox.ancestorInputMap", metalDefaults.get("ComboBox.ancestorInputMap"));
   defaults.put("ComboBox.actionMap", metalDefaults.get("ComboBox.actionMap"));
 }