1. package org.jr.swing;
  2. /**
  3. * Copyright: Copyright (c) 2002-2004
  4. * Company: JavaResearch(http://www.javaresearch.org)
  5. * 最后更新日期:2003年3月7日
  6. * @author Cherami
  7. */
  8. import org.jr.*;
  9. /**
  10. * 工具栏的图像按钮的相关属性的抽象类。
  11. * <p>包括按钮的显示文字,提示信息,图像文件的文件名
  12. * @since 0.4
  13. */
  14. public class ButtonProperty
  15. extends CharSplitProperty {
  16. /**
  17. * 按钮的显示文字。
  18. * @since 0.4
  19. */
  20. public final String text;
  21. /**
  22. * 按钮的提示信息。
  23. * @since 0.4
  24. */
  25. public final String tooltip;
  26. /**
  27. * 图像文件的路径。
  28. * @since 0.4
  29. */
  30. public final String image;
  31. /**
  32. * 显示文字的属性索引。
  33. * @since 0.4
  34. */
  35. public static final int TEXT = 0;
  36. /**
  37. * 提示信息的属性索引。
  38. * @since 0.4
  39. */
  40. public static final int TOOLTIP = 1;
  41. /**
  42. * 图像路径的属性索引。
  43. * @since 0.4
  44. */
  45. public static final int IMAGE = 2;
  46. private static final int LEAST_PROPERTY = 1;
  47. private static final int PROPERTY_COUNT = 3;
  48. /**
  49. * 构造方法,根据原始信息解析得到需要的各个子信息,解析的分隔符为'*'。
  50. * @param source 未经解析的原始信息
  51. * @since 0.4
  52. */
  53. public ButtonProperty(String source) {
  54. this(source, '*');
  55. }
  56. /**
  57. * 构造方法,根据原始信息解析得到需要的各个子信息。
  58. * @param source 未经解析的原始信息
  59. * @param splitChar 解析的分隔符
  60. * @since 0.4
  61. */
  62. public ButtonProperty(String source, char splitChar) {
  63. super(source, splitChar);
  64. text = getProperty(TEXT);
  65. tooltip = getProperty(TOOLTIP);
  66. image = getProperty(IMAGE);
  67. }
  68. /**
  69. * 得到属性应有的最少个数。
  70. * @return 属性应有的最少个数,现在值为1。
  71. * @since 0.4
  72. */
  73. public int getLeastPropertyCount() {
  74. return LEAST_PROPERTY;
  75. }
  76. /**
  77. * 得到属性应有的个数。
  78. * 由于对于具体的的项目而言,其需要的属性个数是不同的,因此此方法被定义为抽象的。
  79. * @return 应有的属性个数
  80. * @since 0.4
  81. */
  82. public int getPropertyCount() {
  83. return PROPERTY_COUNT;
  84. }
  85. /**
  86. * 得到属性数组中的指定索引的属性不存在时的返回值。
  87. * @param index 属性数组中的索引
  88. * @return 属性数组中的指定索引的属性不存在时的返回值
  89. * @since 0.4
  90. */
  91. public String getDefaultProperty(int index) {
  92. switch (index) {
  93. case TEXT:
  94. return "Button " + getNumber();
  95. case TOOLTIP:
  96. return "press this button";
  97. case IMAGE:
  98. return "";
  99. default:
  100. return "";
  101. }
  102. }
  103. }