001: /*
002: * ErrorListDialog.java - Used to list I/O and plugin load errors
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2001 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.gui;
024:
025: //{{{ Imports
026: import java.awt.*;
027: import java.awt.event.*;
028: import java.util.Vector;
029: import javax.swing.*;
030: import javax.swing.border.*;
031: import org.gjt.sp.jedit.*;
032: import org.gjt.sp.jedit.pluginmgr.PluginManager;
033: import org.gjt.sp.util.Log;
034:
035: //}}}
036:
037: public class ErrorListDialog extends EnhancedDialog {
038: //{{{ ErrorEntry class
039: public static class ErrorEntry {
040: String path;
041: String[] messages;
042:
043: public ErrorEntry(String path, String messageProp, Object[] args) {
044: this .path = path;
045:
046: String message = jEdit.getProperty(messageProp, args);
047: if (message == null)
048: message = "Undefined property: " + messageProp;
049:
050: Log.log(Log.ERROR, this , path + ":");
051: Log.log(Log.ERROR, this , message);
052:
053: Vector tokenizedMessage = new Vector();
054: int lastIndex = -1;
055: for (int i = 0; i < message.length(); i++) {
056: if (message.charAt(i) == '\n') {
057: tokenizedMessage.addElement(message.substring(
058: lastIndex + 1, i));
059: lastIndex = i;
060: }
061: }
062:
063: if (lastIndex != message.length()) {
064: tokenizedMessage.addElement(message
065: .substring(lastIndex + 1));
066: }
067:
068: messages = new String[tokenizedMessage.size()];
069: tokenizedMessage.copyInto(messages);
070: }
071:
072: public boolean equals(Object o) {
073: if (o instanceof ErrorEntry) {
074: ErrorEntry e = (ErrorEntry) o;
075: return e.path.equals(path);
076: } else
077: return false;
078: }
079: } //}}}
080:
081: //{{{ ErrorListDialog constructor
082: public ErrorListDialog(Frame frame, String title, String caption,
083: Vector messages, boolean pluginError) {
084: super (frame, title, !pluginError);
085:
086: JPanel content = new JPanel(new BorderLayout(12, 12));
087: content.setBorder(new EmptyBorder(12, 12, 12, 12));
088: setContentPane(content);
089:
090: Box iconBox = new Box(BoxLayout.Y_AXIS);
091: iconBox.add(new JLabel(UIManager
092: .getIcon("OptionPane.errorIcon")));
093: iconBox.add(Box.createGlue());
094: content.add(BorderLayout.WEST, iconBox);
095:
096: JPanel centerPanel = new JPanel(new BorderLayout());
097:
098: JLabel label = new JLabel(caption);
099: label.setBorder(new EmptyBorder(0, 0, 6, 0));
100: centerPanel.add(BorderLayout.NORTH, label);
101:
102: JList errors = new JList(messages);
103: errors.setCellRenderer(new ErrorListCellRenderer());
104: errors.setVisibleRowCount(Math.min(messages.size(), 4));
105:
106: // need this bullshit scroll bar policy for the preferred size
107: // hack to work
108: JScrollPane scrollPane = new JScrollPane(errors,
109: JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
110: JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
111: Dimension size = scrollPane.getPreferredSize();
112: size.width = Math.min(size.width, 400);
113: scrollPane.setPreferredSize(size);
114:
115: centerPanel.add(BorderLayout.CENTER, scrollPane);
116:
117: content.add(BorderLayout.CENTER, centerPanel);
118:
119: Box buttons = new Box(BoxLayout.X_AXIS);
120: buttons.add(Box.createGlue());
121:
122: ok = new JButton(jEdit.getProperty("common.ok"));
123: ok.addActionListener(new ActionHandler());
124:
125: if (pluginError) {
126: pluginMgr = new JButton(jEdit
127: .getProperty("error-list.plugin-manager"));
128: pluginMgr.addActionListener(new ActionHandler());
129: buttons.add(pluginMgr);
130: buttons.add(Box.createHorizontalStrut(6));
131: }
132:
133: buttons.add(ok);
134:
135: buttons.add(Box.createGlue());
136: content.add(BorderLayout.SOUTH, buttons);
137:
138: getRootPane().setDefaultButton(ok);
139:
140: pack();
141: setLocationRelativeTo(frame);
142: setVisible(true);
143: } //}}}
144:
145: //{{{ ok() method
146: public void ok() {
147: dispose();
148: } //}}}
149:
150: //{{{ cancel() method
151: public void cancel() {
152: dispose();
153: } //}}}
154:
155: //{{{ Private members
156: private JButton ok, pluginMgr;
157:
158: //}}}
159:
160: //{{{ ActionHandler class
161: class ActionHandler implements ActionListener {
162: //{{{ actionPerformed() method
163: public void actionPerformed(ActionEvent evt) {
164: if (evt.getSource() == ok)
165: dispose();
166: else if (evt.getSource() == pluginMgr) {
167: PluginManager.showPluginManager(JOptionPane
168: .getFrameForComponent(ErrorListDialog.this ));
169: }
170: } //}}}
171: } //}}}
172: }
|