1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| public class CompositeButtonState extends Composite{
private Button buttonState = null;
private ProgressBar progressState = null;
private int state = -1;
public CompositeButtonState(Composite parent, int style) {
super(parent, style);
GridLayout grid = new GridLayout();
grid.numColumns = 1;
this.setLayout(grid);
this.setBackground(new Color(null, 0, 255, 255));
buttonState = new Button(this, SWT.PUSH);
buttonState.setSize(50, 50);
progressState = new ProgressBar(this, SWT.SMOOTH);
progressState.setMaximum(0);
progressState.setMaximum(100);
progressState.setSize(50, 50);
this.setState(0, 0);
}
public void addSelectionListener(SelectionListener listener){
buttonState.addSelectionListener(listener);
}
public int getState() {
return state;
}
public void setState(int state, int progress){
if(this.state != state){
switch(state){
case 0 : //wait start
buttonState.setImage(Activator.getDefault().getImageRegistry().get(Activator.ICON_WAIT_START));
buttonState.setText("");
buttonState.setVisible(true);
buttonState.setSize(50,50);
progressState.setVisible(false);
this.layout();
break;
case 1 : // progress
buttonState.setVisible(false);
progressState.setVisible(true);
progressState.setSize(50,50);
this.layout();
break;
case 2 : // abort
break;
case 3 : // finished
buttonState.setImage(Activator.getDefault().getImageRegistry().get(Activator.ICON_FINISHED));
buttonState.setVisible(true);
progressState.setVisible(false);
break;
}
this.state = state;
}
if(this.state == 1){
progressState.setSelection(progress);
}
}
} |
Partager