⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ngslider.java

📁 Novocode的 SWT 控件框架 丰富了MDI功能
💻 JAVA
字号:
/*******************************************************************************
 * Copyright (c) 2004 Stefan Zeiger and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.novocode.com/legal/epl-v10.html
 * 
 * Contributors:
 *     Stefan Zeiger (szeiger@novocode.com) - initial API and implementation
 *******************************************************************************/

package com.novocode.naf.gui;

import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.*;

import com.novocode.naf.app.*;
import com.novocode.naf.data.ModelBinding;
import com.novocode.naf.data.Orientation;
import com.novocode.naf.data.XMLProperty;
import com.novocode.naf.gui.event.*;
import com.novocode.naf.model.*;
import com.novocode.naf.resource.*;


/**
 * A slider control.
 * 
 * @author Stefan Zeiger (szeiger@novocode.com)
 * @since Mar 1, 2004
 */

public final class NGSlider extends NGWidget
{
  private int min, max = 15, increment = 1, pageIncrement = 4, thumb = 1;
  private Orientation orientation = Orientation.HORIZONTAL;


  @XMLProperty
  public void setOrientation(Orientation o) { this.orientation = o; }
  public Orientation getOrientation() { return orientation; }


  @XMLProperty
  public void setMin(int i) { this.min = i; }
  public int getMin() { return min; }


  @XMLProperty
  public void setMax(int i) { this.max = i; }
  public int getMax() { return max; }


  @XMLProperty
  public void setThumb(int i) { this.thumb = i; }
  public int getThumb() { return thumb; }


  @XMLProperty
  public void setIncrement(int i) { this.increment = i; }
  public int getIncrement() { return increment; }


  @XMLProperty
  public void setPageIncrement(int i) { this.pageIncrement = i; }
  public int getPageIncrement() { return pageIncrement; }

  
  public Control createControl(Composite parent, NGComponent parentComp, ShellWindowInstance wi, WidgetData pwd) throws NAFException
  {
    final Slider slider = new Slider(parent, orientation.style);
    slider.setMinimum(min);
    slider.setMaximum(max);
    slider.setIncrement(increment);
    slider.setPageIncrement(pageIncrement);
    slider.setThumb(thumb);

    // [TODO] Allow a SliderModel or ScaleModel to be used
    final IIntModel valueModel = getModel("value", wi.models);
    if(valueModel != null)
    {
      final boolean[] lock = new boolean[1];
      IChangeListener cl = new IChangeListener()
      {
        public void stateChanged(ChangeEvent e)
        {
          int i = valueModel.getInt();
          if(i == slider.getSelection()) return;
          try
          {
            lock[0] = true;
            slider.setSelection(i);
          }
          finally { lock[0] = false; }
        }
      };
      SWTUtil.registerModel(slider, valueModel, cl);
      cl.stateChanged(null);

      slider.addSelectionListener(new SelectionAdapter()
      {
        public void widgetSelected(SelectionEvent e)
        {
          if(!lock[0]) valueModel.setInt(slider.getSelection());
        }
      });
    }
    
    return slider;
  }


  protected Object createDefaultModel(ModelBinding mb)
  {
    if("value".equals(mb.type)) return new DefaultIntModel();
    else return super.createDefaultModel(mb);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -