2
* Created on 17-dic-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.gui.actions.composition;
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;
30
* TODO To change the template for this generated type comment go to
31
* Window - Preferences - Java - Code Style - Code Templates
33
public class ChangeInfoAction extends Action{
34
public static final String NAME = "action.composition.change-info";
36
private static final int TEXT_WIDTH = 300;
38
public ChangeInfoAction() {
39
super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | KEY_BINDING_AVAILABLE);
42
protected int execute(TypedEvent e){
43
showDialog(getEditor().getTablature().getShell());
47
public void showDialog(Shell shell) {
48
TGSong song = getSongManager().getSong();
50
final Shell dialog = DialogUtils.newDialog(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
52
dialog.setLayout(new GridLayout());
53
dialog.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
54
dialog.setText(TuxGuitar.getProperty("composition.properties"));
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"));
61
//-------NAME------------------------------------
62
Label nameLabel = new Label(group, SWT.NULL);
63
nameLabel.setLayoutData(makeLabelData());
64
nameLabel.setText(TuxGuitar.getProperty("composition.name") + ":");
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") + ":");
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") + ":");
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") + ":");
90
final Text author = new Text(group, SWT.BORDER);
91
author.setLayoutData(makeTextData());
92
author.setText(song.getAuthor());
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));
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());
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) {
118
dialog.setDefaultButton( buttonOK );
120
DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
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;
135
private GridData makeTextData(){
136
return new GridData(TEXT_WIDTH,SWT.DEFAULT);
139
private GridData makeLabelData(){
140
return new GridData(SWT.RIGHT,SWT.CENTER,true,true);
143
private GridData getButtonData(){
144
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
145
data.minimumWidth = 80;
146
data.minimumHeight = 25;
150
protected void setProperties(String name,String artist,String album,String author){
151
//comienza el undoable
152
UndoableChangeInfo undoable = UndoableChangeInfo.startUndo();
154
getSongManager().setProperties(name,artist,album,author);
155
TuxGuitar.instance().getFileHistory().setUnsavedFile();
156
TuxGuitar.instance().showTitle();
159
addUndoableEdit(undoable.endUndo());