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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/actions/composition/ChangeKeySignatureAction.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.Label;
19
 
import org.eclipse.swt.widgets.Shell;
20
 
import org.herac.tuxguitar.gui.TuxGuitar;
21
 
import org.herac.tuxguitar.gui.actions.Action;
22
 
import org.herac.tuxguitar.gui.editors.TablatureEditor;
23
 
import org.herac.tuxguitar.gui.editors.tab.MeasureCoords;
24
 
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeKeySignature;
25
 
import org.herac.tuxguitar.song.models.Measure;
26
 
import org.herac.tuxguitar.song.models.SongTrack;
27
 
 
28
 
/**
29
 
 * @author julian
30
 
 *
31
 
 * TODO To change the template for this generated type comment go to
32
 
 * Window - Preferences - Java - Code Style - Code Templates
33
 
 */
34
 
public class ChangeKeySignatureAction extends Action{
35
 
    public static final String NAME = "action.composition.change-key-signature";
36
 
    
37
 
    public ChangeKeySignatureAction(TablatureEditor tablatureEditor) {
38
 
        super(NAME,true,tablatureEditor);       
39
 
    }
40
 
 
41
 
    public boolean doAction(TypedEvent e) {
42
 
        showDialog(getEditor().getTablature().getShell()); 
43
 
        return true;
44
 
    }
45
 
 
46
 
    
47
 
    public void showDialog(Shell shell) {
48
 
        MeasureCoords measure = getEditor().getTablature().getCaret().getMeasureCoords();
49
 
        if (measure != null) {
50
 
            final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
51
 
   
52
 
            dialog.setLayout(new GridLayout());
53
 
            dialog.setText(TuxGuitar.getProperty("composition.keysignature"));
54
 
 
55
 
            //-------key Signature-------------------------------------
56
 
            Composite keySignature = new Composite(dialog, SWT.NONE);
57
 
            keySignature.setLayout(new GridLayout(2,false));
58
 
            keySignature.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));   
59
 
            
60
 
            Label numeratorLabel = new Label(keySignature, SWT.NULL);
61
 
            numeratorLabel.setText(TuxGuitar.getProperty("composition.keysignature") + ":");
62
 
            
63
 
            final Combo keySignatures = new Combo(keySignature, SWT.DROP_DOWN | SWT.READ_ONLY);
64
 
            
65
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.natural"));
66
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-1"));
67
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-2"));
68
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-3"));
69
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-4"));
70
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-5"));
71
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-6"));
72
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-7"));
73
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-1"));
74
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-2"));
75
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-3"));
76
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-4"));
77
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-5"));
78
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-6"));
79
 
            keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-7"));
80
 
            keySignatures.select(measure.getMeasure().getKeySignature());
81
 
            keySignatures.setLayoutData(getComboData());
82
 
            //--------------------To End Checkbox-------------------------------
83
 
            Composite check = new Composite(dialog, SWT.NONE);
84
 
            check.setLayout(new GridLayout());
85
 
            check.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));   
86
 
            
87
 
            final Button toEnd = new Button(check, SWT.CHECK);
88
 
            toEnd.setText(TuxGuitar.getProperty("composition.keysignature.to-the-end"));
89
 
            toEnd.setSelection(true);
90
 
            //------------------BUTTONS--------------------------            
91
 
            Composite buttons = new Composite(dialog, SWT.NONE);
92
 
            buttons.setLayout(new GridLayout(2,false));
93
 
            buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));            
94
 
            
95
 
            GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);    
96
 
            data.minimumWidth = 80;
97
 
            data.minimumHeight = 25;      
98
 
            
99
 
            final Button buttonOK = new Button(buttons, SWT.PUSH);
100
 
            buttonOK.setText(TuxGuitar.getProperty("ok"));
101
 
            buttonOK.setLayoutData(data);
102
 
            buttonOK.addSelectionListener(new SelectionAdapter() {
103
 
                public void widgetSelected(SelectionEvent arg0) {   
104
 
                    boolean toEndValue = toEnd.getSelection();                    
105
 
                    setKeySignature(keySignatures.getSelectionIndex(),toEndValue);
106
 
                    
107
 
                    dialog.dispose();
108
 
                }
109
 
            });
110
 
 
111
 
            Button buttonCancel = new Button(buttons, SWT.PUSH);
112
 
            buttonCancel.setText(TuxGuitar.getProperty("cancel"));
113
 
            buttonCancel.setLayoutData(data);
114
 
            buttonCancel.addSelectionListener(new SelectionAdapter() {
115
 
                public void widgetSelected(SelectionEvent arg0) {
116
 
                    dialog.dispose();
117
 
                }
118
 
            });
119
 
 
120
 
            dialog.pack();
121
 
            dialog.open();
122
 
 
123
 
            int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
124
 
            int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
125
 
            dialog.setLocation(x, y);
126
 
            
127
 
                while (!dialog.isDisposed()) {
128
 
                if (!dialog.getDisplay().readAndDispatch()) {
129
 
                        dialog.getDisplay().sleep();
130
 
                }
131
 
            }
132
 
        }
133
 
    }
134
 
    
135
 
    private GridData getComboData(){
136
 
        GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
137
 
        data.minimumWidth = 150;
138
 
        return data;
139
 
    }
140
 
    
141
 
    private void setKeySignature(int keySignature,boolean toEnd){       
142
 
        //comienza el undoable
143
 
        UndoableChangeKeySignature undoable = UndoableChangeKeySignature.startUndo(); 
144
 
        
145
 
        Measure measure = getEditor().getTablature().getCaret().getMeasureCoords().getMeasure();
146
 
        SongTrack track = getEditor().getTablature().getCaret().getSongTrackCoords().getTrack();        
147
 
        getSongManager().getTrackManager().changeKeySignature(track,measure.getStart(),keySignature,toEnd);
148
 
        
149
 
        //actualizo la tablatura
150
 
        updateTablature();
151
 
        redraw();                
152
 
        
153
 
        //termia el undoable
154
 
        getEditor().getUndoManager().addEdit(undoable.endUndo(keySignature,toEnd));
155
 
        
156
 
    }    
157
 
 
158
 
}