package org.domainmath.gui.tools.plot;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import org.domainmath.gui.MainFrame;
public class PlotOptionsDialog extends javax.swing.JDialog {
public DefaultTableModel model;
private String more_cmd="";
public PlotOptionsDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
model = new DefaultTableModel();
model.addColumn("Data");
model.addColumn("Line Style");
initComponents();
dataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION );
dataTable.getTableHeader().setReorderingAllowed(false);
dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
dataTable.setRowHeight(20);
}
public String getMore_cmd() {
return more_cmd;
}
public void setMore_cmd(String more_cmd) {
this.more_cmd = more_cmd;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
cancelButton = new javax.swing.JButton();
OkButton = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
dataTextField = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
lineStyleComboBox = new javax.swing.JComboBox();
addDataButton = new javax.swing.JButton();
clearButton = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
removeDataButton = new javax.swing.JButton();
upDataButton = new javax.swing.JButton();
downButton = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
dataTable = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Plot Options");
setResizable(false);
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
OkButton.setText("OK");
OkButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
OkButtonActionPerformed(evt);
}
});
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Add Data"));
jLabel3.setText("Data");
jLabel4.setText("Line Style");
lineStyleComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "None", "-", ".", "+", "*", "o", "x", "p", "v", "r", "s", "<", ">", ":", "h", "^", "@" }));
addDataButton.setText("Add");
addDataButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addDataButtonActionPerformed(evt);
}
});
clearButton.setText("Clear");
clearButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearButtonActionPerformed(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(jLabel3)
.addComponent(jLabel4))
.addGap(30, 30, 30)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(dataTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
.addComponent(lineStyleComboBox, 0, 239, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(addDataButton, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(clearButton, javax.swing.GroupLayout.Alignment.TRAILING))
.addContainerGap())
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {addDataButton, clearButton});
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(6, 6, 6)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(dataTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(addDataButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(lineStyleComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(clearButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {addDataButton, clearButton});
jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {dataTextField, lineStyleComboBox});
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Data"));
removeDataButton.setText("Remove");
removeDataButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removeDataButtonActionPerformed(evt);
}
});
upDataButton.setText("Up");
upDataButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
upDataButtonActionPerformed(evt);
}
});
downButton.setText("Down");
downButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
downButtonActionPerformed(evt);
}
});
dataTable.setModel(model);
jScrollPane2.setViewportView(dataTable);
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()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGap(28, 28, 28)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(removeDataButton, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(upDataButton, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(downButton, javax.swing.GroupLayout.Alignment.TRAILING))
.addContainerGap())
);
jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {downButton, removeDataButton, upDataButton});
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(removeDataButton)
.addGap(18, 18, 18)
.addComponent(upDataButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(downButton)))
.addContainerGap())
);
jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {downButton, removeDataButton, upDataButton});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(OkButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cancelButton))
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {OkButton, cancelButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cancelButton)
.addComponent(OkButton))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {OkButton, cancelButton});
pack();
}// </editor-fold>//GEN-END:initComponents
private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
this.dataTextField.setText("");
}//GEN-LAST:event_clearButtonActionPerformed
private void addDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addDataButtonActionPerformed
String line_style=lineStyleComboBox.getSelectedItem().toString();
if(!dataTextField.getText().equals("")) {
if(line_style.equalsIgnoreCase("None")) {
String r[] = {dataTextField.getText(),line_style};
model.addRow(r);
}else{
String l=Character.toString('"')+line_style+Character.toString('"');
String r[] = {dataTextField.getText(),l};
model.addRow(r);
}
}
}//GEN-LAST:event_addDataButtonActionPerformed
private void removeDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeDataButtonActionPerformed
int selectedRowIndex =dataTable.getSelectedRow();
if(selectedRowIndex >=0){
model.removeRow(dataTable.getSelectedRow());
}
}//GEN-LAST:event_removeDataButtonActionPerformed
private void upDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upDataButtonActionPerformed
try{
model.moveRow(dataTable.getSelectedRow(), dataTable.getSelectedRow(), (dataTable.getSelectedRow()-1));
}catch(java.lang.ArrayIndexOutOfBoundsException e) {
}
}//GEN-LAST:event_upDataButtonActionPerformed
private void downButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downButtonActionPerformed
try{
model.moveRow(dataTable.getSelectedRow(), dataTable.getSelectedRow(), (dataTable.getSelectedRow()+1));
}catch(java.lang.ArrayIndexOutOfBoundsException e) {
}
}//GEN-LAST:event_downButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
private void OkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OkButtonActionPerformed
String plot_string="";
for(int i=0; i<dataTable.getRowCount(); i++) {
for(int j=0; j<dataTable.getColumnCount(); j++) {
if(!dataTable.getValueAt(i, j).toString().equals("None")){
plot_string+=dataTable.getValueAt(i, j).toString()+",";
}
}
}
if(!plot_string.equals("")) {
StringBuilder b= new StringBuilder(plot_string);
if(plot_string.endsWith(",")) {
String cmd="plot("+b.deleteCharAt(plot_string.length()-1) +");";
MainFrame.octavePanel.evalWithOutput(cmd);
MainFrame.octavePanel.evalWithOutput(this.getMore_cmd());
dispose();
}else{
String cmd="plot("+plot_string.substring(plot_string.lastIndexOf(","))+");";
MainFrame.octavePanel.evalWithOutput(cmd);
MainFrame.octavePanel.evalWithOutput(this.getMore_cmd());
dispose();
}
}
}//GEN-LAST:event_OkButtonActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
PlotOptionsDialog dialog = new PlotOptionsDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton OkButton;
private javax.swing.JButton addDataButton;
private javax.swing.JButton cancelButton;
private javax.swing.JButton clearButton;
private javax.swing.JTable dataTable;
private javax.swing.JTextField dataTextField;
private javax.swing.JButton downButton;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JComboBox lineStyleComboBox;
private javax.swing.JButton removeDataButton;
private javax.swing.JButton upDataButton;
// End of variables declaration//GEN-END:variables
}