Package flacenc.preferences

Source Code of flacenc.preferences.OptionsPreferencePage

/*******************************************************************************
* Copyright 2008 Christian Mader
*
* This file is part of Perestrojka.
* Perestrojka is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Perestrojka 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.
*
* You should have received a copy of the GNU General Public License
* along with Perestrojka.  If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
package flacenc.preferences;

import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
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.Scale;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

import flac.Activator;

public class OptionsPreferencePage extends PreferencePage implements
    IWorkbenchPreferencePage
{
  private Scale compressionScale;
  private Label currentCompressionLabel;
 
  @Override
  protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    composite.setLayout(new GridLayout(1, false));
   
    Group compression = new Group(composite, SWT.NONE);
    compression.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    compression.setLayout(new FillLayout(SWT.HORIZONTAL));
    compression.setText("Compression level");
   
    Composite sliderComposite = new Composite(compression, SWT.NONE);
    sliderComposite.setLayout(new GridLayout(3, false));
    new Label(sliderComposite, SWT.NONE).setText("Fast");
    compressionScale = new Scale(sliderComposite, SWT.NONE);
    compressionScale.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    new Label(sliderComposite, SWT.NONE).setText("Best");
   
    Composite labelComposite = new Composite(compression, SWT.NONE);
    labelComposite.setLayout(new GridLayout(1, true));
    currentCompressionLabel = new Label(labelComposite, SWT.NONE);
    currentCompressionLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
   
    compressionScale.setMaximum(8);
    compressionScale.setMinimum(0);
    compressionScale.setIncrement(1);
    compressionScale.setPageIncrement(1);
   
    int selection = Activator.getDefault().getPreferenceStore().getInt(PreferenceConstants.P_COMPRESSION);
    compressionScale.setSelection(selection);
    updateQualityLabel(selection);
    compressionScale.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        updateQualityLabel(compressionScale.getSelection());
      }
    });
   
    return composite;
  }
 
  private void updateQualityLabel(int newValue)
  {
    currentCompressionLabel.setText("Value: " +newValue);
    currentCompressionLabel.getParent().layout();
  }
 
  @Override
  public boolean performOk() {
    Activator.getDefault().getPreferenceStore().setValue(PreferenceConstants.P_COMPRESSION, compressionScale.getSelection());
    return true;
  }
 
  @Override
  protected void performDefaults() {
    int defaultQuality = Activator.getDefault().getPreferenceStore().getDefaultInt(PreferenceConstants.P_COMPRESSION);
    compressionScale.setSelection(defaultQuality);
    updateQualityLabel(defaultQuality);
  }

  public void init(IWorkbench workbench) {
    setPreferenceStore(Activator.getDefault().getPreferenceStore());
  }
}
TOP

Related Classes of flacenc.preferences.OptionsPreferencePage

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.