PageRenderTime 27ms CodeModel.GetById 12ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

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