~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/actions/composition/ChangeClefAction.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created on 17-dic-2005
 
3
 *
 
4
 * TODO To change the template for this generated file go to
 
5
 * Window - Preferences - Java - Code Style - Code Templates
 
6
 */
 
7
package org.herac.tuxguitar.gui.actions.composition;
 
8
 
 
9
import org.eclipse.swt.SWT;
 
10
import org.eclipse.swt.events.SelectionAdapter;
 
11
import org.eclipse.swt.events.SelectionEvent;
 
12
import org.eclipse.swt.events.TypedEvent;
 
13
import org.eclipse.swt.layout.GridData;
 
14
import org.eclipse.swt.layout.GridLayout;
 
15
import org.eclipse.swt.widgets.Button;
 
16
import org.eclipse.swt.widgets.Combo;
 
17
import org.eclipse.swt.widgets.Composite;
 
18
import org.eclipse.swt.widgets.Group;
 
19
import org.eclipse.swt.widgets.Label;
 
20
import org.eclipse.swt.widgets.Shell;
 
21
import org.herac.tuxguitar.gui.TuxGuitar;
 
22
import org.herac.tuxguitar.gui.actions.Action;
 
23
import org.herac.tuxguitar.gui.editors.tab.TGMeasureImpl;
 
24
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeClef;
 
25
import org.herac.tuxguitar.gui.util.DialogUtils;
 
26
import org.herac.tuxguitar.song.models.TGMeasure;
 
27
import org.herac.tuxguitar.song.models.TGTrack;
 
28
 
 
29
/**
 
30
 * @author julian
 
31
 *
 
32
 * TODO To change the template for this generated type comment go to
 
33
 * Window - Preferences - Java - Code Style - Code Templates
 
34
 */
 
35
public class ChangeClefAction extends Action{
 
36
        public static final String NAME = "action.composition.change-clef";
 
37
        
 
38
        public ChangeClefAction() {
 
39
                super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING | KEY_BINDING_AVAILABLE);
 
40
        }
 
41
        
 
42
        protected int execute(TypedEvent e){
 
43
                showDialog(getEditor().getTablature().getShell());
 
44
                return 0;
 
45
        }
 
46
        
 
47
        public void showDialog(Shell shell) {
 
48
                TGMeasureImpl measure = getEditor().getTablature().getCaret().getMeasure();
 
49
                if (measure != null) {
 
50
                        final Shell dialog = DialogUtils.newDialog(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 
51
                        
 
52
                        dialog.setLayout(new GridLayout());
 
53
                        dialog.setText(TuxGuitar.getProperty("composition.clef"));
 
54
                        
 
55
                        //-------clef-------------------------------------
 
56
                        Group clef = new Group(dialog,SWT.SHADOW_ETCHED_IN);
 
57
                        clef.setLayout(new GridLayout(2,false));
 
58
                        clef.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
59
                        clef.setText(TuxGuitar.getProperty("composition.clef"));
 
60
                        
 
61
                        Label numeratorLabel = new Label(clef, SWT.NULL);
 
62
                        numeratorLabel.setText(TuxGuitar.getProperty("composition.clef") + ":");
 
63
                        
 
64
                        final Combo clefs = new Combo(clef, SWT.DROP_DOWN | SWT.READ_ONLY);
 
65
                        
 
66
                        clefs.add(TuxGuitar.getProperty("composition.clef.treble"));
 
67
                        clefs.add(TuxGuitar.getProperty("composition.clef.bass"));
 
68
                        clefs.add(TuxGuitar.getProperty("composition.clef.tenor"));
 
69
                        clefs.add(TuxGuitar.getProperty("composition.clef.alto"));
 
70
                        clefs.select(measure.getClef() - 1);
 
71
                        clefs.setLayoutData(getComboData());
 
72
                        
 
73
                        //--------------------To End Checkbox-------------------------------
 
74
                        Group check = new Group(dialog,SWT.SHADOW_ETCHED_IN);
 
75
                        check.setLayout(new GridLayout());
 
76
                        check.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
77
                        check.setText(TuxGuitar.getProperty("options"));
 
78
                        
 
79
                        final Button toEnd = new Button(check, SWT.CHECK);
 
80
                        toEnd.setText(TuxGuitar.getProperty("composition.clef.to-the-end"));
 
81
                        toEnd.setSelection(true);
 
82
                        //------------------BUTTONS--------------------------
 
83
                        Composite buttons = new Composite(dialog, SWT.NONE);
 
84
                        buttons.setLayout(new GridLayout(2,false));
 
85
                        buttons.setLayoutData(new GridData(SWT.RIGHT,SWT.FILL,true,true));
 
86
                        
 
87
                        final Button buttonOK = new Button(buttons, SWT.PUSH);
 
88
                        buttonOK.setText(TuxGuitar.getProperty("ok"));
 
89
                        buttonOK.setLayoutData(getButtonData());
 
90
                        buttonOK.addSelectionListener(new SelectionAdapter() {
 
91
                                public void widgetSelected(SelectionEvent arg0) {
 
92
                                        boolean toEndValue = toEnd.getSelection();
 
93
                                        setClef((clefs.getSelectionIndex() + 1),toEndValue);
 
94
                                        
 
95
                                        dialog.dispose();
 
96
                                }
 
97
                        });
 
98
                        
 
99
                        Button buttonCancel = new Button(buttons, SWT.PUSH);
 
100
                        buttonCancel.setText(TuxGuitar.getProperty("cancel"));
 
101
                        buttonCancel.setLayoutData(getButtonData());
 
102
                        buttonCancel.addSelectionListener(new SelectionAdapter() {
 
103
                                public void widgetSelected(SelectionEvent arg0) {
 
104
                                        dialog.dispose();
 
105
                                }
 
106
                        });
 
107
                        
 
108
                        dialog.setDefaultButton( buttonOK );
 
109
                        
 
110
                        DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
 
111
                }
 
112
        }
 
113
        
 
114
        private GridData getComboData(){
 
115
                GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
 
116
                data.minimumWidth = 150;
 
117
                return data;
 
118
        }
 
119
        
 
120
        protected GridData getButtonData(){
 
121
                GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
 
122
                data.minimumWidth = 80;
 
123
                data.minimumHeight = 25;
 
124
                return data;
 
125
        }
 
126
        
 
127
        protected void setClef(int clef,boolean toEnd){
 
128
                //comienza el undoable
 
129
                UndoableChangeClef undoable = UndoableChangeClef.startUndo();
 
130
                
 
131
                TGMeasure measure = getEditor().getTablature().getCaret().getMeasure();
 
132
                TGTrack track = getEditor().getTablature().getCaret().getTrack();
 
133
                getSongManager().getTrackManager().changeClef(track,measure.getStart(),clef,toEnd);
 
134
                
 
135
                TuxGuitar.instance().getFileHistory().setUnsavedFile();
 
136
                
 
137
                //actualizo la tablatura
 
138
                updateTablature();
 
139
                
 
140
                //termia el undoable
 
141
                addUndoableEdit(undoable.endUndo(clef,toEnd));
 
142
        }
 
143
}