update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / radComponents / ButtonGroupPropertiesPanel.java
blobd148e56d551c92e31cd26bcd0710319f25a3853f
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.uiDesigner.radComponents;
19 import com.intellij.uiDesigner.propertyInspector.properties.BindingProperty;
20 import com.intellij.util.containers.ContainerUtil;
22 import javax.swing.*;
23 import javax.swing.event.ChangeEvent;
24 import javax.swing.event.ChangeListener;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.FocusAdapter;
28 import java.awt.event.FocusEvent;
29 import java.util.concurrent.CopyOnWriteArrayList;
31 /**
32 * @author yole
34 public class ButtonGroupPropertiesPanel implements CustomPropertiesPanel {
35 private JTextField myNameTextField;
36 private JCheckBox myBindToFieldCheckBox;
37 private JPanel myPanel;
38 private final RadRootContainer myRootContainer;
39 private final RadButtonGroup myGroup;
40 private final CopyOnWriteArrayList<ChangeListener> myListeners = ContainerUtil.createEmptyCOWList();
42 public ButtonGroupPropertiesPanel(final RadRootContainer rootContainer, final RadButtonGroup group) {
43 myRootContainer = rootContainer;
44 myGroup = group;
45 myNameTextField.setText(group.getName());
46 myBindToFieldCheckBox.setSelected(group.isBound());
47 myBindToFieldCheckBox.addChangeListener(new ChangeListener() {
48 public void stateChanged(ChangeEvent e) {
49 saveButtonGroupIsBound();
51 });
52 myNameTextField.addFocusListener(new FocusAdapter() {
53 public void focusLost(FocusEvent e) {
54 saveButtonGroupName();
56 });
57 myNameTextField.addActionListener(new ActionListener() {
58 public void actionPerformed(ActionEvent e) {
59 saveButtonGroupName();
61 });
64 private void saveButtonGroupIsBound() {
65 if (myGroup.isBound() != myBindToFieldCheckBox.isSelected()) {
66 myGroup.setBound(myBindToFieldCheckBox.isSelected());
67 notifyListeners(new ChangeEvent(myGroup));
68 if (myGroup.isBound()) {
69 BindingProperty.updateBoundFieldName(myRootContainer, null, myGroup.getName(), ButtonGroup.class.getName());
74 private void saveButtonGroupName() {
75 String oldName = myGroup.getName();
76 String newName = myNameTextField.getText();
77 if (!oldName.equals(newName)) {
78 myGroup.setName(newName);
79 notifyListeners(new ChangeEvent(myGroup));
80 if (myGroup.isBound()) {
81 BindingProperty.updateBoundFieldName(myRootContainer, oldName, newName, ButtonGroup.class.getName());
86 public JComponent getComponent() {
87 return myPanel;
90 public void addChangeListener(ChangeListener listener) {
91 myListeners.add(listener);
94 public void removeChangeListener(ChangeListener listener) {
95 myListeners.remove(listener);
98 private void notifyListeners(final ChangeEvent event) {
99 for (ChangeListener changeListener : myListeners) {
100 changeListener.stateChanged(event);