1 29 38 39 package org.planetamessenger.mos.engine; 40 41 import java.util.*; 42 import java.awt.*; 43 import javax.swing.*; 44 import org.planetamessenger.mos.forms.*; 45 import org.planetamessenger.plugin.*; 46 import com.jgoodies.forms.builder.*; 47 import com.jgoodies.forms.layout.*; 48 import com.jgoodies.forms.debug.*; 49 50 51 52 public class JPluginPreferencesManager implements JPreferencesListener { 53 54 private HashMap<Integer , JPluginPreferencesContainer> hPropertyPages = null; 55 private JScrollPane scrollPane = null; 56 private FormLayout layout = null; 57 private JLabel panelLabel = null; 58 private JPanel panelInfo = null; 59 private JDataField selectedItem = null; 60 61 62 65 public JPluginPreferencesManager() { 66 67 hPropertyPages = new HashMap<Integer , JPluginPreferencesContainer>(); 68 scrollPane = new JScrollPane(); 69 layout = new FormLayout( "fill:pref:grow", "fill:15dlu, fill:pref:grow" ); 70 panelLabel = new JLabel(); 71 panelInfo = JSharedObjects.getKernelManager().getUserInterfaceManager().createGradientPanel(); 72 73 panelLabel.setOpaque( false ); 74 panelLabel.setForeground( Color.WHITE ); 75 panelLabel.setFont( JSystemFonts.FONT ); 76 panelInfo.setOpaque( true ); 77 panelInfo.setBackground( Color.DARK_GRAY ); 78 panelInfo.add( panelLabel ); 79 } 80 81 84 public void destroy() { 85 86 scrollPane.removeAll(); 87 hPropertyPages.clear(); 88 hPropertyPages = null; 89 } 90 91 96 public boolean add( int nPluginId, JPluginPreferencesContainer container ) { 97 98 if( container != null ) { 99 hPropertyPages.put( new Integer ( nPluginId ), container ); 100 return true; 101 } 102 103 return false; 104 } 105 106 110 public void remove( int nPluginId ) { 111 112 hPropertyPages.remove( new Integer ( nPluginId ) ); 113 } 114 115 119 public JScrollPane getPreferencesScrollPane() { 120 121 return scrollPane; 122 } 123 124 127 public void clearScrollPane() { 128 129 scrollPane.getViewport().removeAll(); 130 } 131 132 137 public void fireOnShow( int nPluginId, JDataField field ) { 138 139 JPluginPreferencesContainer prefs = hPropertyPages.get( new Integer ( nPluginId ) ); 140 141 if( prefs != null ) { 142 143 CellConstraints cellConst = new CellConstraints(); 144 PanelBuilder builder = new PanelBuilder( layout ); 145 146 selectedItem = field; 147 panelLabel.setText( "<html><b>" + ( ( ( Integer ) selectedItem.getObject() ).intValue() < 0 ? JSharedObjects.getLanguageManager().getStringEx( selectedItem.getKeyName() ) : selectedItem.toString() ) + "</b></html>" ); 148 prefs.onShow(); 149 150 builder.setDefaultDialogBorder(); 151 builder.add( panelInfo, cellConst.xy( 1, 1 ) ); 152 builder.add( prefs, cellConst.xy( 1, 2 ) ); 153 154 clearScrollPane(); 155 scrollPane.getViewport().add( builder.getPanel() ); 156 scrollPane.updateUI(); 157 } 158 else { 159 clearScrollPane(); 160 scrollPane.updateUI(); 161 } 162 } 163 164 167 public boolean fireOnApply() { 168 169 Iterator<JPluginPreferencesContainer> itItem = hPropertyPages.values().iterator(); 170 boolean bRet = true; 171 172 while( itItem.hasNext() ) { 173 JPluginPreferencesContainer preferencesContainer = itItem.next(); 174 175 try { 176 bRet = preferencesContainer.onApply(); 177 } catch( Exception e ) { 178 System.err.println( "JPluginPreferencesManager.fireOnApply() - " + e ); 179 bRet = false; 180 } 181 } 182 183 return bRet; 184 } 185 186 189 public void fireOnCancel() { 190 191 Iterator<JPluginPreferencesContainer> itItem = hPropertyPages.values().iterator(); 192 193 while( itItem.hasNext() ) { 194 JPluginPreferencesContainer preferencesContainer = itItem.next(); 195 196 try { 197 preferencesContainer.onCancel(); 198 } catch( Exception e ) { 199 System.err.println( "JPluginPreferencesManager.fireOnCancel() - " + e ); 200 } 201 } 202 } 203 204 208 public void fireOnLookAndFeelChanged() { 209 210 Iterator<JPluginPreferencesContainer> itItem = hPropertyPages.values().iterator(); 211 212 while( itItem.hasNext() ) { 213 JPluginPreferencesContainer preferencesContainer = itItem.next(); 214 215 try { 216 preferencesContainer.onLookAndFeelChanged(); 217 } catch( Exception e ) { 218 System.err.println( "JPluginPreferencesManager.fireOnLookAndFeelChanged() - " + e ); 219 } 220 } 221 } 222 223 227 public void fireOnLanguageChanged( String strCountryCode ) { 228 229 Iterator<JPluginPreferencesContainer> itItem = hPropertyPages.values().iterator(); 230 231 if( selectedItem != null ) 232 panelLabel.setText( "<html><b>" + ( ( ( Integer ) selectedItem.getObject() ).intValue() < 0 ? JSharedObjects.getLanguageManager().getStringEx( selectedItem.getKeyName() ) : selectedItem.toString() ) + "</b></html>" ); 233 234 while( itItem.hasNext() ) { 235 JPluginPreferencesContainer preferencesContainer = itItem.next(); 236 237 try { 238 preferencesContainer.onLanguageChanged( strCountryCode ); 239 } catch( Exception e ) { 240 System.err.println( "JPluginPreferencesManager.fireOnLanguageChanged() - " + e ); 241 } 242 } 243 } 244 245 251 public void EnableApplyPreferencesManager( boolean bEnabled ) { 252 253 JMOSPreferencesDlg preferencesDlg = JSharedObjects.getMainWindow().getPreferencesDialog(); 254 255 if( preferencesDlg != null ) 256 preferencesDlg.EnableApply( bEnabled ); 257 } 258 } 259 260 | Popular Tags |