public void bind(WinrateView view, WinratePresentationModel model) { Bindings.bind( view.getPlayedLabel(), ConverterFactory.createStringConverter( model.getComponentModel(MatchRecord.PROPERTY_PLAYED), NumberFormat.getIntegerInstance())); Bindings.bind( view.getWonLabel(), ConverterFactory.createStringConverter( model.getComponentModel(MatchRecord.PROPERTY_WON), NumberFormat.getIntegerInstance())); Bindings.bind( view.getLostLabel(), ConverterFactory.createStringConverter( model.getComponentModel(MatchRecord.PROPERTY_LOST), NumberFormat.getIntegerInstance())); }
protected JComponent getControl(String property, Format format) { JComponent c = components.get(property); if (c == null) { JLabel label = createLabel(); try { ValueModel valueModel = ConverterFactory.createStringConverter(model.getModel(property), format); Bindings.bind(label, valueModel); } catch (Exception e) { String msg = ExceptionUtils.getRootCauseMessage(e); label.setToolTipText("Binding error Property: " + property + " " + msg); System.out.println("Binding error Property: " + property + " " + msg); } components.put(property, label); return label; } else return c; }
/** * Creates, binds and configures the UI components. * * <p>If possible, the components are created using the BasicComponentFactory, or the Bindings * class. */ private void initComponents() { // Text Components textField = BasicComponentFactory.createTextField( presentationModel.getModel(ExampleBean.PROPERTYNAME_TEXT)); textArea = BasicComponentFactory.createTextArea( presentationModel.getModel(ExampleBean.PROPERTYNAME_TEXT)); passwordField = BasicComponentFactory.createPasswordField( presentationModel.getModel(ExampleBean.PROPERTYNAME_TEXT)); textLabel = BasicComponentFactory.createLabel( presentationModel.getModel(ExampleBean.PROPERTYNAME_TEXT)); // Formatted Input dateField = BasicComponentFactory.createDateField( presentationModel.getModel(ExampleBean.PROPERTYNAME_DATE)); integerField = BasicComponentFactory.createIntegerField( presentationModel.getModel(ExampleBean.PROPERTYNAME_INT_VALUE)); longField = BasicComponentFactory.createLongField( presentationModel.getModel(ExampleBean.PROPERTYNAME_LONG_VALUE)); // Choice ValueModel intChoiceModel = presentationModel.getModel(ExampleBean.PROPERTYNAME_INT_CHOICE); leftIntRadio = BasicComponentFactory.createRadioButton(intChoiceModel, ExampleBean.LEFT_INTEGER, "Left"); centerIntRadio = BasicComponentFactory.createRadioButton( intChoiceModel, ExampleBean.CENTER_INTEGER, "Center"); rightIntRadio = BasicComponentFactory.createRadioButton(intChoiceModel, ExampleBean.RIGHT_INTEGER, "Right"); alignmentIntCombo = BasicComponentFactory.createComboBox( new SelectionInList(ExampleBean.INTEGER_CHOICES, intChoiceModel)); ValueModel objectChoiceModel = presentationModel.getModel(ExampleBean.PROPERTYNAME_OBJECT_CHOICE); leftObjectRadio = BasicComponentFactory.createRadioButton(objectChoiceModel, ExampleBean.LEFT, "Left"); centerObjectRadio = BasicComponentFactory.createRadioButton(objectChoiceModel, ExampleBean.CENTER, "Center"); rightObjectRadio = BasicComponentFactory.createRadioButton(objectChoiceModel, ExampleBean.RIGHT, "Right"); alignmentObjectCombo = BasicComponentFactory.createComboBox( new SelectionInList(ExampleBean.OBJECT_CHOICES, objectChoiceModel)); // Lists comboBox = BasicComponentFactory.createComboBox( presentationModel.getSelectionInList(), TutorialUtils.createAlbumListCellRenderer()); list = BasicComponentFactory.createList( presentationModel.getSelectionInList(), TutorialUtils.createAlbumListCellRenderer()); table = new JTable(); table.setModel(TutorialUtils.createAlbumTableModel(presentationModel.getSelectionInList())); table.setSelectionModel( new SingleListSelectionAdapter( presentationModel.getSelectionInList().getSelectionIndexHolder())); // Misc checkBox = BasicComponentFactory.createCheckBox( presentationModel.getModel(ExampleBean.PROPERTYNAME_BOOLEAN_VALUE), "available"); colorPreview = new JPanel(); colorPreview.setBorder(new LineBorder(Color.GRAY)); updatePreviewPanel(); ValueModel floatModel = presentationModel.getModel(ExampleBean.PROPERTYNAME_FLOAT_VALUE); slider = new JSlider(); slider.setModel( new BoundedRangeAdapter( ConverterFactory.createFloatToIntegerConverter(floatModel, 100), 0, 0, 100)); floatLabel = BasicComponentFactory.createLabel( ConverterFactory.createStringConverter(floatModel, NumberFormat.getPercentInstance())); spinner = new JSpinner(); spinner.setModel( SpinnerAdapterFactory.createNumberAdapter( presentationModel.getModel(ExampleBean.PROPERTYNAME_INT_LIMITED), 0, // defaultValue 0, // minValue 100, // maxValue 5)); // step }