Revision: 11457
http://jedit.svn.sourceforge.net/jedit/?rev=11457&view=rev
Author: ezust
Date: 2007-12-26 16:56:01 -0800 (Wed, 26 Dec 2007)
Log Message:
-----------
Ran findBugs on console, and got rid of some inefficiencies, added some generics,
and also added an option for console to use jEdit's textArea background color.
Modified Paths:
--------------
plugins/Console/trunk/Console.props
plugins/Console/trunk/console/Console.java
plugins/Console/trunk/console/ConsolePane.java
plugins/Console/trunk/console/ConsoleProcess.java
plugins/Console/trunk/console/ErrorMatcher.java
plugins/Console/trunk/console/SystemShell.java
plugins/Console/trunk/console/SystemShellBuiltIn.java
plugins/Console/trunk/console/commando/CommandoDialog.java
plugins/Console/trunk/console/commando/CommandoToolBar.java
plugins/Console/trunk/console/options/CompileRunOptionPane.java
plugins/Console/trunk/console/options/GeneralOptionPane.java
Modified: plugins/Console/trunk/Console.props
===================================================================
--- plugins/Console/trunk/Console.props 2007-12-26 22:29:14 UTC (rev 11456)
+++ plugins/Console/trunk/Console.props 2007-12-27 00:56:01 UTC (rev 11457)
@@ -79,6 +79,7 @@
options.console.general.font=Font:
options.console.general.encoding=Character encoding:
options.console.general.charlimit=Maximum scrollback buffer size (characters):
+options.console.general.usejEditBgColor=Use jEdit bgColor
options.console.general.bgColor=Console background:
options.console.general.plainColor=Plain text:
options.console.general.caretColor=Caret:
Modified: plugins/Console/trunk/console/Console.java
===================================================================
--- plugins/Console/trunk/console/Console.java 2007-12-26 22:29:14 UTC (rev 11456)
+++ plugins/Console/trunk/console/Console.java 2007-12-27 00:56:01 UTC (rev 11457)
@@ -259,8 +259,6 @@
return shellState;
} //}}}
-
-
//{{{ runLastCommand() method
/**
* Meant to be used as a user action.
@@ -763,11 +761,10 @@
{
return "console." + shell.getName();
} //}}}
-
// }}}
// {{{ Inner classes
- //{{{ ShellState class
+ // {{{ ShellState class
/**
* Each Shell of a Console has its own ShellState
@@ -808,7 +805,7 @@
public void setInputStart(int cmdStart)
{
scrollback.putProperty(ConsolePane.InputStart,
- new Integer(cmdStart));
+ Integer.valueOf(cmdStart));
} //}}}
//{{{ print() method
@@ -898,13 +895,10 @@
setInputStart(scrollback.getLength());
} //}}}
+ } //}}}
-
-
- } //}}}
-
- //{{{ LengthFilter class
- private class LengthFilter extends DocumentFilter
+ // {{{ LengthFilter class
+ static private class LengthFilter extends DocumentFilter
{
public LengthFilter()
{
@@ -932,9 +926,7 @@
} //}}}
} //}}}
-
-
- //{{{ EvalAction class
+ // {{{ EvalAction class
public static class EvalAction extends AbstractAction
{
private String command;
@@ -953,7 +945,7 @@
}
} //}}}
- //{{{ ActionHandler class
+ // {{{ ActionHandler class
class ActionHandler implements ActionListener
{
public void actionPerformed(ActionEvent evt)
@@ -974,7 +966,7 @@
}
} //}}}
- //{{{ RunActionHandler class
+ // {{{ RunActionHandler class
class RunActionHandler implements ActionListener
{
public void actionPerformed(ActionEvent evt)
@@ -1009,7 +1001,7 @@
}
// }}}
- //{{{ CompletionAction class
+ // {{{ CompletionAction class
class CompletionAction extends AbstractAction
{
public void actionPerformed(ActionEvent evt)
@@ -1018,7 +1010,7 @@
}
} //}}}
- //{{{ EOFAction class
+ // {{{ EOFAction class
class EOFAction extends AbstractAction
{
public void actionPerformed(ActionEvent evt)
@@ -1027,7 +1019,7 @@
}
} //}}}
- //{{{ DetachAction class
+ // {{{ DetachAction class
class DetachAction extends AbstractAction
{
public void actionPerformed(ActionEvent evt)
Modified: plugins/Console/trunk/console/ConsolePane.java
===================================================================
--- plugins/Console/trunk/console/ConsolePane.java 2007-12-26 22:29:14 UTC (rev 11456)
+++ plugins/Console/trunk/console/ConsolePane.java 2007-12-27 00:56:01 UTC (rev 11457)
@@ -32,12 +32,24 @@
public class ConsolePane extends JTextPane
{
+ // {{{ Members
public static final String InputStart = "InputStart";
public static final Object Input = new Object();
public static final Object Actions = new Object();
+ private static final Cursor MoveCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
+
+ private static final Cursor DefaultCursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
+
+ private EventListenerList listenerList;
+
+ private ConsoleHistoryText history;
+
+ transient private DocumentHandler documentHandler;
+ // }}}
+
// {{{ ConsolePane constructor
public ConsolePane()
{
@@ -220,7 +232,7 @@
// {{{ setInputStart() method
public void setInputStart(int cmdStart)
{
- getDocument().putProperty(InputStart, new Integer(cmdStart));
+ getDocument().putProperty(InputStart, Integer.valueOf(cmdStart));
} // }}}
// {{{ getPartialInput() method
@@ -271,17 +283,22 @@
return style;
} // }}}
+ // {{{ processKeyEvent method
+ @Override
+ protected void processKeyEvent(KeyEvent e)
+ {
+ int endpos = getDocument().getLength();
+ int startpos = getInputStart();
+
+ if (e.getID() == KeyEvent.KEY_TYPED && getCaretPosition() < startpos)
+ setCaretPosition(endpos);
+
+ super.processKeyEvent(e);
+ } // }}}
+
// {{{ Private members
- private static final Cursor MoveCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
- private static final Cursor DefaultCursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
- private EventListenerList listenerList;
-
- private ConsoleHistoryText history;
-
- private DocumentHandler documentHandler;
-
// {{{ getAttributes() method
private AttributeSet getAttributes(int pos)
{
@@ -335,6 +352,7 @@
// }}}
+ // {{{ Inner classes
// {{{ MouseHandler class
class MouseHandler extends MouseInputAdapter
{
@@ -558,16 +576,6 @@
{
}
} // }}}
+ // }}}
- @Override
- protected void processKeyEvent(KeyEvent e)
- {
- int endpos = getDocument().getLength();
- int startpos = getInputStart();
-
- if (e.getID() == KeyEvent.KEY_TYPED && getCaretPosition() < startpos)
- setCaretPosition(endpos);
-
- super.processKeyEvent(e);
- }
}
Modified: plugins/Console/trunk/console/ConsoleProcess.java
===================================================================
--- plugins/Console/trunk/console/ConsoleProcess.java 2007-12-26 22:29:14 UTC (rev 11456)
+++ plugins/Console/trunk/console/ConsoleProcess.java 2007-12-27 00:56:01 UTC (rev 11457)
@@ -147,7 +147,7 @@
synchronized void showExit () {
boolean showExitStatus = jEdit.getBooleanProperty("console.processrunner.showExitStatus", true);
if (showExitStatus) {
- Object[] pp = { args[0], new Integer(exitCode) };
+ Object[] pp = { args[0], Integer.valueOf(exitCode) };
String msg = jEdit.getProperty("console.shell.exited", pp);
if (exitCode == 0)
error.print(console.getInfoColor(), msg);
@@ -164,11 +164,11 @@
if (console != null)
{
Object[] pp = { args[0] };
- error.print(console.getErrorColor(),
- jEdit.getProperty("console.shell.detached", pp));
output.commandDone();
if (error != null)
{
+ error.print(console.getErrorColor(),
+ jEdit.getProperty("console.shell.detached", pp));
error.commandDone();
}
}
Modified: plugins/Console/trunk/console/ErrorMatcher.java
===================================================================
--- plugins/Console/trunk/console/ErrorMatcher.java 2007-12-26 22:29:14 UTC (rev 11456)
+++ plugins/Console/trunk/console/ErrorMatcher.java 2007-12-27 00:56:01 UTC (rev 11457)
@@ -174,9 +174,11 @@
while (i + 1< sl.length )
{
String current = sl[++i];
+ StringBuffer mlb = new StringBuffer();
String ml = matchLine(current);
if (ml != null) /* We found a match for the first line */
{
+ mlb.append(ml);
if ( extraRE != null )
{
while ( i+1 < sl.length)
@@ -186,15 +188,15 @@
if (!m.matches()) break;
try {
String extra = m.replaceFirst("$1");
- ml += "\n " + extra;
+ mlb.append("\n " + extra);
}
catch (Exception e) {
- ml += "\n " + e.getMessage();
+ mlb.append("\n " + e.getMessage());
}
++i;
}
}
- retval.add(ml);
+ retval.add(mlb.toString());
}
}
return retval;
@@ -229,7 +231,7 @@
// }}}
// {{{ clone()
- public Object clone()
+ public Object clone()
{
ErrorMatcher retval = new ErrorMatcher();
retval.set(this);
Modified: plugins/Console/trunk/console/SystemShell.java
===================================================================
--- plugins/Console/trunk/console/SystemShell.java 2007-12-26 22:29:14 UTC (rev 11456)
+++ plugins/Console/trunk/console/SystemShell.java 2007-12-27 00:56:01 UTC (rev 11457)
@@ -45,8 +45,7 @@
/** The state of each console System Shell instance. */
private Hashtable<Console, ConsoleState> consoleStateMap;
- // Why is this not static?
- private final char dosSlash = 127;
+ static private final char dosSlash = 127;
/** Map of aliases */
private Hashtable<String, String> aliases;
@@ -628,7 +627,7 @@
} // }}}
// {{{ getAliases() method
- public Hashtable getAliases()
+ public Hashtable<String, String> getAliases()
{
init();
return aliases;
@@ -647,7 +646,7 @@
} // }}}
// {{{ getVariables() method
- Map getVariables()
+ Map<String, String> getVariables()
{
return processBuilder.environment();
} // }}}
@@ -716,7 +715,7 @@
// {{{ initAliases() method
private void initAliases()
{
- aliases = new Hashtable();
+ aliases = new Hashtable<String,String>();
ProcessRunner pr = ProcessRunner.getProcessRunner();
pr.setUpDefaultAliases(aliases);
@@ -884,7 +883,7 @@
// {{{ getFileCompletions() method
- private List getFileCompletions(View view, String currentDirName, String typedFilename,
+ private List<String> getFileCompletions(View view, String currentDirName, String typedFilename,
boolean directoriesOnly)
{
String expandedTypedFilename = expandVariables(view, typedFilename);
@@ -928,20 +927,20 @@
if (matchedAgainst.startsWith(matchedString))
{
- String match;
+ StringBuffer match = new StringBuffer();
File matchFile = new File(dir, filenames[i]);
if (directoriesOnly && !matchFile.isDirectory())
continue;
- match = typedDirName + filenames[i];
-
+ match.append(typedDirName + filenames[i]);
+
// Add a separator at the end if it's a
// directory
- if (matchFile.isDirectory() && !match.endsWith(File.separator))
- match = match + File.separator;
+ if (matchFile.isDirectory() && match.charAt(match.length()) != File.separatorChar)
+ match.append(File.separator);
- matchingFilenames.add(match);
+ matchingFilenames.add(match.toString());
}
}
return matchingFilenames;
@@ -950,9 +949,9 @@
// {{{ getCommandCompletions() method
private List getCommandCompletions(View view, String currentDirName, String command)
{
- ArrayList list = new ArrayList();
+ StringList list = new StringList();
- Iterator iter = commands.keySet().iterator();
+ Iterator<String> iter = commands.keySet().iterator();
while (iter.hasNext())
{
String cmd = (String) iter.next();
Modified: plugins/Console/trunk/console/SystemShellBuiltIn.java
===================================================================
--- plugins/Console/trunk/console/SystemShellBuiltIn.java 2007-12-26 22:29:14 UTC (rev 11456)
+++ plugins/Console/trunk/console/SystemShellBuiltIn.java 2007-12-27 00:56:01 UTC (rev 11457)
@@ -25,10 +25,12 @@
//{{{ Imports
import java.util.*;
+
import org.gjt.sp.jedit.*;
import org.gjt.sp.jedit.browser.VFSBrowser;
import org.gjt.sp.jedit.help.HelpViewer;
import org.gjt.sp.util.Log;
+import org.gjt.sp.util.StringList;
import console.SystemShell.ConsoleState;
//}}}
@@ -90,14 +92,15 @@
/**
* Used by executeBuiltIn
*/
- public void execute(Console console, Output output, Output error, Vector args)
+ public void execute(Console console, Output output, Output error,
+ Vector<String> args)
{
- Hashtable values = new Hashtable();
+ Hashtable<String, Object> values = new Hashtable<String, Object>();
Option[] options = getOptions();
for(int i = 0; i < args.size(); i++)
{
- String arg = (String)args.elementAt(i);
+ String arg = args.elementAt(i);
//{{{ end of options
if(arg.equals("--"))
@@ -232,7 +235,7 @@
//{{{ execute() method
protected abstract void execute(Console console, Output output,
- Output error, Vector args, Hashtable values); //}}}
+ Output error, Vector<String> args, Hashtable<String, Object> values); //}}}
//}}}
@@ -257,9 +260,9 @@
}
public void execute(Console console, Output output,
- Output error, Vector args, Hashtable values)
+ Output error, Vector<String> args, Hashtable<String, Object> values)
{
- Hashtable aliases = ConsolePlugin.getSystemShell()
+ Hashtable<String,String> aliases = ConsolePlugin.getSystemShell()
.getAliases();
aliases.put(args.elementAt(0),args.elementAt(1));
}
@@ -279,22 +282,19 @@
}
public void execute(Console console, Output output,
- Output error, Vector args, Hashtable values)
+ Output error, Vector<String> args, Hashtable<String, Object> values)
{
- Hashtable aliases = ConsolePlugin.getSystemShell().getAliases();
- Vector returnValue = new Vector();
- Enumeration keys = aliases.keys();
- while(keys.hasMoreElements())
+ Hashtable<String, String> aliases = ConsolePlugin.getSystemShell().getAliases();
+ StringList returnValue = new StringList();
+ for (Map.Entry<String,String> ent: aliases.entrySet())
{
- Object key = keys.nextElement();
- returnValue.addElement(key + "=" + aliases.get(key));
+ returnValue.add(ent.getKey() + "=" + ent.getValue());
}
- MiscUtilities.quicksort(returnValue,
- new MiscUtilities.StringICaseCompare());
+ Collections.sort(returnValue, new MiscUtilities.StringICaseCompare());
for(int i = 0; i < returnValue.size(); i++)
{
- output.print(null,(String)returnValue.elementAt(i));
+ output.print(null,returnValue.get(i));
}
}
} //}}}
@@ -341,7 +341,7 @@
}
public void execute(Console console, Output output,
- Output error, Vector args, Hashtable values)
+ Output error, Vector<String> args, Hashtable<String, Object> values)
{
SystemShell.ConsoleState state = getConsoleState(console);
@@ -398,7 +398,7 @@
public void execute(Console console, Output output,
Output error, Vector args, Hashtable values)
{
- Stack directoryStack = getConsoleState(console)
+ Stack<String> directoryStack = getConsoleState(console)
.directoryStack;
for(int i = 0; i < directoryStack.size(); i++)
@@ -467,22 +467,20 @@
}
public void execute(Console console, Output output,
- Output error, Vector args, Hashtable values)
+ Output error, Vector<String> args, Hashtable<String, Object> values)
{
- Map variables = ConsolePlugin.getSystemShell().getVariables();
- Vector returnValue = new Vector();
- Iterator keys = variables.keySet().iterator();
- while(keys.hasNext())
+ Map<String, String> variables = ConsolePlugin.getSystemShell().getVariables();
+ StringList returnValue = new StringList();
+ for (Map.Entry<String,String> ent: variables.entrySet())
{
- Object key = keys.next();
- returnValue.addElement(key + "=" + variables.get(key));
+ returnValue.add(ent.getKey() + "=" + ent.getValue());
}
+
+ Collections.sort(returnValue, new MiscUtilities.StringICaseCompare());
- MiscUtilities.quicksort(returnValue,
- new MiscUtilities.StringICaseCompare());
for(int i = 0; i < returnValue.size(); i++)
{
- output.print(null,(String)returnValue.elementAt(i));
+ output.print(null,returnValue.get(i));
}
}
} //}}}
Modified: plugins/Console/trunk/console/commando/CommandoDialog.java
===================================================================
--- plugins/Console/trunk/console/commando/CommandoDialog.java 2007-12-26 22:29:14 UTC (rev 11456)
+++ plugins/Console/trunk/console/commando/CommandoDialog.java 2007-12-27 00:56:01 UTC (rev 11457)
@@ -75,6 +75,24 @@
public class CommandoDialog extends EnhancedDialog
{
+ //{{{ Instance variables
+ private View view;
+
+ private JComboBox commandCombo;
+ private JTabbedPane tabs;
+ private SettingsPane settings;
+ private TextAreaPane commandLine;
+ private JButton ok;
+ private JButton cancel;
+
+ private CommandoCommand command;
+ private NameSpace nameSpace;
+ private List<CommandoHandler.Script> scripts;
+ private List<This> components;
+
+ private boolean init;
+ //}}}
+
//{{{ CommandoDialog constructor
public CommandoDialog(View view, String command)
{
@@ -193,39 +211,19 @@
dispose();
} //}}}
- //{{{ Private members
-
- //{{{ Instance variables
- private View view;
-
- private JComboBox commandCombo;
- private JTabbedPane tabs;
- private SettingsPane settings;
- private TextAreaPane commandLine;
- private JButton ok;
- private JButton cancel;
-
- private CommandoCommand command;
- private NameSpace nameSpace;
- private List scripts;
- private List components;
-
- private boolean init;
- //}}}
-
- //
+ //{{{ load() method
void load(CommandoCommand command)
{
init = true;
this.command = command;
settings.removeAll();
- components = new ArrayList();
+ components = new ArrayList<This>();
commandLine.setText(null);
nameSpace = new NameSpace(BeanShell.getNameSpace(),
"commando");
- scripts = new ArrayList();
+ scripts = new ArrayList<CommandoHandler.Script>();
XmlParser parser = new XmlParser();
CommandoHandler handler = new CommandoHandler(view,command,
@@ -244,9 +242,9 @@
int line = xe.getLine();
String message = xe.getMessage();
- Object[] pp = { command.getLabel() + ".xml", new Integer(line),
+ Object[] pp = { command.getLabel() + ".xml", Integer.valueOf(line),
message };
- GUIUtilities.error(null,"commando.xml-error",pp);
+ GUIUtilities.error(null,"commando.xml-error", pp);
}
catch(IOException io)
{
@@ -351,10 +349,7 @@
commandLine.setText(buf.toString());
} //}}}
- //}}}
-
//{{{ Inner classes
-
//{{{ Renderer class
class Renderer extends DefaultListCellRenderer
{
Modified: plugins/Console/trunk/console/commando/CommandoToolBar.java
===================================================================
--- plugins/Console/trunk/console/commando/CommandoToolBar.java 2007-12-26 22:29:14 UTC (rev 11456)
+++ plugins/Console/trunk/console/commando/CommandoToolBar.java 2007-12-27 00:56:01 UTC (rev 11457)
@@ -166,6 +166,7 @@
* This map keeps track of what
* views had toolbars added to them.
*/
- static HashMap smToolBarMap = new HashMap();
+ static HashMap<View, CommandoToolBar> smToolBarMap =
+ new HashMap<View, CommandoToolBar>();
// }}}
} // }}}
Modified: plugins/Console/trunk/console/options/CompileRunOptionPane.java
===================================================================
--- plugins/Console/trunk/console/options/CompileRunOptionPane.java 2007-12-26 22:29:14 UTC (rev 11456)
+++ plugins/Console/trunk/console/options/CompileRunOptionPane.java 2007-12-27 00:56:01 UTC (rev 11457)
@@ -156,14 +156,14 @@
class ModeTableModel extends AbstractTableModel
{
private static final long serialVersionUID = 5314012645070764005L;
- private ArrayList modes;
+ private ArrayList<Entry> modes;
//{{{ ModeTableModel constructor
ModeTableModel()
{
Mode[] _modes = jEdit.getModes();
- modes = new ArrayList(_modes.length);
+ modes = new ArrayList<Entry>(_modes.length);
for(int i = 0; i < _modes.length; i++)
{
Modified: plugins/Console/trunk/console/options/GeneralOptionPane.java
===================================================================
--- plugins/Console/trunk/console/options/GeneralOptionPane.java 2007-12-26 22:29:14 UTC (rev 11456)
+++ plugins/Console/trunk/console/options/GeneralOptionPane.java 2007-12-27 00:56:01 UTC (rev 11457)
@@ -45,7 +45,7 @@
import console.ProcessRunner;
//}}}
-public class GeneralOptionPane extends AbstractOptionPane
+public class GeneralOptionPane extends AbstractOptionPane implements ActionListener
{
// {{{ data members
@@ -53,6 +53,7 @@
private FontSelector font;
private JComboBox encoding;
private JButton bgColor;
+ private JButton usejEditBgColor;
private JButton plainColor;
private JButton caretColor;
private JButton infoColor;
@@ -131,6 +132,10 @@
limit = new JTextField(jEdit.getProperty("console.outputLimit"));
addComponent(limitLabel, limit);
+ usejEditBgColor = new JButton("reset");
+ usejEditBgColor.addActionListener(this);
+ addComponent(jEdit.getProperty("options.console.general.usejEditBgColor"), usejEditBgColor);
+
addComponent(jEdit.getProperty("options.console.general.bgColor"),
bgColor = createColorButton("console.bgColor"));
addComponent(jEdit.getProperty("options.console.general.plainColor"),
@@ -226,5 +231,13 @@
b.setRequestFocusEnabled(false);
return b;
} //}}}
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if (e.getSource() != usejEditBgColor) return;
+ Color c = jEdit.getColorProperty("view.bgColor");
+ jEdit.setColorProperty("console.bgColor", c);
+ bgColor.setBackground(c);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|