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

« back to all changes in this revision

Viewing changes to 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.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.UndoableChangeClef;
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 ChangeClefAction extends Action{
35
 
    public static final String NAME = "action.composition.change-clef";
36
 
    
37
 
    public ChangeClefAction(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.clef"));
54
 
 
55
 
            //-------clef-------------------------------------
56
 
            Composite clef = new Composite(dialog, SWT.NONE);
57
 
            clef.setLayout(new GridLayout(2,false));
58
 
            clef.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));   
59
 
            
60
 
            Label numeratorLabel = new Label(clef, SWT.NULL);
61
 
            numeratorLabel.setText(TuxGuitar.getProperty("composition.clef") + ":");
62
 
            
63
 
            final Combo clefs = new Combo(clef, SWT.DROP_DOWN | SWT.READ_ONLY);
64
 
            
65
 
            clefs.add(TuxGuitar.getProperty("composition.clef.treble"));
66
 
            clefs.add(TuxGuitar.getProperty("composition.clef.bass"));
67
 
            clefs.add(TuxGuitar.getProperty("composition.clef.tenor"));
68
 
            clefs.add(TuxGuitar.getProperty("composition.clef.alto"));
69
 
            clefs.select(measure.getMeasure().getClef() - 1);
70
 
            clefs.setLayoutData(getComboData());
71
 
            
72
 
            //--------------------To End Checkbox-------------------------------
73
 
            Composite check = new Composite(dialog, SWT.NONE);
74
 
            check.setLayout(new GridLayout());
75
 
            check.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));             
76
 
                        
77
 
            final Button toEnd = new Button(check, SWT.CHECK);
78
 
            toEnd.setText(TuxGuitar.getProperty("composition.clef.to-the-end"));
79
 
            toEnd.setSelection(true);
80
 
            //------------------BUTTONS--------------------------            
81
 
            Composite buttons = new Composite(dialog, SWT.NONE);
82
 
            buttons.setLayout(new GridLayout(2,false));
83
 
            buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));            
84
 
            
85
 
            GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);    
86
 
            data.minimumWidth = 80;
87
 
            data.minimumHeight = 25;    
88
 
            
89
 
            final Button buttonOK = new Button(buttons, SWT.PUSH);
90
 
            buttonOK.setText(TuxGuitar.getProperty("ok"));
91
 
            buttonOK.setLayoutData(data);
92
 
            buttonOK.addSelectionListener(new SelectionAdapter() {
93
 
                public void widgetSelected(SelectionEvent arg0) {   
94
 
                    boolean toEndValue = toEnd.getSelection();                    
95
 
                    setClef((clefs.getSelectionIndex() + 1),toEndValue);
96
 
                    
97
 
                    dialog.dispose();
98
 
                }
99
 
            });
100
 
 
101
 
            Button buttonCancel = new Button(buttons, SWT.PUSH);
102
 
            buttonCancel.setText(TuxGuitar.getProperty("cancel"));
103
 
            buttonCancel.setLayoutData(data);
104
 
            buttonCancel.addSelectionListener(new SelectionAdapter() {
105
 
                public void widgetSelected(SelectionEvent arg0) {
106
 
                    dialog.dispose();
107
 
                }
108
 
            });
109
 
 
110
 
            dialog.pack();
111
 
            dialog.open();
112
 
 
113
 
            int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
114
 
            int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
115
 
            dialog.setLocation(x, y);
116
 
            
117
 
                while (!dialog.isDisposed()) {
118
 
                if (!dialog.getDisplay().readAndDispatch()) {
119
 
                        dialog.getDisplay().sleep();
120
 
                }
121
 
            }
122
 
        }
123
 
    }
124
 
    
125
 
    
126
 
    private GridData getComboData(){
127
 
        GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
128
 
        data.minimumWidth = 150;
129
 
        return data;
130
 
    }
131
 
    
132
 
    private void setClef(int clef,boolean toEnd){       
133
 
        //comienza el undoable
134
 
        UndoableChangeClef undoable = UndoableChangeClef.startUndo(); 
135
 
        
136
 
        Measure measure = getEditor().getTablature().getCaret().getMeasureCoords().getMeasure();
137
 
        SongTrack track = getEditor().getTablature().getCaret().getSongTrackCoords().getTrack();
138
 
        getSongManager().getTrackManager().changeClef(track,measure.getStart(),clef,toEnd);
139
 
        
140
 
        //actualizo la tablatura
141
 
        updateTablature();
142
 
        redraw();                
143
 
        
144
 
        //termia el undoable
145
 
        getEditor().getUndoManager().addEdit(undoable.endUndo(clef,toEnd));
146
 
        
147
 
    }    
148
 
 
149
 
}