PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/gui/ErrorListDialog.java

#
Java | 185 lines | 122 code | 30 blank | 33 comment | 14 complexity | 5f462d693c3239597024ad2f6b6aacaa MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * ErrorListDialog.java - Used to list I/O and plugin load errors
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2001 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.gui;
  23. //{{{ Imports
  24. import java.awt.*;
  25. import java.awt.event.*;
  26. import java.util.Vector;
  27. import javax.swing.*;
  28. import javax.swing.border.*;
  29. import org.gjt.sp.jedit.*;
  30. import org.gjt.sp.util.Log;
  31. //}}}
  32. public class ErrorListDialog extends EnhancedDialog
  33. {
  34. //{{{ ErrorEntry class
  35. public static class ErrorEntry
  36. {
  37. String path;
  38. String[] messages;
  39. public ErrorEntry(String path, String messageProp, Object[] args)
  40. {
  41. this.path = path;
  42. String message = jEdit.getProperty(messageProp,args);
  43. if(message == null)
  44. message = "Undefined property: " + messageProp;
  45. Log.log(Log.ERROR,this,path + ":");
  46. Log.log(Log.ERROR,this,message);
  47. Vector tokenizedMessage = new Vector();
  48. int lastIndex = -1;
  49. for(int i = 0; i < message.length(); i++)
  50. {
  51. if(message.charAt(i) == '\n')
  52. {
  53. tokenizedMessage.addElement(message.substring(
  54. lastIndex + 1,i));
  55. lastIndex = i;
  56. }
  57. }
  58. if(lastIndex != message.length())
  59. {
  60. tokenizedMessage.addElement(message.substring(
  61. lastIndex + 1));
  62. }
  63. messages = new String[tokenizedMessage.size()];
  64. tokenizedMessage.copyInto(messages);
  65. }
  66. public boolean equals(Object o)
  67. {
  68. if(o instanceof ErrorEntry)
  69. {
  70. ErrorEntry e = (ErrorEntry)o;
  71. return e.path.equals(path);
  72. }
  73. else
  74. return false;
  75. }
  76. } //}}}
  77. //{{{ ErrorListDialog constructor
  78. public ErrorListDialog(Frame frame, String title, String caption,
  79. Vector messages, boolean pluginError)
  80. {
  81. super(frame,title,!pluginError);
  82. JPanel content = new JPanel(new BorderLayout(12,12));
  83. content.setBorder(new EmptyBorder(12,12,12,12));
  84. setContentPane(content);
  85. Box iconBox = new Box(BoxLayout.Y_AXIS);
  86. iconBox.add(new JLabel(UIManager.getIcon("OptionPane.errorIcon")));
  87. iconBox.add(Box.createGlue());
  88. content.add(BorderLayout.WEST,iconBox);
  89. JPanel centerPanel = new JPanel(new BorderLayout());
  90. JLabel label = new JLabel(caption);
  91. label.setBorder(new EmptyBorder(0,0,6,0));
  92. centerPanel.add(BorderLayout.NORTH,label);
  93. JList errors = new JList(messages);
  94. errors.setCellRenderer(new ErrorListCellRenderer());
  95. errors.setVisibleRowCount(Math.min(messages.size(),4));
  96. // need this bullshit scroll bar policy for the preferred size
  97. // hack to work
  98. JScrollPane scrollPane = new JScrollPane(errors,
  99. JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
  100. JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  101. Dimension size = scrollPane.getPreferredSize();
  102. size.width = Math.min(size.width,400);
  103. scrollPane.setPreferredSize(size);
  104. centerPanel.add(BorderLayout.CENTER,scrollPane);
  105. content.add(BorderLayout.CENTER,centerPanel);
  106. Box buttons = new Box(BoxLayout.X_AXIS);
  107. buttons.add(Box.createGlue());
  108. ok = new JButton(jEdit.getProperty("common.ok"));
  109. ok.addActionListener(new ActionHandler());
  110. if(pluginError)
  111. {
  112. pluginMgr = new JButton(jEdit.getProperty("error-list.plugin-manager"));
  113. pluginMgr.addActionListener(new ActionHandler());
  114. buttons.add(pluginMgr);
  115. buttons.add(Box.createHorizontalStrut(6));
  116. }
  117. buttons.add(ok);
  118. buttons.add(Box.createGlue());
  119. content.add(BorderLayout.SOUTH,buttons);
  120. getRootPane().setDefaultButton(ok);
  121. pack();
  122. setLocationRelativeTo(frame);
  123. show();
  124. } //}}}
  125. //{{{ ok() method
  126. public void ok()
  127. {
  128. dispose();
  129. } //}}}
  130. //{{{ cancel() method
  131. public void cancel()
  132. {
  133. dispose();
  134. } //}}}
  135. //{{{ Private members
  136. private JButton ok, pluginMgr;
  137. //}}}
  138. //{{{ ActionHandler class
  139. class ActionHandler implements ActionListener
  140. {
  141. //{{{ actionPerformed() method
  142. public void actionPerformed(ActionEvent evt)
  143. {
  144. if(evt.getSource() == ok)
  145. dispose();
  146. else if(evt.getSource() == pluginMgr)
  147. {
  148. org.gjt.sp.jedit.pluginmgr.PluginManager
  149. .showPluginManager(JOptionPane
  150. .getFrameForComponent(
  151. ErrorListDialog.this));
  152. }
  153. } //}}}
  154. } //}}}
  155. }