1 19 20 package org.netbeans.spi.palette; 21 22 import java.awt.datatransfer.DataFlavor ; 23 import java.beans.PropertyChangeListener ; 24 import java.beans.PropertyChangeSupport ; 25 import org.netbeans.modules.palette.Category; 26 import org.netbeans.modules.palette.Item; 27 import org.netbeans.modules.palette.Model; 28 import org.netbeans.modules.palette.ModelListener; 29 import org.netbeans.modules.palette.Settings; 30 import org.openide.util.Lookup; 31 32 50 51 public final class PaletteController { 52 53 59 public static final DataFlavor ITEM_DATA_FLAVOR; 60 static { 61 try { 62 ITEM_DATA_FLAVOR = new DataFlavor ("application/x-java-openide-paletteitem;class=org.openide.util.Lookup", "Paste Item", Lookup.class.getClassLoader()); 65 } catch (ClassNotFoundException e) { 66 throw new AssertionError (e); 67 } 68 } 69 70 78 86 public static final String ATTR_ITEM_WIDTH = "itemWidth"; 87 92 public static final String ATTR_SHOW_ITEM_NAMES = "showItemNames"; 93 99 public static final String ATTR_ICON_SIZE = "iconSize"; 100 104 public static final String ATTR_IS_EXPANDED = "isExpanded"; 105 110 public static final String ATTR_IS_VISIBLE = "isVisible"; 111 116 public static final String ATTR_IS_READONLY = "isReadonly"; 117 122 public static final String ATTR_HELP_ID = "helpId"; 123 124 128 public static final String PROP_SELECTED_ITEM = Model.PROP_SELECTED_ITEM; 129 130 133 private Model model; 134 137 private Settings settings; 138 139 private PropertyChangeSupport support ; 140 141 143 private PaletteController() { 144 } 145 146 147 PaletteController( Model model, Settings settings ) { 148 this.model = model; 149 this.settings = settings; 150 151 support = new PropertyChangeSupport ( this ); 152 this.model.addModelListener( new ModelListener() { 153 public void propertyChange(java.beans.PropertyChangeEvent evt) { 154 if( Model.PROP_SELECTED_ITEM.equals( evt.getPropertyName() ) ) { 155 Lookup oldValue = null == evt.getOldValue() ? Lookup.EMPTY : ((Item)evt.getOldValue()).getLookup(); 156 Lookup newValue = null == evt.getNewValue() ? Lookup.EMPTY : ((Item)evt.getNewValue()).getLookup(); 157 support.firePropertyChange( PROP_SELECTED_ITEM, oldValue, newValue ); 158 } 159 } 160 161 public void categoriesRemoved(Category[] removedCategories) { 162 } 164 165 public void categoriesAdded(Category[] addedCategories) { 166 } 168 169 public void categoriesReordered() { 170 } 172 }); 173 } 174 175 public void addPropertyChangeListener( PropertyChangeListener listener ) { 176 support.addPropertyChangeListener( listener ); 177 } 178 179 public void removePropertyChangeListener( PropertyChangeListener listener ) { 180 support.removePropertyChangeListener( listener ); 181 } 182 183 187 public Lookup getSelectedItem() { 188 Item selItem = model.getSelectedItem(); 189 return null == selItem ? Lookup.EMPTY : selItem.getLookup(); 190 } 191 192 198 public void setSelectedItem( Lookup category, Lookup item ) { 199 model.setSelectedItem( category, item ); 200 } 201 202 206 public Lookup getSelectedCategory() { 207 Category selCategory = model.getSelectedCategory(); 208 return null == selCategory ? Lookup.EMPTY : selCategory.getLookup(); 209 } 210 211 214 public void clearSelection() { 215 model.clearSelection(); 216 } 217 218 222 public void refresh() { 223 model.refresh(); 224 } 225 226 230 public void showCustomizer() { 231 model.showCustomizer( this, settings ); 232 } 233 234 237 public Lookup getRoot() { 238 return model.getRoot(); 239 } 240 241 Model getModel() { 242 return model; 243 } 244 245 248 void setModel( Model model ) { 249 this.model = model; 250 } 251 252 Settings getSettings() { 253 return settings; 254 } 255 } 256 | Popular Tags |