Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.custom.SashForm;
- import org.eclipse.swt.events.SelectionEvent;
- import org.eclipse.swt.events.SelectionListener;
- import org.eclipse.swt.graphics.Image;
- import org.eclipse.swt.layout.FillLayout;
- import org.eclipse.swt.layout.GridData;
- import org.eclipse.swt.layout.GridLayout;
- import org.eclipse.swt.widgets.Button;
- import org.eclipse.swt.widgets.Composite;
- import org.eclipse.swt.widgets.DirectoryDialog;
- import org.eclipse.swt.widgets.Display;
- import org.eclipse.swt.widgets.ExpandBar;
- import org.eclipse.swt.widgets.ExpandItem;
- import org.eclipse.swt.widgets.FileDialog;
- import org.eclipse.swt.widgets.Shell;
- import org.eclipse.swt.widgets.TabFolder;
- import org.eclipse.swt.widgets.Text;
- /**
- * A minimal program that draws with JOGL in an SWT Composite.
- *
- * @author Wade Walker
- */
- public class OneTriangleSWT {
- private Display display;
- private Shell shell;
- // file explorer
- private FileDialog dialog;
- private DirectoryDialog folderDialog;
- private Text txtPath;
- private ExpandBar blocks;
- private MeshList meshes;
- // private OpenGLCanvas3DJOGL D3Display;
- // private OpenGLCanvas2DJOGL D2Display;
- private TabFolder tabs;
- public OneTriangleSWT() {
- display = new Display();
- shell = new Shell( display );
- shell.setText( "OneTriangle SWT" );
- shell.setLayout( new FillLayout() );
- shell.setSize( 640, 480 );
- SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL);
- final Composite composite_1 = new Composite(sashForm, SWT.BORDER);
- // GridData gd_composite_1 = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
- // gd_composite_1.widthHint = 150;
- // composite_1.setLayoutData(gd_composite_1);
- GridLayout gl_composite_1 = new GridLayout(4, true);
- gl_composite_1.marginRight = 1;
- gl_composite_1.marginLeft = 1;
- gl_composite_1.verticalSpacing = 1;
- gl_composite_1.marginWidth = 0;
- gl_composite_1.marginHeight = 1;
- gl_composite_1.horizontalSpacing = 1;
- composite_1.setLayout(gl_composite_1);
- Button btnDir = new Button(composite_1, SWT.NONE);
- btnDir.setImage(new Image(display, getClass().getResourceAsStream("folder-open.png")));
- btnDir.addSelectionListener(new SelectionListener() {
- @Override
- public void widgetSelected(SelectionEvent arg0) {
- folderDialog = new DirectoryDialog(shell);
- folderDialog.setFilterPath(txtPath.getText());
- String path = folderDialog.open();
- if (path != null)
- txtPath.setText(path);
- }
- @Override
- public void widgetDefaultSelected(SelectionEvent arg0) {}
- });
- Button btnPlus = new Button(composite_1, SWT.NONE);
- btnPlus.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 3, 1));
- btnPlus.setImage(new Image(display, getClass().getResourceAsStream("plus.png")));
- btnPlus.addSelectionListener(new SelectionListener() {
- @Override
- public void widgetSelected(SelectionEvent arg0) {
- dialog = new FileDialog(shell);
- dialog.setFilterPath(txtPath.getText());
- String pathToMesh = dialog.open();
- if (pathToMesh != null) {
- try {
- Bdy bdy = new Bdy(pathToMesh);
- ExpandItem newItem = new ExpandItem(blocks, SWT.NONE);
- newItem.setExpanded(true);
- newItem.setText(dialog.getFileName().substring(0, dialog.getFileName().length()-4));
- BdyPanel bdyPanel = new BdyPanel(blocks, SWT.NONE, bdy);
- newItem.setControl(bdyPanel);
- newItem.setHeight(bdyPanel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
- meshes.add(bdy);
- // updateView();
- // bdyPanel.addObserver(JMeshingToolNew.this);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- @Override
- public void widgetDefaultSelected(SelectionEvent arg0) {}
- });
- txtPath = new Text(composite_1, SWT.BORDER);
- // txtPath.setText(System.getProperty("user.dir"));
- // txtPath.setText("test");
- txtPath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));
- blocks = new ExpandBar(composite_1, SWT.NONE);
- blocks.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));
- blocks.setSize(170, 484);
- /*
- */
- Composite composite = new Triangle( sashForm, SWT.NONE );
- sashForm.setWeights(new int[] {1,3});
- shell.open();
- while( !shell.isDisposed() ) {
- if( !display.readAndDispatch() )
- display.sleep();
- }
- composite.dispose();
- display.dispose();
- }
- public static void main( String [] args ) {
- new OneTriangleSWT();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement