update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / propertyInspector / PropertyEditor.java
blob5b5f4ded27c2e1f2710b54525ecdd1b8b955d8d5
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;
18 import com.intellij.uiDesigner.radComponents.RadComponent;
19 import org.jetbrains.annotations.NotNull;
20 import org.jetbrains.annotations.Nullable;
22 import javax.swing.*;
23 import javax.swing.event.EventListenerList;
25 /**
26 * @author Anton Katilin
27 * @author Vladimir Kondratyev
29 public abstract class PropertyEditor<V> {
30 private final EventListenerList myListenerList;
32 protected PropertyEditor(){
33 myListenerList=new EventListenerList();
36 /**
37 * @return edited value. Note that <code>null</code> is the legal.
39 * @exception java.lang.Exception the method throws exception
40 * if user enters wrong value and it cannot be applied. Note, that
41 * exception's message will be shown to the user.
43 @Nullable
44 public abstract V getValue() throws Exception;
46 /**
47 * @param component this component can be used to prepare editor UI
48 * component
50 * @param value value to be edited. The editor should not
51 * directly edit the passed object. Instead of this it must edit some
52 * internal data and return the edited value by <code>getValue</code>
53 * method.
55 * @param inplaceContext this is hint for the editor. This parameter is not <code>null</code>
56 * in case if the editor is used for inplace editing. This hint is very useful.
57 * For example string editor doesn't have a border when it is used
58 * inside property inspector and has border when it is used for inspace editing.
60 * @return the component which is used to edit the property in UI.
61 * The method must always return not <code>null</code> component.
63 public abstract JComponent getComponent(
64 RadComponent component,
65 V value,
66 InplaceContext inplaceContext);
68 /**
69 * Property editor can return preferred focused component (if any) inside the component
70 * which is returned by the {@link #getComponent(com.intellij.uiDesigner.radComponents.RadComponent,V,InplaceContext) } method.
71 * This method is used as a hint to implement better focus handling.
72 * <code>null</code> values means that editor relies on the UI editor in
73 * determing preferred focused component.
75 * @param component cannot be null
77 public JComponent getPreferredFocusedComponent(@NotNull final JComponent component){
78 return null;
81 /**
82 * Editor should update UI of all its internal components to fit current
83 * IDEA Look And Feel. We cannot directly update UI of the component
84 * that is returned by {@link #getComponent(com.intellij.uiDesigner.radComponents.RadComponent,V,InplaceContext) } method
85 * because hidden components that are not in the Swing tree can exist.
87 public abstract void updateUI();
89 /**
90 * Adds specified listener
92 public final void addPropertyEditorListener(final PropertyEditorListener l){
93 myListenerList.add(PropertyEditorListener.class,l);
96 /**
97 * Removes specified listener
99 public final void removePropertyEditorListener(final PropertyEditorListener l){
100 myListenerList.remove(PropertyEditorListener.class,l);
103 protected final void fireEditingCancelled(){
104 final PropertyEditorListener[] listeners=myListenerList.getListeners(PropertyEditorListener.class);
105 for (PropertyEditorListener listener : listeners) {
106 listener.editingCanceled(this);
110 protected final void fireValueCommitted(final boolean continueEditing, final boolean closeEditorOnError) {
111 final PropertyEditorListener[] listeners=myListenerList.getListeners(PropertyEditorListener.class);
112 for (PropertyEditorListener listener : listeners) {
113 listener.valueCommitted(this, continueEditing, closeEditorOnError);
117 protected final void preferredSizeChanged(){
118 final PropertyEditorListener[] listeners=myListenerList.getListeners(PropertyEditorListener.class);
119 for (PropertyEditorListener listener : listeners) {
120 listener.preferredSizeChanged(this);