update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / propertyInspector / properties / LayoutManagerProperty.java
blobd1824b9b3f23f6f7e37feb69af76d76e56df7278
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.
16 package com.intellij.uiDesigner.propertyInspector.properties;
18 import com.intellij.uiDesigner.propertyInspector.Property;
19 import com.intellij.uiDesigner.propertyInspector.PropertyEditor;
20 import com.intellij.uiDesigner.propertyInspector.PropertyRenderer;
21 import com.intellij.uiDesigner.propertyInspector.InplaceContext;
22 import com.intellij.uiDesigner.propertyInspector.editors.ComboBoxPropertyEditor;
23 import com.intellij.uiDesigner.propertyInspector.renderers.LabelPropertyRenderer;
24 import com.intellij.uiDesigner.radComponents.RadComponent;
25 import com.intellij.uiDesigner.radComponents.RadContainer;
26 import com.intellij.uiDesigner.radComponents.RadLayoutManager;
27 import com.intellij.uiDesigner.radComponents.LayoutManagerRegistry;
28 import com.intellij.uiDesigner.UIFormXmlConstants;
29 import com.intellij.openapi.util.Comparing;
30 import com.intellij.ui.ColoredListCellRenderer;
31 import com.intellij.ui.SimpleTextAttributes;
32 import org.jetbrains.annotations.NotNull;
34 import javax.swing.*;
36 /**
37 * @author yole
39 public class LayoutManagerProperty extends Property<RadContainer, String> {
40 private final PropertyRenderer<String> myRenderer = new LabelPropertyRenderer<String>() {
41 @Override protected void customize(final String value) {
42 setText(LayoutManagerRegistry.getLayoutManagerDisplayName(value));
46 private static class LayoutManagerEditor extends ComboBoxPropertyEditor<String> {
47 public LayoutManagerEditor() {
48 myCbx.setRenderer(new ColoredListCellRenderer() {
49 protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
50 append(LayoutManagerRegistry.getLayoutManagerDisplayName((String) value), SimpleTextAttributes.REGULAR_ATTRIBUTES);
52 });
55 public JComponent getComponent(RadComponent component, String value, InplaceContext inplaceContext) {
56 if (UIFormXmlConstants.LAYOUT_XY.equals(value)) {
57 myCbx.setModel(new DefaultComboBoxModel(LayoutManagerRegistry.getLayoutManagerNames()));
59 else {
60 myCbx.setModel(new DefaultComboBoxModel(LayoutManagerRegistry.getNonDeprecatedLayoutManagerNames()));
62 myCbx.setSelectedItem(value);
63 return myCbx;
67 private final PropertyEditor<String> myEditor = new LayoutManagerEditor();
69 public LayoutManagerProperty() {
70 super(null, "Layout Manager");
73 public String getValue(RadContainer component) {
74 RadContainer container = component;
75 while(container != null) {
76 final RadLayoutManager layoutManager = container.getLayoutManager();
77 if (layoutManager != null) {
78 return layoutManager.getName();
80 container = container.getParent();
82 return UIFormXmlConstants.LAYOUT_INTELLIJ;
85 protected void setValueImpl(RadContainer component, String value) throws Exception {
86 final RadLayoutManager oldLayout = component.getLayoutManager();
87 if (oldLayout != null && Comparing.equal(oldLayout.getName(), value)) {
88 return;
91 RadLayoutManager newLayoutManager = LayoutManagerRegistry.createLayoutManager(value);
92 newLayoutManager.changeContainerLayout(component);
95 @NotNull public PropertyRenderer<String> getRenderer() {
96 return myRenderer;
99 public PropertyEditor<String> getEditor() {
100 return myEditor;
103 @Override
104 public boolean needRefreshPropertyList() {
105 return true;