@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();
  }
 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);
   }
 }
 protected void initGeneralDefaults(UIDefaults table) {
   Object[] uiDefaults;
   uiDefaults =
       new Object[] {
         "ClassLoader", getClass().getClassLoader(),
       };
   table.putDefaults(uiDefaults);
 }
  @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);
   }
 }
  /**
   * Initialize the uiClassID to BasicComponentUI mapping. The JComponent classes define their own
   * uiClassID constants (see AbstractComponent.getUIClassID). This table must map those constants
   * to a BasicComponentUI class of the appropriate type.
   *
   * @see #getDefaults
   */
  @Override
  protected void initClassDefaults(UIDefaults table) {
    String basicPrefix = "javax.swing.plaf.basic.Basic";
    String quaquaPrefix = "ch.randelshofer.quaqua.Quaqua";
    String quaquaPantherPrefix = "ch.randelshofer.quaqua.panther.QuaquaPanther";

    // NOTE: Uncomment parts of the code below, to override additional
    // UI classes of the target look and feel.
    Object[] uiDefaults = {
      "BrowserUI", quaquaPrefix + "BrowserUI",
      "FileChooserUI", quaquaPantherPrefix + "FileChooserUI",
    };
    table.putDefaults(uiDefaults);
  }
  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);
  }
Beispiel #9
0
  /**
   * Add this theme's custom entries to the defaults table.
   *
   * @param table the defaults table, non-null
   * @throws NullPointerException if {@code table} is {@code null}
   */
  public void addCustomEntriesToTable(UIDefaults table) {
    UIDefaults.LazyValue focusBorder =
        t -> new BorderUIResource.LineBorderUIResource(getPrimary1());
    // .30 0 DDE8F3 white secondary2
    java.util.List<?> buttonGradient =
        Arrays.asList(
            new Object[] {
              Float.valueOf(.3f),
              Float.valueOf(0f),
              new ColorUIResource(0xDDE8F3),
              getWhite(),
              getSecondary2()
            });

    // Other possible properties that aren't defined:
    //
    // Used when generating the disabled Icons, provides the region to
    // constrain grays to.
    // Button.disabledGrayRange -> Object[] of Integers giving min/max
    // InternalFrame.inactiveTitleGradient -> Gradient when the
    //   internal frame is inactive.
    Color cccccc = new ColorUIResource(0xCCCCCC);
    Color dadada = new ColorUIResource(0xDADADA);
    Color c8ddf2 = new ColorUIResource(0xC8DDF2);
    Object directoryIcon = getIconResource("icons/ocean/directory.gif");
    Object fileIcon = getIconResource("icons/ocean/file.gif");
    java.util.List<?> sliderGradient =
        Arrays.asList(
            new Object[] {
              Float.valueOf(.3f),
              Float.valueOf(.2f),
              c8ddf2,
              getWhite(),
              new ColorUIResource(SECONDARY2)
            });

    Object[] defaults =
        new Object[] {
          "Button.gradient",
          buttonGradient,
          "Button.rollover",
          Boolean.TRUE,
          "Button.toolBarBorderBackground",
          INACTIVE_CONTROL_TEXT_COLOR,
          "Button.disabledToolBarBorderBackground",
          cccccc,
          "Button.rolloverIconType",
          "ocean",
          "CheckBox.rollover",
          Boolean.TRUE,
          "CheckBox.gradient",
          buttonGradient,
          "CheckBoxMenuItem.gradient",
          buttonGradient,

          // home2
          "FileChooser.homeFolderIcon",
          getIconResource("icons/ocean/homeFolder.gif"),
          // directory2
          "FileChooser.newFolderIcon",
          getIconResource("icons/ocean/newFolder.gif"),
          // updir2
          "FileChooser.upFolderIcon",
          getIconResource("icons/ocean/upFolder.gif"),

          // computer2
          "FileView.computerIcon",
          getIconResource("icons/ocean/computer.gif"),
          "FileView.directoryIcon",
          directoryIcon,
          // disk2
          "FileView.hardDriveIcon",
          getIconResource("icons/ocean/hardDrive.gif"),
          "FileView.fileIcon",
          fileIcon,
          // floppy2
          "FileView.floppyDriveIcon",
          getIconResource("icons/ocean/floppy.gif"),
          "Label.disabledForeground",
          getInactiveControlTextColor(),
          "Menu.opaque",
          Boolean.FALSE,
          "MenuBar.gradient",
          Arrays.asList(
              new Object[] {
                Float.valueOf(1f),
                Float.valueOf(0f),
                getWhite(),
                dadada,
                new ColorUIResource(dadada)
              }),
          "MenuBar.borderColor",
          cccccc,
          "InternalFrame.activeTitleGradient",
          buttonGradient,
          // close2
          "InternalFrame.closeIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new IFIcon(
                  getHastenedIcon("icons/ocean/close.gif", table),
                  getHastenedIcon("icons/ocean/close-pressed.gif", table));
            }
          },
          // minimize
          "InternalFrame.iconifyIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new IFIcon(
                  getHastenedIcon("icons/ocean/iconify.gif", table),
                  getHastenedIcon("icons/ocean/iconify-pressed.gif", table));
            }
          },
          // restore
          "InternalFrame.minimizeIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new IFIcon(
                  getHastenedIcon("icons/ocean/minimize.gif", table),
                  getHastenedIcon("icons/ocean/minimize-pressed.gif", table));
            }
          },
          // menubutton3
          "InternalFrame.icon",
          getIconResource("icons/ocean/menu.gif"),
          // maximize2
          "InternalFrame.maximizeIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new IFIcon(
                  getHastenedIcon("icons/ocean/maximize.gif", table),
                  getHastenedIcon("icons/ocean/maximize-pressed.gif", table));
            }
          },
          // paletteclose
          "InternalFrame.paletteCloseIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new IFIcon(
                  getHastenedIcon("icons/ocean/paletteClose.gif", table),
                  getHastenedIcon("icons/ocean/paletteClose-pressed.gif", table));
            }
          },
          "List.focusCellHighlightBorder",
          focusBorder,
          "MenuBarUI",
          "javax.swing.plaf.metal.MetalMenuBarUI",
          "OptionPane.errorIcon",
          getIconResource("icons/ocean/error.png"),
          "OptionPane.informationIcon",
          getIconResource("icons/ocean/info.png"),
          "OptionPane.questionIcon",
          getIconResource("icons/ocean/question.png"),
          "OptionPane.warningIcon",
          getIconResource("icons/ocean/warning.png"),
          "RadioButton.gradient",
          buttonGradient,
          "RadioButton.rollover",
          Boolean.TRUE,
          "RadioButtonMenuItem.gradient",
          buttonGradient,
          "ScrollBar.gradient",
          buttonGradient,
          "Slider.altTrackColor",
          new ColorUIResource(0xD2E2EF),
          "Slider.gradient",
          sliderGradient,
          "Slider.focusGradient",
          sliderGradient,
          "SplitPane.oneTouchButtonsOpaque",
          Boolean.FALSE,
          "SplitPane.dividerFocusColor",
          c8ddf2,
          "TabbedPane.borderHightlightColor",
          getPrimary1(),
          "TabbedPane.contentAreaColor",
          c8ddf2,
          "TabbedPane.contentBorderInsets",
          new Insets(4, 2, 3, 3),
          "TabbedPane.selected",
          c8ddf2,
          "TabbedPane.tabAreaBackground",
          dadada,
          "TabbedPane.tabAreaInsets",
          new Insets(2, 2, 0, 6),
          "TabbedPane.unselectedBackground",
          SECONDARY3,
          "Table.focusCellHighlightBorder",
          focusBorder,
          "Table.gridColor",
          SECONDARY1,
          "TableHeader.focusCellBackground",
          c8ddf2,
          "ToggleButton.gradient",
          buttonGradient,
          "ToolBar.borderColor",
          cccccc,
          "ToolBar.isRollover",
          Boolean.TRUE,
          "Tree.closedIcon",
          directoryIcon,
          "Tree.collapsedIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new COIcon(
                  getHastenedIcon("icons/ocean/collapsed.gif", table),
                  getHastenedIcon("icons/ocean/collapsed-rtl.gif", table));
            }
          },
          "Tree.expandedIcon",
          getIconResource("icons/ocean/expanded.gif"),
          "Tree.leafIcon",
          fileIcon,
          "Tree.openIcon",
          directoryIcon,
          "Tree.selectionBorderColor",
          getPrimary1(),
          "Tree.dropLineColor",
          getPrimary1(),
          "Table.dropLineColor",
          getPrimary1(),
          "Table.dropLineShortColor",
          OCEAN_BLACK,
          "Table.dropCellBackground",
          OCEAN_DROP,
          "Tree.dropCellBackground",
          OCEAN_DROP,
          "List.dropCellBackground",
          OCEAN_DROP,
          "List.dropLineColor",
          getPrimary1()
        };
    table.putDefaults(defaults);
  }
  @Override
  protected void initComponentDefaults(UIDefaults table) {
    String prefValue;
    // True if file choosers orders by type
    boolean isOrderFilesByType = false;
    // True if file choosers shows all files by default
    prefValue =
        OSXPreferences.getString( //
                OSXPreferences.FINDER_PREFERENCES, "AppleShowAllFiles", "false") //
            .toLowerCase();
    boolean isFileHidingEnabled = prefValue.equals("false") || prefValue.equals("no");
    boolean isQuickLookEnabled =
        Boolean.valueOf(QuaquaManager.getProperty("Quaqua.FileChooser.quickLookEnabled", "true"));

    Font smallSystemFont = SMALL_SYSTEM_FONT;
    Color grayedFocusCellBorderColor = (Color) table.get("listHighlight");

    Object[] uiDefaults = {
      "Browser.expandedIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 0}),
      "Browser.expandingIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 1}),
      "Browser.focusedSelectedExpandedIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 2}),
      "Browser.focusedSelectedExpandingIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 3}),
      "Browser.selectedExpandedIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 4}),
      "Browser.selectedExpandingIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 5}),
      //
      "Browser.selectionBackground",
      new ColorUIResource(56, 117, 215),
      "Browser.selectionForeground",
      new ColorUIResource(255, 255, 255),
      "Browser.inactiveSelectionBackground",
      new ColorUIResource(208, 208, 208),
      "Browser.inactiveSelectionForeground",
      new ColorUIResource(0, 0, 0),
      "Browser.sizeHandleIcon",
      makeIcon(getClass(), commonDir + "Browser.sizeHandleIcon.png"),
      "FileChooser.homeFolderIcon",
      LookAndFeel.makeIcon(getClass(), commonDir + "FileChooser.homeFolderIcon.png"),
      //
      "FileView.computerIcon",
      LookAndFeel.makeIcon(getClass(), commonDir + "FileView.computerIcon.png"),
      //
      "FileChooser.fileHidingEnabled",
      isFileHidingEnabled,
      "FileChooser.quickLookEnabled",
      isQuickLookEnabled,
      "FileChooser.orderByType",
      isOrderFilesByType,
      "FileChooser.previewLabelForeground",
      new ColorUIResource(0x000000),
      "FileChooser.previewValueForeground",
      new ColorUIResource(0x000000),
      "FileChooser.previewLabelFont",
      smallSystemFont,
      "FileChooser.previewValueFont",
      smallSystemFont,
      "FileChooser.splitPaneDividerSize",
      6,
      "FileChooser.previewLabelInsets",
      new InsetsUIResource(0, 0, 0, 4),
      "FileChooser.cellTipOrigin",
      new Point(18, 1),
      "FileChooser.autovalidate",
      Boolean.TRUE,
      "FileChooser.browserFocusCellHighlightBorder",
      new UIDefaults.ProxyLazyValue(
          "javax.swing.plaf.BorderUIResource$EmptyBorderUIResource",
          new Object[] {new Insets(1, 1, 1, 1)}),
      "FileChooser.browserFocusCellHighlightBorderGrayed",
      new UIDefaults.ProxyLazyValue(
          "javax.swing.plaf.BorderUIResource$MatteBorderUIResource",
          new Object[] {1, 1, 1, 1, grayedFocusCellBorderColor}),
      "FileChooser.browserCellBorder",
      new UIDefaults.ProxyLazyValue(
          "javax.swing.plaf.BorderUIResource$EmptyBorderUIResource",
          new Object[] {new Insets(1, 1, 1, 1)}),
      "FileChooser.browserUseUnselectedExpandIconForLabeledFile",
      Boolean.TRUE,
      "Sheet.showAsSheet",
      Boolean.TRUE,
    };
    table.putDefaults(uiDefaults);
  }
 @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"));
 }