📄 mainwindow.java
字号:
public void refreshIconBar() {
iconBar.setCurrentEnabler(this);
}
public void close() {
getShell().close();
}
public void closeViewOrWindow() {
if(getCurrentView() != null)
Tab.closeCurrent();
else
close();
}
public void showConfig() {
if (config == null){
config_view = new ConfigView( azureus_core );
config = new Tab(config_view);
}else{
config.setFocus();
}
}
public boolean showConfig(String id) {
if (config == null){
config_view = new ConfigView( azureus_core );
config = new Tab(config_view);
}else{
config.setFocus();
}
return config_view.selectSection(id);
}
public void showConsole() {
if (console == null)
console = new Tab(new LoggerView(events));
else
console.setFocus();
}
public void showStats() {
if (stats_tab == null)
stats_tab = new Tab(new StatsView(globalManager));
else
stats_tab.setFocus();
}
public void setSelectedLanguageItem()
{
try{
this_mon.enter();
Messages.updateLanguageForControl(mainWindow.getShell());
if ( systemTraySWT != null ){
Messages.updateLanguageForControl(systemTraySWT.getMenu());
}
if (statusText != null){
statusText.update();
}
if (folder != null) {
if(useCustomTab) {
((CTabFolder)folder).update();
} else {
((TabFolder)folder).update();
}
}
if (tray != null){
tray.updateLanguage();
}
Tab.updateLanguage();
setStatusText(statusTextKey);
}finally{
this_mon.exit();
}
}
public MainMenu getMenu() {
return mainMenu;
}
/*
* STProgressListener implementation, used for startup.
*/
public void reportCurrentTask(String task) {}
/**
* A percent > 100 means the end of the startup process
*/
public void reportPercent(int percent) {
if(percent > 100) {
Utils.execSWTThread(new AERunnable(){
public void runSupport() {
if(display == null || display.isDisposed())
return;
openMainWindow();
}
});
}
}
/**
* MUST be called by the SWT Thread
* @param updateWindow the updateWindow or null if no update is available
*/
public void setUpdateNeeded(UpdateWindow updateWindow) {
this.updateWindow = updateWindow;
if(updateWindow != null) {
statusText.setCursor(Cursors.handCursor);
statusText.setForeground(Colors.colorWarning);
updateStatusText();
} else {
statusText.setCursor(null);
statusText.setForeground(null);
updateStatusText();
}
}
//DownloadManagerListener implementation
public void completionChanged(DownloadManager manager, boolean bCompleted) {
// Do Nothing
}
public void downloadComplete(DownloadManager manager) {
// Do Nothing
}
public void positionChanged(DownloadManager download, int oldPosition,
int newPosition) {
// Do Nothing
}
public void stateChanged(final DownloadManager manager, int state) {
// if state == STARTED, then open the details window (according to config)
if(state == DownloadManager.STATE_DOWNLOADING || state == DownloadManager.STATE_SEEDING) {
if(display != null && !display.isDisposed()) {
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (display == null || display.isDisposed())
return;
if (COConfigurationManager.getBooleanParameter("Open Details",false)) {
openManagerView(manager);
}
if (COConfigurationManager.getBooleanParameter("Open Bar", false)) {
try{
downloadBars_mon.enter();
if(downloadBars.get(manager) == null) {
MinimizedWindow mw = new MinimizedWindow(manager, mainWindow);
downloadBars.put(manager, mw);
}
}finally{
downloadBars_mon.exit();
}
}
}
});
}
}
}
public AzureusCore
getAzureusCore()
{
return( azureus_core );
}
private void
addUpdateListener()
{
azureus_core.getPluginManager().getDefaultPluginInterface().getUpdateManager().addListener(new UpdateManagerListener () {
public void checkInstanceCreated(UpdateCheckInstance instance) {
new updateStatusChanger( instance );
}
});
}
protected class
updateStatusChanger
{
UpdateCheckInstance instance;
int check_num = 0;
boolean active;
protected
updateStatusChanger(
UpdateCheckInstance _instance )
{
instance = _instance;
try{
this_mon.enter();
update_stack.add( this );
instance.addListener(
new UpdateCheckInstanceListener ()
{
public void
cancelled(
UpdateCheckInstance instance)
{
deactivate();
}
public void
complete(
UpdateCheckInstance instance)
{
deactivate();
}
});
UpdateChecker[] checkers = instance.getCheckers();
UpdateCheckerListener listener = new UpdateCheckerListener() {
public void cancelled(UpdateChecker checker) {
// we don't count a cancellation as progress step
}
public void completed(UpdateChecker checker) {
setNextCheck();
}
public void failed(UpdateChecker checker) {
setNextCheck();
}
};
for(int i = 0 ; i < checkers.length ; i++) {
checkers[i].addListener(listener);
}
activate();
}finally{
this_mon.exit();
}
}
protected UpdateCheckInstance
getInstance()
{
return( instance );
}
private void
activate()
{
try{
this_mon.enter();
active = true;
switchStatusToUpdate();
setNbChecks(instance.getCheckers().length);
}finally{
this_mon.exit();
}
}
private void
deactivate()
{
try{
this_mon.enter();
active = false;
for (int i=0;i<update_stack.size();i++){
if ( update_stack.get(i) == this ){
update_stack.remove(i);
break;
}
}
if ( update_stack.size()==0){
switchStatusToText();
}else{
((updateStatusChanger)update_stack.get(update_stack.size()-1)).activate();
}
}finally{
this_mon.exit();
}
}
private void setNbChecks(final int nbChecks) {
if(display != null && ! display.isDisposed())
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if(statusUpdateProgressBar == null || statusUpdateProgressBar.isDisposed())
return;
statusUpdateProgressBar.setMinimum(0);
statusUpdateProgressBar.setMaximum(nbChecks);
statusUpdateProgressBar.setSelection(check_num);
}
});
}
private void setNextCheck() {
if(display != null && ! display.isDisposed())
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if(statusUpdateProgressBar == null || statusUpdateProgressBar.isDisposed())
return;
check_num++;
if ( active ){
statusUpdateProgressBar.setSelection( check_num );
}
}
});
}
private void switchStatusToUpdate() {
if(display != null && ! display.isDisposed())
Utils.execSWTThread(new AERunnable(){
public void runSupport() {
if ( statusArea == null || statusArea.isDisposed()){
return;
}
String name = instance.getName();
if ( MessageText.keyExists(name)){
name = MessageText.getString( name );
}
statusUpdateLabel.setText( name );
layoutStatusArea.topControl = statusUpdate;
statusArea.layout();
}
});
}
private void switchStatusToText() {
if(display != null && ! display.isDisposed())
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if ( statusArea == null || statusArea.isDisposed()){
return;
}
layoutStatusArea.topControl = statusText;
statusArea.layout();
}
});
}
}
protected void
showUpdateProgressWindow()
{
try{
this_mon.enter();
UpdateCheckInstance[] instances = new UpdateCheckInstance[update_stack.size()];
for (int i=0;i<instances.length;i++){
instances[i] = ((updateStatusChanger)update_stack.get(i)).getInstance();
}
UpdateProgressWindow.show( instances, this.getShell());
}finally{
this_mon.exit();
}
}
public void
generate(
IndentWriter writer )
{
writer.println( "SWT UI" );
try{
writer.indent();
writer.println( "SWT Version:" + SWT.getVersion() + "/" + SWT.getPlatform());
writer.println( "MyTorrents" );
try{
writer.indent();
Tab t = mytorrents;
if ( t != null ){
t.generateDiagnostics( writer );
}
}finally{
writer.exdent();
}
writer.println( "MyTracker" );
try{
writer.indent();
Tab t = my_tracker_tab;
if ( t != null ){
t.generateDiagnostics( writer );
}
}finally{
writer.exdent();
}
writer.println( "MyShares" );
try{
writer.indent();
Tab t = my_shares_tab;
if ( t != null ){
t.generateDiagnostics( writer );
}
}finally{
writer.exdent();
}
}finally{
writer.exdent();
}
}
private void checkForWhatsNewWindow() {
try {
int version = WelcomeWindow.WELCOME_VERSION;
int latestDisplayed = COConfigurationManager.getIntParameter("welcome.version.lastshown",0);
if(latestDisplayed < version) {
new WelcomeWindow();
COConfigurationManager.setParameter("welcome.version.lastshown",version);
COConfigurationManager.save();
}
} catch(Exception e) {
//DOo Nothing
}
}
public UISWTInstanceImpl getUISWTInstanceImpl() {
return uiSWTInstanceImpl;
}
private class CLabelPadding extends CLabel {
private int lastWidth = 0;
private long widthSetOn = 0;
private final int KEEPWIDTHFOR_MS = 30 * 1000;
public CLabelPadding(Composite parent, int style) {
super(parent, style | SWT.CENTER);
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER
| GridData.VERTICAL_ALIGN_FILL);
setLayoutData(gridData);
}
/* (non-Javadoc)
* @see org.eclipse.swt.custom.CLabel#computeSize(int, int, boolean)
*/
public Point computeSize(int wHint, int hHint, boolean changed) {
if ( !isVisible()){
return( new Point(0,0));
}
Point pt = super.computeSize(wHint, hHint, changed);
pt.x += 4;
long now = System.currentTimeMillis();
if (lastWidth > pt.x && now - widthSetOn < KEEPWIDTHFOR_MS) {
pt.x = lastWidth;
} else {
if (lastWidth != pt.x)
lastWidth = pt.x;
widthSetOn = now;
}
return pt;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -