Package org.jampa.gui.wizard.playlistsgenerator

Source Code of org.jampa.gui.wizard.playlistsgenerator.PlaylistGeneratorIntroPage

/*
* Jampa
* Copyright (C) 2008-2009 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*/

package org.jampa.gui.wizard.playlistsgenerator;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import org.jampa.gui.translations.Messages;
import org.jampa.model.validators.PlaylistNameValidator;

public class PlaylistGeneratorIntroPage extends WizardPage {
 
  private Composite container;
 
  private Button btnNormalMode;
  private Button btnAdvancedMode;
  private Text tePlaylistName;
  private Spinner spSongsNumber;
  private Button ckPlay;
 
  private PlaylistNameValidator nameValidator;
  private boolean boPlaylistNameOk = false;
 
  public PlaylistGeneratorIntroPage() {
    super("PlaylistGeneratorWizard"); //$NON-NLS-1$
    setTitle(Messages.getString("PlaylistGeneratorWizard.Title")); //$NON-NLS-1$
    setDescription(Messages.getString("PlaylistGeneratorWizard.IntroText")); //$NON-NLS-1$
   
    nameValidator = new PlaylistNameValidator();
  }

  @Override
  public void createControl(Composite parent) {       
    container = new Composite(parent, SWT.NULL);
   
    GridLayout gl = new GridLayout(2, false);
    container.setLayout(gl);
   
    Label laPlaylistName = new Label(container, SWT.NONE);
    laPlaylistName.setText(Messages.getString("PlaylistGeneratorWizard.PlaylistName")); //$NON-NLS-1$
    tePlaylistName = new Text(container, SWT.BORDER);
    tePlaylistName.setText(Messages.getString("NewPlaylistAction.DefaultName")); //$NON-NLS-1$
    tePlaylistName.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    tePlaylistName.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        checkPlaylistName();
        getWizard().getContainer().updateButtons();
      }     
    });   
   
    Label laSongsNumber = new Label(container, SWT.NONE);
    laSongsNumber.setText(Messages.getString("PlaylistGeneratorWizard.SongsNumber")); //$NON-NLS-1$
   
    spSongsNumber = new Spinner(container, SWT.BORDER);
    spSongsNumber.setMinimum(1);
    spSongsNumber.setMaximum(10000);
    spSongsNumber.setSelection(100);
    spSongsNumber.setIncrement(1);
    spSongsNumber.setPageIncrement(100);
    spSongsNumber.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
   
    Group modeGroup = new Group(container, SWT.NONE);
    modeGroup.setLayout(new GridLayout(1, false));
    modeGroup.setText(Messages.getString("PlaylistGeneratorWizard.GeneratorMode")); //$NON-NLS-1$
    GridData gd = new GridData();
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    modeGroup.setLayoutData(gd);
   
    btnNormalMode = new Button(modeGroup, SWT.RADIO);
    btnNormalMode.setText(Messages.getString("PlaylistGeneratorWizard.GeneratorNormalMode")); //$NON-NLS-1$
    btnNormalMode.setSelection(true);
    btnNormalMode.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent arg0) {
        getWizard().getContainer().updateButtons();
      }
    });
   
    btnAdvancedMode = new Button(modeGroup, SWT.RADIO);
    btnAdvancedMode.setText(Messages.getString("PlaylistGeneratorWizard.GeneratorAdvancedMode")); //$NON-NLS-1$
    btnAdvancedMode.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent arg0) {
        getWizard().getContainer().updateButtons();
      }
    });
   
    ckPlay = new Button(container, SWT.CHECK);
    ckPlay.setText(Messages.getString("PlaylistGeneratorWizard.Play")); //$NON-NLS-1$

    tePlaylistName.setSelection(0, tePlaylistName.getText().length());
   
    // Required to avoid an error in the system
    setControl(container);
    setPageComplete(true);
    checkPlaylistName();
  }
 
  public IWizardPage getNextPage(){
    if (btnAdvancedMode.getSelection()) {
      PlaylistGeneratorGenrePage page = ((PlaylistGeneratorWizard)getWizard()).genrePage;
      page.fillList();
      return page;
    }       
    return null;
  }
 
  public void checkPlaylistName() {   
    String result = nameValidator.isValid(tePlaylistName.getText());
    if (result != null) {
      setErrorMessage(result);
      boPlaylistNameOk = false;
    } else {
      setErrorMessage(null);
      boPlaylistNameOk = true;
    }
   
    if (tePlaylistName.getText().isEmpty()) {
      boPlaylistNameOk = false;
    }
    setPageComplete(boPlaylistNameOk);   
  }
 
  public boolean canFlipToNextPage(){
    return boPlaylistNameOk && btnAdvancedMode.getSelection();
  }
 
  public boolean getPlay() {
    return ckPlay.getSelection();
  }
 
  public String getPlaylistName() {
    return tePlaylistName.getText();
  }
 
  public int getSongsNumber() {
    return spSongsNumber.getSelection();
  }
 
  public boolean isAdvancedMode() {
    return btnAdvancedMode.getSelection();
  }
 
  public Control getControl() {
    return container;
  }

}
TOP

Related Classes of org.jampa.gui.wizard.playlistsgenerator.PlaylistGeneratorIntroPage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.