public static void main(String[] args) { // PHYSICS SIMULATION TestbedModel model = new TestbedModel(); model.addCategory("My Tests"); // add a category InteractiveBipedSimulator simulator = new InteractiveBipedSimulator(); model.addTest(simulator); TestbedPanel panel = new TestPanelJ2D(model); JFrame testbed = new TestbedFrame(model, panel); testbed.setVisible(true); testbed.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
public TestbedSidePanel(TestbedModel argModel, TestbedController argController) { model = argModel; controller = argController; initComponents(); addListeners(); model.addTestChangeListener( new TestbedModel.TestChangedListener() { @Override public void testChanged(TestbedTest argTest, int argIndex) { tests.setSelectedIndex(argIndex); saveButton.setEnabled(argTest.isSaveLoadEnabled()); loadButton.setEnabled(argTest.isSaveLoadEnabled()); } }); }
public void stateChanged(ChangeEvent e) { JComponent component = (JComponent) e.getSource(); TestbedSetting setting = (TestbedSetting) component.getClientProperty(SETTING_TAG); switch (setting.constraintType) { case BOOLEAN: JCheckBox box = (JCheckBox) e.getSource(); setting.enabled = box.isSelected(); break; case RANGE: JSlider slider = (JSlider) e.getSource(); setting.value = slider.getValue(); JLabel label = (JLabel) slider.getClientProperty(LABEL_TAG); label.setText(setting.name + ": " + setting.value); break; } model.getPanel().grabFocus(); }
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"); }