下面列出了org.eclipse.swt.widgets.Combo#pack ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected Control createComboParameterControl(final Composite comp) {
possibleValues = new ArrayList<T>(param.getAmongValue(getScope()));
final String[] valuesAsString = new String[possibleValues.size()];
for (int i = 0; i < possibleValues.size(); i++) {
// if ( param.isLabel() ) {
// valuesAsString[i] = possibleValues.get(i).toString();
// } else {
if (getExpectedType() == Types.STRING) {
valuesAsString[i] = StringUtils.toJavaString(StringUtils.toGaml(possibleValues.get(i), false));
} else {
valuesAsString[i] = StringUtils.toGaml(possibleValues.get(i), false);
// }
}
}
combo = new Combo(comp, SWT.READ_ONLY | SWT.DROP_DOWN);
combo.setForeground(IGamaColors.BLACK.color()); // force text color, see #2601
combo.setItems(valuesAsString);
combo.select(possibleValues.indexOf(getOriginalValue()));
// combo.addModifyListener(new ModifyListener() {
//
// @Override
// public void modifyText(final ModifyEvent me) {
// modifyValue(possibleValues.get(combo.getSelectionIndex()));
// }
// });
combo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent me) {
modifyValue(possibleValues.get(combo.getSelectionIndex()));
}
});
final GridData d = new GridData(SWT.LEFT, SWT.CENTER, false, true);
d.minimumWidth = 48;
// d.widthHint = 100; // SWT.DEFAULT
combo.setLayoutData(d);
combo.pack();
return combo;
}
private void installFactors(Combo combo) {
for (String text : FACTORS) {
combo.add(text);
}
combo.pack();
}
public CompositeTableRow(CompositeEntry entry,
Table container,
CompositingControl control,
boolean disableOp) {
this.name = entry.getName();
TableItem newItem = new TableItem(container,SWT.DOUBLE_BUFFERED);
TableEditor editor0 = new TableEditor(container);
editor0.horizontalAlignment = SWT.CENTER;
editor0.grabHorizontal = true;
chkActive = new Button(container,SWT.CHECK);
chkActive.setSelection(true);
chkActive.addSelectionListener(control);
editor0.setEditor(chkActive,newItem,0);
TableEditor editor = new TableEditor(container);
editor.horizontalAlignment = SWT.CENTER;
editor.grabHorizontal = true;
panel = new Composite(container, SWT.NONE);
panel.setLayout(new GridLayout(2,true));
slider = new Slider(panel,SWT.HORIZONTAL|SWT.NO_TRIM);
slider.setValues((int)(entry.getWeight()*100), 0, 104, 5, 1, 5);
slider.addSelectionListener(this);
slider.addSelectionListener(control);
spinner = new Spinner(panel,SWT.DOUBLE_BUFFERED);
spinner.setMinimum(0);
spinner.setMaximum(100);
spinner.setSelection((int)(entry.getWeight()*100));
spinner.addSelectionListener(control);
spinner.addSelectionListener(this);
panel.pack();
editor.setEditor(panel,newItem,2);
newItem.setText(1,name);
TableEditor editor2 = new TableEditor(container);
editor2.horizontalAlignment = SWT.CENTER;
editor2.grabHorizontal = true;
editor2.grabVertical = true;
op = new Combo(container,SWT.NONE);
op.add("ADD");
op.add("SUBTRACT");
op.add("MULTIPLY");
op.add("DIVIDE");
op.add("MINIMUM");
op.add("MAXIMUM");
op.select(convertOperationToInt(entry.getOperation()));
op.pack();
op.addSelectionListener(control);
op.setEnabled(!disableOp);
editor2.setEditor(op,newItem,3);
TableEditor editor3 = new TableEditor(container);
editor3.horizontalAlignment = SWT.CENTER;
editor3.grabHorizontal = true;
editor3.grabVertical = true;
chkRed = new Button(container,SWT.CHECK);
chkRed.setSelection(true);
chkRed.pack();
chkRed.addSelectionListener(control);
editor3.setEditor(chkRed,newItem,4);
TableEditor editor4 = new TableEditor(container);
editor4.horizontalAlignment = SWT.CENTER;
editor4.grabHorizontal = true;
editor4.grabVertical = true;
chkGreen = new Button(container,SWT.CHECK);
chkGreen.pack();
chkGreen.setSelection(true);
chkGreen.addSelectionListener(control);
editor4.setEditor(chkGreen,newItem,5);
TableEditor editor5 = new TableEditor(container);
editor5.horizontalAlignment = SWT.CENTER;
editor5.grabHorizontal = true;
editor5.grabVertical = true;
chkBlue = new Button(container,SWT.CHECK);
chkBlue.pack();
chkBlue.setSelection(true);
chkBlue.addSelectionListener(control);
editor5.setEditor(chkBlue,newItem,6);
}
/**
* Setups gateway SWT controls by populating a gateway combobox and configuring an information
* Label and the enabling checkbox.
*
* @param combo {@link Combo} selector to populate with discovered gateways
* @param info {@link Label} displaying status information of the discovery
* @param checkbox {@link Button} checkbox to enable/disable UPnP support
*/
private void populateGatewaySelectionControls(
List<GatewayDevice> gateways, final Combo combo, final Label info, final Button checkbox) {
combo.setEnabled(false);
checkbox.setEnabled(false);
combo.removeAll();
// if no devices are found, return now - nothing to populate
if (gateways == null || gateways.isEmpty()) {
info.setText(Messages.UPnPUIUtils_no_gateway);
info.getParent().pack();
return;
}
this.gateways = new ArrayList<GatewayDevice>();
// insert found gateways into combobox
for (GatewayDevice gw : gateways) {
try {
String name = gw.getFriendlyName();
if (!gw.isConnected()) name += Messages.UPnPUIUtils_disconnected;
combo.add(name);
this.gateways.add(gw);
} catch (Exception e) {
log.debug("Error updating UPnP selector:" + e.getMessage()); // $NON-NLS-1$
// ignore faulty gateway
}
}
// if valid gateway found, show info and enable
if (combo.getItemCount() > 0) {
checkbox.setEnabled(true);
combo.setEnabled(true);
combo.select(0);
combo.pack();
info.setVisible(false);
} else {
info.setText(Messages.UPnPUIUtils_no_valid_gateway);
}
info.getParent().pack();
}
private void addToolBar() {
try {
toolbar = (XulToolbar) getXulDomContainer().getDocumentRoot().getElementById( "nav-toolbar" );
ToolBar swtToolbar = (ToolBar) toolbar.getManagedObject();
swtToolbar.setBackground( GUIResource.getInstance().getColorDemoGray() );
swtToolbar.pack();
// Added 1/11/2016 to implement dropdown option for "Run"
ToolItem runItem = new ToolItem( swtToolbar, SWT.DROP_DOWN, 0 );
runItem.setImage( GUIResource.getInstance().getImage( "ui/images/run.svg" ) );
runItem.setToolTipText( BaseMessages.getString( PKG, "Spoon.Tooltip.RunTranformation" ) );
runItem.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
if ( e.detail == SWT.DROP_DOWN ) {
Menu menu = new Menu( shell, SWT.POP_UP );
MenuItem item1 = new MenuItem( menu, SWT.PUSH );
item1.setText( BaseMessages.getString( PKG, "Spoon.Run.Run" ) );
item1.setAccelerator( SWT.F9 );
item1.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e1 ) {
runJob();
}
} );
MenuItem item2 = new MenuItem( menu, SWT.PUSH );
item2.setText( BaseMessages.getString( PKG, "Spoon.Run.RunOptions" ) );
item2.setAccelerator( SWT.F8 );
item2.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e2 ) {
runOptionsJob();
}
} );
menu.setLocation( shell.getDisplay().map( mainComposite.getParent(), null, mainComposite.getLocation() ) );
menu.setVisible( true );
} else {
runJob();
}
}
} );
// Hack alert : more XUL limitations...
//
ToolItem sep = new ToolItem( swtToolbar, SWT.SEPARATOR );
zoomLabel = new Combo( swtToolbar, SWT.DROP_DOWN );
zoomLabel.setItems( TransPainter.magnificationDescriptions );
zoomLabel.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent arg0 ) {
readMagnification();
}
} );
zoomLabel.addKeyListener( new KeyAdapter() {
public void keyPressed( KeyEvent event ) {
if ( event.character == SWT.CR ) {
readMagnification();
}
}
} );
setZoomLabel();
zoomLabel.pack();
sep.setWidth( 80 );
sep.setControl( zoomLabel );
swtToolbar.pack();
} catch ( Throwable t ) {
log.logError( Const.getStackTracker( t ) );
new ErrorDialog( shell,
BaseMessages.getString( PKG, "Spoon.Exception.ErrorReadingXULFile.Title" ),
BaseMessages.getString( PKG, "Spoon.Exception.ErrorReadingXULFile.Message", XUL_FILE_JOB_GRAPH ),
new Exception( t ) );
}
}