/** * Computes the global dialog base units. The current implementation * assumes a fixed 8pt font and on 96 or 120 dpi. A better implementation * should ask for the main dialog font and should honor the current * screen resolution.<p> * * Should be re-computed if the l&f, platform, or screen changes. * * @return a DialogBaseUnits object used globally if no container is available */ private DialogBaseUnits computeGlobalDialogBaseUnits() { LOGGER.config("Computing global dialog base units..."); Font dialogFont = getDefaultDialogFont(); FontMetrics metrics = createDefaultGlobalComponent().getFontMetrics(dialogFont); DialogBaseUnits globalDialogBaseUnits = computeDialogBaseUnits(metrics); return globalDialogBaseUnits; }
/** * Computes the global dialog base units. The current implementation * assumes a fixed 8pt font and on 96 or 120 dpi. A better implementation * should ask for the main dialog font and should honor the current * screen resolution.<p> * * Should be re-computed if the l&f, platform, or screen changes. * * @return a DialogBaseUnits object used globally if no container is available */ private DialogBaseUnits computeGlobalDialogBaseUnits() { LOGGER.config("Computing global dialog base units..."); Font dialogFont = getDefaultDialogFont(); FontMetrics metrics = createDefaultGlobalComponent().getFontMetrics(dialogFont); DialogBaseUnits globalDialogBaseUnits = computeDialogBaseUnits(metrics); return globalDialogBaseUnits; }
/** * Computes and returns the width of this Size's prototype in pixel. * Ignores the component list and measures. Obtains the FontMetrics * from the given layout {@code container} for the default dialog font * provided by {@link DefaultUnitConverter#getDefaultDialogFont()}.<p> * * Invoked by {@link com.jgoodies.forms.layout.FormSpec} to determine * the size of a column or row. * * @param container the layout container * @param components the list of components used to compute the size * @param minMeasure the measure that determines the minimum sizes * @param prefMeasure the measure that determines the preferred sizes * @param defaultMeasure the measure that determines the default sizes * * @return the {@code stringWidth} for this size's prototype string * computed by the {@code container}'s FontMetrics for the * {@code DefaultUnitConverter}'s default dialog font */ public int maximumSize(Container container, List components, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure, FormLayout.Measure defaultMeasure) { Font font = DefaultUnitConverter.getInstance().getDefaultDialogFont(); FontMetrics fm = container.getFontMetrics(font); return fm.stringWidth(getPrototype()); }
/** * Looks up and returns the dialog base units for the given component. * In case the component is <code>null</code> the global dialog base units * are answered.<p> * * Before we compute the dialog base units we check whether they * have been computed and cached before - for the same component * <code>FontMetrics</code>. * * @param c the component that provides the graphics object * @return the DialogBaseUnits object for the given component */ private DialogBaseUnits getDialogBaseUnits(Component c) { FormUtils.ensureValidCache(); if (c == null) { // || (font = c.getFont()) == null) { // logInfo("Missing font metrics: " + c); return getGlobalDialogBaseUnits(); } FontMetrics fm = c.getFontMetrics(getDefaultDialogFont()); DialogBaseUnits dialogBaseUnits = (DialogBaseUnits) cachedDialogBaseUnits.get(fm); if (dialogBaseUnits == null) { dialogBaseUnits = computeDialogBaseUnits(fm); cachedDialogBaseUnits.put(fm, dialogBaseUnits); } return dialogBaseUnits; }
/** * Looks up and returns the dialog base units for the given component. In * case the component is <code>null</code> the global dialog base units * are answered. * <p> * * Before we compute the dialog base units we check whether they have been * computed and cached before - for the same component * <code>FontMetrics</code>. * * @param c * the component that provides the graphics object * @return the DialogBaseUnits object for the given component */ private DialogBaseUnits getDialogBaseUnits(Component c) { if (c == null) { // || (font = c.getFont()) == null) { logInfo("Missing font metrics: " + c); return getGlobalDialogBaseUnits(); } FontMetrics fm = c.getFontMetrics(getDefaultDialogFont()); DialogBaseUnits dialogBaseUnits = (DialogBaseUnits) cachedDialogBaseUnits.get(fm); if (dialogBaseUnits == null) { dialogBaseUnits = computeDialogBaseUnits(fm); cachedDialogBaseUnits.put(fm, dialogBaseUnits); } return dialogBaseUnits; }
/** * Computes and returns the width of this Size's prototype in pixel. * Ignores the component list and measures. Obtains the FontMetrics * from the given layout {@code container} for the default dialog font * provided by {@link DefaultUnitConverter#getDefaultDialogFont()}.<p> * * Invoked by {@link com.jgoodies.forms.layout.FormSpec} to determine * the size of a column or row. * * @param container the layout container * @param components the list of components used to compute the size * @param minMeasure the measure that determines the minimum sizes * @param prefMeasure the measure that determines the preferred sizes * @param defaultMeasure the measure that determines the default sizes * * @return the {@code stringWidth} for this size's prototype string * computed by the {@code container}'s FontMetrics for the * {@code DefaultUnitConverter}'s default dialog font */ @Override public int maximumSize(Container container, List components, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure, FormLayout.Measure defaultMeasure) { Font font = DefaultUnitConverter.getInstance().getDefaultDialogFont(); FontMetrics fm = container.getFontMetrics(font); return fm.stringWidth(getPrototype()); }
/** * Looks up and returns the dialog base units for the given component. * In case the component is {@code null} the global dialog base units * are answered.<p> * * Before we compute the dialog base units we check whether they * have been computed and cached before - for the same component * {@code FontMetrics}. * * @param c the component that provides the graphics object * @return the DialogBaseUnits object for the given component */ private DialogBaseUnits getDialogBaseUnits(Component c) { FormUtils.ensureValidCache(); if (c == null) { // || (font = c.getFont()) == null) { // logInfo("Missing font metrics: " + c); return getGlobalDialogBaseUnits(); } FontMetrics fm = c.getFontMetrics(getDefaultDialogFont()); if (fm.equals(cachedFontMetrics)) { return cachedDialogBaseUnits; } DialogBaseUnits dialogBaseUnits = computeDialogBaseUnits(fm); cachedFontMetrics = fm; cachedDialogBaseUnits = dialogBaseUnits; return dialogBaseUnits; }
/** * Computes the global dialog base units. The current implementation assumes * a fixed 8pt font and on 96 or 120 dpi. A better implementation should ask * for the main dialog font and should honor the current screen resolution. * <p> * * Should be re-computed if the l&f, platform, or screen changes. * * @return a DialogBaseUnits object used globally if no container is * available */ private DialogBaseUnits computeGlobalDialogBaseUnits() { logInfo("Computing global dialog base units..."); Font dialogFont = getDefaultDialogFont(); FontMetrics metrics = createDefaultGlobalComponent().getFontMetrics(dialogFont); DialogBaseUnits globalDialogBaseUnits = computeDialogBaseUnits(metrics); return globalDialogBaseUnits; }