1 19 20 21 package org.netbeans.spi.palette; 22 23 import java.awt.BorderLayout ; 24 import java.awt.Dimension ; 25 import java.beans.PropertyChangeEvent ; 26 import java.beans.PropertyChangeListener ; 27 import org.netbeans.modules.palette.Utils; 28 import org.netbeans.modules.palette.ui.PalettePanel; 29 import org.openide.util.HelpCtx; 30 import org.openide.util.RequestProcessor; 31 import org.openide.util.Utilities; 32 import org.openide.windows.TopComponent; 33 34 35 36 37 43 44 final class PaletteTopComponent extends TopComponent implements PropertyChangeListener { 45 46 static final long serialVersionUID = 4248268998485315735L; 47 48 private static PaletteTopComponent instance; 49 50 private RequestProcessor.Task nodeSetterTask; 51 private final Object NODE_SETTER_LOCK = new Object (); 52 53 private TopComponent paletteSource; 54 55 56 private PaletteTopComponent() { 57 setName(Utils.getBundleString("CTL_Component_palette")); setToolTipText(Utils.getBundleString("HINT_PaletteComponent")); 59 setIcon(Utilities.loadImage("org/netbeans/modules/palette/resources/palette.png")); 61 setLayout(new BorderLayout ()); 62 setPreferredSize(new Dimension (505, 88)); 63 add( PalettePanel.getDefault().getScrollPane(), BorderLayout.CENTER ); 64 65 putClientProperty( "keepPreferredSizeWhenSlideIn", Boolean.TRUE ); } 67 68 public void requestActive() { 69 super.requestActive(); 70 PalettePanel.getDefault().requestFocusInWindow(); 71 } 72 73 75 public static synchronized PaletteTopComponent getDefault() { 76 if(instance == null) { 77 instance = new PaletteTopComponent(); 78 } 79 return instance; 80 } 81 82 84 public int getPersistenceType() { 85 return TopComponent.PERSISTENCE_ALWAYS; 86 } 87 88 public void componentOpened() { 89 PaletteSwitch switcher = PaletteSwitch.getDefault(); 90 91 switcher.addPropertyChangeListener( this ); 92 setPaletteController( switcher.getCurrentPalette() ); 93 } 94 95 public void componentClosed() { 96 setPaletteController( null ); 98 99 PaletteSwitch.getDefault().removePropertyChangeListener( this ); 100 } 101 102 103 public Object writeReplace() { 104 return new ResolvableHelper(); 105 } 106 107 protected String preferredID() { 108 return getClass().getName(); 109 } 110 111 public void propertyChange (PropertyChangeEvent e) { 112 if( PaletteSwitch.PROP_PALETTE_CONTENTS.equals( e.getPropertyName() ) ) { 113 PaletteController pc = (PaletteController)e.getNewValue(); 114 115 setPaletteController( pc ); 116 } 117 } 118 119 private void setPaletteController( PaletteController pc ) { 120 if( null != pc ) { 121 PalettePanel.getDefault().setContent( pc, pc.getModel(), pc.getSettings() ); 122 } else { 123 PalettePanel.getDefault().setContent( null, null, null ); 124 } 125 } 126 127 public HelpCtx getHelpCtx() { 128 return PalettePanel.getDefault().getHelpCtx(); 129 } 130 131 final static class ResolvableHelper implements java.io.Serializable { 132 static final long serialVersionUID = 7424646018839457788L; 133 public Object readResolve() { 134 return PaletteTopComponent.getDefault(); 135 } 136 } 137 } 138 | Popular Tags |