Package oggenc.preferences

Source Code of oggenc.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 oggenc.preferences;

import oggenc.Activator;

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;

public class OptionsPreferencePage extends PreferencePage implements
    IWorkbenchPreferencePage
{
  private Scale qualityScale;
  private Label currentQualityValueLabel;
 
  @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 quality = new Group(composite, SWT.NONE);
    quality.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    quality.setLayout(new FillLayout(SWT.HORIZONTAL));
    quality.setText("Quality");
   
    Composite sliderComposite = new Composite(quality, SWT.NONE);
    sliderComposite.setLayout(new GridLayout(3, false));
    new Label(sliderComposite, SWT.NONE).setText("Low");
    qualityScale = new Scale(sliderComposite, SWT.NONE);
    qualityScale.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    new Label(sliderComposite, SWT.NONE).setText("High");
   
    Composite labelComposite = new Composite(quality, SWT.NONE);
    labelComposite.setLayout(new GridLayout(1, false));
    currentQualityValueLabel = new Label(labelComposite, SWT.NONE);
    currentQualityValueLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
   
    qualityScale.setMaximum(10);
    qualityScale.setMinimum(0);
    qualityScale.setIncrement(1);
    qualityScale.setPageIncrement(1);
   
    int selection = Activator.getDefault().getPreferenceStore().getInt(PreferenceConstants.P_QUALITY);
    qualityScale.setSelection(selection);
    updateQualityLabel(selection);
    qualityScale.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        updateQualityLabel(qualityScale.getSelection());
      }
    });
   
    return composite;
  }
 
  private void updateQualityLabel(int newValue)
  {
    currentQualityValueLabel.setText("Value: " +newValue);
    currentQualityValueLabel.getParent().layout();
  }
 
  @Override
  public boolean performOk() {
    Activator.getDefault().getPreferenceStore().setValue(PreferenceConstants.P_QUALITY, qualityScale.getSelection());
    return true;
  }
 
  @Override
  protected void performDefaults() {
    int defaultQuality = Activator.getDefault().getPreferenceStore().getDefaultInt(PreferenceConstants.P_QUALITY);
    qualityScale.setSelection(defaultQuality);
    updateQualityLabel(defaultQuality);
  }

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

Related Classes of oggenc.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.