com.lowagie.toolbox.Toolbox Maven / Gradle / Ivy
/*
* $Id: Toolbox.java 3271 2008-04-18 20:39:42Z xlv $
* Copyright (c) 2005-2007 Bruno Lowagie, Carsten Hammer
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* This class was originally published under the MPL by Bruno Lowagie
* and Carsten Hammer.
* It was a part of iText, a Java-PDF library. You can now use it under
* the MIT License; for backward compatibility you can also use it under
* the MPL version 1.1: http://www.mozilla.org/MPL/
* A copy of the MPL license is bundled with the source code FYI.
*/
package com.lowagie.toolbox;
import com.lowagie.tools.Executable;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.beans.PropertyVetoException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import java.util.Vector;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
/**
* This is a utility that allows you to use a number of iText tools.
*
* @since 2.1.1 (imported from itexttoolbox project)
*/
public class Toolbox extends JFrame implements ActionListener {
/**
* A serial version ID
*/
private static final long serialVersionUID = -3766198389452935073L;
/**
* The DesktopPane of the toolbox.
*/
private final JDesktopPane desktop;
/**
* The ConsolePane of the toolbox.
*/
private JScrollPane console;
/**
* The list of tools in the toolbox.
*/
private Properties toolmap = new Properties();
/**
* x-coordinate of the location of a new internal frame.
*/
private int locationX = 0;
/**
* y-coordinate of the location of a new internal frame.
*/
private int locationY = 0;
/**
* toolarray
*/
private final ArrayList toolarray = new ArrayList<>();
private final Vector menulist = new Vector<>();
private final Vector menuitemlist = new Vector<>();
/**
* Constructs the Toolbox object.
*/
public Toolbox() {
super();
setSize(600, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(true);
setTitle("iText Toolbox");
desktop = new JDesktopPane();
setJMenuBar(getMenubar());
try {
setIconImage(new ImageIcon(com.lowagie.toolbox.Toolbox.class.getResource(
"1t3xt.gif")).getImage());
} catch (Exception err) {
System.err.println("Problem loading icon image.");
}
Console c;
try {
c = new Console();
console = new JScrollPane(c.textArea);
} catch (IOException e) {
e.printStackTrace();
}
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
desktop,
console);
splitPane.setContinuousLayout(true);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(300);
setContentPane(splitPane);
centerFrame(this);
setVisible(true);
}
/**
* Starts the Toolbox utility.
*
* use as first argument the name of the plugin, then the arguments of the plugin used.
*
* e.g.
*
* java -jar itext.jar Burst inputfile.pdf
*
* That way you can call plugins by name directly.
*
* @param args no arguments needed
*/
public static void main(String[] args) {
try {
Class.forName("com.lowagie.text.Document");
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(null,
"You need the iText.jar in your CLASSPATH!",
e.getClass().getName(),
JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
Toolbox toolbox = new Toolbox();
if (args.length > 0) {
try {
AbstractTool tool = toolbox.createFrame(args[0]);
String[] nargs = new String[args.length - 1];
System.arraycopy(args, 1, nargs, 0, args.length - 1);
tool.setMainArguments(nargs);
tool.execute();
} catch (PropertyVetoException | InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
}
}
}
/**
* Gets the menubar.
*
* @return a menubar
*/
private JMenuBar getMenubar() {
Properties p = new Properties();
try {
p.load(Toolbox.class.getClassLoader().getResourceAsStream(
"tools.txt"));
String usertoolstxt = System.getProperty("user.home") +
System.getProperty("file.separator") +
"tools.txt";
File uttf = new File(usertoolstxt);
if (uttf.isFile() && uttf.exists()) {
p.load(new FileInputStream(usertoolstxt));
}
} catch (IOException e) {
e.printStackTrace();
}
toolmap = new Properties();
JMenuBar menubar = new JMenuBar();
JMenu file = new JMenu(ToolMenuItems.FILE);
file.setMnemonic(KeyEvent.VK_T);
JMenuItem close = new JMenuItem(ToolMenuItems.CLOSE);
close.setMnemonic(KeyEvent.VK_C);
close.addActionListener(this);
file.add(close);
JMenu view = new JMenu(ToolMenuItems.VIEW);
JMenuItem reset = new JMenuItem(ToolMenuItems.RESET);
reset.addActionListener(this);
view.add(reset);
// JMenuItem filelist = new JMenuItem(FILELIST);
// filelist.addActionListener(this);
// view.add(filelist);
JMenu tools = new JMenu(ToolMenuItems.TOOLS);
// Here one day should be the wizard to help you create a new beanshell script
// JMenuItem create = new JMenuItem(CREATE);
// create.addActionListener(this);
// tools.add(create);
buildPluginMenuItems(new TreeMap<>(p), tools);
JMenu help = new JMenu(ToolMenuItems.HELP);
JMenuItem about = new JMenuItem(ToolMenuItems.ABOUT);
// about.setIcon(new ImageIcon(Toolbox.class.getResource(
// "Help24.gif")));
about.setMnemonic(KeyEvent.VK_A);
about.addActionListener(this);
help.add(about);
JMenuItem versions = new JMenuItem(ToolMenuItems.VERSION);
// versions.setIcon(new ImageIcon(Toolbox.class.getResource(
// "About24.gif")));
versions.addActionListener(this);
help.add(versions);
menubar.add(file);
menubar.add(tools);
menubar.add(view);
menubar.add(Box.createGlue());
menubar.add(help);
return menubar;
}
/**
* BuildPluginMenuItems
*
* @param tmp Map
* @param tools JMenu
*/
private void buildPluginMenuItems(Map