1 22 23 package org.gjt.sp.jedit.gui; 24 25 import java.awt.*; 27 import java.awt.event.*; 28 import java.util.Vector ; 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 36 public class ErrorListDialog extends EnhancedDialog 37 { 38 public static class ErrorEntry 40 { 41 String path; 42 String [] messages; 43 44 public ErrorEntry(String path, String messageProp, Object [] args) 45 { 46 this.path = path; 47 48 String 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 tokenizedMessage = new Vector (); 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 [tokenizedMessage.size()]; 74 tokenizedMessage.copyInto(messages); 75 } 76 77 public boolean equals(Object 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 } 89 public ErrorListDialog(Frame frame, String title, String caption, 91 Vector 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 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 } 153 public void ok() 155 { 156 dispose(); 157 } 159 public void cancel() 161 { 162 dispose(); 163 } 165 private JButton ok, pluginMgr; 167 169 class ActionHandler implements ActionListener 171 { 172 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 } } } 185 | Popular Tags |