SVMenuItem.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.events.SVEventType;
  20. import javax.swing.JMenuItem;
  21. /**
  22. * Constructs a new menulistitem which also has a value and a description. For
  23. * these, we will not have to ask the server what the value is when the user
  24. * wants to change it, but can just call the client with the new value.
  25. */
  26. class SVMenuItem extends SVAbstractMenuItem {
  27. public String value = null;
  28. public String desc = null;
  29. SVMenuItem(int id, String name, String v, String d) {
  30. super(id, name, new JMenuItem(name));
  31. value = v;
  32. desc = d;
  33. }
  34. /**
  35. * Ask the user for new input for a variable and send it.
  36. * Depending on whether there is a description given for the entry, show
  37. * the description in the dialog or just show the name.
  38. */
  39. @Override
  40. public void performAction(SVWindow window, SVEventType eventType) {
  41. if (desc != null) {
  42. window.showInputDialog(desc, value, id, eventType);
  43. } else {
  44. window.showInputDialog(name, value, id, eventType);
  45. }
  46. }
  47. /** Returns the actual value of the MenuListItem. */
  48. @Override
  49. public String getValue() {
  50. return value;
  51. }
  52. }