GMF學習系列(二) 一些知識點(續2)

8.插件的國際化,可以參考nwpu.cdcsp.sbpel.diagram.part中messages.java的做法。

9.Text自動提示功能

import org.eclipse.jface.bindings.keys.KeyStroke;

import org.eclipse.jface.dialogs.Dialog;

import org.eclipse.jface.fieldassist.AutoCompleteField;

import org.eclipse.jface.fieldassist.ComboContentAdapter;

import org.eclipse.jface.fieldassist.ContentProposalAdapter;

import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;

import org.eclipse.jface.fieldassist.TextContentAdapter;

import org.eclipse.swt.SWT;

import org.eclipse.swt.layout.GridData;

import org.eclipse.swt.layout.GridLayout;

import org.eclipse.swt.widgets.Combo;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Label;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.swt.widgets.Text;

?

public class LaunchApp {

??? protected Shell shell;

?

??? private Text nameT;

??? private Combo cityC;

??? private Text remarksT;

?

??? /**

???? * Launch the application

???? * @param args

???? */

??? public static void main(String[] args) {

??????? try {

??????????? LaunchApp window = new LaunchApp();

??????????? window.open();

??????? } catch (Exception e) {

??????????? e.printStackTrace();

??????? }

??? }

?

??? /**

???? * Open the window

???? */

??? public void open() {

??????? final Display display = Display.getDefault();

??????? createContents();

??????? shell.open();

??????? shell.layout();

??????? while (!shell.isDisposed()) {

??????????? if (!display.readAndDispatch())

??????????????? display.sleep();

??????? }

??? }

?

??? /**

???? * Create contents of the window

???? */

??? protected void createContents() {

??????? shell = new Shell();

??????? final GridLayout gridLayout = new GridLayout();

??????? gridLayout.numColumns = 2;

??????? shell.setLayout(gridLayout);

??????? shell.setSize(226, 122);

??????? shell.setText("Field Assist");

?

??????? final Label nameL = new Label(shell, SWT.NONE);

??????? nameL.setText("姓名");

?

??????? nameT = new Text(shell, SWT.BORDER);

??????? nameT.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

?

??????? final Label cityL = new Label(shell, SWT.NONE);

??????? cityL.setText("城市");

?

??????? cityC = new Combo(shell, SWT.NONE);

???????cityC.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

???????

??????? final Label remarksL = new Label(shell, SWT.NONE);

??????? remarksL.setText("備注");

?

??????? remarksT = new Text(shell, SWT.BORDER);

??????? remarksT.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

???????

??????? //

??????? Dialog.applyDialogFont(this.shell);

???????

??????? //

??????? this.addNameTextFieldAssist();

??????? this.addCityComboFieldAssist();

??????? this.addRemarksTextFieldAssist();

??? }

?

??? /**

???? * 給名稱Text添加自動完成功能

???? */

??? private void addNameTextFieldAssist() {

??????? // 讓text可以進行代碼提示. 提示內容為: "aa", "BB", "無敵".

??????? // 注意: 不區分大小寫. [如: 輸入'b', 內容中會出現"BB"]

??????? new AutoCompleteField(nameT, new TextContentAdapter(), new String[]{"aa", "BB", "無敵"});

??? }

???

??? /**

???? * 給城市Combo添加自動完成功能

???? */

??? private void addCityComboFieldAssist() {

??????? // 讓combo可以代碼提示. 提示內容為: "BeiJing", "南京", "北京"

??????? new AutoCompleteField(cityC, new ComboContentAdapter(), new String[] {"BeiJing", "南京", "北京"});

??? }

???

??? /**

???? * 給備注Text添加自動完成功能

???? */

??? private void addRemarksTextFieldAssist() {

??????? // 下面使用ContentProposalAdapter,而沒有繼續使用AutoCompleteField.

???????// [去查看代碼你會發現:AutoCompleteFiled實現和下面的代碼幾乎一樣. ]

??????? // AutoCompleteFiled使用的同樣就將傳入的String[]去構造一個SimpleContentProposalProvider.

??????? // 但是,AutoCompleteFiled內部的ContentProposalAdapter是無法從外部得到的.

??????? // 所以,為了能夠自定義ContentProposalAdapter, 還必須將AutoCompleteField內部實現的代碼在外部再寫一遍.

??????? KeyStroke keyStroke = null; // null 表示不接受快捷鍵

??????? try {

??????????? keyStroke = KeyStroke.getInstance("Ctrl+1"); // 在text上按Ctrl+1彈出popup的shell.

??????? } catch (Exception e) {

??????????? e.printStackTrace();

??????? }

??????? ContentProposalAdapter adapter = new ContentProposalAdapter(remarksT, new TextContentAdapter(), new SimpleContentProposalProvider(new String[] {"one", "two", "three"}), keyStroke, new char[] {'.', ' '});

??????? adapter.setAutoActivationDelay(200); // 延時200ms

??????? adapter.setPropagateKeys(true); // 如果用戶的輸入值在內容列表中[比如輸入'o',而內容中有'one'],則彈出popup的shell

??????? adapter.setFilterStyle(ContentProposalAdapter.FILTER_CUMULATIVE); // 用戶同步輸入的內容也過濾列表[如:用戶輸入'o',則彈出popup的shell中的內容列表被過濾,其中都是'o'開頭的, 再輸入一個'n', 則內容列表中被過濾,只有以'on'開頭的]

??????? adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_INSERT); // 回寫插入

//??????? adapter.setLabelProvider(new LabelProvider() { // 可以不用指定LabelProvider. 如果指定,則不僅僅可以顯示Text, 還可以顯示Image.

//??????????? @Override

//??????????? public String getText(Object element) {

//??????????????? IContentProposal proposal = (IContentProposal) element;

//??????????????? return "XX" + proposal.getContent();

//??????????? }

//??????????? @Override

//??????????? public Image getImage(Object element) {

//??????????????? return super.getImage(element);

//??????????? }

//??????? });

???????

??? ????// 上面的代碼中使用的是SimpleContentProposalProvider, 則會用每個String去構造默認的一個IContentProposal,

??????? // 具體邏輯見: SimpleContentProposalProvider.makeContentProposal

???????

??????? // 請注意: 可以不用設置setLabelProvider的, 那么將會直接從IContentProposal中取label或content顯示.

??????? // 有labelProvider則從labelProvider得到在內容list中顯示的值.

??????? // 具體邏輯見: ContentProposalAdapter.getString()方法

//??????? if (labelProvider == null) {

//??????????? return proposal.getLabel() == null ? proposal.getContent() : proposal.getLabel();

//??????? }

//?????? ?return labelProvider.getText(proposal);

???????

??????? // 同樣的, 如果你添加了labelProvider, 那么也可以給每個IContentProposal返回Image.

??????? // 具體邏輯見: ContentProposalAdapter.getImage()方法

???????

??? }

?

???

??? // ContentProposalAdapter.setAutoActivationDelay 彈出popup的延遲時間

???

??? // ContentProposalAdapter.setPropagateKeys(true);

??? // 說明: 如果用戶敲入的字母在內容列表內時,是否彈出popup內容列表.

??? // true 彈出. 用戶輸入'o'也會彈出popup的shell. 輸入'.'也會彈出.

??? // false 不彈出. 用戶只有輸入'.'才彈出popup的shell. 輸入'o'等,不彈出.

???

??? // ContentProposalAdapter.setFilterStyle(ContentProposalAdapter.FILTER_*);

??? // 作用: 在用戶敲入字母的時候是否過濾popup彈出的shell里面的內容.

??? // ContentProposalAdapter.FILTER_NONE 不過濾. 說明: 下面的內容列表永遠不變.

??? // ContentProposalAdapter.FILTER_CHARACTER 只用一個輸入字符為條件過濾下面的內容列表. 說明:在輸入多個字符后,下面的內容列表會被清空.

??? // ContentProposalAdapter.FILTER_CUMULATIVE 隨著用戶輸入不停的過濾下面的內容列表. 注意在3.4后被@deprecated了. 說明: 隨著用戶的輸入,下面的內容一直在過濾

???

??? // ContentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_*);

??? // 說明: 用戶從popup的shell中得到的內容怎么回寫到控件上.

??? // ContentProposalAdapter.PROPOSAL_INSERT 插入.

??? // ContentProposalAdapter.PROPOSAL_REPLACE 覆蓋.

??? // ContentProposalAdapter.PROPOSAL_IGNORE 忽略. 應該叫追加比較合適.

?

?? ?

??? // TextContentAdapter只可以用于Text.

??? // ComboContentAdapter只可以用于Combo.

??? // 所以, 對于StyledText或Snipper等都需要自定義ContentAdapter.

???

}

轉載于:https://www.cnblogs.com/yangqk/archive/2011/10/26/2225463.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/275229.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/275229.shtml
英文地址,請注明出處:http://en.pswp.cn/news/275229.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

新手向:前端程序員必學基本技能——調試JS代碼

1前言大家好,我是若川。最近組織了源碼共讀活動,感興趣的可以加我微信 ruochuan12 參與,已進行三個月了,大家一起交流學習,共同進步。想學源碼,極力推薦之前我寫的《學習源碼整體架構系列》 包含jQuery、un…

iOS開發ApplePay的介紹與實現

1、Apple Pay的介紹 Apple Pay官方1.1 Apple Pay概念 Apple Pay,簡單來說, 就是一種移動支付方式。通過Touch ID/ Passcode,用戶可使用存儲在iPhone 6, 6p等之后的新設備上的信用卡和借記卡支付證書來授權支付; 它是蘋果公司在2014蘋果秋季新…

mes建設指南_給予和接受建設性批評的設計師指南

mes建設指南Constructive criticism, or more plainly, feedback, plays a crucial role in a designer’s job. Design is an iterative process, so we are often either asking for feedback on our own work or dishing it out to a fellow designer.建設性的批評&#xff…

面試官:請實現一個通用函數把 callback 轉成 promise

1. 前言大家好,我是若川。最近組織了源碼共讀活動,感興趣的可以加我微信 ruochuan12 參與,或者在公眾號:若川視野,回復"源碼"參與,每周大家一起學習200行左右的源碼,共同進步。已進行…

java中filter的用法

filter過濾器主要使用于前臺向后臺傳遞數據是的過濾操作。程度很簡單就不說明了,直接給幾個已經寫好的代碼: 一、使瀏覽器不緩存頁面的過濾器 Java代碼 import javax.servlet.*;import javax.servlet.http.HttpServletResponse;import java.io.IOExcept…

我很喜歡玩游戲,那么我就適合做游戲程序員嗎?

作者:黃小斜文章來源:【程序員江湖】游戲在今天的普及度已經不是端游時代可以比肩的了。如今人手一臺手機、平板就可以吃雞、打農藥,不僅是男生,也有很多女生加入了游戲圈。相信現在在看文章的你也玩游戲,雖然愛玩的程…

open-falcon_NASA在Falcon 9上帶回了蠕蟲-其背后的故事是什么?

open-falconYes, that’s right. The classic NASA “worm” logo is back! An image of the revived NASA worm logo was released on Twitter by NASA Administrator Jim Bridenstine as well as press release on the NASA.gov website. NASA explained that original NASA …

聽說你對 ES6 class 類還不是很了解

大家好,我是若川。最近組織了源碼共讀活動,感興趣的可以加我微信 ruochuan12 參與。前言在ES5中是原型函數,到了ES6中出現了"類"的概念。等同于是ES5的語法糖,大大提升了編寫代碼的速度,本文只講一些常用的&…

《CSS揭秘》讀書筆記

摘要 《CSS揭秘》主要是介紹了使用CSS的技巧,通過47個案例來靈活的使用CSS進行實現,同時在實現過程中注重CSS代碼的靈活性與健壯性。通過閱讀這本書有利于我們編寫高質量的CSS代碼以及打破使用CSS時的固定思維,能夠更加靈活的使用CSS。 《CSS…

一篇文章帶你搞懂前端面試技巧及進階路線

大家好,我是若川。最近有很多朋友給我后臺留言:自己投了不少簡歷,但是收到的面試邀請卻特別少;好不容易收到了大廠的面試邀請,但由于對面試流程不清楚,準備的特別不充分,結果也掛了;…

小屏幕 ui設計_UI設計基礎:屏幕

小屏幕 ui設計重點 (Top highlight)第4部分 (Part 4) Welcome to the fourth part of the UI Design basics. This time we’ll cover the screens you’ll likely design for. This is also a part of the free chapters from Designing User Interfaces.歡迎使用UI設計基礎知…

RabbitMQ指南之四:路由(Routing)和直連交換機(Direct Exchange)

在上一章中,我們構建了一個簡單的日志系統,我們可以把消息廣播給很多的消費者。在本章中我們將增加一個特性:我們可以訂閱這些信息中的一些信息。例如,我們希望只將error級別的錯誤存儲到硬盤中,同時可以將所有級別&am…

不用任何插件實現 WordPress 的彩色標簽云

側邊欄的標簽云(Tag Cloud)一直是 WordPress 2.3 以后的內置功能,一般直接調用函數wp_tag_cloud 或者在 Widgets 里開啟即可,但是默認的全部是一個顏色,只是大小不一樣,很是不順眼,雖然可以用 S…

隨時隨地能寫代碼, vscode.dev 出手了

大家好,我是若川。最近組織了源碼共讀活動,感興趣的可以加我微信 ruochuan12 參與。今天偶然看到了 VSCode 官方發布了一條激動人心的 Twitter,vscode.dev[1] 域名上線了!image-20211021211915942新的域名 vscode.dev[2] 它是一個…

七種主流設計風格_您是哪種設計風格?

七種主流設計風格重點 (Top highlight)I had an idea for another mindblowing test, so here it is. Since you guys liked the first one so much, and I got so many nice, funny responses and private messages on how accurate it actually was, I thought you will prob…

算法精講:分享一道值得分享的算法題

分享一道leetcode上的題,當然,居然不是放在刷題貼里來講,意味著分享的這道題不僅僅是教你怎么來解決,更重要的是這道題引發出來的一些解題技巧或許可以用在其他地方,下面我們來看看這道題的描述。 問題描述 給定一個未…

正幾邊形可以實現無縫拼接?

正n邊形內角為 (n-2)*180/n ,要保證可以無縫拼接,就是一個圓可以被整數個n邊形內角拼接,即 360k*(n-2)*180/n > 2nk(n-2)。(摘自http://blog.csdn.net/ray58750034/article/details/1365813) 以下代碼表明&#xff…

React 18 Beta 來了

大家好,我是若川。最近組織了源碼共讀活動,感興趣的可以加我微信 ruochuan12 參與,目前近3000人參與。經過「React18工作組」幾個月工作,11月16日v18終于從Alpha版本更新到Beta版本。本文會解釋:這次更新帶來的變化對開…

osg著色語言著色_探索數字著色

osg著色語言著色Learn how to colorize icons with your NounPro subscription and Adobe Illustrator.了解如何使用NounPro訂閱和Adobe Illustrator為圖標著色。 For those who want to level up their black and white Noun Project icons with a splash of color, unlockin…

upc組隊賽15 Supreme Number【打表】

Supreme Number題目鏈接 題目描述 A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. Now lets define a number N as the supreme number if and only if each number made up of an non-e…