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.palette;
41  
42  import java.util.ArrayList;
43  import java.util.List;
44  import java.util.logging.Logger;
45  
46  import javax.swing.Icon;
47  import javax.swing.ImageIcon;
48  import javax.swing.JTabbedPane;
49  
50  import org.openflexo.gina.swing.editor.FIBEditor;
51  import org.openflexo.gina.swing.editor.controller.FIBEditorController;
52  import org.openflexo.icon.ImageIconResource;
53  import org.openflexo.logging.FlexoLogger;
54  import org.openflexo.rm.Resource;
55  import org.openflexo.rm.ResourceLocator;
56  
57  public class FIBEditorPalettes extends JTabbedPane {
58  
59  	static final Logger logger = FlexoLogger.getLogger(FIBEditor.class.getPackage().getName());
60  
61  	private FIBEditorController editorController;
62  
63  	private List<FIBEditorPalette> palettes;
64  
65  	public FIBEditorPalettes() {
66  		super();
67  
68  		palettes = new ArrayList<>();
69  
70  		Resource[] paletteDirs = new Resource[4];
71  		Object[] paletteData = new Object[4];
72  
73  		paletteDirs[0] = ResourceLocator.locateResource("FIBEditorPalettes/Panels");
74  		paletteData[0] = new WidgetsPaletteData();
75  
76  		paletteDirs[1] = ResourceLocator.locateResource("FIBEditorPalettes/Widgets");
77  		paletteData[1] = new WidgetsPaletteData();
78  
79  		paletteDirs[2] = ResourceLocator.locateResource("FIBEditorPalettes/Advanced");
80  		paletteData[2] = new AdvancedPaletteData();
81  
82  		paletteDirs[3] = ResourceLocator.locateResource("FIBEditorPalettes/Graphs");
83  		paletteData[3] = new WidgetsPaletteData();
84  
85  		for (int i = 0; i < 4; i++) {
86  			Resource paletteDir = paletteDirs[i];
87  			Object data = paletteData[i];
88  			FIBEditorPalette palette = new FIBEditorPalette(paletteDir, this, data);
89  			palettes.add(palette);
90  			add(palette.getName(), palette);
91  		}
92  
93  	}
94  
95  	public FIBEditorController getEditorController() {
96  		return editorController;
97  	}
98  
99  	public void setEditorController(FIBEditorController editorController) {
100 		this.editorController = editorController;
101 	}
102 
103 	public static class PanelsPaletteData {
104 	}
105 
106 	public static class WidgetsPaletteData {
107 		public String textFieldString = "TextField";
108 		public Double doubleValue = 3.14159;
109 	}
110 
111 	public static class AdvancedPaletteData {
112 
113 		public static final ImageIcon ITEM1_ICON = new ImageIconResource(
114 				ResourceLocator.locateResource("FIBEditorPalettes/Advanced/Item1.png"));
115 		public static final ImageIcon ITEM2_ICON = new ImageIconResource(
116 				ResourceLocator.locateResource("FIBEditorPalettes/Advanced/Item2.png"));
117 		public static final ImageIcon ITEM3_ICON = new ImageIconResource(
118 				ResourceLocator.locateResource("FIBEditorPalettes/Advanced/Item3.png"));
119 		public static final ImageIcon FOLDER_ICON = new ImageIconResource(
120 				ResourceLocator.locateResource("FIBEditorPalettes/Advanced/Folder.gif"));
121 
122 		public List<TableItem> tableItems;
123 		public List<BrowserFolder> browserFolders;
124 
125 		public String htmlText = "<html><b>Formatted text editor</b><br>Used to edit some <i>formatted</i> text</html>";
126 
127 		public AdvancedPaletteData() {
128 			tableItems = new ArrayList<>();
129 			tableItems.add(new TableItem(ITEM3_ICON, "Item1", "data1"));
130 			tableItems.add(new TableItem(ITEM3_ICON, "Item2", "data2"));
131 			tableItems.add(new TableItem(ITEM3_ICON, "Item3", "data3"));
132 			browserFolders = new ArrayList<>();
133 			List<BrowserItem> itemsInFolder1 = new ArrayList<>();
134 			itemsInFolder1.add(new BrowserItem(ITEM2_ICON, "Item1"));
135 			itemsInFolder1.add(new BrowserItem(ITEM2_ICON, "Item2"));
136 			List<BrowserItem> itemsInFolder2 = new ArrayList<>();
137 			itemsInFolder2.add(new BrowserItem(ITEM2_ICON, "Item3"));
138 			browserFolders.add(new BrowserFolder(FOLDER_ICON, "Folder1", itemsInFolder1));
139 			browserFolders.add(new BrowserFolder(FOLDER_ICON, "Folder2", itemsInFolder2));
140 		}
141 
142 		public static class TableItem {
143 			public Icon icon;
144 			public String data1;
145 			public String data2;
146 
147 			public TableItem(Icon icon, String data1, String data2) {
148 				super();
149 				this.icon = icon;
150 				this.data1 = data1;
151 				this.data2 = data2;
152 			}
153 		}
154 
155 		public static class BrowserFolder {
156 			public Icon icon;
157 			public String folderName;
158 			public List<BrowserItem> items;
159 
160 			public BrowserFolder(Icon icon, String folderName, List<BrowserItem> items) {
161 				super();
162 				this.icon = icon;
163 				this.folderName = folderName;
164 				this.items = items;
165 			}
166 		}
167 
168 		public static class BrowserItem {
169 			public Icon icon;
170 			public String itemName;
171 
172 			public BrowserItem(Icon icon, String itemName) {
173 				super();
174 				this.icon = icon;
175 				this.itemName = itemName;
176 			}
177 		}
178 
179 	}
180 
181 }