Java Code Examples for com.intellij.util.SystemProperties#getBooleanProperty()

The following examples show how to use com.intellij.util.SystemProperties#getBooleanProperty() . 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: JBUIScale.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static float computeUserScaleFactor(float scale) {
  if (!SystemProperties.getBooleanProperty("hidpi", true)) {
    return 1f;
  }

  scale = discreteScale(scale);

  // Downgrading user scale below 1.0 may be uncomfortable (tiny icons),
  // whereas some users prefer font size slightly below normal which is ok.
  if (scale < 1 && sysScale() >= 1) {
    scale = 1;
  }

  // Ignore the correction when UIUtil.DEF_SYSTEM_FONT_SIZE is overridden, see UIUtil.initSystemFontData.
  if (SystemInfo.isLinux && scale == 1.25f && UIUtil.DEF_SYSTEM_FONT_SIZE == 12) {
    // Default UI font size for Unity and Gnome is 15. Scaling factor 1.25f works badly on Linux
    scale = 1f;
  }
  return scale;
}
 
Example 2
Source File: JBUIScale.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Float initialize() {
  if (!SystemProperties.getBooleanProperty("hidpi", true)) {
    return 1f;
  }
  if (JreHiDpiUtil.isJreHiDPIEnabled()) {
    GraphicsDevice gd = null;
    try {
      gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    }
    catch (HeadlessException ignore) {
    }
    if (gd != null && gd.getDefaultConfiguration() != null) {
      return sysScale(gd.getDefaultConfiguration());
    }
    return 1f;
  }
  Pair<String, Integer> fdata = JBUIScale.getSystemFontData();

  int size = fdata.getSecond();
  return getFontScale(size);
}
 
Example 3
Source File: StateMap.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static byte[] getNewByteIfDiffers(@Nonnull String key, @Nonnull Object newState, @Nonnull byte[] oldState) {
  byte[] newBytes = newState instanceof Element ? archiveState((Element)newState) : (byte[])newState;
  if (Arrays.equals(newBytes, oldState)) {
    return null;
  }
  else if (LOG.isDebugEnabled() && SystemProperties.getBooleanProperty("idea.log.changed.components", false)) {
    String before = stateToString(oldState);
    String after = stateToString(newState);
    if (before.equals(after)) {
      LOG.debug("Serialization error: serialized are different, but unserialized are equal");
    }
    else {
      LOG.debug(key + " " + StringUtil.repeat("=", 80 - key.length()) + "\nBefore:\n" + before + "\nAfter:\n" + after);
    }
  }
  return newBytes;
}
 
Example 4
Source File: XDebugSessionTab.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static XDebugSessionTab create(@Nonnull XDebugSessionImpl session,
                                      @Nullable Image icon,
                                      @Nullable ExecutionEnvironment environment,
                                      @Nullable RunContentDescriptor contentToReuse) {
  if (contentToReuse != null && SystemProperties.getBooleanProperty("xdebugger.reuse.session.tab", false)) {
    JComponent component = contentToReuse.getComponent();
    if (component != null) {
      XDebugSessionTab oldTab = DataManager.getInstance().getDataContext(component).getData(TAB_KEY);
      if (oldTab != null) {
        oldTab.setSession(session, environment, icon);
        oldTab.attachToSession(session);
        return oldTab;
      }
    }
  }
  XDebugSessionTab tab = new XDebugSessionTab(session, icon, environment);
  tab.myRunContentDescriptor.setActivateToolWindowWhenAdded(contentToReuse == null || contentToReuse.isActivateToolWindowWhenAdded());
  return tab;
}
 
Example 5
Source File: RepositoryHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String buildUrlForDownload(@Nonnull UpdateChannel channel,
                                         @Nonnull String pluginId,
                                         @Nullable String platformVersion,
                                         boolean noTracking,
                                         boolean viaUpdate) {
  if (platformVersion == null) {
    platformVersion = ApplicationInfoImpl.getShadowInstance().getBuild().asString();
  }

  StringBuilder builder = new StringBuilder();
  builder.append(WebServiceApi.REPOSITORY_API.buildUrl("download"));
  builder.append("?platformVersion=");
  builder.append(platformVersion);
  builder.append("&channel=");
  builder.append(channel);
  builder.append("&id=");
  builder.append(pluginId);

  if (!noTracking) {
    noTracking = SystemProperties.getBooleanProperty("consulo.repository.no.tracking", false);
  }

  if (noTracking) {
    builder.append("&noTracking=true");
  }
  if (viaUpdate) {
    builder.append("&viaUpdate=true");
  }
  return builder.toString();
}
 
Example 6
Source File: JBUIScale.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the user scale factor.
 * The method is used by the IDE, it's not recommended to call the method directly from the client code.
 * For debugging purposes, the following JVM system property can be used:
 * ide.ui.scale=[float]
 * or the IDE registry keys (for backward compatibility):
 * ide.ui.scale.override=[boolean]
 * ide.ui.scale=[float]
 *
 * @return the result
 */
public static float setUserScaleFactor(float scale) {
  if (DEBUG_USER_SCALE_FACTOR.isNotNull()) {
    float debugScale = ObjectUtil.notNull(DEBUG_USER_SCALE_FACTOR.get());
    if (scale == debugScale) {
      setUserScaleFactorProperty(debugScale); // set the debug value as is, or otherwise ignore
    }
    return debugScale;
  }

  if (!SystemProperties.getBooleanProperty("hidpi", true)) {
    setUserScaleFactorProperty(1f);
    return 1f;
  }

  scale = discreteScale(scale);

  // Downgrading user scale below 1.0 may be uncomfortable (tiny icons),
  // whereas some users prefer font size slightly below normal which is ok.
  if (scale < 1 && sysScale() >= 1) scale = 1;

  // Ignore the correction when UIUtil.DEF_SYSTEM_FONT_SIZE is overridden, see UIUtil.initSystemFontData.
  if (SystemInfo.isLinux && scale == 1.25f && UIUtil.DEF_SYSTEM_FONT_SIZE == 12) {
    //Default UI font size for Unity and Gnome is 15. Scaling factor 1.25f works badly on Linux
    scale = 1f;
  }
  setUserScaleFactorProperty(scale);
  return scale;
}
 
Example 7
Source File: JreHiDpiUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the JRE-managed HiDPI mode is enabled.
 * (True for macOS JDK >= 7.10 versions)
 *
 * @see ScaleType
 */
public static boolean isJreHiDPIEnabled() {
  Boolean value = jreHiDPI.get();
  if (value == null) {
    synchronized (jreHiDPI) {
      value = jreHiDPI.get();
      if (value == null) {
        value = false;
        if (SystemProperties.getBooleanProperty("hidpi", true)) {
          jreHiDPI_earlierVersion = true;
          // fixme [vistall] always allow hidpi on other jdks
          if (Boolean.TRUE) {
            try {
              GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
              Boolean uiScaleEnabled = GraphicsEnvironmentHacking.isUIScaleEnabled(ge);
              if (uiScaleEnabled != null) {
                value = uiScaleEnabled;
                jreHiDPI_earlierVersion = false;
              }
            }
            catch (Throwable ignore) {
            }
          }
          if (SystemInfo.isMac) {
            value = true;
          }
        }
        jreHiDPI.set(value);
      }
    }
  }
  return value;
}
 
Example 8
Source File: DesktopStartUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void blockATKWrapper() {
  /*
   * The method should be called before java.awt.Toolkit.initAssistiveTechnologies()
   * which is called from Toolkit.getDefaultToolkit().
   */
  if (!SystemInfo.isLinux || !SystemProperties.getBooleanProperty("linux.jdk.accessibility.atkwrapper.block", true)) return;

  if (ScreenReader.isEnabled(ScreenReader.ATK_WRAPPER)) {
    // Replace AtkWrapper with a dummy Object. It'll be instantiated & GC'ed right away, a NOP.
    System.setProperty("javax.accessibility.assistive_technologies", "java.lang.Object");
    getLogger().info(ScreenReader.ATK_WRAPPER + " is blocked, see IDEA-149219");
  }
}
 
Example 9
Source File: LowMemoryWatcherManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public LowMemoryWatcherManager(@Nonnull ExecutorService backendExecutorService) {
  // whether LowMemoryWatcher runnables should be executed on the same thread that the low memory events come
  myExecutorService = SystemProperties.getBooleanProperty("low.memory.watcher.sync", false)
                      ? ConcurrencyUtil.newSameThreadExecutorService()
                      : SequentialTaskExecutor.createSequentialApplicationPoolExecutor("LowMemoryWatcherManager", backendExecutorService);

  myMemoryPoolMXBeansFuture = initializeMXBeanListenersLater(backendExecutorService);
}
 
Example 10
Source File: SystemNotificationsImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Notifier getPlatformNotifier() {
  try {
    if (SystemInfo.isMac) {
      if (SystemInfo.isMacOSMountainLion && SystemProperties.getBooleanProperty("ide.mac.mountain.lion.notifications.enabled", true)) {
        return MountainLionNotifications.getInstance();
      }
      else {
        return GrowlNotifications.getInstance();
      }
    }
    else if (SystemInfo.isXWindow) {
      return LibNotifyWrapper.getInstance();
    }
    else if (SystemInfo.isWin10OrNewer) {
      return SystemTrayNotifications.getWin10Instance();
    }
  }
  catch (Throwable t) {
    Logger logger = Logger.getInstance(SystemNotifications.class);
    if (logger.isDebugEnabled()) {
      logger.debug(t);
    }
    else {
      logger.info(t.getMessage());
    }
  }

  return null;
}
 
Example 11
Source File: WSLUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return list of existing UNC roots for known WSL distributions
 */
//@ApiStatus.Experimental
@Nonnull
public static List<File> getExistingUNCRoots() {
  if (!isSystemCompatible() || !SystemProperties.getBooleanProperty("wsl.p9.support", true)) {
    return Collections.emptyList();
  }
  return getAvailableDistributions().stream().map(WSLDistribution::getUNCRoot).filter(File::exists).collect(Collectors.toList());
}
 
Example 12
Source File: WSLDistribution.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return UNC root for the distribution, e.g. {@code \\wsl$\Ubuntu}
 * @implNote there is a hack in {@link LocalFileSystemBase#getAttributes(com.intellij.openapi.vfs.VirtualFile)} which causes all network
 * virtual files to exists all the time. So we need to check explicitly that root exists. After implementing proper non-blocking check
 * for the network resource availability, this method may be simplified to findFileByIoFile
 * @see VfsUtil#findFileByIoFile(java.io.File, boolean)
 */
//@ApiStatus.Experimental
@Nullable
public VirtualFile getUNCRootVirtualFile(boolean refreshIfNeed) {
  if (!SystemProperties.getBooleanProperty("wsl.p9.support", true)) {
    return null;
  }
  File uncRoot = getUNCRoot();
  return uncRoot.exists() ? VfsUtil.findFileByIoFile(uncRoot, refreshIfNeed) : null;
}
 
Example 13
Source File: LaterInvocator.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void invokeAndWait(@Nonnull final Runnable runnable, @Nonnull ModalityState modalityState) {
  LOG.assertTrue(!isDispatchThread());

  final Semaphore semaphore = new Semaphore();
  semaphore.down();
  final Ref<Throwable> exception = Ref.create();
  Runnable runnable1 = new Runnable() {
    @Override
    public void run() {
      try {
        runnable.run();
      }
      catch (Throwable e) {
        exception.set(e);
      }
      finally {
        semaphore.up();
      }
    }

    @Override
    @NonNls
    public String toString() {
      return "InvokeAndWait[" + runnable + "]";
    }
  };
  invokeLaterWithCallback(runnable1, modalityState, Conditions.FALSE, null);
  semaphore.waitFor();
  if (!exception.isNull()) {
    Throwable cause = exception.get();
    if (SystemProperties.getBooleanProperty("invoke.later.wrap.error", true)) {
      // wrap everything to keep the current thread stacktrace
      // also TC ComparisonFailure feature depends on this
      throw new RuntimeException(cause);
    }
    else {
      ExceptionUtil.rethrow(cause);
    }
  }
}
 
Example 14
Source File: HttpRequests.java    From leetcode-editor with Apache License 2.0 4 votes vote down vote up
private static boolean shouldOverrideContextClassLoader() {
    return Patches.JDK_BUG_ID_8032832 &&
            SystemProperties.getBooleanProperty("http.requests.override.context.classloader", true);
}
 
Example 15
Source File: NetUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isSniEnabled() {
  return SystemProperties.getBooleanProperty("jsse.enableSNIExtension", true);
}
 
Example 16
Source File: BaseOutputReader.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static Options forMostlySilentProcess() {
  if (SystemProperties.getBooleanProperty("output.reader.blocking.mode.for.mostly.silent.processes", true) || Boolean.getBoolean("output.reader.blocking.mode")) {
    return BLOCKING;
  }
  return NON_BLOCKING;
}
 
Example 17
Source File: ArchiveFileSystemBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected ArchiveFileSystemBase(@Nonnull String protocol) {
  myProtocol = protocol;
  boolean noCopy = SystemProperties.getBooleanProperty("idea.jars.nocopy", !SystemInfo.isWindows);
  myNoCopyJarPaths = noCopy ? null : ConcurrentCollectionFactory.createConcurrentSet(FileUtil.PATH_HASHING_STRATEGY);
}
 
Example 18
Source File: HttpRequests.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean shouldOverrideContextClassLoader() {
  return Patches.JDK_BUG_ID_8032832 &&
         SystemProperties.getBooleanProperty("http.requests.override.context.classloader", true);
}
 
Example 19
Source File: TriggerExceptionAction.java    From protobuf-jetbrains-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void update(AnActionEvent e) {
    boolean visible = SystemProperties.getBooleanProperty("trigger_exception_action.visible", false);
    e.getPresentation().setEnabledAndVisible(visible);
}