/plugins/JavaSideKick/tags/javasidekick-3-1-0/src/sidekick/java/node/TigerLabeler.java

#
Java | 786 lines | 647 code | 40 blank | 99 comment | 117 complexity | 725f2c90e3fb5a90da2f754e1358c78b MD5 | raw file

✨ Summary
  1. /*
  2. Copyright (c) 2005, Dale Anson
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without modification,
  5. are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. * Neither the name of the <ORGANIZATION> nor the names of its contributors
  12. may be used to endorse or promote products derived from this software without
  13. specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  21. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. package sidekick.java.node;
  26. import java.awt.*;
  27. import java.awt.event.*;
  28. import javax.swing.*;
  29. import javax.swing.event.*;
  30. import javax.swing.tree.*;
  31. import org.gjt.sp.jedit.jEdit;
  32. import org.gjt.sp.jedit.GUIUtilities;
  33. import eclipseicons.EclipseIconsPlugin;
  34. import sidekick.java.options.*;
  35. /**
  36. * Most of the display settings (how to show) are handled here.
  37. *
  38. * @author Dale Anson
  39. * @version $Revision: 18719 $
  40. */
  41. public class TigerLabeler {
  42. // current option settings
  43. private static OptionValues options = null;
  44. // various icons for display
  45. protected static ImageIcon CU_ICON = null;
  46. protected static ImageIcon IMPORT_ICON = null;
  47. protected static ImageIcon ERROR_ICON = null;
  48. protected static ImageIcon CLASS_ICON = null;
  49. protected static ImageIcon INNER_CLASS_ICON = null;
  50. protected static ImageIcon EXTENDS_ICON = null;
  51. protected static ImageIcon IMPLEMENTS_ICON = null;
  52. protected static ImageIcon INTERFACE_ICON = null;
  53. protected static ImageIcon CONSTRUCTOR_ICON = null;
  54. protected static ImageIcon METHOD_ICON = null;
  55. protected static ImageIcon THROWS_ICON = null;
  56. protected static ImageIcon FIELD_ICON = null;
  57. protected static ImageIcon ENUM_ICON = null;
  58. protected static ImageIcon REGEX_PRODUCTION_ICON = null;
  59. protected static ImageIcon TOKEN_MGR_PRODUCTION_ICON = null;
  60. protected static ImageIcon JAVA_PRODUCTION_ICON = null;
  61. protected static ImageIcon BNF_PRODUCTION_ICON = null;
  62. protected static ImageIcon DEFAULT_ICON = null;
  63. // eclipse-style icons
  64. protected static ImageIcon E_CU_ICON = null;
  65. protected static ImageIcon E_IMPORT_ICON = null;
  66. protected static ImageIcon E_ERROR_ICON = null;
  67. protected static ImageIcon E_CLASS_ICON = null;
  68. protected static ImageIcon E_INNER_CLASS_DEFAULT_ICON = null;
  69. protected static ImageIcon E_INNER_CLASS_PUBLIC_ICON = null;
  70. protected static ImageIcon E_INNER_CLASS_PROTECTED_ICON = null;
  71. protected static ImageIcon E_INNER_CLASS_PRIVATE_ICON = null;
  72. protected static ImageIcon E_INTERFACE_ICON = null;
  73. protected static ImageIcon E_CONSTRUCTOR_ICON = null;
  74. protected static ImageIcon E_METHOD_DEFAULT_ICON = null;
  75. protected static ImageIcon E_METHOD_PUBLIC_ICON = null;
  76. protected static ImageIcon E_METHOD_PROTECTED_ICON = null;
  77. protected static ImageIcon E_METHOD_PRIVATE_ICON = null;
  78. protected static ImageIcon E_FIELD_DEFAULT_ICON = null;
  79. protected static ImageIcon E_FIELD_PUBLIC_ICON = null;
  80. protected static ImageIcon E_FIELD_PROTECTED_ICON = null;
  81. protected static ImageIcon E_FIELD_PRIVATE_ICON = null;
  82. protected static ImageIcon E_ENUM_DEFAULT_ICON = null;
  83. protected static ImageIcon E_ENUM_PUBLIC_ICON = null;
  84. protected static ImageIcon E_ENUM_PROTECTED_ICON = null;
  85. protected static ImageIcon E_ENUM_PRIVATE_ICON = null;
  86. protected static ImageIcon E_CONSTRUCTOR_DEC_ICON = null;
  87. protected static ImageIcon E_ABSTRACT_DEC_ICON = null;
  88. protected static ImageIcon E_STATIC_DEC_ICON = null;
  89. protected static ImageIcon E_FINAL_DEC_ICON = null;
  90. // load the icons
  91. static {
  92. // JBrowse icons
  93. try {
  94. CU_ICON = (ImageIcon) GUIUtilities.loadIcon("OpenFile.png");
  95. }
  96. catch (Exception e) { // NOPMD
  97. }
  98. try {
  99. IMPORT_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Import.gif"));
  100. }
  101. catch (Exception e) { // NOPMD
  102. }
  103. try {
  104. ERROR_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Error.gif"));
  105. }
  106. catch (Exception e) { // NOPMD
  107. }
  108. try {
  109. CLASS_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Class.gif"));
  110. }
  111. catch (Exception e) { // NOPMD
  112. }
  113. try {
  114. INNER_CLASS_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/InnerClass.gif"));
  115. }
  116. catch (Exception e) { // NOPMD
  117. }
  118. try {
  119. EXTENDS_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Extends.gif"));
  120. }
  121. catch (Exception e) { // NOPMD
  122. }
  123. try {
  124. IMPLEMENTS_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Implements.gif"));
  125. }
  126. catch (Exception e) { // NOPMD
  127. }
  128. try {
  129. INTERFACE_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Interface.gif"));
  130. }
  131. catch (Exception e) { // NOPMD
  132. }
  133. try {
  134. CONSTRUCTOR_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Constructor.gif"));
  135. }
  136. catch (Exception e) { // NOPMD
  137. }
  138. try {
  139. METHOD_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Method.gif"));
  140. }
  141. catch (Exception e) { // NOPMD
  142. }
  143. try {
  144. THROWS_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Throws.gif"));
  145. }
  146. catch (Exception e) { // NOPMD
  147. }
  148. try {
  149. FIELD_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Field.gif"));
  150. }
  151. catch (Exception e) { // NOPMD
  152. }
  153. try {
  154. ENUM_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Constructor.gif"));
  155. }
  156. catch (Exception e) { // NOPMD
  157. }
  158. try {
  159. DEFAULT_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/Operation.gif"));
  160. }
  161. catch (Exception e) { // NOPMD
  162. }
  163. try {
  164. REGEX_PRODUCTION_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/RegexProduction.gif"));
  165. }
  166. catch (Exception e) { // NOPMD
  167. }
  168. try {
  169. BNF_PRODUCTION_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/BNFProduction.gif"));
  170. }
  171. catch (Exception e) { // NOPMD
  172. }
  173. try {
  174. JAVA_PRODUCTION_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/JavaProduction.gif"));
  175. }
  176. catch (Exception e) { // NOPMD
  177. }
  178. try {
  179. TOKEN_MGR_PRODUCTION_ICON = new ImageIcon(TigerLabeler.class.getClassLoader().getResource("sidekick/java/icons/TokenMgrProduction.gif"));
  180. }
  181. catch (Exception e) { // NOPMD
  182. }
  183. // Eclipse icons
  184. try {
  185. E_CU_ICON = EclipseIconsPlugin.getIcon("jcu_obj.gif");
  186. }
  187. catch (Exception e) { // NOPMD
  188. }
  189. try {
  190. E_IMPORT_ICON = EclipseIconsPlugin.getIcon("imp_obj.gif");
  191. }
  192. catch (Exception e) { // NOPMD
  193. }
  194. try {
  195. E_INNER_CLASS_PUBLIC_ICON = EclipseIconsPlugin.getIcon("innerclass_public_obj.gif");
  196. }
  197. catch (Exception e) { // NOPMD
  198. }
  199. try {
  200. E_INNER_CLASS_PROTECTED_ICON = EclipseIconsPlugin.getIcon("innerclass_protected_obj.gif");
  201. }
  202. catch (Exception e) { // NOPMD
  203. }
  204. try {
  205. E_INNER_CLASS_PRIVATE_ICON = EclipseIconsPlugin.getIcon("innerclass_private_obj.gif");
  206. }
  207. catch (Exception e) { // NOPMD
  208. }
  209. try {
  210. E_INNER_CLASS_DEFAULT_ICON = EclipseIconsPlugin.getIcon("innerclass_default_obj.gif");
  211. }
  212. catch (Exception e) { // NOPMD
  213. }
  214. try {
  215. E_CLASS_ICON = EclipseIconsPlugin.getIcon("class_obj.gif");
  216. }
  217. catch (Exception e) { // NOPMD
  218. }
  219. try {
  220. E_INTERFACE_ICON = EclipseIconsPlugin.getIcon("int_obj.gif");
  221. }
  222. catch (Exception e) { // NOPMD
  223. }
  224. try {
  225. E_METHOD_PUBLIC_ICON = EclipseIconsPlugin.getIcon("methpub_obj.gif");
  226. }
  227. catch (Exception e) { // NOPMD
  228. e.printStackTrace();
  229. }
  230. try {
  231. E_METHOD_PROTECTED_ICON = EclipseIconsPlugin.getIcon("methpro_obj.gif");
  232. }
  233. catch (Exception e) { // NOPMD
  234. }
  235. try {
  236. E_METHOD_PRIVATE_ICON = EclipseIconsPlugin.getIcon("methpri_obj.gif");
  237. }
  238. catch (Exception e) { // NOPMD
  239. }
  240. try {
  241. E_METHOD_DEFAULT_ICON = EclipseIconsPlugin.getIcon("methdef_obj.gif");
  242. }
  243. catch (Exception e) { // NOPMD
  244. }
  245. try {
  246. E_CONSTRUCTOR_DEC_ICON = EclipseIconsPlugin.getIcon("constr_ovr.gif");
  247. }
  248. catch (Exception e) { // NOPMD
  249. }
  250. try {
  251. E_FIELD_PUBLIC_ICON = EclipseIconsPlugin.getIcon("field_public_obj.gif");
  252. }
  253. catch (Exception e) { // NOPMD
  254. }
  255. try {
  256. E_FIELD_PROTECTED_ICON = EclipseIconsPlugin.getIcon("field_protected_obj.gif");
  257. }
  258. catch (Exception e) { // NOPMD
  259. }
  260. try {
  261. E_FIELD_PRIVATE_ICON = EclipseIconsPlugin.getIcon("field_private_obj.gif");
  262. }
  263. catch (Exception e) { // NOPMD
  264. }
  265. try {
  266. E_FIELD_DEFAULT_ICON = EclipseIconsPlugin.getIcon("field_default_obj.gif");
  267. }
  268. catch (Exception e) { // NOPMD
  269. }
  270. try {
  271. E_ENUM_PUBLIC_ICON = EclipseIconsPlugin.getIcon("enum_obj.gif");
  272. }
  273. catch (Exception e) { // NOPMD
  274. }
  275. try {
  276. E_ENUM_PROTECTED_ICON = EclipseIconsPlugin.getIcon("enum_protected_obj.gif");
  277. }
  278. catch (Exception e) { // NOPMD
  279. }
  280. try {
  281. E_ENUM_PRIVATE_ICON = EclipseIconsPlugin.getIcon("enum_private_obj.gif");
  282. }
  283. catch (Exception e) { // NOPMD
  284. }
  285. try {
  286. E_ENUM_DEFAULT_ICON = EclipseIconsPlugin.getIcon("enum_default_obj.gif");
  287. }
  288. catch (Exception e) { // NOPMD
  289. }
  290. try {
  291. E_ABSTRACT_DEC_ICON = EclipseIconsPlugin.getIcon("abstract_co.gif");
  292. }
  293. catch (Exception e) { // NOPMD
  294. }
  295. try {
  296. E_STATIC_DEC_ICON = EclipseIconsPlugin.getIcon("static_co.png");
  297. }
  298. catch (Exception e) { // NOPMD
  299. }
  300. try {
  301. E_FINAL_DEC_ICON = EclipseIconsPlugin.getIcon("final_co.gif");
  302. }
  303. catch (Exception e) { // NOPMD
  304. }
  305. }
  306. /**
  307. * Sets the displayOptions attribute of the TigerLabeler class
  308. *
  309. * @param opts The new displayOptions value
  310. */
  311. public static void setOptionValues(OptionValues opts) {
  312. options = opts;
  313. }
  314. /**
  315. * Gets the icon attribute of the TigerLabeler class
  316. *
  317. * @param tn
  318. * @return The icon value
  319. */
  320. public static Icon getIcon(TigerNode tn) {
  321. if (options == null) {
  322. return null;
  323. }
  324. ImageIcon icon = null;
  325. if (options.getShowIcons()) {
  326. if (options.getShowIconsLikeEclipse()) {
  327. int modifiers = tn.getModifiers();
  328. switch (tn.getOrdinal()) {
  329. case TigerNode.ERROR:
  330. icon = ERROR_ICON;
  331. break;
  332. case TigerNode.COMPILATION_UNIT:
  333. icon = E_CU_ICON;
  334. break;
  335. case TigerNode.IMPORT:
  336. icon = E_IMPORT_ICON;
  337. break;
  338. case TigerNode.CLASS:
  339. if (((ClassNode) tn).isInnerClass()) {
  340. if (ModifierSet.isPublic(modifiers))
  341. icon = E_INNER_CLASS_PUBLIC_ICON;
  342. else if (ModifierSet.isProtected(modifiers))
  343. icon = E_INNER_CLASS_PROTECTED_ICON;
  344. else if (ModifierSet.isPrivate(modifiers))
  345. icon = E_INNER_CLASS_PRIVATE_ICON;
  346. else
  347. icon = E_INNER_CLASS_DEFAULT_ICON;
  348. }
  349. else {
  350. icon = E_CLASS_ICON;
  351. }
  352. icon = addModifiers(modifiers, icon);
  353. break;
  354. case TigerNode.EXTENDS:
  355. icon = EXTENDS_ICON;
  356. break;
  357. case TigerNode.IMPLEMENTS:
  358. icon = IMPLEMENTS_ICON;
  359. break;
  360. case TigerNode.INTERFACE:
  361. icon = E_INTERFACE_ICON;
  362. break;
  363. case TigerNode.CONSTRUCTOR:
  364. ImageIcon bottom;
  365. if (ModifierSet.isPublic(modifiers))
  366. bottom = E_METHOD_PUBLIC_ICON;
  367. else if (ModifierSet.isProtected(modifiers))
  368. bottom = E_METHOD_PROTECTED_ICON;
  369. else if (ModifierSet.isPrivate(modifiers))
  370. bottom = E_METHOD_PRIVATE_ICON;
  371. else
  372. bottom = E_METHOD_DEFAULT_ICON;
  373. ImageIcon top = E_CONSTRUCTOR_DEC_ICON;
  374. icon = blend(bottom, SwingUtilities.SOUTH_WEST, top, SwingUtilities.NORTH_EAST, new Dimension(18, 16));
  375. icon = addModifiers(modifiers, icon);
  376. break;
  377. case TigerNode.METHOD:
  378. if (ModifierSet.isPublic(modifiers))
  379. icon = E_METHOD_PUBLIC_ICON;
  380. else if (ModifierSet.isProtected(modifiers))
  381. icon = E_METHOD_PROTECTED_ICON;
  382. else if (ModifierSet.isPrivate(modifiers))
  383. icon = E_METHOD_PRIVATE_ICON;
  384. else
  385. icon = E_METHOD_DEFAULT_ICON;
  386. icon = addModifiers(modifiers, icon);
  387. break;
  388. case TigerNode.THROWS:
  389. icon = THROWS_ICON;
  390. break;
  391. case TigerNode.FIELD:
  392. if (ModifierSet.isPublic(modifiers))
  393. icon = E_FIELD_PUBLIC_ICON;
  394. else if (ModifierSet.isProtected(modifiers))
  395. icon = E_FIELD_PROTECTED_ICON;
  396. else if (ModifierSet.isPrivate(modifiers))
  397. icon = E_FIELD_PRIVATE_ICON;
  398. else
  399. icon = E_FIELD_DEFAULT_ICON;
  400. icon = addModifiers(modifiers, icon);
  401. break;
  402. case TigerNode.ENUM:
  403. if (ModifierSet.isPublic(modifiers))
  404. icon = E_ENUM_PUBLIC_ICON;
  405. else if (ModifierSet.isProtected(modifiers))
  406. icon = E_ENUM_PROTECTED_ICON;
  407. else if (ModifierSet.isPrivate(modifiers))
  408. icon = E_ENUM_PRIVATE_ICON;
  409. else
  410. icon = E_ENUM_DEFAULT_ICON;
  411. icon = addModifiers(modifiers, icon);
  412. break;
  413. case TigerNode.BNF_PRODUCTION:
  414. icon = BNF_PRODUCTION_ICON;
  415. break;
  416. case TigerNode.REGEX_PRODUCTION:
  417. icon = REGEX_PRODUCTION_ICON;
  418. break;
  419. case TigerNode.JAVA_PRODUCTION:
  420. icon = JAVA_PRODUCTION_ICON;
  421. break;
  422. case TigerNode.TOKEN_MGR_PRODUCTION:
  423. icon = TOKEN_MGR_PRODUCTION_ICON;
  424. break;
  425. default:
  426. icon = DEFAULT_ICON;
  427. break;
  428. }
  429. }
  430. else {
  431. switch (tn.getOrdinal()) {
  432. case TigerNode.ERROR:
  433. icon = ERROR_ICON;
  434. break;
  435. case TigerNode.COMPILATION_UNIT:
  436. icon = CU_ICON;
  437. break;
  438. case TigerNode.IMPORT:
  439. icon = IMPORT_ICON;
  440. break;
  441. case TigerNode.CLASS:
  442. icon = ((ClassNode) tn).isInnerClass() ? INNER_CLASS_ICON : CLASS_ICON;
  443. break;
  444. case TigerNode.EXTENDS:
  445. icon = EXTENDS_ICON;
  446. break;
  447. case TigerNode.IMPLEMENTS:
  448. icon = IMPLEMENTS_ICON;
  449. break;
  450. case TigerNode.INTERFACE:
  451. icon = INTERFACE_ICON;
  452. break;
  453. case TigerNode.CONSTRUCTOR:
  454. icon = CONSTRUCTOR_ICON;
  455. break;
  456. case TigerNode.METHOD:
  457. icon = METHOD_ICON;
  458. break;
  459. case TigerNode.THROWS:
  460. icon = THROWS_ICON;
  461. break;
  462. case TigerNode.FIELD:
  463. icon = FIELD_ICON;
  464. break;
  465. case TigerNode.ENUM:
  466. icon = ENUM_ICON;
  467. break;
  468. case TigerNode.BNF_PRODUCTION:
  469. icon = BNF_PRODUCTION_ICON;
  470. break;
  471. case TigerNode.REGEX_PRODUCTION:
  472. icon = REGEX_PRODUCTION_ICON;
  473. break;
  474. case TigerNode.JAVA_PRODUCTION:
  475. icon = JAVA_PRODUCTION_ICON;
  476. break;
  477. case TigerNode.TOKEN_MGR_PRODUCTION:
  478. icon = TOKEN_MGR_PRODUCTION_ICON;
  479. break;
  480. default:
  481. icon = DEFAULT_ICON;
  482. break;
  483. }
  484. }
  485. }
  486. // may be null to not show an icon
  487. return icon;
  488. }
  489. /**
  490. * Adds a feature to the Modifiers attribute of the TigerLabeler class
  491. *
  492. * @param modifiers The feature to be added to the Modifiers attribute
  493. * @param bottom The feature to be added to the Modifiers attribute
  494. * @return Description of the Returned Value
  495. */
  496. private static ImageIcon addModifiers(int modifiers, ImageIcon bottom) {
  497. ImageIcon icon = bottom;
  498. int width = 18;
  499. if (ModifierSet.isAbstract(modifiers)) {
  500. icon = blend(bottom, SwingUtilities.SOUTH_WEST, E_ABSTRACT_DEC_ICON, SwingUtilities.NORTH_EAST, new Dimension(width, 16));
  501. width += 6;
  502. }
  503. if (ModifierSet.isStatic(modifiers)) {
  504. icon = blend(bottom, SwingUtilities.SOUTH_WEST, E_STATIC_DEC_ICON, SwingUtilities.NORTH_EAST, new Dimension(width, 16));
  505. width += 6;
  506. }
  507. if (ModifierSet.isFinal(modifiers)) {
  508. icon = blend(bottom, SwingUtilities.SOUTH_WEST, E_FINAL_DEC_ICON, SwingUtilities.NORTH_EAST, new Dimension(width, 16));
  509. }
  510. return icon;
  511. }
  512. /**
  513. * Description of the Method
  514. *
  515. * @param bottom
  516. * @param bottomLocation
  517. * @param top
  518. * @param topLocation
  519. * @param minimumSize
  520. * @return Description of the Returned Value
  521. */
  522. private static ImageIcon blend(ImageIcon bottom, int bottomLocation, ImageIcon top, int topLocation, Dimension minimumSize) {
  523. return IconBlender.blend(jEdit.getActiveView(), bottom, bottomLocation, top, topLocation, minimumSize);
  524. }
  525. /**
  526. * Gets the text attribute of the TigerLabeler class
  527. *
  528. * @param tn
  529. * @return The text value
  530. */
  531. public static String getText(TigerNode tn) {
  532. if (tn != null) {
  533. if (options == null) {
  534. return tn.toString();
  535. }
  536. // build the string for the label
  537. StringBuffer sb = new StringBuffer();
  538. // maybe add the line number
  539. if (options.getShowLineNum()) {
  540. sb.append(tn.getStartLocation().line).append(": "); //.append(tn.getStartLocation().column).append("::").append( tn.getEndLocation().line ).append( ": " ).append(tn.getEndLocation().column);
  541. }
  542. // add visibility modifiers, use either +, #, -, or public,
  543. // protected, private
  544. int modifiers = tn.getModifiers();
  545. if (options.getVisSymbols()) {
  546. if (ModifierSet.isPublic(modifiers))
  547. sb.append('+');
  548. else if (ModifierSet.isProtected(modifiers))
  549. sb.append('#');
  550. else if (ModifierSet.isPrivate(modifiers))
  551. sb.append('-');
  552. else
  553. sb.append(' ');
  554. }
  555. else if (options.getVisWords()) {
  556. if (ModifierSet.isPublic(modifiers))
  557. sb.append("public ");
  558. else if (ModifierSet.isProtected(modifiers))
  559. sb.append("protected ");
  560. else if (ModifierSet.isPrivate(modifiers))
  561. sb.append("private ");
  562. else
  563. sb.append(' ');
  564. }
  565. // maybe show keywords, this is the "Keywords specified by icons" setting,
  566. // which seems like an odd choice of words to me. I was expecting icons,
  567. // but I think it means more like "show keywords beside icons"
  568. if (options.getShowIconKeywords()) {
  569. switch (tn.getOrdinal()) {
  570. case TigerNode.CLASS:
  571. sb.append("class ");
  572. break;
  573. case TigerNode.EXTENDS:
  574. sb.append("extends ");
  575. break;
  576. case TigerNode.IMPLEMENTS:
  577. sb.append("implements ");
  578. break;
  579. }
  580. }
  581. // maybe add misc. modifiers, e.g. synchronized, native, transient, etc
  582. if (options.getShowMiscMod()) {
  583. String mods = ModifierSet.modifiersAsString(modifiers);
  584. if (mods != null && mods.length() > 0)
  585. sb.append(mods).append(' ');
  586. }
  587. // for methods and fields, maybe add return type before node name
  588. if (!options.getTypeIsSuffixed()) {
  589. switch (tn.getOrdinal()) {
  590. case TigerNode.CONSTRUCTOR:
  591. sb.append("/*constructor*/");
  592. break;
  593. case TigerNode.METHOD:
  594. case TigerNode.BNF_PRODUCTION:
  595. sb.append(((MethodNode) tn).getReturnType()).append(' ');
  596. break;
  597. case TigerNode.FIELD:
  598. sb.append(((FieldNode) tn).getType()).append(' ');
  599. break;
  600. case TigerNode.ENUM:
  601. sb.append("enum ");
  602. break;
  603. }
  604. }
  605. // maybe qualify inner class/interface name
  606. if (options.getShowNestedName() && tn.getParent() != null &&
  607. (tn.getOrdinal() == TigerNode.CLASS || tn.getOrdinal() == TigerNode.INTERFACE) &&
  608. (tn.getParent().getOrdinal() == TigerNode.CLASS || tn.getParent().getOrdinal() == TigerNode.INTERFACE)) {
  609. sb.append(tn.getParent().getName()).append('.');
  610. }
  611. // add the node name
  612. switch (tn.getOrdinal()) {
  613. case TigerNode.EXTENDS:
  614. sb.append("class ");
  615. break;
  616. case TigerNode.IMPLEMENTS:
  617. sb.append("interface ");
  618. break;
  619. }
  620. sb.append(tn.getName());
  621. // maybe show generics type arguments
  622. if (options.getShowTypeArgs()) {
  623. String typeParams = null;
  624. if (tn.getOrdinal() == TigerNode.CLASS) {
  625. typeParams = ((ClassNode) tn).getTypeParams();
  626. }
  627. else if (tn.getOrdinal() == TigerNode.EXTENDS) {
  628. typeParams = ((ExtendsNode) tn).getTypeParams();
  629. }
  630. else if (tn.getOrdinal() == TigerNode.IMPLEMENTS) {
  631. typeParams = ((ImplementsNode) tn).getTypeParams();
  632. }
  633. else if (tn.getOrdinal() == TigerNode.FIELD) {
  634. typeParams = ((FieldNode) tn).getTypeParams();
  635. }
  636. if (typeParams != null)
  637. sb.append(typeParams);
  638. }
  639. // for constructors and methods, maybe add the arguments
  640. if (options.getShowArguments()) {
  641. if (tn.getOrdinal() == TigerNode.CONSTRUCTOR) {
  642. sb.append('(').append(((ConstructorNode) tn).getFormalParams(options.getShowArgumentNames(), options.getTypeIsSuffixed(), options.getShowMiscMod(), options.getShowTypeArgs())).append(')');
  643. }
  644. else if (tn.getOrdinal() == TigerNode.METHOD || tn.getOrdinal() == TigerNode.BNF_PRODUCTION) {
  645. sb.append('(').append(((MethodNode) tn).getFormalParams(options.getShowArgumentNames(), options.getTypeIsSuffixed(), options.getShowMiscMod(), options.getShowTypeArgs())).append(')');
  646. }
  647. }
  648. // for methods and fields, maybe add return type after node name
  649. if (options.getTypeIsSuffixed()) {
  650. switch (tn.getOrdinal()) {
  651. case TigerNode.CONSTRUCTOR:
  652. sb.append(": &lt;init&gt;");
  653. break;
  654. case TigerNode.METHOD:
  655. case TigerNode.BNF_PRODUCTION:
  656. sb.append(" : ").append(((MethodNode) tn).getReturnType());
  657. break;
  658. case TigerNode.FIELD:
  659. sb.append(" : ").append(((FieldNode) tn).getType());
  660. break;
  661. case TigerNode.ENUM:
  662. sb.append(" : enum");
  663. break;
  664. }
  665. }
  666. String labelText = toHtml(sb.toString());
  667. sb = new StringBuffer();
  668. sb.append("<html>");
  669. // maybe underline static items
  670. if (options.getStaticUlined() && ModifierSet.isStatic(tn.getModifiers())) {
  671. sb.append("<u>");
  672. }
  673. // maybe set abstract items in italics
  674. if (options.getAbstractItalic() && ModifierSet.isAbstract(tn.getModifiers())) {
  675. sb.append("<i>");
  676. }
  677. sb.append(labelText);
  678. return sb.toString();
  679. }
  680. else
  681. return tn.toString();
  682. }
  683. /**
  684. * Gets the toolTipText attribute of the TigerLabeler class
  685. *
  686. * @param tn
  687. * @return The toolTipText value
  688. */
  689. public static String getToolTipText(TigerNode tn) {
  690. return tn.toString();
  691. }
  692. /**
  693. * Description of the Method
  694. *
  695. * @param s
  696. * @return Description of the Returned Value
  697. */
  698. private static String toHtml(String s) {
  699. s = s.replaceAll("<", "&lt;");
  700. s = s.replaceAll(">", "&gt;");
  701. return s;
  702. }
  703. public static ImageIcon getMethodIcon() {
  704. if (!options.getShowIcons()) return null;
  705. if (options.getShowIconsLikeEclipse()) {
  706. return E_METHOD_DEFAULT_ICON;
  707. }
  708. return METHOD_ICON;
  709. }
  710. public static ImageIcon getFieldIcon() {
  711. if (!options.getShowIcons()) return null;
  712. if (options.getShowIconsLikeEclipse()) {
  713. return E_FIELD_DEFAULT_ICON;
  714. }
  715. return FIELD_ICON;
  716. }
  717. public static ImageIcon getConstructorIcon() {
  718. if (!options.getShowIcons()) return null;
  719. if (options.getShowIconsLikeEclipse()) {
  720. return E_CONSTRUCTOR_ICON;
  721. }
  722. return CONSTRUCTOR_ICON;
  723. }
  724. public static ImageIcon getClassIcon() {
  725. if (!options.getShowIcons()) return null;
  726. if (options.getShowIconsLikeEclipse()) {
  727. return E_CLASS_ICON;
  728. }
  729. return CLASS_ICON;
  730. }
  731. public static ImageIcon getInnerClassIcon(boolean isInterface, boolean isEnum) {
  732. if (!options.getShowIcons()) return null;
  733. if (options.getShowIconsLikeEclipse()) {
  734. if (isInterface)
  735. return E_INTERFACE_ICON;
  736. else if (isEnum)
  737. return E_ENUM_DEFAULT_ICON;
  738. return E_INNER_CLASS_DEFAULT_ICON;
  739. }
  740. if (isInterface)
  741. return INTERFACE_ICON;
  742. else if (isEnum)
  743. return ENUM_ICON;
  744. return INNER_CLASS_ICON;
  745. }
  746. }