aboutaction.java
来自「mywork是rcp开发的很好的例子」· Java 代码 · 共 91 行
JAVA
91 行
package es.org.chemi.games.sokoban.actions;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import es.org.chemi.games.sokoban.SokobanMessages;
import es.org.chemi.games.sokoban.ui.TileMap;
import es.org.chemi.games.sokoban.util.Constants;
/**
* 关于对话框
* @author levin
* @since 20080917
*/
public class AboutAction extends Action {
private TileMap map;
public AboutAction(TileMap map) {
super();
this.map = map;
}
public void run() {
new AboutDialog(map.getShell()).open();
}
class AboutDialog extends Dialog{
private int step=0,x=20,y=20;
public AboutDialog(Shell parent) {
super(parent);
}
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText(SokobanMessages.getString("AboutDialog.title"));
newShell.setSize(320, 240);
//居中
newShell.setLocation(newShell.getDisplay().getBounds().width/2-120, newShell.getDisplay().getBounds().height/2-100);
}
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID,IDialogConstants.OK_LABEL, true);
}
protected Control createDialogArea(Composite parent) {
final Composite composite=(Composite) super.createDialogArea(parent);
composite.setBackground(map.getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
composite.setForeground(map.getShell().getDisplay().getSystemColor(SWT.COLOR_GREEN));
final String list=SokobanMessages.getString("AboutDialog.text")+"\n\n\nhttp://mywork.sf.net";
final GC gc = new GC(composite);
final FontMetrics fm=gc.getFontMetrics();
new Runnable(){
public void run() {
try{
if(step >= list.length()){
gc.dispose();
return ;
}
char ch = list.charAt(step);
if(ch == '\n'){
y += fm.getHeight()+2;
x = 20;
}else{
String s = String.valueOf(ch);
gc.drawText(s, x, y);
}
x += fm.getAverageCharWidth();
if(ch < 32 || ch > 127)
x += fm.getAverageCharWidth();
step ++;
Display.getCurrent().timerExec(Constants.ANIMATION_SPEED/2, this);
}catch(Exception ex){
ex.printStackTrace();
}
}
}.run();
return composite;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?