SVCheckboxMenuItem.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2007 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"); You may not
  4. // use this file except in compliance with the License. You may obtain a copy of
  5. // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
  6. // applicable law or agreed to in writing, software distributed under the
  7. // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
  8. // OF ANY KIND, either express or implied. See the License for the specific
  9. // language governing permissions and limitations under the License.
  10. package com.google.scrollview.ui;
  11. /**
  12. * A MenuListItem is any sort of menu entry. This can either be within a popup
  13. * menu or within a menubar. It can either be a submenu (only name and
  14. * command-id) or a name with an associated value and possibly description. They
  15. * can also have new entries added (if they are submenus).
  16. *
  17. * @author wanke@google.com
  18. */
  19. import com.google.scrollview.ScrollView;
  20. import com.google.scrollview.events.SVEvent;
  21. import com.google.scrollview.events.SVEventType;
  22. import javax.swing.JCheckBoxMenuItem;
  23. /**
  24. * Constructs a new menulistitem which possesses a flag that can be toggled.
  25. */
  26. class SVCheckboxMenuItem extends SVAbstractMenuItem {
  27. public boolean bvalue;
  28. SVCheckboxMenuItem(int id, String name, boolean val) {
  29. super(id, name, new JCheckBoxMenuItem(name, val));
  30. bvalue = val;
  31. }
  32. /** What to do when user clicks on this item. */
  33. @Override
  34. public void performAction(SVWindow window, SVEventType eventType) {
  35. // Checkbox entry - trigger and send event.
  36. if (bvalue) {
  37. bvalue = false;
  38. } else {
  39. bvalue = true;
  40. }
  41. SVEvent svme = new SVEvent(eventType, window, id, getValue());
  42. ScrollView.addMessage(svme);
  43. }
  44. /** Returns the actual value of the MenuListItem. */
  45. @Override
  46. public String getValue() {
  47. return Boolean.toString(bvalue);
  48. }
  49. }