PageRenderTime 118ms CodeModel.GetById 89ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 1ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/gui/ErrorListDialog.java

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