View Javadoc
1   /**
2    * 
3    * Copyright (c) 2013-2014, Openflexo
4    * Copyright (c) 2011-2012, AgileBirds
5    * 
6    * This file is part of Gina-swing-editor, a component of the software infrastructure 
7    * developed at Openflexo.
8    * 
9    * 
10   * Openflexo is dual-licensed under the European Union Public License (EUPL, either 
11   * version 1.1 of the License, or any later version ), which is available at 
12   * https://joinup.ec.europa.eu/software/page/eupl/licence-eupl
13   * and the GNU General Public License (GPL, either version 3 of the License, or any 
14   * later version), which is available at http://www.gnu.org/licenses/gpl.html .
15   * 
16   * You can redistribute it and/or modify under the terms of either of these licenses
17   * 
18   * If you choose to redistribute it and/or modify under the terms of the GNU GPL, you
19   * must include the following additional permission.
20   *
21   *          Additional permission under GNU GPL version 3 section 7
22   *
23   *          If you modify this Program, or any covered work, by linking or 
24   *          combining it with software containing parts covered by the terms 
25   *          of EPL 1.0, the licensors of this Program grant you additional permission
26   *          to convey the resulting work. * 
27   * 
28   * This software is distributed in the hope that it will be useful, but WITHOUT ANY 
29   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
30   * PARTICULAR PURPOSE. 
31   *
32   * See http://www.openflexo.org/license.html for details.
33   * 
34   * 
35   * Please contact Openflexo (openflexo-contacts@openflexo.org)
36   * or visit www.openflexo.org if you need additional information.
37   * 
38   */
39  
40  package org.openflexo.gina.swing.editor.view;
41  
42  import javax.swing.BorderFactory;
43  import javax.swing.JComponent;
44  import javax.swing.border.CompoundBorder;
45  
46  import org.openflexo.gina.model.FIBComponent;
47  import org.openflexo.gina.swing.editor.controller.FIBEditorController;
48  import org.openflexo.gina.swing.view.JFIBView;
49  import org.openflexo.gina.view.FIBView;
50  
51  /**
52   * Represent a {@link FIBView} with editing features
53   * 
54   * @author sylvain
55   *
56   * @param <M>
57   * @param <C>
58   */
59  public interface FIBSwingEditableView<M extends FIBComponent, J extends JComponent> extends JFIBView<M, J> {
60  
61  	public static final int OPERATOR_ICON_SPACE = 18;
62  
63  	public abstract FIBEditorController getEditorController();
64  
65  	// public abstract boolean hasValue();
66  
67  	public FIBSwingEditableViewDelegate<M, J> getDelegate();
68  
69  	/**
70  	 * Return JComponent on which drag and drop is to be applied
71  	 * 
72  	 * @return
73  	 */
74  	public JComponent getDraggableComponent();
75  
76  	/**
77  	 * Return boolean indicating that in EDIT mode, this view is the first view on an operator<br>
78  	 * Usefull to rendering features (give extra space to render operator icon)
79  	 * 
80  	 * @return
81  	 */
82  	public boolean isOperatorContentsStart();
83  
84  	/**
85  	 * Sets boolean indicating that in EDIT mode, this view is the first view on an operator<br>
86  	 * Usefull to rendering features (give extra space to render operator icon)
87  	 * 
88  	 * @param flag
89  	 */
90  	public void setOperatorContentsStart(boolean flag);
91  
92  	public static void updateOperatorContentsStart(FIBSwingEditableView<?, ?> view, boolean flag) {
93  		if (flag) {
94  			if (view.getResultingJComponent().getBorder() == null) {
95  				view.getResultingJComponent().setBorder(BorderFactory.createEmptyBorder(0, OPERATOR_ICON_SPACE, 0, 0));
96  			}
97  			else {
98  				view.getResultingJComponent().setBorder(BorderFactory.createCompoundBorder(
99  						BorderFactory.createEmptyBorder(0, OPERATOR_ICON_SPACE, 0, 0), view.getResultingJComponent().getBorder()));
100 			}
101 		}
102 		else {
103 			if (view.getResultingJComponent().getBorder() instanceof CompoundBorder) {
104 				view.getResultingJComponent().setBorder(((CompoundBorder) view.getResultingJComponent().getBorder()).getInsideBorder());
105 			}
106 			else {
107 				view.getResultingJComponent().setBorder(null);
108 			}
109 
110 		}
111 	}
112 
113 }