summaryrefslogtreecommitdiff
path: root/removed-code/Browser.java
diff options
context:
space:
mode:
authorguest <guest@f059d3a0-6783-47b7-97ff-1fe0bbf25129>2008-09-23 21:29:27 +0000
committerguest <guest@f059d3a0-6783-47b7-97ff-1fe0bbf25129>2008-09-23 21:29:27 +0000
commitd6fa96b4cd67cf4fa18b5b9b6739f9bc2494a9f4 (patch)
tree00aa9a27acb6b4c8d9868795a5295e9231f1eb20 /removed-code/Browser.java
initial import
git-svn-id: http://manut.eu/svn/yalp/trunk@1 f059d3a0-6783-47b7-97ff-1fe0bbf25129
Diffstat (limited to 'removed-code/Browser.java')
-rw-r--r--removed-code/Browser.java157
1 files changed, 157 insertions, 0 deletions
diff --git a/removed-code/Browser.java b/removed-code/Browser.java
new file mode 100644
index 0000000..daafa05
--- /dev/null
+++ b/removed-code/Browser.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2006 Manuel Traut and Volker Dahnke
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors: Manuel Traut and Volker Dahnke
+ */
+
+package YalpClients.SwtClient.GUI;
+
+import YalpClients.*;
+import YalpClients.SwtClient.*;
+
+import YalpInterfaces.*;
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+
+import java.util.LinkedList;
+
+/*
+ * Class Browser
+ *
+ * <em></em>
+ *
+ * @author Volker Dahnke / Manuel Traut
+ *
+ * @version 1 02-04-2006<br>
+ */
+public class Browser extends Composite{
+ private Composite parentComposite;
+ private Display display1;
+ private Shell shell;
+ private Model model;
+ private LinkedList<String> alreadyBrowsed;
+ private Tree tree;
+ private Button add;
+ private Button cancel;
+
+ Browser( Composite parent,
+ final Model model,
+ Display display,
+ Composite parentComposite,
+ int style )
+ {
+ super(parent, style);
+ this.parentComposite=parentComposite;
+ this.alreadyBrowsed = new LinkedList<String>();
+ this.model = model;
+ this.display1 = display;
+ this.shell = new Shell(this.display1,SWT.NONE);
+ this.setSize(300,400);
+ GridLayout gridLayout = new GridLayout();
+ this.shell.setLayout(gridLayout);
+ gridLayout.numColumns = 2;
+
+ GridData treeGrid = new GridData();
+ treeGrid.horizontalSpan = 2;
+ treeGrid.widthHint = 300;
+ treeGrid.heightHint = 400;
+ treeGrid.grabExcessHorizontalSpace = true;
+ treeGrid.grabExcessVerticalSpace = true;
+ treeGrid.horizontalAlignment = SWT.FILL;
+ treeGrid.verticalAlignment = SWT.FILL;
+
+ this.tree = new Tree(this.shell, SWT.SINGLE);
+ this.tree.setLayoutData(treeGrid);
+
+ TreeItem tmp;
+ for(YalpFile aFile : model.getDir("/")){
+ tmp = new TreeItem(this.tree, SWT.NULL);
+ tmp.setText(aFile.name);
+ if(aFile.isDir) tmp.setImage(new Image(display1, "folder.gif"));
+ else tmp.setImage(new Image(display1, "yalpV2_klein.gif"));
+ }
+
+ this.tree.addSelectionListener (
+ new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ String path = getPath();
+ if(!alreadyBrowsed.contains(path)){
+ alreadyBrowsed.add(path);
+ TreeItem tmp;
+ for(YalpFile aFile : model.getDir(path)){
+ tmp = new TreeItem(tree.getSelection()[0],SWT.NULL);
+ tmp.setText(aFile.name);
+ if(aFile.isDir) tmp.setImage(new Image(display1, "folder.gif"));
+ else tmp.setImage(new Image(display1, "yalpV2_klein.gif"));
+ tmp.getParentItem().setExpanded(true);
+ }
+ }
+ }
+ }
+ );
+
+ GridData buttonGrid1 = new GridData();
+ buttonGrid1.horizontalSpan = 1;
+
+ this.add = new Button(this.shell, SWT.PUSH);
+ this.add.setText("Indicate");
+ this.add.setLayoutData(buttonGrid1);
+ this.add.addSelectionListener(new SelectionAdapter(){
+ public void widgetSelected(SelectionEvent e){
+ model.addDir(getPath());
+ parentEnable(true);
+ shell.setVisible(false);
+ }
+ });
+
+ GridData buttonGrid2 = new GridData();
+ buttonGrid2.horizontalSpan = 1;
+ buttonGrid2.horizontalAlignment = SWT.END;
+
+ this.cancel = new Button(this.shell, SWT.PUSH);
+ this.cancel.setText("Cancel");
+ this.cancel.setLayoutData(buttonGrid2);
+ this.cancel.addSelectionListener(new SelectionAdapter(){
+ public void widgetSelected(SelectionEvent e){
+ parentEnable(true);
+ shell.setVisible(false);
+ }
+ });
+ }
+
+ public void show(){
+ parentEnable(false);
+ Point size=this.getSize();
+ Rectangle parentRec=((Shell)this.parentComposite).getBounds();
+ Rectangle thisRec=this.shell.computeTrim(parentRec.x+(parentRec.width/2)-(size.x/2),parentRec.y+(parentRec.height/2)-(size.y/2),size.x,size.y);
+ shell.setBounds(thisRec);
+ shell.open();
+ while(!shell.isDisposed()){
+ if(!this.display1.readAndDispatch()) this.display1.sleep();
+ }
+ this.display1.dispose();
+ }
+
+ private String getPath(){
+ TreeItem actualItem = tree.getSelection()[0];
+ String path = "/"+tree.getSelection()[0].getText();
+ while(actualItem.getParentItem() != null){
+ actualItem = actualItem.getParentItem();
+ path = "/" + actualItem.getText() + path;
+ }
+ return path;
+ }
+ private void parentEnable(boolean bool){
+ parentComposite.setEnabled(bool);
+ }
+}