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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/actions/composition/ChangeTripletFeelAction.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.Composite;
 
17
import org.eclipse.swt.widgets.Group;
 
18
import org.eclipse.swt.widgets.Shell;
 
19
import org.herac.tuxguitar.gui.TuxGuitar;
 
20
import org.herac.tuxguitar.gui.actions.Action;
 
21
import org.herac.tuxguitar.gui.editors.tab.Caret;
 
22
import org.herac.tuxguitar.gui.editors.tab.TGMeasureImpl;
 
23
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeTripletFeel;
 
24
import org.herac.tuxguitar.gui.util.DialogUtils;
 
25
import org.herac.tuxguitar.song.models.TGMeasureHeader;
 
26
 
 
27
/**
 
28
 * @author julian
 
29
 *
 
30
 * TODO To change the template for this generated type comment go to
 
31
 * Window - Preferences - Java - Code Style - Code Templates
 
32
 */
 
33
public class ChangeTripletFeelAction extends Action{
 
34
        public static final String NAME = "action.composition.change-triplet-feel";
 
35
        
 
36
        public ChangeTripletFeelAction() {
 
37
                super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING | KEY_BINDING_AVAILABLE);
 
38
        }
 
39
        
 
40
        protected int execute(TypedEvent e){
 
41
                showDialog(getEditor().getTablature().getShell());
 
42
                return 0;
 
43
        }
 
44
        
 
45
        public void showDialog(Shell shell) {
 
46
                TGMeasureImpl measure = getEditor().getTablature().getCaret().getMeasure();
 
47
                if (measure != null) {
 
48
                        final Shell dialog = DialogUtils.newDialog(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 
49
                        
 
50
                        dialog.setLayout(new GridLayout());
 
51
                        dialog.setText(TuxGuitar.getProperty("composition.tripletfeel"));
 
52
                        dialog.setMinimumSize(300,0);
 
53
                        
 
54
                        //-------------TIME SIGNATURE-----------------------------------------------
 
55
                        Group tripletFeel = new Group(dialog,SWT.SHADOW_ETCHED_IN);
 
56
                        tripletFeel.setLayout(new GridLayout());
 
57
                        tripletFeel.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
58
                        tripletFeel.setText(TuxGuitar.getProperty("composition.tripletfeel"));
 
59
                        
 
60
                        //none
 
61
                        final Button tripletFeelNone = new Button(tripletFeel, SWT.RADIO);
 
62
                        tripletFeelNone.setText(TuxGuitar.getProperty("composition.tripletfeel.none"));
 
63
                        tripletFeelNone.setSelection(measure.getTripletFeel() == TGMeasureHeader.TRIPLET_FEEL_NONE);
 
64
                        
 
65
                        final Button tripletFeelEighth = new Button(tripletFeel, SWT.RADIO);
 
66
                        tripletFeelEighth.setText(TuxGuitar.getProperty("composition.tripletfeel.eighth"));
 
67
                        tripletFeelEighth.setSelection(measure.getTripletFeel() == TGMeasureHeader.TRIPLET_FEEL_EIGHTH);
 
68
                        
 
69
                        final Button tripletFeelSixteenth = new Button(tripletFeel, SWT.RADIO);
 
70
                        tripletFeelSixteenth.setText(TuxGuitar.getProperty("composition.tripletfeel.sixteenth"));
 
71
                        tripletFeelSixteenth.setSelection(measure.getTripletFeel() == TGMeasureHeader.TRIPLET_FEEL_SIXTEENTH);
 
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.tripletfeel.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.END,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
                                        int tripletFeel = TGMeasureHeader.TRIPLET_FEEL_NONE;
 
94
                                        if(tripletFeelNone.getSelection()){
 
95
                                                tripletFeel = TGMeasureHeader.TRIPLET_FEEL_NONE;
 
96
                                        }else if(tripletFeelEighth.getSelection()){
 
97
                                                tripletFeel = TGMeasureHeader.TRIPLET_FEEL_EIGHTH;
 
98
                                        }else if(tripletFeelSixteenth.getSelection()){
 
99
                                                tripletFeel = TGMeasureHeader.TRIPLET_FEEL_SIXTEENTH;
 
100
                                        }
 
101
                                        setTripletFeel(tripletFeel,toEndValue);
 
102
                                        dialog.dispose();
 
103
                                }
 
104
                        });
 
105
                        
 
106
                        Button buttonCancel = new Button(buttons, SWT.PUSH);
 
107
                        buttonCancel.setLayoutData(getButtonData());
 
108
                        buttonCancel.setText(TuxGuitar.getProperty("cancel"));
 
109
                        buttonCancel.addSelectionListener(new SelectionAdapter() {
 
110
                                public void widgetSelected(SelectionEvent arg0) {
 
111
                                        dialog.dispose();
 
112
                                }
 
113
                        });
 
114
                        
 
115
                        dialog.setDefaultButton( buttonOk );
 
116
                        
 
117
                        DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
 
118
                }
 
119
        }
 
120
        
 
121
        private GridData getButtonData(){
 
122
                GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
 
123
                data.minimumWidth = 80;
 
124
                data.minimumHeight = 25;
 
125
                return data;
 
126
        }
 
127
        
 
128
        protected void setTripletFeel(int tripletFeel,boolean toEnd){
 
129
                //comienza el undoable
 
130
                UndoableChangeTripletFeel undoable = UndoableChangeTripletFeel.startUndo();
 
131
                
 
132
                Caret caret = getEditor().getTablature().getCaret();
 
133
                TGMeasureImpl measure = caret.getMeasure();
 
134
                
 
135
                getSongManager().changeTripletFeel(measure.getStart(),tripletFeel,toEnd);
 
136
                
 
137
                TuxGuitar.instance().getFileHistory().setUnsavedFile();
 
138
                
 
139
                //actualizo la tablatura
 
140
                updateTablature();
 
141
                
 
142
                //termia el undoable
 
143
                addUndoableEdit(undoable.endUndo(tripletFeel,toEnd));
 
144
        }
 
145
}