public static void saveAndOpen(final String file) {
    ActionLock.lock();

    TuxGuitar.instance().getPlayer().reset();

    if (TuxGuitar.instance().getFileHistory().isUnsavedFile()) {
      ConfirmDialog confirm =
          new ConfirmDialog(TuxGuitar.getProperty("file.save-changes-question"));
      confirm.setDefaultStatus(ConfirmDialog.STATUS_CANCEL);
      int status =
          confirm.confirm(
              ConfirmDialog.BUTTON_YES | ConfirmDialog.BUTTON_NO | ConfirmDialog.BUTTON_CANCEL,
              ConfirmDialog.BUTTON_YES);
      if (status == ConfirmDialog.STATUS_CANCEL) {
        ActionLock.unlock();
        return;
      }
      if (status == ConfirmDialog.STATUS_YES) {
        final String fileName = FileActionUtils.getFileName();
        if (fileName == null) {
          ActionLock.unlock();
          return;
        }
        TuxGuitar.instance().loadCursor(SWT.CURSOR_WAIT);
        new Thread(
                new Runnable() {
                  public void run() {
                    if (!TuxGuitar.isDisposed()) {
                      FileActionUtils.save(fileName);
                      new SyncThread(
                              new Runnable() {
                                public void run() {
                                  if (!TuxGuitar.isDisposed()) {
                                    TuxGuitar.instance().loadCursor(SWT.CURSOR_ARROW);
                                    openFile(file);
                                  }
                                }
                              })
                          .start();
                    }
                  }
                })
            .start();
        return;
      }
    }
    openFile(file);
  }
Beispiel #2
0
  protected int execute(TypedEvent e) {
    if (TuxGuitar.instance().getFileHistory().isUnsavedFile()) {
      ConfirmDialog confirm =
          new ConfirmDialog(TuxGuitar.getProperty("file.save-changes-question"));
      confirm.setDefaultStatus(ConfirmDialog.STATUS_CANCEL);
      int status =
          confirm.confirm(
              ConfirmDialog.BUTTON_YES | ConfirmDialog.BUTTON_NO | ConfirmDialog.BUTTON_CANCEL,
              ConfirmDialog.BUTTON_YES);
      if (status == ConfirmDialog.STATUS_CANCEL) {
        return AUTO_UNLOCK;
      }
      if (status == ConfirmDialog.STATUS_YES) {
        final String fileName = FileActionUtils.getFileName();
        if (fileName == null) {
          return AUTO_UNLOCK;
        }
        TuxGuitar.instance().loadCursor(SWT.CURSOR_WAIT);
        new Thread(
                new Runnable() {
                  public void run() {
                    if (!TuxGuitar.isDisposed()) {
                      FileActionUtils.save(fileName);
                      TuxGuitar.instance().loadCursor(SWT.CURSOR_ARROW);
                      new SyncThread(
                              new Runnable() {
                                public void run() {
                                  if (!TuxGuitar.isDisposed()) {
                                    newSong();
                                  }
                                }
                              })
                          .start();
                    }
                  }
                })
            .start();
        return 0;
      }
    }
    newSong();

    return 0;
  }
  protected void open(Shell shell) {
    this.accepted = false;

    final Shell dialog = DialogUtils.newDialog(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

    dialog.setLayout(new GridLayout());
    dialog.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    dialog.setImage(TuxGuitar.instance().getIconManager().getAppIcon());
    dialog.setText(TuxGuitar.getProperty("tuxguitar-community.share-dialog.title"));

    Group group = new Group(dialog, SWT.SHADOW_ETCHED_IN);
    group.setLayout(makeGroupLayout(5));
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    group.setText(TuxGuitar.getProperty("tuxguitar-community.share-dialog.details"));

    // -------USERNAME---------------------------------
    Label usernameLabel = new Label(group, SWT.NULL);
    usernameLabel.setLayoutData(makeLabelData());
    usernameLabel.setText(
        TuxGuitar.getProperty("tuxguitar-community.share-dialog.details.user") + ":");

    final Text usernameText = new Text(group, SWT.BORDER | SWT.READ_ONLY);
    usernameText.setLayoutData(makeUsernameTextData());
    usernameText.setText(TGCommunitySingleton.getInstance().getAuth().getUsername());

    final Button usernameChooser = new Button(group, SWT.PUSH);
    usernameChooser.setText("...");
    usernameChooser.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            TGCommunityAuthDialog authDialog = new TGCommunityAuthDialog();
            authDialog.open(dialog);
            if (authDialog.isAccepted()) {
              TGCommunitySingleton.getInstance().getAuth().update();
              usernameText.setText(TGCommunitySingleton.getInstance().getAuth().getUsername());
            }
          }
        });

    // -------TITLE------------------------------------
    Label titleLabel = new Label(group, SWT.NULL);
    titleLabel.setLayoutData(makeLabelData());
    titleLabel.setText(
        TuxGuitar.getProperty("tuxguitar-community.share-dialog.details.title") + ":");

    final Text titleText = new Text(group, SWT.BORDER);
    titleText.setLayoutData(makeTextData());
    titleText.setText(this.file.getTitle());

    // -------TAGKEYS------------------------------------
    Label tagkeysLabel = new Label(group, SWT.NULL);
    tagkeysLabel.setLayoutData(makeLabelData());
    tagkeysLabel.setText(
        TuxGuitar.getProperty("tuxguitar-community.share-dialog.details.tagkeys") + ":");

    final Text tagkeysText = new Text(group, SWT.BORDER);
    tagkeysText.setLayoutData(makeTextData());
    tagkeysText.setText(this.file.getTagkeys());

    // -------DESCRIPTION------------------------------------
    Label descriptionLabel = new Label(group, SWT.NULL);
    descriptionLabel.setLayoutData(makeLabelData());
    descriptionLabel.setText(
        TuxGuitar.getProperty("tuxguitar-community.share-dialog.details.description") + ":");

    final Text descriptionText = new Text(group, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
    descriptionText.setLayoutData(makeTextAreaData());
    descriptionText.setText(this.file.getDescription());

    // ------------------BUTTONS--------------------------
    Composite buttons = new Composite(dialog, SWT.NONE);
    buttons.setLayout(new GridLayout(2, false));
    buttons.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true));

    final Button buttonOK = new Button(buttons, SWT.PUSH);
    buttonOK.setText(TuxGuitar.getProperty("ok"));
    buttonOK.setLayoutData(getButtonData());
    buttonOK.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            update(titleText.getText(), tagkeysText.getText(), descriptionText.getText());

            dialog.dispose();
          }
        });

    Button buttonCancel = new Button(buttons, SWT.PUSH);
    buttonCancel.setText(TuxGuitar.getProperty("cancel"));
    buttonCancel.setLayoutData(getButtonData());
    buttonCancel.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            dialog.dispose();
          }
        });

    dialog.setDefaultButton(buttonOK);

    if (this.errors != null) {
      MessageDialog.errorMessage(dialog, this.errors);
    }
    DialogUtils.openDialog(
        dialog,
        DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
  }
  public static PrintStyles open(Shell shell) {
    final PrintStyles styles = new PrintStyles();
    final Shell dialog = DialogUtils.newDialog(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new GridLayout());
    dialog.setText(TuxGuitar.getProperty("options"));

    // ------------------TRACK SELECTION------------------
    Group track = new Group(dialog, SWT.SHADOW_ETCHED_IN);
    track.setLayout(new GridLayout(2, false));
    track.setLayoutData(getGroupData());
    track.setText(TuxGuitar.getProperty("track"));

    Label trackLabel = new Label(track, SWT.NULL);
    trackLabel.setText(TuxGuitar.getProperty("track"));

    final Combo tracks = new Combo(track, SWT.DROP_DOWN | SWT.READ_ONLY);
    tracks.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    for (int number = 1;
        number <= TuxGuitar.instance().getSongManager().getSong().countTracks();
        number++) {
      tracks.add(TuxGuitar.instance().getSongManager().getTrack(number).getName());
    }
    tracks.select(
        TuxGuitar.instance().getTablatureEditor().getTablature().getCaret().getTrack().getNumber()
            - 1);

    // ------------------MEASURE RANGE------------------
    Group range = new Group(dialog, SWT.SHADOW_ETCHED_IN);
    range.setLayout(new GridLayout(2, false));
    range.setLayoutData(getGroupData());
    range.setText(TuxGuitar.getProperty("print.range"));

    final int minSelection = 1;
    final int maxSelection = TuxGuitar.instance().getSongManager().getSong().countMeasureHeaders();

    Label fromLabel = new Label(range, SWT.NULL);
    fromLabel.setText(TuxGuitar.getProperty("edit.from"));
    final Spinner fromSpinner = new Spinner(range, SWT.BORDER);
    fromSpinner.setLayoutData(getSpinnerData());
    fromSpinner.setMaximum(maxSelection);
    fromSpinner.setMinimum(minSelection);
    fromSpinner.setSelection(minSelection);

    Label toLabel = new Label(range, SWT.NULL);
    toLabel.setText(TuxGuitar.getProperty("edit.to"));
    final Spinner toSpinner = new Spinner(range, SWT.BORDER);
    toSpinner.setLayoutData(getSpinnerData());
    toSpinner.setMinimum(minSelection);
    toSpinner.setMaximum(maxSelection);
    toSpinner.setSelection(maxSelection);

    fromSpinner.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            int fromSelection = fromSpinner.getSelection();
            int toSelection = toSpinner.getSelection();

            if (fromSelection < minSelection) {
              fromSpinner.setSelection(minSelection);
            } else if (fromSelection > toSelection) {
              fromSpinner.setSelection(toSelection);
            }
          }
        });
    toSpinner.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            int toSelection = toSpinner.getSelection();
            int fromSelection = fromSpinner.getSelection();
            if (toSelection < fromSelection) {
              toSpinner.setSelection(fromSelection);
            } else if (toSelection > maxSelection) {
              toSpinner.setSelection(maxSelection);
            }
          }
        });
    // ------------------CHECK OPTIONS--------------------
    Group options = new Group(dialog, SWT.SHADOW_ETCHED_IN);
    options.setLayout(new GridLayout());
    options.setLayoutData(getGroupData());
    options.setText(TuxGuitar.getProperty("options"));

    final Button tablatureEnabled = new Button(options, SWT.CHECK);
    tablatureEnabled.setText(TuxGuitar.getProperty("export.tablature-enabled"));
    tablatureEnabled.setSelection(true);

    final Button scoreEnabled = new Button(options, SWT.CHECK);
    scoreEnabled.setText(TuxGuitar.getProperty("export.score-enabled"));
    scoreEnabled.setSelection(true);

    final Button chordNameEnabled = new Button(options, SWT.CHECK);
    chordNameEnabled.setText(TuxGuitar.getProperty("export.chord-name-enabled"));
    chordNameEnabled.setSelection(true);

    final Button chordDiagramEnabled = new Button(options, SWT.CHECK);
    chordDiagramEnabled.setText(TuxGuitar.getProperty("export.chord-diagram-enabled"));
    chordDiagramEnabled.setSelection(true);

    final Button blackAndWhite = new Button(options, SWT.CHECK);
    blackAndWhite.setText(TuxGuitar.getProperty("export.black-and-white"));
    blackAndWhite.setSelection(true);

    tablatureEnabled.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            if (!tablatureEnabled.getSelection()) {
              scoreEnabled.setSelection(true);
            }
          }
        });
    scoreEnabled.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            if (!scoreEnabled.getSelection()) {
              tablatureEnabled.setSelection(true);
            }
          }
        });

    // ------------------BUTTONS--------------------------
    Composite buttons = new Composite(dialog, SWT.NONE);
    buttons.setLayout(new GridLayout(2, false));
    buttons.setLayoutData(new GridData(SWT.END, SWT.FILL, true, true));

    final Button buttonOK = new Button(buttons, SWT.PUSH);
    buttonOK.setText(TuxGuitar.getProperty("ok"));
    buttonOK.setLayoutData(getButtonData());
    buttonOK.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            int style = 0;
            style |= (scoreEnabled.getSelection() ? ViewLayout.DISPLAY_SCORE : 0);
            style |= (tablatureEnabled.getSelection() ? ViewLayout.DISPLAY_TABLATURE : 0);
            style |= (chordNameEnabled.getSelection() ? ViewLayout.DISPLAY_CHORD_NAME : 0);
            style |= (chordDiagramEnabled.getSelection() ? ViewLayout.DISPLAY_CHORD_DIAGRAM : 0);
            styles.setTrackNumber(tracks.getSelectionIndex() + 1);
            styles.setFromMeasure(fromSpinner.getSelection());
            styles.setToMeasure(toSpinner.getSelection());
            styles.setBlackAndWhite(blackAndWhite.getSelection());
            styles.setStyle(style);
            dialog.dispose();
          }
        });

    Button buttonCancel = new Button(buttons, SWT.PUSH);
    buttonCancel.setText(TuxGuitar.getProperty("cancel"));
    buttonCancel.setLayoutData(getButtonData());
    buttonCancel.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            dialog.dispose();
          }
        });

    dialog.setDefaultButton(buttonOK);

    DialogUtils.openDialog(
        dialog,
        DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);

    return ((styles.getTrackNumber() > 0) ? styles : null);
  }
 public String getName() {
   return TuxGuitar.getProperty("browser.factory.fs.name");
 }
  protected void open(Shell parent) {
    final Shell dialog = DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM);
    dialog.setLayout(new GridLayout());
    dialog.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    dialog.setImage(TuxGuitar.instance().getIconManager().getAppIcon());
    dialog.setText(TuxGuitar.getProperty("tuxguitar-community.welcome-dialog.title"));

    Composite composite = new Composite(dialog, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(MAIN_WIDTH, MAIN_HEIGHT));

    // ==============================================================//
    Composite top = new Composite(composite, SWT.NONE);
    top.setLayout(new GridLayout(2, false));
    top.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite topLeft = new Composite(top, SWT.NONE);
    topLeft.setLayout(new GridLayout());
    topLeft.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));

    Label image = new Label(topLeft, SWT.NONE);
    image.setImage(TuxGuitar.instance().getIconManager().getAppIcon());

    Composite topRight = new Composite(top, SWT.NONE);
    topRight.setLayout(new GridLayout(2, false));
    topRight.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    addTitle(topRight, TuxGuitar.getProperty("tuxguitar-community.welcome-dialog.title"));

    addTipItem(topRight);
    addComment(topRight, TuxGuitar.getProperty("tuxguitar-community.welcome-dialog.tip-1"));

    addTipItem(topRight);
    addComment(topRight, TuxGuitar.getProperty("tuxguitar-community.welcome-dialog.tip-2"));

    // ==============================================================//
    Composite bottom = new Composite(composite, SWT.NONE);
    bottom.setLayout(new GridLayout());
    bottom.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    addComment(bottom, TuxGuitar.getProperty("tuxguitar-community.welcome-dialog.tip-bottom"));

    // ==============================================================//
    Composite buttons = new Composite(composite, SWT.NONE);
    buttons.setLayout(new GridLayout(2, false));
    buttons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Button buttonDisabled = new Button(buttons, SWT.CHECK);
    buttonDisabled.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, true, true));
    buttonDisabled.setText(TuxGuitar.getProperty("tuxguitar-community.welcome-dialog.disable"));
    buttonDisabled.setSelection(this.isDisabled());

    final Button buttonOK = new Button(buttons, SWT.PUSH);
    buttonOK.setText(TuxGuitar.getProperty("ok"));
    buttonOK.setLayoutData(getButtonOkData());
    buttonOK.setFocus();
    buttonOK.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            setDisabled(buttonDisabled.getSelection());
            dialog.dispose();
          }
        });

    dialog.setDefaultButton(buttonOK);

    DialogUtils.openDialog(dialog, DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK);
  }
 public void loadProperties() {
   if (!isDisposed()) {
     this.dialog.setText(TuxGuitar.getProperty("lyric.editor"));
     this.fromLabel.setText(TuxGuitar.getProperty("edit.from"));
   }
 }