??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲视频在线一区观看,久久一区国产,日韩久久精品一区二区三区http://www.aygfsteel.com/hengheng123456789/category/16704.htmlzh-cnSun, 12 Aug 2007 03:35:13 GMTSun, 12 Aug 2007 03:35:13 GMT60SWT 控g?/title><link>http://www.aygfsteel.com/hengheng123456789/articles/79899.html</link><dc:creator>哼哼</dc:creator><author>哼哼</author><pubDate>Wed, 08 Nov 2006 08:55:00 GMT</pubDate><guid>http://www.aygfsteel.com/hengheng123456789/articles/79899.html</guid><wfw:comment>http://www.aygfsteel.com/hengheng123456789/comments/79899.html</wfw:comment><comments>http://www.aygfsteel.com/hengheng123456789/articles/79899.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/hengheng123456789/comments/commentRss/79899.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/hengheng123456789/services/trackbacks/79899.html</trackback:ping><description><![CDATA[可以参考这文章:<br /><a >http://www.eclipse.org/swt/widgets/</a><br /><img src ="http://www.aygfsteel.com/hengheng123456789/aggbug/79899.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/hengheng123456789/" target="_blank">哼哼</a> 2006-11-08 16:55 <a href="http://www.aygfsteel.com/hengheng123456789/articles/79899.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SWT Layoutshttp://www.aygfsteel.com/hengheng123456789/articles/79894.html哼哼哼哼Wed, 08 Nov 2006 08:51:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/79894.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/79894.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/79894.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/79894.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/79894.html可以参看此文章,写得相当详细Q)
http://www.eclipse.org/articles/Article-Understanding-Layouts/Understanding-Layouts.htm



哼哼 2006-11-08 16:51 发表评论
]]>
SWT Drag and Drop http://www.aygfsteel.com/hengheng123456789/articles/79661.html哼哼哼哼Tue, 07 Nov 2006 10:05:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/79661.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/79661.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/79661.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/79661.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/79661.html1、拖拽Label的文字?br />
 public static void main (String [] args) {
  
  Display display = new Display ();
  final Shell shell = new Shell (display);
  shell.setLayout(new FillLayout());
  final Label label1 = new Label (shell, SWT.BORDER);
  label1.setText ("TEXT");
  final Label label2 = new Label (shell, SWT.BORDER);
  setDragDrop (label1);
  setDragDrop (label2);
  shell.setSize (200, 200);
  shell.open ();
  while (!shell.isDisposed ()) {
   if (!display.readAndDispatch ()) display.sleep ();
  }
  display.dispose ();
 }
 
 public static void setDragDrop (final Label label) {
  
  Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
  int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
  
  final DragSource source = new DragSource (label, operations);
  source.setTransfer(types);
  source.addDragListener (new DragSourceListener () {
   public void dragStart(DragSourceEvent event) {
    event.doit = (label.getText ().length () != 0);
   }
   public void dragSetData (DragSourceEvent event) {
    event.data = label.getText ();
   }
   public void dragFinished(DragSourceEvent event) {
    if (event.detail == DND.DROP_MOVE)
     label.setText ("");
   }
  });

  DropTarget target = new DropTarget(label, operations);
  target.setTransfer(types);
  target.addDropListener (new DropTargetAdapter() {
   public void drop(DropTargetEvent event) {
    if (event.data == null) {
     event.detail = DND.DROP_NONE;
     return;
    }
    label.setText ((String) event.data);
   }
  });
 }

2、随意拖拽Tree子节炏V?br />
 public static void main (String [] args) {
  
  final Display display = new Display ();
  final Shell shell = new Shell (display);
  shell.setLayout(new FillLayout());
  //建立用于拖拽的树
  final Tree tree = new Tree(shell, SWT.BORDER);
  for (int i = 0; i < 3; i++) {
   TreeItem item = new TreeItem(tree, SWT.NONE);
   item.setText("item "+i);
   for (int j = 0; j < 3; j++) {
    TreeItem subItem = new TreeItem(item, SWT.NONE);
    subItem.setText("item "+i+" "+j);
    for (int k = 0; k < 3; k++) {
     TreeItem subsubItem = new TreeItem(subItem, SWT.NONE);
     subsubItem.setText("item "+i+" "+j+" "+k);
    }
   }
  }
  
  Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
  int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
  
  //建立拖拽 源————树tree对象
  final DragSource source = new DragSource (tree, operations);
  source.setTransfer(types);
  final TreeItem[] dragSourceItem = new TreeItem[1];
  source.addDragListener (new DragSourceListener () {
   public void dragStart(DragSourceEvent event) {
    TreeItem[] selection = tree.getSelection(); // 获取所选tree的节?br />    if (selection.length > 0 && selection[0].getItemCount() == 0) //判断所选节Ҏ否存在ƈ且ؓ末端节点
    {
     event.doit = true; //启动拖拽功能
     dragSourceItem[0] = selection[0]; //保存拖拽节点信息
    } else {
     event.doit = false;
    }
   };
   public void dragSetData (DragSourceEvent event) {
    event.data = dragSourceItem[0].getText(); //保存拖拽节点信息C件数据中
   }
   public void dragFinished(DragSourceEvent event) {
    if (event.detail == DND.DROP_MOVE)
     dragSourceItem[0].dispose();
     dragSourceItem[0] = null;
   }
  });
  
  //建立拖拽 目的————树tree对象
  DropTarget target = new DropTarget(tree, operations);
  target.setTransfer(types);
  target.addDropListener (new DropTargetAdapter() {
   //处理拖拽到目的上I时的方?br />   public void dragOver(DropTargetEvent event) {
    event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL; //响应拖拽动作QFEEDBACK_EXPAND表示拖拽到可以展开的节Ҏ展开相应节点?br />    if (event.item != null) {
     TreeItem item = (TreeItem)event.item;
     //处理拖拽动作响应Q根据拖拽的位置不同产生不同的响?br />     Point pt = display.map(null, tree, event.x, event.y); //获取拖拽当前位置?br />     Rectangle bounds = item.getBounds(); //获取目的节点的边?br />     
     //Ҏ拖拽当前位置点与目的节点的边框位|设|响应,如显CZؓFEEDBACK_INSERT_BEFORE、FEEDBACK_INSERT_AFTER
     if (pt.y < bounds.y + bounds.height/3) {
      event.feedback |= DND.FEEDBACK_INSERT_BEFORE;
     } else if (pt.y > bounds.y + 2*bounds.height/3) {
      event.feedback |= DND.FEEDBACK_INSERT_AFTER;
     } else {
      event.feedback |= DND.FEEDBACK_SELECT;
     }
    }
   }
   //处理放下时的Ҏ
   public void drop(DropTargetEvent event) {
    if (event.data == null) {
     event.detail = DND.DROP_NONE;
     return;
    }
    String text = (String)event.data;
    //如果放下的位|没有节点,则新建立一个节点,以根节点为父节点
    if (event.item == null)
    {
     TreeItem item = new TreeItem(tree, SWT.NONE);
     item.setText(text);
    }
    //如果放下的位|有节点
    else
    {
     TreeItem item = (TreeItem)event.item;
     Point pt = display.map(null, tree, event.x, event.y);
     Rectangle bounds = item.getBounds();
     TreeItem parent = item.getParentItem();
     if (parent != null) {
      TreeItem[] items = parent.getItems();
      int index = 0;
      for (int i = 0; i < items.length; i++) {
       if (items[i] == item) {
        index = i;
        break;
       }
      }
      if (pt.y < bounds.y + bounds.height/3) {
       //以当前节点的父节点ؓ父徏立一个子节点Qƈ且插入到当前节点?br />       TreeItem newItem = new TreeItem(parent, SWT.NONE, index);
       newItem.setText(text);
      } else if (pt.y > bounds.y + 2*bounds.height/3) {
       //以当前节点的父节点ؓ父徏立一个子节点Qƈ且插入到当前节点?br />       TreeItem newItem = new TreeItem(parent, SWT.NONE, index+1);
       newItem.setText(text);
      } else {
       //以当前ؓ父节点徏立一个子节点
       TreeItem newItem = new TreeItem(item, SWT.NONE);
       newItem.setText(text);
      }
      
     } else {
      TreeItem[] items = tree.getItems();
      int index = 0;
      for (int i = 0; i < items.length; i++) {
       if (items[i] == item) {
        index = i;
        break;
       }
      }
      if (pt.y < bounds.y + bounds.height/3) {
       TreeItem newItem = new TreeItem(tree, SWT.NONE, index);
       newItem.setText(text);
      } else if (pt.y > bounds.y + 2*bounds.height/3) {
       TreeItem newItem = new TreeItem(tree, SWT.NONE, index+1);
       newItem.setText(text);
      } else {
       TreeItem newItem = new TreeItem(item, SWT.NONE);
       newItem.setText(text);
      }
     }
     
     
    }
   }
  });

  shell.setSize (400, 400);
  shell.open ();
  while (!shell.isDisposed ()) {
   if (!display.readAndDispatch ()) display.sleep ();
  }
  display.dispose ();
 }



哼哼 2006-11-07 18:05 发表评论
]]>
SWT Tool Tips实现QTool Tips c)http://www.aygfsteel.com/hengheng123456789/articles/79658.html哼哼哼哼Tue, 07 Nov 2006 09:39:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/79658.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/79658.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/79658.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/79658.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/79658.htmlTool Tips 实现囑փ内的Tool Tips ?br /> public static void main (String [] args) {
  Display display = new Display ();
  final Color [] colors = {
   display.getSystemColor (SWT.COLOR_RED),
   display.getSystemColor (SWT.COLOR_GREEN),
   display.getSystemColor (SWT.COLOR_BLUE),
  };
  final Rectangle [] rects = {
   new Rectangle (10, 10, 30, 30),
   new Rectangle (20, 45, 25, 35),
   new Rectangle (80, 80, 10, 10),
  };
  final Shell shell = new Shell (display);
  Listener mouseListener = new Listener () {
   public void handleEvent (Event event) {
    switch (event.type) {
     case SWT.MouseEnter:
     case SWT.MouseMove:
      for (int i=0; i<rects.length; i++) {
       if (rects [i].contains (event.x, event.y)) {
        String text = "ToolTip " + i;
        if (!(text.equals (shell.getToolTipText ()))) {
         shell.setToolTipText ("ToolTip " + i);
        }
        return;
       }
      }
      shell.setToolTipText (null);
      break;
     }
   }
  };
  shell.addListener (SWT.MouseMove, mouseListener);
  shell.addListener (SWT.MouseEnter, mouseListener);
  shell.addListener (SWT.Paint, new Listener () {
   public void handleEvent (Event event) {
    GC gc = event.gc;
    for (int i=0; i<rects.length; i++) {
     gc.setBackground (colors [i]);
     gc.fillRectangle (rects [i]);
     gc.drawRectangle (rects [i]);
    }
   }
  });
  shell.setSize (200, 200);
  shell.open ();
  while (!shell.isDisposed ()) {
   if (!display.readAndDispatch ()) display.sleep ();
  }
  display.dispose ();
 }

2、用Shell实现Tool Tip的功能?br /> public static void main (String[] args) {
  final Display display = new Display ();
  final Shell shell = new Shell (display);
  shell.setLayout (new FillLayout ());
  final Table table = new Table (shell, SWT.BORDER);
  for (int i = 0; i < 20; i++) {
   TableItem item = new TableItem (table, SWT.NONE);
   item.setText ("item " + i);
  }
  // Disable native tooltip
  table.setToolTipText ("");
  
  // Implement a "fake" tooltip
  final Listener labelListener = new Listener () {
   public void handleEvent (Event event) {
    Label label = (Label)event.widget;
    Shell shell = label.getShell ();
    switch (event.type) {
     case SWT.MouseDown:
      Event e = new Event ();
      e.item = (TableItem) label.getData ("_TABLEITEM");
      // Assuming table is single select, set the selection as if
      // the mouse down event went through to the table
      table.setSelection (new TableItem [] {(TableItem) e.item});
      table.notifyListeners (SWT.Selection, e);
      shell.dispose ();
      table.setFocus();
      break;
     case SWT.MouseExit:
      shell.dispose ();
      break;
    }
   }
  };
  
  Listener tableListener = new Listener () {
   Shell tip = null;
   Label label = null;
   public void handleEvent (Event event) {
    switch (event.type) {
     case SWT.Dispose:
     case SWT.KeyDown:
     case SWT.MouseMove: {
      if (tip == null) break;
      tip.dispose ();
      tip = null;
      label = null;
      break;
     }
     case SWT.MouseHover: {
      TableItem item = table.getItem (new Point (event.x, event.y));
      if (item != null) {
       if (tip != null  && !tip.isDisposed ()) tip.dispose ();
       //使用Shell实现Tool Tip的功?br />       tip = new Shell (shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
       tip.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
       FillLayout layout = new FillLayout ();
       layout.marginWidth = 2;
       tip.setLayout (layout);
       label = new Label (tip, SWT.NONE);
       label.setForeground (display.getSystemColor (SWT.COLOR_INFO_FOREGROUND));
       label.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
       label.setData ("_TABLEITEM", item);
       label.setText (item.getText ());
       label.addListener (SWT.MouseExit, labelListener);
       label.addListener (SWT.MouseDown, labelListener);
       Point size = tip.computeSize (SWT.DEFAULT, SWT.DEFAULT);
       Rectangle rect = item.getBounds (0);
       Point pt = table.toDisplay (rect.x, rect.y);
       tip.setBounds (pt.x, pt.y, size.x, size.y);
       tip.setVisible (true);
      }
     }
    }
   }
  };
  table.addListener (SWT.Dispose, tableListener);
  table.addListener (SWT.KeyDown, tableListener);
  table.addListener (SWT.MouseMove, tableListener);
  table.addListener (SWT.MouseHover, tableListener);
  shell.pack ();
  shell.open();
  while (!shell.isDisposed()) {
   if (!display.readAndDispatch())
    display.sleep();
  }
  display.dispose();
 }


哼哼 2006-11-07 17:39 发表评论
]]>
SWT Stack布局QStackLayout c)http://www.aygfsteel.com/hengheng123456789/articles/79648.html哼哼哼哼Tue, 07 Nov 2006 09:14:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/79648.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/79648.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/79648.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/79648.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/79648.html1、不同Componsit间的切换?br /> static int pageNum = -1;

 public static void main (String [] args) {
  Display display = new Display ();
  Shell shell = new Shell (display);
  shell.setBounds (10, 10, 300, 200);
  // create the composite that the pages will share
  final Composite contentPanel = new Composite (shell, SWT.BORDER);
  contentPanel.setBounds (100, 10, 190, 90);
  final StackLayout layout = new StackLayout ();
  contentPanel.setLayout (layout);

  // create the first page's content
  Composite page0;
  page0 = new Composite (contentPanel, SWT.NONE);
  page0.setLayout (new RowLayout ());
  Label label = new Label (page0, SWT.NONE);
  label.setText ("Label on page 1");
  label.pack ();

  // create the second page's content 
  Composite page1;
  page1 = new Composite (contentPanel, SWT.NONE);
  page1.setLayout (new RowLayout ());
  Button button = new Button (page1, SWT.NONE);
  button.setText ("Button on page 2");
  button.pack ();

  // create the button that will switch between the pages
  Button pageButton = new Button (shell, SWT.PUSH);
  pageButton.setText ("Push");
  pageButton.setBounds (10, 10, 80, 25);
  pageButton.addListener (SWT.Selection, new Listener () {
   public void handleEvent (Event event) {
    pageNum = ++pageNum % 2;
    contentPanel.layout ();
   }
  });
  layout.topControl = page0;

  shell.open ();
  while (!shell.isDisposed ()) {
   if (!display.readAndDispatch ()) display.sleep ();
  }
  display.dispose ();
 }



哼哼 2006-11-07 17:14 发表评论
]]>
SWT Swing/AWT QSwing/AWT c)http://www.aygfsteel.com/hengheng123456789/articles/79645.html哼哼哼哼Tue, 07 Nov 2006 09:09:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/79645.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/79645.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/79645.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/79645.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/79645.html Swing/AWT 主要是可以在SWT中?a name="awt">Swing/AWT Q但是是有条件的?br />
1、集成简单的AWT表和标签?br /> static class FileTableModel extends AbstractTableModel {  
  File[] files;       
  String[] columnsName = {"Name", "Size", "Date Modified"};
  
  public FileTableModel (File[] files) {
   this.files = files;
  }
  public int getColumnCount () {
   return columnsName.length;
  }
  public Class getColumnClass (int col) {
   if (col == 1) return Long.class;
   if (col == 2) return Date.class;
   return String.class;
  }
  public int getRowCount () {
   return files == null ? 0 : files.length;
  }
  public Object getValueAt (int row, int col) {
   if (col == 0) return files[row].getName();
   if (col == 1) return new Long(files[row].length());
   if (col == 2) return new Date(files[row].lastModified());
   return "";
  }
  public String getColumnName (int col) {
   return columnsName[col];
  }
 }

 public static void main(String[] args) {
  final Display display = new Display();
  final Shell shell = new Shell(display);
  shell.setText("SWT and Swing/AWT Example");

  Listener exitListener = new Listener() {
   public void handleEvent(Event e) {
    MessageBox dialog = new MessageBox(shell, SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
    dialog.setText("Question");
    dialog.setMessage("Exit?");
    if (e.type == SWT.Close) e.doit = false;
    if (dialog.open() != SWT.OK) return;
    shell.dispose();
   }
  }; 
  Listener aboutListener = new Listener() {
   public void handleEvent(Event e) {
    final Shell s = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    s.setText("About");
    GridLayout layout = new GridLayout(1, false);
    layout.verticalSpacing = 20;
    layout.marginHeight = layout.marginWidth = 10;
    s.setLayout(layout);
    Label label = new Label(s, SWT.NONE);
    label.setText("SWT and AWT Example.");
    Button button = new Button(s, SWT.PUSH);
    button.setText("OK");
    GridData data = new GridData();
    data.horizontalAlignment = GridData.CENTER;
    button.setLayoutData(data);
    button.addListener(SWT.Selection, new Listener() {
     public void handleEvent(Event event) {
      s.dispose();
     }
    });
    s.pack();
    Rectangle parentBounds = shell.getBounds();
    Rectangle bounds = s.getBounds();
    int x = parentBounds.x + (parentBounds.width - bounds.width) / 2;
    int y = parentBounds.y + (parentBounds.height - bounds.height) / 2;
    s.setLocation(x, y);
    s.open();
    while (!s.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
    }
   }
  };
  shell.addListener(SWT.Close, exitListener);
  Menu mb = new Menu(shell, SWT.BAR);
  MenuItem fileItem = new MenuItem(mb, SWT.CASCADE);
  fileItem.setText("&File");
  Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
  fileItem.setMenu(fileMenu);
  MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
  exitItem.setText("&Exit\tCtrl+X");
  exitItem.setAccelerator(SWT.CONTROL + 'X');
  exitItem.addListener(SWT.Selection, exitListener);
  MenuItem aboutItem = new MenuItem(fileMenu, SWT.PUSH);
  aboutItem.setText("&About\tCtrl+A");
  aboutItem.setAccelerator(SWT.CONTROL + 'A');
  aboutItem.addListener(SWT.Selection, aboutListener);
  shell.setMenuBar(mb);

  RGB color = shell.getBackground().getRGB();
  Label separator1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
  Label locationLb = new Label(shell, SWT.NONE);
  locationLb.setText("Location:");
  Composite locationComp = new Composite(shell, SWT.EMBEDDED);
  ToolBar toolBar = new ToolBar(shell, SWT.FLAT);
  ToolItem exitToolItem = new ToolItem(toolBar, SWT.PUSH);
  exitToolItem.setText("&Exit");
  exitToolItem.addListener(SWT.Selection, exitListener);
  ToolItem aboutToolItem = new ToolItem(toolBar, SWT.PUSH);
  aboutToolItem.setText("&About");
  aboutToolItem.addListener(SWT.Selection, aboutListener);
  Label separator2 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
  final Composite comp = new Composite(shell, SWT.NONE);
  final Tree fileTree = new Tree(comp, SWT.SINGLE | SWT.BORDER);
  Sash sash = new Sash(comp, SWT.VERTICAL);
  Composite tableComp = new Composite(comp, SWT.EMBEDDED); //Composite对象必须为SWT.EMBEDDED才可以装载awt/swing内容
  Label separator3 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
  Composite statusComp = new Composite(shell, SWT.EMBEDDED);

  java.awt.Frame locationFrame = SWT_AWT.new_Frame(locationComp);
  final java.awt.TextField locationText = new java.awt.TextField();
  locationFrame.add(locationText);

  //处理awt?br />  java.awt.Frame fileTableFrame = SWT_AWT.new_Frame(tableComp);
  java.awt.Panel panel = new java.awt.Panel(new java.awt.BorderLayout());
  fileTableFrame.add(panel);
  final JTable fileTable = new JTable(new FileTableModel(null));
  fileTable.setDoubleBuffered(true);
  fileTable.setShowGrid(false);
  fileTable.createDefaultColumnsFromModel();
  JScrollPane scrollPane = new JScrollPane(fileTable);
  panel.add(scrollPane);

  //处理awt状态Label
  java.awt.Frame statusFrame = SWT_AWT.new_Frame(statusComp);
  statusFrame.setBackground(new java.awt.Color(color.red, color.green, color.blue));
  final java.awt.Label statusLabel = new java.awt.Label();
  statusFrame.add(statusLabel);
  statusLabel.setText("Select a file");

  sash.addListener(SWT.Selection, new Listener() {
   public void handleEvent(Event e) {
    if (e.detail == SWT.DRAG) return;
    GridData data = (GridData)fileTree.getLayoutData();
    Rectangle trim = fileTree.computeTrim(0, 0, 0, 0);
    data.widthHint = e.x - trim.width;
    comp.layout();
   }
  });

  File[] roots = File.listRoots();
  for (int i = 0; i < roots.length; i++) {
   File file = roots[i];
   TreeItem treeItem = new TreeItem(fileTree, SWT.NONE);
   treeItem.setText(file.getAbsolutePath());
   treeItem.setData(file);
   new TreeItem(treeItem, SWT.NONE);
  }
  fileTree.addListener(SWT.Expand, new Listener() {
   public void handleEvent(Event e) {
    TreeItem item = (TreeItem)e.item;
    if (item == null) return;
    if (item.getItemCount() == 1) {
     TreeItem firstItem = item.getItems()[0];
     if (firstItem.getData() != null) return;
     firstItem.dispose();
    } else {
     return;
    }
    File root = (File)item.getData();
    File[] files = root.listFiles();
    if (files == null) return;
    for (int i = 0; i < files.length; i++) {
     File file = files[i];
     if (file.isDirectory()) {
      TreeItem treeItem = new TreeItem(item, SWT.NONE);
      treeItem.setText(file.getName());
      treeItem.setData(file);
      new TreeItem(treeItem, SWT.NONE);
     }
    }
   }
  });
  fileTree.addListener(SWT.Selection, new Listener() {
   public void handleEvent(Event e) {
    TreeItem item = (TreeItem)e.item;
    if (item == null) return;
    final File root = (File)item.getData();
    EventQueue.invokeLater(new Runnable() {
     public void run() {
      statusLabel.setText(root.getAbsolutePath());
      locationText.setText(root.getAbsolutePath());
      fileTable.setModel(new FileTableModel(root.listFiles()));
     }
    });
   }
  });
  
  GridLayout layout = new GridLayout(4, false);
  layout.marginWidth = layout.marginHeight = 0;
  layout.horizontalSpacing = layout.verticalSpacing = 1;
  shell.setLayout(layout);
  GridData data;  
  data = new GridData(GridData.FILL_HORIZONTAL);
  data.horizontalSpan = 4;
  separator1.setLayoutData(data);
  data = new GridData();
  data.horizontalSpan = 1;
  data.horizontalIndent = 10;
  locationLb.setLayoutData(data);
  data = new GridData(GridData.FILL_HORIZONTAL);
  data.horizontalSpan = 2;
  data.heightHint = locationText.getPreferredSize().height;
  locationComp.setLayoutData(data);
  data = new GridData(GridData.FILL_HORIZONTAL);
  data.horizontalSpan = 1;
  toolBar.setLayoutData(data);
  data = new GridData(GridData.FILL_HORIZONTAL);
  data.horizontalSpan = 4;
  separator2.setLayoutData(data);
  data = new GridData(GridData.FILL_BOTH);
  data.horizontalSpan = 4;
  comp.setLayoutData(data);
  data = new GridData(GridData.FILL_HORIZONTAL);
  data.horizontalSpan = 4;
  separator3.setLayoutData(data);
  data = new GridData(GridData.FILL_HORIZONTAL);
  data.horizontalSpan = 4;
  data.heightHint = statusLabel.getPreferredSize().height;
  statusComp.setLayoutData(data);
  
  layout = new GridLayout(3, false);
  layout.marginWidth = layout.marginHeight = 0;
  layout.horizontalSpacing = layout.verticalSpacing = 1;
  comp.setLayout(layout);   
  data = new GridData(GridData.FILL_VERTICAL);
  data.widthHint = 200;
  fileTree.setLayoutData(data);  
  data = new GridData(GridData.FILL_VERTICAL);
  sash.setLayoutData(data);  
  data = new GridData(GridData.FILL_BOTH);
  tableComp.setLayoutData(data);

  shell.open();
  while(!shell.isDisposed()) {
   if (!display.readAndDispatch()) display.sleep();
  }
  display.dispose();
 }



哼哼 2006-11-07 17:09 发表评论
]]>
SWT 目录对话框(DirectoryDialogc)http://www.aygfsteel.com/hengheng123456789/articles/79615.html哼哼哼哼Tue, 07 Nov 2006 07:13:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/79615.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/79615.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/79615.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/79615.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/79615.html
 public static void main (String [] args) {
  Display display = new Display ();
  Shell shell = new Shell (display);
  shell.open ();
  DirectoryDialog dialog = new DirectoryDialog (shell);
  dialog.setFilterPath ("c:\\"); //Windows specific
  System.out.println ("RESULT=" + dialog.open ());
  while (!shell.isDisposed()) {
   if (!display.readAndDispatch ()) display.sleep ();
  }
  display.dispose ();
 }

哼哼 2006-11-07 15:13 发表评论
]]>
SWT 文g对话框(FileDialogc)http://www.aygfsteel.com/hengheng123456789/articles/79614.html哼哼哼哼Tue, 07 Nov 2006 07:11:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/79614.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/79614.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/79614.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/79614.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/79614.html public static void main (String [] args) {
  Display display = new Display ();
  Shell shell = new Shell (display);
  shell.open ();
  FileDialog dialog = new FileDialog (shell, SWT.SAVE);
  dialog.setFilterNames (new String [] {"Batch Files", "All Files (*.*)"});
  dialog.setFilterExtensions (new String [] {"*.bat", "*.*"}); //Windows wild cards
  dialog.setFilterPath ("c:\\"); //Windows path
  dialog.setFileName ("fred.bat");
  System.out.println ("Save to: " + dialog.open ()); //打开对话?br />  while (!shell.isDisposed ()) {
   if (!display.readAndDispatch ()) display.sleep ();
  }
  display.dispose ();
 }

哼哼 2006-11-07 15:11 发表评论
]]>
SWT l图QGCc)http://www.aygfsteel.com/hengheng123456789/articles/79610.html哼哼哼哼Tue, 07 Nov 2006 07:05:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/79610.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/79610.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/79610.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/79610.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/79610.html1、点击鼠标左键在shell里画Uѝ?br />
 public static void main(String[] args)
 {
  Display display = new Display();
  final Shell shell = new Shell(display);
  Listener listener = new Listener() {
   int lastX = 0, lastY = 0;

   public void handleEvent(Event event)
   {
    switch (event.type)
    {
     case SWT.MouseMove :
      if ((event.stateMask & SWT.BUTTON1) == 0)
       break; // 判断是否为鼠标左键,如果不是跛_
      GC gc = new GC(shell);
      gc.drawLine(lastX, lastY, event.x, event.y);
      gc.dispose();
     // FALL THROUGH
     case SWT.MouseDown :
      lastX = event.x;
      lastY = event.y;
      break;
    }
   }
  };
  shell.addListener(SWT.MouseDown, listener);
  shell.addListener(SWT.MouseMove, listener);
  shell.open();
  while (!shell.isDisposed())
  {
   if (!display.readAndDispatch())
    display.sleep();
  }
  display.dispose();
 }

2、在弹出H口中显C的当时图像状态?br /> public static void main(String[] args) {
  final Display display = new Display();
  final Shell shell = new Shell(display);
  shell.setText("Widget");
  
  //建立一个简单的?br />  final Table table = new Table(shell, SWT.MULTI);
  table.setLinesVisible(true);
  table.setBounds(10, 10, 100, 100);
  for (int i = 0; i < 9; i++) {
   new TableItem(table, SWT.NONE).setText("item" + i);
  }
  
  //建立捕捉囑փ的按?br />  Button button = new Button(shell, SWT.PUSH);
  button.setText("Capture");
  button.pack();
  button.setLocation(10, 140);
  
  
  button.addListener(SWT.Selection, new Listener() {
   public void handleEvent(Event event) {
    Point tableSize = table.getSize(); //获取表的大小
    GC gc = new GC(table); //建立表的GC对象
    final Image image =
     new Image(display, tableSize.x, tableSize.y); //建立表大的囑փimage
    gc.copyArea(image, 0, 0); //利用表的GC对象把表的图像复制到image?br />    gc.dispose();
    
    //建立一个弹出面板Shell对象popup
    Shell popup = new Shell(shell);
    popup.setText("Image");
    popup.addListener(SWT.Close, new Listener() {
     public void handleEvent(Event e) {
      image.dispose();
     }
    });
    //在popup上徏立画布对象canvas
    Canvas canvas = new Canvas(popup, SWT.NONE);
    canvas.setBounds(10, 10, tableSize.x+10, tableSize.y+10);
    canvas.addPaintListener(new PaintListener() {
     public void paintControl(PaintEvent e) {
      e.gc.drawImage(image, 0, 0); //在画布上l出表的囑փimage
     }
    });
    popup.pack();
    popup.open();
   }
  });
  shell.pack();
  shell.open();
  while (!shell.isDisposed()) {
   if (!display.readAndDispatch()) display.sleep();
  }
  display.dispose();
 }

3、获取整个窗口的囑փq显C?br /> public static void main(String[] args) {
  final Display display = new Display();
  final Shell shell = new Shell(display);
  shell.setLayout(new FillLayout());
  Button button = new Button(shell, SWT.PUSH);
  button.setText("Capture");
  button.addListener(SWT.Selection, new Listener() {
   public void handleEvent(Event event) {
    
    /* Take the screen shot */
    GC gc = new GC(display);
    final Image image = new Image(display, display.getBounds());
    gc.copyArea(image, 0, 0);
    gc.dispose();
    
    Shell popup = new Shell(shell, SWT.SHELL_TRIM);
    popup.setLayout(new FillLayout());
    popup.setText("Image");
    popup.setBounds(50, 50, 200, 200);
    popup.addListener(SWT.Close, new Listener() {
     public void handleEvent(Event e) {
      image.dispose();
     }
    });
    
    ScrolledComposite sc = new ScrolledComposite (popup, SWT.V_SCROLL | SWT.H_SCROLL);
    Canvas canvas = new Canvas(sc, SWT.NONE);
    sc.setContent(canvas);
    canvas.setBounds(display.getBounds ());
    canvas.addPaintListener(new PaintListener() {
     public void paintControl(PaintEvent e) {
      e.gc.drawImage(image, 0, 0);
     }
    });
    popup.open();
   }
  });
  shell.pack();
  shell.open();
  while (!shell.isDisposed()) {
   if (!display.readAndDispatch()) display.sleep();
  }
  display.dispose();
 }

4、用transform、alpha和paths混合技术绘图。注意:必须在项目中import“swt-gdip-win32-3139.dll”?br /> public static void main(String[] args) {
  final Display display = new Display();
  final Shell shell = new Shell(display);
  shell.setText("Advanced Graphics");
  FontData fd = shell.getFont().getFontData()[0];
  final Font font = new Font(display, fd.getName(), 60, SWT.BOLD | SWT.ITALIC);
  final Image image = new Image(display, 640, 480);
  final Rectangle rect = image.getBounds();
  GC gc = new GC(image);
  gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
  gc.fillOval(rect.x, rect.y, rect.width, rect.height);
  gc.dispose();
  shell.addListener(SWT.Paint, new Listener() {
   public void handleEvent(Event event) {
    GC gc = event.gc;    
    Transform tr = new Transform(display);
    tr.translate(50, 120);
    tr.rotate(-30);
    gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2);
    gc.setAlpha(100);
    gc.setTransform(tr);
    Path path = new Path(display);
    path.addString("SWT", 0, 0, font);
    gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
    gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
    gc.fillPath(path);
    gc.drawPath(path);
    tr.dispose();
    path.dispose();
   }   
  });
  shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2));
  shell.open();
  while (!shell.isDisposed()) {
   if (!display.readAndDispatch())
    display.sleep();
  }
  image.dispose();
  font.dispose();
  display.dispose();
 }

5、对囑փq行旋{?br /> public static void main(String[] args) {
  final Display display = new Display();
  
  final Image image = new Image(display, 110, 60);
  GC gc = new GC(image);
  Font font = new Font(display, "Times", 30, SWT.BOLD);
  gc.setFont(font);
  gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
  gc.fillRectangle(0, 0, 110, 60);
  gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
  gc.drawText("SWT", 10, 10, true);
  font.dispose();
  gc.dispose();
  
  final Rectangle rect = image.getBounds();
  Shell shell = new Shell(display);
  shell.setText("Matrix Tranformations");
  shell.setLayout(new FillLayout());
  final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED);
  canvas.addPaintListener(new PaintListener () {
   public void paintControl(PaintEvent e) { 
    GC gc = e.gc;
    gc.setAdvanced(true);
    if (!gc.getAdvanced()){
     gc.drawText("Advanced graphics not supported", 30, 30, true);
     return;
    }
    
    // Original image
    int x = 30, y = 30;
    gc.drawImage(image, x, y);
    x += rect.width + 30;
    
    Transform transform = new Transform(display);
    
    // Note that the tranform is applied to the whole GC therefore
    // the coordinates need to be adjusted too.
    
    // Reflect around the y axis.
    transform.setElements(-1, 0, 0, 1, 0 ,0);
    gc.setTransform(transform);
    gc.drawImage(image, -1*x-rect.width, y);
    
    x = 30; y += rect.height + 30;
    
    // Reflect around the x axis.
    transform.setElements(1, 0, 0, -1, 0, 0);
    gc.setTransform(transform);
    gc.drawImage(image, x, -1*y-rect.height);
    
    x += rect.width + 30;
    
    // Reflect around the x and y axes 
    transform.setElements(-1, 0, 0, -1, 0, 0);
    gc.setTransform(transform);
    gc.drawImage(image, -1*x-rect.width, -1*y-rect.height);
    
    x = 30; y += rect.height + 30;
    
    // Shear in the x-direction
    transform.setElements(1, 0, -1, 1, 0, 0);
    gc.setTransform(transform);
    gc.drawImage(image, 300, y);
    
    // Shear in y-direction
    transform.setElements(1, -1, 0, 1, 0, 0);
    gc.setTransform(transform);
    gc.drawImage(image, 150, 475);
    
    // Rotate by 45 degrees 
    float cos45 = (float)Math.cos(45);
    float sin45 = (float)Math.sin(45);
    transform.setElements(cos45, sin45, -sin45, cos45, 0, 0);
    gc.setTransform(transform);
    gc.drawImage(image, 350, 100);
    
    transform.dispose();
   }
  });
  
  shell.setSize(350, 550);
  shell.open();
  while (!shell.isDisposed()) {
   if (!display.readAndDispatch())
    display.sleep();
  }
  image.dispose();
  display.dispose();
 }



哼哼 2006-11-07 15:05 发表评论
]]>
SWT 树(Treec)http://www.aygfsteel.com/hengheng123456789/articles/78734.html哼哼哼哼Thu, 02 Nov 2006 09:31:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/78734.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/78734.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/78734.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/78734.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/78734.html
1、简单树
 public static void main (String [] args) {
  Display display = new Display ();
  Shell shell = new Shell (display);
  shell.setLayout(new FillLayout());
  
  final Tree tree = new Tree (shell, SWT.BORDER);
  
  for (int i=0; i<4; i++) {
   TreeItem iItem = new TreeItem (tree, 0);
   iItem.setText ("TreeItem (0) -" + i);
   for (int j=0; j<4; j++) {
    TreeItem jItem = new TreeItem (iItem, 0);
    jItem.setText ("TreeItem (1) -" + j);
    for (int k=0; k<4; k++) {
     TreeItem kItem = new TreeItem (jItem, 0);
     kItem.setText ("TreeItem (2) -" + k);
     for (int l=0; l<4; l++) {
      TreeItem lItem = new TreeItem (kItem, 0);
      lItem.setText ("TreeItem (3) -" + l);
     }
    }
   }
  }
  shell.setSize (200, 200);
  shell.open ();
  while (!shell.isDisposed()) {
   if (!display.readAndDispatch ()) display.sleep ();
  }
  display.dispose ();
 }

2、类D源管理器的树Q其中包含鼠标双M?br /> public static void main (String [] args) {
  final Display display = new Display ();
  final Shell shell = new Shell (display);
  shell.setText ("Lazy Tree");
  shell.setLayout (new FillLayout ());
  
  final Tree tree = new Tree (shell, SWT.BORDER);
  File [] roots = File.listRoots ();
  for (int i=0; i<roots.length; i++) {
   TreeItem root = new TreeItem (tree, 0);
   root.setText (roots [i].toString ());
   root.setData (roots [i]);//保存当前节点数据
   new TreeItem (root, 0);//把当前节点作为目录节?br />  }
  
  tree.addListener (SWT.Expand, new Listener () {
   public void handleEvent (final Event event) {
    final TreeItem root = (TreeItem) event.item;
    TreeItem [] items = root.getItems ();
    for (int i= 0; i<items.length; i++) {
     if (items [i].getData () != null) return;
     items [i].dispose ();
    }
    File file = (File) root.getData ();
    File [] files = file.listFiles ();
    if (files == null) return;
    for (int i= 0; i<files.length; i++) {
     TreeItem item = new TreeItem (root, 0);
     item.setText (files [i].getName ());
     item.setData (files [i]);
     if (files [i].isDirectory()) {
      new TreeItem (item, 0);
     }
    }
   }
  });
    tree.addListener (SWT.MouseDoubleClick, new Listener () {
   public void handleEvent (Event event) {
    Point point = new Point (event.x, event.y);
    TreeItem item = tree.getItem (point);
    if (item != null) {
     System.out.println ("Mouse down: " + item);
    }
   }
  });
  //ҎTree的大更改shell的大?br />  Point size = tree.computeSize (300, SWT.DEFAULT);
  int width = Math.max (300, size.x);
  int height = Math.max (300, size.y);
  shell.setSize (shell.computeSize (width, height));
  shell.open ();
  while (!shell.isDisposed ()) {
   if (!display.readAndDispatch ()) display.sleep ();
  }
  display.dispose ();
 }


哼哼 2006-11-02 17:31 发表评论
]]>
SWT 分割H(SashFormc)http://www.aygfsteel.com/hengheng123456789/articles/78709.html哼哼哼哼Thu, 02 Nov 2006 07:47:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/78709.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/78709.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/78709.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/78709.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/78709.html
/*
 * SashForm example snippet: create a sash form with three children
 *
 * For a list of all SWT example snippets see
 * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class Snippet109 {

  public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    SashForm form new SashForm(shell, SWT.HORIZONTAL);
    form.setLayout(new FillLayout());

    Composite child1 = new Composite(form, SWT.NONE);
    child1.setLayout(new FillLayout());
    new Label(child1, SWT.NONE).setText("Label in pane 1");

    Composite child2 = new Composite(form, SWT.NONE);
    child2.setLayout(new FillLayout());
    new Button(child2, SWT.PUSH).setText("Button in pane2");

    Composite child3 = new Composite(form, SWT.NONE);
    child3.setLayout(new FillLayout());
    new Label(child3, SWT.PUSH).setText("Label in pane3");

    form.setWeights(new int[] { 304030 });
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}



哼哼 2006-11-02 15:47 发表评论
]]>
SWT入门Q?Q?/title><link>http://www.aygfsteel.com/hengheng123456789/articles/78223.html</link><dc:creator>哼哼</dc:creator><author>哼哼</author><pubDate>Tue, 31 Oct 2006 02:36:00 GMT</pubDate><guid>http://www.aygfsteel.com/hengheng123456789/articles/78223.html</guid><wfw:comment>http://www.aygfsteel.com/hengheng123456789/comments/78223.html</wfw:comment><comments>http://www.aygfsteel.com/hengheng123456789/articles/78223.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/hengheng123456789/comments/commentRss/78223.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/hengheng123456789/services/trackbacks/78223.html</trackback:ping><description><![CDATA[     摘要: 书写 swt E序的基本步骤如下:1.      创徏一个Display对象?.      创徏一个或者多个Shell对象Q你可以认ؓShell代表了程序的H口?.      在Shell内创建各U部ӞwidgetQ?.      对各个部件进行初始化Q外观,状态等Q,同时为各U部件的事g创徏监听器(listenerQ?.      调用Shell对象的open()?..  <a href='http://www.aygfsteel.com/hengheng123456789/articles/78223.html'>阅读全文</a><img src ="http://www.aygfsteel.com/hengheng123456789/aggbug/78223.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/hengheng123456789/" target="_blank">哼哼</a> 2006-10-31 10:36 <a href="http://www.aygfsteel.com/hengheng123456789/articles/78223.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SWT概述http://www.aygfsteel.com/hengheng123456789/articles/78124.html哼哼哼哼Mon, 30 Oct 2006 10:18:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/78124.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/78124.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/78124.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/78124.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/78124.html      SWT/JFace 象一股清新的风吹入了 Java ?/span> GUI 开发领域,个沉L领域带来了勃勃生机。虽?/span> SUN 不接U?/span> SWT/JFace 作ؓ Java 中的一U图?/span> API 标准Q但它虽然借着 Eclipse 的优异表玎ͼ以不可阻挡之势向前发展着。终于可以用 SWT L的开发出高效率的 GUI E序Q且拥有标准?/span> Windows 外观Q?/span> Eclipse 软g是Z SWT/JFace 构徏的,大家看看 Eclipse3.0 q?/span> SWT 有多么的?br />
   Z方便开?span lang="EN-US">SWT
E序Q在SWT基础上又创徏了一个更易用、功能强大的囑Ş包?/span>JFace”。然而,JFaceq不能完全覆?/span>SWT的所有功能,所以编E时SWT?/span>JFace都会要用刎ͼ但是一般来_能用JFace的组件就最好不要用SWT?/font>?br />
SWT中的?/span>

SWT?/span>Eclipse囑ŞAPI的基Q本节将单介l一?/span>SWT中所包含的子包?/span>

1?/span>org.eclipse.swt.widgets

最常用的组件基本都在此包中Q如Button?/span>Text?/span>Label?/span>Combo{。其中两个最重要的组件当?/span>Shell?/span>CompositeQ?/span>Shell相当于应用程序的ȝ口;Composite相当?/span>SWING中的Panel对象Q是容纳lg的容器?/span>

2?/span>org.eclipse.swt.layout

主要的界面布局方式在此包中?/span>SWT对组件的布局也采用了AWT/SWING中的Layout?/span>Layout Datal合的方式?/span>

3?/span>org.eclipse.swt.custom

对一些基本图形组件的扩展在此包中Q比如其中的CLabel是Ҏ?/span>Labellg的扩展,?/span>CLabel上可以同时加入文字和囄。在此包中还有一个新的布局方式StackLayout?/span>

4?/span>org.eclipse.swt.event

SWT采用了和AWT/SWING一L事g模型Q在包中可以扑ֈ事g监听cd相应的事件对象。比如,鼠标事g监听?/font>MouseListenerQ?/span>MouseMoveListener{,及对应的事g对象MouseEvent?/span>

5?/span>org.eclipse.swt.graphics

此包中包含针对图片、光标、字体或l图API。比如,可通过Imagec调用系l中不同cd的图片文件?/span>

6?/span>org.eclipse.swt.ole.win32

对不同^収ͼSWT有一些针Ҏ的API。例如,?/span>Windowsq_Q可以通过此包很容易的调用OLElgQ这使得SWTE序也可以内?/span>IE览器或Word?/span>Excel{程序?/span>

此外q有org.eclipse.swt.dnd?/span>org.eclipse.swt.printing?/span>org.eclipse.swt.program?/span>org.eclipse.swt.accessibility?/span>org.eclipse.swt.browser?/span>org.eclipse.swt.awt{包Q在此不一一介绍了。这些包一般很用刎ͼ只需要稍微了解一下就行了Q不必深I?br />
?/strong>SWT Designer

   SWT Designer是优U?/span>SWT/JFace开发辅助工?br />http://downloads.instantiations.com/Designer/release/v5.1.0_20060908125203/Designer_v5.1.0_win32_x86.exe
http://www.codefocus.cn/code/JAVA/SWT_Designer5.rar
codefocus.cn解压

   SWT Designerq无法完成所有的界面设计工作Q所以在界面开发中依然是以手工写代码ؓ主,而且手写代码某些时候比界面拖拉操作更快捗以下是W者在使用SWT Designer开发界面时的基本流E:

l           新开一个时的Application文gQ用SWT Desiger快速做好开发所需要的部䆾界面?/span>

l           自动生成的代码UL到正式项目中Q进行手工修改和代码_?/span>

另外Q由?/span>SWT Designer不是很稳定,所以在使用时还应注意:

l           不要在界面中加入太多lg?/span>

l           不要频繁的移动组Ӟ或者删除又dlgQ否则很可能因ؓ内存耗尽而死机?/span>



哼哼 2006-10-30 18:18 发表评论
]]>
SWT的来源(转)http://www.aygfsteel.com/hengheng123456789/articles/78098.html哼哼哼哼Mon, 30 Oct 2006 09:25:00 GMThttp://www.aygfsteel.com/hengheng123456789/articles/78098.htmlhttp://www.aygfsteel.com/hengheng123456789/comments/78098.htmlhttp://www.aygfsteel.com/hengheng123456789/articles/78098.html#Feedback0http://www.aygfsteel.com/hengheng123456789/comments/commentRss/78098.htmlhttp://www.aygfsteel.com/hengheng123456789/services/trackbacks/78098.html
        Amy来自一家Smalltalk公司Q叫做ObjectshareQ在那里她负责搞UIcd。跟Java相比Smalltalk的历史有些悲惨,曑և何时?家庞大的Smalltalk公司——IBM、Parc-Place和Digitalk。在90q代初期3家公司的市场份额大致相等Q生zL好的。Parc-Place采用仿窗口部Ӟemulated widgetsQ的设计Q即Swing的设计)QIBM和Digitalk则采用原生窗口部Ӟnative widgetsQ。后来IBM压倒了另外两家Q因此他们打合q成一Ӟ假设叫做Parc-Place Digitalk。随后当他们试图他们的产品融合C个叫做Jigsaw的计划中时爆发了一场大战,计划׃政治原因p|了(开发h员实际上已经能让它运转v来)Q就因ؓ原生和仿造两zL。Amy赢得了精上的胜利,不过在IBM我们赢得了他们所有的生意Q因两家公司在一整年里除了吵架什么都没做。当埃落定之后PPDQParc-Place Digitalk当时已改名ؓObjectshareQ跟Windscale改名为Sellafield的原因相同——让Z淡忘之前发生的灾难)的股hg60元掉到了低?元1股。他们因Z报收入被NASDAQ摘牌Q从此消失。此时SUN正走上与PPDcM的技术方向,于是PDD的技术h员都把他们的历投CSUN。Amy被雇佣了Q她承诺通过轻量U方案解x有窗口组件的问题Q因此说服SUN理层让她当了GUI开发部门的头头。她是拿着“这里原来的人都搞砸了,我是来解决的”的钥匙q来的。随后Amy雇䄦了所有她q去在Parc-Place的旧朋友Q让他们来开发Swing?br />
        昄Swing应该做的是仅仅成Z个绘制框Ӟl那些希望创建地图Y件或者绘图Y件的Z使用Q无论如何,应该围绕AWTcd来徏造它Q按钮之cȝ东西仍然交给AWT来管。SUN的h比如Philip和Mark已经让AWT能够处理表格、树和记事本QnotebookQ?Q,所以Swing的方向应该说很明显了。但那些毁了PDD的h不干Q他们非要把一切都弄成轻量U的。由于SUN理层的无知Q再加上Amy无情的政LD,造成了我们今天所见的混ؕ局面。AmyqSUN怿Swing是作为Mozilla目的一部分与Netscape联合开发的Q事实上q只是她的宣传伎俩?br />
        在IBMQ我们从W一天v憎恶Swing。庞大、满是错误,而且隄x。原先我们的工具如VisualAge for Java都是用SmalltalkQ用的是原生H口lgQ写的,所以当我们这些工具向Java代码库迁ULQ我们需要一套窗口组件。IBMq边的开发h员都是原来搞Smalltalk的那一批hQ我们对理层要求用Swing来构建WebSphere Studio工具都非怸情愿。Swing是个可怕的充满~陷的怪兽。在WebSphere Studio最初的预览中,当与Microsoft Visual Studio作对比演C的时候,我们所有的客户都讨厌它Q就因ؓ它的外观Q而不它的功能有多强。大多数消费者都不会C辆让得难看的车,哪怕这车有一台出色的引擎。因此我们开始了一个项目,是把我们的Smalltalk原生H口lgUL到Java上去。这个项目是加拿大的Object Technology International组做的。这个项目获得了成功Q被q用在在我们发布的VisualAge Micro Edition产品中,VisualAge Micro Edition后来成ؓJ2ME开发方面一个非常成功的IDE。但是OTI的h发现QSwing在读取Windows事g斚w有极严重的缺P我们甚至无法q行SWTQS开始是Simple的羃写,不过后来变成了Standard的羃写)和Swing间的互操作。他们在M仉列的时候用了一U可能留下内存漏z的方式Q所以我们不得不采用我们自己的查询Windows事g队列的@环,以纠正这个错误。我们试了一ơ又一ơ让SUN修复q个错误Q但Amy是听不q去Q所以我们才军_SWT和AWT/Swing不能共存。我们甚臛_SWT中定义了自己的Point和RectanglecZ—整个工具包对AWT或Swing都没有Q何依赖。我们把q个工具包放CEclipse中,q是一个工具^収ͼ它的M设计目标是要战胜Micrsoft和Visual Studio。Eclipse是开源的Q所以Q何h都可以在上面构徏自己的东西,我们已经有像TogetherSoft和Rationalq样的公司移植到了上面。我们的竞争者是MicrosoftQ所以我们所有努力和注意力都是从正面针对Microsoft?br />
        不管怎么说SUNҎ非常不满。他们的Netbeans跟Eclipse做的是相同的事,因此他们向IBM高层抱怨。他们认为SWT是要你l到Windows上,q纯_Ҏ胡说Q因为SWT能通过GTK在Mac/Linux上运行,以及一大堆嵌入式^台。他们拒l让Eclipse获得Java认证Q因为里面有原生代码Q所以Eclipse产品必须很小心地使用单词“Java”这个SUN的商标。Eclipse甚至不能把自qZ个Java IDEQSUN已经威胁q要采取法律行动来制止IBM在Q何时候把EclipseUC一个Java IDE。结果之一是IBM在Eclipse上创建的GUI设计工具Q允怽构徏Swing/AWT GUIQ却不让你往里面拖放SWTH口控g?br />
        SWT从Eclipse中分d来是完全可能的,只需要把DLL抠出来放到\径中Qƈ使用H口lg工具包来l你的银行或者保险或者其他什么应用程序开发GUI。再ơ说明,我们无法更进一步,因ؓSUN把我们的双手l上了。虽然作为Eclipse开放源码协议的一部分QCPL允许我们提供q样的解x案,但SUN已经很清楚地表明他们不希望我们这样做?br />
        对于用户C֌来说Q无论IBM和SUN的最l动机是什么,我发现有一ҎL很有:喜爱Swing的hM说“一旦你׃几年旉L握它Q你p正确C用它”,q基本上是他们在试图证明和维护他们辛苦得来的用途有限的专门技术;而SWT的拥护者们说的是“哇Q这真快Q这跟原生的一Pq可以用XP皮肤……它q又d”。有一句话是我喜欢的,我们的一个用戯QSwing像Java军_不通过操作pȝ来实现原生的IOQ而是通过头马达API自己来读盘的扇区。Swing基本上就是这LQ它拿着个底层的“paint(Graphics)”方法,自己来绘制所有的H口lg?img src ="http://www.aygfsteel.com/hengheng123456789/aggbug/78098.html" width = "1" height = "1" />

哼哼 2006-10-30 17:25 发表评论
]]>
վ֩ģ壺 ҽ| | | ֹ| ɿ| | ԭ| ߰| | | | | Ӫ| ̫| | ϸ| | | | | ʯȪ| | | Ϸ| | | ϲ| | | ˮ| ư| ɽ| | | | ƽ| | | | | |