2
* Created on 18-dic-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.gui.items;
10
import java.util.ArrayList;
11
import java.util.Iterator;
12
import java.util.List;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.graphics.Point;
16
import org.eclipse.swt.layout.FormAttachment;
17
import org.eclipse.swt.layout.FormData;
18
import org.eclipse.swt.widgets.Control;
19
import org.eclipse.swt.widgets.CoolBar;
20
import org.eclipse.swt.widgets.CoolItem;
21
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.swt.widgets.Listener;
23
import org.eclipse.swt.widgets.Menu;
24
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.swt.widgets.ToolBar;
26
import org.herac.tuxguitar.gui.editors.TablatureEditor;
27
import org.herac.tuxguitar.gui.items.menu.CompositionMenuItem;
28
import org.herac.tuxguitar.gui.items.menu.EditMenuItem;
29
import org.herac.tuxguitar.gui.items.menu.FileMenuItem;
30
import org.herac.tuxguitar.gui.items.menu.HelpMenuItem;
31
import org.herac.tuxguitar.gui.items.menu.LayoutMenuItem;
32
import org.herac.tuxguitar.gui.items.menu.MarkerMenuItem;
33
import org.herac.tuxguitar.gui.items.menu.MeasureMenuItem;
34
import org.herac.tuxguitar.gui.items.menu.NoteMenuItem;
35
import org.herac.tuxguitar.gui.items.menu.PlayMenuItem;
36
import org.herac.tuxguitar.gui.items.menu.PluginMenuItem;
37
import org.herac.tuxguitar.gui.items.menu.SettingsMenuItem;
38
import org.herac.tuxguitar.gui.items.menu.TrackMenuItem;
39
import org.herac.tuxguitar.gui.items.tool.CompositionToolItems;
40
import org.herac.tuxguitar.gui.items.tool.DurationToolItems;
41
import org.herac.tuxguitar.gui.items.tool.DynamicToolItems;
42
import org.herac.tuxguitar.gui.items.tool.EditToolItems;
43
import org.herac.tuxguitar.gui.items.tool.FileToolItems;
44
import org.herac.tuxguitar.gui.items.tool.LayoutToolItems;
45
import org.herac.tuxguitar.gui.items.tool.MarkerToolItems;
46
import org.herac.tuxguitar.gui.items.tool.NoteEffectToolItems;
47
import org.herac.tuxguitar.gui.items.tool.NoteToolItems;
48
import org.herac.tuxguitar.gui.items.tool.PlayerToolItems;
49
import org.herac.tuxguitar.gui.items.tool.PropertiesToolItems;
50
import org.herac.tuxguitar.gui.items.tool.TrackToolItems;
51
import org.herac.tuxguitar.gui.items.tool.ViewToolItems;
52
import org.herac.tuxguitar.gui.items.xml.ToolBarsReader;
53
import org.herac.tuxguitar.gui.items.xml.ToolBarsWriter;
54
import org.herac.tuxguitar.gui.util.TuxGuitarFileUtils;
59
* TODO To change the template for this generated type comment go to
60
* Window - Preferences - Java - Code Style - Code Templates
62
public class ItemManager {
63
private static final int HEIGHT = 32;
65
private static ToolItems[] AVAILABLE_TOOL_BARS = new ToolItems[]{
68
new PropertiesToolItems(),
70
new DurationToolItems(),
72
new CompositionToolItems(),
73
new PlayerToolItems(),
74
new MarkerToolItems(),
75
new LayoutToolItems(),
77
new NoteEffectToolItems(),
78
new DynamicToolItems()
81
private TablatureEditor tablatureEditor;
83
private Menu popupMenu;
84
private CoolBar coolBar;
85
private List toolItems;
86
private List menuItems;
87
private List popupMenuItems;
88
private boolean layout_locked;
90
public ItemManager(TablatureEditor tablatureEditor){
91
this.tablatureEditor = tablatureEditor;
92
this.toolItems = new ArrayList();
93
this.menuItems = new ArrayList();
94
this.popupMenuItems = new ArrayList();
95
this.layout_locked = false;
98
public void createItems(final Shell shell){
99
this.createMenu(shell);
100
this.createPopupMenu(shell);
101
this.createCoolbar(shell);
104
public void createCoolbar(final Shell shell) {
105
this.coolBar = new CoolBar(shell,SWT.FLAT);
106
this.makeCoolItems();
108
FormData coolData = new FormData();
109
coolData.left = new FormAttachment(0);
110
coolData.right = new FormAttachment(100);
111
coolData.top = new FormAttachment(0,0);
112
coolBar.setLayoutData(coolData);
113
coolBar.addListener(SWT.Resize, new Listener() {
114
public void handleEvent(Event event) {
120
private void clearCoolBar(){
121
if(this.coolBar != null && !this.coolBar.isDisposed()){
122
this.toolItems.clear();
124
CoolItem[] items = this.coolBar.getItems();
125
for(int i = 0;i < items.length; i ++){
128
Control[] controls = this.coolBar.getChildren();
129
for(int i = 0;i < controls.length; i ++){
130
controls[i].dispose();
135
private void layoutCoolBar(){
136
if(!this.layout_locked){
137
this.layout_locked = true;
139
this.coolBar.getParent().layout();
140
this.coolBar.layout();
142
this.layout_locked = false;
146
public void makeCoolItems(){
148
List enableToolBars = getEnabledToolBars();
149
for(int i = 0; i < enableToolBars.size(); i ++){
150
String name = (String)enableToolBars.get(i);
151
for(int j = 0; j < AVAILABLE_TOOL_BARS.length; j ++){
152
if(AVAILABLE_TOOL_BARS[j].getName().trim().toLowerCase().equals(name.trim().toLowerCase())){
153
makeToolBar(AVAILABLE_TOOL_BARS[j]);
161
private void makeToolBar(ToolItems item){
162
ToolBar toolBar = new ToolBar(this.coolBar,SWT.FLAT | SWT.WRAP);
163
item.showItems(toolBar);
164
makeCoolItem(toolBar);
165
this.toolItems.add(item);
168
private void makeCoolItem(ToolBar toolBar){
169
CoolItem coolItem = new CoolItem(coolBar,SWT.NONE);
170
coolItem.setControl(toolBar);
171
Point size = toolBar.computeSize( SWT.DEFAULT,SWT.DEFAULT);
172
Point coolSize = coolItem.computeSize(size.x, HEIGHT);
173
coolItem.setMinimumSize(coolSize);
174
coolItem.setSize(coolSize);
177
public List getEnabledToolBars(){
178
return loadEnableToolBars(getAvailableToolBarNames());
181
public List getAvailableToolBarNames(){
182
List names = new ArrayList();
183
for(int i = 0; i < AVAILABLE_TOOL_BARS.length; i ++){
184
names.add(AVAILABLE_TOOL_BARS[i].getName());
189
public void createMenu(Shell shell) {
190
this.menu = new Menu(shell, SWT.BAR);
191
this.menuItems.add(new FileMenuItem(shell,this.menu, SWT.CASCADE,tablatureEditor));
192
this.menuItems.add(new EditMenuItem(shell,this.menu, SWT.CASCADE,tablatureEditor));
193
this.menuItems.add(new LayoutMenuItem(shell,this.menu, SWT.CASCADE,tablatureEditor));
194
this.menuItems.add(new CompositionMenuItem(shell,this.menu, SWT.CASCADE,tablatureEditor));
195
this.menuItems.add(new TrackMenuItem(shell,this.menu, SWT.CASCADE,tablatureEditor));
196
this.menuItems.add(new MeasureMenuItem(shell,this.menu, SWT.CASCADE,tablatureEditor));
197
this.menuItems.add(new NoteMenuItem(shell,this.menu, SWT.CASCADE,tablatureEditor));
198
this.menuItems.add(new MarkerMenuItem(shell,this.menu, SWT.CASCADE,tablatureEditor));
199
this.menuItems.add(new PlayMenuItem(shell,this.menu, SWT.CASCADE,tablatureEditor));
200
this.menuItems.add(new SettingsMenuItem(shell,this.menu, SWT.CASCADE));
201
this.menuItems.add(new PluginMenuItem(shell,this.menu, SWT.CASCADE));
202
this.menuItems.add(new HelpMenuItem(shell,this.menu, SWT.CASCADE));
203
this.showMenuItems(this.menuItems);
204
shell.setMenuBar(this.menu);
207
public void createPopupMenu(Shell shell) {
208
this.popupMenu = new Menu(shell, SWT.POP_UP);
209
this.popupMenuItems.add(new EditMenuItem(shell,this.popupMenu, SWT.CASCADE,tablatureEditor));
210
this.popupMenuItems.add(new CompositionMenuItem(shell,this.popupMenu, SWT.CASCADE,tablatureEditor));
211
this.popupMenuItems.add(new TrackMenuItem(shell,this.popupMenu, SWT.CASCADE,tablatureEditor));
212
this.popupMenuItems.add(new MeasureMenuItem(shell,this.popupMenu, SWT.CASCADE,tablatureEditor));
213
this.popupMenuItems.add(new NoteMenuItem(shell,this.popupMenu, SWT.CASCADE,tablatureEditor));
214
this.popupMenuItems.add(new MarkerMenuItem(shell,this.popupMenu, SWT.CASCADE,tablatureEditor));
215
this.popupMenuItems.add(new PlayMenuItem(shell,this.popupMenu, SWT.CASCADE,tablatureEditor));
216
this.showMenuItems(this.popupMenuItems);
219
private void showMenuItems(List items){
220
Iterator it = items.iterator();
222
MenuItems item = (MenuItems)it.next();
227
public void updateItems(){
229
updateItems(toolItems);
230
updateItems(menuItems);
231
updateItems(popupMenuItems);
235
public void updateItems(List items){
236
Iterator it = items.iterator();
238
ItemBase item = (ItemBase)it.next();
243
public void loadProperties(){
245
loadProperties(toolItems);
246
loadProperties(menuItems);
247
loadProperties(popupMenuItems);
251
public void loadProperties(List items){
252
Iterator it = items.iterator();
254
ItemBase item = (ItemBase)it.next();
255
item.loadProperties();
259
public CoolBar getCoolbar(){
263
public Menu getPopupMenu(){
264
return this.popupMenu;
267
public List loadEnableToolBars(List availableItems) {
268
File file = new File(getCoolItemsFileName());
270
saveToolBars(availableItems);
272
return new ToolBarsReader().loadToolBars(file);
275
public void saveToolBars(List toolItems){
276
new ToolBarsWriter().saveToolBars(toolItems, getCoolItemsFileName());
279
public void saveDefaultToolBars(){
280
saveToolBars(getAvailableToolBarNames());
283
private boolean isDisposed(){
284
return (this.coolBar.isDisposed() || this.menu.isDisposed() || this.popupMenu.isDisposed());
287
private String getCoolItemsFileName(){
288
return TuxGuitarFileUtils.USER_CONFIG_PREFIX + File.separator + "toolbars.xml";