Java tutorial
/*---------------- FILE HEADER KALYPSO ------------------------------------------ * * This file is part of kalypso. * Copyright (C) 2004 by: * * Technical University Hamburg-Harburg (TUHH) * Institute of River and coastal engineering * Denickestrae 22 * 21073 Hamburg, Germany * http://www.tuhh.de/wb * * and * * Bjoernsen Consulting Engineers (BCE) * Maria Trost 3 * 56070 Koblenz, Germany * http://www.bjoernsen.de * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Contact: * * E-Mail: * belger@bjoernsen.de * schlienger@bjoernsen.de * v.doemming@tuhh.de * * ---------------------------------------------------------------------------*/ package org.kalypso.ui.editor.styleeditor.graphic; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.databinding.swt.ISWTObservableValue; import org.eclipse.jface.databinding.swt.SWTObservables; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Spinner; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; import org.kalypso.commons.databinding.IDataBinding; import org.kalypso.commons.databinding.forms.DatabindingForm; import org.kalypso.commons.databinding.validation.NumberNotNegativeValidator; import org.kalypso.contribs.eclipse.swt.layout.Layouts; import org.kalypso.ui.editor.styleeditor.MessageBundle; import org.kalypso.ui.editor.styleeditor.binding.IStyleInput; import org.kalypsodeegree.graphics.sld.Graphic; /** * @author Gernot Belger */ public class GraphicComposite extends Composite { private GraphicElementsTabViewer m_graphicTabViewer; private final IStyleInput<Graphic> m_input; private final IDataBinding m_binding; public GraphicComposite(final FormToolkit toolkit, final Composite parent, final IStyleInput<Graphic> input) { super(parent, SWT.NONE); m_input = input; toolkit.adapt(this); setLayout(new FillLayout()); final ScrolledForm form = toolkit.createScrolledForm(this); form.setExpandHorizontal(true); form.setExpandVertical(true); final Composite body = form.getBody(); GridLayoutFactory.fillDefaults().applyTo(body); m_binding = new DatabindingForm(form.getForm(), toolkit); final Control commonControls = createCommonControls(toolkit, body); commonControls.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); final Control tabControl = createTabViewer(toolkit, body); tabControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); } private Control createTabViewer(final FormToolkit toolkit, final Composite body) { m_graphicTabViewer = new GraphicElementsTabViewer(toolkit, body, m_input); return m_graphicTabViewer.getControl(); } // public IInputWithContext<Graphic> getInput( ) // { // return m_input; // } private Control createCommonControls(final FormToolkit toolkit, final Composite parent) { final Composite commonComposite = toolkit.createComposite(parent); final GridLayout commonLayout = new GridLayout(2, true); commonLayout.horizontalSpacing = 20; commonComposite.setLayout(commonLayout); createSizeControl(toolkit, commonComposite).setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); createRotationControl(toolkit, commonComposite) .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); // TODO: add control for graphics-opacity: as soon as Kalypso supports the Graphic#opacity // createOpacityControl( toolkit, commonComposite ); return commonComposite; } private Control createSizeControl(final FormToolkit toolkit, final Composite parent) { final Composite composite = toolkit.createComposite(parent); composite.setLayout(Layouts.createGridLayout(2)); toolkit.createLabel(composite, MessageBundle.STYLE_EDITOR_SIZE); final Spinner sizeSpinner = new Spinner(composite, SWT.BORDER); toolkit.adapt(sizeSpinner, true, true); sizeSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); final GraphicSizeValue graphicSizeField = new GraphicSizeValue(m_input); graphicSizeField.configureSpinner(sizeSpinner); final ISWTObservableValue target = SWTObservables.observeSelection(sizeSpinner); m_binding.bindValue(target, graphicSizeField, new NumberNotNegativeValidator(IStatus.WARNING)); return composite; } private Control createRotationControl(final FormToolkit toolkit, final Composite parent) { final Composite composite = toolkit.createComposite(parent); composite.setLayout(Layouts.createGridLayout(2)); toolkit.createLabel(composite, MessageBundle.STYLE_EDITOR_ROTATION); final Spinner rotationSpinner = new Spinner(composite, SWT.BORDER); toolkit.adapt(rotationSpinner, true, true); rotationSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); final GraphicRotationField graphicRotationField = new GraphicRotationField(m_input); graphicRotationField.configureSpinner(rotationSpinner); final ISWTObservableValue target = SWTObservables.observeSelection(rotationSpinner); m_binding.bindValue(target, graphicRotationField, new NumberNotNegativeValidator(IStatus.WARNING)); return composite; } public void updateControl() { m_binding.getBindingContext().updateTargets(); m_graphicTabViewer.refresh(); } }