Search in sources :

Example 1 with ListItem

use of nars.rover.physics.TestbedState.ListItem in project narchy by automenta.

the class TestbedSidePanel method initComponents.

public void initComponents() {
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    TestbedSettings settings = model.getSettings();
    JPanel top = new JPanel();
    top.setLayout(new GridLayout(0, 1));
    top.setBorder(BorderFactory.createCompoundBorder(new EtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    tests = new JComboBox(model.getComboModel());
    tests.setMaximumRowCount(30);
    tests.setMaximumSize(new Dimension(250, 20));
    tests.addActionListener(this);
    tests.setRenderer(new ListCellRenderer() {

        JLabel categoryLabel = null;

        JLabel testLabel = null;

        @Override
        public Component getListCellRendererComponent(JList list, Object ovalue, int index, boolean isSelected, boolean cellHasFocus) {
            ListItem value = (ListItem) ovalue;
            if (value.isCategory()) {
                if (categoryLabel == null) {
                    categoryLabel = new JLabel();
                    categoryLabel.setOpaque(true);
                    categoryLabel.setBackground(new Color(.5f, .5f, .6f));
                    categoryLabel.setForeground(Color.white);
                    categoryLabel.setHorizontalAlignment(SwingConstants.CENTER);
                    categoryLabel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
                }
                categoryLabel.setText(value.category);
                return categoryLabel;
            } else {
                if (testLabel == null) {
                    testLabel = new JLabel();
                    testLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 1, 0));
                }
                testLabel.setText(value.test.getTestName());
                if (isSelected) {
                    testLabel.setBackground(list.getSelectionBackground());
                    testLabel.setForeground(list.getSelectionForeground());
                } else {
                    testLabel.setBackground(list.getBackground());
                    testLabel.setForeground(list.getForeground());
                }
                return testLabel;
            }
        }
    });
    top.add(new JLabel("Choose a test:"));
    top.add(tests);
    addSettings(top, settings, SettingType.DRAWING);
    add(top, "North");
    JPanel middle = new JPanel();
    middle.setLayout(new GridLayout(0, 1));
    middle.setBorder(BorderFactory.createCompoundBorder(new EtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(5, 10, 5, 10)));
    addSettings(middle, settings, SettingType.ENGINE);
    add(middle, "Center");
    pauseButton.setAlignmentX(CENTER_ALIGNMENT);
    stepButton.setAlignmentX(CENTER_ALIGNMENT);
    resetButton.setAlignmentX(CENTER_ALIGNMENT);
    saveButton.setAlignmentX(CENTER_ALIGNMENT);
    loadButton.setAlignmentX(CENTER_ALIGNMENT);
    quitButton.setAlignmentX(CENTER_ALIGNMENT);
    Box buttonGroups = Box.createHorizontalBox();
    JPanel buttons1 = new JPanel();
    buttons1.setLayout(new GridLayout(0, 1));
    buttons1.add(resetButton);
    JPanel buttons2 = new JPanel();
    buttons2.setLayout(new GridLayout(0, 1));
    buttons2.add(pauseButton);
    buttons2.add(stepButton);
    JPanel buttons3 = new JPanel();
    buttons3.setLayout(new GridLayout(0, 1));
    buttons3.add(saveButton);
    buttons3.add(loadButton);
    buttons3.add(quitButton);
    buttonGroups.add(buttons1);
    buttonGroups.add(buttons2);
    buttonGroups.add(buttons3);
    add(buttonGroups, "South");
}
Also used : TestbedSettings(nars.rover.physics.TestbedSettings) EtchedBorder(javax.swing.border.EtchedBorder) ListItem(nars.rover.physics.TestbedState.ListItem)

Aggregations

EtchedBorder (javax.swing.border.EtchedBorder)1 TestbedSettings (nars.rover.physics.TestbedSettings)1 ListItem (nars.rover.physics.TestbedState.ListItem)1