📄 saleinstore.java
字号:
package GUI;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.*;
import PizzaProduct.Pizza;
public class SaleInStore extends Composite {
private Table table;
protected String name;
protected String type;
protected String size;
protected String[] topping;
protected String toppings="";
protected int quantity;
protected boolean namechoosed=false;
protected boolean typechoosed=false;
protected boolean sizechoosed=false;
private String sizeStrings[] = { "5'", "6'", "7'", "8'" };
//private double sizeValues[] = { 5.0, 6.0, 7.0, 8.0 };
private String typeNames[] = {
"Thick pan", "Thin Pan", "Special" };
private String pizzaNames[] = {
"Supreme", "Hawaii", "Meat Lover", "Seafood" };
private String[] toppingNames = {
"Pineapple", "Mushroom", "Gallic" };
Button[] namebutton = new Button[pizzaNames.length];
Button[] typebutton = new Button[typeNames.length];
Button[] sizebutton = new Button[sizeStrings.length];
Button[] toppingbutton = new Button[toppingNames.length];
TableItem[] pizzaitem = new TableItem[50];
/**
* Create the composite
* @param parent
* @param style
*/
public SaleInStore(final Composite parent, int style) {
super(parent, style);
//Name Group setup
final Group nameGroup = new Group(this, SWT.NONE);
nameGroup.setText("Name");
nameGroup.setBounds(10, 0, 480, 50);
quantity=0;
int i;
for(i=0;i<pizzaNames.length;i++){
namebutton[i]=new Button(nameGroup, SWT.RADIO);
namebutton[i].setText(pizzaNames[i]);
namebutton[i].setBounds(5+124*i, 25, 93, 16);
namebutton[i].addSelectionListener(new NameAction(pizzaNames[i]));
}
//Type Group setup
final Group baseTypeGroup = new Group(this, SWT.NONE);
baseTypeGroup.setText("Base Type");
baseTypeGroup.setBounds(10, 50, 480, 50);
for(i=0;i<typeNames.length;i++){
typebutton[i]=new Button(baseTypeGroup, SWT.RADIO);
typebutton[i].setText(typeNames[i]);
typebutton[i].setBounds(5+124*i, 25, 93, 16);
typebutton[i].addSelectionListener(new TypeAction(typeNames[i]));
}
//Size Group setup
final Group sizeGroup = new Group(this, SWT.NONE);
sizeGroup.setText("Size");
sizeGroup.setBounds(10, 100, 480, 50);
for(i=0;i<sizeStrings.length;i++){
sizebutton[i]=new Button(sizeGroup, SWT.RADIO);
sizebutton[i].setText(sizeStrings[i]);
sizebutton[i].setBounds(5+124*i, 25, 93, 16);
sizebutton[i].addSelectionListener(new SizeAction(sizeStrings[i]));
}
//Topping Group setup
final Group toppingGroup = new Group(this, SWT.NONE);
toppingGroup.setText("Topping");
toppingGroup.setBounds(10, 150, 480, 50);
for(i=0;i<toppingNames.length;i++){
toppingbutton[i]=new Button(toppingGroup, SWT.CHECK);
toppingbutton[i].setText(toppingNames[i]);
toppingbutton[i].setBounds(5+124*i, 25, 93, 16);
}
//Create a table to display the pizza information
table = new Table(this, SWT.BORDER|SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setBounds(10, 235, 480, 147);
final TableColumn newColumnTableColumn = new TableColumn(table, SWT.NONE);
newColumnTableColumn.setWidth(100);
newColumnTableColumn.setText("Name");
final TableColumn newColumnTableColumn_1 = new TableColumn(table, SWT.NONE);
newColumnTableColumn_1.setWidth(100);
newColumnTableColumn_1.setText("Type");
final TableColumn newColumnTableColumn_2 = new TableColumn(table, SWT.NONE);
newColumnTableColumn_2.setWidth(100);
newColumnTableColumn_2.setText("Size");
final TableColumn newColumnTableColumn_3 = new TableColumn(table, SWT.NONE);
newColumnTableColumn_3.setWidth(177);
newColumnTableColumn_3.setText("Toppings");
//Setup some functional buttons
final Button button_4 = new Button(this, SWT.NONE);
button_4.setText("确认添加");
/**
* In there, when user click the button "确认添加" We have something to do
* 1. Check if all the information is it have
* 2. Find the toppings the cunstomer need. Because it's a multi-choices, we used a String to save a the topping
* 3. Make a table item to display the Pizza that customer ordered.
*/
button_4.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int i;
if(namechoosed&&typechoosed&&sizechoosed){
for(i=0;i<toppingNames.length;i++)
{
if (toppingbutton[i].getSelection())
{
if(toppings.equals(""))
toppings=toppingbutton[i].getText();
else
toppings=toppings+","+toppingbutton[i].getText();
}
}
pizzaitem[quantity] = new TableItem(table, SWT.BORDER);
pizzaitem[quantity].setText(3, toppings);
pizzaitem[quantity].setText(2, size);
pizzaitem[quantity].setText(1, type);
pizzaitem[quantity].setText(0, name);
quantity++;
toppings="";
}
else{
MessageDialog.openWarning(parent.getShell(), "警告","输入数据不完整!请检查");
}
}
});
button_4.setBounds(70, 207, 59, 22);
//a delete button to delete the choiced item.
final Button button_5 = new Button(this, SWT.NONE);
button_5.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if(table.getSelectionCount()!=0){
table.remove(table.getSelectionIndex());
quantity--;}
}
});
button_5.setText("删除");
button_5.setBounds(200, 207, 59, 22);
/**
* when user have click the button"完成" means the customer have choose all the pizza he wanted
* Then we create some Pizza Object to store the pizza that customer ordered.
* So we need to ask some feather question. Such like the Speed and eatting in store or not
* To do that, we need to create some dialog to get the message.
* To create a shell to set the dialog.
* When a order is complete, the system will come back, and the history options will be delete.
*/
final Button button_6 = new Button(this, SWT.NONE);
button_6.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int i;
Pizza[] pizzas = new Pizza[quantity];
if(quantity == 0){
MessageDialog.openWarning(parent.getShell(), "警告","未添加任何PIZZA");
}
else{
for (i=0;i<quantity;i++){
if(!pizzaitem[i].isDisposed())
pizzas[i]=new Pizza(pizzaitem[i].getText(0),pizzaitem[i].getText(1),pizzaitem[i].getText(2),pizzaitem[i].getText(3));
}
//a dialog shell.
final Shell fornext;
fornext = parent.getShell();
final ChooseTheRoutines choosttheroutines = new ChooseTheRoutines(fornext,pizzas);
choosttheroutines.open();
initial();
}
}
});
button_6.setText("完成");
button_6.setBounds(315, 206, 59, 22);
//
}
public void dispose() {
super.dispose();
}
// When one order is complete , the compsite must be initialed again.
public void initial(){
table.removeAll();
int i;
for(i=0;i<pizzaNames.length;i++){
namebutton[i].setSelection(false);
}
for(i=0;i<typeNames.length;i++){
typebutton[i].setSelection(false);;
}
for(i=0;i<sizeStrings.length;i++){
sizebutton[i].setSelection(false);;
}
for(i=0;i<toppingNames.length;i++){
toppingbutton[i].setSelection(false);;
}
namechoosed=false;
typechoosed=false;
sizechoosed=false;
pizzaitem = new TableItem[50];
quantity = 0;
}
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
class NameAction extends SelectionAdapter{
String aname;
public NameAction(String aname)
{
super();
this.aname = aname;
}
public void widgetSelected(SelectionEvent e)
{
name=aname;
namechoosed=true;
}
}
class TypeAction extends SelectionAdapter{
String atype;
public TypeAction(String atype)
{
super();
this.atype = atype;
}
public void widgetSelected(SelectionEvent e)
{
type=atype;
typechoosed=true;
}
}
class SizeAction extends SelectionAdapter{
String asize;
public SizeAction(String asize)
{
super();
this.asize = asize;
}
public void widgetSelected(SelectionEvent e)
{
size=asize;
sizechoosed=true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -