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 java.awt.Point;
43  import java.awt.event.MouseEvent;
44  import java.util.List;
45  import java.util.logging.Logger;
46  
47  import javax.swing.JComponent;
48  
49  import org.openflexo.gina.model.FIBContainer;
50  import org.openflexo.gina.model.FIBModelObject;
51  import org.openflexo.logging.FlexoLogger;
52  
53  public class FIBSwingEditableContainerViewDelegate<M extends FIBContainer, J extends JComponent>
54  		extends FIBSwingEditableViewDelegate<M, J> {
55  
56  	static final Logger logger = FlexoLogger.getLogger(FIBSwingEditableContainerViewDelegate.class.getPackage().getName());
57  
58  	private List<PlaceHolder> placeholders;
59  	private List<OperatorDecorator> operatorDecorators = null;
60  
61  	public FIBSwingEditableContainerViewDelegate(FIBSwingEditableContainerView<M, J> view) {
62  		super(view);
63  	}
64  
65  	@Override
66  	public FIBSwingEditableContainerView<M, J> getView() {
67  		return (FIBSwingEditableContainerView<M, J>) super.getView();
68  	}
69  
70  	public List<PlaceHolder> getPlaceholders() {
71  		return placeholders;
72  	}
73  
74  	public void handlePlaceHolders(List<PlaceHolder> placeholders) {
75  		this.placeholders = placeholders;
76  		getView().getResultingJComponent().repaint();
77  	}
78  
79  	public void dismissPlaceHolders() {
80  		if (placeholders != null) {
81  			for (PlaceHolder ph : placeholders) {
82  				ph.setVisible(false);
83  			}
84  		}
85  		if (getView().getResultingJComponent() != null) {
86  			getView().getResultingJComponent().repaint();
87  		}
88  	}
89  
90  	public void deletePlaceHolders() {
91  		this.placeholders = null;
92  	}
93  
94  	public List<OperatorDecorator> getOperatorDecorators() {
95  		if (operatorDecorators == null) {
96  			operatorDecorators = getView().makeOperatorDecorators();
97  		}
98  		return operatorDecorators;
99  	}
100 
101 	public void updateOperatorDecorators() {
102 		operatorDecorators = null;
103 	}
104 
105 	private FIBModelObject lastSelectedObject = null;
106 
107 	@Override
108 	public FIBModelObject getLastSelectedObject() {
109 		if (lastSelectedObject != null) {
110 			return lastSelectedObject;
111 		}
112 		else {
113 			return getFIBComponent();
114 		}
115 	}
116 
117 	@Override
118 	public void mouseClicked(MouseEvent e) {
119 		OperatorDecorator d = getOperatorDecorator(e.getPoint());
120 		if (d != null) {
121 			lastSelectedObject = d.getOperator();
122 			getEditorController().setSelectedObject(d.getOperator());
123 			return;
124 		}
125 		else {
126 			lastSelectedObject = null;
127 		}
128 
129 		super.mouseClicked(e);
130 	}
131 
132 	public OperatorDecorator getOperatorDecorator(Point location) {
133 		if (operatorDecorators != null) {
134 			for (OperatorDecorator d : operatorDecorators) {
135 				//System.out.println(" > " + d.getOperator().getName() + " ? " + d.getBounds());
136 				if (d.getBounds().contains(location)) {
137 					return d;
138 				}
139 			}
140 		}
141 		return null;
142 	}
143 }