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

📄 ngscaledimage.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 java.util.ArrayList;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.*;

import com.novocode.naf.app.*;
import com.novocode.naf.color.ColorData;
import com.novocode.naf.data.Orientation;
import com.novocode.naf.data.XMLProperty;
import com.novocode.naf.resource.*;
import com.novocode.naf.swt.custom.ScaledImage;


/**
 * A scaled image.
 * 
 * @author Stefan Zeiger (szeiger@novocode.com)
 * @since Mar 21, 2005
 */

public final class NGScaledImage extends NGWidget
{
  private String imageResource;
  private ColorData[] gradientColors;
  private Orientation gradientOrientation = Orientation.HORIZONTAL;
  private int[] gradientWeights;


  @XMLProperty("image")
  public void setImageResource(String s) { this.imageResource = s; }
  public String getImageResource() { return imageResource; }


  @XMLProperty public void setGradientOrientation(Orientation ori) { this.gradientOrientation = ori; }
  public Orientation getGradientOrientation() { return gradientOrientation; }


  @XMLProperty public void setGradientColors(ColorData[] cda) { this.gradientColors = cda; }
  public ColorData[] getGradientColors() { return gradientColors; }


  @XMLProperty public void setGradientWeights(int[] weights) { this.gradientWeights = weights; }
  public int[] getGradientWeights() { return gradientWeights; }

  
  protected void init() throws NAFException
  {
    if(gradientWeights != null && gradientColors != null)
    {
      if(gradientColors.length != gradientWeights.length+1)
        throw new NAFException("Length of gradientWeights must be one less than length of gradientColors");
    }
    if(gradientColors != null && gradientWeights == null)
    {
      gradientWeights = new int[gradientColors.length-1];
      for(int i=0; i<gradientWeights.length-1; i++)
        gradientWeights[i] = (int)(100.0 / gradientWeights.length * (i+1));
      if(gradientWeights.length != 0) gradientWeights[gradientWeights.length-1] = 100;
    }
    super.init();
    if(gradientColors != null) setBackgroundColor(ColorData.DEFAULT);
  }

  
  public Control createControl(Composite parent, NGComponent parentComp, ShellWindowInstance wi, WidgetData pwd) throws NAFException
  {
    final ScaledImage si = new ScaledImage(parent, SWT.NONE);

    if(imageResource != null)
    {
      si.setImage(SWTUtil.getRegisteredImage(imageResource, getResourceURL(), si, wi.imageManager, true));
    }

    if(gradientColors != null)
    {
      final ArrayList<Color> allocList = new ArrayList<Color>();
      Color[] colors = new Color[gradientColors.length];
      for(int i=0; i<colors.length; i++)
      {
        ColorData c = gradientColors[i];
        if(c.getType() == ColorData.TYPE_SYSTEM_COLOR) colors[i] = wi.display.getSystemColor(c.systemColorCode);
        else if(c.getType() == ColorData.TYPE_CUSTOM_COLOR)
        {
          colors[i] = c.createCustomColor(wi.display);
          allocList.add(colors[i]);
        }
        else if(c.getType() == ColorData.TYPE_INHERIT)
        {
          if(pwd != null && pwd.givenBG != null) colors[i] = pwd.givenBG;
          else colors[i] = si.getBackground();
        }
        else // TYPE_DEFAULT
        {
          colors[i] = si.getBackground();
        }
        if(allocList.size() != 0)
        {
          si.addDisposeListener(new DisposeListener()
          {
            public void widgetDisposed(DisposeEvent e)
            {
              for(Color c : allocList) c.dispose();
            }
          });
        }
      }
      si.setBackground(colors, gradientWeights, gradientOrientation == Orientation.VERTICAL);
    }

    return si;
  }
}

⌨️ 快捷键说明

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