Search in sources :

Example 1 with ComboUIParameter

use of de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter in project micro-manager by micro-manager.

the class ConfigurablePanelTest method testGetComboUIParameterNullValue.

@Test(expected = NullPointerException.class)
public void testGetComboUIParameterNullValue() throws IncorrectUIParameterTypeException, UnknownUIParameterException {
    final int defval = 2;
    final String[] vals = { "SuperVal", "MediocreVal", "UnitTesting is tough", "SomeVal" };
    final String param = "Param";
    ConfigurableTestPanel cp = new ConfigurableTestPanel("MyPanel") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void initializeParameters() {
            this.addUIParameter(new ComboUIParameter(this, param, "", vals, defval));
        }
    };
    cp.getStringUIParameterValue(null);
}
Also used : ComboUIParameter(de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter) Test(org.junit.Test)

Example 2 with ComboUIParameter

use of de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter in project micro-manager by micro-manager.

the class ParametersTable method createTable.

private void createTable(DefaultTableModel model) {
    table = new JTable(model) {

        private static final long serialVersionUID = 1L;

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            switch(column) {
                case 0:
                    return new BoldTableCellRenderer();
                case 1:
                    String s = (String) table.getValueAt(row, 0);
                    if (uiparameterSet_.get(s).getType().equals(UIParameter.UIParameterType.COLOR)) {
                        // if Color parameter
                        return new IconTableCellRenderer();
                    } else if (uiparameterSet_.get(s).getType().equals(UIParameter.UIParameterType.BOOL)) {
                        // if checkbox
                        return super.getDefaultRenderer(Boolean.class);
                    } else {
                        return new DefaultTableCellRenderer();
                    }
                default:
                    return super.getCellRenderer(row, column);
            }
        }

        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            switch(column) {
                case 0:
                    return super.getCellEditor(row, column);
                case 1:
                    String s = (String) table.getValueAt(row, 0);
                    if (uiparameterSet_.get(s).getType().equals(UIParameter.UIParameterType.COLOR)) {
                        return new DefaultCellEditor(color);
                    } else if (uiparameterSet_.get(s) instanceof ComboUIParameter) {
                        return new DefaultCellEditor(new JComboBox<String>(((ComboUIParameter) uiparameterSet_.get(s)).getComboValues()));
                    } else if (uiparameterSet_.get(s).getType().equals(UIParameter.UIParameterType.BOOL)) {
                        return super.getDefaultEditor(Boolean.class);
                    } else if (uiparameterSet_.get(s).getType().equals(UIParameter.UIParameterType.UIPROPERTY)) {
                        return new DefaultCellEditor(new JComboBox<String>(getAvailableProperties((UIPropertyParameter) uiparameterSet_.get(s))));
                    } else {
                        return new DefaultCellEditor(new JTextField());
                    }
                default:
                    return super.getCellEditor(row, column);
            }
        }

        @Override
        public boolean isCellEditable(int row, int col) {
            // only second column is editable
            if (col < 1) {
                return false;
            } else {
                return true;
            }
        }
    };
    table.setAutoCreateRowSorter(false);
    table.setRowHeight(23);
    table.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            int row = table.rowAtPoint(evt.getPoint());
            updateHelper(row);
        }
    });
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) IconTableCellRenderer(de.embl.rieslab.emu.configuration.ui.utils.IconTableCellRenderer) JTextField(javax.swing.JTextField) IconTableCellRenderer(de.embl.rieslab.emu.configuration.ui.utils.IconTableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) DefaultCellEditor(javax.swing.DefaultCellEditor) JTable(javax.swing.JTable) ComboUIParameter(de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter) TableCellEditor(javax.swing.table.TableCellEditor)

Example 3 with ComboUIParameter

use of de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter in project micro-manager by micro-manager.

the class ConfigurablePanelTest method testGetComboUIParameterWrongValue.

@Test(expected = UnknownUIParameterException.class)
public void testGetComboUIParameterWrongValue() throws IncorrectUIParameterTypeException, UnknownUIParameterException {
    final int defval = 2;
    final String[] vals = { "SuperVal", "MediocreVal", "UnitTesting is tough", "SomeVal" };
    final String param = "Param";
    ConfigurableTestPanel cp = new ConfigurableTestPanel("MyPanel") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void initializeParameters() {
            this.addUIParameter(new ComboUIParameter(this, param, "", vals, defval));
        }
    };
    cp.getStringUIParameterValue("Rosebud");
}
Also used : ComboUIParameter(de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter) Test(org.junit.Test)

Example 4 with ComboUIParameter

use of de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter in project micro-manager by micro-manager.

the class ConfigurablePanelTest method testGetStringUIParameterWithAllTypes.

public void testGetStringUIParameterWithAllTypes() throws UnknownUIParameterException {
    final String parambool = "Param";
    final String paramcombo = "Param";
    final String paramuiprop = "Param";
    final String paramstring = "Param";
    final String paramcolor = "Param";
    final String paramdouble = "Param";
    final String paramint = "Param";
    final boolean defbool = false;
    final String defstring = "Papouasie";
    final String defstring2 = "New Guinea";
    final double defdouble = 42.5;
    final int defval = 2;
    final String[] vals = { "SuperVal", "MediocreVal", "UnitTesting is tough", "SomeVal" };
    ConfigurableTestPanel cp = new ConfigurableTestPanel("MyPanel") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void initializeParameters() {
            this.addUIParameter(new ComboUIParameter(this, paramcombo, "", vals, defval));
            this.addUIParameter(new BoolUIParameter(this, parambool, "", defbool));
            UIPropertyParameter p = new UIPropertyParameter(this, paramuiprop, "", new NoFlag());
            this.addUIParameter(p);
            p.setStringValue(defstring2);
            this.addUIParameter(new StringUIParameter(this, paramstring, "", defstring));
            this.addUIParameter(new ColorUIParameter(this, paramcolor, "", Color.BLACK));
            this.addUIParameter(new DoubleUIParameter(this, paramdouble, "", defdouble));
            this.addUIParameter(new IntegerUIParameter(this, paramint, "", defval));
        }
    };
    assertEquals(String.valueOf(defbool), cp.getStringUIParameterValue(parambool));
    assertEquals(vals[defval], cp.getStringUIParameterValue(paramcombo));
    assertEquals(defstring2, cp.getStringUIParameterValue(paramuiprop));
    assertEquals(defstring, cp.getStringUIParameterValue(paramstring));
    assertEquals("black", cp.getStringUIParameterValue(paramcolor));
    assertEquals(String.valueOf(defdouble), cp.getStringUIParameterValue(paramdouble));
    assertEquals(String.valueOf(defval), cp.getStringUIParameterValue(paramint));
}
Also used : BoolUIParameter(de.embl.rieslab.emu.ui.uiparameters.BoolUIParameter) ColorUIParameter(de.embl.rieslab.emu.ui.uiparameters.ColorUIParameter) IntegerUIParameter(de.embl.rieslab.emu.ui.uiparameters.IntegerUIParameter) StringUIParameter(de.embl.rieslab.emu.ui.uiparameters.StringUIParameter) UIPropertyParameter(de.embl.rieslab.emu.ui.uiparameters.UIPropertyParameter) ComboUIParameter(de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter) NoFlag(de.embl.rieslab.emu.ui.uiproperties.flag.NoFlag) DoubleUIParameter(de.embl.rieslab.emu.ui.uiparameters.DoubleUIParameter)

Example 5 with ComboUIParameter

use of de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter in project micro-manager by micro-manager.

the class ConfigurablePanelTest method testgetStringUIParameterValue.

// get ComboUIParameter value
@Test
public void testgetStringUIParameterValue() throws IncorrectUIParameterTypeException, UnknownUIParameterException {
    final int defval = 2;
    final String[] vals = { "SuperVal", "MediocreVal", "UnitTesting is tough", "SomeVal" };
    final String param = "Param";
    ConfigurableTestPanel cp = new ConfigurableTestPanel("MyPanel") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void initializeParameters() {
            this.addUIParameter(new ComboUIParameter(this, param, "", vals, defval));
        }
    };
    assertEquals(vals[defval], cp.getStringUIParameterValue(param));
    cp.getUIParameter(param).setStringValue(vals[0]);
    assertEquals(vals[0], String.valueOf(cp.getStringUIParameterValue(param)));
}
Also used : ComboUIParameter(de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter) Test(org.junit.Test)

Aggregations

ComboUIParameter (de.embl.rieslab.emu.ui.uiparameters.ComboUIParameter)5 Test (org.junit.Test)3 IconTableCellRenderer (de.embl.rieslab.emu.configuration.ui.utils.IconTableCellRenderer)1 BoolUIParameter (de.embl.rieslab.emu.ui.uiparameters.BoolUIParameter)1 ColorUIParameter (de.embl.rieslab.emu.ui.uiparameters.ColorUIParameter)1 DoubleUIParameter (de.embl.rieslab.emu.ui.uiparameters.DoubleUIParameter)1 IntegerUIParameter (de.embl.rieslab.emu.ui.uiparameters.IntegerUIParameter)1 StringUIParameter (de.embl.rieslab.emu.ui.uiparameters.StringUIParameter)1 UIPropertyParameter (de.embl.rieslab.emu.ui.uiparameters.UIPropertyParameter)1 NoFlag (de.embl.rieslab.emu.ui.uiproperties.flag.NoFlag)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 JTable (javax.swing.JTable)1 JTextField (javax.swing.JTextField)1 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)1 TableCellEditor (javax.swing.table.TableCellEditor)1 TableCellRenderer (javax.swing.table.TableCellRenderer)1