用SWT画了一个QQ2006的界面

最近心血来潮,学习了一下SWT,感觉确实比Swing要美观,而且运行速度也比较快。光学不做,可不是我的作风,于是我用SWT画了一个QQ2006的个人设置中的“个人资料”界面,画得不好请SWT高手指教。
QQ原图

使用SWT画的图(修改于2007年5月12日,添加了几张图片,修改了背景颜色和一些细节。)


源代码(其中的mum.jpg和rank.jpg都存放在工程主目录下)

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;


public class QQ
{

    
private Text introText;
    
private Combo constellationCombo;
    
private Combo jobCombo;
    
private Combo animalCombo;
    
private Combo bloodCombo;
    
private Text schoolText;
    
private Text frontPageText;
    
private Text oleText;
    
private Text nameText;
    
private Combo sexCombo;
    
private Canvas rank;
    
private Text attachName;
    
private Text nickName;
    
private Text text;
    
private List selectList;
    
private StackLayout stackLayout = new StackLayout();
    
private Composite composite;
    
private Composite composite_1;
    
private Composite rightComp;
    
private static Image image;
    
private static Image rankimage;
    
/**
     * Launch the application
     * 
@param args
     
*/

    
public static void main(String[] args)
    
{
        
try
        
{
            QQ window 
= new QQ();
            window.open();
        }
 catch (Exception e)
        
{
            e.printStackTrace();
        }

    }


    
/**
     * Open the window
     
*/

    
public void open()
    
{
        
final Display display = Display.getDefault();
        
final Shell shell = new Shell();
        shell.setBackground(SWTResourceManager.getColor(
103172231));
        shell.setLayout(
new GridLayout());
        shell.setSize(
500400);
            shell.setLocation(262, 184);
        shell.setText(
"QQ2006设置");
        
//

        shell.open();

        
final SashForm sashForm = new SashForm(shell, SWT.NONE);
        sashForm.setForeground(SWTResourceManager.getColor(
103172231));
        sashForm.setLayoutData(
new GridData(GridData.FILL_BOTH));
        selectList 
= new List(sashForm, SWT.NONE);
        selectList.addMouseListener(
new MouseAdapter() {
            
public void mouseDown(MouseEvent arg0)
            
{
                
int selectionIndex=selectList.getSelectionIndex();
                
if(selectionIndex==0)
                stackLayout.topControl
=composite;
                
else
                stackLayout.topControl
=composite_1;
                rightComp.layout();
            }

        }
);
        selectList.setItems(
new String[] {"个人资料""联系方式"});
        

        rightComp 
= new Composite(sashForm, SWT.NONE);
        rightComp.setBackground(SWTResourceManager.getColor(
23255255));
    
        rightComp.setLayout(stackLayout);

        composite 
= new Composite(rightComp, SWT.BORDER);
        composite.setForeground(SWTResourceManager.getColor(
00255));
        composite.setBackground(SWTResourceManager.getColor(
255255255));
        GridLayout gridLayout
=new GridLayout(6,false);
        gridLayout.horizontalSpacing
=10;
        composite.setLayout(gridLayout);
        
final Label titleLabel = new Label(composite, SWT.NONE);
        titleLabel.setForeground(SWTResourceManager.getColor(
12597));
        titleLabel.setBackground(SWTResourceManager.getColor(
229241253));
        titleLabel.setFont(SWTResourceManager.getFont(
""11, SWT.BOLD));
        titleLabel.setText(
"个人设置-个人资料");
        GridData gridData3
=new GridData(GridData.FILL_HORIZONTAL);
         gridData3.horizontalSpan
=6;
        titleLabel.setLayoutData(gridData3);
        
final Label label1 = new Label(composite, SWT.NONE);
        label1.setBackground(SWTResourceManager.getColor(
255255255));
        label1.setText(
"用户号码:");
        text 
= new Text(composite, SWT.READ_ONLY | SWT.BORDER);
        text.setBackground(SWTResourceManager.getColor(
255255255));
        GridData gridData
=new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan
=3;
        text.setLayoutData(gridData);
        
final Composite photoComp = new Composite(composite, SWT.NONE);
        photoComp.setBackground(SWTResourceManager.getColor(
255255255));
        gridData
=new GridData(GridData.HORIZONTAL_ALIGN_FILL|GridData.VERTICAL_ALIGN_FILL);
        gridData.horizontalSpan
=2;
        gridData.verticalSpan
=2;
        photoComp.setLayoutData(gridData);
        photoComp.setLayout(
new GridLayout(2,false));

        
final Composite tempComp = new Composite(photoComp, SWT.BORDER);
        tempComp.setLayout(
new FillLayout());
        tempComp.setLayoutData(
new GridData(30,30));

        
final Canvas canvas = new Canvas(tempComp, SWT.NONE);
        image
=new Image(display,"mum.jpg");
        canvas.redraw();
        canvas.addPaintListener(
new PaintListener() {
            
public void paintControl(PaintEvent event)
            
{
                
if(image!=null)
                    event.gc.drawImage(image,
0,0);
            }

        }
);
        
        
final Button setPhotoButton = new Button(photoComp, SWT.DOWN);
        setPhotoButton.setLayoutData(
new GridData(GridData.VERTICAL_ALIGN_END));
        setPhotoButton.setText(
"更改");

        
final Label label2 = new Label(composite, SWT.NONE);
        label2.setBackground(SWTResourceManager.getColor(
255255255));
        label2.setText(
"用户昵称:");

        nickName 
= new Text(composite, SWT.BORDER);
        gridData
=new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan
=3;
        nickName.setLayoutData(gridData);

        
final Label label3 = new Label(composite, SWT.NONE);
        label3.setBackground(SWTResourceManager.getColor(
255255255));
        gridData
=new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
        label3.setLayoutData(gridData);
        label3.setText(
"个性签名:");

        attachName 
= new Text(composite, SWT.BORDER);
        gridData
=new GridData(GridData.FILL_BOTH);
        gridData.horizontalSpan
=5;
        gridData.verticalSpan
=2;
        attachName.setLayoutData(gridData);
        
final Label label22 = new Label(composite, SWT.NONE);
        
final Label labe24 = new Label(composite, SWT.NONE);
        labe24.setBackground(SWTResourceManager.getColor(
255255255));
        labe24.setText(
"会员阶段:");
        
final Label labe23 = new Label(composite, SWT.NONE);
        
final Label label4 = new Label(composite, SWT.NONE);
        label4.setBackground(SWTResourceManager.getColor(
255255255));
        label4.setText(
"QQ等级:");

        rank 
= new Canvas(composite, SWT.NONE);
        rank.addPaintListener(
new PaintListener() {
            
public void paintControl(PaintEvent event)
            
{
                event.gc.drawImage(rankimage, 
00);
            }

        }
);
        rank.setBackground(SWTResourceManager.getColor(
255255255));
        gridData
=new GridData(SWT.FILL, SWT.CENTER, truefalse31);
        gridData.heightHint 
= 17;
        rank.setLayoutData(gridData);
        rankimage
=new Image(display,"rank.jpg");
        rank.redraw();

        
final Label label5 = new Label(composite, SWT.NONE);
        label5.setBackground(SWTResourceManager.getColor(
255255255));
        label5.setLayoutData(
new GridData());
        label5.setText(
"性    别:");

        sexCombo 
= new Combo(composite, SWT.NONE);
        sexCombo.setItems(
new String[] {""""});
        sexCombo.setText("男");


        
final Label label6 = new Label(composite, SWT.NONE);
        label6.setBackground(SWTResourceManager.getColor(
255255255));
        label6.setText(
"姓名:");

        nameText 
= new Text(composite, SWT.BORDER);
        nameText.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_FILL));

        
final Label label7 = new Label(composite, SWT.NONE);
        label7.setBackground(SWTResourceManager.getColor(
255255255));
        label7.setText(
"年龄:");

        oleText 
= new Text(composite, SWT.BORDER);
        oleText.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_FILL));

        
final Label label8 = new Label(composite, SWT.NONE);
        label8.setBackground(SWTResourceManager.getColor(
255255255));
        label8.setText(
"毕业院校:");

        schoolText 
= new Text(composite, SWT.BORDER);
        gridData
=new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan
=3;
        schoolText.setLayoutData(gridData);

        
final Label label9 = new Label(composite, SWT.NONE);
        label9.setBackground(SWTResourceManager.getColor(
255255255));
        label9.setText(
"生肖:");

        animalCombo 
= new Combo(composite, SWT.NONE);
        animalCombo.setItems(
new String[] {""""""});
        animalCombo.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_FILL));
        animalCombo.setText("鸡")
;

        
final Label label10 = new Label(composite, SWT.NONE);
        label10.setBackground(SWTResourceManager.getColor(
255255255));
        label10.setText(
"职    业:");

        jobCombo 
= new Combo(composite, SWT.BORDER);
        jobCombo.setItems(
new String[] {"计算机业""学生"});
        gridData
=new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan
=3;
        jobCombo.setLayoutData(gridData);
        jobCombo.setText("计算机业");


        
final Label label11 = new Label(composite, SWT.NONE);
        label11.setBackground(SWTResourceManager.getColor(
255255255));
        label11.setText(
"星座:");

        constellationCombo 
= new Combo(composite, SWT.NONE);
        constellationCombo.setItems(
new String[] {"牧羊座""金牛座"});
        constellationCombo.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_FILL));
        constellationCombo.setText("牧羊座");

        
        
final Label label28 = new Label(composite, SWT.NONE);
        label28.setBackground(SWTResourceManager.getColor(
255255255));
        label28.setText(
"个人主页:");

        frontPageText 
= new Text(composite, SWT.BORDER);
        gridData
=new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan
=3;
        frontPageText.setLayoutData(gridData);

        
final Label label29 = new Label(composite, SWT.NONE);
        label29.setBackground(SWTResourceManager.getColor(
255255255));
        label29.setText(
"血型:");

        bloodCombo 
= new Combo(composite, SWT.NONE);
        bloodCombo.setItems(
new String[] {"A型""B型""O型""AB型""其他"});
        bloodCombo.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_FILL));
        bloodCombo.setText("O型")
;

        
final Label introLabel = new Label(composite, SWT.NONE);
        introLabel.setBackground(SWTResourceManager.getColor(
255255255));
        introLabel.setLayoutData(
new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
        introLabel.setText(
"个人说明:");

        introText 
= new Text(composite, SWT.WRAP | SWT.BORDER);
        gridData
=new GridData(GridData.HORIZONTAL_ALIGN_FILL|GridData.FILL_VERTICAL);
        gridData.horizontalSpan
=5;
        introText.setLayoutData(gridData);

        composite_1 
= new Composite(rightComp, SWT.NONE);
        composite_1.setLayout(
new FillLayout());

        
final Label label = new Label(composite_1, SWT.NONE);
        label.setText(
"联系方式面板");
        stackLayout.topControl 
= composite;
        

        
final Composite buttonComp = new Composite(shell, SWT.NONE);
        buttonComp.setBackground(SWTResourceManager.getColor(
107172231));
        gridData
=new GridData();
        gridData.horizontalAlignment
=GridData.END;
        buttonComp.setLayoutData(gridData);
        RowLayout rowLayout
=new RowLayout();
        rowLayout.spacing
=15;
        buttonComp.setLayout(rowLayout);

        
final Button button = new Button(buttonComp, SWT.NONE);
        button.setForeground(SWTResourceManager.getColor(
0255255));
        button.setBackground(SWTResourceManager.getColor(
182222255));
        button.setText(
"   确定   ");

        
final Button button_1 = new Button(buttonComp, SWT.NONE);
        button_1.setText(
"   取消   ");

        
final Button button_2 = new Button(buttonComp, SWT.NONE);
        button_2.setText(
"   应用   ");
        sashForm.setWeights(
new int[] {14 });
        shell.layout();
        
while (!shell.isDisposed())
        
{
            
if (!display.readAndDispatch())
                display.sleep();
        }

    }

}

package com.swtdesigner;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

/**
 * Utility class for managing OS resources associated with SWT controls such as
 * colors, fonts, images, etc.
 * 
 * !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code>
 * method to release the operating system resources managed by cached objects
 * when those objects and OS resources are no longer needed (e.g. on
 * application shutdown)
 * 
 * This class may be freely distributed as part of any application or plugin.
 * <p>
 * Copyright (c) 2003 - 2005, Instantiations, Inc. <br>All Rights Reserved
 * 
 * 
@author scheglov_ke
 * 
@author Dan Rubel
 
*/

public class SWTResourceManager {

    
/**
     * Dispose of cached objects and their underlying OS resources. This should
     * only be called when the cached objects are no longer needed (e.g. on
     * application shutdown)
     
*/

    
public static void dispose() {
        disposeColors();
        disposeFonts();
        disposeImages();
        disposeCursors();
    }


    
//////////////////////////////
    
// Color support
    //////////////////////////////

    
/**
     * Maps RGB values to colors
     
*/

    
private static HashMap<RGB, Color> m_ColorMap = new HashMap<RGB, Color>();

    
/**
     * Returns the system color matching the specific ID
     * 
@param systemColorID int The ID value for the color
     * 
@return Color The system color matching the specific ID
     
*/

    
public static Color getColor(int systemColorID) {
        Display display 
= Display.getCurrent();
        
return display.getSystemColor(systemColorID);
    }


    
/**
     * Returns a color given its red, green and blue component values
     * 
@param r int The red component of the color
     * 
@param g int The green component of the color
     * 
@param b int The blue component of the color
     * 
@return Color The color matching the given red, green and blue componet values
     
*/

    
public static Color getColor(int r, int g, int b) {
        
return getColor(new RGB(r, g, b));
    }


    
/**
     * Returns a color given its RGB value
     * 
@param rgb RGB The RGB value of the color
     * 
@return Color The color matching the RGB value
     
*/

    
public static Color getColor(RGB rgb) {
        Color color 
= m_ColorMap.get(rgb);
        
if (color == null{
            Display display 
= Display.getCurrent();
            color 
= new Color(display, rgb);
            m_ColorMap.put(rgb, color);
        }

        
return color;
    }


    
/**
     * Dispose of all the cached colors
     
*/

    
public static void disposeColors() {
        
for (Iterator iter = m_ColorMap.values().iterator(); iter.hasNext();)
             ((Color) iter.next()).dispose();
        m_ColorMap.clear();
    }


    
//////////////////////////////
    
// Image support
    //////////////////////////////

    
/**
     * Maps image names to images
     
*/

    
private static HashMap<String, Image> m_ClassImageMap = new HashMap<String, Image>();

    
/**
     * Maps images to image decorators
     
*/

    
private static HashMap<Image, HashMap<Image, Image>> m_ImageToDecoratorMap = new HashMap<Image, HashMap<Image, Image>>();

    
/**
     * Returns an image encoded by the specified input stream
     * 
@param is InputStream The input stream encoding the image data
     * 
@return Image The image encoded by the specified input stream
     
*/

    
protected static Image getImage(InputStream is) {
        Display display 
= Display.getCurrent();
        ImageData data 
= new ImageData(is);
        
if (data.transparentPixel > 0)
            
return new Image(display, data, data.getTransparencyMask());
        
return new Image(display, data);
    }


    
/**
     * Returns an image stored in the file at the specified path
     * 
@param path String The path to the image file
     * 
@return Image The image stored in the file at the specified path
     
*/

    
public static Image getImage(String path) {
        
return getImage("default", path); //$NON-NLS-1$
    }


    
/**
     * Returns an image stored in the file at the specified path
     * 
@param section The section to which belongs specified image
     * 
@param path String The path to the image file
     * 
@return Image The image stored in the file at the specified path
     
*/

    
public static Image getImage(String section, String path) {
        String key 
= section + '|' + SWTResourceManager.class.getName() + '|' + path;
        Image image 
= m_ClassImageMap.get(key);
        
if (image == null{
            
try {
                FileInputStream fis 
= new FileInputStream(path);
                image 
= getImage(fis);
                m_ClassImageMap.put(key, image);
                fis.close();
            }
 catch (Exception e) {
                image 
= getMissingImage();
                m_ClassImageMap.put(key, image);
            }

        }

        
return image;
    }


    
/**
     * Returns an image stored in the file at the specified path relative to the specified class
     * 
@param clazz Class The class relative to which to find the image
     * 
@param path String The path to the image file
     * 
@return Image The image stored in the file at the specified path
     
*/

    
public static Image getImage(Class clazz, String path) {
        String key 
= clazz.getName() + '|' + path;
        Image image 
= m_ClassImageMap.get(key);
        
if (image == null{
            
try {
                
if (path.length() > 0 && path.charAt(0== '/'{
                    String newPath 
= path.substring(1, path.length());
                    image 
= getImage(new BufferedInputStream(clazz.getClassLoader().getResourceAsStream(newPath)));
                }
 else {
                    image 
= getImage(clazz.getResourceAsStream(path));
                }

                m_ClassImageMap.put(key, image);
            }
 catch (Exception e) {
                image 
= getMissingImage();
                m_ClassImageMap.put(key, image);
            }

        }

        
return image;
    }


    
private static final int MISSING_IMAGE_SIZE = 10;
    
private static Image getMissingImage() {
        Image image 
= new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
        
//
        GC gc = new GC(image);
        gc.setBackground(getColor(SWT.COLOR_RED));
        gc.fillRectangle(
00, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
        gc.dispose();
        
//
        return image;
    }


    
/**
     * Style constant for placing decorator image in top left corner of base image.
     
*/

    
public static final int TOP_LEFT = 1;
    
/**
     * Style constant for placing decorator image in top right corner of base image.
     
*/

    
public static final int TOP_RIGHT = 2;
    
/**
     * Style constant for placing decorator image in bottom left corner of base image.
     
*/

    
public static final int BOTTOM_LEFT = 3;
    
/**
     * Style constant for placing decorator image in bottom right corner of base image.
     
*/

    
public static final int BOTTOM_RIGHT = 4;
    
    
/**
     * Returns an image composed of a base image decorated by another image
     * 
@param baseImage Image The base image that should be decorated
     * 
@param decorator Image The image to decorate the base image
     * 
@return Image The resulting decorated image
     
*/

    
public static Image decorateImage(Image baseImage, Image decorator) {
        
return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
    }

    
    
/**
     * Returns an image composed of a base image decorated by another image
     * 
@param baseImage Image The base image that should be decorated
     * 
@param decorator Image The image to decorate the base image
     * 
@param corner The corner to place decorator image
     * 
@return Image The resulting decorated image
     
*/

    
public static Image decorateImage(Image baseImage, Image decorator, int corner) {
        HashMap
<Image, Image> decoratedMap = m_ImageToDecoratorMap.get(baseImage);
        
if (decoratedMap == null{
            decoratedMap 
= new HashMap<Image, Image>();
            m_ImageToDecoratorMap.put(baseImage, decoratedMap);
        }

        Image result 
= decoratedMap.get(decorator);
        
if (result == null{
            Rectangle bid 
= baseImage.getBounds();
            Rectangle did 
= decorator.getBounds();
            result 
= new Image(Display.getCurrent(), bid.width, bid.height);
            GC gc 
= new GC(result);
            gc.drawImage(baseImage, 
00);
            
//
            if (corner == TOP_LEFT) {
                gc.drawImage(decorator, 
00);
            }
 else if (corner == TOP_RIGHT) {
                gc.drawImage(decorator, bid.width 
- did.width - 10);
            }
 else if (corner == BOTTOM_LEFT) {
                gc.drawImage(decorator, 
0, bid.height - did.height - 1);
            }
 else if (corner == BOTTOM_RIGHT) {
                gc.drawImage(decorator, bid.width 
- did.width - 1, bid.height - did.height - 1);
            }

            
//
            gc.dispose();
            decoratedMap.put(decorator, result);
        }

        
return result;
    }


    
/**
     * Dispose all of the cached images
     
*/

    
public static void disposeImages() {
        
for (Iterator I = m_ClassImageMap.values().iterator(); I.hasNext();)
             ((Image) I.next()).dispose();
        m_ClassImageMap.clear();
        
//
        for (Iterator I = m_ImageToDecoratorMap.values().iterator(); I.hasNext();) {
            HashMap decoratedMap 
= (HashMap) I.next();
            
for (Iterator J = decoratedMap.values().iterator(); J.hasNext();) {
                Image image 
= (Image) J.next();
                image.dispose();
            }

        }

    }


    
/**
     * Dispose cached images in specified section
     * 
@param section the section do dispose
     
*/

    
public static void disposeImages(String section) {
        
for (Iterator I = m_ClassImageMap.keySet().iterator(); I.hasNext();) {
            String key 
= (String) I.next();
            
if (!key.startsWith(section + '|'))
                
continue;
            Image image 
= m_ClassImageMap.get(key);
            image.dispose();
            I.remove();
        }

    }


    
//////////////////////////////
    
// Font support
    //////////////////////////////

    
/**
     * Maps font names to fonts
     
*/

    
private static HashMap<String, Font> m_FontMap = new HashMap<String, Font>();

    
/**
     * Maps fonts to their bold versions
     
*/

    
private static HashMap<Font, Font> m_FontToBoldFontMap = new HashMap<Font, Font>();

    
/**
     * Returns a font based on its name, height and style
     * 
@param name String The name of the font
     * 
@param height int The height of the font
     * 
@param style int The style of the font
     * 
@return Font The font matching the name, height and style
     
*/

    
public static Font getFont(String name, int height, int style) {
        
return getFont(name, height, style, falsefalse);
    }



    
/**
     * Returns a font based on its name, height and style. 
     * Windows-specific strikeout and underline flags are also supported.
     * 
@param name String The name of the font
     * 
@param size int The size of the font
     * 
@param style int The style of the font
     * 
@param strikeout boolean The strikeout flag (warning: Windows only)
     * 
@param underline boolean The underline flag (warning: Windows only)
     * 
@return Font The font matching the name, height, style, strikeout and underline
     
*/

    
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
        String fontName 
= name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
        Font font 
= m_FontMap.get(fontName);
        
if (font == null{
            FontData fontData 
= new FontData(name, size, style);
            
if (strikeout || underline) {
                
try {
                    Class logFontClass 
= Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$
                    Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$
                    if (logFont != null && logFontClass != null{
                        
if (strikeout) {
                            logFontClass.getField(
"lfStrikeOut").set(logFont, new Byte((byte1)); //$NON-NLS-1$
                        }

                        
if (underline) {
                            logFontClass.getField(
"lfUnderline").set(logFont, new Byte((byte1)); //$NON-NLS-1$
                        }

                    }

                }
 catch (Throwable e) {
                    System.err.println(
                        
"Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
                }

            }

            font 
= new Font(Display.getCurrent(), fontData);
            m_FontMap.put(fontName, font);
        }

        
return font;
    }

    

    
/**
     * Return a bold version of the give font
     * 
@param baseFont Font The font for whoch a bold version is desired
     * 
@return Font The bold version of the give font
     
*/

    
public static Font getBoldFont(Font baseFont) {
        Font font 
= m_FontToBoldFontMap.get(baseFont);
        
if (font == null{
            FontData fontDatas[] 
= baseFont.getFontData();
            FontData data 
= fontDatas[0];
            font 
= new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
            m_FontToBoldFontMap.put(baseFont, font);
        }

        
return font;
    }


    
/**
     * Dispose all of the cached fonts
     
*/

    
public static void disposeFonts() {
        
for (Iterator iter = m_FontMap.values().iterator(); iter.hasNext();)
             ((Font) iter.next()).dispose();
        m_FontMap.clear();
    }


    
//////////////////////////////
    
// CoolBar support
    //////////////////////////////

    
/**
     * Fix the layout of the specified CoolBar
     * 
@param bar CoolBar The CoolBar that shgoud be fixed
     
*/

    
public static void fixCoolBarSize(CoolBar bar) {
        CoolItem[] items 
= bar.getItems();
        
// ensure that each item has control (at least empty one)
        for (int i = 0; i < items.length; i++{
            CoolItem item 
= items[i];
            
if (item.getControl() == null)
                item.setControl(
new Canvas(bar, SWT.NONE) {
                @Override
                
public Point computeSize(int wHint, int hHint, boolean changed) {
                    
return new Point(2020);
                }

            }
);
        }

        
// compute size for each item
        for (int i = 0; i < items.length; i++{
            CoolItem item 
= items[i];
            Control control 
= item.getControl();
            control.pack();
            Point size 
= control.getSize();
            item.setSize(item.computeSize(size.x, size.y));
        }

    }


    
//////////////////////////////
    
// Cursor support
    //////////////////////////////

    
/**
     * Maps IDs to cursors
     
*/

    
private static HashMap<Integer, Cursor> m_IdToCursorMap = new HashMap<Integer, Cursor>();
 
    
/**
     * Returns the system cursor matching the specific ID
     * 
@param id int The ID value for the cursor
     * 
@return Cursor The system cursor matching the specific ID
     
*/

    
public static Cursor getCursor(int id) {
        Integer key 
= new Integer(id);
        Cursor cursor 
= m_IdToCursorMap.get(key);
        
if (cursor == null{
            cursor 
= new Cursor(Display.getDefault(), id);
            m_IdToCursorMap.put(key, cursor);
        }

        
return cursor;
    }

 
    
/**
     * Dispose all of the cached cursors
     
*/

    
public static void disposeCursors() {
        
for (Iterator iter = m_IdToCursorMap.values().iterator(); iter.hasNext();)
             ((Cursor) iter.next()).dispose();
        m_IdToCursorMap.clear();
    }

}


posted on 2007-05-07 21:27 我为J狂 阅读(5272) 评论(14)  编辑  收藏 所属分类: 图形用户界面

评论

# re: 用SWT画了一个QQ2006的界面 2007-05-08 08:08 久城

SWT和SWING我都没有深入的研究过,有时间我也要细细的体会下。
给我的感觉好像SWING的潜力更大一些。就象JBuilder,就是Swing的杰作。  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面 2007-05-08 09:58 BeanSoft

SWT 不能换肤, 所以想要界面完全仿 QQ 难度有些大, 这时候基本上得用 Canvas 组件自己来画一些组件. 国内做的好的开源的当属基于 SWT 的 LumaQQ, 可惜因为没有形成团队, 加上Tencent的阻挠, 已经很久未更新了.  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面 2007-05-11 11:38 我为J狂

@久城
但是你没有发现用Swing生成界面的速度比SWT生成界面的速度要慢得多吗?  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面[未登录] 2007-05-11 13:10 Roger

你的美术功底比较差,对图形界面的细节没有很强的敏感性,建议你有空练习一下绘画  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面 2007-05-11 13:37 我为J狂

@Roger
能不能说得具体一点,究竟是哪一方面的细节,说清楚了,我才能改进呀!  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面[未登录] 2007-05-11 17:26 Roger

具体的地方太多了,说不完的,也不好说清楚。最好自己体会。
建议你研究一下azure画的瑞星杀毒。  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面 2007-05-11 18:45 我为J狂

@Roger
我是SWT的初学者,开来我要走的路还很长,任重而道远。  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面 2007-05-12 10:37 我为J狂

今天,我将程序修改了一下,感觉比以前的效果要好一些,大家认为怎么样?请留言评价一下。  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面 2007-06-09 22:13 itkui

不错呀。
我是学jsp,企业级开发的。
所以用不着他们了!  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面 2007-06-10 08:46 我为J狂

@itkui
我也是用JSP开发的,不过我对未知的领域挺好奇的。  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面 2007-09-28 12:13 千里冰封

用SWING吧,SWT太差了  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面 2007-10-18 14:06 黑巧克力

@千里冰封
swt差?正因为swing的缺陷大才会有swt的出现。SWT调用系统低层,显示出的界面会跟系统界面没有任何出入。比起swing难以忍受的画面要好的多。而且最大的优势就是性能  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面 2007-10-18 21:21 我为J狂

同意,看看Eclipse和JBuilder的界面,就知道SWT和Swing哪个更漂亮了。  回复  更多评论   

# re: 用SWT画了一个QQ2006的界面 2009-02-12 21:45 SWT

@我为J狂
那个漂亮不重要,重要的是美工做的好不好,从性能上比较的话还是SWT好一点
  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2007年5月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

统计

常用链接

留言簿(11)

随笔分类(48)

文章分类(29)

常去逛逛

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜