📄 toolbox.java
字号:
}
String menuitem = name.substring(current.getText().length() + 1);
menuitemlist.add(menuitem);
item = new JMenuItem(menuitem);
item.addActionListener(this);
tool = (String) entry.getValue();
try {
if (Class.forName(tool) != null) {
toolmap.put(item.getText(), tool);
current.add(item);
}
} catch (ClassNotFoundException e) {
System.err.println("Plugin " + name
+ " was not found in your CLASSPATH.");
}
}
}
/**
* Creates an Internal Frame.
*
* @param name the name of the application
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
* @throws PropertyVetoException
* @return AbstractTool
*/
public AbstractTool createFrame(String name) throws InstantiationException,
IllegalAccessException, ClassNotFoundException,
PropertyVetoException {
AbstractTool ti = null;
String classname = (String) toolmap.get(name);
ti = (AbstractTool) Class.forName(classname).newInstance();
toolarray.add(ti);
JInternalFrame f = ti.getInternalFrame();
f.setLocation(locationX, locationY);
locationX += 25;
if (locationX > this.getWidth() + 50) {
locationX = 0;
}
locationY += 25;
if (locationY > this.getHeight() + 50) {
locationY = 0;
}
f.setVisible(true);
desktop.add(f);
f.setSelected(true);
return ti;
}
/**
* Centers a JFrame.
*
* @param f JFrame
*/
public static void centerFrame(Frame f) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = f.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
f.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
}
/**
*
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
* @param evt ActionEvent
*/
public void actionPerformed(ActionEvent evt) {
if (ToolMenuItems.CLOSE.equals(evt.getActionCommand())) {
System.out.println("The Toolbox is closed.");
System.exit(0);
} else if (ToolMenuItems.ABOUT.equals(evt.getActionCommand())) {
System.out
.println("The iText Toolbox is part of iText, a Free Java-PDF Library.\nVisit http://itexttoolbox.sourceforge.net/ for more info.");
try {
Executable
.launchBrowser("http://itexttoolbox.sourceforge.net/");
} catch (IOException ioe) {
JOptionPane
.showMessageDialog(
this,
"The iText Toolbox is part of iText, a Free Java-PDF Library.\nVisit http://itexttoolbox.sourceforge.net/ for more info.");
}
} else if (ToolMenuItems.RESET.equals(evt.getActionCommand())) {
JInternalFrame[] framearray = desktop.getAllFrames();
int xx = 0, yy = 0;
for (int i = 0; i < framearray.length; i++) {
if (!framearray[i].isIcon()) {
try {
int frameDistance = framearray[i].getHeight() -
framearray[i].getContentPane().
getHeight();
framearray[i].setMaximum(false);
int fwidth = framearray[i].getWidth();
int fheight = framearray[i].getHeight();
framearray[i].reshape(xx, yy, fwidth, fheight);
xx += frameDistance;
yy += frameDistance;
if (xx + fwidth > desktop.getWidth()) {
xx = 0;
}
if (yy + fheight > desktop.getHeight()) {
yy = 0;
}
} catch (PropertyVetoException e) {
}
}
}
} else if (ToolMenuItems.VERSION.equals(evt.getActionCommand())) {
JFrame f = new Versions();
centerFrame(f);
f.setVisible(true);
} else {
try {
createFrame(evt.getActionCommand());
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* A Class that redirects output to System.out and System.err.
*/
public class Console {
class ErrorContext extends StyleContext {
private static final long serialVersionUID = 7766294638325167438L;
public static final String STDERROR = "Error";
public static final String STDOUT = "StdOut";
public ErrorContext() {
super();
Style root = getStyle(DEFAULT_STYLE);
Style s = addStyle(STDERROR, root);
StyleConstants.setForeground(s, Color.RED);
s = addStyle(STDOUT, root);
StyleConstants.setForeground(s, Color.BLACK);
}
}
PipedInputStream piOut;
PipedInputStream piErr;
PipedOutputStream poOut;
PipedOutputStream poErr;
ErrorContext errorcontext = new ErrorContext();
JTextPane textArea = new JTextPane(new DefaultStyledDocument(
errorcontext));
PrintStream oriout;
PrintStream orierr;
/**
* Creates a new Console object.
* @throws IOException
*/
public Console() throws IOException {
// Set up System.out
piOut = new PipedInputStream();
poOut = new PipedOutputStream(piOut);
oriout = System.out;
System.setOut(new PrintStream(poOut, true));
// Set up System.err
piErr = new PipedInputStream();
poErr = new PipedOutputStream(piErr);
orierr = System.err;
System.setErr(new PrintStream(poErr, true));
// Add a scrolling text area
textArea.setEditable(false);
// Create reader threads
new ReaderThread(piOut, ErrorContext.STDOUT).start();
new ReaderThread(piErr, ErrorContext.STDERROR).start();
}
class ReaderThread extends Thread {
PipedInputStream pi;
String type;
ReaderThread(PipedInputStream pi, String type) {
this.pi = pi;
this.type = type;
}
/**
* @see java.lang.Thread#run()
*/
public void run() {
final byte[] buf = new byte[1024];
while (true) {
try {
final int len = pi.read(buf);
if (len == -1) {
break;
}
javax.swing.text.Document doc = textArea.getDocument();
AttributeSet attset = errorcontext.getStyle(type);
String snippet = new String(buf, 0, len);
doc.insertString(doc.getLength(),
snippet, attset);
oriout.print(snippet);
textArea.setCaretPosition(textArea.getDocument().
getLength());
} catch (BadLocationException ex) {
} catch (IOException e) {
}
}
}
}
}
public Vector<String> getMenulist() {
return menulist;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -