Package giggler.ui.plugin

Source Code of giggler.ui.plugin.UISettings$SettingsSurface

package giggler.ui.plugin;

import giggler.ui.*;
import giggler.ui.swt.skin.themes.Theme;
import giggler.ui.swt.skin.themes.ThemeFactory;

import java.util.ArrayList;

import org.eclipse.swt.SWT;
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.*;



public class UISettings implements Settings
{
    private java.util.List<Control> changedControlList = new ArrayList<Control>();

    private String storedTheme = null;
   
//    private Composite priceComposite = null;
//    private Label priceDescriptionLabel = null;
    private Combo themeComboBox = null;
    private ChangeListener changeListener = null;

   
    public Composite createComposite(Composite parent) {

        SettingsSurface settingsSurface = new SettingsSurface();
       
        Composite settingsComposite = settingsSurface.create(parent);
       
        return settingsComposite;
    }
   
    public void setChangeListener(ChangeListener changeListener) {
   
        this.changeListener = changeListener;
    }

    public void load(Config config) {

        storedTheme = config.get(UIEnvironment.ACTIVE_THEME);
       
        if (storedTheme != null) {
           
            if (themeComboBox!=null && !themeComboBox.isDisposed())
                setUITheme(storedTheme);
        }
    }

    public void store(Config config) {

        String theme = getUITheme();

        storedTheme = theme;
       
        config.set(UIEnvironment.ACTIVE_THEME, theme);
    }
   
    public void apply() {
       
        String theme = getUITheme();
       
        ThemeFactory.setTheme(theme);
       
        storedTheme = theme;
    }
   
    // PRIVATE //////////////////////////////////////////////////////////////////////////////////////////

    private void setUIChange(Control control, boolean isChanged) {

        int index = changedControlList.indexOf(control);
       
        if (isChanged) {
           
            if (index < 0)
                changedControlList.add(control);

            changeListener.changed();

        } else if (index > -1) {
           
            changedControlList.remove(index);
           
            changeListener.unchanged();
        }
    }

    private void setUITheme(String theme) {
       
      boolean selectionChanged = false;
     
      if (theme == null) {

        selectionChanged = (themeComboBox.getSelectionIndex() > -1);
       
        themeComboBox.clearSelection();
       
      } else {

        for (int i=0; i < themeComboBox.getItemCount(); i++) {

          if (theme.equals(themeComboBox.getItem(i))) {

            themeComboBox.select(i);
            selectionChanged = true;
            break;
          }
        }
      }
     
        setUIChange(themeComboBox, selectionChanged);
    }

    private String getUITheme() {
       
        if (themeComboBox == null)
            return null;
       
        int index = themeComboBox.getSelectionIndex();
       
        if (index < 0)
            return null;
       
        return themeComboBox.getItem(index);
    }
   
    // INNER CLASS //////////////////////////////////////////////////////////////////////////////////////
   
    class SettingsSurface extends Surface
    {
        public Composite create(final Composite parent) {
           
            GridLayout gridLayout = null;
            GridData gridData = null;

            Composite composite = new Composite(parent, SWT.NONE);

            gridLayout = new GridLayout(1, false);

            composite.setLayout(gridLayout);

            Label descriptionTitleLabel = new Label(composite, SWT.TRANSPARENT);
            changeFont(descriptionTitleLabel, +2, true);
            descriptionTitleLabel.setText(UiPlugin.PLUGIN);
           
            gridData = new GridData(H_GRAB_FILL);

            descriptionTitleLabel.setLayoutData(gridData);

            Label descriptionLabel = new Label(composite, SWT.WRAP|SWT.TRANSPARENT);
            descriptionLabel.setText(
                "Responsible for visual management of the available plugins.");

            gridData = new GridData(H_GRAB_FILL);
            gridData.horizontalIndent = 10;

            descriptionLabel.setLayoutData(gridData);
           
            Label themeTitleLabel = new Label(composite, SWT.TRANSPARENT);
            changeFont(themeTitleLabel, +2, true);
            themeTitleLabel.setText("Theme");

            gridData = new GridData(H_GRAB_FILL);

            themeTitleLabel.setLayoutData(gridData);

//            Label themeDescriptionLabel = new Label(composite, SWT.WRAP|SWT.TRANSPARENT);
//            themeDescriptionLabel.setText("x\nx\n");
//           
//            gridData = new GridData(H_GRAB_FILL);
//            gridData.horizontalIndent = 10;
//            gridData.heightHint = 28;
//
//            themeDescriptionLabel.setLayoutData(gridData);

            Composite themeComposite = new Composite(composite, SWT.TRANSPARENT);
           
            gridLayout = configLayout(new GridLayout(1, false), 1);

            themeComposite.setLayout(gridLayout);

            gridData = new GridData();
            gridData.horizontalIndent = 20;
            gridData.grabExcessHorizontalSpace = true;

            themeComposite.setLayoutData(gridData);

            themeComboBox = new Combo(themeComposite, SWT.DROP_DOWN|SWT.READ_ONLY);

            gridData = new GridData(V_GRAB_FILL);
//            gridData.horizontalIndent = 10;
            gridData.widthHint = 200;
//
            themeComboBox.setLayoutData(gridData);

            themeComboBox.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {

                    Combo combo = (Combo) e.widget;
                   
                    System.out.println("widget="+e.widget+" selected="+combo.getSelectionIndex());
                   
                    if (combo.getSelectionIndex() > -1) {
                       
//                        combo.getSelectionIndex();
//                       
//                        priceDescriptionLabel.setText(priceOption.description.replace('\n', ' '));
                       
                        setUIChange(themeComboBox,
                            themeComboBox.getItem(combo.getSelectionIndex()) != storedTheme);
                    }
                }
            });
           
            Theme themes[] = ThemeFactory.getThemes();
           
            for (Theme theme : themes) {

                themeComboBox.add(theme.getName());
            }
           
            setUITheme(storedTheme);
          
            return composite;
        }
    }
}
TOP

Related Classes of giggler.ui.plugin.UISettings$SettingsSurface

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.