コード例 #1
0
  private static void patchGtkDefaults(UIDefaults defaults) {
    if (!UIUtil.isUnderGTKLookAndFeel()) return;

    Map<String, Icon> map =
        ContainerUtil.newHashMap(
            Arrays.asList(
                "OptionPane.errorIcon",
                "OptionPane.informationIcon",
                "OptionPane.warningIcon",
                "OptionPane.questionIcon"),
            Arrays.asList(
                AllIcons.General.ErrorDialog,
                AllIcons.General.InformationDialog,
                AllIcons.General.WarningDialog,
                AllIcons.General.QuestionDialog));
    // GTK+ L&F keeps icons hidden in style
    SynthStyle style = SynthLookAndFeel.getStyle(new JOptionPane(""), Region.DESKTOP_ICON);
    for (String key : map.keySet()) {
      if (defaults.get(key) != null) continue;

      Object icon = style == null ? null : style.get(null, key);
      defaults.put(key, icon instanceof Icon ? icon : map.get(key));
    }

    Color fg = defaults.getColor("Label.foreground");
    Color bg = defaults.getColor("Label.background");
    if (fg != null && bg != null) {
      defaults.put("Label.disabledForeground", UIUtil.mix(fg, bg, 0.5));
    }
  }
コード例 #2
0
 private static void fixMenuIssues(UIDefaults uiDefaults) {
   if (UIUtil.isUnderAquaLookAndFeel()) {
     // update ui for popup menu to get round corners
     uiDefaults.put("PopupMenuUI", MacPopupMenuUI.class.getCanonicalName());
     uiDefaults.put("Menu.invertedArrowIcon", getAquaMenuInvertedIcon());
     uiDefaults.put("Menu.disabledArrowIcon", getAquaMenuDisabledIcon());
   } else if (UIUtil.isUnderJGoodiesLookAndFeel()) {
     uiDefaults.put("Menu.opaque", true);
     uiDefaults.put("MenuItem.opaque", true);
   }
   uiDefaults.put("MenuItem.background", UIManager.getColor("Menu.background"));
 }
コード例 #3
0
 private static void fixTreeWideSelection(UIDefaults uiDefaults) {
   if (UIUtil.isUnderAlloyIDEALookAndFeel() || UIUtil.isUnderJGoodiesLookAndFeel()) {
     final Color bg = new ColorUIResource(56, 117, 215);
     final Color fg = new ColorUIResource(255, 255, 255);
     uiDefaults.put("info", bg);
     uiDefaults.put("textHighlight", bg);
     for (String key : ourAlloyComponentsToPatchSelection) {
       uiDefaults.put(key + ".selectionBackground", bg);
       uiDefaults.put(key + ".selectionForeground", fg);
     }
   }
 }
コード例 #4
0
  @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();
  }
コード例 #5
0
  /**
   * Updates LAF of all windows. The method also updates font of components as it's configured in
   * <code>UISettings</code>.
   */
  @Override
  public void updateUI() {
    final UIDefaults uiDefaults = UIManager.getLookAndFeelDefaults();

    fixPopupWeight();

    fixGtkPopupStyle();

    fixTreeWideSelection(uiDefaults);

    fixMenuIssues(uiDefaults);

    if (UIUtil.isUnderAquaLookAndFeel()) {
      uiDefaults.put("Panel.opaque", Boolean.TRUE);
    } else if (UIUtil.isWinLafOnVista()) {
      uiDefaults.put("ComboBox.border", null);
    }

    initInputMapDefaults(uiDefaults);

    uiDefaults.put("Button.defaultButtonFollowsFocus", Boolean.FALSE);

    patchFileChooserStrings(uiDefaults);

    patchLafFonts(uiDefaults);

    patchHiDPI(uiDefaults);

    patchGtkDefaults(uiDefaults);

    fixSeparatorColor(uiDefaults);

    updateToolWindows();

    for (Frame frame : Frame.getFrames()) {
      // OSX/Aqua fix: Some image caching components like ToolWindowHeader use
      // com.apple.laf.AquaNativeResources$CColorPaintUIResource
      // a Java wrapper for ObjC MagicBackgroundColor class (Java RGB values ignored).
      // MagicBackgroundColor always reports current Frame background.
      // So we need to set frames background to exact and correct value.
      if (SystemInfo.isMac) {
        //noinspection UseJBColor
        frame.setBackground(new Color(UIUtil.getPanelBackground().getRGB()));
      }

      updateUI(frame);
    }
    fireLookAndFeelChanged();
  }
コード例 #6
0
  @SuppressWarnings({"HardCodedStringLiteral"})
  static void initFontDefaults(UIDefaults defaults, int fontSize, FontUIResource uiFont) {
    defaults.put("Tree.ancestorInputMap", null);
    FontUIResource textFont = new FontUIResource("Serif", Font.PLAIN, fontSize);
    FontUIResource monoFont = new FontUIResource("Monospaced", Font.PLAIN, fontSize);

    for (String fontResource : ourPatchableFontResources) {
      defaults.put(fontResource, uiFont);
    }

    defaults.put("PasswordField.font", monoFont);
    defaults.put("TextArea.font", monoFont);
    defaults.put("TextPane.font", textFont);
    defaults.put("EditorPane.font", textFont);
  }
コード例 #7
0
  private static void patchHiDPI(UIDefaults defaults) {
    if (!JBUI.isHiDPI()) return;

    List<String> myIntKeys = Arrays.asList("Tree.leftChildIndent", "Tree.rightChildIndent");
    List<String> patched = new ArrayList<String>();
    for (Map.Entry<Object, Object> entry : defaults.entrySet()) {
      Object value = entry.getValue();
      String key = entry.getKey().toString();
      if (value instanceof DimensionUIResource) {
        entry.setValue(JBUI.size((DimensionUIResource) value).asUIResource());
      } else if (value instanceof InsetsUIResource) {
        entry.setValue(JBUI.insets(((InsetsUIResource) value)).asUIResource());
      } else if (value instanceof Integer) {
        if (key.endsWith(".maxGutterIconWidth") || myIntKeys.contains(key)) {
          if (!"true".equals(defaults.get(key + ".hidpi.patched"))) {
            entry.setValue(Integer.valueOf(JBUI.scale((Integer) value)));
            patched.add(key);
          }
        }
      }
    }
    for (String key : patched) {
      defaults.put(key + ".hidpi.patched", "true");
    }
  }
コード例 #8
0
 private static void patchFileChooserStrings(final UIDefaults defaults) {
   if (!defaults.containsKey(ourFileChooserTextKeys[0])) {
     // Alloy L&F does not define strings for names of context menu actions, so we have to patch
     // them in here
     for (String key : ourFileChooserTextKeys) {
       defaults.put(key, IdeBundle.message(key));
     }
   }
 }
コード例 #9
0
 private void restoreOriginalFontDefaults(UIDefaults defaults) {
   UIManager.LookAndFeelInfo lf = getCurrentLookAndFeel();
   HashMap<String, Object> lfDefaults = myStoredDefaults.get(lf);
   if (lfDefaults != null) {
     for (String resource : ourPatchableFontResources) {
       defaults.put(resource, lfDefaults.get(resource));
     }
   }
   JBUI.setScaleFactor(JBUI.Fonts.label().getSize() / 12f);
 }
コード例 #10
0
  @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);
    }
  }
コード例 #11
0
 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));
   }
 }
コード例 #12
0
 @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);
   }
 }
コード例 #13
0
 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);
   }
 }
コード例 #14
0
 private static void fixSeparatorColor(UIDefaults uiDefaults) {
   if (UIUtil.isUnderAquaLookAndFeel()) {
     uiDefaults.put("Separator.background", UIUtil.AQUA_SEPARATOR_BACKGROUND_COLOR);
     uiDefaults.put("Separator.foreground", UIUtil.AQUA_SEPARATOR_FOREGROUND_COLOR);
   }
 }
コード例 #15
0
 @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"
           }));
 }
コード例 #16
0
 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"));
 }