KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > gui > ErrorListDialog


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
23 package org.gjt.sp.jedit.gui;
24
25 //{{{ Imports
26
import java.awt.*;
27 import java.awt.event.*;
28 import java.util.Vector JavaDoc;
29 import javax.swing.*;
30 import javax.swing.border.*;
31 import org.gjt.sp.jedit.*;
32 import org.gjt.sp.jedit.pluginmgr.PluginManager;
33 import org.gjt.sp.util.Log;
34 //}}}
35

36 public class ErrorListDialog extends EnhancedDialog
37 {
38     //{{{ ErrorEntry class
39
public static class ErrorEntry
40     {
41         String JavaDoc path;
42         String JavaDoc[] messages;
43
44         public ErrorEntry(String JavaDoc path, String JavaDoc messageProp, Object JavaDoc[] args)
45         {
46             this.path = path;
47
48             String JavaDoc message = jEdit.getProperty(messageProp,args);
49             if(message == null)
50                 message = "Undefined property: " + messageProp;
51
52             Log.log(Log.ERROR,this,path + ":");
53             Log.log(Log.ERROR,this,message);
54
55             Vector JavaDoc tokenizedMessage = new Vector JavaDoc();
56             int lastIndex = -1;
57             for(int i = 0; i < message.length(); i++)
58             {
59                 if(message.charAt(i) == '\n')
60                 {
61                     tokenizedMessage.addElement(message.substring(
62                         lastIndex + 1,i));
63                     lastIndex = i;
64                 }
65             }
66
67             if(lastIndex != message.length())
68             {
69                 tokenizedMessage.addElement(message.substring(
70                     lastIndex + 1));
71             }
72
73             messages = new String JavaDoc[tokenizedMessage.size()];
74             tokenizedMessage.copyInto(messages);
75         }
76
77         public boolean equals(Object JavaDoc o)
78         {
79             if(o instanceof ErrorEntry)
80             {
81                 ErrorEntry e = (ErrorEntry)o;
82                 return e.path.equals(path);
83             }
84             else
85                 return false;
86         }
87     } //}}}
88

89     //{{{ ErrorListDialog constructor
90
public ErrorListDialog(Frame frame, String JavaDoc title, String JavaDoc caption,
91         Vector JavaDoc messages, boolean pluginError)
92     {
93         super(frame,title,!pluginError);
94
95         JPanel content = new JPanel(new BorderLayout(12,12));
96         content.setBorder(new EmptyBorder(12,12,12,12));
97         setContentPane(content);
98
99         Box iconBox = new Box(BoxLayout.Y_AXIS);
100         iconBox.add(new JLabel(UIManager.getIcon("OptionPane.errorIcon")));
101         iconBox.add(Box.createGlue());
102         content.add(BorderLayout.WEST,iconBox);
103
104         JPanel centerPanel = new JPanel(new BorderLayout());
105
106         JLabel label = new JLabel(caption);
107         label.setBorder(new EmptyBorder(0,0,6,0));
108         centerPanel.add(BorderLayout.NORTH,label);
109
110         JList errors = new JList(messages);
111         errors.setCellRenderer(new ErrorListCellRenderer());
112         errors.setVisibleRowCount(Math.min(messages.size(),4));
113
114         // need this bullshit scroll bar policy for the preferred size
115
// hack to work
116
JScrollPane scrollPane = new JScrollPane(errors,
117             JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
118             JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
119         Dimension size = scrollPane.getPreferredSize();
120         size.width = Math.min(size.width,400);
121         scrollPane.setPreferredSize(size);
122
123         centerPanel.add(BorderLayout.CENTER,scrollPane);
124
125         content.add(BorderLayout.CENTER,centerPanel);
126
127         Box buttons = new Box(BoxLayout.X_AXIS);
128         buttons.add(Box.createGlue());
129
130         ok = new JButton(jEdit.getProperty("common.ok"));
131         ok.addActionListener(new ActionHandler());
132
133         if(pluginError)
134         {
135             pluginMgr = new JButton(jEdit.getProperty("error-list.plugin-manager"));
136             pluginMgr.addActionListener(new ActionHandler());
137             buttons.add(pluginMgr);
138             buttons.add(Box.createHorizontalStrut(6));
139         }
140
141         buttons.add(ok);
142
143         buttons.add(Box.createGlue());
144         content.add(BorderLayout.SOUTH,buttons);
145
146         getRootPane().setDefaultButton(ok);
147
148         pack();
149         setLocationRelativeTo(frame);
150         setVisible(true);
151     } //}}}
152

153     //{{{ ok() method
154
public void ok()
155     {
156         dispose();
157     } //}}}
158

159     //{{{ cancel() method
160
public void cancel()
161     {
162         dispose();
163     } //}}}
164

165     //{{{ Private members
166
private JButton ok, pluginMgr;
167     //}}}
168

169     //{{{ ActionHandler class
170
class ActionHandler implements ActionListener
171     {
172         //{{{ actionPerformed() method
173
public void actionPerformed(ActionEvent evt)
174         {
175             if(evt.getSource() == ok)
176                 dispose();
177             else if(evt.getSource() == pluginMgr)
178             {
179                 PluginManager.showPluginManager(JOptionPane.getFrameForComponent(
180                     ErrorListDialog.this));
181             }
182         } //}}}
183
} //}}}
184
}
185
Popular Tags