Package bs.bs2d.gui.views

Source Code of bs.bs2d.gui.views.LoadcaseViewControls

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bs.bs2d.gui.views;

import bs.bs2d.fea.BoundaryCondition;
import bs.bs2d.gui.MainGUI;
import bs.bs2d.gui.plot.MeshPlotter;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JDialog;

/**
*
* @author Djen
*/
public class LoadcaseViewControls extends javax.swing.JPanel {

    DefaultListModel<BoundaryCondition> bcListModel;
   
    BCCreationDialog bcCreate;
    BCFLEditDialog fdEdit;
    BCPLEditDialog plEdit;
   
    MeshPlotter plotter;
   
    /**
     * Creates new form LoadcaseViewControls
     */
    public LoadcaseViewControls() {
        initComponents();
        bcCreate = new BCCreationDialog(null, true);
        fdEdit = new BCFLEditDialog(null, true);
        plEdit = new BCPLEditDialog(null, true);
       
        bcListModel = new DefaultListModel<>();
        lstBC.setModel(bcListModel);
       
        if(MainGUI.DEBUG_LOADCASE){
            BoundaryCondition bc;
            bc = new BoundaryCondition("fixed",
                    BoundaryCondition.Type.FIXED, 0, 0);
            bcListModel.add(0, bc);
            bc = new BoundaryCondition("load",
                    BoundaryCondition.Type.POINT_LOAD, 0, -1);
            bcListModel.add(0, bc);
        }
    }
   
    public void init(MeshPlotter plotter){
        this.plotter = plotter;
    }

    /**
     * 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() {

        jScrollPane1 = new javax.swing.JScrollPane();
        lstBC = new javax.swing.JList();
        btnNew = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        btnRemove = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        txtNodes = new javax.swing.JTextField();
        btnAddNodes = new javax.swing.JButton();
        btnSelectNodes = new javax.swing.JButton();
        btnRemoveNodes = new javax.swing.JButton();

        setBorder(javax.swing.BorderFactory.createTitledBorder("Boundary Conditions"));
        setMinimumSize(new java.awt.Dimension(250, 380));
        setPreferredSize(new java.awt.Dimension(250, 380));

        lstBC.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lstBC.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstBCValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(lstBC);

        btnNew.setText("New...");
        btnNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewActionPerformed(evt);
            }
        });

        btnEdit.setText("Edit...");
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        btnRemove.setText("Remove");
        btnRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveActionPerformed(evt);
            }
        });

        jLabel1.setText("Nodes:");

        txtNodes.setEditable(false);
        txtNodes.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        txtNodes.setText("0");

        btnAddNodes.setText("Add Selected Nodes");
        btnAddNodes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddNodesActionPerformed(evt);
            }
        });

        btnSelectNodes.setText("Show Nodes");
        btnSelectNodes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSelectNodesActionPerformed(evt);
            }
        });

        btnRemoveNodes.setText("Remove Selected Nodes");
        btnRemoveNodes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveNodesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnNew)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnEdit)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnRemove)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 6, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtNodes, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnSelectNodes, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnAddNodes, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnRemoveNodes, javax.swing.GroupLayout.Alignment.TRAILING)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, 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(btnNew)
                    .addComponent(btnEdit)
                    .addComponent(btnRemove))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtNodes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAddNodes))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnRemoveNodes)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSelectNodes))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewActionPerformed
        int i = bcListModel.getSize();
        bcCreate.reset(i);
        showDialog(bcCreate);
       
        BoundaryCondition bc = bcCreate.bc;
        if(bc == null)
            return;
       
        bcListModel.add(i, bc);
        lstBC.setSelectedIndex(i);
       
        btnEditActionPerformed(evt);
       
        btnAddNodesActionPerformed(evt);
    }//GEN-LAST:event_btnNewActionPerformed

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
        BoundaryCondition bc = bcListModel.get(lstBC.getSelectedIndex());
        if(bc.type == BoundaryCondition.Type.FIXED){
            fdEdit.reset(bc);
            showDialog(fdEdit);
            if(fdEdit.ok){
                bc.x = fdEdit.x;
                bc.y = fdEdit.y;
            }
        } else if(bc.type == BoundaryCondition.Type.POINT_LOAD){
            plEdit.reset(bc);
            showDialog(plEdit);
            if(plEdit.ok){
                bc.x = plEdit.x;
                bc.y = plEdit.y;
            }
        }
        lstBC.repaint();
    }//GEN-LAST:event_btnEditActionPerformed

    private void btnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveActionPerformed
        bcListModel.remove(lstBC.getSelectedIndex());
    }//GEN-LAST:event_btnRemoveActionPerformed

    private void lstBCValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstBCValueChanged
        int index = lstBC.getSelectedIndex();
        String s = "";
        if(index >= 0){
            int count = bcListModel.get(index).getNodeCount();
             s += count;
        }
        txtNodes.setText(s);
    }//GEN-LAST:event_lstBCValueChanged

    private void btnAddNodesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddNodesActionPerformed
        if(plotter != null){
            int i = lstBC.getSelectedIndex();
            BoundaryCondition bc = bcListModel.get(i);
            bc.addNodes(plotter.getSelection());
            txtNodes.setText("" + bc.getNodeCount());
        }
    }//GEN-LAST:event_btnAddNodesActionPerformed

    private void btnRemoveNodesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveNodesActionPerformed
        if(plotter != null){
            int i = lstBC.getSelectedIndex();
            BoundaryCondition bc = bcListModel.get(i);
            bc.removeNodes(plotter.getSelection());
            txtNodes.setText("" + bc.getNodeCount());
        }
    }//GEN-LAST:event_btnRemoveNodesActionPerformed

    private void btnSelectNodesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectNodesActionPerformed
        if(plotter != null){
            int i = lstBC.getSelectedIndex();
            BoundaryCondition bc = bcListModel.get(i);
            plotter.setSelection(bc.getNodes());
        }
    }//GEN-LAST:event_btnSelectNodesActionPerformed

    /**
     * Shows a dialog and blocks until the dialog has been closed by the user.
     * @param dialog the dialog to show
     */
    private void showDialog(JDialog dialog){
        dialog.setVisible(true);
        while(dialog.isVisible()){
            try {
                Thread.sleep(10);
            } catch (Exception e) { }
        }
    }
   
    public List<BoundaryCondition> getBoundaryConditions(){
        ArrayList<BoundaryCondition> bcs = new ArrayList<>(bcListModel.size());
        for (int i = 0; i < bcListModel.size(); i++) {
            bcs.add(bcListModel.get(i));
        }
        return bcs;
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddNodes;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnNew;
    private javax.swing.JButton btnRemove;
    private javax.swing.JButton btnRemoveNodes;
    private javax.swing.JButton btnSelectNodes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList lstBC;
    private javax.swing.JTextField txtNodes;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of bs.bs2d.gui.views.LoadcaseViewControls

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.