日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Draw2d 學(xué)習(xí)筆記八 GridLayout ToolbarLayout布

系統(tǒng) 2021 0

原文: http://www.cnblogs.com/bjzhanghao/archive/2006/09/05/495747.html

該文章來之“八進(jìn)制”。

    public class Draw2DLayoutExample {
	static Figure canvas;//Parent figure which uses XYLayout as its layout manager
	static RectangleFigure containerFig;//canvas's only child, which uses ToolbarLayout
	static RectangleFigure innerContainerFig;//containerFig's only child, which uses ToolbarLayout, too
	static RectangleFigure firstGreenFig;//innerContainerFig's first child, which has no layout manager
	static Dimension dimension = new Dimension(40, 20);

	public static void main(String args[]) {
		Shell shell = new Shell();
		shell.setLayout(new GridLayout(1, false));

		//Create control buttons
		Button button = new Button(shell, SWT.PUSH);
		GridData gd = new GridData();
		button.setLayoutData(gd);
		button.setText("Add Red");
		Button button2 = new Button(shell, SWT.PUSH);
		gd = new GridData();
		button2.setLayoutData(gd);
		button2.setText("Add Green");
		Button button3 = new Button(shell, SWT.PUSH);
		gd = new GridData();
		button3.setLayoutData(gd);
		button3.setText("Enlarge Green");

		//Draw2d area
		LightweightSystem lws = new LightweightSystem(shell);

		//The canvas figure which fills right half of shell
		canvas = new Figure();
		canvas.setLayoutManager(new XYLayout());
		lws.setContents(canvas);
		System.out.println(canvas.getLayoutManager());

		//A rectangle figure
		containerFig = new RectangleFigure();
		canvas.add(containerFig);
		canvas.getLayoutManager().setConstraint(containerFig, new Rectangle(120, 10, -1, -1));
		
		ToolbarLayout layout = new ToolbarLayout();
		layout.setVertical(true);
		layout.setSpacing(3);
		layout.setStretchMinorAxis(false);
		containerFig.setLayoutManager(layout);
		containerFig.setBorder(new MarginBorder(5));
		RectangleFigure fig = new RectangleFigure();
		fig.setBackgroundColor(ColorConstants.red);
		fig.setSize(dimension);
		containerFig.add(fig);

		//A inner container figure
		innerContainerFig = new RectangleFigure();
		ToolbarLayout layout2 = new ToolbarLayout();
		layout2.setVertical(false);
		layout2.setSpacing(3);
		layout2.setStretchMinorAxis(false);
		innerContainerFig.setLayoutManager(layout2);
		innerContainerFig.setBorder(new MarginBorder(5));
		containerFig.add(innerContainerFig);

		//The first green figure in innerContainerFig
		firstGreenFig = new RectangleFigure();
		firstGreenFig.setBackgroundColor(ColorConstants.green);
		firstGreenFig.setSize(dimension);
		innerContainerFig.add(firstGreenFig);

		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				RectangleFigure fig = new RectangleFigure();
				fig.setBackgroundColor(ColorConstants.red);
				fig.setPreferredSize(dimension);
				containerFig.add(fig);
			}
		});

		button2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				RectangleFigure fig = new RectangleFigure();
				fig.setBackgroundColor(ColorConstants.green);
				fig.setPreferredSize(dimension);
				innerContainerFig.add(fig);
			}
		});

		button3.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				//Make this figure bigger, and see if the outer figure grows accordingly
				firstGreenFig.setPreferredSize(100, 100);
			}
		});

		shell.setSize(500, 400);
		shell.open();
		shell.setText("Draw2D Layout Example");
		Display display = Display.getDefault();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}
}
  

?
Draw2d 學(xué)習(xí)筆記八 GridLayout ToolbarLayout布局管理器
?

文中提到了:

Draw2D里Figure類的setPreferredSize(Dimension)和setSize(Dimension)的區(qū)別是,setSize()方法不會調(diào)用revalidate()方法導(dǎo)致重新layout,而只是調(diào)用repaint()對所涉及到的“臟”區(qū)域進(jìn)行重繪(repaint)。setPreferredSize()方法可以約等于setSize()方法+revalidate()方法,因?yàn)樵贔igure對getPreferredSize(int,int)的實(shí)現(xiàn)里,若該figure沒有任何layoutmanager,則返回當(dāng)前size:

例如當(dāng)父圖形使用XYLayout,子圖形使用ToolbarLayout時(shí),假設(shè)在子圖形里又增加了子子圖形(子圖形里的子圖形),add()方法會導(dǎo)致revalidate()的調(diào)用,這時(shí)父圖形的xylayout將檢查子圖形是否具有constraint,如果有并且有至少一個(gè)方向?yàn)?1,則利用子圖形上的ToolbarLayout計(jì)算出子圖形新的尺寸,這個(gè)尺寸是和子圖形里包含的子子圖形的數(shù)目有關(guān)的(ToolbarLayout會把每個(gè)子圖形的寬/高度加起來,加上其中間隔的空間,再考慮圖形的邊框,返回得到的尺寸)。

?

指出了figure什么時(shí)候,調(diào)用revalidate()。

Draw2d 學(xué)習(xí)筆記八 GridLayout ToolbarLayout布局管理器


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 霍山县| 江西省| 安化县| 垦利县| 长岭县| 罗平县| 武山县| 迁西县| 垣曲县| 华蓥市| 慈利县| 沧州市| 玛纳斯县| 奇台县| 长治县| 郧西县| 龙陵县| 平谷区| 利辛县| 武陟县| 武安市| 华安县| 荔波县| 佛学| 莱西市| 咸丰县| 察隅县| 吉木萨尔县| 壤塘县| 贵阳市| 革吉县| 楚雄市| 佛山市| 嘉鱼县| 浦东新区| 江西省| 精河县| 南平市| 喀喇| 韶山市| 顺昌县|