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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/actions/composition/ChangeInfoAction.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.Label;
 
19
import org.eclipse.swt.widgets.Shell;
 
20
import org.eclipse.swt.widgets.Text;
 
21
import org.herac.tuxguitar.gui.TuxGuitar;
 
22
import org.herac.tuxguitar.gui.actions.Action;
 
23
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeInfo;
 
24
import org.herac.tuxguitar.gui.util.DialogUtils;
 
25
import org.herac.tuxguitar.song.models.TGSong;
 
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 ChangeInfoAction extends Action{
 
34
        public static final String NAME = "action.composition.change-info";
 
35
        
 
36
        private static final int TEXT_WIDTH = 300;
 
37
        
 
38
        public ChangeInfoAction() {
 
39
                super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | 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
                TGSong song = getSongManager().getSong();
 
49
                if (song != null) {
 
50
                        final Shell dialog = DialogUtils.newDialog(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 
51
                        
 
52
                        dialog.setLayout(new GridLayout());
 
53
                        dialog.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
54
                        dialog.setText(TuxGuitar.getProperty("composition.properties"));
 
55
                        
 
56
                        Group group = new Group(dialog,SWT.SHADOW_ETCHED_IN);
 
57
                        group.setLayout(makeGroupLayout(5));
 
58
                        group.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
59
                        group.setText(TuxGuitar.getProperty("composition.properties"));
 
60
                        
 
61
                        //-------NAME------------------------------------
 
62
                        Label nameLabel = new Label(group, SWT.NULL);
 
63
                        nameLabel.setLayoutData(makeLabelData()); 
 
64
                        nameLabel.setText(TuxGuitar.getProperty("composition.name") + ":");
 
65
                        
 
66
                        final Text name = new Text(group, SWT.BORDER);
 
67
                        name.setLayoutData(makeTextData());
 
68
                        name.setText(song.getName());
 
69
                        //-------ARTIST------------------------------------
 
70
                        Label artistLabel = new Label(group, SWT.NULL);
 
71
                        artistLabel.setLayoutData(makeLabelData());
 
72
                        artistLabel.setText(TuxGuitar.getProperty("composition.artist") + ":");
 
73
                        
 
74
                        final Text artist = new Text(group, SWT.BORDER);
 
75
                        artist.setLayoutData(makeTextData());
 
76
                        artist.setText(song.getArtist());
 
77
                        //-------ALBUM------------------------------------
 
78
                        Label albumLabel = new Label(group, SWT.NULL);
 
79
                        albumLabel.setLayoutData(makeLabelData());
 
80
                        albumLabel.setText(TuxGuitar.getProperty("composition.album") + ":");
 
81
                        
 
82
                        final Text album = new Text(group, SWT.BORDER);
 
83
                        album.setLayoutData(makeTextData());
 
84
                        album.setText(song.getAlbum());
 
85
                        //-------AUTHOR------------------------------------
 
86
                        Label authorLabel = new Label(group, SWT.NULL);
 
87
                        authorLabel.setLayoutData(makeLabelData());
 
88
                        authorLabel.setText(TuxGuitar.getProperty("composition.author") + ":");
 
89
                        
 
90
                        final Text author = new Text(group, SWT.BORDER);
 
91
                        author.setLayoutData(makeTextData());
 
92
                        author.setText(song.getAuthor());
 
93
                        
 
94
                        //------------------BUTTONS--------------------------
 
95
                        Composite buttons = new Composite(dialog, SWT.NONE);
 
96
                        buttons.setLayout(new GridLayout(2,false));
 
97
                        buttons.setLayoutData(new GridData(SWT.RIGHT,SWT.FILL,true,true));
 
98
                        
 
99
                        final Button buttonOK = new Button(buttons, SWT.PUSH);
 
100
                        buttonOK.setText(TuxGuitar.getProperty("ok"));
 
101
                        buttonOK.setLayoutData(getButtonData());
 
102
                        buttonOK.addSelectionListener(new SelectionAdapter() {
 
103
                                public void widgetSelected(SelectionEvent arg0) {
 
104
                                        setProperties(name.getText(),artist.getText(),album.getText(),author.getText());
 
105
                                        dialog.dispose();
 
106
                                }
 
107
                        });
 
108
                        
 
109
                        Button buttonCancel = new Button(buttons, SWT.PUSH);
 
110
                        buttonCancel.setText(TuxGuitar.getProperty("cancel"));
 
111
                        buttonCancel.setLayoutData(getButtonData());
 
112
                        buttonCancel.addSelectionListener(new SelectionAdapter() {
 
113
                                public void widgetSelected(SelectionEvent arg0) {
 
114
                                        dialog.dispose();
 
115
                                }
 
116
                        });
 
117
                        
 
118
                        dialog.setDefaultButton( buttonOK );
 
119
                        
 
120
                        DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
 
121
                }
 
122
        }
 
123
        
 
124
        private GridLayout makeGroupLayout(int spacing){
 
125
                GridLayout layout = new GridLayout(2,false);
 
126
                layout.marginTop = spacing;
 
127
                layout.marginBottom = spacing;
 
128
                layout.marginLeft = spacing;
 
129
                layout.marginRight = spacing;
 
130
                layout.verticalSpacing = spacing;
 
131
                layout.horizontalSpacing = spacing;
 
132
                return layout;
 
133
        }
 
134
        
 
135
        private GridData makeTextData(){
 
136
                return new GridData(TEXT_WIDTH,SWT.DEFAULT);
 
137
        }
 
138
        
 
139
        private GridData makeLabelData(){
 
140
                return new GridData(SWT.RIGHT,SWT.CENTER,true,true);
 
141
        }
 
142
        
 
143
        private GridData getButtonData(){
 
144
                GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
 
145
                data.minimumWidth = 80;
 
146
                data.minimumHeight = 25;
 
147
                return data;
 
148
        }
 
149
        
 
150
        protected void setProperties(String name,String artist,String album,String author){
 
151
                //comienza el undoable
 
152
                UndoableChangeInfo undoable = UndoableChangeInfo.startUndo();
 
153
                
 
154
                getSongManager().setProperties(name,artist,album,author);
 
155
                TuxGuitar.instance().getFileHistory().setUnsavedFile();
 
156
                TuxGuitar.instance().showTitle();
 
157
                
 
158
                //termia el undoable
 
159
                addUndoableEdit(undoable.endUndo());
 
160
        }
 
161
}