⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 counterstatus.java

📁 mywork是rcp开发的很好的例子
💻 JAVA
字号:
package es.org.chemi.games.sokoban;

import org.eclipse.jface.action.StatusLineContributionItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import es.org.chemi.games.sokoban.ui.MainView;
import es.org.chemi.games.sokoban.util.Constants;
import es.org.chemi.games.util.Counter;
import es.org.chemi.games.util.Timer;
/**
 * 在状态栏显示解关的相关计数,在mywork中会切换透视图,因此,本类会反复fill
 * @author levin
 */
public class CounterStatus extends StatusLineContributionItem {
	MainView view = null;
	public CounterStatus(String id,MainView view) {
		super(id);
		this.view=view;
		setVisible(true);
	}
	@Override
	public void fill(Composite parent) {
		Composite line=new Composite(parent,SWT.NULL);
		GridLayout layout = new GridLayout(9,false); //9>8 留一空
		layout.marginWidth=0;
		layout.marginHeight=0;
		line.setLayout(layout);
		GridData gridData = new GridData();
		gridData.horizontalAlignment = GridData.CENTER;
		gridData.verticalAlignment = GridData.CENTER;
		gridData.verticalSpan = 0;
		
		Label label = new Label(line,SWT.NONE);
		label.setText(SokobanMessages.getString("MainView.moves")); //$NON-NLS-1$
		label.setLayoutData(gridData);
		Counter counterMoves = new Counter(line,SWT.BORDER,4,0,Constants.PLUGIN_ID);
		Counter oldCounterMoves = (Counter) view.getCounters().get(Constants.COUNTER_MOVES);
		if(oldCounterMoves != null){
			counterMoves.increase(oldCounterMoves.getValue());
			oldCounterMoves.dispose();
		}
		
		label = new Label(line,SWT.NONE);
		label.setText(SokobanMessages.getString("MainView.pushes")); //$NON-NLS-1$
		label.setLayoutData(gridData);
		Counter counterPushes = new Counter(line,SWT.BORDER,4,0,Constants.PLUGIN_ID);
		Counter oldCounterPushs = (Counter) view.getCounters().get(Constants.COUNTER_PUSHES);
		if(oldCounterPushs != null){
			counterPushes.increase(oldCounterPushs.getValue());
			oldCounterPushs.dispose();
		}
		
		
		label = new Label(line,SWT.CENTER);
		label.setText(SokobanMessages.getString("MainView.time")); //$NON-NLS-1$
		label.setLayoutData(gridData);
		Timer counterTime = new Timer(line,SWT.BORDER,4,Constants.PLUGIN_ID);
		Timer oldCounterTime = (Timer) view.getCounters().get(Constants.COUNTER_TIME);
		if(oldCounterTime != null){
			counterTime.setTime(oldCounterTime.getTime());
			oldCounterTime.stop();
			oldCounterTime.dispose();
		}
		
		label = new Label(line,SWT.NONE);
		label.setText(SokobanMessages.getString("MainView.level")); //$NON-NLS-1$
		label.setLayoutData(gridData);
		Counter counterLevel = new Counter(line,SWT.BORDER,4,view.getPreferences().getLevel(),Constants.PLUGIN_ID);
		Counter oldCounterLevel = (Counter) view.getCounters().get(Constants.COUNTER_LEVEL);
		if(oldCounterLevel != null){
			oldCounterLevel.dispose();
		}
		
		view.getCounters().put(Constants.COUNTER_MOVES,counterMoves);
		view.getCounters().put(Constants.COUNTER_PUSHES,counterPushes);
		view.getCounters().put(Constants.COUNTER_TIME,counterTime);
		view.getCounters().put(Constants.COUNTER_LEVEL,counterLevel);
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -