Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. import org.eclipse.swt.SWT;
  2. import org.eclipse.swt.custom.SashForm;
  3. import org.eclipse.swt.events.SelectionEvent;
  4. import org.eclipse.swt.events.SelectionListener;
  5. import org.eclipse.swt.graphics.Image;
  6. import org.eclipse.swt.layout.FillLayout;
  7. import org.eclipse.swt.layout.GridData;
  8. import org.eclipse.swt.layout.GridLayout;
  9. import org.eclipse.swt.widgets.Button;
  10. import org.eclipse.swt.widgets.Composite;
  11. import org.eclipse.swt.widgets.DirectoryDialog;
  12. import org.eclipse.swt.widgets.Display;
  13. import org.eclipse.swt.widgets.ExpandBar;
  14. import org.eclipse.swt.widgets.ExpandItem;
  15. import org.eclipse.swt.widgets.FileDialog;
  16. import org.eclipse.swt.widgets.Shell;
  17. import org.eclipse.swt.widgets.TabFolder;
  18. import org.eclipse.swt.widgets.Text;
  19.  
  20. /**
  21. * A minimal program that draws with JOGL in an SWT Composite.
  22. *
  23. * @author Wade Walker
  24. */
  25. public class OneTriangleSWT {
  26.  
  27. private Display display;
  28. private Shell shell;
  29. // file explorer
  30. private FileDialog dialog;
  31. private DirectoryDialog folderDialog;
  32. private Text txtPath;
  33. private ExpandBar blocks;
  34. private MeshList meshes;
  35. // private OpenGLCanvas3DJOGL D3Display;
  36. // private OpenGLCanvas2DJOGL D2Display;
  37. private TabFolder tabs;
  38.  
  39. public OneTriangleSWT() {
  40. display = new Display();
  41. shell = new Shell( display );
  42. shell.setText( "OneTriangle SWT" );
  43. shell.setLayout( new FillLayout() );
  44. shell.setSize( 640, 480 );
  45.  
  46. SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL);
  47.  
  48. final Composite composite_1 = new Composite(sashForm, SWT.BORDER);
  49. // GridData gd_composite_1 = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
  50. // gd_composite_1.widthHint = 150;
  51. // composite_1.setLayoutData(gd_composite_1);
  52. GridLayout gl_composite_1 = new GridLayout(4, true);
  53. gl_composite_1.marginRight = 1;
  54. gl_composite_1.marginLeft = 1;
  55. gl_composite_1.verticalSpacing = 1;
  56. gl_composite_1.marginWidth = 0;
  57. gl_composite_1.marginHeight = 1;
  58. gl_composite_1.horizontalSpacing = 1;
  59. composite_1.setLayout(gl_composite_1);
  60. Button btnDir = new Button(composite_1, SWT.NONE);
  61. btnDir.setImage(new Image(display, getClass().getResourceAsStream("folder-open.png")));
  62. btnDir.addSelectionListener(new SelectionListener() {
  63.  
  64. @Override
  65. public void widgetSelected(SelectionEvent arg0) {
  66. folderDialog = new DirectoryDialog(shell);
  67. folderDialog.setFilterPath(txtPath.getText());
  68. String path = folderDialog.open();
  69. if (path != null)
  70. txtPath.setText(path);
  71. }
  72.  
  73. @Override
  74. public void widgetDefaultSelected(SelectionEvent arg0) {}
  75.  
  76. });
  77.  
  78. Button btnPlus = new Button(composite_1, SWT.NONE);
  79. btnPlus.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 3, 1));
  80. btnPlus.setImage(new Image(display, getClass().getResourceAsStream("plus.png")));
  81. btnPlus.addSelectionListener(new SelectionListener() {
  82.  
  83. @Override
  84. public void widgetSelected(SelectionEvent arg0) {
  85. dialog = new FileDialog(shell);
  86. dialog.setFilterPath(txtPath.getText());
  87. String pathToMesh = dialog.open();
  88. if (pathToMesh != null) {
  89. try {
  90. Bdy bdy = new Bdy(pathToMesh);
  91.  
  92. ExpandItem newItem = new ExpandItem(blocks, SWT.NONE);
  93. newItem.setExpanded(true);
  94. newItem.setText(dialog.getFileName().substring(0, dialog.getFileName().length()-4));
  95.  
  96. BdyPanel bdyPanel = new BdyPanel(blocks, SWT.NONE, bdy);
  97. newItem.setControl(bdyPanel);
  98. newItem.setHeight(bdyPanel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
  99. meshes.add(bdy);
  100. // updateView();
  101. // bdyPanel.addObserver(JMeshingToolNew.this);
  102. } catch (Exception e) {
  103. // TODO Auto-generated catch block
  104. e.printStackTrace();
  105. }
  106. }
  107. }
  108.  
  109. @Override
  110. public void widgetDefaultSelected(SelectionEvent arg0) {}
  111. });
  112.  
  113. txtPath = new Text(composite_1, SWT.BORDER);
  114. // txtPath.setText(System.getProperty("user.dir"));
  115. // txtPath.setText("test");
  116. txtPath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));
  117.  
  118. blocks = new ExpandBar(composite_1, SWT.NONE);
  119. blocks.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));
  120. blocks.setSize(170, 484);
  121. /*
  122. */
  123. Composite composite = new Triangle( sashForm, SWT.NONE );
  124.  
  125. sashForm.setWeights(new int[] {1,3});
  126.  
  127. shell.open();
  128.  
  129. while( !shell.isDisposed() ) {
  130. if( !display.readAndDispatch() )
  131. display.sleep();
  132. }
  133.  
  134. composite.dispose();
  135. display.dispose();
  136. }
  137.  
  138. public static void main( String [] args ) {
  139. new OneTriangleSWT();
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement