~motu-torrent/azureus/upstream-stable

« back to all changes in this revision

Viewing changes to org/gudy/azureus2/pluginsimpl/local/ui/SWT/SWTManagerImpl.java

  • Committer: John Dong
  • Date: 2007-10-22 04:54:13 UTC
  • Revision ID: john.dong@gmail.com-20071022045413-3ovb11u82rrcokxx
Commit 3.0.3.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Created on 2004/May/14
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU General Public License
6
 
 * as published by the Free Software Foundation; either version 2
7
 
 * of the License, or (at your option) any later version.
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 * You should have received a copy of the GNU General Public License
13
 
 * along with this program; if not, write to the Free Software
14
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15
 
 */
16
 
 
17
 
package org.gudy.azureus2.pluginsimpl.local.ui.SWT;
18
 
 
19
 
import org.eclipse.swt.graphics.Image;
20
 
import org.eclipse.swt.widgets.Display;
21
 
 
22
 
import org.gudy.azureus2.core3.util.AEMonitor;
23
 
import org.gudy.azureus2.ui.swt.mainwindow.SWTThread;
24
 
import org.gudy.azureus2.ui.swt.plugins.UISWTInstance;
25
 
 
26
 
import com.aelitis.azureus.core.AzureusCoreFactory;
27
 
import com.aelitis.azureus.ui.UIFunctions;
28
 
import com.aelitis.azureus.ui.UIFunctionsManager;
29
 
import com.aelitis.azureus.ui.swt.UIFunctionsSWT;
30
 
 
31
 
import org.gudy.azureus2.plugins.PluginView;
32
 
import org.gudy.azureus2.plugins.ui.UIInstance;
33
 
import org.gudy.azureus2.plugins.ui.UIManager;
34
 
import org.gudy.azureus2.plugins.ui.UIManagerListener;
35
 
import org.gudy.azureus2.plugins.ui.SWT.GraphicSWT;
36
 
import org.gudy.azureus2.plugins.ui.SWT.SWTManager;
37
 
import org.gudy.azureus2.plugins.ui.model.PluginViewModel;
38
 
 
39
 
/*
40
 
 * @deprecated
41
 
 */
42
 
 
43
 
public class SWTManagerImpl
44
 
        implements SWTManager
45
 
{       
46
 
        protected static SWTManagerImpl singleton;
47
 
        
48
 
        private static AEMonitor        class_mon       = new AEMonitor( "SWTManager" );
49
 
 
50
 
        public static SWTManagerImpl getSingleton() {
51
 
                try{
52
 
                        class_mon.enter();
53
 
                
54
 
                        if (singleton == null)
55
 
                                singleton = new SWTManagerImpl();
56
 
                        return singleton;
57
 
                }finally{
58
 
                        
59
 
                        class_mon.exit();
60
 
                }
61
 
        }
62
 
  
63
 
  public Display getDisplay() {
64
 
        SWTThread instance = SWTThread.getInstance();
65
 
        if (instance == null)
66
 
                return null;
67
 
    return instance.getDisplay();
68
 
  }
69
 
  
70
 
  public GraphicSWT createGraphic(Image img) {
71
 
    return new GraphicSWTImpl(img);
72
 
  }
73
 
  
74
 
 
75
 
        public void addView(final PluginView view, final boolean bAutoOpen) {
76
 
                try {
77
 
                        UIManager ui_manager = AzureusCoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getUIManager();
78
 
 
79
 
                        ui_manager.addUIListener(new UIManagerListener() {
80
 
                                public void UIAttached(UIInstance instance) {
81
 
                                        if (instance instanceof UISWTInstance) {
82
 
                                                if (view instanceof PluginViewWrapper) {
83
 
 
84
 
                                                        // legacy support for RSSImport plugin
85
 
                                                        // model already registered, no need to do anything as UI will pick it up
86
 
 
87
 
                                                } else {
88
 
                                                        UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
89
 
                                                        if (uiFunctions instanceof UIFunctionsSWT) {
90
 
                                                                ((UIFunctionsSWT)uiFunctions).addPluginView(view);
91
 
 
92
 
                                                                if (bAutoOpen) {
93
 
                                                                        ((UIFunctionsSWT)uiFunctions).openPluginView(view);
94
 
                                                                }
95
 
                                                        }
96
 
                                                }
97
 
                                        }
98
 
                                }
99
 
 
100
 
                                public void UIDetached(UIInstance instance) {
101
 
                                }
102
 
                        });
103
 
 
104
 
                } catch (Throwable e) {
105
 
                        // SWT not available prolly
106
 
                }
107
 
        } 
108
 
 
109
 
        public void 
110
 
        addView(
111
 
                PluginView view)
112
 
        {
113
 
                addView(view, false);
114
 
        } 
115
 
 
116
 
        public PluginView
117
 
        createPluginView(
118
 
                PluginViewModel model )
119
 
        {               
120
 
                return( new PluginViewWrapper(model));
121
 
        
122
 
        }
123
 
        
124
 
        protected class
125
 
        PluginViewWrapper
126
 
                extends PluginView
127
 
        {
128
 
                private PluginViewModel         model;
129
 
                
130
 
                protected
131
 
                PluginViewWrapper(
132
 
                        PluginViewModel _model )
133
 
                {
134
 
                        model   = _model;
135
 
                }
136
 
                
137
 
                public String 
138
 
                getPluginViewName()
139
 
                {
140
 
                        return( model.getName());
141
 
                }
142
 
        }
143
 
        
144
 
  /* 
145
 
   * Not working due to class loader being different between plugins and
146
 
   * main program.
147
 
   * 
148
 
  public boolean loadImage(String resource,String name) {
149
 
    try {
150
 
      ImageRepository.loadImage(getDisplay(),resource,name);
151
 
      return true;
152
 
    } catch(Exception e) {
153
 
      e.printStackTrace();
154
 
      return false;
155
 
    }
156
 
  }
157
 
  
158
 
  public Image getImage(String name) {
159
 
    return ImageRepository.getImage(name);
160
 
  }*/
161
 
}
 
1
/*
 
2
 * Created on 2004/May/14
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 * You should have received a copy of the GNU General Public License
 
13
 * along with this program; if not, write to the Free Software
 
14
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
15
 */
 
16
 
 
17
package org.gudy.azureus2.pluginsimpl.local.ui.SWT;
 
18
 
 
19
import org.eclipse.swt.graphics.Image;
 
20
import org.eclipse.swt.widgets.Display;
 
21
 
 
22
import org.gudy.azureus2.core3.util.AEMonitor;
 
23
import org.gudy.azureus2.ui.swt.mainwindow.SWTThread;
 
24
import org.gudy.azureus2.ui.swt.plugins.UISWTInstance;
 
25
 
 
26
import com.aelitis.azureus.core.AzureusCoreFactory;
 
27
import com.aelitis.azureus.ui.UIFunctions;
 
28
import com.aelitis.azureus.ui.UIFunctionsManager;
 
29
import com.aelitis.azureus.ui.swt.UIFunctionsSWT;
 
30
 
 
31
import org.gudy.azureus2.plugins.PluginView;
 
32
import org.gudy.azureus2.plugins.ui.UIInstance;
 
33
import org.gudy.azureus2.plugins.ui.UIManager;
 
34
import org.gudy.azureus2.plugins.ui.UIManagerListener;
 
35
import org.gudy.azureus2.plugins.ui.SWT.GraphicSWT;
 
36
import org.gudy.azureus2.plugins.ui.SWT.SWTManager;
 
37
import org.gudy.azureus2.plugins.ui.model.PluginViewModel;
 
38
 
 
39
/*
 
40
 * @deprecated
 
41
 */
 
42
 
 
43
public class SWTManagerImpl
 
44
        implements SWTManager
 
45
{       
 
46
        protected static SWTManagerImpl singleton;
 
47
        
 
48
        private static AEMonitor        class_mon       = new AEMonitor( "SWTManager" );
 
49
 
 
50
        public static SWTManagerImpl getSingleton() {
 
51
                try{
 
52
                        class_mon.enter();
 
53
                
 
54
                        if (singleton == null)
 
55
                                singleton = new SWTManagerImpl();
 
56
                        return singleton;
 
57
                }finally{
 
58
                        
 
59
                        class_mon.exit();
 
60
                }
 
61
        }
 
62
  
 
63
  public Display getDisplay() {
 
64
        SWTThread instance = SWTThread.getInstance();
 
65
        if (instance == null)
 
66
                return null;
 
67
    return instance.getDisplay();
 
68
  }
 
69
  
 
70
  public GraphicSWT createGraphic(Image img) {
 
71
    return new GraphicSWTImpl(img);
 
72
  }
 
73
  
 
74
 
 
75
        public void addView(final PluginView view, final boolean bAutoOpen) {
 
76
                try {
 
77
                        UIManager ui_manager = AzureusCoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getUIManager();
 
78
 
 
79
                        ui_manager.addUIListener(new UIManagerListener() {
 
80
                                public void UIAttached(UIInstance instance) {
 
81
                                        if (instance instanceof UISWTInstance) {
 
82
                                                if (view instanceof PluginViewWrapper) {
 
83
 
 
84
                                                        // legacy support for RSSImport plugin
 
85
                                                        // model already registered, no need to do anything as UI will pick it up
 
86
 
 
87
                                                } else {
 
88
                                                        UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
 
89
                                                        if (uiFunctions instanceof UIFunctionsSWT) {
 
90
                                                                ((UIFunctionsSWT)uiFunctions).addPluginView(view);
 
91
 
 
92
                                                                if (bAutoOpen) {
 
93
                                                                        ((UIFunctionsSWT)uiFunctions).openPluginView(view);
 
94
                                                                }
 
95
                                                        }
 
96
                                                }
 
97
                                        }
 
98
                                }
 
99
 
 
100
                                public void UIDetached(UIInstance instance) {
 
101
                                }
 
102
                        });
 
103
 
 
104
                } catch (Throwable e) {
 
105
                        // SWT not available prolly
 
106
                }
 
107
        } 
 
108
 
 
109
        public void 
 
110
        addView(
 
111
                PluginView view)
 
112
        {
 
113
                addView(view, false);
 
114
        } 
 
115
 
 
116
        public PluginView
 
117
        createPluginView(
 
118
                PluginViewModel model )
 
119
        {               
 
120
                return( new PluginViewWrapper(model));
 
121
        
 
122
        }
 
123
        
 
124
        protected class
 
125
        PluginViewWrapper
 
126
                extends PluginView
 
127
        {
 
128
                private PluginViewModel         model;
 
129
                
 
130
                protected
 
131
                PluginViewWrapper(
 
132
                        PluginViewModel _model )
 
133
                {
 
134
                        model   = _model;
 
135
                }
 
136
                
 
137
                public String 
 
138
                getPluginViewName()
 
139
                {
 
140
                        return( model.getName());
 
141
                }
 
142
        }
 
143
        
 
144
  /* 
 
145
   * Not working due to class loader being different between plugins and
 
146
   * main program.
 
147
   * 
 
148
  public boolean loadImage(String resource,String name) {
 
149
    try {
 
150
      ImageRepository.loadImage(getDisplay(),resource,name);
 
151
      return true;
 
152
    } catch(Exception e) {
 
153
      e.printStackTrace();
 
154
      return false;
 
155
    }
 
156
  }
 
157
  
 
158
  public Image getImage(String name) {
 
159
    return ImageRepository.getImage(name);
 
160
  }*/
 
161
}