pdfsam-1.1.4/ 0000755 0001750 0001750 00000000000 11365105226 012726 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/ 0000755 0001750 0001750 00000000000 10725773606 015345 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/ant/ 0000755 0001750 0001750 00000000000 10726034742 016117 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/ant/build.properties 0000644 0001750 0001750 00000000741 11211203422 021315 0 ustar twerner twerner #where classes are compiled, jars distributed, javadocs created and release created
build.dir=f:/build
#libraries
libs.dir=F:/pdfsam/workspace-enhanced/pdfsam-maine/lib
pdfsam.release.jar.dir=f:/build/pdfsam-maine/release/jar
log4j.jar.name=log4j-1.2.15
dom4j.jar.name=dom4j-1.6.1
jaxen.jar.name=jaxen-1.1
pdfsam-console.jar.name=pdfsam-console-1.1.3e
pdfsam-split.jar.name=pdfsam-split-0.5.3
pdfsam-langpack.jar.name=pdfsam-langpack
pdfsam.jar.name=pdfsam-1.0.0e-b3
pdfsam-1.1.4/pdfsam-split/ant/build.xml 0000644 0001750 0001750 00000007272 11175612606 017750 0 ustar twerner twerner
Split plugin for pdfsam
pdfsam-1.1.4/pdfsam-split/apidocs/ 0000755 0001750 0001750 00000000000 11225360212 016744 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/images/ 0000755 0001750 0001750 00000000000 10725773616 016613 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/images/split.png 0000644 0001750 0001750 00000001124 10725773620 020445 0 ustar twerner twerner PNG
IHDR a bKGD e[ pHYs !3 tIME5 IDAT8˥kq?w9ڀBT$D/v$b(,骜[!kUZ 48LsHsDo|x{BT\?Jh=MpCSaiicc RXGi)w=u,{ ֳYm`O/DN.:0|;Y,eȪmA*7bӐUsDz,ܜ"M],/&w{՜i=ȩ x A#蕺ܝ)-C3Y`'~U[
GM/|p"|`v a4~#^e&>ƪD +ϝ lW* =%٬V8}[MQvtbi2)om%CV;@?P.tN|u]
+SW^|~txz':qFz΅[W
/a IENDB` pdfsam-1.1.4/pdfsam-split/src/ 0000755 0001750 0001750 00000000000 10725773620 016130 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/src/java/ 0000755 0001750 0001750 00000000000 10725773620 017051 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/src/java/org/ 0000755 0001750 0001750 00000000000 10725773620 017640 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/src/java/org/pdfsam/ 0000755 0001750 0001750 00000000000 10725773620 021112 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/src/java/org/pdfsam/plugin/ 0000755 0001750 0001750 00000000000 10725773622 022412 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/src/java/org/pdfsam/plugin/split/ 0000755 0001750 0001750 00000000000 10725773622 023545 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/src/java/org/pdfsam/plugin/split/components/ 0000755 0001750 0001750 00000000000 11125404756 025724 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/src/java/org/pdfsam/plugin/split/components/JSplitSizeCombo.java 0000644 0001750 0001750 00000005371 10726035162 031612 0 ustar twerner twerner /*
* Created on 30-Nov-2007
* Copyright (C) 2007 by Andrea Vacondio.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation;
* either version 2 of the License.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.pdfsam.plugin.split.components;
import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JComboBox;
import org.pdfsam.guiclient.configuration.Configuration;
import org.pdfsam.i18n.GettextResource;
/**
* Combo for the size selection
* @author Andrea Vacondio
*
*/
public class JSplitSizeCombo extends JComboBox {
private static final long serialVersionUID = 1342525636090510279L;
private Pattern pattern = Pattern.compile("^(\\d+[.[0-9]+]*)(\\s*)([KB||MB]+)", Pattern.CASE_INSENSITIVE );
public static final String KB = "KB";
public static final String MB = "MB";
public JSplitSizeCombo(){
init();
}
private void init(){
setEditable(true);
addItem("");
addItem("500 "+KB);
addItem("1 "+MB);
addItem("3 "+MB);
addItem("5 "+MB);
addItem("10 "+MB);
}
/**
* @return Bytes of the selected item
* @throws Exception
*/
public long getSelectedBytes() throws Exception{
long retVal = 0;
if(isValidSelectedItem()){
Matcher m = pattern.matcher((String)getSelectedItem());
m.reset();
m.matches();
BigDecimal value = new BigDecimal(m.group(1));
String unit = m.group(3);
if (KB.equals(unit.toUpperCase())){
value = value.multiply(new BigDecimal(1024));
}else if (MB.equals(unit.toUpperCase())){
value = value.multiply(new BigDecimal(1024*1024));
}else{
throw new Exception(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),"Invalid unit: ")+unit);
}
retVal = value.longValue();
}
return retVal;
}
/**
* @return true if the selected item is valid
*/
public boolean isValidSelectedItem(){
pattern.matcher((String)getSelectedItem()).reset();
return pattern.matcher((String)getSelectedItem()).matches();
}
/**
* @return if a not empty item is selected
*/
public boolean isSelectedItem(){
return (getSelectedItem()!=null && ((String)getSelectedItem()).trim().length()>0);
}
}
pdfsam-1.1.4/pdfsam-split/src/java/org/pdfsam/plugin/split/components/JSplitRadioButton.java 0000644 0001750 0001750 00000002471 10726035174 032153 0 ustar twerner twerner /*
* Created on 25-feb-2006
* Copyright (C) 2006 by Andrea Vacondio.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation;
* either version 2 of the License.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.pdfsam.plugin.split.components;
import javax.swing.JRadioButton;
/**
* This component is used to get the split type selected by the user
* @author Andrea Vacondio
*
*/
public class JSplitRadioButton extends JRadioButton {
private static final long serialVersionUID = 5210692149732974444L;
public JSplitRadioButton(String splitCommand) {
super();
this.setModel(new JSplitRadioButtonModel(splitCommand));
}
public String getSplitCommand(){
return ((JSplitRadioButtonModel)this.getModel()).getSplitCommand();
}
}
pdfsam-1.1.4/pdfsam-split/src/java/org/pdfsam/plugin/split/components/JBLevelCombo.java 0000644 0001750 0001750 00000014146 11162215046 031031 0 ustar twerner twerner /*
* Created on 27-DEC-2008
* Copyright (C) 2008 by Andrea Vacondio.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation;
* either version 2 of the License.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.pdfsam.plugin.split.components;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.List;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import org.apache.log4j.Logger;
import org.pdfsam.console.utils.PdfUtility;
import org.pdfsam.guiclient.commons.panels.JPdfSelectionPanel;
import org.pdfsam.guiclient.configuration.Configuration;
import org.pdfsam.guiclient.dto.PdfSelectionTableItem;
import org.pdfsam.i18n.GettextResource;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.RandomAccessFileOrArray;
import com.lowagie.text.pdf.SimpleBookmark;
/**
* Panel with the bookmarks level combo and the button to fill it
* @author Andrea Vacondio
*
*/
public class JBLevelCombo extends JPanel {
private static final long serialVersionUID = -1413124292303614507L;
private static final Logger log = Logger.getLogger(JBLevelCombo.class.getPackage().getName());
private JComboBox levelCombo;
private JButton fillCombo;
private JPdfSelectionPanel inputPanel;
private Thread filler = null;
public JBLevelCombo(JPdfSelectionPanel inputPanel) {
this.inputPanel = inputPanel;
init();
}
private void init(){
levelCombo = new JComboBox();
levelCombo.setPreferredSize(new Dimension(45,20));
fillCombo = new JButton();
fillCombo.setText("< "+GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),"Fill from document"));
levelCombo.setEditable(true);
fillCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
PdfSelectionTableItem[] items = inputPanel.getTableRows();
if (items != null && items.length == 1) {
if(filler == null){
filler = new Thread(new FillThread(items[0]));
filler.start();
}
}
else {
JOptionPane.showMessageDialog(getParent(), GettextResource.gettext(Configuration.getInstance()
.getI18nResourceBundle(), "Please select a pdf document."), GettextResource.gettext(
Configuration.getInstance().getI18nResourceBundle(), "Warning"), JOptionPane.WARNING_MESSAGE);
}
} catch (Exception ex) {
log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex);
}
}
});
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
add(Box.createHorizontalGlue());
add(levelCombo);
add(Box.createRigidArea(new Dimension(10, 0)));
add(fillCombo);
}
/**
* Fills the levels combo
* @author Andrea Vacondio
*
*/
private class FillThread implements Runnable {
private PdfSelectionTableItem item;
/**
* @param item
*/
public FillThread(PdfSelectionTableItem item) {
super();
this.item = item;
}
public void run() {
fillCombo.setEnabled(false);
fillCombo.setToolTipText(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Getting bookmarks max depth"));
try {
levelCombo.removeAllItems();
byte[] password = null;
if((item.getPassword()) != null && (item.getPassword()).length()>0){
password = item.getPassword().getBytes();
}
PdfReader pdfReader = new PdfReader(new RandomAccessFileOrArray(item.getInputFile().getAbsolutePath()),password);
pdfReader.consolidateNamedDestinations();
List bookmarks = SimpleBookmark.getBookmark(pdfReader);
ByteArrayOutputStream out = new ByteArrayOutputStream();
SimpleBookmark.exportToXML(bookmarks, out, "UTF-8", false);
ByteArrayInputStream input = new ByteArrayInputStream(out.toByteArray());
int maxDepth = PdfUtility.getMaxBookmarksDepth(input);
for(int i = 1; i<=maxDepth; i++){
levelCombo.addItem(i+"");
}
} catch (Throwable t) {
log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), t);
} finally {
fillCombo.setEnabled(true);
fillCombo.setToolTipText(null);
filler = null;
}
}
}
public void resetComponent(){
levelCombo.removeAllItems();
setEnabled(isEnabled());
}
/**
* @return selected index
* @see javax.swing.JComboBox#getSelectedIndex()
*/
public int getSelectedIndex() {
return levelCombo.getSelectedIndex();
}
/**
* @return selected item
* @see javax.swing.JComboBox#getSelectedItem()
*/
public Object getSelectedItem() {
return levelCombo.getSelectedItem();
}
/**
*
* @see javax.swing.JComboBox#removeAllItems()
*/
public void removeAllItems() {
levelCombo.removeAllItems();
}
/**
* @param anObject
* @see javax.swing.JComboBox#setSelectedItem(java.lang.Object)
*/
public void setSelectedItem(Object anObject) {
levelCombo.setSelectedItem(anObject);
}
/* (non-Javadoc)
* @see javax.swing.JComponent#setEnabled(boolean)
*/
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
levelCombo.setEnabled(enabled);
fillCombo.setEnabled(enabled);
}
/**
* @return the levelCombo
*/
public JComboBox getLevelCombo() {
return levelCombo;
}
/**
* @return the fillCombo
*/
public JButton getFillCombo() {
return fillCombo;
}
/* (non-Javadoc)
* @see javax.swing.JComponent#requestFocus()
*/
public void requestFocus() {
levelCombo.requestFocus();
}
}
pdfsam-1.1.4/pdfsam-split/src/java/org/pdfsam/plugin/split/components/JSplitRadioButtonModel.java 0000644 0001750 0001750 00000002750 10725771640 033140 0 ustar twerner twerner /*
* Created on 02-Dec-2007
* Copyright (C) 2007 by Andrea Vacondio.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation;
* either version 2 of the License.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.pdfsam.plugin.split.components;
import javax.swing.JToggleButton.ToggleButtonModel;
/**
* Model for the split radio buttons
* @author Andrea Vacondio
*
*/
public class JSplitRadioButtonModel extends ToggleButtonModel {
private static final long serialVersionUID = -541344769909895211L;
private String splitCommand;
/**
*
*/
public JSplitRadioButtonModel(String splitCommand) {
super();
this.splitCommand = splitCommand;
}
/**
* @return the splitCommand
*/
public String getSplitCommand() {
return splitCommand;
}
/**
* @param splitCommand the splitCommand to set
*/
public void setSplitCommand(String splitCommand) {
this.splitCommand = splitCommand;
}
}
pdfsam-1.1.4/pdfsam-split/src/java/org/pdfsam/plugin/split/GUI/ 0000755 0001750 0001750 00000000000 10725773622 024171 5 ustar twerner twerner pdfsam-1.1.4/pdfsam-split/src/java/org/pdfsam/plugin/split/GUI/SplitMainGUI.java 0000644 0001750 0001750 00000141035 11211203054 027257 0 ustar twerner twerner /*
* Created on 17-Feb-2006
* Copyright (C) 2006 by Andrea Vacondio.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation;
* either version 2 of the License.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.pdfsam.plugin.split.GUI;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FocusTraversalPolicy;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.LinkedList;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import org.apache.log4j.Logger;
import org.dom4j.Element;
import org.dom4j.Node;
import org.pdfsam.console.business.dto.commands.AbstractParsedCommand;
import org.pdfsam.console.business.dto.commands.MixParsedCommand;
import org.pdfsam.console.business.dto.commands.SplitParsedCommand;
import org.pdfsam.guiclient.business.listeners.EnterDoClickListener;
import org.pdfsam.guiclient.commons.business.SoundPlayer;
import org.pdfsam.guiclient.commons.business.WorkExecutor;
import org.pdfsam.guiclient.commons.business.WorkThread;
import org.pdfsam.guiclient.commons.business.listeners.CompressCheckBoxItemListener;
import org.pdfsam.guiclient.commons.components.CommonComponentsFactory;
import org.pdfsam.guiclient.commons.components.JPdfVersionCombo;
import org.pdfsam.guiclient.commons.models.AbstractPdfSelectionTableModel;
import org.pdfsam.guiclient.commons.models.SimplePdfSelectionTableModel;
import org.pdfsam.guiclient.commons.panels.JPdfSelectionPanel;
import org.pdfsam.guiclient.configuration.Configuration;
import org.pdfsam.guiclient.dto.PdfSelectionTableItem;
import org.pdfsam.guiclient.dto.StringItem;
import org.pdfsam.guiclient.exceptions.LoadJobException;
import org.pdfsam.guiclient.exceptions.SaveJobException;
import org.pdfsam.guiclient.gui.components.JHelpLabel;
import org.pdfsam.guiclient.plugins.interfaces.AbstractPlugablePanel;
import org.pdfsam.guiclient.utils.DialogUtility;
import org.pdfsam.i18n.GettextResource;
import org.pdfsam.plugin.split.components.JBLevelCombo;
import org.pdfsam.plugin.split.components.JSplitRadioButton;
import org.pdfsam.plugin.split.components.JSplitRadioButtonModel;
import org.pdfsam.plugin.split.components.JSplitSizeCombo;
import org.pdfsam.plugin.split.listeners.RadioListener;
/**
* Plugable JPanel provides a GUI for split functions.
* @author Andrea Vacondio
* @see javax.swing.JPanel
*/
public class SplitMainGUI extends AbstractPlugablePanel{
private static final long serialVersionUID = -5907189950338614835L;
private static final Logger log = Logger.getLogger(SplitMainGUI.class.getPackage().getName());
private JTextField outPrefixText = CommonComponentsFactory.getInstance().createTextField(CommonComponentsFactory.PREFIX_TEXT_FIELD_TYPE);
private SpringLayout outputPanelLayout;
private SpringLayout destinationPanelLayout;
private JTextField destinationFolderText = CommonComponentsFactory.getInstance().createTextField(CommonComponentsFactory.DESTINATION_TEXT_FIELD_TYPE);
private JTextField thisPageTextField = CommonComponentsFactory.getInstance().createTextField(CommonComponentsFactory.SIMPLE_TEXT_FIELD_TYPE);
private JTextField nPagesTextField = CommonComponentsFactory.getInstance().createTextField(CommonComponentsFactory.SIMPLE_TEXT_FIELD_TYPE);
private JHelpLabel checksHelpLabel;
private SpringLayout optionsPaneLayout;
private JHelpLabel prefixHelpLabel;
private JHelpLabel destinationHelpLabel;
private SpringLayout splitSpringLayout;
private String splitType = "";
private JPdfVersionCombo versionCombo = new JPdfVersionCombo(true);
private Configuration config;
private JPdfSelectionPanel selectionPanel = new JPdfSelectionPanel(JPdfSelectionPanel.SINGLE_SELECTABLE_FILE, SimplePdfSelectionTableModel.DEFAULT_SHOWED_COLUMNS_NUMBER);
private JSplitSizeCombo splitSizeCombo = new JSplitSizeCombo();
private JBLevelCombo bLevelCombo = new JBLevelCombo(selectionPanel);
//file_chooser
private JFileChooser browseDestFileChooser = null;
//button
private final JButton browseDestButton = CommonComponentsFactory.getInstance().createButton(CommonComponentsFactory.BROWSE_BUTTON_TYPE);
private final JButton runButton = CommonComponentsFactory.getInstance().createButton(CommonComponentsFactory.RUN_BUTTON_TYPE);
//key_listeners
private final EnterDoClickListener browsedEnterkeyListener = new EnterDoClickListener(browseDestButton);
private final EnterDoClickListener runEnterkeyListener = new EnterDoClickListener(runButton);
//split_radio
private final JSplitRadioButton burstRadio = new JSplitRadioButton(SplitParsedCommand.S_BURST);
private final JSplitRadioButton everyNRadio = new JSplitRadioButton(SplitParsedCommand.S_NSPLIT);
private final JSplitRadioButton evenRadio = new JSplitRadioButton(SplitParsedCommand.S_EVEN);
private final JSplitRadioButton oddRadio = new JSplitRadioButton(SplitParsedCommand.S_ODD);
private final JSplitRadioButton thisPageRadio = new JSplitRadioButton(SplitParsedCommand.S_SPLIT);
private final JSplitRadioButton sizeRadio = new JSplitRadioButton(SplitParsedCommand.S_SIZE);
private final JSplitRadioButton bookmarksLevel = new JSplitRadioButton(SplitParsedCommand.S_BLEVEL);
private RadioListener radioListener;
//radio
private final JRadioButton sameAsSourceRadio = new JRadioButton();
private final JRadioButton chooseAFolderRadio = new JRadioButton();
private ButtonGroup splitOptionsRadioGroup;
//checks
private final JCheckBox overwriteCheckbox = CommonComponentsFactory.getInstance().createCheckBox(CommonComponentsFactory.OVERWRITE_CHECKBOX_TYPE);
private final JCheckBox outputCompressedCheck = CommonComponentsFactory.getInstance().createCheckBox(CommonComponentsFactory.COMPRESS_CHECKBOX_TYPE);
//focus policy
private final SplitFocusPolicy splitFocusPolicy = new SplitFocusPolicy();
//panels
private final JPanel splitOptionsPanel = new JPanel();
private final JPanel destinationPanel = new JPanel();
private final JPanel outputOptionsPanel = new JPanel();
private final JPanel splitTypesPanel = new JPanel();
//labels
private final JLabel outPrefixLabel = new JLabel();
private final JLabel outputVersionLabel = CommonComponentsFactory.getInstance().createLabel(CommonComponentsFactory.PDF_VERSION_LABEL);
private final String PLUGIN_AUTHOR = "Andrea Vacondio";
private final String PLUGIN_VERSION = "0.5.3";
/**
* Constructor
*
*/
public SplitMainGUI() {
super();
initialize();
}
private void initialize() {
config = Configuration.getInstance();
setPanelIcon("/images/split.png");
setPreferredSize(new Dimension(500,555));
//
splitSpringLayout = new SpringLayout();
setLayout(splitSpringLayout);
add(selectionPanel);
//SPLIT_SECTION
optionsPaneLayout = new SpringLayout();
splitOptionsPanel.setLayout(optionsPaneLayout);
splitOptionsPanel.setBorder(BorderFactory.createTitledBorder(GettextResource.gettext(config.getI18nResourceBundle(),"Split options")));
add(splitOptionsPanel);
GridLayout splitOptionsLayout = new GridLayout(0,3,5,5);
splitTypesPanel.setLayout(splitOptionsLayout);
burstRadio.setText(GettextResource.gettext(config.getI18nResourceBundle(),"Burst (split into single pages)"));
everyNRadio.setText(GettextResource.gettext(config.getI18nResourceBundle(),"Split every \"n\" pages"));
evenRadio.setText(GettextResource.gettext(config.getI18nResourceBundle(),"Split even pages"));
oddRadio.setText(GettextResource.gettext(config.getI18nResourceBundle(),"Split odd pages"));
nPagesTextField.setEnabled(false);
thisPageRadio.setText(GettextResource.gettext(config.getI18nResourceBundle(),"Split after these pages"));
sizeRadio.setText(GettextResource.gettext(config.getI18nResourceBundle(),"Split at this size"));
bookmarksLevel.setText(GettextResource.gettext(config.getI18nResourceBundle(),"Split by bookmarks level"));
thisPageTextField.setEnabled(false);
splitSizeCombo.setEnabled(false);
bLevelCombo.setEnabled(false);
splitTypesPanel.add(burstRadio);
splitTypesPanel.add(thisPageRadio);
splitTypesPanel.add(thisPageTextField);
splitTypesPanel.add(evenRadio);
splitTypesPanel.add(everyNRadio);
splitTypesPanel.add(nPagesTextField);
splitTypesPanel.add(oddRadio);
splitTypesPanel.add(sizeRadio);
splitTypesPanel.add(splitSizeCombo);
splitTypesPanel.add(new JLabel());
splitTypesPanel.add(bookmarksLevel);
splitTypesPanel.add(bLevelCombo);
splitOptionsPanel.add(splitTypesPanel);
String helpText =
"
"+GettextResource.gettext(config.getI18nResourceBundle(),"Split options")+"" +
"- "+GettextResource.gettext(config.getI18nResourceBundle(),"Burst")+": "+GettextResource.gettext(config.getI18nResourceBundle(),"Explode the pdf document into single pages")+".
" +
"- "+GettextResource.gettext(config.getI18nResourceBundle(),"Split every \"n\" pages")+": "+GettextResource.gettext(config.getI18nResourceBundle(),"Split the document every \"n\" pages")+".
" +
"- "+GettextResource.gettext(config.getI18nResourceBundle(),"Split even pages")+": "+GettextResource.gettext(config.getI18nResourceBundle(),"Split the document every even page")+".
" +
"- "+GettextResource.gettext(config.getI18nResourceBundle(),"Split odd pages")+": "+GettextResource.gettext(config.getI18nResourceBundle(),"Split the document every odd page")+".
" +
"- "+GettextResource.gettext(config.getI18nResourceBundle(),"Split after these pages")+": "+GettextResource.gettext(config.getI18nResourceBundle(),"Split the document after page numbers (num1-num2-num3..)")+".
" +
"- "+GettextResource.gettext(config.getI18nResourceBundle(),"Split at this size")+": "+GettextResource.gettext(config.getI18nResourceBundle(),"Split the document in files of the given size (roughly)")+".
" +
"- "+GettextResource.gettext(config.getI18nResourceBundle(),"Split by bookmarks level")+": "+GettextResource.gettext(config.getI18nResourceBundle(),"Split the document at pages referred by bookmarks of the given level")+".
" +
"
";
checksHelpLabel = new JHelpLabel(helpText, true);
splitOptionsPanel.add(checksHelpLabel);
//END_SPLIT_SECTION
//RADIO_LISTENERS
/*This listeners enable or disable text field based on what you select*/
radioListener = new RadioListener(this, nPagesTextField, thisPageTextField, splitSizeCombo, bLevelCombo);
burstRadio.setActionCommand(RadioListener.DISABLE_ALL);
burstRadio.addActionListener(radioListener);
everyNRadio.setActionCommand(RadioListener.ENABLE_FIRST);
everyNRadio.addActionListener(radioListener);
evenRadio.setActionCommand(RadioListener.DISABLE_ALL);
evenRadio.addActionListener(radioListener);
oddRadio.setActionCommand(RadioListener.DISABLE_ALL);
oddRadio.addActionListener(radioListener);
thisPageRadio.setActionCommand(RadioListener.ENABLE_SECOND);
thisPageRadio.addActionListener(radioListener);
sizeRadio.setActionCommand(RadioListener.ENABLE_THIRD);
sizeRadio.addActionListener(radioListener);
bookmarksLevel.setActionCommand(RadioListener.ENABLE_FOURTH);
bookmarksLevel.addActionListener(radioListener);
//END_RADIO_LISTENERS
//DESTINATION_PANEL
destinationPanelLayout = new SpringLayout();
destinationPanel.setLayout(destinationPanelLayout);
destinationPanel.setBorder(BorderFactory.createTitledBorder(GettextResource.gettext(config.getI18nResourceBundle(),"Destination folder")));
add(destinationPanel);
//END_DESTINATION_PANEL
//DESTINATION_RADIOS
sameAsSourceRadio.setText(GettextResource.gettext(config.getI18nResourceBundle(),"Same as source"));
destinationPanel.add(sameAsSourceRadio);
chooseAFolderRadio.setSelected(true);
chooseAFolderRadio.setText(GettextResource.gettext(config.getI18nResourceBundle(),"Choose a folder"));
destinationPanel.add(chooseAFolderRadio);
//END_DESTINATION_RADIOS
//RADIOGROUP
splitOptionsRadioGroup = new ButtonGroup();
splitOptionsRadioGroup.add(burstRadio);
splitOptionsRadioGroup.add(everyNRadio);
splitOptionsRadioGroup.add(evenRadio);
splitOptionsRadioGroup.add(oddRadio);
splitOptionsRadioGroup.add(thisPageRadio);
splitOptionsRadioGroup.add(sizeRadio);
splitOptionsRadioGroup.add(bookmarksLevel);
final ButtonGroup outputRadioGroup = new ButtonGroup();
outputRadioGroup.add(sameAsSourceRadio);
outputRadioGroup.add(chooseAFolderRadio);
//END_RADIOGROUP
destinationPanel.add(destinationFolderText);
destinationPanel.add(overwriteCheckbox);
destinationPanel.add(outputCompressedCheck);
outputCompressedCheck.addItemListener(new CompressCheckBoxItemListener(versionCombo));
outputCompressedCheck.setSelected(true);
destinationPanel.add(versionCombo);
destinationPanel.add(outputVersionLabel);
browseDestButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(browseDestFileChooser==null){
browseDestFileChooser = new JFileChooser(Configuration.getInstance().getDefaultWorkingDir());
browseDestFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
File chosenFile = null;
if(destinationFolderText.getText().length()>0){
browseDestFileChooser.setCurrentDirectory(new File(destinationFolderText.getText()));
}
if (browseDestFileChooser.showOpenDialog(browseDestButton.getParent()) == JFileChooser.APPROVE_OPTION){
chosenFile = browseDestFileChooser.getSelectedFile();
}
//write the destination in text field
if (chosenFile != null && chosenFile.isDirectory()){
try{
destinationFolderText.setText(chosenFile.getAbsolutePath());
}
catch (Exception ex){
log.error(GettextResource.gettext(config.getI18nResourceBundle(),"Error: "), ex);
}
}
}
});
destinationPanel.add(browseDestButton);
//HELP_LABEL_DESTINATION
String helpTextDest =
""+GettextResource.gettext(config.getI18nResourceBundle(),"Destination output directory")+"" +
""+GettextResource.gettext(config.getI18nResourceBundle(),"Use the same output folder as the input file or choose a folder.")+"
"+
""+GettextResource.gettext(config.getI18nResourceBundle(),"To choose a folder browse or enter the full path to the destination output directory.")+"
"+
""+GettextResource.gettext(config.getI18nResourceBundle(),"Check the box if you want to overwrite the output files if they already exist.")+"
"+
""+GettextResource.gettext(config.getI18nResourceBundle(),"Check the box if you want compressed output files.")+" "+GettextResource.gettext(config.getI18nResourceBundle(),"PDF version 1.5 or above.")+"
"+
""+GettextResource.gettext(config.getI18nResourceBundle(),"Set the pdf version of the ouput document.")+"
"+
"";
destinationHelpLabel = new JHelpLabel(helpTextDest, true);
destinationPanel.add(destinationHelpLabel);
//END_HELP_LABEL_DESTINATION
//S_PANEL
outputOptionsPanel.setBorder(BorderFactory.createTitledBorder(GettextResource.gettext(config.getI18nResourceBundle(),"Output options")));
outputPanelLayout = new SpringLayout();
outputOptionsPanel.setLayout(outputPanelLayout);
add(outputOptionsPanel);
outPrefixLabel.setText(GettextResource.gettext(config.getI18nResourceBundle(),"Output file names prefix:"));
outputOptionsPanel.add(outPrefixLabel);
outPrefixText.setPreferredSize(new Dimension(180,20));
outputOptionsPanel.add(outPrefixText);
//END_S_PANEL
//HELP_LABEL_PREFIX
String helpTextPrefix =
""+GettextResource.gettext(config.getI18nResourceBundle(),"Output files prefix")+"" +
" "+GettextResource.gettext(config.getI18nResourceBundle(),"If it contains \"[CURRENTPAGE]\", \"[TIMESTAMP]\", \"[FILENUMBER]\" or \"[BOOKMARK_NAME]\" it performs variable substitution.")+"
"+
" "+GettextResource.gettext(config.getI18nResourceBundle(),"Ex. prefix_[BASENAME]_[CURRENTPAGE] generates prefix_FileName_005.pdf.")+"
"+
"
"+GettextResource.gettext(config.getI18nResourceBundle(),"If it doesn't contain \"[CURRENTPAGE]\", \"[TIMESTAMP]\" or \"[FILENUMBER]\" it generates oldstyle output file names.")+"
"+
"
"+GettextResource.gettext(config.getI18nResourceBundle(),"Available variables")+": [CURRENTPAGE], [TIMESTAMP], [BASENAME], [FILENUMBER], [BOOKMARK_NAME].
"+
"";
prefixHelpLabel = new JHelpLabel(helpTextPrefix, true);
outputOptionsPanel.add(prefixHelpLabel);
//END_HELP_LABEL_PREFIX
//RUN_BUTTON
//listener
runButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (WorkExecutor.getInstance().getRunningThreads() > 0 || selectionPanel.isAdding()){
log.info(GettextResource.gettext(config.getI18nResourceBundle(),"Please wait while all files are processed.."));
return;
}
final LinkedList args = new LinkedList();
try{
PdfSelectionTableItem item = null;
PdfSelectionTableItem[] items = selectionPanel.getTableRows();
if(items != null && items.length == 1){
item = items[0];
args.add("-"+SplitParsedCommand.F_ARG);
String f = item.getInputFile().getAbsolutePath();
if((item.getPassword()) != null && (item.getPassword()).length()>0){
log.debug(GettextResource.gettext(config.getI18nResourceBundle(),"Found a password for input file."));
f +=":"+item.getPassword();
}
args.add(f);
args.add("-"+SplitParsedCommand.P_ARG);
args.add(outPrefixText.getText());
args.add("-"+SplitParsedCommand.S_ARG);
args.add(splitType);
//check if is needed page option
if (splitType.equals(SplitParsedCommand.S_SPLIT)){
args.add("-"+SplitParsedCommand.N_ARG);
args.add(thisPageTextField.getText());
}else if (splitType.equals(SplitParsedCommand.S_NSPLIT)){
args.add("-"+SplitParsedCommand.N_ARG);
args.add(nPagesTextField.getText());
}else if (splitType.equals(SplitParsedCommand.S_SIZE)){
args.add("-"+SplitParsedCommand.B_ARG);
if(splitSizeCombo.isSelectedItem() && splitSizeCombo.isValidSelectedItem()){
args.add(Long.toString(splitSizeCombo.getSelectedBytes()));
}else{
throw new Exception(GettextResource.gettext(config.getI18nResourceBundle(),"Invalid split size"));
}
} else if (splitType.equals(SplitParsedCommand.S_BLEVEL)){
args.add("-"+SplitParsedCommand.BL_ARG);
args.add((String)bLevelCombo.getSelectedItem());
}
args.add("-"+SplitParsedCommand.O_ARG);
//check radio for output options
if (sameAsSourceRadio.isSelected()){
if(item != null){
args.add(item.getInputFile().getParent());
}
}else{
if(destinationFolderText.getText()==null || destinationFolderText.getText().length()==0){
String suggestedDir = Configuration.getInstance().getDefaultWorkingDir();
if(suggestedDir != null){
int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(getParent(),suggestedDir);
if(JOptionPane.YES_OPTION == chosenOpt){
destinationFolderText.setText(suggestedDir);
}else if(JOptionPane.CANCEL_OPTION == chosenOpt){
return;
}
}
}
args.add(destinationFolderText.getText());
}
if (overwriteCheckbox.isSelected()) args.add("-"+SplitParsedCommand.OVERWRITE_ARG);
if (outputCompressedCheck.isSelected()) args.add("-"+SplitParsedCommand.COMPRESSED_ARG);
args.add("-"+MixParsedCommand.PDFVERSION_ARG);
if(JPdfVersionCombo.SAME_AS_SOURCE.equals(((StringItem)versionCombo.getSelectedItem()).getId())){
StringItem minItem = versionCombo.getMinItem();
String currentPdfVersion = Character.toString(item.getPdfVersion());
if(minItem != null){
if(Integer.parseInt(currentPdfVersion) < Integer.parseInt(minItem.getId())){
if(JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(getParent(),
GettextResource.gettext(config.getI18nResourceBundle(),"The lowest available pdf version is ")+minItem.getDescription()+".\n"+GettextResource.gettext(config.getI18nResourceBundle(),"You selected a lower output pdf version, continue anyway ?"),
GettextResource.gettext(config.getI18nResourceBundle(),"Pdf version conflict"),
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE)){
return;
}
}
}
args.add(currentPdfVersion);
}else{
args.add(((StringItem)versionCombo.getSelectedItem()).getId());
}
args.add(AbstractParsedCommand.COMMAND_SPLIT);
final String[] myStringArray = (String[])args.toArray(new String[args.size()]);
WorkExecutor.getInstance().execute(new WorkThread(myStringArray));
}else{
JOptionPane.showMessageDialog(getParent(),
GettextResource.gettext(config.getI18nResourceBundle(),"Please select a pdf document."),
GettextResource.gettext(config.getI18nResourceBundle(),"Warning"),
JOptionPane.WARNING_MESSAGE);
}
}catch(Exception ex){
log.error(GettextResource.gettext(config.getI18nResourceBundle(),"Error: "), ex);
SoundPlayer.getInstance().playErrorSound();
}
}
});
runButton.setToolTipText(GettextResource.gettext(config.getI18nResourceBundle(),"Split selected file"));
runButton.setMargin(new Insets(5, 5, 5, 5));
runButton.setSize(new Dimension(88,25));
add(runButton);
//END_RUN_BUTTON
//RADIO_LISTENERS
sameAsSourceRadio.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
destinationFolderText.setEnabled(false);
browseDestButton.setEnabled(false);
}
});
chooseAFolderRadio.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
destinationFolderText.setEnabled(true);
browseDestButton.setEnabled(true);
}
});
//END_RADIO_LISTENERS
//ENTER_KEY_LISTENERS
browseDestButton.addKeyListener(browsedEnterkeyListener);
runButton.addKeyListener(runEnterkeyListener);
outPrefixText.addKeyListener(runEnterkeyListener);
//END_ENTER_KEY_LISTENERS
setLayout();
}
/**
* @return Returns the Plugin author.
*/
public String getPluginAuthor() {
return PLUGIN_AUTHOR;
}
/**
* @return Returns the Plugin name.
*/
public String getPluginName() {
return GettextResource.gettext(config.getI18nResourceBundle(),"Split");
}
/**
* @return Returns the version.
*/
public String getVersion() {
return PLUGIN_VERSION;
}
public Node getJobNode(Node arg0, boolean savePasswords) throws SaveJobException {
try{
if (arg0 != null){
Element fileSource = ((Element)arg0).addElement("source");
PdfSelectionTableItem[] items = selectionPanel.getTableRows();
if(items != null && items.length>0){
fileSource.addAttribute("value",items[0].getInputFile().getAbsolutePath());
if(savePasswords){
fileSource.addAttribute("password",items[0].getPassword());
}
}
Element splitOption = ((Element)arg0).addElement("split_option");
if(splitOptionsRadioGroup.getSelection() != null){
splitOption.addAttribute("value",((JSplitRadioButtonModel)splitOptionsRadioGroup.getSelection()).getSplitCommand());
}
Element splitNpages = ((Element)arg0).addElement("npages");
splitNpages.addAttribute("value", nPagesTextField.getText());
Element splitThispage = ((Element)arg0).addElement("thispage");
splitThispage.addAttribute("value", thisPageTextField.getText());
Element splitSize = ((Element)arg0).addElement("splitsize");
splitSize.addAttribute("value", splitSizeCombo.getSelectedItem().toString());
Element bookLevel = ((Element)arg0).addElement("bookmarkslevel");
if(bLevelCombo.getSelectedItem() != null){
bookLevel.addAttribute("value", bLevelCombo.getSelectedItem().toString());
}
Element fileDestination = ((Element)arg0).addElement("destination");
fileDestination.addAttribute("value", destinationFolderText.getText());
Element filePrefix = ((Element)arg0).addElement("prefix");
filePrefix.addAttribute("value", outPrefixText.getText());
Element file_overwrite = ((Element)arg0).addElement("overwrite");
file_overwrite.addAttribute("value", overwriteCheckbox.isSelected()?TRUE:FALSE);
Element fileCompress = ((Element)arg0).addElement("compressed");
fileCompress.addAttribute("value", outputCompressedCheck.isSelected()?TRUE:FALSE);
Element pdfVersion = ((Element)arg0).addElement("pdfversion");
pdfVersion.addAttribute("value", ((StringItem)versionCombo.getSelectedItem()).getId());
}
return arg0;
}
catch (Exception ex){
throw new SaveJobException(ex);
}
}
public void loadJobNode(Node arg0) throws LoadJobException {
if(arg0!=null){
try{
resetPanel();
Node fileSource = (Node) arg0.selectSingleNode("source/@value");
if (fileSource != null && fileSource.getText().length()>0){
Node filePwd = (Node) arg0.selectSingleNode("source/@password");
String password = null;
if (filePwd != null && filePwd.getText().length()>0){
password = filePwd.getText();
}
selectionPanel.getLoader().addFile(new File(fileSource.getText()), password);
}
Node splitOption = (Node) arg0.selectSingleNode("split_option/@value");
if (splitOption != null){
if(splitOption.getText().equals(burstRadio.getSplitCommand())) burstRadio.doClick();
else if(splitOption.getText().equals(everyNRadio.getSplitCommand())) everyNRadio.doClick();
else if(splitOption.getText().equals(evenRadio.getSplitCommand())) evenRadio.doClick();
else if(splitOption.getText().equals(oddRadio.getSplitCommand())) oddRadio.doClick();
else if(splitOption.getText().equals(thisPageRadio.getSplitCommand())) thisPageRadio.doClick();
else if(splitOption.getText().equals(sizeRadio.getSplitCommand())) sizeRadio.doClick();
else if(splitOption.getText().equals(bookmarksLevel.getSplitCommand())) bookmarksLevel.doClick();
}
Node splitNpages = (Node) arg0.selectSingleNode("npages/@value");
if (splitNpages != null){
nPagesTextField.setText(splitNpages.getText());
}
Node splitThispage = (Node) arg0.selectSingleNode("thispage/@value");
if (splitThispage != null){
thisPageTextField.setText(splitThispage.getText());
}
Node splitSize = (Node) arg0.selectSingleNode("splitsize/@value");
if (splitSize != null){
splitSizeCombo.setSelectedItem(splitSize.getText());
}
Node bookLevel = (Node) arg0.selectSingleNode("bookmarkslevel/@value");
if (bookLevel != null){
bLevelCombo.setSelectedItem(bookLevel.getText());
}
Node fileDestination = (Node) arg0.selectSingleNode("destination/@value");
if (fileDestination != null && fileDestination.getText().length()>0){
destinationFolderText.setText(fileDestination.getText());
chooseAFolderRadio.doClick();
}else{
sameAsSourceRadio.doClick();
}
Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value");
if (fileOverwrite != null){
overwriteCheckbox.setSelected(TRUE.equals(fileOverwrite.getText()));
}
Node fileCompressed = (Node) arg0.selectSingleNode("compressed/@value");
if (fileCompressed != null && TRUE.equals(fileCompressed.getText())){
outputCompressedCheck.doClick();
}
Node filePrefix = (Node) arg0.selectSingleNode("prefix/@value");
if (filePrefix != null){
outPrefixText.setText(filePrefix.getText());
}
Node pdfVersion = (Node) arg0.selectSingleNode("pdfversion/@value");
if (pdfVersion != null){
for (int i = 0; i