@Override public int getHorizontalScreenDPI() { return PlatformDefaults.getDefaultDPI(); }
private static boolean isDialogInsets(UnitValue[] insets) { for (int i = 0; i < 4; i++) { if (PlatformDefaults.getDialogInsets(i) != insets[i]) return false; } return true; }
private static boolean isPanelInsets(UnitValue[] insets) { for (int i = 0; i < 4; i++) { if (PlatformDefaults.getPanelInsets(i) != insets[i]) return false; } return true; }
@Override public final float getPixelUnitFactor(boolean isHor) { switch (PlatformDefaults.getLogicalPixelBase()) { case PlatformDefaults.BASE_FONT_SIZE: Font font = c.getFont(); FontMetrics fm = c.getFontMetrics(font != null ? font : SUBST_FONT); Point.Float p = FM_MAP.get(fm); if (p == null) { Rectangle2D r = fm.getStringBounds("X", c.getGraphics()); p = new Point.Float(((float) r.getWidth()) / 6f, ((float) r.getHeight()) / 13.27734375f); FM_MAP.put(fm, p); } return isHor ? p.x : p.y; case PlatformDefaults.BASE_SCALE_FACTOR: Float s = isHor ? PlatformDefaults.getHorizontalScaleFactor() : PlatformDefaults.getVerticalScaleFactor(); float scaleFactor = (s != null) ? s : 1f; // Swing in Java 9 scales automatically using the system scale factor(s) that the // user can change in the system settings (Windows: Control Panel; Mac: System Preferences). // Each connected screen may use its own scale factor // (e.g. 1.5 for primary 4K 40inch screen and 1.0 for secondary HD screen). float screenScale = isJava9orLater ? 1f // use system scale factor(s) : (float) (isHor ? getHorizontalScreenDPI() : getVerticalScreenDPI()) / (float) PlatformDefaults.getDefaultDPI(); return scaleFactor * screenScale; default: return 1f; } }
case PT: float f = SCALE[unit - MM]; Float s = isHor ? PlatformDefaults.getHorizontalScaleFactor() : PlatformDefaults.getVerticalScaleFactor(); if (s != null) f *= s; return PlatformDefaults.getMinimumButtonWidthIncludingPadding(refValue, parent, comp); return PlatformDefaults.getLabelAlignPercentage() * refValue;
BoundSize defGap = isCols ? PlatformDefaults.getGridGapX() : PlatformDefaults.getGridGapY();
/** Parses insets which consists of 1-4 <code>UnitValue</code>s. * @param s The string to parse. E.g. "10 10 10 10" or "20". If less than 4 groups the last will be used for the missing. * @param acceptPanel If "panel" and "dialog" should be accepted. They are used to access platform defaults. * @return An array of length 4 with the parsed insets. * @throws IllegalArgumentException if the parsing could not be done. */ public static UnitValue[] parseInsets(String s, boolean acceptPanel) { if (s.length() == 0 || s.equals("dialog") || s.equals("panel")) { if (acceptPanel == false) throw new IllegalArgumentException("Insets now allowed: " + s + "\n"); boolean isPanel = s.startsWith("p"); UnitValue[] ins = new UnitValue[4]; for (int j = 0; j < 4; j++) ins[j] = isPanel ? PlatformDefaults.getPanelInsets(j) : PlatformDefaults.getDialogInsets(j); return ins; } else { String[] insS = toTrimmedTokens(s, ' '); UnitValue[] ins = new UnitValue[4]; for (int j = 0; j < 4; j++) { UnitValue insSz = parseUnitValue(insS[j < insS.length ? j : insS.length - 1], UnitValue.ZERO, j % 2 == 1); ins[j] = insSz != null ? insSz : PlatformDefaults.getPanelInsets(j); } return ins; } }
/** Check if something has changed and if so recreate it to the cached objects. * @param parent The parent that is the target for this layout manager. */ private void checkCache(Composite parent) { if (parent == null) return; checkConstrMap(parent); ContainerWrapper par = checkParent(parent); // Check if the grid is valid int mc = PlatformDefaults.getModCount(); if (lastModCount != mc) { grid = null; lastModCount = mc; } int hash = parent.getSize().hashCode(); for (ComponentWrapper cw : ccMap.keySet()) { hash ^= cw.getLayoutHashCode(); hash += 285134905; } if (hash != lastHash) { grid = null; lastHash = hash; } setDebug(par, getDebugMillis() > 0); if (grid == null) grid = new Grid(par, lc, rowSpecs, colSpecs, ccMap, callbackList); }
@Override public final float getPixelUnitFactor(boolean isHor) { switch (PlatformDefaults.getLogicalPixelBase()) { case PlatformDefaults.BASE_FONT_SIZE: GC gc = new GC(c); FontMetrics fm = gc.getFontMetrics(); float f = isHor ? fm.getAverageCharWidth() / 5f : fm.getHeight() / 13f; gc.dispose(); return f; case PlatformDefaults.BASE_SCALE_FACTOR: Float s = isHor ? PlatformDefaults.getHorizontalScaleFactor() : PlatformDefaults.getVerticalScaleFactor(); if (s != null) return s.floatValue(); return (isHor ? getHorizontalScreenDPI() : getVerticalScreenDPI()) / (float) PlatformDefaults.getDefaultDPI(); default: return 1f; } }
defGap = isHor ? PlatformDefaults.getGridGapX() : PlatformDefaults.getGridGapY(); int[] defGapArr = defGap.getPixelSizes(refSize, container, null);
int mc = PlatformDefaults.getModCount(); if (lastModCount != mc) { grid = null;
@Override public int getVerticalScreenDPI() { return PlatformDefaults.getDefaultDPI(); }
/** Returns the insets for the side. * @param side top == 0, left == 1, bottom = 2, right = 3. * @param getDefault If <code>true</code> the default insets will get retrieved if <code>lc</code> has none set. * @return The insets for the side. Never <code>null</code>. */ static UnitValue getInsets(LC lc, int side, boolean getDefault) { UnitValue[] i = lc.getInsets(); return (i != null && i[side] != null) ? i[side] : (getDefault ? PlatformDefaults.getPanelInsets(side) : UnitValue.ZERO); }
@Override public final int getHorizontalScreenDPI() { try { return c.getToolkit().getScreenResolution(); } catch (HeadlessException ex) { return PlatformDefaults.getDefaultDPI(); } }
@Override public final int getVerticalScreenDPI() { try { return c.getToolkit().getScreenResolution(); } catch (HeadlessException ex) { return PlatformDefaults.getDefaultDPI(); } }