Mercurial > hg > ltpda
view src/MPipeline2/src/mpipeline/ltpdapreferences/DisplayPrefGroupPanel.java @ 44:409a22968d5e default
Add unit tests
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 18:42:11 +0100 |
parents | f0afece42f48 |
children |
line wrap: on
line source
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * DisplayPrefGroupPanel.java * * Created on Aug 14, 2010, 12:30:02 PM */ package mpipeline.ltpdapreferences; import java.awt.event.ActionEvent; import java.util.Observable; import java.util.Observer; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.event.ActionListener; /** * * @author hewitson */ public class DisplayPrefGroupPanel extends javax.swing.JPanel implements Observer, ChangeListener, ActionListener { private DisplayPrefGroup displayPrefs; /** Creates new form DisplayPrefGroupPanel */ public DisplayPrefGroupPanel(DisplayPrefGroup prefs) { this.displayPrefs = prefs; initComponents(); setPreferences(); displayPrefs.addObserver(this); verboseLevelCombo.addActionListener(this); wrapStringsSpinner.addChangeListener(this); wrapLegendStringsSpinner.addChangeListener(this); } /** 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() { jLabel1 = new javax.swing.JLabel(); verboseLevelCombo = new javax.swing.JComboBox(); jLabel2 = new javax.swing.JLabel(); wrapStringsSpinner = new javax.swing.JSpinner(); wrapLegendStringsSpinner = new javax.swing.JSpinner(); jLabel3 = new javax.swing.JLabel(); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel1.setText("Verbose Level:"); verboseLevelCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "OFF", "IMPORTANT", "MNAME", "PROC1", "PROC2", "PROC3", "PROC4", "PROC5", "OMNAME", "OPROC1", "OPROC2", "OPROC3", "OPROC4", "OPROC5" })); jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel2.setText("Wrap Strings:"); wrapStringsSpinner.setModel(new javax.swing.SpinnerNumberModel(5, 5, 500, 1)); wrapLegendStringsSpinner.setModel(new javax.swing.SpinnerNumberModel(5, 5, 500, 1)); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel3.setText("Wrap Legend Strings:"); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel1) .add(jLabel2) .add(jLabel3)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(org.jdesktop.layout.GroupLayout.TRAILING, verboseLevelCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 156, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(org.jdesktop.layout.GroupLayout.TRAILING, wrapStringsSpinner, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.TRAILING, wrapLegendStringsSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 156, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); layout.linkSize(new java.awt.Component[] {jLabel1, jLabel2, jLabel3}, org.jdesktop.layout.GroupLayout.HORIZONTAL); layout.linkSize(new java.awt.Component[] {verboseLevelCombo, wrapLegendStringsSpinner, wrapStringsSpinner}, org.jdesktop.layout.GroupLayout.HORIZONTAL); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel1) .add(verboseLevelCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER) .add(jLabel2) .add(wrapStringsSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER) .add(jLabel3) .add(wrapLegendStringsSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JComboBox verboseLevelCombo; private javax.swing.JSpinner wrapLegendStringsSpinner; private javax.swing.JSpinner wrapStringsSpinner; // End of variables declaration//GEN-END:variables public void setPreferences() { updateVerboseLevel(); updateWrapLegendStrings(); updateWrapStrings(); } public void update(Observable o, Object arg) { if (arg != null) { if (arg instanceof Integer) { int identifier = ((Integer) arg).intValue(); if (identifier == DisplayPrefGroup.DISPLAY_VERBOSE_LEVEL_CHANGED) { updateVerboseLevel(); } else if (identifier == DisplayPrefGroup.DISPLAY_WRAP_STRINGS_CHANGED) { updateWrapStrings(); } else if (identifier == DisplayPrefGroup.DISPLAY_WRAP_LEGEND_STRINGS_CHANGED) { updateWrapLegendStrings(); } else { System.err.println("Unknown observation argument: " + arg.toString()); } } } } private void updateVerboseLevel() { verboseLevelCombo.setSelectedIndex(this.displayPrefs.getDisplayVerboseLevel()+1); } private void updateWrapStrings() { wrapStringsSpinner.setValue(this.displayPrefs.getDisplayWrapStrings()); } private void updateWrapLegendStrings() { wrapLegendStringsSpinner.setValue(this.displayPrefs.getDisplayWrapLegendStrings()); } public void actionPerformed(ActionEvent e) { if (e.getSource() == verboseLevelCombo) { displayPrefs.setDisplayVerboseLevel(verboseLevelCombo.getSelectedIndex()-1); } } public void stateChanged(ChangeEvent e) { if (e.getSource() == wrapStringsSpinner) { displayPrefs.setDisplayWrapStrings((Integer) wrapStringsSpinner.getValue()); } else if (e.getSource() == wrapLegendStringsSpinner) { displayPrefs.setDisplayWrapLegendStrings((Integer) wrapLegendStringsSpinner.getValue()); } } }