Files
x07db/plugins/XPS.java
gac-ISS 34c56d7822
2023-01-18 17:07:49 +01:00

800 lines
34 KiB
Java

import ch.psi.pshell.scan.Scan;
import ch.psi.pshell.ui.ScriptProcessor;
import ch.psi.utils.EncoderJson;
import ch.psi.utils.IO;
import ch.psi.utils.State;
import ch.psi.utils.swing.StandardDialog;
import ch.psi.utils.swing.SwingUtils;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
/**
*
*/
public class XPS extends ScriptProcessor {
File currentFile;
final DefaultTableModel model;
public static final String FILE_EXTENSION = "xps";
public XPS() {
initComponents();
model = (DefaultTableModel) table.getModel();
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
if ((e.getClickCount() == 2) && (!e.isPopupTrigger())) {
if (table.isEnabled()){
int row = table.getSelectedRow();
if ((model.getRowCount()>0) && (row>=0)){
row = table.convertRowIndexToModel(row);
String name = (String) model.getValueAt(row, 1);
String json = (String) model.getValueAt(row, 2);
Map pars = (Map) EncoderJson.decode(json, Map.class);
pars.put("name", name);
Map<String, Object> newPars = showScientaParametersDialog(pars);
if (newPars!=null){
name = (String) newPars.get("name");
if (name!=null){
newPars.remove("name");
json = EncoderJson.encode(newPars, true);
//showMessage(name, json);
model.setValueAt(name, row, 1);
model.setValueAt(json, row, 2);
}
}
}
}
}
} catch (Exception ex) {
showException(ex);
}
}
});
table.getColumnModel().getColumn(0).setMaxWidth(60);
table.getColumnModel().getColumn(0).setResizable(false);
progress.setVisible(false);
updateButtons();
}
@Override
public String getType() {
return "XPS";
}
@Override
public boolean canSave() {
return true;
}
@Override
public String getFileName() {
return (currentFile==null) ? null : currentFile.toString();
}
@Override
public boolean createMenuNew() {
return true;
}
@Override
public boolean createFilePanel() {
return true;
}
@Override
public String getDescription() {
return "XPS scan definition file (*." + FILE_EXTENSION + ")";
}
@Override
public String[] getExtensions() {
return new String[]{FILE_EXTENSION};
}
@Override
public String getHomePath() {
return "{home}/parameters";
}
//Overridable callbacks
@Override
public void onInitialize(int runCount) {
progress.setVisible(false);
this.startTimer(1000);
}
@Override
public void onStateChange(State state, State former) {
buttonStart.setEnabled(state == State.Ready);
buttonAbort.setEnabled((state == State.Busy) && isRunning());
buttonScienta.setEnabled(state.isInitialized());
buttonAddToQueue.setEnabled(buttonStart.isEnabled());
updateButtons();
updateSeq();
}
@Override
public void onTimer() {
if (isRunning()){
progress.setVisible(true);
try {
progress.setValue((Integer) this.eval("int(scienta.getProgress()*1000)", true));
//this.getView().getStatusBar().setProgress(eval("scienta.getProgress()", true));
} catch (Exception ex) {
getLogger().log(Level.FINER, null, ex);
}
try{
Object region = getGlobalVar("CURRENT_REGION");
Object pass = getGlobalVar("CURRENT_PASS");
Number no_pases = (Number) getGlobalVar("PASSES");
String text = region.toString();
if (no_pases.intValue()>1){
text = text + " [" + pass + "]";
}
textCurScan.setText(text);
} catch(Exception ex){
getLogger().log(Level.FINER, null, ex);
textCurScan.setText("");
}
try{
int index = (Integer)getGlobalVar("CURRENT_INDEX");
for (int row=0; row<model.getRowCount(); row++){
if (Boolean.TRUE.equals(model.getValueAt(row, 0))){
if (index==0){
row = table.convertRowIndexToView(row);
table.setRowSelectionInterval(row, row);
break;
}
index--;
}
}
} catch(Exception ex){
getLogger().log(Level.FINER, null, ex);
table.clearSelection();
}
} else {
textCurScan.setText("");
progress.setVisible(false);
}
}
void updateSeq() {
try {
textFileId.setText(String.valueOf(getContext().getFileSequentialNumber()));
} catch (Exception ex) {
textFileId.setText("");
}
}
@Override
public void onExecutedFile(String fileName, Object result) {
}
//Callback to perform update - in event thread
@Override
protected void doUpdate() {
}
String getScanName() {
String name = textName.getText().trim();
return name.isEmpty() ? null : name;
}
@Override
public String getScript() {
return "templates/XPS";
}
@Override
public Map<String, Object> getArgs() {
HashMap<String, Object> args = new HashMap<>();
ArrayList regions = new ArrayList();
for (int i = 0; i < model.getRowCount(); i++) {
if (Boolean.TRUE.equals(model.getValueAt(i, 0))){
ArrayList region = new ArrayList();
region.add(model.getValueAt(i, 1));
region.add(model.getValueAt(i, 2));
regions.add(region);
}
}
args.put("FILE", null);
args.put("NAME", getScanName());
args.put("PASSES", spinnerPasses.getValue());
args.put("REGIONS", regions);
return args;
}
@Override
protected void onStartingExecution(Map<String, Object> args){
table.clearSelection();
}
@Override
protected void onFinishedExecution(Map<String, Object> args, Object ret, Throwable t){
}
@Override
public void saveAs(String fileName) throws IOException {
currentFile = new File(fileName);
ArrayList data = new ArrayList();
data.add(new Object[][]{new Object[]{textName.getText()}});
data.add(model.getDataVector());
data.add(new Object[][]{new Object[]{spinnerPasses.getValue()}});
String json = EncoderJson.encode(data, true);
Files.write(currentFile.toPath(), json.getBytes());
updateButtons();
}
@Override
public void open(String fileName) throws IOException {
if (fileName==null){
currentFile = null;
textName.setText("");
model.setRowCount(0);
spinnerPasses.setValue(1);
} else {
Path path = Paths.get(fileName);
String json = new String(Files.readAllBytes(path));
currentFile = path.toFile();
Object[][][] vector = (Object[][][]) EncoderJson.decode(json, Object[][][].class);
textName.setText(String.valueOf(vector[0][0][0]));
model.setDataVector(vector[1], SwingUtils.getTableColumnNames(table));
spinnerPasses.setValue((vector.length>2) ? (Integer)vector[2][0][0] : 1);
}
updateButtons();
}
Map<String, Object> showScientaParametersDialog(Map<String, Object> pars) throws Exception{
Class cls = getContext().getClassByName("ScientaParametersDialog");
Constructor constructor= cls.getConstructor(Window.class, boolean.class, Map.class);
StandardDialog dlg = (StandardDialog) constructor.newInstance(getWindow(),true, pars);
dlg.setVisible(true);
if (dlg.getResult()){
return (Map<String, Object>)cls.getMethod("getValues").invoke(dlg);
}
return null;
}
protected void updateButtons() {
boolean editing = !isExecuting();
int rows = model.getRowCount();
int cur = table.getSelectedRow();
buttonUp.setEnabled((rows > 0) && (cur > 0) && editing);
buttonDown.setEnabled((rows > 0) && (cur >= 0) && (cur < (rows - 1)) && editing);
buttonDelete.setEnabled((rows > 0) && (cur >= 0) && editing);
buttonInsert.setEnabled(editing);
buttonClear.setEnabled(editing);
buttonOpen.setEnabled(editing);
buttonSave.setEnabled(getState().isInitialized());
table.setEnabled(editing);
textName.setEnabled(editing);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane2 = new javax.swing.JScrollPane();
jEditorPane1 = new javax.swing.JEditorPane();
buttonStart = new javax.swing.JButton();
buttonAbort = new javax.swing.JButton();
buttonScienta = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
textName = new javax.swing.JTextField();
buttonOpen = new javax.swing.JButton();
buttonSave = new javax.swing.JButton();
buttonClear = new javax.swing.JButton();
buttonAddToQueue = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
spinnerPasses = new javax.swing.JSpinner();
jPanel1 = new javax.swing.JPanel();
buttonUp = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
table = new javax.swing.JTable();
buttonDown = new javax.swing.JButton();
buttonInsert = new javax.swing.JButton();
buttonDelete = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
textFileId = new javax.swing.JTextField();
buttonResetId = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
textCurScan = new javax.swing.JTextField();
progress = new javax.swing.JProgressBar();
jScrollPane2.setViewportView(jEditorPane1);
buttonStart.setText("Start");
buttonStart.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonStartActionPerformed(evt);
}
});
buttonAbort.setText("Abort");
buttonAbort.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonAbortActionPerformed(evt);
}
});
buttonScienta.setText("Scienta Panel");
buttonScienta.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonScientaActionPerformed(evt);
}
});
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters"));
jLabel1.setText("Name:");
textName.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
textNameActionPerformed(evt);
}
});
buttonOpen.setText("Open");
buttonOpen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonOpenActionPerformed(evt);
}
});
buttonSave.setText("Save");
buttonSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonSaveActionPerformed(evt);
}
});
buttonClear.setText("Clear");
buttonClear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonClearActionPerformed(evt);
}
});
buttonAddToQueue.setText("Add To Queue");
buttonAddToQueue.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonAddToQueueActionPerformed(evt);
}
});
jLabel3.setText("Passes:");
spinnerPasses.setModel(new javax.swing.SpinnerNumberModel(1, 1, 100, 1));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Regions"));
buttonUp.setText("Move Up");
buttonUp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonUpActionPerformed(evt);
}
});
table.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Enabled", "Region Name", "Arguments"
}
) {
Class[] types = new Class [] {
java.lang.Boolean.class, java.lang.Object.class, java.lang.String.class
};
boolean[] canEdit = new boolean [] {
true, true, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
table.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(java.awt.event.MouseEvent evt) {
tableMouseReleased(evt);
}
});
table.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
tableKeyReleased(evt);
}
});
jScrollPane1.setViewportView(table);
buttonDown.setText("Move Down");
buttonDown.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonDownActionPerformed(evt);
}
});
buttonInsert.setText("Insert");
buttonInsert.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonInsertActionPerformed(evt);
}
});
buttonDelete.setText("Delete");
buttonDelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonDeleteActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(buttonUp)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonDown)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonInsert)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonDelete)))
.addContainerGap())
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonDelete, buttonDown, buttonInsert, buttonUp});
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonInsert)
.addComponent(buttonDelete)
.addComponent(buttonUp)
.addComponent(buttonDown))
.addContainerGap())
);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textName)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonClear)
.addGap(5, 5, 5)
.addComponent(buttonOpen)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonSave))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spinnerPasses, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonAddToQueue))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(textName)
.addComponent(jLabel1)
.addComponent(buttonOpen)
.addComponent(buttonSave)
.addComponent(buttonClear))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(11, 11, 11)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonAddToQueue)
.addComponent(jLabel3)
.addComponent(spinnerPasses, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
);
jLabel2.setText("File ID:");
textFileId.setEditable(false);
textFileId.setHorizontalAlignment(javax.swing.JTextField.CENTER);
buttonResetId.setText("Reset");
buttonResetId.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonResetIdActionPerformed(evt);
}
});
jLabel4.setText("Current Region:");
textCurScan.setEditable(false);
textCurScan.setHorizontalAlignment(javax.swing.JTextField.CENTER);
progress.setMaximum(1000);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 421, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 34, Short.MAX_VALUE)
.addComponent(buttonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(33, 33, 33)
.addComponent(buttonAbort)
.addContainerGap(44, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textCurScan, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(buttonScienta, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGap(18, 18, Short.MAX_VALUE)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textFileId, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(buttonResetId, javax.swing.GroupLayout.Alignment.TRAILING))
.addContainerGap())))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonStart});
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonResetId, textCurScan, textFileId});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(8, 8, 8)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(textCurScan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(jLabel2)
.addComponent(textFileId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonResetId)
.addComponent(buttonScienta))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonStart)
.addComponent(buttonAbort))
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed
try {
execute();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonStartActionPerformed
private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed
try {
abort();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonAbortActionPerformed
private void buttonScientaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScientaActionPerformed
try {
this.showDevicePanel("scienta");
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonScientaActionPerformed
private void buttonResetIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonResetIdActionPerformed
try {
this.getContext().setFileSequentialNumber(0);
updateSeq();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonResetIdActionPerformed
private void buttonOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOpenActionPerformed
try {
open();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonOpenActionPerformed
private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed
try {
JFileChooser chooser = new JFileChooser(getContext().getSetup().expandPath(getHomePath()));
FileNameExtensionFilter filter = new FileNameExtensionFilter(getDescription(), getExtensions());
chooser.setFileFilter(filter);
try {
if (currentFile != null) {
chooser.setSelectedFile(currentFile);
} else if (getScanName() != null) {
File file = Paths.get(chooser.getCurrentDirectory().getAbsolutePath(), getScanName()).toFile();
chooser.setSelectedFile(file);
}
} catch (Exception ex) {
this.showException(ex);
}
int rVal = chooser.showSaveDialog(this);
if (rVal == JFileChooser.APPROVE_OPTION) {
String fileName = chooser.getSelectedFile().getAbsolutePath();
if (IO.getExtension(chooser.getSelectedFile().getAbsolutePath()).isEmpty()) {
fileName += "." + FILE_EXTENSION;
}
saveAs(fileName);
}
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonSaveActionPerformed
private void buttonAddToQueueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddToQueueActionPerformed
try {
//queue(getFileName()!=null); //If file is defined then queue file.
queue(); //Queue editing parameters
} catch (Exception ex) {
showException( ex);
}
}//GEN-LAST:event_buttonAddToQueueActionPerformed
private void textNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textNameActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_textNameActionPerformed
private void buttonClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonClearActionPerformed
try {
open(null);
} catch (Exception ex) {
showException( ex);
}
}//GEN-LAST:event_buttonClearActionPerformed
private void buttonInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonInsertActionPerformed
try {
Map<String, Object> pars = showScientaParametersDialog(null);
if (pars!=null){
String name = (String) pars.get("name");
if (name!=null){
pars.remove("name");
String json = EncoderJson.encode(pars, true);
model.addRow(new Object[]{true, name, json});
updateButtons();
}
}
} catch (Exception ex) {
showException( ex);
}
}//GEN-LAST:event_buttonInsertActionPerformed
private void buttonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDeleteActionPerformed
try {
if ((model.getRowCount() > 0) && (table.getSelectedRow() >= 0)) {
model.removeRow(table.getSelectedRow());
updateButtons();
}
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonDeleteActionPerformed
private void buttonUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUpActionPerformed
try {
int rows = model.getRowCount();
int cur = table.getSelectedRow();
model.moveRow(cur, cur, cur - 1);
table.setRowSelectionInterval(cur - 1, cur - 1);
updateButtons();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonUpActionPerformed
private void buttonDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDownActionPerformed
try {
int rows = model.getRowCount();
int cur = table.getSelectedRow();
model.moveRow(cur, cur, cur + 1);
table.setRowSelectionInterval(cur + 1, cur + 1);
updateButtons();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonDownActionPerformed
private void tableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyReleased
updateButtons();
}//GEN-LAST:event_tableKeyReleased
private void tableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseReleased
updateButtons();
}//GEN-LAST:event_tableMouseReleased
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton buttonAbort;
private javax.swing.JButton buttonAddToQueue;
private javax.swing.JButton buttonClear;
private javax.swing.JButton buttonDelete;
private javax.swing.JButton buttonDown;
private javax.swing.JButton buttonInsert;
private javax.swing.JButton buttonOpen;
private javax.swing.JButton buttonResetId;
private javax.swing.JButton buttonSave;
private javax.swing.JButton buttonScienta;
private javax.swing.JButton buttonStart;
private javax.swing.JButton buttonUp;
private javax.swing.JEditorPane jEditorPane1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JProgressBar progress;
private javax.swing.JSpinner spinnerPasses;
private javax.swing.JTable table;
private javax.swing.JTextField textCurScan;
private javax.swing.JTextField textFileId;
private javax.swing.JTextField textName;
// End of variables declaration//GEN-END:variables
}