/plugins/LaTeXTools/tags/release-0-5-4/uk/co/antroy/latextools/macros/ErrorFindingMacros.java

# · Java · 139 lines · 91 code · 29 blank · 19 comment · 8 complexity · 4399de5691edf458d1a17d495f7bc442 MD5 · raw file

  1. /*:folding=indent:
  2. * ErrorFindingMacros.java - Macros to parse for obvious errors.
  3. * Copyright (C) 2003 Anthony Roy
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. package uk.co.antroy.latextools.macros;
  20. import java.awt.event.MouseAdapter;
  21. import java.awt.event.MouseEvent;
  22. import java.util.ArrayList;
  23. import java.util.HashSet;
  24. import java.util.Iterator;
  25. import java.util.List;
  26. import java.util.Set;
  27. import javax.swing.JComponent;
  28. import javax.swing.JLabel;
  29. import javax.swing.JList;
  30. import javax.swing.JScrollPane;
  31. import org.gjt.sp.jedit.Buffer;
  32. import org.gjt.sp.jedit.View;
  33. import uk.co.antroy.latextools.parsers.LaTeXAsset;
  34. import uk.co.antroy.latextools.LaTeXDockable;
  35. import uk.co.antroy.latextools.parsers.LabelParser;
  36. public class ErrorFindingMacros {
  37. //~ Methods ...............................................................
  38. public static void _displayDuplicateLabels(final View view, Buffer buff) {
  39. LaTeXDockable dockable = LaTeXDockable.getInstance();
  40. dockable.setInfoPanel(new JLabel("<html><font color='#dd0000'>Working..."),
  41. "Orphaned References:");
  42. LabelParser parser = new LabelParser(view, buff);
  43. List duplicates = parser.getDuplicateList();
  44. JComponent out = null;
  45. if (duplicates.size() == 0) {
  46. out = new JLabel("Success! No Duplicates Found!");
  47. } else {
  48. final JList list = new JList(duplicates.toArray());
  49. list.addMouseListener(new MouseAdapter() {
  50. public void mouseClicked(MouseEvent e) {
  51. LaTeXAsset asset = (LaTeXAsset)list.getSelectedValue();
  52. TextMacros.visitAsset(view, asset);
  53. }
  54. });
  55. out = new JScrollPane(list,
  56. JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  57. JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  58. }
  59. dockable.setInfoPanel(out, "Duplicate Labels:");
  60. }
  61. public static void _displayOrphanedRefs(final View view, Buffer buff) {
  62. LaTeXDockable.getInstance().setInfoPanel(new JLabel("<html><font color='#dd0000'>Working..."),
  63. "Orphaned References:");
  64. LabelParser labParser = new LabelParser(view, buff);
  65. Set labels = labParser.getLabelNameSet();
  66. LabelParser refParser = new LabelParser(view, buff, LabelParser.REF);
  67. Set refs = new HashSet(refParser.getLabelList());
  68. List orphans = new ArrayList();
  69. for (Iterator it = refs.iterator(); it.hasNext();) {
  70. LaTeXAsset asset = (LaTeXAsset)it.next();
  71. String name = asset.getShortString();
  72. if (!labels.contains(name)) {
  73. orphans.add(asset);
  74. }
  75. }
  76. JComponent out = null;
  77. if (orphans.size() == 0) {
  78. out = new JLabel("Success! No Orphaned References Found!");
  79. } else {
  80. final JList list = new JList(orphans.toArray());
  81. list.addMouseListener(new MouseAdapter() {
  82. public void mouseClicked(MouseEvent e) {
  83. LaTeXAsset asset = (LaTeXAsset)list.getSelectedValue();
  84. TextMacros.visitAsset(view, asset);
  85. }
  86. });
  87. out = new JScrollPane(list,
  88. JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
  89. JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  90. }
  91. LaTeXDockable.getInstance().setInfoPanel(out, "Orphaned References:");
  92. }
  93. public static void displayDuplicateLabels(final View view,
  94. final Buffer buff) {
  95. Thread t = new Thread(new Runnable() {
  96. public void run() {
  97. _displayDuplicateLabels(view, buff);
  98. }
  99. });
  100. t.start();
  101. }
  102. public static void displayOrphanedRefs(final View view, final Buffer buff) {
  103. Thread t = new Thread(new Runnable() {
  104. public void run() {
  105. _displayOrphanedRefs(view, buff);
  106. }
  107. });
  108. t.start();
  109. }
  110. }