PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/gui/ErrorListDialog.java

#
Java | 169 lines | 108 code | 28 blank | 33 comment | 13 complexity | 21dc51b61cf0b1e01e2741068b765574 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 javax.swing.*;
  25. import javax.swing.border.*;
  26. import java.awt.*;
  27. import java.awt.event.*;
  28. import java.util.Vector;
  29. import org.gjt.sp.jedit.*;
  30. //}}}
  31. public class ErrorListDialog extends EnhancedDialog
  32. {
  33. //{{{ ErrorEntry class
  34. public static class ErrorEntry
  35. {
  36. String path;
  37. String[] messages;
  38. public ErrorEntry(String path, String messageProp, Object[] args)
  39. {
  40. this.path = path;
  41. String message = jEdit.getProperty(messageProp,args);
  42. if(message == null)
  43. message = "Undefined property: " + messageProp;
  44. Vector tokenizedMessage = new Vector();
  45. int lastIndex = -1;
  46. for(int i = 0; i < message.length(); i++)
  47. {
  48. if(message.charAt(i) == '\n')
  49. {
  50. tokenizedMessage.addElement(message.substring(
  51. lastIndex + 1,i));
  52. lastIndex = i;
  53. }
  54. }
  55. if(lastIndex != message.length())
  56. {
  57. tokenizedMessage.addElement(message.substring(
  58. lastIndex + 1));
  59. }
  60. messages = new String[tokenizedMessage.size()];
  61. tokenizedMessage.copyInto(messages);
  62. }
  63. } //}}}
  64. //{{{ ErrorListDialog constructor
  65. public ErrorListDialog(Frame frame, String title, String caption,
  66. Vector messages, boolean showPluginMgrButton)
  67. {
  68. super(frame,title,true);
  69. JPanel content = new JPanel(new BorderLayout(12,12));
  70. content.setBorder(new EmptyBorder(12,12,12,12));
  71. setContentPane(content);
  72. Box iconBox = new Box(BoxLayout.Y_AXIS);
  73. iconBox.add(new JLabel(UIManager.getIcon("OptionPane.errorIcon")));
  74. iconBox.add(Box.createGlue());
  75. content.add(BorderLayout.WEST,iconBox);
  76. JPanel centerPanel = new JPanel(new BorderLayout());
  77. JLabel label = new JLabel(caption);
  78. label.setBorder(new EmptyBorder(0,0,6,0));
  79. centerPanel.add(BorderLayout.NORTH,label);
  80. JList errors = new JList(messages);
  81. errors.setCellRenderer(new ErrorListCellRenderer());
  82. errors.setVisibleRowCount(Math.min(messages.size(),4));
  83. // need this bullshit scroll bar policy for the preferred size
  84. // hack to work
  85. JScrollPane scrollPane = new JScrollPane(errors,
  86. JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
  87. JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  88. Dimension size = scrollPane.getPreferredSize();
  89. size.width = Math.min(size.width,400);
  90. scrollPane.setPreferredSize(size);
  91. centerPanel.add(BorderLayout.CENTER,scrollPane);
  92. content.add(BorderLayout.CENTER,centerPanel);
  93. Box buttons = new Box(BoxLayout.X_AXIS);
  94. buttons.add(Box.createGlue());
  95. ok = new JButton(jEdit.getProperty("common.ok"));
  96. ok.addActionListener(new ActionHandler());
  97. if(showPluginMgrButton)
  98. {
  99. pluginMgr = new JButton(jEdit.getProperty("error-list.plugin-manager"));
  100. pluginMgr.addActionListener(new ActionHandler());
  101. buttons.add(pluginMgr);
  102. buttons.add(Box.createHorizontalStrut(6));
  103. }
  104. buttons.add(ok);
  105. buttons.add(Box.createGlue());
  106. content.add(BorderLayout.SOUTH,buttons);
  107. getRootPane().setDefaultButton(ok);
  108. pack();
  109. setLocationRelativeTo(frame);
  110. show();
  111. } //}}}
  112. //{{{ ok() method
  113. public void ok()
  114. {
  115. dispose();
  116. } //}}}
  117. //{{{ cancel() method
  118. public void cancel()
  119. {
  120. dispose();
  121. } //}}}
  122. //{{{ Private members
  123. private JButton ok, pluginMgr;
  124. //}}}
  125. //{{{ ActionHandler class
  126. class ActionHandler implements ActionListener
  127. {
  128. //{{{ actionPerformed() method
  129. public void actionPerformed(ActionEvent evt)
  130. {
  131. if(evt.getSource() == ok)
  132. dispose();
  133. else if(evt.getSource() == pluginMgr)
  134. {
  135. new org.gjt.sp.jedit.pluginmgr.PluginManager(
  136. JOptionPane.getFrameForComponent(
  137. ErrorListDialog.this));
  138. }
  139. } //}}}
  140. } //}}}
  141. }