PageRenderTime 153ms CodeModel.GetById 145ms app.highlight 5ms 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
  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
 98		// need this bullshit scroll bar policy for the preferred size
 99		// hack to work
100		JScrollPane scrollPane = new JScrollPane(errors,
101			JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
102			JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
103		Dimension size = scrollPane.getPreferredSize();
104		size.width = Math.min(size.width,400);
105		scrollPane.setPreferredSize(size);
106
107		centerPanel.add(BorderLayout.CENTER,scrollPane);
108
109		content.add(BorderLayout.CENTER,centerPanel);
110
111		Box buttons = new Box(BoxLayout.X_AXIS);
112		buttons.add(Box.createGlue());
113
114		ok = new JButton(jEdit.getProperty("common.ok"));
115		ok.addActionListener(new ActionHandler());
116
117		if(showPluginMgrButton)
118		{
119			pluginMgr = new JButton(jEdit.getProperty("error-list.plugin-manager"));
120			pluginMgr.addActionListener(new ActionHandler());
121			buttons.add(pluginMgr);
122			buttons.add(Box.createHorizontalStrut(6));
123		}
124
125		buttons.add(ok);
126
127		buttons.add(Box.createGlue());
128		content.add(BorderLayout.SOUTH,buttons);
129
130		getRootPane().setDefaultButton(ok);
131
132		pack();
133		setLocationRelativeTo(frame);
134		show();
135	} //}}}
136
137	//{{{ ok() method
138	public void ok()
139	{
140		dispose();
141	} //}}}
142
143	//{{{ cancel() method
144	public void cancel()
145	{
146		dispose();
147	} //}}}
148
149	//{{{ Private members
150	private JButton ok, pluginMgr;
151	//}}}
152
153	//{{{ ActionHandler class
154	class ActionHandler implements ActionListener
155	{
156		//{{{ actionPerformed() method
157		public void actionPerformed(ActionEvent evt)
158		{
159			if(evt.getSource() == ok)
160				dispose();
161			else if(evt.getSource() == pluginMgr)
162			{
163				new org.gjt.sp.jedit.pluginmgr.PluginManager(
164					JOptionPane.getFrameForComponent(
165					ErrorListDialog.this));
166			}
167		} //}}}
168	} //}}}
169}