From 5810f90913735936ef580fd78861b7b31835a6f4 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 18:52:08 +0000 Subject: + Main Window Template + Some GUI Stuff git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@16 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../gui/components/DataSourceSelectComposite.java | 159 +++++++++++++++++ .../at/asit/pdfover/gui/components/MainWindow.java | 192 +++++++++++++++++++++ .../gui/components/PositioningComposite.java | 63 +++++++ .../pdfover/gui/components/StateComposite.java | 32 ++++ 4 files changed, 446 insertions(+) create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/DataSourceSelectComposite.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/PositioningComposite.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/StateComposite.java (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/components') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/DataSourceSelectComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/DataSourceSelectComposite.java new file mode 100644 index 00000000..cffef8cc --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/DataSourceSelectComposite.java @@ -0,0 +1,159 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.components; + +// Imports +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.SWT; + +import at.asit.pdfover.gui.workflow.Workflow; + +/** + * + * + */ +public class DataSourceSelectComposite extends Composite implements StateComposite { + + /** + * SFL4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(DataSourceSelectComposite.class); + + private Workflow workflow; + + /** + * Create the composite. + * @param parent + * @param style + * @param flow + */ + public DataSourceSelectComposite(Composite parent, int style, Workflow flow) { + super(parent, style); + + this.workflow = flow; + + this.setLayout(new FormLayout()); + + Color back = new Color(Display.getCurrent(), 77, 190, 250); + + this.drop_area = new Composite(this, SWT.RESIZE | SWT.BORDER_DASH); + FormData fd_drop_area = new FormData(); + fd_drop_area.left = new FormAttachment(0, 0); + fd_drop_area.right = new FormAttachment(100, 0); + fd_drop_area.top = new FormAttachment(0, 0); + fd_drop_area.bottom = new FormAttachment(100, 0); + this.drop_area.setLayoutData(fd_drop_area); + this.drop_area.setLayout(new FormLayout()); + this.drop_area.setBackground(back); + + final Label lbl_drag = new Label(this.drop_area, SWT.NONE | SWT.RESIZE ); + FormData fd_lbl_drag = new FormData(); + fd_lbl_drag.left = new FormAttachment(5, 5); + fd_lbl_drag.right = new FormAttachment(100, -5); + fd_lbl_drag.top = new FormAttachment(5, 5); + fd_lbl_drag.bottom = new FormAttachment(55, -5); + lbl_drag.setLayoutData(fd_lbl_drag); + FontData[] fD = lbl_drag.getFont().getFontData(); + fD[0].setHeight(18); + lbl_drag.setFont( new Font(Display.getCurrent(),fD[0])); + lbl_drag.setText("Drag and Drop"); + lbl_drag.setAlignment(SWT.CENTER); + lbl_drag.setBackground(back); + + + Button btn_open = new Button(this.drop_area, SWT.NATIVE | SWT.RESIZE ); + btn_open.setText("Choose file ..."); + Point size = btn_open.computeSize(SWT.DEFAULT, SWT.DEFAULT); + FormData fd_btn_open = new FormData(); + fd_btn_open.left = new FormAttachment(100, size.x * -1 - 10); + fd_btn_open.right = new FormAttachment(100, -5); + fd_btn_open.top = new FormAttachment(100, size.y * -1 - 10); + fd_btn_open.bottom = new FormAttachment(100, -5); + btn_open.setLayoutData(fd_btn_open); + btn_open.setBackground(back); + + this.drop_area.pack(); + + /*Button btn = new Button(this, SWT.NATIVE); + btn.setBounds(50, 20, 100, 50); + btn.setText("Click Me"); + btn.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent arg0) { + DataSourceSelectComposite.this.setPress(true); + DataSourceSelectComposite.this.workflow.update(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + // TODO Auto-generated method stub + + } + });*/ + } + + private boolean press = false; + + private Composite drop_area; + + @Override + protected void checkSubclass() { + // Disable the check that prevents subclassing of SWT components + } + + /** + * @return the press + */ + public boolean isPress() { + return this.press; + } + + /** + * @param press the press to set + */ + public void setPress(boolean press) { + this.press = press; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.components.StateComposite#doLayout() + */ + @Override + public void doLayout() { + this.layout(true, true); + this.drop_area.layout(true, true); + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java new file mode 100644 index 00000000..704a2440 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java @@ -0,0 +1,192 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.components; + +// Imports +import javax.swing.GroupLayout; + +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormAttachment; + +/** + * The Main Window of PDFOver 4.0 + */ +public class MainWindow { + + /** + * SFL4J Logger instance + **/ + private static final Logger log = LoggerFactory.getLogger(MainWindow.class); + private Shell shell; + private CLabel lbl_status; + private Composite container; + private StackLayout stack; + + /** + * Set current status (may be removed in production release) + * @param value + */ + public void setStatus(String value) { + this.lbl_status.setText("[DEBUG]: Current workflow state: " + value); + } + + /** + * Sets top level composite for stack layout + * @param ctrl + */ + public void setTopControl(Control ctrl) { + log.debug("Top control: " + ctrl.toString()); + this.stack.topControl = ctrl; + this.container.layout(true, true); + this.shell.layout(true, true); + // Note: SWT only layouts children! No grandchildren! + if(ctrl instanceof StateComposite) { + ((StateComposite)ctrl).doLayout(); + } + } + + /** + * Gets the container composite + * @return + */ + public Composite getContainer() { + return this.container; + } + + /** + * Entrance point for swt designer + * @param args + */ + public static void main(String[] args) { + Display display = Display.getDefault(); + + MainWindow window = new MainWindow(); + + window.open(); + + window.getShell().open(); + window.getShell().layout(); + while (!window.getShell().isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + + /** + * Open the window. + * @wbp.parser.entryPoint + */ + public void open() { + createContents(); + } + + /** + * Create contents of the window. + */ + protected void createContents() { + this.shell = new Shell(); + getShell().setSize(450, 329); + getShell().setText("PDF OVER 4.0! :)"); + + getShell().setLayout(new FormLayout()); + + + + Composite composite = new Composite(getShell(), SWT.NONE); + FormData fd_composite = new FormData(); + fd_composite.left = new FormAttachment(0, 5); + fd_composite.right = new FormAttachment(100, -5); + fd_composite.top = new FormAttachment(0, 5); + fd_composite.bottom = new FormAttachment(0, 40); + composite.setLayoutData(fd_composite); + composite.setLayout(new FormLayout()); + + Button btn_config = new Button(composite, SWT.NONE); + FormData fd_config = new FormData(); + fd_config.left = new FormAttachment(0, 0); + fd_config.right = new FormAttachment(25, 0); + fd_config.top = new FormAttachment(0, 0); + fd_config.bottom = new FormAttachment(100, 0); + btn_config.setLayoutData(fd_config); + btn_config.setText("Config ..."); + + Button btn_open = new Button(composite, SWT.NONE); + FormData fd_open = new FormData(); + fd_open.left = new FormAttachment(25, 0); + fd_open.right = new FormAttachment(50, 0); + fd_open.top = new FormAttachment(0, 0); + fd_open.bottom = new FormAttachment(100, 0); + btn_open.setLayoutData(fd_open); + btn_open.setText("Open ..."); + + Button btn_position = new Button(composite, SWT.NONE); + FormData fd_position = new FormData(); + fd_position.left = new FormAttachment(50, 0); + fd_position.right = new FormAttachment(75, 0); + fd_position.top = new FormAttachment(0, 0); + fd_position.bottom = new FormAttachment(100, 0); + btn_position.setLayoutData(fd_position); + btn_position.setText("Positon ..."); + + Button btn_sign = new Button(composite, SWT.NONE); + FormData fd_sign = new FormData(); + fd_sign.left = new FormAttachment(75, 0); + fd_sign.right = new FormAttachment(100, 0); + fd_sign.top = new FormAttachment(0, 0); + fd_sign.bottom = new FormAttachment(100, 0); + btn_sign.setLayoutData(fd_sign); + btn_sign.setText("Sign ..."); + + this.container = new Composite(getShell(), SWT.BORDER | SWT.RESIZE); + FormData fd_composite_1 = new FormData(); + fd_composite_1.bottom = new FormAttachment(100, -25); + fd_composite_1.right = new FormAttachment(100, -5); + fd_composite_1.top = new FormAttachment(0, 45); + fd_composite_1.left = new FormAttachment(0, 5); + this.container.setLayoutData(fd_composite_1); + this.stack = new StackLayout(); + this.container.setLayout(this.stack); + + this.lbl_status = new CLabel(getShell(), SWT.NONE); + FormData fd_lblNewLabel = new FormData(); + fd_lblNewLabel.right = new FormAttachment(100, -5); + fd_lblNewLabel.bottom = new FormAttachment(100, -5); + fd_lblNewLabel.top = new FormAttachment(100, -20); + fd_lblNewLabel.left = new FormAttachment(0, 5); + this.lbl_status.setLayoutData(fd_lblNewLabel); + this.lbl_status.setText("New Label"); + + } + + /** + * @return the shell + */ + public Shell getShell() { + return this.shell; + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/PositioningComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/PositioningComposite.java new file mode 100644 index 00000000..79cbbc68 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/PositioningComposite.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.components; + +// Imports +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.gui.workflow.Workflow; + +/** + * + * + */ +public class PositioningComposite extends Composite implements StateComposite { + + /** + * SFL4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(PositioningComposite.class); + + /** + * Create the composite. + * @param parent + * @param style + */ + public PositioningComposite(Composite parent, int style, Workflow workflow) { + super(parent, style); + Label test = new Label(this, SWT.NATIVE); + test.setBounds(10, 20, 100, 50); + test.setText("POSITIONING ----"); + } + + @Override + protected void checkSubclass() { + // Disable the check that prevents subclassing of SWT components + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.components.StateComposite#doLayout() + */ + @Override + public void doLayout() { + this.layout(true, true); + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/StateComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/StateComposite.java new file mode 100644 index 00000000..0bfd7b87 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/StateComposite.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.components; + +// Imports +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Composite interface for workflow state gui implementations + */ +public interface StateComposite { + + /** + * Performs layout for all children in composite + * (SWT layout(...) only layouts children no grandchildren!) + */ + public void doLayout(); +} -- cgit v1.2.3