下面列出了org.eclipse.swt.widgets.ProgressBar#setLayoutData ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ProgressController(Composite parent, int style) {
this.parent = parent;
display = Display.getCurrent();
progressTitle = new Label(parent, SWT.NONE);
progressTitle.setText("Progress");
GridData titleData = new GridData();
titleData.horizontalAlignment = GridData.BEGINNING;
titleData.grabExcessHorizontalSpace = true;
progressTitle.setLayoutData(titleData);
progressValue = new Label(parent, SWT.NONE);
progressValue.setText("0%");
GridData valueData = new GridData();
valueData.horizontalAlignment = GridData.END;
progressValue.setLayoutData(valueData);
progressBar = new ProgressBar(parent, style);
GridData progressData = new GridData();
progressData.horizontalAlignment = GridData.FILL;
progressData.horizontalSpan = 2;
progressData.grabExcessHorizontalSpace = true;
progressBar.setLayoutData(progressData);
}
/**
* Create contents of the dialog.
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
container.setLayout(new GridLayout(1, false));
completedInfo = new Label(container, SWT.NONE);
completedInfo.setAlignment(SWT.CENTER);
GridData gd_completedInfo = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
gd_completedInfo.minimumWidth = 250;
completedInfo.setLayoutData(gd_completedInfo);
completedInfo.setSize(250, 40);
completedInfo.setText("Processing Data ...");
new Label(container, SWT.NONE);
progressBar = new ProgressBar(container, SWT.INDETERMINATE);
GridData gd_progressBar = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
gd_progressBar.minimumWidth = 250;
progressBar.setLayoutData(gd_progressBar);
progressBar.setBounds(10, 23, 400, 17);
progressBar.setSelection(100);
return container;
}
private void createBarComp(Composite parent) {
Composite barComp = new Composite(parent, SWT.NONE);
GridLayout barLayout = new GridLayout();
barLayout.marginTop = 10;
barComp.setLayout(barLayout);
barComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
label4 = new Label(barComp, SWT.NONE);
label4.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
bar = new ProgressBar(barComp, SWT.NONE);
bar.setMaximum(10);
bar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
setVisible(false);
}
public void fill(Composite parent) {
super.fill(parent);
Composite container = new Composite(parent, SWT.NONE);
GridLayout gl = new GridLayout(2, false);
gl.marginWidth = 5;
gl.marginHeight = 3;
container.setLayout(gl);
progressBar = new ProgressBar(container, SWT.SMOOTH);
GridData gdPprogressBar = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gdPprogressBar.heightHint = 16;
gdPprogressBar.widthHint = 130;
progressBar.setLayoutData(gdPprogressBar);
progressBar.setMinimum(0); // 最小值
progressBar.setMaximum(100);// 最大值
progressBar.setSelection(progressValue);
progressBar.setToolTipText(defaultMessage);
label = new Label(container, SWT.None);
label.setText(progressValue + "%");
StatusLineLayoutData data = new StatusLineLayoutData();
container.setLayoutData(data);
}
private void createBarComp(Composite parent) {
Composite barComp = new Composite(parent, SWT.NONE);
GridLayout barLayout = new GridLayout();
barLayout.marginTop = 10;
barComp.setLayout(barLayout);
barComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
label4 = new Label(barComp, SWT.NONE);
label4.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
bar = new ProgressBar(barComp, SWT.NONE);
bar.setMaximum(10);
bar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
setVisible(false);
}
/**
* Create a progress bar
*/
private void createProgressBar() {
progressBar = new ProgressBar(composite, SWT.SMOOTH | SWT.HORIZONTAL);
progressBar.setMinimum(progressBarMinimumValue);
progressBar.setMaximum(progressBarMaximumValue);
progressBar.setSelection(progressBarValue);
final GridData gd = new GridData(GridData.FILL, GridData.FILL, true, false, 1, 1);
progressBar.setLayoutData(gd);
}
@Override
protected Control createDialogArea(Composite parent) {
setTitleImage(null);
setTitle("Metric informations");
Composite area = (Composite) super.createDialogArea(parent);
area.setLayout(new GridLayout(1, false));
Composite textContainer = new Composite(area, SWT.NONE);
textContainer.setLayout(new FillLayout(SWT.HORIZONTAL));
textContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
table = new Table(textContainer, SWT.BORDER | SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn tblclmnNewColumn = new TableColumn(table, SWT.NONE);
tblclmnNewColumn.setWidth(300);
tblclmnNewColumn.setText("ID");
TableColumn tblclmnNewColumn_1 = new TableColumn(table, SWT.NONE);
tblclmnNewColumn_1.setWidth(100);
tblclmnNewColumn_1.setText("Value");
TableColumn tblclmnNewColumn_2 = new TableColumn(table, SWT.NONE);
tblclmnNewColumn_2.setWidth(300);
tblclmnNewColumn_2.setText("Description");
progressBar = new ProgressBar(area, SWT.SMOOTH);
progressBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
refreshMetrics();
return area;
}
/**
* Create contents of the dialog.
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
container.setLayout(new GridLayout(1, false));
completedInfo = new Label(container, SWT.NONE);
completedInfo.setAlignment(SWT.CENTER);
GridData gd_completedInfo = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
gd_completedInfo.minimumWidth = 250;
completedInfo.setLayoutData(gd_completedInfo);
completedInfo.setSize(250, 40);
completedInfo.setText("Processing Data ...");
new Label(container, SWT.NONE);
progressBar = new ProgressBar(container, SWT.SMOOTH);
GridData gd_progressBar = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
gd_progressBar.minimumWidth = 250;
progressBar.setLayoutData(gd_progressBar);
progressBar.setBounds(10, 23, 400, 17);
taskLabel = new Label(container, SWT.NONE);
taskLabel.setAlignment(SWT.CENTER);
GridData gd_taskLabel = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
gd_taskLabel.heightHint = 15;
gd_taskLabel.minimumWidth = 250;
taskLabel.setLayoutData(gd_taskLabel);
taskLabel.setSize(250, 40);
return container;
}
public ProgressModal(Shell parent, String title) {
display = Display.getDefault();
yuneImage = new Image(display, Main.class.getClassLoader().getResourceAsStream("YuneIcon_100x100.png"));
dialogShell = new Shell(parent, SWT.PRIMARY_MODAL | SWT.DIALOG_TRIM);
dialogShell.setText(title);
dialogShell.setImage(yuneImage);
progressBar = new ProgressBar(dialogShell, SWT.SMOOTH);
FormLayout mainLayout = new FormLayout();
mainLayout.marginWidth = 5;
mainLayout.marginHeight = 5;
dialogShell.setLayout(mainLayout);
imageLabel = new Label(dialogShell, SWT.NONE);
imageLabel.setImage(yuneImage);
FormData imageData = new FormData(100, 100);
imageData.left = new FormAttachment(0, 10);
imageData.top = new FormAttachment(0, 10);
imageData.bottom = new FormAttachment(100, -10);
imageLabel.setLayoutData(imageData);
FormData progressData = new FormData(300, 20);
progressData.left = new FormAttachment(imageLabel, 10);
progressData.bottom = new FormAttachment(imageLabel, -50, SWT.CENTER);
progressData.right = new FormAttachment(100, -10);
progressBar.setLayoutData(progressData);
statusLabel = new Label(dialogShell, SWT.NONE);
FormData statusData = new FormData();
statusData.left = new FormAttachment(progressBar, 0, SWT.LEFT);
statusData.top = new FormAttachment(progressBar, 5);
statusData.right = new FormAttachment(100, -10);
statusLabel.setLayoutData(statusData);
dialogShell.layout();
final Point newSize = dialogShell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
dialogShell.setSize(newSize);
Rectangle parentBounds = parent.getBounds();
Rectangle dialogBounds = dialogShell.getBounds();
dialogShell.setLocation(parentBounds.x + (parentBounds.width - dialogBounds.width) / 2, parentBounds.y + (parentBounds.height - dialogBounds.height) / 2);
}
@Override
protected Control createContents(final Composite parent) {
final Color bgColor = SWTResourceManager.getColor(SWT.COLOR_WHITE);
final Composite frame = new Composite(parent, SWT.NONE);
final FormData titleData = new FormData();
final FormData statusData = new FormData();
final FormLayout layout = new FormLayout();
final Label titleLabel = new Label(frame, SWT.NONE);
final Label statusLabel = new Label(frame, SWT.NONE);
final ProgressBar bar = new ProgressBar(frame, SWT.NONE);
final FormData barData = new FormData();
bar.setMaximum(100);
titleLabel.setText(Version.getApplicationName() + " " + Version.getVersion() + "\n" + Version.getStage() + "\n(C) " + Version.getDevelopmentLead()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
titleLabel.setBackground(bgColor);
bar.setBackground(bgColor);
statusLabel.setBackground(bgColor);
frame.setLayout(layout);
frame.setBackgroundImage(ResourceManager.getImage("imgSplash.png")); //$NON-NLS-1$
barData.left = new FormAttachment(15, 5);
barData.right = new FormAttachment(100, -5);
barData.bottom = new FormAttachment(100, -5);
bar.setLayoutData(barData);
titleData.left = new FormAttachment(45, 5);
titleData.right = new FormAttachment(100, 0);
titleData.top = new FormAttachment(50, 0);
titleLabel.setLayoutData(titleData);
statusData.left = new FormAttachment(15, 5);
statusData.right = new FormAttachment(100, 0);
statusData.top = new FormAttachment(80, 0);
statusLabel.setLayoutData(statusData);
this.bar = bar;
this.label = statusLabel;
return frame;
}
public void setViewer( IViewer viewer )
{
this.viewer = viewer;
if ( !( viewer instanceof AbstractViewer ) )
{
return;
}
Composite viewerUI = (Composite) ( (SWTAbstractViewer) viewer ).getUI( );
if ( viewerUI == null )
{
return;
}
pane = new Composite( viewerUI, SWT.NONE );
pane.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_FILL ) );
RowLayout rowLayout = new RowLayout( );
rowLayout.type = SWT.HORIZONTAL;
rowLayout.spacing = 5;
pane.setLayout( rowLayout );
for ( Iterator iter = buttons.iterator( ); iter.hasNext( ); )
{
ButtonInfo buttonInfo = (ButtonInfo) iter.next( );
Button button = new Button( pane, SWT.PUSH );
button.setText( buttonInfo.text );
button.setToolTipText( buttonInfo.toolTip );
if ( buttonInfo.selectionListener != null )
{
button.addSelectionListener( buttonInfo.selectionListener );
}
}
GridData gd = new GridData( GridData.END, GridData.CENTER, false, false );
gd.heightHint = 10;
gd.widthHint = 100;
progressBar = new ProgressBar( viewerUI, SWT.INDETERMINATE );
progressBar.setLayoutData( gd );
setBusy( true );
}