Package moppydesk.ui

Source Code of moppydesk.ui.PoolingControls

package moppydesk.ui;

import java.awt.Component;
import moppydesk.Constants;
import moppydesk.MoppyUI;
import moppydesk.midputs.DrivePooler;

/**
*
* @author Sam
*/
public class PoolingControls extends javax.swing.JPanel {

    private DrivePooler pooler;
    private MoppyUI app;

    /**
     * This constructor is only for use in the NetBeans editor window.  The constructor
     * below that takes a {@link MoppyUI} as an argument should always be used.
     */
    public PoolingControls() {
        initComponents();
    }

    public PoolingControls(MoppyUI app) {
        this.app = app;

        initComponents();
        pooler = new DrivePooler();

        loadSettings();
        updatePooler();
    }

    public boolean isPoolingEnabled() {
        return enablePoolingCB.isSelected();
    }

    public DrivePooler getDrivePooler() {
        return pooler;
    }

    public void connected() {
        saveSettings();
        for (Component c : this.getComponents()) {
            c.setEnabled(false);
        }
    }

    public void disconnected() {
        pooler.close();
        for (Component c : this.getComponents()) {
            c.setEnabled(true);
        }
    }

    private void loadSettings() {
        enablePoolingCB.setSelected(app.prefs.getBoolean(Constants.PREF_POOL_ENABLE, false));
        inputStartSpinner.setValue(app.prefs.getInt(Constants.PREF_POOL_FROM_START, 1));
        inputEndSpinner.setValue(app.prefs.getInt(Constants.PREF_POOL_FROM_END, 1));
        outputStartSpinner.setValue(app.prefs.getInt(Constants.PREF_POOL_TO_START, 1));
        outputEndSpinner.setValue(app.prefs.getInt(Constants.PREF_POOL_TO_END, 1));

        jComboBox1.setSelectedIndex(app.prefs.getInt(Constants.PREF_POOL_STRATEGY, 0));

        updatePooler();
    }

    private void saveSettings() {
        app.prefs.putBoolean(Constants.PREF_POOL_ENABLE, enablePoolingCB.isSelected());

        app.prefs.putInt(Constants.PREF_POOL_FROM_START, (Integer) inputStartSpinner.getValue());
        app.prefs.putInt(Constants.PREF_POOL_FROM_END, (Integer) inputEndSpinner.getValue());
        app.prefs.putInt(Constants.PREF_POOL_TO_START, (Integer) outputStartSpinner.getValue());
        app.prefs.putInt(Constants.PREF_POOL_TO_END, (Integer) outputEndSpinner.getValue());

        app.prefs.putInt(Constants.PREF_POOL_STRATEGY, jComboBox1.getSelectedIndex());
        app.savePreferences();
    }

    private void updatePooler() {
        pooler.setInputRange((Integer) inputStartSpinner.getValue(), (Integer) inputEndSpinner.getValue());
        pooler.setOutputRange((Integer) outputStartSpinner.getValue(), (Integer) outputEndSpinner.getValue());
        pooler.setStrategy(DrivePooler.PoolingStrategy.values()[jComboBox1.getSelectedIndex()]);
    }

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

        enablePoolingCB = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        inputStartSpinner = new javax.swing.JSpinner();
        inputEndSpinner = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        outputEndSpinner = new javax.swing.JSpinner();
        outputStartSpinner = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();

        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        setPreferredSize(new java.awt.Dimension(525, 149));

        enablePoolingCB.setText("Enable Drive-Pooling");

        jLabel1.setText("Pool channels:");

        inputStartSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 16, 1));
        inputStartSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                poolingControlChanged(evt);
            }
        });

        inputEndSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 16, 1));
        inputEndSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                poolingControlChanged(evt);
            }
        });

        jLabel2.setText("Into channels:");

        outputEndSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 16, 1));
        outputEndSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                poolingControlChanged(evt);
            }
        });

        outputStartSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 16, 1));
        outputStartSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                poolingControlChanged(evt);
            }
        });

        jLabel3.setText("Using strategy:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Straight-through", "Round-Robin", "Stacking (Start-biased)" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                strategyDropdownChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(enablePoolingCB)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(inputStartSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(inputEndSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(38, 38, 38)
                                .addComponent(jLabel3))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(outputStartSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(outputEndSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(105, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(enablePoolingCB)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(inputStartSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(inputEndSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(outputStartSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(outputEndSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(68, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void poolingControlChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_poolingControlChanged
        updatePooler();
    }//GEN-LAST:event_poolingControlChanged

    private void strategyDropdownChanged(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_strategyDropdownChanged
        updatePooler();
    }//GEN-LAST:event_strategyDropdownChanged
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox enablePoolingCB;
    private javax.swing.JSpinner inputEndSpinner;
    private javax.swing.JSpinner inputStartSpinner;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JSpinner outputEndSpinner;
    private javax.swing.JSpinner outputStartSpinner;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of moppydesk.ui.PoolingControls

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.