FileDocCategorySizeDatePackage
UISWTInstanceImpl.javaAPI DocAzureus 3.0.3.419132Sat May 12 15:38:18 BST 2007org.gudy.azureus2.ui.swt.pluginsimpl

UISWTInstanceImpl

public class UISWTInstanceImpl extends Object implements UISWTInstance, UIManagerEventListener, UIInstanceFactory

Fields Summary
private com.aelitis.azureus.core.AzureusCore
core
private Map
awt_view_map
private Map
config_view_map
private Map
views
private Map
plugin_map
private boolean
bUIAttaching
private final com.aelitis.azureus.ui.swt.UIFunctionsSWT
uiFunctions
Constructors Summary
public UISWTInstanceImpl(com.aelitis.azureus.core.AzureusCore _core)

	
	
	   
		core		= _core;

		// Since this is a UI **SWT** Instance Implementor, it's assumed
		// that the UI Functions are of UIFunctionsSWT 
		uiFunctions = (UIFunctionsSWT) UIFunctionsManager.getUIFunctions();
	
Methods Summary
public voidaddView(UISWTAWTPluginView view, boolean auto_open)

deprecated

		UISWTPluginView	v = 
			new UISWTPluginView()
			{
				Composite		composite;
				Component		component;
				
				boolean	first_paint = true;
				
				public String
				getPluginViewName()
				{
					return( view.getPluginViewName());
				}
				
				public String 
				getFullTitle() 
				{
					return( view.getPluginViewName());
				}
				 
				public void 
				initialize(
					Composite _composite )
				{
					first_paint	= true;
					
					composite	= _composite;
					
					Composite frame_composite = new Composite(composite, SWT.EMBEDDED);
	
					GridData data = new GridData(GridData.FILL_BOTH);
					
					frame_composite.setLayoutData(data);
	
					Frame	f = SWT_AWT.new_Frame(frame_composite);
	
					BorderLayout	layout = 
						new BorderLayout()
						{
							public void 
							layoutContainer(Container parent)
							{
								try{
									super.layoutContainer( parent );
								
								}finally{
									if ( first_paint ){
										
										first_paint	= false;
											
										view.open( component );
									}
								}
							}
						};
					
					Panel	pan = new Panel( layout );
	
					f.add( pan );
							
					component	= view.create();
					
					pan.add( component, BorderLayout.CENTER );
				}
				
				public Composite 
				getComposite()
				{
					return( composite );
				}
				
				public void 
				delete() 
				{
					super.delete();
					
					view.delete( component );
				}
			};
			
		awt_view_map.put( view, v );
		
		addView( v, auto_open );
	
public voidaddView(java.lang.String sParentID, java.lang.String sViewID, UISWTViewEventListener l)

		Map subViews = (Map) views.get(sParentID);
		if (subViews == null) {
			subViews = new HashMap();
			views.put(sParentID, subViews);
		}

		subViews.put(sViewID, l);

		if (sParentID.equals(UISWTInstance.VIEW_MAIN)) {
			Utils.execSWTThread(new AERunnable() {
				public void runSupport() {
					try {
						uiFunctions.addPluginView(sViewID, l);
					} catch (Throwable e) {
						// SWT not available prolly
					}
				}
			});
		}
	
public voidaddView(UISWTPluginView view, boolean bAutoOpen)

deprecated

		try {
			uiFunctions.addPluginView(view);
			if (bAutoOpen) {
				uiFunctions.openPluginView(view);
			}
		} catch (Throwable e) {
			// SWT not available prolly
		}
	
public UISWTGraphiccreateGraphic(org.eclipse.swt.graphics.Image img)

		return new UISWTGraphicImpl(img);
	
public UISWTStatusEntrycreateStatusEntry()

		final UISWTStatusEntryImpl entry = new UISWTStatusEntryImpl();
		final CLabel label = MainWindow.getWindow().getMainStatusBar().createStatusEntry(entry);
		final Listener click_listener = new Listener() {
			public void handleEvent(Event e) {
				entry.onClick();
			}
		};

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				label.addListener(SWT.MouseDoubleClick, click_listener);
			}
		}, true);
		
		return entry;
	
public voiddetach()

		throw( new UIException( "not supported" ));
	
public booleaneventOccurred(UIManagerEvent event)

		boolean	done = true;
		
		final Object	data = event.getData();
		
		switch( event.getType()){
		
			case UIManagerEvent.ET_SHOW_TEXT_MESSAGE:
			{
				Utils.execSWTThread(
					new Runnable()
					{
						public void 
						run()
						{
							String[]	params = (String[])data;
							
							new TextViewerWindow( params[0], params[1], params[2] );
						}
					});
				
				break;
			}
			
			case UIManagerEvent.ET_OPEN_TORRENT_VIA_FILE:
			{	
				TorrentOpener.openTorrent(((File)data).toString());

				break;
			}
			case UIManagerEvent.ET_OPEN_TORRENT_VIA_URL:
			{
				Display display = SWTThread.getInstance().getDisplay();

				display.syncExec(new AERunnable() {
					public void runSupport() {
						Object[] params = (Object[]) data;

						URL target = (URL) params[0];
						URL referrer = (URL) params[1];
						boolean auto_download = ((Boolean) params[2]).booleanValue();

						// programmatic request to add a torrent, make sure az is visible

						if (!COConfigurationManager.getBooleanParameter("add_torrents_silently")) {
							uiFunctions.bringToFront();
						}

						if (auto_download) {
							Shell shell = uiFunctions.getMainShell();
							if (shell != null) {
								new FileDownloadWindow(core, shell, target.toString(),
										referrer == null ? null : referrer.toString());
							}
						} else {

							// TODO: handle referrer?

							TorrentOpener.openTorrent(target.toString());
						}
					}
				});

				break;
			}
			case UIManagerEvent.ET_PLUGIN_VIEW_MODEL_CREATED:
			{
				if ( data instanceof BasicPluginViewModel ){
					BasicPluginViewModel model = (BasicPluginViewModel)data;
					
					// property bundles can't handle spaces in keys
					String sViewID = model.getName().replaceAll(" ", ".");
					BasicPluginViewImpl view = new BasicPluginViewImpl(model);
					addView(UISWTInstance.VIEW_MAIN, sViewID, view);
				}
				
				break;
			}
			case UIManagerEvent.ET_PLUGIN_VIEW_MODEL_DESTROYED:
			{
				if ( data instanceof BasicPluginViewModel ){
					BasicPluginViewModel model = (BasicPluginViewModel)data;
					// property bundles can't handle spaces in keys
					String sViewID = model.getName().replaceAll(" ", ".");
					removeViews(UISWTInstance.VIEW_MAIN, sViewID);
				}
				
				break;
			}
			case UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_CREATED:
			{
				if ( data instanceof BasicPluginConfigModel ){
					
					BasicPluginConfigModel	model = (BasicPluginConfigModel)data;
					
					BasicPluginConfigImpl view = new BasicPluginConfigImpl(model);
					   
					config_view_map.put( model, view );
					
					model.getPluginInterface().addConfigSection( view );
				}
				
				break;
			}
			case UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_DESTROYED:
			{
				if ( data instanceof BasicPluginConfigModel ){
					
					BasicPluginConfigModel	model = (BasicPluginConfigModel)data;
					
					BasicPluginConfigImpl view = (BasicPluginConfigImpl)config_view_map.get( model );
					   
					if ( view != null ){
						
						model.getPluginInterface().removeConfigSection( view );
					}
				}
				
				break;
			}
			case UIManagerEvent.ET_COPY_TO_CLIPBOARD:
			{
				ClipboardCopy.copyToClipBoard((String)data);
				
				break;
			}
			case UIManagerEvent.ET_OPEN_URL:
			{
				Utils.launch(((URL)data).toExternalForm());
				
				break;
			}
			case UIManagerEvent.ET_CREATE_TABLE_COLUMN:{
				
	 			String[]	args = (String[])data;
	 			
	 			event.setResult( new TableColumnImpl(args[0], args[1]));
	 			
	 			break;
			} 
			case UIManagerEvent.ET_ADD_TABLE_COLUMN:{
				
				TableColumn	_col = (TableColumn)data;
				
				if ( _col instanceof TableColumnImpl ){
					
					TableColumnManager.getInstance().addColumn((TableColumnImpl)_col);
					
				}else{
					
					throw(new UIRuntimeException("TableManager.addColumn(..) can only add columns created by createColumn(..)"));
				}
				
				break;
			} 
			case UIManagerEvent.ET_ADD_TABLE_CONTEXT_MENU_ITEM:{
				TableContextMenuItem	item = (TableContextMenuItem)data;
				TableContextMenuManager.getInstance().addContextMenuItem(item);
				break;
			}
			case UIManagerEvent.ET_ADD_MENU_ITEM: {
				MenuItem item = (MenuItem)data;
				MenuItemManager.getInstance().addMenuItem(item);
				break;
			}
			case UIManagerEvent.ET_REMOVE_TABLE_CONTEXT_MENU_ITEM:{
				TableContextMenuItem item = (TableContextMenuItem)data;
				TableContextMenuManager.getInstance().removeContextMenuItem(item);
				break;
			}
			case UIManagerEvent.ET_REMOVE_MENU_ITEM: {
				MenuItem item = (MenuItem)data;
				MenuItemManager.getInstance().removeMenuItem(item);
				break;
			}			
			case UIManagerEvent.ET_SHOW_CONFIG_SECTION: {
				event.setResult(new Boolean(false));

				if (!(data instanceof String))
					break;

	    	event.setResult(new Boolean(uiFunctions.showConfig((String)data)));

				break;
			}
			default:
			{
				done	= false;
				
				break;
			}
		}
		
		return( done );
	
public org.eclipse.swt.widgets.DisplaygetDisplay()

		return SWTThread.getInstance().getDisplay();
	
public UIInputReceivergetInputReceiver()

		return new SimpleTextEntryWindow(getDisplay());
	
public UIInstancegetInstance(org.gudy.azureus2.plugins.PluginInterface plugin_interface)

		UIInstance	instance = (UIInstance)plugin_map.get( plugin_interface );
		
		if ( instance == null ){
			
			instance = new instanceWrapper( plugin_interface, this );
			
			plugin_map.put( plugin_interface, instance );
		}
		
		return( instance );
	
public UISWTView[]getOpenViews(java.lang.String sParentID)

		if (sParentID.equals(UISWTInstance.VIEW_MAIN)) {
			try {
				if (uiFunctions != null) {
					return uiFunctions.getPluginViews();
				}
			} catch (Throwable e) {
				// SWT not available prolly
			}
		}
		return new UISWTView[0];
	
public java.util.MapgetViewListeners(java.lang.String sParentID)

		return (Map)views.get(sParentID);
	
public voidinit()

		try{
			UIManager	ui_manager = core.getPluginManager().getDefaultPluginInterface().getUIManager();
			
			ui_manager.addUIEventListener( this );
			
			bUIAttaching = true;
			
			ui_manager.attachUI( this );
			
			bUIAttaching = false;
			
		}catch( UIException e ){
			
			Debug.printStackTrace(e);
		}
	
public org.eclipse.swt.graphics.ImageloadImage(java.lang.String resource)

		throw( new RuntimeException( "plugin specific instance required" ));
	
protected org.eclipse.swt.graphics.ImageloadImage(org.gudy.azureus2.plugins.PluginInterface pi, java.lang.String res)

		InputStream is = pi.getPluginClassLoader().getResourceAsStream( res);
		
		if ( is != null ){
		        
			ImageData imageData = new ImageData(is);
		    
			return new Image(getDisplay(), imageData);
		}
		
		return null;
	
public voidopenMainView(java.lang.String sViewID, UISWTViewEventListener l, java.lang.Object dataSource)

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				if (uiFunctions != null) {
					uiFunctions.openPluginView(UISWTInstance.VIEW_MAIN, sViewID, l, dataSource, !bUIAttaching);
				}
			}
		});
	
public booleanopenView(java.lang.String sParentID, java.lang.String sViewID, java.lang.Object dataSource)

		Map subViews = (Map) views.get(sParentID);
		if (subViews == null) {
			return false;
		}

		final UISWTViewEventListener l = (UISWTViewEventListener) subViews.get(sViewID);
		if (l == null) {
			return false;
		}

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				if (uiFunctions != null) {
					uiFunctions.openPluginView(sParentID, sViewID, l, dataSource,
							!bUIAttaching);
				}
			}
		});

		return true;
	
public intpromptUser(java.lang.String title, java.lang.String text, java.lang.String[] options, int defaultOption)

		return MessageBoxShell.open(uiFunctions.getMainShell(), title, text,
				options, defaultOption);
	
public voidremoveView(UISWTPluginView view)

		try {
			uiFunctions.removePluginView(view);
		} catch (Throwable e) {
			// SWT not available prolly
		}
	
public voidremoveView(UISWTAWTPluginView view)

		UISWTPluginView	v = (UISWTPluginView)awt_view_map.remove(view );
		
		if ( v != null ){
			
			removeView( v );
		}
	
public voidremoveViews(java.lang.String sParentID, java.lang.String sViewID)

		Map subViews = (Map) views.get(sParentID);
		if (subViews == null)
			return;

		if (sParentID.equals(UISWTInstance.VIEW_MAIN)) {
			Utils.execSWTThread(new AERunnable() {
				public void runSupport() {
					try {
						if (uiFunctions != null) {
							uiFunctions.removePluginView(sViewID);
						}
					} catch (Throwable e) {
						// SWT not available prolly
					}
				}
			});
		}
		subViews.remove(sViewID);
	
public voidshowDownloadBar(org.gudy.azureus2.plugins.download.Download download, boolean display)

		if (!(download instanceof DownloadImpl)) {return;}
		final DownloadManager dm = ((DownloadImpl)download).getDownload();
		if (dm == null) {return;} // Not expecting this, but just in case...
		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				if (display) {
					DownloadBar.open(dm, getDisplay().getActiveShell());
				}
				else {
					DownloadBar.close(dm);
				}
			}
		}, false);
	
public voidshowTransfersBar(boolean display)

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				if (display) {
					AllTransfersBar.open(core.getGlobalManager(), getDisplay().getActiveShell());
				}
				else {
					AllTransfersBar.close(core.getGlobalManager());
				}
			}
		}, false);