1 19 20 package org.netbeans.modules.project.uiapi; 21 22 import java.awt.Component ; 23 import java.awt.Dimension ; 24 import java.awt.GridBagConstraints ; 25 import java.awt.Insets ; 26 import java.beans.PropertyChangeEvent ; 27 import java.beans.PropertyChangeListener ; 28 import java.util.HashMap ; 29 import javax.swing.BorderFactory ; 30 import javax.swing.JComponent ; 31 import javax.swing.JPanel ; 32 import javax.swing.JTextArea ; 33 import javax.swing.UIManager ; 34 import org.netbeans.spi.project.ui.support.ProjectCustomizer; 35 import org.openide.util.HelpCtx; 36 import org.openide.util.NbBundle; 37 38 42 public class CustomizerPane extends JPanel 43 implements HelpCtx.Provider, PropertyChangeListener { 44 45 public static final String HELP_CTX_PROPERTY = "helpCtxProperty"; 46 47 private Component currentCustomizer; 48 private JTextArea errorMessageValue = new JTextArea (); 49 private HelpCtx currentHelpCtx; 50 51 private GridBagConstraints fillConstraints; 52 private GridBagConstraints errMessConstraints = new GridBagConstraints (); 53 54 private ProjectCustomizer.CategoryComponentProvider componentProvider; 55 56 private HashMap <ProjectCustomizer.Category, JComponent > panelCache = new HashMap <ProjectCustomizer.Category, JComponent >(); 57 58 60 61 public CustomizerPane( JPanel categoryView, CategoryModel categoryModel, ProjectCustomizer.CategoryComponentProvider componentProvider ) { 62 initComponents(); 63 this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerPane.class,"AD_CustomizerPane")); this.componentProvider = componentProvider; 66 fillConstraints = new GridBagConstraints (); 67 fillConstraints.gridwidth = GridBagConstraints.REMAINDER; 68 fillConstraints.gridheight = 1; 69 fillConstraints.fill = GridBagConstraints.BOTH; 70 fillConstraints.weightx = 1.0; 71 fillConstraints.weighty = 1.0; 72 categoryModel.addPropertyChangeListener( new CategoryChangeListener() ); 73 categoryPanel.add( categoryView, fillConstraints ); 74 75 errorMessageValue.setWrapStyleWord(true); 77 errorMessageValue.setLineWrap(true); 78 errorMessageValue.setBorder(BorderFactory.createEmptyBorder()); 79 errorMessageValue.setEditable(false); 80 errorMessageValue.setForeground(UIManager.getColor("nb.errorForeground")); errorMessageValue.setBackground(customizerPanel.getBackground()); 82 83 errMessConstraints = new GridBagConstraints (); 85 errMessConstraints.gridx = 0; 86 errMessConstraints.gridy = 1; 87 errMessConstraints.gridwidth = 1; 88 errMessConstraints.gridheight = 1; 89 errMessConstraints.insets = new Insets (12, 0, 0, 0); 90 errMessConstraints.fill = GridBagConstraints.HORIZONTAL; 91 customizerPanel.add(errorMessageValue, errMessConstraints); 92 93 setCategory( categoryModel.getCurrentCategory() ); 94 } 95 96 101 private void initComponents() { 103 java.awt.GridBagConstraints gridBagConstraints; 104 105 jLabel1 = new javax.swing.JLabel (); 106 categoryPanel = new javax.swing.JPanel (); 107 customizerPanel = new javax.swing.JPanel (); 108 109 setLayout(new java.awt.GridBagLayout ()); 110 111 jLabel1.setLabelFor(categoryPanel); 112 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CustomizerPane.class, "LBL_Customizer_Categories")); gridBagConstraints = new java.awt.GridBagConstraints (); 114 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 115 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 116 gridBagConstraints.insets = new java.awt.Insets (8, 11, 0, 0); 117 add(jLabel1, gridBagConstraints); 118 119 categoryPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 120 categoryPanel.setMinimumSize(new java.awt.Dimension (220, 4)); 121 categoryPanel.setPreferredSize(new java.awt.Dimension (220, 4)); 122 categoryPanel.setLayout(new java.awt.GridBagLayout ()); 123 gridBagConstraints = new java.awt.GridBagConstraints (); 124 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 125 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 126 gridBagConstraints.weighty = 1.0; 127 gridBagConstraints.insets = new java.awt.Insets (3, 11, 8, 11); 128 add(categoryPanel, gridBagConstraints); 129 130 customizerPanel.setLayout(new java.awt.GridBagLayout ()); 131 gridBagConstraints = new java.awt.GridBagConstraints (); 132 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 133 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 134 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 135 gridBagConstraints.weightx = 1.0; 136 gridBagConstraints.weighty = 1.0; 137 gridBagConstraints.insets = new java.awt.Insets (3, 0, 8, 11); 138 add(customizerPanel, gridBagConstraints); 139 } 141 142 private javax.swing.JPanel categoryPanel; 144 private javax.swing.JPanel customizerPanel; 145 private javax.swing.JLabel jLabel1; 146 148 149 public void clearPanelComponentCache() { 150 panelCache.clear(); 152 } 153 154 public Dimension getPreferredSize() { 155 if (isPreferredSizeSet()) { 156 return super.getPreferredSize(); 157 } 158 Dimension dim = super.getPreferredSize(); 159 if (dim == null) { 160 return new Dimension (750, 450); 161 } 162 if (dim.getWidth() < 750 || dim.getHeight() < 450) { 163 return new Dimension (750, 450); 164 } 165 if (dim.getWidth() > 850) { 166 dim.width = 850; 167 } 168 if (dim.getHeight() > 550) { 169 dim.height = 550; 170 } 171 return dim; 172 } 173 174 176 public HelpCtx getHelpCtx() { 177 return currentHelpCtx; 178 195 } 196 197 198 200 private void setCategory( ProjectCustomizer.Category newCategory) { 201 if ( newCategory == null ) { 202 return; 203 } 204 205 if ( currentCustomizer != null ) { 206 customizerPanel.remove( currentCustomizer ); 207 } 208 209 JComponent newCustomizer = panelCache.get(newCategory); 210 if (newCustomizer == null && !panelCache.containsKey(newCustomizer)) { 211 newCustomizer = componentProvider.create( newCategory ); 212 panelCache.put(newCategory, newCustomizer); 213 } 214 215 if ( newCustomizer != null ) { 216 Utilities.getCategoryChangeSupport(newCategory).addPropertyChangeListener(this); 217 currentCustomizer = newCustomizer; 218 currentHelpCtx = HelpCtx.findHelp( currentCustomizer ); 219 220 225 customizerPanel.add( currentCustomizer, fillConstraints ); 226 customizerPanel.validate(); 227 customizerPanel.repaint(); 228 229 setErrorMessage(newCategory.getErrorMessage()); 230 firePropertyChange( HELP_CTX_PROPERTY, null, getHelpCtx() ); 231 } 232 else { 233 currentCustomizer = null; 234 } 235 236 } 237 238 private void setErrorMessage(String errMessage) { 239 errorMessageValue.setText(errMessage); 240 if (errMessage == null || errMessage.trim().equals("")) { 241 customizerPanel.remove(errorMessageValue); 242 } else { 243 customizerPanel.add(errorMessageValue, errMessConstraints); 244 } 245 customizerPanel.revalidate(); 246 } 247 248 public void propertyChange(PropertyChangeEvent evt) { 249 if (evt.getPropertyName() == CategoryChangeSupport.ERROR_MESSAGE_PROPERTY) { 250 String errMessage = (String ) evt.getNewValue(); 251 setErrorMessage(errMessage); 252 } 253 } 254 255 257 260 private class CategoryChangeListener implements PropertyChangeListener { 261 262 public void propertyChange(PropertyChangeEvent evt) { 263 264 if ( CategoryModel.PROP_CURRENT_CATEGORY.equals( evt.getPropertyName() ) ) { 265 ProjectCustomizer.Category newCategory = (ProjectCustomizer.Category)evt.getNewValue(); 266 setCategory( newCategory ); 267 } 268 } 269 } 270 271 } 272 | Popular Tags |