本文整理汇总了Java中org.apache.harmony.awt.state.MenuBarState类的典型用法代码示例。如果您正苦于以下问题:Java MenuBarState类的具体用法?Java MenuBarState怎么用?Java MenuBarState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MenuBarState类属于org.apache.harmony.awt.state包,在下文中一共展示了MenuBarState类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: layoutMenuBar
import org.apache.harmony.awt.state.MenuBarState; //导入依赖的package包/类
public static void layoutMenuBar(MenuBarState s, int width) {
Font f = s.getFont();
FontMetrics fm = s.getFontMetrics(f);
int lineHeight = getItemHeight(fm);
int lines = 0;
int lineWidth = 0;
for (int i=0; i<s.getItemCount(); i++) {
MenuItemState is = s.getItem(i);
int itemWidth = getItemWidth(fm, is);
if (itemWidth >= width) {
lines += (lineWidth == 0 ? 1 : 2);
lineWidth = 0;
is.setItemBounds(0, lines * lineHeight, itemWidth, lineHeight);
continue;
}
if (lineWidth + itemWidth > width) {
lines ++;
lineWidth = itemWidth;
is.setItemBounds(0, lines * lineHeight, itemWidth, lineHeight);
continue;
}
is.setItemBounds(lineWidth, lines * lineHeight, itemWidth, lineHeight);
lineWidth += itemWidth;
}
if (lineWidth > 0) {
lines ++;
}
s.setSize(width, lines * lineHeight + 1);
}
示例2: getPreferredWidth
import org.apache.harmony.awt.state.MenuBarState; //导入依赖的package包/类
public static int getPreferredWidth(MenuBarState s) {
int width = 0;
Font f = s.getFont();
FontMetrics fm = s.getFontMetrics(f);
for (int i=0; i<s.getItemCount(); i++) {
width += getItemWidth(fm, s.getItem(i));
}
return width;
}
示例3: drawMenuBar
import org.apache.harmony.awt.state.MenuBarState; //导入依赖的package包/类
public static void drawMenuBar(MenuBarState s, Graphics g) {
int width = s.getWidth(), height = s.getHeight();
g.setColor(SystemColor.control);
g.fillRect(0, 0, width, height);
g.setColor(SystemColor.menu);
g.drawLine(0, height-1, width-1, height-1);
g.setFont(s.getFont());
g.setColor(SystemColor.menuText);
int selected = s.getSelectedItemIndex();
for (int i=0; i<s.getItemCount(); i++) {
MenuItemState is = s.getItem(i);
Rectangle item = is.getItemBounds();
Rectangle text = is.getTextBounds();
if (!is.isEnabled()) {
g.setColor(SystemColor.textInactiveText);
} else if (i == selected) {
g.setColor(SystemColor.textHighlight);
g.fillRect(item.x, item.y, item.width, item.height);
g.setColor(SystemColor.textHighlightText);
} else {
g.setColor(SystemColor.menuText);
}
g.drawString(is.getText(), item.x + text.x, item.y + text.y);
}
}
示例4: getItemIndex
import org.apache.harmony.awt.state.MenuBarState; //导入依赖的package包/类
public static int getItemIndex(MenuBarState s, Point p) {
for (int i=0; i<s.getItemCount(); i++) {
MenuItemState is = s.getItem(i);
Rectangle bounds = is.getItemBounds();
if (bounds.contains(p)) {
return i;
}
}
return -1;
}
示例5: getItemLocation
import org.apache.harmony.awt.state.MenuBarState; //导入依赖的package包/类
public static Point getItemLocation(MenuBarState s, int index) {
if (index < 0 || index >= s.getItemCount()) {
return new Point(-1, -1);
}
MenuItemState is = s.getItem(index);
Rectangle bounds = is.getItemBounds();
Point where = new Point(bounds.x, bounds.y + bounds.height);
Point screenPos = s.getLocationOnScreen();
where.translate(screenPos.x, screenPos.y);
return where;
}
示例6: drawMenuBar
import org.apache.harmony.awt.state.MenuBarState; //导入依赖的package包/类
public void drawMenuBar(MenuBarState s, Graphics gr) {
DefaultMenuBar.drawMenuBar(s, gr);
}
示例7: layoutMenuBar
import org.apache.harmony.awt.state.MenuBarState; //导入依赖的package包/类
public void layoutMenuBar(MenuBarState s, int width) {
DefaultMenuBar.layoutMenuBar(s, width);
}
示例8: getMenuBarItemIndex
import org.apache.harmony.awt.state.MenuBarState; //导入依赖的package包/类
public int getMenuBarItemIndex(MenuBarState s, Point p) {
return DefaultMenuBar.getItemIndex(s, p);
}
示例9: getMenuBarItemLocation
import org.apache.harmony.awt.state.MenuBarState; //导入依赖的package包/类
public Point getMenuBarItemLocation(MenuBarState s, int index) {
return DefaultMenuBar.getItemLocation(s, index);
}