You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/09/11 16:53:14 UTC
svn commit: r813865 - in
/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: ./ content/ skin/
skin/terra/
Author: gbrown
Date: Fri Sep 11 14:53:13 2009
New Revision: 813865
URL: http://svn.apache.org/viewvc?rev=813865&view=rev
Log:
Resolve issue PIVOT-290.
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBar.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/MenuBarItemDataRenderer.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/MenuItemDataRenderer.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuBarItemSkin.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuBarItemSkin.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuItemSkin.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java?rev=813865&r1=813864&r2=813865&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Menu.java Fri Sep 11 14:53:13 2009
@@ -86,6 +86,8 @@
+ Menu.class.getName());
}
+ setActive(false);
+
super.setParent(parent);
}
@@ -163,35 +165,34 @@
public void setActive(boolean active) {
if (active
- && !isEnabled()) {
+ && (getParent() == null
+ || !isEnabled())) {
throw new IllegalStateException();
}
if (this.active != active) {
this.active = active;
- if (section != null
- && section.menu != null) {
- // Update the active item
- Item activeItem = section.menu.getActiveItem();
-
- if (active) {
- // Set this as the new active item (do this before
- // de-selecting any currently active item so the
- // menu bar's change event isn't fired twice)
- section.menu.setActiveItem(this);
-
- // Deactivate any previously active item
- if (activeItem != null) {
- activeItem.setActive(false);
- }
+ // Update the active item
+ Menu menu = (Menu)getParent();
+ Item activeItem = menu.getActiveItem();
+
+ if (active) {
+ // Set this as the new active item (do this before
+ // de-selecting any currently active item so the
+ // menu bar's change event isn't fired twice)
+ menu.setActiveItem(this);
+
+ // Deactivate any previously active item
+ if (activeItem != null) {
+ activeItem.setActive(false);
}
- else {
- // If this item is currently active, clear the
- // selection
- if (activeItem == this) {
- section.menu.setActiveItem(null);
- }
+ }
+ else {
+ // If this item is currently active, clear the
+ // selection
+ if (activeItem == this) {
+ menu.setActiveItem(null);
}
}
@@ -214,11 +215,16 @@
if (menu == null) {
Item item = this;
- while (item != null
- && item.section != null
- && item.section.menu != null) {
- item.section.menu.menuItemSelectionListeners.itemSelected(this);
- item = item.section.menu.item;
+
+ while (item != null) {
+ Menu menu = (Menu)item.getParent();
+
+ if (menu == null) {
+ item = null;
+ } else {
+ menu.menuItemSelectionListeners.itemSelected(this);
+ item = menu.item;
+ }
}
}
}
@@ -742,11 +748,12 @@
@Override
public Sequence<Component> remove(int index, int count) {
for (int i = index, n = index + count; i < n; i++) {
- Item item = (Item)get(i);
+ Component component = get(i);
- if (item.getSection() != null
- && item.getSection().getMenu() != null) {
- throw new UnsupportedOperationException();
+ for (Section section : sections) {
+ if (section.indexOf((Menu.Item)component) >= 0) {
+ throw new UnsupportedOperationException();
+ }
}
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBar.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBar.java?rev=813865&r1=813864&r2=813865&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBar.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/MenuBar.java Fri Sep 11 14:53:13 2009
@@ -49,7 +49,6 @@
}
}
- private MenuBar menuBar = null;
private Menu menu = null;
private boolean active = false;
@@ -75,6 +74,8 @@
+ MenuBar.class.getName());
}
+ setActive(false);
+
super.setParent(parent);
}
@@ -87,28 +88,6 @@
}
}
- public MenuBar getMenuBar() {
- return menuBar;
- }
-
- private void setMenuBar(MenuBar menuBar) {
- MenuBar previousMenuBar = this.menuBar;
-
- if (previousMenuBar != menuBar) {
- this.menuBar = menuBar;
-
- if (isActive()) {
- if (previousMenuBar != null) {
- previousMenuBar.setActiveItem(null);
- }
-
- if (menuBar != null) {
- menuBar.setActiveItem(this);
- }
- }
- }
- }
-
public Menu getMenu() {
return menu;
}
@@ -133,34 +112,34 @@
public void setActive(boolean active) {
if (active
- && !isEnabled()) {
+ && (getParent() == null
+ || !isEnabled())) {
throw new IllegalStateException();
}
if (this.active != active) {
this.active = active;
- if (menuBar != null) {
- // Update the active item
- Item activeItem = menuBar.getActiveItem();
-
- if (active) {
- // Set this as the new active item (do this before
- // de-selecting any currently active item so the
- // menu bar's change event isn't fired twice)
- menuBar.setActiveItem(this);
-
- // Deactivate any previously active item
- if (activeItem != null) {
- activeItem.setActive(false);
- }
+ // Update the active item
+ MenuBar menuBar = (MenuBar)getParent();
+ Item activeItem = menuBar.getActiveItem();
+
+ if (active) {
+ // Set this as the new active item (do this before
+ // de-selecting any currently active item so the
+ // menu bar's change event isn't fired twice)
+ menuBar.setActiveItem(this);
+
+ // Deactivate any previously active item
+ if (activeItem != null) {
+ activeItem.setActive(false);
}
- else {
- // If this item is currently active, clear the
- // selection
- if (activeItem == this) {
- menuBar.setActiveItem(null);
- }
+ }
+ else {
+ // If this item is currently active, clear the
+ // selection
+ if (activeItem == this) {
+ menuBar.setActiveItem(null);
}
}
@@ -206,13 +185,8 @@
@Override
public void insert(Item item, int index) {
- if (item.getMenuBar() != null) {
- throw new IllegalArgumentException("item already has a menu bar.");
- }
-
MenuBar.this.add(item);
items.insert(item, index);
- item.setMenuBar(MenuBar.this);
menuBarListeners.itemInserted(MenuBar.this, index);
}
@@ -238,8 +212,8 @@
for (int i = 0, n = removed.getLength(); i < n; i++) {
Item item = removed.get(i);
- item.setGroup((Button.Group)null);
- item.setMenuBar(null);
+ item.setActive(false);
+
MenuBar.this.remove(item);
}
@@ -361,20 +335,6 @@
}
}
- @Override
- public Sequence<Component> remove(int index, int count) {
- for (int i = index, n = index + count; i < n; i++) {
- Item item = (Item)get(i);
-
- if (item.getMenuBar() != null) {
- throw new UnsupportedOperationException();
- }
- }
-
- // Call the base method to remove the components
- return super.remove(index, count);
- }
-
public ListenerList<MenuBarListener> getMenuBarListeners() {
return menuBarListeners;
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/MenuBarItemDataRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/MenuBarItemDataRenderer.java?rev=813865&r1=813864&r2=813865&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/MenuBarItemDataRenderer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/MenuBarItemDataRenderer.java Fri Sep 11 14:53:13 2009
@@ -75,7 +75,7 @@
// Update the image view
MenuBar.Item menuBarItem = (MenuBar.Item)button;
- MenuBar menuBar = menuBarItem.getMenuBar();
+ MenuBar menuBar = (MenuBar)menuBarItem.getParent();
if (icon == null) {
imageView.setVisible(false);
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/MenuItemDataRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/MenuItemDataRenderer.java?rev=813865&r1=813864&r2=813865&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/MenuItemDataRenderer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/MenuItemDataRenderer.java Fri Sep 11 14:53:13 2009
@@ -99,7 +99,7 @@
// Update the image view
Menu.Item menuItem = (Menu.Item)button;
- Menu menu = menuItem.getSection().getMenu();
+ Menu menu = (Menu)menuItem.getParent();
int margin = (Integer)menu.getStyles().get("margin");
Insets padding = (Insets)getStyles().get("padding");
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuBarItemSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuBarItemSkin.java?rev=813865&r1=813864&r2=813865&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuBarItemSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/MenuBarItemSkin.java Fri Sep 11 14:53:13 2009
@@ -43,7 +43,7 @@
boolean consumed = false;
MenuBar.Item menuBarItem = (MenuBar.Item)getComponent();
- MenuBar menuBar = menuBarItem.getMenuBar();
+ MenuBar menuBar = (MenuBar)menuBarItem.getParent();
if (keyCode == Keyboard.KeyCode.LEFT
|| (keyCode == Keyboard.KeyCode.TAB
@@ -75,7 +75,7 @@
// If the menu bar is no longer active, move the window to the
// front to restore focus
- MenuBar menuBar = menuBarItem.getMenuBar();
+ MenuBar menuBar = (MenuBar)menuBarItem.getParent();
if (menuBar.getActiveItem() == null) {
Window menuBarWindow = menuBar.getWindow();
@@ -142,7 +142,7 @@
super.mouseOver(component);
MenuBar.Item menuBarItem = (MenuBar.Item)getComponent();
- MenuBar menuBar = menuBarItem.getMenuBar();
+ MenuBar menuBar = (MenuBar)menuBarItem.getParent();
if (menuBar.getActiveItem() != null) {
menuBarItem.setActive(true);
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuBarItemSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuBarItemSkin.java?rev=813865&r1=813864&r2=813865&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuBarItemSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuBarItemSkin.java Fri Sep 11 14:53:13 2009
@@ -86,7 +86,7 @@
// Paint highlight state
if (highlight) {
- MenuBar menuBar = menuBarItem.getMenuBar();
+ MenuBar menuBar = (MenuBar)menuBarItem.getParent();
Color activeBackgroundColor = (Color)menuBar.getStyles().get("activeBackgroundColor");
graphics.setColor(activeBackgroundColor);
graphics.fillRect(0, 0, width, height);
@@ -107,7 +107,7 @@
MenuBar.Item menuBarItem = (MenuBar.Item)getComponent();
if (menuBarItem.isActive()) {
- MenuBar menuBar = menuBarItem.getMenuBar();
+ MenuBar menuBar = (MenuBar)menuBarItem.getParent();
Color activeBackgroundColor = (Color)menuBar.getStyles().get("activeBackgroundColor");
opaque = (activeBackgroundColor.getTransparency() == Transparency.OPAQUE);
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuItemSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuItemSkin.java?rev=813865&r1=813864&r2=813865&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuItemSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraMenuItemSkin.java Fri Sep 11 14:53:13 2009
@@ -53,7 +53,7 @@
@Override
public void paint(Graphics2D graphics) {
Menu.Item menuItem = (Menu.Item)getComponent();
- Menu menu = menuItem.getSection().getMenu();
+ Menu menu = (Menu)menuItem.getParent();
Color color = (Color)menu.getStyles().get("color");
graphics.setColor(color);
@@ -129,7 +129,7 @@
@Override
public void paint(Graphics2D graphics) {
Menu.Item menuItem = (Menu.Item)getComponent();
- Menu menu = menuItem.getSection().getMenu();
+ Menu menu = (Menu)menuItem.getParent();
int width = getWidth();
int height = getHeight();
@@ -178,7 +178,7 @@
Menu.Item menuItem = (Menu.Item)getComponent();
if (menuItem.isActive()) {
- Menu menu = menuItem.getSection().getMenu();
+ Menu menu = (Menu)menuItem.getParent();
Color activeBackgroundColor = (Color)menu.getStyles().get("activeBackgroundColor");
opaque = (activeBackgroundColor.getTransparency() == Transparency.OPAQUE);
}