Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch processing GUI #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions jsignpdf/src/main/java/net/sf/jsignpdf/BatchFilelistTableModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package net.sf.jsignpdf;

import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import org.apache.commons.io.FilenameUtils;

/**
*
* @author jansv
*/
public class BatchFilelistTableModel extends AbstractTableModel {

private final List<BasicSignerOptions> optionsList;

private final String[] columnNames = {
"Path", "Filename", "New name"
};
private final Class[] columnTypes = new Class[]{
java.lang.String.class, java.lang.String.class, java.lang.String.class
};
private final boolean[] columnCanEdit = new boolean[]{
false, false, false
};

public BatchFilelistTableModel() {
super();
this.optionsList = new ArrayList<>();
}

@Override
public int getRowCount() {
return optionsList.size();
}

@Override
public int getColumnCount() {
return columnTypes.length;
}

@Override
public Class getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}

@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnCanEdit[columnIndex];
}

@Override
public String getColumnName(int column) {
return columnNames[column];
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Object value = "??";
BasicSignerOptions options = this.getOptionsAt(rowIndex);
switch (columnIndex) {
case 0:
value = FilenameUtils.getPath(options.getInFile());
break;
case 1:
value = FilenameUtils.getName(options.getInFile());
break;
case 2:
value = FilenameUtils.getName(options.getOutFile());
break;
}

return value;
}

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
super.setValueAt(aValue, rowIndex, columnIndex); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/OverriddenMethodBody
}

public BasicSignerOptions getOptionsAt(int index) {
return optionsList.get(index);
}

public void setOutputSuffix(String suffix) {
if (suffix.equals("")) {
suffix = "_signed";
}
for (BasicSignerOptions options : optionsList) {
String newName = FilenameUtils.getBaseName(options.getInFile()) + suffix + ".pdf";
String parentDir = FilenameUtils.getPath(options.getInFile());
options.setOutFile(FilenameUtils.concat(parentDir, newName));
}
for (int row = 0; row < optionsList.size(); row++) {
fireTableCellUpdated(row, 2);
}
}

void removeRow(int i) {
this.optionsList.remove(i);
// LOGGER.log(Level.INFO, "Removed row at index {0}", i);
this.fireTableRowsDeleted(i, i);
}

void addFileOptions(BasicSignerOptions options) {
int newRowIndex = optionsList.size();
this.optionsList.add(options);
// LOGGER.log(Level.INFO, "Added file {0}", options.getInFile());
fireTableRowsInserted(newRowIndex, newRowIndex);
}

void addFiles(File[] chosenFiles, BasicSignerOptions defaultOptions, String fileSuffix) {
// LOGGER.log(Level.INFO, "Adding {0} entries", chosenFiles.length);
for (File file : chosenFiles) {
String suffix = !"".equals(fileSuffix) ? fileSuffix : "_signed";
String newName = FilenameUtils.getBaseName(file.getName()) + suffix + ".pdf";
String parentDir = file.getAbsoluteFile().getParent();

BasicSignerOptions options = (BasicSignerOptions) cloneObject(defaultOptions);
options.setInFile(file.getAbsolutePath());
options.setOutFile(FilenameUtils.concat(parentDir, newName));
this.addFileOptions(options);
}
}

/**
* Clones object
*
* @param obj Object to clone
* @return
*/
private static Object cloneObject(Object obj) {
try {
Object clone = obj.getClass().newInstance();
for (Field field : obj.getClass().getDeclaredFields()) {
field.setAccessible(true);
field.set(clone, field.get(obj));
}
return clone;
} catch (Exception e) {
return null;
}
}

}
121 changes: 121 additions & 0 deletions jsignpdf/src/main/java/net/sf/jsignpdf/BatchFrame.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-67,0,0,3,39"/>
</AuxValues>

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="scpFileList">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="0" gridWidth="2" gridHeight="4" fill="1" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="5" insetsBottom="5" insetsRight="5" anchor="10" weightX="100.0" weightY="100.0"/>
</Constraint>
</Constraints>

<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="tblFileList">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="tableModel" type="code"/>
</Property>
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
<TableColumnModel selectionModel="0"/>
</Property>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="btnAddFiles">
<Properties>
<Property name="text" type="java.lang.String" value="Add files"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnAddFilesActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="2" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="5" insetsBottom="5" insetsRight="5" anchor="19" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="btnRemoveFiles">
<Properties>
<Property name="text" type="java.lang.String" value="Remove files"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnRemoveFilesActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="2" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="5" insetsBottom="5" insetsRight="5" anchor="19" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="lblFileSuffix">
<Properties>
<Property name="text" type="java.lang.String" value="Suffix of signed files"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="4" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="5" insetsBottom="5" insetsRight="5" anchor="22" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="tfFileSuffix">
<Properties>
<Property name="text" type="java.lang.String" value="_signed"/>
</Properties>
<Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="tfFileSuffixFocusLost"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="tfFileSuffixActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="4" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="5" insetsBottom="5" insetsRight="5" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="btnSignFiles">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="sansserif" size="14" style="1"/>
</Property>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/net/sf/jsignpdf/signedpdf16.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Sign files"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSignFilesActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="2" gridY="5" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="5" insetsBottom="5" insetsRight="5" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Form>
Loading