Search in sources :

Example 1 with ListItem

use of nars.lab.narclear.jbox2d.TestbedState.ListItem in project opennars by opennars.

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 : JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) Color(java.awt.Color) JLabel(javax.swing.JLabel) TestbedSettings(nars.lab.narclear.jbox2d.TestbedSettings) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) GridLayout(java.awt.GridLayout) EtchedBorder(javax.swing.border.EtchedBorder) BorderLayout(java.awt.BorderLayout) ListCellRenderer(javax.swing.ListCellRenderer) ListItem(nars.lab.narclear.jbox2d.TestbedState.ListItem) JComponent(javax.swing.JComponent) Component(java.awt.Component) JList(javax.swing.JList)

Aggregations

BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 GridLayout (java.awt.GridLayout)1 Box (javax.swing.Box)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JComponent (javax.swing.JComponent)1 JLabel (javax.swing.JLabel)1 JList (javax.swing.JList)1 JPanel (javax.swing.JPanel)1 ListCellRenderer (javax.swing.ListCellRenderer)1 EtchedBorder (javax.swing.border.EtchedBorder)1 TestbedSettings (nars.lab.narclear.jbox2d.TestbedSettings)1 ListItem (nars.lab.narclear.jbox2d.TestbedState.ListItem)1