Java Code Examples for com.intellij.openapi.util.SystemInfo#isJetBrainsJvm()

The following examples show how to use com.intellij.openapi.util.SystemInfo#isJetBrainsJvm() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MouseShortcutPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
MouseShortcutPanel(boolean allowDoubleClick) {
  super(new BorderLayout());
  myClickCount = allowDoubleClick ? 2 : 1;
  addMouseListener(myMouseListener);
  addMouseWheelListener(myMouseListener);
  if (SystemInfo.isMacIntel64 && SystemInfo.isJetBrainsJvm && Registry.is("ide.mac.forceTouch")) {
    new MacGestureSupportForMouseShortcutPanel(this, () -> myMouseShortcut = null);
  }
  setBackground(BACKGROUND);
  setOpaque(true);
}
 
Example 2
Source File: OwnerOptional.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static OwnerOptional fromComponent(Component parentComponent) {
  Window owner = findOwnerByComponent(parentComponent);

  IdePopupManager manager = IdeEventQueue.getInstance().getPopupManager();

  if (manager.isPopupWindow(owner)) {
    if (!owner.isFocused() || !SystemInfo.isJetBrainsJvm) {
      owner = owner.getOwner();

      while (owner != null && !(owner instanceof Dialog) && !(owner instanceof Frame)) {
        owner = owner.getOwner();
      }
    }
  }

  if (owner instanceof Dialog) {
    Dialog ownerDialog = (Dialog)owner;
    if (ownerDialog.isModal() || UIUtil.isPossibleOwner(ownerDialog)) {
      owner = ownerDialog;
    }
    else {
      while (owner instanceof Dialog && !((Dialog)owner).isModal()) {
        owner = owner.getOwner();
      }
    }
  }

  while (owner != null && !owner.isShowing()) {
    owner = owner.getOwner();
  }

  // Window cannot be parent of JDialog ()
  if (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
    owner = null;
  }

  return new OwnerOptional(owner);
}
 
Example 3
Source File: SystemHealthMonitor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void checkHiDPIMode() {
  // if switched from JRE-HiDPI to IDE-HiDPI
  boolean switchedHiDPIMode = SystemInfo.isJetBrainsJvm && "true".equalsIgnoreCase(System.getProperty("sun.java2d.uiScale.enabled")) && !UIUtil.isJreHiDPIEnabled();
  if (SystemInfo.isWindows && ((switchedHiDPIMode && JBUI.isHiDPI(JBUI.sysScale())) || RemoteDesktopService.isRemoteSession())) {
    showNotification(new KeyHyperlinkAdapter("ide.set.hidpi.mode"));
  }
}
 
Example 4
Source File: MultiIconSimpleColoredComponent.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static int getTextBaseLine(@NotNull FontMetrics metrics, final int height) {
  // adding leading to ascent, just like in editor (leads to bad presentation for certain fonts with Oracle JDK, see IDEA-167541)
  return (height - metrics.getHeight()) / 2 + metrics.getAscent() +
         (SystemInfo.isJetBrainsJvm ? metrics.getLeading() : 0);
}
 
Example 5
Source File: MultiIconSimpleColoredComponent.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static int getTextBaseLine(@NotNull FontMetrics metrics, final int height) {
  // adding leading to ascent, just like in editor (leads to bad presentation for certain fonts with Oracle JDK, see IDEA-167541)
  return (height - metrics.getHeight()) / 2 + metrics.getAscent() +
         (SystemInfo.isJetBrainsJvm ? metrics.getLeading() : 0);
}
 
Example 6
Source File: SystemShortcuts.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void readSystem() {
  myKeyStroke2SysShortcut.clear();

  if (!SystemInfo.isMac || !SystemInfo.isJetBrainsJvm) return;

  try {
    if (!Registry.is("read.system.shortcuts")) return;

    if (ourShkClass == null) ourShkClass = ReflectionUtil.forName("java.awt.desktop.SystemHotkey");
    if (ourShkClass == null) return;

    if (ourMethodReadSystemHotkeys == null) ourMethodReadSystemHotkeys = ReflectionUtil.getMethod(ourShkClass, "readSystemHotkeys");
    if (ourMethodReadSystemHotkeys == null) return;

    List<AWTKeyStroke> all = (List<AWTKeyStroke>)ourMethodReadSystemHotkeys.invoke(ourShkClass);
    if (all == null || all.isEmpty()) return;

    String debugInfo = "";
    for (AWTKeyStroke shk : all) {
      if (shk.getModifiers() == 0) {
        //System.out.println("Skip system shortcut [without modifiers]: " + shk);
        continue;
      }
      if (shk.getKeyChar() == KeyEvent.CHAR_UNDEFINED && shk.getKeyCode() == KeyEvent.VK_UNDEFINED) {
        //System.out.println("Skip system shortcut [undefined key]: " + shk);
        continue;
      }
      if ("Move focus to the next window in application".equals(getDescription(shk))) {
        // Skip this shortcut because it handled in IDE-side
        // see: JBR-1515 Regression test jb/sun/awt/macos/MoveFocusShortcutTest.java fails on macOS  (Now we prevent Mac OS from handling the shortcut. We can enumerate windows on IDE level.)
        continue;
      }

      KeyStroke sysKS;
      if (shk.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
        final int keyCode = KeyEvent.getExtendedKeyCodeForChar(shk.getKeyChar());
        if (keyCode == KeyEvent.VK_UNDEFINED) {
          //System.out.println("Skip system shortcut [undefined key]: " + shk);
          continue;
        }
        sysKS = KeyStroke.getKeyStroke(keyCode, shk.getModifiers());
      }
      else sysKS = KeyStroke.getKeyStroke(shk.getKeyCode(), shk.getModifiers());

      myKeyStroke2SysShortcut.put(sysKS, shk);

      if (DEBUG_SYSTEM_SHORTCUTS) {
        debugInfo += shk.toString() + ";\n";
      }
    }
    if (DEBUG_SYSTEM_SHORTCUTS) {
      Logger.getInstance(SystemShortcuts.class).info("system shortcuts:\n" + debugInfo);
    }
  }
  catch (Throwable e) {
    Logger.getInstance(SystemShortcuts.class).debug(e);
  }
}
 
Example 7
Source File: MacFileChooseDialogProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isAvaliable() {
  return SystemInfo.isMac && SystemInfo.isJetBrainsJvm;
}
 
Example 8
Source File: JBUIScale.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static Pair<String, Integer> calcSystemFontData() {
  // with JB Linux JDK the label font comes properly scaled based on Xft.dpi settings.
  Font font = UIManager.getFont("Label.font");
  if (SystemInfo.isMacOSElCapitan) {
    // text family should be used for relatively small sizes (<20pt), don't change to Display
    // see more about SF https://medium.com/@mach/the-secret-of-san-francisco-fonts-4b5295d9a745#.2ndr50z2v
    font = new Font(".SF NS Text", font.getStyle(), font.getSize());
  }

  Logger log = getLogger();
  boolean isScaleVerbose = Boolean.getBoolean("ide.ui.scale.verbose");
  if (isScaleVerbose) {
    log.info(String.format("Label font: %s, %d", font.getFontName(), font.getSize()));
  }

  if (SystemInfo.isLinux) {
    Object value = Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Xft/DPI");
    if (isScaleVerbose) {
      log.info(String.format("gnome.Xft/DPI: %s", value));
    }
    if (value instanceof Integer) { // defined by JB JDK when the resource is available in the system
      // If the property is defined, then:
      // 1) it provides correct system scale
      // 2) the label font size is scaled
      int dpi = ((Integer)value).intValue() / 1024;
      if (dpi < 50) dpi = 50;
      float scale = JreHiDpiUtil.isJreHiDPIEnabled() ? 1f : discreteScale(dpi / 96f); // no scaling in JRE-HiDPI mode
      UIUtil.DEF_SYSTEM_FONT_SIZE = font.getSize() / scale; // derive actual system base font size
      if (isScaleVerbose) {
        log.info(String.format("DEF_SYSTEM_FONT_SIZE: %.2f", UIUtil.DEF_SYSTEM_FONT_SIZE));
      }
    }
    else if (!SystemInfo.isJetBrainsJvm) {
      // With Oracle JDK: derive scale from X server DPI, do not change DEF_SYSTEM_FONT_SIZE
      float size = UIUtil.DEF_SYSTEM_FONT_SIZE * getScreenScale();
      font = font.deriveFont(size);
      if (isScaleVerbose) {
        log.info(String.format("(Not-JB JRE) reset font size: %.2f", size));
      }
    }
  }
  else if (SystemInfo.isWindows) {
    //noinspection HardCodedStringLiteral
    @SuppressWarnings("SpellCheckingInspection") Font winFont = (Font)Toolkit.getDefaultToolkit().getDesktopProperty("win.messagebox.font");
    if (winFont != null) {
      font = winFont; // comes scaled
      if (isScaleVerbose) {
        log.info(String.format("Windows sys font: %s, %d", winFont.getFontName(), winFont.getSize()));
      }
    }
  }
  Pair<String, Integer> result = Pair.create(font.getName(), font.getSize());
  if (isScaleVerbose) {
    log.info(String.format("ourSystemFontData: %s, %d", result.first, result.second));
  }
  return result;
}