checklevelsdialog.java
来自「mywork是rcp开发的很好的例子」· Java 代码 · 共 111 行
JAVA
111 行
/************************************************************
*
* Copyright (c) 2003 Chemi. All rights reserved.
*
* This program and the accompanying materials
* are made available under the terms of the MIT License
* which accompanies this distribution, and is available at
* http://www.opensource.org/licenses/mit-license.html
*
************************************************************/
package es.org.chemi.games.sokoban.ui;
import java.util.ArrayList;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import es.org.chemi.games.sokoban.SokobanMessages;
import es.org.chemi.games.sokoban.SokobanPlugin;
import es.org.chemi.games.sokoban.util.Constants;
import es.org.chemi.games.sokoban.util.LevelInformation;
public class CheckLevelsDialog extends Dialog
{
private TileMap map = null;
public CheckLevelsDialog(Shell shell, TileMap map)
{
super(shell);
this.map = map;
}
protected void configureShell(Shell newShell)
{
super.configureShell(newShell);
newShell.setSize(280, 480);
newShell.setText(SokobanMessages.getString("CheckLevelsDialog.title")); //$NON-NLS-1$
}
protected Control createDialogArea(Composite parent)
{
SokobanPlugin.trace(this.getClass().getName(),"Creating CheckLevelsDialog."); //$NON-NLS-1$
Composite composite = (Composite)super.createDialogArea(parent);
composite.setLayout(new FillLayout());
Table table = new Table(composite,SWT.BORDER);
table.setLinesVisible (true);
table.setHeaderVisible (true);
String[] titles = {SokobanMessages.getString("CheckLevelsDialog.column1"),null, SokobanMessages.getString("CheckLevelsDialog.column3"), SokobanMessages.getString("CheckLevelsDialog.column4"), SokobanMessages.getString("CheckLevelsDialog.column5"), SokobanMessages.getString("CheckLevelsDialog.column6")}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
for(int i=0; i<titles.length; i++)
{
TableColumn column = new TableColumn(table, SWT.CENTER);
if(i == 1)
column.setImage(SokobanPlugin.getResourceManager().getImage(Constants.IMAGE_CHECK));
else
column.setText(titles [i]);
column.setResizable(false);
}
ArrayList tmp = null;
if(map.getPreferences().getMode() == Constants.MODE_ORIGINAL)
tmp = (ArrayList)map.getPreferences().getLevelsInfo().get(Constants.INFO_ORIGINAL);
else if(map.getPreferences().getMode() == Constants.MODE_EXTRA)
tmp = (ArrayList)map.getPreferences().getLevelsInfo().get(Constants.INFO_EXTRA);
else
tmp = (ArrayList)map.getPreferences().getLevelsInfo().get(Constants.INFO_OTHER);
for (int i=0; i<tmp.size(); i++)
{
TableItem item = new TableItem(table, SWT.NULL);
LevelInformation aux = (LevelInformation)tmp.get(i);
item.setText (0, Integer.toString(aux.getLevel()));
if(aux.isCompleted())
item.setImage(1,SokobanPlugin.getResourceManager().getImage(Constants.IMAGE_DONE));
else
item.setImage(1,SokobanPlugin.getResourceManager().getImage(Constants.IMAGE_FAILED));
item.setText(2,aux.getPlayer());
item.setText(3,Integer.toString(aux.getMoves()));
item.setText(4,Integer.toString(aux.getPushes()));
item.setText(5,Integer.toString(aux.getTime()));
}
for (int i=0; i<titles.length; i++)
table.getColumn(i).pack();
table.getColumn(1).setWidth(20);
return composite;
}
// Overwrite Dialog method to change the labels of its default buttons.
protected void createButtonsForButtonBar(Composite parent)
{
// create OK and Cancel buttons by default
createButton(parent, IDialogConstants.OK_ID, SokobanMessages.getString("CheckLevelsDialog.ok"), true); //$NON-NLS-1$
}
protected void okPressed()
{
SokobanPlugin.trace(this.getClass().getName(),"Closing CheckLevelsDialog."); //$NON-NLS-1$
super.okPressed();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?