1
package org.herac.tuxguitar.gui.system.config.items;
3
import java.util.Iterator;
6
import org.eclipse.swt.SWT;
7
import org.eclipse.swt.events.SelectionAdapter;
8
import org.eclipse.swt.events.SelectionEvent;
9
import org.eclipse.swt.layout.GridData;
10
import org.eclipse.swt.layout.GridLayout;
11
import org.eclipse.swt.widgets.Button;
12
import org.eclipse.swt.widgets.Composite;
13
import org.eclipse.swt.widgets.ToolBar;
14
import org.herac.tuxguitar.gui.SystemImages;
15
import org.herac.tuxguitar.gui.TuxGuitar;
16
import org.herac.tuxguitar.gui.system.config.ConfigEditor;
18
public class ToolBarsOption extends Option{
19
private boolean changes;
20
private List availableToolBars;
21
private List customToolBars;
22
private org.eclipse.swt.widgets.List availableList;
23
private org.eclipse.swt.widgets.List customList;
24
private Button addButton;
25
private Button removeButton;
26
private Button moveUpButton;
27
private Button moveDownButton;
29
public ToolBarsOption(ConfigEditor configEditor,ToolBar toolBar,final Composite parent){
30
super(configEditor,toolBar,parent,TuxGuitar.getProperty("settings.config.toolbars"),SWT.FILL,SWT.FILL);
35
public void createOption() {
36
getToolItem().setText(TuxGuitar.getProperty("settings.config.toolbars"));
37
getToolItem().setImage(SystemImages.OPTION_TOOLBARS);
38
getToolItem().addSelectionListener(this);
40
Composite composite = new Composite(getComposite(),SWT.NONE);
41
composite.setLayout(new GridLayout(2,false));
42
composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
45
Composite leftList = new Composite(composite, SWT.NONE);
46
leftList.setLayout(new GridLayout());
47
leftList.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
49
availableList = new org.eclipse.swt.widgets.List(leftList,SWT.BORDER | SWT.V_SCROLL);
50
availableList.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
51
for(int i = 0;i < this.availableToolBars.size(); i ++){
52
String name = (String)availableToolBars.get(i);
53
availableList.add(TuxGuitar.getProperty(name));
55
availableList.addSelectionListener(new SelectionAdapter() {
56
public void widgetSelected(SelectionEvent e) {
62
Composite rightList = new Composite(composite, SWT.NONE);
63
rightList.setLayout(new GridLayout());
64
rightList.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
66
customList = new org.eclipse.swt.widgets.List(rightList,SWT.BORDER | SWT.V_SCROLL);
67
customList.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
68
customList.addSelectionListener(new SelectionAdapter() {
69
public void widgetSelected(SelectionEvent e) {
75
Composite leftButtons = new Composite(composite, SWT.NONE);
76
leftButtons.setLayout(new GridLayout());
77
leftButtons.setLayoutData(new GridData(SWT.FILL,SWT.BOTTOM,true,true));
79
addButton = new Button(leftButtons, SWT.PUSH);
80
addButton.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
81
addButton.setText("Add");
82
addButton.addSelectionListener(new SelectionAdapter() {
83
public void widgetSelected(SelectionEvent e) {
84
addToolBar(availableList.getSelectionIndex());
89
Composite rightButtons = new Composite(composite, SWT.NONE);
90
rightButtons.setLayout(new GridLayout(3,false));
91
rightButtons.setLayoutData(new GridData(SWT.FILL,SWT.BOTTOM,true,true));
93
removeButton = new Button(rightButtons, SWT.PUSH);
94
removeButton.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
95
removeButton.setText("Remove");
96
removeButton.addSelectionListener(new SelectionAdapter() {
97
public void widgetSelected(SelectionEvent e) {
98
removeToolBar(customList.getSelectionIndex());
102
moveUpButton = new Button(rightButtons,SWT.ARROW | SWT.UP);
103
moveUpButton.addSelectionListener(new SelectionAdapter() {
104
public void widgetSelected(SelectionEvent e) {
105
moveUp(customList.getSelectionIndex());
109
moveDownButton = new Button(rightButtons,SWT.ARROW | SWT.DOWN);
110
moveDownButton.addSelectionListener(new SelectionAdapter() {
111
public void widgetSelected(SelectionEvent e) {
112
moveDown(customList.getSelectionIndex());
120
public GridData makeButtonData(int horizontalAlignment,int minWith,int minHeight){
121
GridData data = new GridData();
122
data.minimumWidth = minWith;
123
data.minimumHeight = minHeight;
125
data.horizontalAlignment = horizontalAlignment;
126
data.grabExcessHorizontalSpace = true;
131
private void loadToolBars(){
132
this.availableToolBars = TuxGuitar.instance().getItemManager().getAvailableToolBarNames();
133
this.customToolBars = TuxGuitar.instance().getItemManager().getEnabledToolBars();
136
private void reloadList(int selection){
137
this.customList.removeAll();
139
Iterator it = this.customToolBars.iterator();
141
String name = (String)it.next();
142
this.customList.add(TuxGuitar.getProperty(name));
144
this.customList.select(selection);
148
private void checkButtons(){
149
if(addButton != null && !addButton.isDisposed()){
150
boolean enabled = false;
151
int index = availableList.getSelectionIndex();
152
if(index >= 0 && index < this.availableToolBars.size()){
153
enabled = (!exists((String)this.availableToolBars.get(index)));
155
addButton.setEnabled(enabled);
157
if(removeButton != null && !removeButton.isDisposed()){
158
int index = customList.getSelectionIndex();
159
removeButton.setEnabled((index >= 0 && index < this.customToolBars.size()));
161
if(moveUpButton != null && !moveUpButton.isDisposed()){
162
int index = customList.getSelectionIndex();
163
moveUpButton.setEnabled(index > 0 && index < this.customToolBars.size());
165
if(moveDownButton != null && !moveDownButton.isDisposed()){
166
int index = customList.getSelectionIndex();
167
moveDownButton.setEnabled(index >= 0 && index < (this.customToolBars.size() - 1));
171
private void addToolBar(int index){
172
if(index >= 0 && index < this.availableToolBars.size()){
173
String name = (String)this.availableToolBars.get(index);
175
this.customToolBars.add(name);
176
this.reloadList((this.customToolBars.size() - 1));
182
private void removeToolBar(int index){
183
if(index >= 0 && index < this.customToolBars.size()){
184
this.customToolBars.remove(index);
185
this.reloadList((this.customToolBars.size() > index)?index:this.customToolBars.size() - 1);
190
private void moveUp(int index){
191
if(index > 0 && index < this.customToolBars.size()){
192
String name = (String)this.customToolBars.get(index);
193
this.customToolBars.remove(index);
194
this.customToolBars.add((index - 1),name);
195
this.reloadList((index - 1));
200
private void moveDown(int index){
201
if(index >= 0 && index < (this.customToolBars.size() - 1)){
202
String name = (String)this.customToolBars.get(index);
203
this.customToolBars.remove(index);
204
this.customToolBars.add((index + 1),name);
205
this.reloadList((index + 1));
210
private boolean exists(String name){
211
Iterator it = this.customToolBars.iterator();
213
String currentName = (String)it.next();
214
if(currentName.equals(name)){
221
public void updateConfig() {
222
TuxGuitar.instance().getItemManager().saveToolBars(this.customToolBars);
225
public void applyConfig(boolean force){
226
if(this.changes || force){
227
TuxGuitar.instance().loadToolBars();