/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Calculates preferred size and layouts menu items.
*/
public class MenuItemLayoutHelper {
/* Client Property keys for calculation of maximal widths */
new StringUIClientPropertyKey("maxArrowWidth");
new StringUIClientPropertyKey("maxCheckWidth");
new StringUIClientPropertyKey("maxIconWidth");
new StringUIClientPropertyKey("maxTextWidth");
new StringUIClientPropertyKey("maxAccWidth");
new StringUIClientPropertyKey("maxLabelWidth");
private boolean isColumnLayout;
private boolean useCheckAndArrow;
private boolean isLeftToRight;
private boolean isTopLevelMenu;
private int verticalAlignment;
private int horizontalAlignment;
private int verticalTextPosition;
private int horizontalTextPosition;
private int gap;
private int leadingGap;
private int afterCheckIconGap;
private int minTextOffset;
private int leftTextExtraWidth;
/**
* The empty protected constructor is necessary for derived classes.
*/
protected MenuItemLayoutHelper() {
}
}
this.useCheckAndArrow = useCheckAndArrow;
this.isLeftToRight = isLeftToRight;
}
private void calcExtraWidths() {
}
if (lsb < 0) {
return -lsb;
} else {
return 0;
}
}
private void setOriginalWidths() {
}
if (accelerator != null) {
if (modifiers > 0) {
}
if (keyCode != 0) {
} else {
}
}
return accText;
}
// In case of column layout, .checkIconFactory is defined for this UI,
// the icon is compatible with it and useCheckAndArrow() is true,
// then the icon is handled by the checkIcon.
+ ".checkIconFactory");
}
return icon;
}
int minimumTextOffset = 0;
if (minimumTextOffsetObject instanceof Integer) {
}
return minimumTextOffset;
}
int afterCheckIconGap = gap;
if (afterCheckIconGapObject instanceof Integer) {
}
return afterCheckIconGap;
}
return getCheckOffset(propertyPrefix);
} else {
return gap; // There is no any check icon
}
}
int checkIconOffset = gap;
if (checkIconOffsetObject instanceof Integer) {
}
return checkIconOffset;
}
protected void calcWidthsAndHeights() {
// iconRect
}
// accRect
}
// textRect
text = "";
// Text is HTML
} else {
// Text isn't HTML
}
}
if (useCheckAndArrow) {
// checkIcon
}
// arrowRect
}
}
// labelRect
if (isColumnLayout) {
} else {
}
}
protected void calcMaxWidths() {
if (isColumnLayout) {
curGap = 0;
}
} else {
// We shouldn't use current icon and text widths
// in maximal widths calculation for complex layout.
// If maxLabelWidth is wider
// than the widest icon + the widest text + gap,
// we should update the maximal text witdh
}
}
}
}
/**
* Calculates and returns maximal value through specified parent component
* client property.
*
* @param propertyName name of the property, which stores the maximal value.
* @param value a value which pretends to be maximal
* @return maximal value among the parent property and the value.
*/
// Get maximal value from parent client property
// Store new maximal width in parent client property
}
return value;
} else {
return maxValue;
}
}
/**
* Returns parent client property as int.
* @param propertyName name of the parent property.
* @return value of the property as int.
*/
}
value = 0;
}
}
}
/**
* Answers should we do column layout for a menu item or not.
* We do it when a user doesn't set any alignments
* and text positions manually, except the vertical alignment.
*/
int horizontalAlignment,
int verticalTextPosition) {
return false;
}
if (isLeftToRight) {
return false;
}
return false;
}
} else {
return false;
}
return false;
}
}
return true;
}
/**
* Calculates maximal text offset.
* It is required for some L&Fs (ex: Vista L&F).
* The offset is meaningful only for L2R column layout.
*
* @param viewRect the rectangle, the maximal text offset
* will be calculated for.
*/
if (!isColumnLayout || !isLeftToRight) {
return;
}
// Calculate the current text offset
}
}
// maximal text offset shouldn't be less than minimal text offset;
if (offset < minTextOffset) {
}
// Calculate and store the maximal text offset
}
/**
* Layout icon, text, check icon, accelerator text and arrow icon
* in the viewRect and return their positions.
*
* If horizontalAlignment, verticalTextPosition and horizontalTextPosition
* are default (user doesn't set any manually) the layouting algorithm is:
* Elements are layouted in the five columns:
* check icon + icon + text + accelerator text + arrow icon
*
* In the other case elements are layouted in the four columns:
* check icon + label + accelerator text + arrow icon
* Label is union of icon and text.
*
* The order of columns can be reversed.
* It depends on the menu item orientation.
*/
if (isColumnLayout()) {
if (isLeftToRight()) {
} else {
}
} else {
if (isLeftToRight()) {
} else {
}
}
return lr;
}
return new LayoutResult(
);
}
return ColumnAlignment.LEFT_ALIGNMENT;
}
return ColumnAlignment.RIGHT_ALIGNMENT;
}
}
/**
* Aligns the accelertor text and the check and arrow icons vertically
* with the center of the label rect.
*/
if (useCheckAndArrow) {
}
}
/**
* Fixes vertical alignment of all menu item elements if rect.y
* or (rect.y + rect.height) is out of viewRect bounds
*/
int delta = 0;
if (r.y < viewRect.y) {
}
if (delta != 0) {
}
}
// Set maximal width for all the five basic rects
// (three other ones are already maximal)
// Set X coordinates
// All rects will be aligned at the left side
// Tune afterCheckIconGap
}
// Take into account minimal text offset
}
// Set Y coordinate for text and icon.
// Y coordinates for other rects
// will be calculated later in layoutMenuItem.
// Calculate valid X and Y coordinates for labelRect
}
// Set X coordinates
// Tune afterCheckIconGap
}
// Take into account minimal text offset
}
// Center labelRect vertically
}
// Set maximal width for all the five basic rects
// (three other ones are already maximal)
// Set X coordinates
// Tune the gap after check icon
}
// Take into account minimal text offset
}
// Set Y coordinates for text and icon.
// Y coordinates for other rects
// will be calculated later in layoutMenuItem.
// Calculate valid X and Y coordinate for labelRect
}
// Set X coordinates
// Tune the gap after check icon
}
// Take into account minimal text offset
}
// Center labelRect vertically
}
iconSize.getOrigWidth());
textSize.getOrigWidth());
accSize.getOrigWidth());
}
}
}
}
}
}
}
}
}
}
/**
* Sets Y coordinates of text and icon
* taking into account the vertical alignment
*/
}
}
}
/**
* Sets labelRect Y coordinate
* taking into account the vertical alignment
*/
}
}
/**
* Returns parent of this component if it is not a top-level menu
* Otherwise returns null.
* @param menuItem the menu item whose parent will be returned.
* @return parent of this component if it is not a top-level menu
* Otherwise returns null.
*/
if ((parent instanceof JComponent) &&
return (JComponent) parent;
} else {
return null;
}
}
}
if (c != null) {
}
}
/**
* Finds and returns maximal integer value in the given array.
* @param values array where the search will be performed.
* @return maximal vaule.
*/
for (int i : values) {
if (i > maxValue) {
maxValue = i;
}
}
return maxValue;
}
}
}
}
if (width > 0) {
}
}
return mi;
}
return miParent;
}
return font;
}
return accFont;
}
return fm;
}
return accFm;
}
return icon;
}
return checkIcon;
}
return arrowIcon;
}
return text;
}
return accText;
}
public boolean isColumnLayout() {
return isColumnLayout;
}
public boolean useCheckAndArrow() {
return useCheckAndArrow;
}
public boolean isLeftToRight() {
return isLeftToRight;
}
public boolean isTopLevelMenu() {
return isTopLevelMenu;
}
return htmlView;
}
public int getVerticalAlignment() {
return verticalAlignment;
}
public int getHorizontalAlignment() {
return horizontalAlignment;
}
public int getVerticalTextPosition() {
return verticalTextPosition;
}
public int getHorizontalTextPosition() {
return horizontalTextPosition;
}
public int getGap() {
return gap;
}
public int getLeadingGap() {
return leadingGap;
}
public int getAfterCheckIconGap() {
return afterCheckIconGap;
}
public int getMinTextOffset() {
return minTextOffset;
}
return viewRect;
}
return iconSize;
}
return textSize;
}
return accSize;
}
return checkSize;
}
return arrowSize;
}
return labelSize;
}
}
}
}
}
}
}
}
}
}
}
}
}
this.useCheckAndArrow = useCheckAndArrow;
}
}
}
}
this.verticalAlignment = verticalAlignment;
}
}
}
}
}
this.leadingGap = leadingGap;
}
this.afterCheckIconGap = afterCheckIconGap;
}
this.minTextOffset = minTextOffset;
}
}
}
}
}
}
}
}
public int getLeftTextExtraWidth() {
return leftTextExtraWidth;
}
/**
* Returns false if the component is a JMenu and it is a top
* level menu (on the menubar).
*/
boolean b = true;
b = false;
}
return b;
}
public static class LayoutResult {
public LayoutResult() {
}
}
return iconRect;
}
}
return textRect;
}
}
return accRect;
}
}
return checkRect;
}
}
return arrowRect;
}
}
return labelRect;
}
}
return result;
}
}
public static class ColumnAlignment {
private int checkAlignment;
private int iconAlignment;
private int textAlignment;
private int accAlignment;
private int arrowAlignment;
new ColumnAlignment(
);
new ColumnAlignment(
);
int textAlignment, int accAlignment,
int arrowAlignment) {
this.checkAlignment = checkAlignment;
this.iconAlignment = iconAlignment;
this.textAlignment = textAlignment;
this.accAlignment = accAlignment;
this.arrowAlignment = arrowAlignment;
}
public int getCheckAlignment() {
return checkAlignment;
}
public int getIconAlignment() {
return iconAlignment;
}
public int getTextAlignment() {
return textAlignment;
}
public int getAccAlignment() {
return accAlignment;
}
public int getArrowAlignment() {
return arrowAlignment;
}
}
public static class RectSize {
private int width;
private int height;
private int origWidth;
private int maxWidth;
public RectSize() {
}
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getOrigWidth() {
return origWidth;
}
public int getMaxWidth() {
return maxWidth;
}
}
}
}
}
}
}
}