玩游戏出现stringtalble fileblurred liness not match怎么解决

Constructing String Graphs in External Memory (PDF Download Available)
For full functionality of ResearchGate it is necessary to enable JavaScript.
Here are the .
See all >4 CitationsSee all >19 References
29.34 · Università degli Studi di Milano-Bicocca26.56 · Università degli Studi di Milano-Bicocca+ 119.85 · Università degli Studi di Milano-Bicocca21.14 · Università degli Studi di Milano-BicoccaShow
more authorsAbstractIn this paper we present an efficient external memory algorithm to compute
the string graph from a collection of reads, which is a fundamental data
representation used for sequence assembly.
Our algorithm builds upon some recent results on lightweight Burrows-Wheeler
Transform (BWT) and Longest Common Prefix (LCP) construction providing, as a
by-product, an efficient procedure to extend intervals of the BWT that could be
of independent interest.
We have implemented our algorithm and compared its efficiency against SGA-the
most advanced assembly string graph construction program.Discover the world's research10+ million members100+ million publications100k+ research projects
Constructing String Graphs in External Memory 325References1. Bankevich, A., Nurk, S., Antipov, D., et al.: SPAdes: A new genome assemblyalgorithm and its applications to single-cell sequencing. J. Comput. Biol. 19(5),455–477 (2012)2. Bauer, M., Cox, A., Rosone, G.: Lightweight algorithms for constructing and in-verting the BWT of string collections. Theor. Comput. Sci. 483, 134–148 (2013)3. Bauer, M.J., Cox, A.J., Rosone, G., Sciortino, M.: Lightweight LCP constructionfor next-generation sequencing datasets. In: Raphael, B., Tang, J. (eds.) WABI2012. LNCS, vol. 7534, pp. 326–337. Springer, Heidelberg (2012)4. Beretta, S., Bonizzoni, P., Della Vedova, G., Pirola, Y., Rizzi, R.: Modeling al-ternative splicing variants from RNA-Seq data with isoform graphs. J. Comput.Biol. 16(1), 16–40 (2014)5. Cox, A.J., Jakobi, T., Rosone, G., Schulz-Trieglaff, O.B.: Comparing DNA sequencecollections by direct comparison of compressed text indexes. In: Raphael, B., Tang,J. (eds.) WABI 2012. LNCS, vol. 7534, pp. 214–224. Springer, Heidelberg (2012)6. Ferragina, P., Gagie, T., Manzini, G.: Lightweight data indexing and compressionin external memory. Algorithmica 63(3), 707–730 (2012)7. Ferragina, P., Manzini, G.: Indexing compressed text. J. ACM 52(4), 552–581(2005)8. Lam, T., Li, R., Tam, A., Wong, S., Wu, E., Yiu, S.: High throughput short readalignment via bi-directional BWT. In: BIBM 2009, pp. 31–36 (2009)9. Myers, E.: The fragment assembly string graph. Bioinformatics 21, ii79–ii85 (2005)10. Peng, Y., Leung, H.C.M., Yiu, S.M., Chin, F.Y.L.: IDBA – A practical iterativede bruijn graph de novo assembler. In: Berger, B. (ed.) RECOMB 2010. LNCS,vol. 6044, pp. 426–440. Springer, Heidelberg (2010)11. Salzberg, S.L., et al.: GAGE: A critical evaluation of genome assemblies and as-sembly algorithms. Genome Res. 22(3), 557–567 (2012)12. Shi, F.: Suffix arrays for multiple strings: A method for on-line multiple stringsearches. In: Jaffar, J., Yap, R.H.C. (eds.) ASIAN 1996. LNCS, vol. 1179,pp. 11–22. Springer, Heidelberg (1996)13. Simpson, J., Durbin, R.: Efficient construction of an assembly string graph usingthe FM-index. Bioinformatics 26(12), i367–i373 (2010)14. Simpson, J., Durbin, R.: Efficient de novo assembly of large genomes using com-pressed data structures. Genome Res. 22, 549–556 (2012)15. Simpson, J., Wong, K., Jackman, S., et al.: ABySS: a parallel assembler for shortread sequence data. Genome Res. 19(6),
&Similarly, a lightweight approach to the construction of the LCP array has been investigated [3]. Towards an external memory genome assembler, LSG [4, 5] is founded upon BCRext and builds in external memory the string graph of a set of strings. In that approach, external memory algorithms to compute the BWT and the LCP array [2, 3] are fundamental. &ABSTRACT: Indexing of very large collections of strings such as those produced by the widespread sequencing technologies, heavily relies on multi-string generalizations of the Burrows-Wheeler Transform (BWT), and for this problem various in-memory algorithms have been proposed. The rapid growing of data that are processed routinely, such as in bioinformatics, requires a large amount of main memory, and this fact has motivated the development of algorithms, to compute the BWT, that work almost entirely in external memory. On the other hand, the related problem of computing the Longest Common Prefix (LCP) array is often instrumental in several algorithms on collection of strings, such as those that compute the suffix-prefix overlap among strings, which is an essential step for many genome assembly algorithms. The best current lightweight approach to compute BWT and LCP array on a set of $m$ strings, each one $k$ characters long, has I/O complexity that is $O(mk^2 \log |\Sigma|)$ (where $|\Sigma|$ is the size of the alphabet), thus it is not optimal. In this paper we propose a novel approach to build BWT and LCP array (simultaneously) with $O(kmL(\log k +\log \sigma))$ I/O complexity, where $L$ is the length of longest substring that appears at least twice in the input strings.Article · Jul 2016 · Algorithmica+1 more author ...&In [18] redundant arcs are those arcs (r, s) labeled by αβ, for α the prefix of an arc (r, t). In [7] we state an equivalent characterization of string graphs, which is given below. An arc e 1 = (r i , r j ) of G O labeled by α is transitive (or reducible) if there exists another arc e 2 = (r k , r j ) labeled by δ where δ is a suffix of α. &ABSTRACT: The string graph for a collection of next-generation reads is a lossless data representation that is fundamental for de novo assemblers based on the overlap-layout-consensus paradigm. In this paper, we explore a novel approach to compute the string graph, based on the FM-index and Burrows-Wheeler Transform. We describe a simple algorithm that uses only the FM-index representation of the collection of reads to construct the string graph, without accessing the input reads. Our algorithm has been integrated into the SGA assembler as a standalone module to construct the string graph. The new integrated assembler has been assessed on a standard benchmark, showing that FSG is significantly faster than SGA while maintaining a moderate use of main memory, and showing practical advantages in running FSG on multiple threads.Article · Apr 2016 · Algorithmica+1 more author ...ABSTRACT: Some recent results (Bauer et al. in Algorithms in bioinformatics, Springer, Berlin, pp 326–337, 2012; Cox et al. in Algorithms in bioinformatics, Springer, Berlin, pp. 214–224, 2012; Rosone and Sciortino in The nature of computation. Logic, algorithms, applications, Springer, Berlin, pp 353–364, 2013) have introduced external-memory algorithms to compute self-indexes of a set of strings, mainly via computing the Burrows–Wheeler transform of the input strings. The motivations for those results stem from Bioinformatics, where a large number of short strings (called reads) are routinely produced and analyzed. In that field, a fundamental problem is to assemble a genome from a large set of much shorter samples extracted from the unknown genome. The approaches that are currently used to tackle this problem are memory-intensive. This fact does not bode well with the ongoing increase in the availability of genomic data. A data structure that is used in genome assembly is the string graph, where vertices correspond to samples and arcs represent two overlapping samples. In this paper we address an open problem of Simpson and Durbin (Bioinformatics 26(12):i367–i373, 2010): to design an external-memory algorithm to compute the string graph.Article · May 2016 +1 more author ...ArticleSeptember 2016 · Algorithmica · Impact Factor: 0.79+1 more author…ChapterSeptember 2016+1 more author…ArticleSeptember 2016+1 more author…ArticleSeptember 2016+1 more author…Data provided are for informational purposes only. Although carefully collected, accuracy cannot be guaranteed. The impact factor represents a rough estimation of the journal's impact factor and does not reflect the actual current impact factor. Publisher conditions are provided by RoMEO. Differing provisions from the publisher's actual policy or licence agreement may be applicable.This publication is from a journal that may support self archiving.
oror log in with2898人阅读
Eclipse.SWT(5)
Java(27)
前言:哈哈哈,最近清理了下群里的人。主要是想整顿下风气,希望大家能活跃一点&,不过好像效果不是很好。还好我做了两手准备,反正留言的是想留下来的,而且有空的。接下来我想和几个人一起做几个小程序出来,毕竟现在不是一个人关门早车有什么前途的年代呀&&今天在学校有空,又翻译了半章。
Advanced&SWT Widegt&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
by Shantha Ramachandran
Department of Computer Science, Uniersity of Manitoba, Winnipeg, Canada
Overview:
接下来的文档中,我们将介绍一些高级的SWT widgets。
Tables:下面的代码会添加一个table控件到你的shell上:
Talble table1= new Table(shell, SWT.BORDER);
它支持的样式有:BORDER,H_SCROLL,V_SCROLL,SINGLE,MULTI,CHECK(这个样式在第一列创建一个check box列),FULL_SELECTION和HIDE_SELECTION。你可以为table设置两个选项。你可以决定是否显示table内的分隔线。你还可以决定是否突出显示列名。这两个属性默认都是关闭的。接下来的代码会教你设置这些属性:
table1.setLinesVisible(true);table1.setHeaderVisible(true);
好了,table已经创建好了,但是默认的它只有一列。如果你想添加了内容到这个table里,也只有第一列内的内容会显示出来。为了显示出你想要的效果,你就必须定义TableColumns。
TalbeColumns:下面代码添加表的列:
TableColumn name = new TableColumn(table1,SWT.LEFT);
它支持的样式有:LEFT,RIGHT和CENTER。你同时也应该设置它的宽度以及列名(如果你想显示列名):
name.setText(&Name&);name.setWidth(50);
为你的表建立了列,现在你就可以往里面添加东西了。这就需要用到TableItem。
TableItem:用下面的代码来向表添加内容:
TableItem item1 = new TableItem(table1, SWT.NONE);
它没有可用的风格,所以你可以放置一个SWT.NONE,它表示0。你可以用setText()方法为这个item设定一个文本:
item1.setText(new String[] {&Sarah&,&15&,&390 Sussex Ave&});
这段代码会建立一个你自己定义内容(文本内容)的TableItem。如果你想要一次定义其中某一个的区域,那么你可以使用setText(int, string)方法。这个方法把文本放在指定的记录中。当建立好TableColumn和TableItem后,你的Table就比较&丰满&了。接下来我们来看个用三个table的例子,然后看下它用了那些不同的风格样式。第一个table有一个边框,大小合适的列以及不同的水平对其方式:
Table&table1&=&new&Table(shell,&SWT.BORDER);table1.setBounds(<span style="COLOR: #,<span style="COLOR: #,<span style="COLOR: #0,<span style="COLOR: #);table1.setLinesVisible(true);TableColumn&name&=&new&TableColumn(table1,SWT.LEFT);name.setText(&Name&);name.setWidth(<span style="COLOR: #);TableColumn&age&=&new&TableColumn(table1,SWT.RIGHT);age.setText(&Age&);age.setWidth(<span style="COLOR: #);TableColumn&address&=&new&TableColumn(table1,SWT.LEFT);address.setText(&Address&);address.setWidth(<span style="COLOR: #0);TableItem&item1&=&new&TableItem(table1,SWT.NONE);item1.setText(new&String[]&...{&Sarah&,&<span style="COLOR: #&,&<span style="COLOR: #0&Sussex&Ave&});TableItem&item2&=&new&TableItem(table1,SWT.NONE);item2.setText(new&String[]&...{&Joseph&,&<span style="COLOR: #&,&<span style="COLOR: #&Yourstreet&St&});
第二个Table有列checkbox。我们可以通过代码设置checked的状态。里面没有网格线,但是它的列名是突出显示的。这个表格的例子还为表格内其中一行设置了背景颜色:
Table&table2&=&new&Table(shell,&SWT.CHECK|SWT.HIDE_SELECTION);table2.setBounds(<span style="COLOR: #,<span style="COLOR: #,<span style="COLOR: #0,<span style="COLOR: #);table2.setHeaderVisible(true);TableColumn&fruit&=&new&TableColumn(table2,SWT.LEFT);fruit.setText(&Fruit&);fruit.setWidth(<span style="COLOR: #0);TableColumn&colour&=&new&TableColumn(table2,SWT.LEFT);colour.setText(&Colour&);colour.setWidth(<span style="COLOR: #0);TableItem&fruit1&=&new&TableItem(table2,SWT.NONE);fruit1.setText(<span style="COLOR: #,&Apple&);fruit1.setText(<span style="COLOR: #,&Red&);fruit1.setChecked(true);TableItem&fruit2&=&new&TableItem(table2,SWT.NONE);fruit2.setText(new&String[]&{&Kiwi&,&Green&});fruit2.setBackground(new&Color(display,<span style="COLOR: #5,<span style="COLOR: #,<span style="COLOR: #));TableItem&fruit3&=&new&TableItem(table2,SWT.NONE);fruit3.setText(new&String[]&{&Banana&,&Yellow&});
最后一个表格的例子用了FULL_SELECTION的样式。它意味着当你选择一个表格的单元格时高亮显示这一整行而不单单显示第一列区域。第一列是大小可变的,也就是说你可以随意用鼠标拖拽它的大小。注意,三列字段都有自己的对其方式:
Table&table3&=&new&Table(shell,&SWT.FULL_SELECTION);table3.setLinesVisible(true);table3.setBounds(<span style="COLOR: #,<span style="COLOR: #0,<span style="COLOR: #0,<span style="COLOR: #);TableColumn&first&=&new&TableColumn(table3,SWT.LEFT);first.setResizable(true);first.setText(&First&);first.setWidth(<span style="COLOR: #);TableColumn&second&=&new&TableColumn(table3,SWT.CENTER);second.setText(&Second&);second.setWidth(<span style="COLOR: #);TableColumn&third&=&new&TableColumn(table3,SWT.RIGHT);third.setText(&Third&);third.setWidth(<span style="COLOR: #);String[]&numbers&=&new&String[]&{&One&,&Two&,&Three&};TableItem&firstItem&=&new&TableItem(table3,SWT.NONE);firstItem.setText(numbers);TableItem&secondItem&=&new&TableItem(table3,SWT.NONE);secondItem.setText(numbers);TableItem&thirdItem&=&new&TableItem(table3,SWT.NONE);thirdItem.setText(numbers);TableItem&fourthItem&=&new&TableItem(table3,SWT.NONE);fourthItem.setText(numbers);table3.select(<span style="COLOR: #);
下面是代码合并后的效果图:
TabFolder:用以下代码添加一个标签页控件(tab folder)到shell:
TabFolder tabFolder1 = new TabFolder(shell,SWT.NONE);
以下代码创建一个TabItem:
TabItem item1 = new TabItem(tabFolder1,SWT.NONE);
TabItem没有相对应的样式。创建一个标签页的一个内容条目必须遵循两个重要的步骤。首先,如果你想让这个标签页显示一个Label,那么你需要用setText()方法去完成。然后为了装上这个刚定义的TabItem,你必须用setControl()方法设置它含有哪个控件:
item1.setText(&Buttons&);item1.setControl(buttonComp);
就像你在后面的例子中看到的一样,buttonComp是一个Composite。之后你可以添加多种控件到这个composite中。下面是这个例子的具体代码:
TabFolder&tabFolder1&=&new&TabFolder(shell,SWT.NONE);tabFolder1.setBounds(<span style="COLOR: #,<span style="COLOR: #,<span style="COLOR: #0,250);//Set&up&the&button&tabComposite&buttonComp&=&new&Composite(tabFolder1,SWT.NONE);Button&button1&=&new&Button(buttonComp,SWT.PUSH);button1.setSize(<span style="COLOR: #0,100);button1.setText(&Hello&);button1.setLocation(<span style="COLOR: #,0);Button&button2&=&new&Button(buttonComp,SWT.ARROW);button2.setBounds(<span style="COLOR: #0,<span style="COLOR: #,<span style="COLOR: #,50);TabItem&item1&=&new&TabItem(tabFolder1,SWT.NONE);item1.setText(&Buttons&);item1.setControl(buttonComp);//Set&up&the&label&tabComposite&labelComp&=&new&Composite(tabFolder1,SWT.NONE);Label&label1&=&new&Label(labelComp,SWT.NONE);label1.setText(&Here&are&some&labels&for&your&viewing&pleasure&);label1.setBounds(<span style="COLOR: #,<span style="COLOR: #,<span style="COLOR: #0,20);Label&label2&=&new&Label(labelComp,SWT.NONE);label2.setText(&A&label&is&a&fine&fingered&fiend&);label2.setBounds(<span style="COLOR: #,<span style="COLOR: #,<span style="COLOR: #0,20);TabItem&item2&=&new&TabItem(tabFolder1,SWT.NONE);item2.setText(&Labels&);item2.setControl(labelComp);
这个例子创建了一个有两个页面的TabFolder,一个用来放按钮,另一个用来放Lable。当窗口初始化显示后,它是下面图示的样子:
如果你单击Labels的标签(tab),那么标签页就转换到Labels的内容下,看上去像这样:
Slider, Scale and Progress Bar:Slider、Scale和Progress Bar是一些很相似的控件。不过他们各自有不同的方法来运行。我们暂时大致了解下这个三个widget,之后会用例子分别看下这些小控件。先由Slider和Scale开始,因为它们两个有很多相同的功能。
以下代码创建一个Slider:
Slider slider1 = new Slider(shell, SWT.HORIZONTAL);
创建一个Scale:
Scale scale1 = new Scale(shell, SWT.HORIZONTAL);
它们两个能设置的样式有:BORDER,HORIZONTAL和VERTICAL。你可以用setMinimum()和setMaximum()方法来设置Slider或者Scale最小值和最大值。
slider1.setMaximum(100);slider1.setMinimum(0);
你可能像设置Slider或者Scale的拖动的位置。下面的代码表示Slider的滑块在中间的情况。
slider1.setSelection(50);
同样,你还可以设置滑块的尺寸。这个尺寸和你设置Slider的最大值和最小值有关。举个例子,如果你设置最小值为0,最大值为100,然后设置滑块的尺寸为30,那么这个滑块将会占整个Slider的三分之一大小。
slider1.setThumb(30);
对于Scale,你可以设置每格的增量。这取决于你放置的刻度的大小。举个例子,如果你设置Scale的最小值为0,最大值为500,然后设置增量为50,那表示整个Scale上有10个刻度。它也取决于Scale的最大值和最小值。
接下来的例子会把两个widget放在一起顺便讨论它们的方法(methods):
Slider&slider1&=&new&Slider(shell,&SWT.HORIZONTAL);slider1.setBounds(<span style="COLOR: #,<span style="COLOR: #,<span style="COLOR: #0,20);slider1.setSelection(50);slider1.setMaximum(100);slider1.setMinimum(0);slider1.setThumb(30);Scale&scale1&=&new&Scale(shell,&SWT.HORIZONTAL);scale1.setBounds(<span style="COLOR: #,<span style="COLOR: #,<span style="COLOR: #0,40);scale1.setMinimum(0);scale1.setMaximum(500);scale1.setSelection(100);scale1.setPageIncrement(<span style="COLOR: #);
下面是这段代码的效果图:
接下来我们来看以下Progress Bar。以下代码创建一个Progress Bar:
ProgressBar progressBar1 = new ProgressBar(shell,SWT.HORIZONTAL);
它可以设置的样式有:BORDER,VERTICAL和HORIZONTAL(就和Slider和Scale一样),不过你还能用SMOOTH样式,它使得进度指示器(progress indicator)变得更加平滑。
对于一个进度条来说,你只能设置它的最小值、最大值以及进度指示位置。进度位置是基于最小值和最大值来设置的(你不能大于最大值或者小于最小值了)。不像Scale或者Slider,你不能改变进度条的宽度,或者进度记号(progress marker)。下列代码本别对这些方法举例:
ProgressBar&progressBar1&=&new&ProgressBar(shell,SWT.HORIZONTAL);progressBar1.setMinimum(0);progressBar1.setMaximum(100);progressBar1.setSelection(30);progressBar1.setBounds(<span style="COLOR: #,<span style="COLOR: #,<span style="COLOR: #0,<span style="COLOR: #);
下面是代码产生的窗口效果:
Menus and MenuItems:我们来看两个菜单的例子。第一个比较基础,只是创建了一个带有选项的普通菜单,并且添加了选择事件。另一个比较大的例子演示了菜单的一些更加复杂的使用,包括子菜单,加速键,mnemoics(不好翻,暂且放这里,下面有介绍,相信大家一看就懂什么意思了:p)还有添加了相应的事件以及一些可用的不同类型的菜单选项(内容)。
用Menu和MenuItem控件可以设置菜单。以下代码在shell的顶部创建了一个菜单。
Menu menu = new Menu(shell, SWT.BAR);shell.setMenuBar(menu);
它的样式必须为SWT.BAR。然后,我们要加点东西到这个菜单栏中去。
MenuItem file = new MenuItem(menu, SWT.CASCADE);file.setText(&File&);
上面的代码会在菜单栏上创建一个名为&File&的选项。如果你就运行这几行代码,你将会看到一个只显示File字样的菜单栏的窗口。而且你按下这个选项也不会发生什么事情。要先保证它(MenuItem)的样式是SWT.CASCADE否则你不能放一个下拉菜单上去。现在我们就来演示当你单击File选项时如何显示一个下拉菜单。
Menu filemenu = new Menu(shell, SWT.DROP_DOWN);file.setMenu(filemenu);
这个菜单的样式必须为SWT.DROP_DOWN,而且要依附到正确的MenuItem上。
最后,我们可以添加一个MenuItem到外面的&File&菜单上,并使它有交互的效果。
MenuItem actionItem = new MenuItem(filemenu, SWT.PUSH);actionItem.setText(&Action&);
通过以下代码,为这个选项添加一个listener:
actionItem.addListener(SWT.Selection,&new&Listener()&{&public&void&handleEvent(Event&e)&{&&System.out.println(&Action&performed!&);&}});
当&Action&选项被按下时,控制台上会输出&Action performed!&。重复这些步骤,你就可以为你的程序添加一些有用的普通菜单了。最后这些菜单会显示成这个样子:
我们现在开始弄点长点的例子。首先要考虑的就是MenuItem支持的其他除了SWT.PUSH的样式。包括CHECK,RADIO,SEPARATOR和CASCADE。第一个是一个checkbox(检查栏)选项,第二个是一个单选按钮选项。SEPARATOR是用来分隔其它选项的水平分隔线,它是不可选中的。下面的代码演示了如何使用CHECK,SEPARATOR和RADIO选项。它会依次创建一条分隔线,一个检查栏样式的菜单选项,最后是一个单选风格的菜单选项。
MenuItem&separator&=&new&MenuItem(filemenu,&SWT.SEPARATOR);final&MenuItem&radioItem&=&new&MenuItem(filemenu,&SWT.RADIO);radioItem.setText(&Radio&);final&MenuItem&checkItem&=&new&MenuItem(filemenu,&SWT.CHECK);checkItem.setText(&Check&);
接下来的几行为Check和Radio选项添加listener(在控制台输出它们当前的值-true或者false)。
radioItem.addListener(SWT.Selection,&new&Listener()&{&public&void&handleEvent(Event&e)&{&&System.out.println(&Radio&item&toggled&to:&+&&&radioItem.getSelection());&}});checkItem.addListener(SWT.Selection,&new&Listener()&{&public&void&handleEvent(Event&e)&{&&System.out.println(&Check&item&toggled&to:&&+&&&checkItem.getSelection());&}});
接下来我们创建一个子菜单,就和创建菜单到菜单栏很相似。我们用SWT.CASCADE样式创建一个新的MenuItem,然后创建一个新的菜单并依附到这个下拉菜单上去。我们可以调用setMenu()方法来添加这个新建的菜单。
MenuItem&cascadeItem&=&new&MenuItem(filemenu,&SWT.CASCADE);cascadeItem.setText(&Cascade&);Menu&submenu&=&new&Menu(shell,&SWT.DROP_DOWN);cascadeItem.setMenu(submenu);
下面的几行代码添加一个菜单选项到上面的子菜单中。新的选项叫做&SubAction&。注意,在setText()方法中,在S之前有一个&的记号。这样设置后,当子菜单显示时,只要按下键盘上的S键就会选中这个选项,就像用鼠标选中一样(就像有记忆效果一样,这里叫做mnemonic)。调用中接下来在该选项(SubAction)上设置了一个加速键(setAccelerator()),当按下Control-S的联合按钮时就直接执行SubAction命令,无论是否点开了这个下拉菜单。
final&MenuItem&subactionItem&=&new&MenuItem(submenu,&SWT.PUSH);subactionItem.setText(&&SubAction Ctrl+S&);subactionItem.setAccelerator(SWT.CTRL+'S');
我们在这个子菜单上添加一个额外的选项用来演示启用和屏蔽MenuItem的效果。我们添加一个检查栏,它会启动和屏蔽SubAction这个选项:
final&MenuItem&enableItem&=&new&MenuItem(submenu,&SWT.CHECK);enableItem.setText(&Enable&SubAction&);
这里我们添加一个之前从来没有用到过的listener:MenuListener,它会在控制台告诉我们按钮的状态:
submenu.addMenuListener(new&MenuListener()&{&public&void&menuShown(MenuEvent&e)&{&&System.out.println(&SubMenu&shown&);&}&public&void&menuHidden(MenuEvent&e)&{&&System.out.println(&SubMenu&hidden&);&}});
下面来用另一个检查栏选项来设置启动还是屏蔽菜单选项。第一行首先使得SubAction一开始就被屏蔽,它的文本的颜色是暗的。当屏蔽掉了后,你就不能选择该选项,并且它上面的加速键也失灵了。后面的代码添加了一个listener,它依据&Enable SubAction&这个检查栏选项是否被按下来屏蔽或者启用SubAction这个MenuItem选项。
subactionItem.setEnabled(false);enableItem.addListener(SWT.Selection,&new&Listener()&{&public&void&handleEvent(Event&e)&{&&System.out.println(&Toggling&&Enable&SubAction&&to&&&+&&&enableItem.getSelection());&&subactionItem.setEnabled(enableItem.getSelection());&}});
添加一个普通的listener:
subactionItem.addSelectionListener(new&SelectionListener()&{&public&void&widgetSelected(SelectionEvent&e)&{&&System.out.println(&SubAction&performed!&);&}&public&void&widgetDefaultSelected(SelectionEvent&e)&{&}});
另一个有趣的listener是ArmListener。当一个菜单选项因为鼠标或者键盘变成高亮(其实也就是指针或者用方向键移到该选项上)但是没有选中(没有按下左键或者回车键)时调用内部的widgetArmed(ArmEvent e)方法。
subactionItem.addArmListener(new&ArmListener()&{&public&void&widgetArmed(ArmEvent&e)&{&&System.out.println(&SubAction&armed!&);&}});
最后的listener类型是HelpListener。当按下F1/Help键时激活HelpListener。它可能会通过各种各样的选项提供很多有用的帮助。
subactionItem.addHelpListener(new&HelpListener()&{&public&void&helpRequested(HelpEvent&e)&{&&System.out.println(&Help&requested&on&SubAction&);&}});
当按下Enable SubAction选项时将会激活SubAction。按Ctrl+S将执行SubAction对应的程序,但是只有当Enable SubAction是选中的情况下才有用。当listener激活时,它们会向控制台打印信息。
Menu和MenuItem还有很多其他可用的小工具,我们这里尽量介绍其中多数的有用的一部分。下面让我们来简要得看一下简单的pop-up菜单。
Popup Menus:Pop-up菜单是很有用的context-sensitive菜单,它可以在屏幕上不同的区域出现,它远比让用户去菜单栏找寻他们想要的选项然后按下要方便快速地多!在一个Composite上用鼠标右键单击就会在鼠标指针边上浮现一个pop-up菜单,它上面以列表的形式让用户选择一些常用的菜单。在下面的演示中,我们在shell的composite中创建了一个按钮。然后我们创建了两个pop-up菜单,然后一个在这个按钮上响应,另一个在composite和shell中得到响应。我们首先创建一个SWT.POP_UP风格的菜单,然后添加一些选项进去,然后用一个listener来捕捉选择的事件。下面这个是用在shell和composite响应的:
Menu&popupmenu&=&new&Menu(shell,&SWT.POP_UP);MenuItem&actionItem&=&new&MenuItem(popupmenu,&SWT.PUSH);actionItem.setText(&Other&Action&);actionItem.addListener(SWT.Selection,&new&Listener()&{&public&void&handleEvent(Event&e)&{&&System.out.println(&Other&Action&performed!&);&}});
我们重复上面的过程,下面的代码会和按钮联系起来:
Menu&popupmenu2&=&new&Menu(shell,&SWT.POP_UP);MenuItem&buttonItem&=&new&MenuItem(popupmenu2,&SWT.PUSH);buttonItem.setText(&Button&Action&);buttonItem.addListener(SWT.Selection,&new&Listener()&{&public&void&handleEvent(Event&e)&{&&System.out.println(&Button&Action&performed!&);&}});
然后我们创建一个composite和一个button。
Composite&c1&=&new&Composite&(shell,&SWT.BORDER);c1.setSize&(<span style="COLOR: #0,&<span style="COLOR: #0);c1.setLocation(<span style="COLOR: #,<span style="COLOR: #);Button&b&=&new&Button(c1,&SWT.PUSH);b.setText(&Button&);b.setSize(<span style="COLOR: #,<span style="COLOR: #);b.setLocation(<span style="COLOR: #,<span style="COLOR: #);
最后,我们为相应的控件设置pop-up菜单。
b.setMenu(popupmenu2);c1.setMenu&(popupmenu);shell.setMenu&(popupmenu);
现在我们可以运行代码,然后在按钮上点右键,它会显示一个菜单,如果我们在composite或者shell上点右键我们会看到一个带不同菜单选项的菜单显示在屏幕上。下面的图例是在按钮上点击右键后的结果。
虽然这是一个简单的例子,但是弹出(pop-up)菜单可以和子菜单、单选、listener等一起使得早前我们写的Menu bar的例子更加复杂。(这就看你的需要的了咯~)
先翻到这里吧,我发现我已经有点思维混乱了,翻得也是牛头不对马嘴,休息下下&&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:296051次
积分:4085
积分:4085
排名:第5296名
原创:103篇
转载:26篇
评论:70条
(2)(2)(7)(4)(2)(1)(1)(1)(1)(1)(1)(2)(1)(2)(5)(4)(1)(7)(6)(10)(1)(2)(1)(7)(1)(2)(39)(11)(10)

我要回帖

更多关于 blurred lines 原版mv 的文章

 

随机推荐