Search in sources :

Example 6 with BindingGroup

use of org.jdesktop.beansbinding.BindingGroup in project JMRI by JMRI.

the class WebServerPreferencesPanel method initComponents.

private void initComponents() {
    bindingGroup = new BindingGroup();
    port = new JSpinner();
    portLabel = new JLabel();
    readonlyPower = new JCheckBox();
    startup = new JCheckBox();
    port.setModel(new SpinnerNumberModel(12080, 1, 65535, 1));
    port.setEditor(new JSpinner.NumberEditor(port, "#"));
    // NOI18N
    port.setToolTipText(Bundle.getMessage("ToolTipPort"));
    Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${port}"), port, BeanProperty.create("value"));
    bindingGroup.addBinding(binding);
    // NOI18N
    portLabel.setText(Bundle.getMessage("LabelPort"));
    // NOI18N
    portLabel.setToolTipText(Bundle.getMessage("ToolTipPort"));
    // NOI18N
    readonlyPower.setText(Bundle.getMessage("LabelReadonlyPower"));
    readonlyPower.addActionListener((ActionEvent e) -> {
        readonlyPower.setToolTipText(Bundle.getMessage(readonlyPower.isSelected() ? "ToolTipReadonlyPowerTrue" : "ToolTipReadonlyPowerFalse"));
    });
    binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${readonlyPower}"), readonlyPower, BeanProperty.create("selected"));
    bindingGroup.addBinding(binding);
    startup.setSelected(this.isStartupAction());
    // NOI18N
    startup.setText(Bundle.getMessage("LabelStartup"));
    this.startupItemListener = (ItemEvent e) -> {
        this.startup.removeItemListener(this.startupItemListener);
        StartupActionsManager manager = InstanceManager.getDefault(StartupActionsManager.class);
        if (this.startup.isSelected()) {
            PerformActionModel model = new PerformActionModel();
            model.setClassName(WebServerAction.class.getName());
            if (this.startupActionPosition == -1 || this.startupActionPosition >= manager.getActions().length) {
                manager.addAction(model);
            } else {
                manager.setActions(this.startupActionPosition, model);
            }
        } else {
            manager.getActions(PerformActionModel.class).stream().filter((model) -> (WebServerAction.class.getName().equals(model.getClassName()))).forEach((model) -> {
                this.startupActionPosition = Arrays.asList(manager.getActions()).indexOf(model);
                manager.removeAction(model);
            });
        }
        this.startup.addItemListener(this.startupItemListener);
    };
    this.startup.addItemListener(this.startupItemListener);
    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(port, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(portLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addComponent(startup, GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE).addComponent(readonlyPower, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(port, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(portLabel)).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(readonlyPower).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(startup).addContainerGap(198, Short.MAX_VALUE)));
    bindingGroup.bind();
}
Also used : AutoBinding(org.jdesktop.beansbinding.AutoBinding) Binding(org.jdesktop.beansbinding.Binding) PerformActionModel(apps.PerformActionModel) JComponent(javax.swing.JComponent) ItemEvent(java.awt.event.ItemEvent) InstanceManager(jmri.InstanceManager) BeanProperty(org.jdesktop.beansbinding.BeanProperty) Arrays(java.util.Arrays) JSpinner(javax.swing.JSpinner) SpinnerNumberModel(javax.swing.SpinnerNumberModel) Bindings(org.jdesktop.beansbinding.Bindings) ItemListener(java.awt.event.ItemListener) StartupActionsManager(apps.StartupActionsManager) ActionEvent(java.awt.event.ActionEvent) AutoBinding(org.jdesktop.beansbinding.AutoBinding) LayoutStyle(javax.swing.LayoutStyle) PerformActionModel(apps.PerformActionModel) BindingGroup(org.jdesktop.beansbinding.BindingGroup) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) JCheckBox(javax.swing.JCheckBox) ELProperty(org.jdesktop.beansbinding.ELProperty) Binding(org.jdesktop.beansbinding.Binding) JPanel(javax.swing.JPanel) PreferencesPanel(jmri.swing.PreferencesPanel) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) StartupActionsManager(apps.StartupActionsManager) JCheckBox(javax.swing.JCheckBox) SpinnerNumberModel(javax.swing.SpinnerNumberModel) BindingGroup(org.jdesktop.beansbinding.BindingGroup) GroupLayout(javax.swing.GroupLayout) JSpinner(javax.swing.JSpinner)

Example 7 with BindingGroup

use of org.jdesktop.beansbinding.BindingGroup in project MtgDesktopCompanion by nicho92.

the class LightDescribeCardPanel method initDataBindings.

protected BindingGroup initDataBindings() {
    BeanProperty<MagicCard, String> nameProperty = BeanProperty.create("name");
    BeanProperty<JTextField, String> textProperty = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ, card, nameProperty, txtName, textProperty);
    autoBinding.bind();
    BeanProperty<MagicCard, String> costProperty = BeanProperty.create("cost");
    BeanProperty<ManaPanel, String> textProperty1 = BeanProperty.create("manaCost");
    AutoBinding<MagicCard, String, ManaPanel, String> autoBinding1 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, card, costProperty, manaPanel, textProperty1);
    autoBinding1.bind();
    BeanProperty<MagicCard, String> fullTypeProperty = BeanProperty.create("fullType");
    BeanProperty<JTextField, String> textProperty2 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding2 = Bindings.createAutoBinding(UpdateStrategy.READ, card, fullTypeProperty, txtType, textProperty2);
    autoBinding2.bind();
    BeanProperty<MagicCard, Integer> loyaltyProperty = BeanProperty.create("loyalty");
    BeanProperty<JTextField, String> textProperty4 = BeanProperty.create("text");
    AutoBinding<MagicCard, Integer, JTextField, String> autoBinding4 = Bindings.createAutoBinding(UpdateStrategy.READ, card, loyaltyProperty, txtLoyalty, textProperty4);
    autoBinding4.bind();
    BeanProperty<MagicCard, String> textProperty8 = BeanProperty.create("text");
    BeanProperty<MagicTextPane, String> textProperty9 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, MagicTextPane, String> autoBinding8 = Bindings.createAutoBinding(UpdateStrategy.READ, card, textProperty8, magicTextPane, textProperty9);
    autoBinding8.bind();
    BeanProperty<MagicCard, String> pProperty = BeanProperty.create("power");
    BeanProperty<JTextField, String> textPropertyP = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBindingP = Bindings.createAutoBinding(UpdateStrategy.READ, card, pProperty, txtPower, textPropertyP);
    autoBindingP.bind();
    BeanProperty<MagicCard, String> tProperty = BeanProperty.create("toughness");
    BeanProperty<JTextField, String> textPropertyT = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBindingT = Bindings.createAutoBinding(UpdateStrategy.READ, card, tProperty, txtT, textPropertyT);
    autoBindingT.bind();
    StringBuilder rules = new StringBuilder();
    for (MagicRuling rul : card.getRulings()) rules.append("-").append(rul.getText()).append("\n");
    rulesTextPane.setText(rules.toString());
    // 
    BindingGroup bindingGroup = new BindingGroup();
    // 
    bindingGroup.addBinding(autoBinding);
    bindingGroup.addBinding(autoBinding1);
    bindingGroup.addBinding(autoBinding2);
    bindingGroup.addBinding(autoBinding4);
    bindingGroup.addBinding(autoBinding8);
    bindingGroup.addBinding(autoBindingT);
    bindingGroup.addBinding(autoBindingP);
    magicTextPane.updateTextWithIcons();
    return bindingGroup;
}
Also used : JTextField(javax.swing.JTextField) ManaPanel(org.magic.gui.components.ManaPanel) MagicCard(org.magic.api.beans.MagicCard) BindingGroup(org.jdesktop.beansbinding.BindingGroup) MagicTextPane(org.magic.gui.components.MagicTextPane) MagicRuling(org.magic.api.beans.MagicRuling)

Example 8 with BindingGroup

use of org.jdesktop.beansbinding.BindingGroup in project MtgDesktopCompanion by nicho92.

the class DeckDetailsPanel method initDataBindings.

protected BindingGroup initDataBindings() {
    BeanProperty<MagicDeck, String> nameProperty = BeanProperty.create("name");
    BeanProperty<JTextField, String> textProperty1 = BeanProperty.create("text");
    AutoBinding<MagicDeck, String, JTextField, String> autoBinding1 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicDeck, nameProperty, nameJTextField, textProperty1);
    autoBinding1.bind();
    // 
    BeanProperty<MagicDeck, Integer> nbCardsProperty = BeanProperty.create("nbCards");
    BeanProperty<JProgressBar, Integer> textProperty4 = BeanProperty.create("value");
    AutoBinding<MagicDeck, Integer, JProgressBar, Integer> autoBinding2 = Bindings.createAutoBinding(UpdateStrategy.READ, magicDeck, nbCardsProperty, nbCardsProgress, textProperty4);
    autoBinding2.bind();
    nbCardsProgress.setString("" + magicDeck.getNbCards());
    nbSideProgress.setValue(magicDeck.getSideAsList().size());
    setLegalities();
    // 
    BeanProperty<MagicDeck, String> descriptionProperty = BeanProperty.create("description");
    BeanProperty<JTextArea, String> textProperty2 = BeanProperty.create("text");
    AutoBinding<MagicDeck, String, JTextArea, String> autoBinding3 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, magicDeck, descriptionProperty, textArea, textProperty2);
    autoBinding3.bind();
    // 
    BeanProperty<MagicDeck, String> colorIdentityProperty = BeanProperty.create("colors");
    BeanProperty<ManaPanel, String> manaCostProperty3 = BeanProperty.create("manaCost");
    AutoBinding<MagicDeck, String, ManaPanel, String> autoBinding4 = Bindings.createAutoBinding(UpdateStrategy.READ, magicDeck, colorIdentityProperty, manaPanel, manaCostProperty3);
    autoBinding4.bind();
    // 
    BindingGroup bindingGroup = new BindingGroup();
    bindingGroup.addBinding(autoBinding1);
    bindingGroup.addBinding(autoBinding2);
    bindingGroup.addBinding(autoBinding3);
    bindingGroup.addBinding(autoBinding4);
    if (magicDeck != null && magicDeck.getDateCreation() != null) {
        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, MTGControler.getInstance().getLocale());
        lblDateInformation.setText(df.format(magicDeck.getDateCreation()));
    }
    tagsPanel.clean();
    if (magicDeck != null)
        tagsPanel.bind(magicDeck.getTags());
    return bindingGroup;
}
Also used : JTextArea(javax.swing.JTextArea) JProgressBar(javax.swing.JProgressBar) JTextField(javax.swing.JTextField) BindingGroup(org.jdesktop.beansbinding.BindingGroup) DateFormat(java.text.DateFormat) MagicDeck(org.magic.api.beans.MagicDeck)

Aggregations

BindingGroup (org.jdesktop.beansbinding.BindingGroup)8 JCheckBox (javax.swing.JCheckBox)6 JTextField (javax.swing.JTextField)6 GroupLayout (javax.swing.GroupLayout)3 JLabel (javax.swing.JLabel)3 JPanel (javax.swing.JPanel)3 JSpinner (javax.swing.JSpinner)3 SpinnerNumberModel (javax.swing.SpinnerNumberModel)3 AutoBinding (org.jdesktop.beansbinding.AutoBinding)3 Binding (org.jdesktop.beansbinding.Binding)3 MagicCard (org.magic.api.beans.MagicCard)3 PerformActionModel (apps.PerformActionModel)2 StartupActionsManager (apps.StartupActionsManager)2 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 Arrays (java.util.Arrays)2 JComponent (javax.swing.JComponent)2 LayoutStyle (javax.swing.LayoutStyle)2 InstanceManager (jmri.InstanceManager)2 PreferencesPanel (jmri.swing.PreferencesPanel)2