﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Jiangshachina-随笔分类-English</title><link>http://www.blogjava.net/jiangshachina/category/16087.html</link><description>同是Java爱好者，相逢何必曾相识！&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;a cup of Java, cheers!</description><language>zh-cn</language><lastBuildDate>Sat, 17 Aug 2013 08:51:37 GMT</lastBuildDate><pubDate>Sat, 17 Aug 2013 08:51:37 GMT</pubDate><ttl>60</ttl><item><title>Oracle OpenWorld 2013(上海)(原)</title><link>http://www.blogjava.net/jiangshachina/archive/2013/08/02/402274.html</link><dc:creator>Sha Jiang</dc:creator><author>Sha Jiang</author><pubDate>Fri, 02 Aug 2013 03:50:00 GMT</pubDate><guid>http://www.blogjava.net/jiangshachina/archive/2013/08/02/402274.html</guid><wfw:comment>http://www.blogjava.net/jiangshachina/comments/402274.html</wfw:comment><comments>http://www.blogjava.net/jiangshachina/archive/2013/08/02/402274.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jiangshachina/comments/commentRss/402274.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiangshachina/services/trackbacks/402274.html</trackback:ping><description><![CDATA[<div><div align="center"><strong><span style="font-size: 14pt; font-family: Courier;">Oracle OpenWorld 2013(上海)</span></strong></div><span style="font-size: 10pt; font-family: Courier;">Oracle OpenWorld 2013(上海)已经结束，我全程参与了此次技术大会。本文是我参会的所见、所闻、所思与所感，有文，有图，且无码。(2013.08.03最后更新)</span><br /><br /><span style="font-size: 10pt; font-family: Courier;">Oracle OpenWorld 2013(Shanghai) lasted four days, and included over 300 keynotes, sessions and hands-on labs. 18000+ attendees, including company leaders, industries experts and developers, joined the event, which was said the biggest IT activity in Asia-Pacific area as never before.</span><br /><br /><strong><span style="font-size: 12pt; font-family: Courier;">Sessions</span></strong><br /><strong style="font-size: 10pt; font-family: Courier;">* Java strategy/technical keynote</strong><br style="font-size: 10pt; font-family: Courier;" /><span style="font-size: 10pt; font-family: Courier;">Every JavaOne conference must has such keynote, which introduces and demonstrates the latest new JDK versions and features, and prospects upcoming JDK version and features. All parts of Java ecosystem, including JME, JSE, JEE and JavaFX, are involved in the keynote. I was deeply impressed by JavaFX demo by Jim Weaver. The Java champion played musical instruments with a JavaFX application; that's really cool. In this JavaOne, JavaFX has a separated track, and the technology is very highlighted by Oracle. The software giant expects JavaFX to enhance Java's performance on rich application. But outspokenly, it's difficult to take end users to install a JRE beforehand if they just want to run a desktop application.</span><br style="font-size: 10pt; font-family: Courier;" /><img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/oow_05.jpg" height="375" width="500" /> <img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/oow_06.jpg" height="375" width="500" /><br /><br /><strong style="font-size: 10pt; font-family: Courier;">* Why should I switch to Java SE 7?</strong><br style="font-size: 10pt; font-family: Courier;" /><span style="font-size: 10pt; font-family: Courier;">JDK 6 has rested in peace(exactly, the version isn't completely frozen), and JDK 7 has been released for two years, and even JDK 8 will come next March. But do you migrate your JRE to Java 7? Strings in switch statements, diamond operator, try with resources, multi-catch statement, ... Do you like the compiler sugar? Anyway, the features could improve development productivity. But fork-join framework really touches my heart. Because of complete backward compatibility, you just need to run your application in the new platform, and the performance could be accelerated.</span><br style="font-size: 10pt; font-family: Courier;" /><br style="font-size: 10pt; font-family: Courier;" /><strong style="font-size: 10pt; font-family: Courier;"><span style="font-size: 10pt;">* The road to Lambda</span></strong><br style="font-size: 10pt; font-family: Courier;" /><span style="font-size: 10pt; font-family: Courier;">Java has been being criticis</span><span style="font-size: 10pt; font-family: Courier;">ed for implementing modern language features, like closure. The argument around closure implementation has lasted for a long time. Finally, Lambda, the closure for Java, has been finished, and will be distributed with JDK 8. Lambda is regarded as the biggest change since Generics in Java 5. Function Programming (FP) is popular, and Java developers can utilise Lambda expression to apply FP. And JDK 8 extends Collection framework to take advantage of Lambda as powerful as possible. For example, currently we need an iterator or loop to iterate a Collection container, that's so-called external iteration. JDK 8 adds a new method forEach() for Collection interface, and we can iterate a Collection object via internal iteration, that means it's no need to care the iteration details by developers. In fact, it's impossible to debug the iterating process. And the process may apply fork-join if possible to improve performance. That sounds cool!</span><br style="font-size: 10pt; font-family: Courier;" /><br style="font-size: 10pt; font-family: Courier;" /><strong style="font-size: 10pt; font-family: Courier;">* Effective Scala</strong><br style="font-size: 10pt; font-family: Courier;" /><span style="font-size: 10pt; font-family: Courier;">Dynamic programming languages are emerging, and more languages, such as Groovy, Scala and Clojure, can run on JVM, and JDK 7 introduced a new instruction "invokeDynamic" to support dynamic languages better. Therefore, I have to pay some attention to other JVM languages. The session "Effective Scala" was provided by TypeSafe, a company founded by Scala creators; Spring founder Rod Johnson joined the company as member of board of directors last year. The session simulated the style of Effective Java, and also introduced some best practices and coding regulations. Frankly, I don't know Scala syntax, like traits, totally, so I don't understand the lecture exactly. But I still obtained something new, like Cake pattern. Do you know the design pattern? I never hear it before this session, but the pattern is well-known in Scala world. It's time to learn another language, and I think Groovy is a good start-up due to it is closer to Java.</span><br style="font-size: 10pt; font-family: Courier;" /><strong style="font-size: 10pt; font-family: Courier;"><br />* Taobao GCIH</strong><br style="font-size: 10pt; font-family: Courier;" /><span style="font-size: 10pt; font-family: Courier;">Taobao creates GCIH (GC Invisible Heap) based on Oracle VM Hotspot, and allows different VM to access a shared heap. In Taobao business scenario, the shared heap only stores read-only objects. All of the objects are initialized after the application is launched, and not be cleaned before the application shutdowns. Therefore, single VM can consume less memory, that means we can deploy more VMs in single machine. And GCIH cannot be accessed by GC so that reducing the garbage collection overhead.</span><br style="font-size: 10pt; font-family: Courier;" /><br style="font-size: 10pt; font-family: Courier;" /><strong style="font-family: Courier;"><span style="font-size: 10pt;">* What do you mean, backwards compatibility?</span></strong><br style="font-size: 10pt; font-family: Courier;" /><span style="font-size: 10pt; font-family: Courier;">10gen, the company behind MongoDB, presented the topic. Because old MongoDB driver isn't well designed, so it's difficult to understand and use the driver API. For example, the driver has a lot of find() methods, but how do I know which one is my want. According to the session, method chaining not only makes codes more readable, and the idiom benefits the backward compatibility as well. Generally, method chaining only handle one parameter at each invoking, and application codes don't care the sequence of invoking. In this case, it's no need to provide the methods with several arguments, and the methods are possible to be deprecated in later time due to their ambiguity. Of course, method chaining isn't designed for backward compatibility. And applying backward compatibility is still a hard job, because you don't know what would happen in the future. In fact, many and many APIs are deprecated in later JDK versions.</span><br style="font-size: 10pt; font-family: Courier;" /><br style="font-size: 10pt; font-family: Courier;" /><strong style="font-family: Courier;"><span style="font-size: 12pt;">Appreciation Party</span></strong><br style="font-size: 10pt; font-family: Courier;" /><span style="font-size: 10pt; font-family: Courier;">In the third evening, Oracle catered a small but exciting party to every attendee. Beer, snacks, professional band, beautiful girls, hot performances, ... were on the stage. All of performances were shown by Oracle employees, and we just rock!</span><br style="font-size: 10pt; font-family: Courier;" /><img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/oow_07.jpg" height="375" width="500" /> <img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/oow_09.jpg" height="375" width="500" /><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/oow_11.jpg" height="533" width="400" /><br /><br /><strong><span style="font-size: 12pt; font-family: Courier;">I was on the scene</span></strong><br /><span style="font-family: Courier;">In OTN lounge, I communicated with Jim Weaver and his assistant about JavaFX and UI testing. In this event, my small dream, taking a photo with Java mascot -- Duke, came true </span><span style="font-family: Courier;">^_^ Additionally, don't forget iron man :-)</span><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/js_01.jpg" height="533" width="400" /> <img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/js_02.jpg" height="533" width="400" /><br /><br /><strong style="font-size: 12pt; font-family: Courier;">Event Organization</strong><br style="font-size: 12pt; font-family: Courier;" /><span style="font-family: Courier;">This is my sixth SunTechDays/OOW, and I must say that the conference was organized the best this time. Professional agenda, considerate attendee service, delicious dessert and drinking, all of them, except for lunch, must be delighted.</span><br style="font-family: Courier;" /><img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/oow_01.jpg" height="375" width="500" /> <img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/oow_02.jpg" height="375" width="500" /><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/oow_04.jpg" height="375" width="500" /> <img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/oow_10.jpg" height="375" width="500" /><br /><img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/oow_13.jpg" height="533" width="400" /> <img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/oow2013/oow_12.jpg" height="533" width="400" /><br /><strong style="font-family: Courier;">Finally, I must say the event is well worth participating; join it, and enjoy it :-)</strong><strong><br /></strong></div><img src ="http://www.blogjava.net/jiangshachina/aggbug/402274.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiangshachina/" target="_blank">Sha Jiang</a> 2013-08-02 11:50 <a href="http://www.blogjava.net/jiangshachina/archive/2013/08/02/402274.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>世界一直在变(原)</title><link>http://www.blogjava.net/jiangshachina/archive/2013/07/14/401546.html</link><dc:creator>Sha Jiang</dc:creator><author>Sha Jiang</author><pubDate>Sun, 14 Jul 2013 03:15:00 GMT</pubDate><guid>http://www.blogjava.net/jiangshachina/archive/2013/07/14/401546.html</guid><wfw:comment>http://www.blogjava.net/jiangshachina/comments/401546.html</wfw:comment><comments>http://www.blogjava.net/jiangshachina/archive/2013/07/14/401546.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/jiangshachina/comments/commentRss/401546.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiangshachina/services/trackbacks/401546.html</trackback:ping><description><![CDATA[<div><div align="center"><strong><span style="font-size: 14pt; font-family: Courier;">世界一直在变</span></strong></div><span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; 最近有点儿闲，看了一些文章，有了一些感触，写成一篇小文。软件世界真的变化很大，没有永恒的终结者。今天的终结者，明天可能就会被别人终结。道理大家都懂，但现实依然很残酷。(2013.07.29最后更新)</span><br /><br /><span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; This week, I read some articles about some API and tools that developers, especially Java guys, must know. Fortunately, I really know some of them, but unfortunately, I really miss something.</span><br /><br /><span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; Please let me introduce some cases at first:</span><br /><span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; 1. In our real projects, we only use JDK 6, but the version had been in End-Of-Life; we never touch JDK 7, but JDK 8 is upcoming. I don't know how much time we would spend on accepting <a href="http://openjdk.java.net/projects/lambda/"><span style="font-family: Courier;">Lambda</span></a></span><span style="font-size: 10pt; font-family: Courier;"> expression. In fact, at present, a lot of Java developers cannot understand Generics exactly, however the syntax has been introduced for more than 8 years. Of course, Java Generics is a bit ambiguous, so it may be difficult to understand.</span><br /><span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; 2. Ant was ever the standard for building, and it still being used by many projects, even new ones. Maven was designed to terminate Ant due to the older cannot make life easy. Some conceptions of Maven, such as build life cycle, dependency management, default directory structure, are very advanced. But Maven dependency and transitive dependency management is nightmare, you have to include/exclude this or that. And extending Maven is also a hard job. I have real experience on both of them, I even wrote some popular preliminary <a href="http://www.blogjava.net/jiangshachina/category/16092.html">blogs</a> about Maven several years ago. But what I really don't know? I don't know Maven is becoming legacy, and worse, a new super star <a href="http://www.gradle.org/"><span style="font-family: Courier;">Gradle</span></a></span><span style="font-size: 10pt; font-family: Courier;"> is on stage. Outspokenly, I never hear of the artifact before this week :-( Outstanding Spring framework is a very case about the trend. At beginning, obviously Spring is built by Ant, then the framework switched to Maven some years ago, but last year Spring migrated to Gradle.</span><br /><span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; 3. Google-Collections was well-known if you used it or not, and I know <a href="http://code.google.com/p/guava-libraries/"><span style="font-family: Courier;">Guava</span></a></span><span style="font-size: 10pt; font-family: Courier;"> however I never use the API. But what I really don't know? I don't know google-collections was closed several years ago, and even it was combined by Guava, which is a new rock star in Java ecosystem.</span><br /><br /><span style="font-size: 10pt; font-family: Courier;">　　OH, something is born, and then grows, and then rests in peace. That's nature, and we have to face it, but why I don't know? Exactly, I have no idea.</span><br /><span style="font-size: 10pt; font-family: Courier;">　　World has been changing, and is changing faster as never before. How to keep us up-to-date with new fashion? I think the question may be asked by every "old" developer. After a long term career life, some of us may become veteran, but absolutely, it's impossible that everyone become expert, particularly the expert in underlying fields. We just be proficient in some programming languages, frameworks, APIs, or tools. So we must update our brains continuously.</span><br /><span style="font-size: 10pt; font-family: Courier;">　　Maybe the issue is one of the middle life crisis problems, good luck for you and me :-)</span></div><img src ="http://www.blogjava.net/jiangshachina/aggbug/401546.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiangshachina/" target="_blank">Sha Jiang</a> 2013-07-14 11:15 <a href="http://www.blogjava.net/jiangshachina/archive/2013/07/14/401546.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle OpenWorld 2013(Shanghai) -- Preview(原)</title><link>http://www.blogjava.net/jiangshachina/archive/2013/05/28/399843.html</link><dc:creator>Sha Jiang</dc:creator><author>Sha Jiang</author><pubDate>Tue, 28 May 2013 13:56:00 GMT</pubDate><guid>http://www.blogjava.net/jiangshachina/archive/2013/05/28/399843.html</guid><wfw:comment>http://www.blogjava.net/jiangshachina/comments/399843.html</wfw:comment><comments>http://www.blogjava.net/jiangshachina/archive/2013/05/28/399843.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jiangshachina/comments/commentRss/399843.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiangshachina/services/trackbacks/399843.html</trackback:ping><description><![CDATA[<div><div align="center"><strong style="font-size: 14pt; font-family: Courier;">Oracle OpenWorld 2013(Shanghai) -- Preview</strong></div><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; Oracle </span><a href="http://www.oracle.com/events/apac/cn/en/openworld/index.html"><span style="font-family: Courier;">OpenWorld</span></a><span style="font-family: Courier;"> 2013(中国)将在七月的上海举行，日前已发布了是次大会的各个</span><a href="https://oraclecn.activeevents.com/connect/search.ww"><span style="font-family: Courier;">专题讲座</span></a><span style="font-family: Courier;">。本文简介了若干我个人比较关注的主题与讲座，希望其他朋友也能感兴趣。(2013.06.06最后更新)</span><br /><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; JavaOne hasn't been an independent event since Sun was required by Oracle, the software giant merged the conference with OpenWorld. As a Java developer, I concentrate more on JavaOne than OpenWorld, but I'm interested in some of OpenWorld sessions. I describe my favorite JavaOne and OpenWorld sessions respectively.</span><br /><br /><strong><span style="font-size: 12pt; font-family: Courier;">JavaOne</span></strong><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; As tradition, every time, there's a keynote or general session about Java present and future. So I think every attendee must focus on "</span><a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=2215"><span style="font-family: Courier;">KEY2215 - Java Strategy / Technical Keynote</span></a><span style="font-family: Courier;">".</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; JDK 6 has rest in peace, and its last update u45 was released last month. And after this February, Oracle will no longer post updates of Java SE 6 to its public download sites. So far, I never touch Java 7 in real world projects. Session "</span><a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=2227"><span style="font-family: Courier;">CON2227 - Why Should I Switch to Java SE 7?</span></a><span style="font-family: Courier;">" may encourage me to switch to JDK 7.</span><br />&nbsp;&nbsp;&nbsp; <a href="http://openjdk.java.net/projects/jdk8/"><span style="font-family: Courier;">Java 8</span></a><span style="font-family: Courier;"> is next major version, and it has delayed for a long time. In this April, Oracle announced this release is rescheduled again due to the guys shifted their focus to </span><a href="http://mreinhold.org/blog/secure-the-train"><span style="font-family: Courier;">security problems</span></a><span style="font-family: Courier;">@_@ Java 8 general available version will be issued in next March. And </span><a href="http://openjdk.java.net/projects/lambda/"><span style="font-family: Courier;">Lambda</span></a><span style="font-family: Courier;"> expression, which is known as the biggest update in Java language since Generics, will be introduced with the new distribution. Sessions "</span><a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=2224"><span style="font-family: Courier;">CON2224 - 55 New Features in Java SE 8</span></a><span style="font-family: Courier;">" and "</span><a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=2241"><span style="font-family: Courier;">CON2241 - The Road to Lambda</span></a><span style="font-family: Courier;">" will glance at the overview and new features of JDK 8.</span><br />&nbsp;&nbsp;&nbsp; <a href="http://oauth.net/"><span style="font-family: Courier;">OAuth</span></a><span style="font-family: Courier;"> is "an open protocol to allow secure authorization in a simple and standard method from web, mobile and desktop applications". I ever developed an experimental desktop application for Sina Weibo, and the Weibo open API platform is using OAuth as its authorization interface. Session "</span><a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1241"><span style="font-family: Courier;">CON1241 - OAuth 101: How to Protect Your Resources in a Web-Connected Environment</span></a><span style="font-family: Courier;">" will introduce the basis of OAuth protocol and demonstrate how to use the authorization.</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; I really concern application performance. How to profile program, how to find the bottleneck, and how to tune performance, all of them are my core focus. In session "</span><a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1327"><span style="font-family: Courier;">CON1327 - Practical Performance: Understand the Performance of Your Application</span></a><span style="font-family: Courier;">", an IBM guy will use JDK built-in tools (maybe VisualVM) to detect and troubleshoot the performance problems.</span><div><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; In daily work, we need to process data in parallel, but I have to say our concurrent logics are pretty simple. However we still suffer from some troubles due to abusing, even worse, misunderstanding the concurrent utilities. Session "</span><a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1250"><span style="font-family: Courier;">CON1250 - Implement a High-Level Parallel API in JDK</span></a><span style="font-family: Courier;">" may inspire me in different approaches.</span></div><br /><strong style="font-size: 12pt; font-family: Courier;">OpenWorld</strong><br style="font-size: 12pt;" />&nbsp;&nbsp;&nbsp; Compared with Oracle, I'm more familiar with MySQL, because it's much simpler. But I just work on MySQL simply: simple user management, simple performance tuning, simple data synchronization, simple backup and restoration, certainly, and simple installation and configuration in Linux environment. But...I have left MySQL for several years. How about the dolphin today? Session "<a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1704">CON1704 - MySQL: State of the Dolphin</a>" may give me some answers, and I hope I could recall the days of playing the artifact.<br />&nbsp;&nbsp;&nbsp; At present, NoSQL, Cloud, big data, ... are the hottest words, even though they aren't on my radar, it's necessary to know some basic conceptions on the fields. Therefore sessions "<a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1445">CON1445 - Oracle NoSQL Database and Oracle Database: A Perfect Fit</a>", "<a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1612">CON1612 - Developing Java Applications in the Cloud: Oracle Java Cloud Service</a>", "<a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=2303">CON2303 - Big Data Overview and Oracle&#8217;s Big Data Solution</a>", and "<a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1476">CON1476 - Implementing Big Data Solutions: From Theory to Practice</a>" are accessible 101 lessons for me.<br />&nbsp;&nbsp;&nbsp; OpenWorld gains more attention from Oracle, so it has more tracks. If I have enough time, and the agenda has no conflict, I'd like to listen to other topics, such as "<a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1554">CON1554 - What&#8217;s New for Java in the Latest Generation of Oracle Database Technology</a>", "<a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1452">CON1452 - Advanced Database Performance Analysis with SQL Performance Analyzer</a>", "<a href="https://oraclecn.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1686">CON1686 - Oracle Linux Strategy and Roadmap</a>", ...</div><img src ="http://www.blogjava.net/jiangshachina/aggbug/399843.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiangshachina/" target="_blank">Sha Jiang</a> 2013-05-28 21:56 <a href="http://www.blogjava.net/jiangshachina/archive/2013/05/28/399843.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Custom Layout Manager: PyramidLayout(原)</title><link>http://www.blogjava.net/jiangshachina/archive/2012/07/15/383156.html</link><dc:creator>Sha Jiang</dc:creator><author>Sha Jiang</author><pubDate>Sun, 15 Jul 2012 14:14:00 GMT</pubDate><guid>http://www.blogjava.net/jiangshachina/archive/2012/07/15/383156.html</guid><wfw:comment>http://www.blogjava.net/jiangshachina/comments/383156.html</wfw:comment><comments>http://www.blogjava.net/jiangshachina/archive/2012/07/15/383156.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/jiangshachina/comments/commentRss/383156.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiangshachina/services/trackbacks/383156.html</trackback:ping><description><![CDATA[<span style="font-size: 10pt; font-family: Courier;"> </span>
<div>
<div align="center"><strong><span style="font-size: 14pt; font-family: Courier;">Custom Layout Manager: PyramidLayout</span></strong></div>&nbsp;&nbsp;&nbsp; <span style="font-size: 10pt; font-family: Courier;">已有太多关于自定义部局管理器的文章了。本文仅是一篇学习笔记，描述了如何实现一种像堆金字塔似的部局管理器，很简单，也有点儿意思，可能你也会感兴趣的。(2012.07.17最后更新)</span><span style="font-size: 10pt;">&nbsp;&nbsp;&nbsp; </span><br />
<br />
<span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; I have developed Swing application for several years, although I'm not professional GUI developer, I'm shamed of never creating any custom layout manager. Maybe the existing Swing layout managers are too powerful to create new ones. At least, <a href="http://docs.oracle.com/javase/7/docs/api/java/awt/GridBagLayout.html"><span style="font-family: Courier;">GridBagLayout</span></a></span><span style="font-size: 10pt; font-family: Courier;"> is powerful enough for my real works. And we have much more flexible <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/GroupLayout.html"><span style="font-family: Courier;">GroupLayout</span></a></span><span style="font-size: 10pt; font-family: Courier;"> and <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/SpringLayout.html"><span style="font-family: Courier;">SpringLayout</span></a></span><span style="font-size: 10pt; font-family: Courier;">, of course, both of them are too complex, in fact I never use them directly. However I indirectly take advantage of GroupLayout due to using <a href="http://netbeans.org/"><span style="font-family: Courier;">NetBeans</span></a></span><span style="font-size: 10pt; font-family: Courier;">' GUI designer <a href="http://netbeans.org/features/java/swing.html"><span style="font-family: Courier;">Matisse</span></a></span><span style="font-size: 10pt; font-family: Courier;">.</span><br />
<br />
<strong><span style="font-size: 12pt; font-family: Courier;">1. Layout Manager basics</span></strong><br />
<span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; Let's start with some layout manager foundation. Before this time I learn to customize layout, I always think layout manager is very mysterious. Layout is like a magic player that put a variety of components to right positions in containers. I haven't browsed any code of any layout, event the simplest one. That's why I think layout is mystery. But it's simple for me now.</span><br />
&nbsp;&nbsp;&nbsp; <span style="font-size: 10pt; font-family: Courier;">Generally, all of layout implements one or both of <a href="http://docs.oracle.com/javase/7/docs/api/java/awt/LayoutManager.html"><span style="font-family: Courier;">LayoutManager</span></a></span><span style="font-size: 10pt; font-family: Courier;"> and <a href="http://docs.oracle.com/javase/7/docs/api/java/awt/LayoutManager2.html"><span style="font-family: Courier;">LayoutManager2</span></a></span><span style="font-size: 10pt; font-family: Courier;"> interfaces. LayoutManager2 is LayoutManager's sub-interface, then if someone implements LayoutManager2 that means it really implements LayoutManager. Mostly all modern layouts implements LayoutManager2.</span><br />
<span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; Interface LayoutManager defines the basic methods must be implemented by every layout, all of them are intuitional: add new component--addLayoutComponent(); remove component--removeLayoutComponent(); calculate preferred size--preferredLayoutSize(); calculate minimum size--minimumLayoutSize(); how to layout the components--layoutContainer(). Absolutely, the layoutContainer() method is essential, you must instruct the parent container how to allocate space(bounds) for every component.</span><br />
<span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; The extension interface LayoutManager2 introduces more methods that if you have to: support constraints--addLayoutComponent(Component, Object); specify maximum size--maximumLayoutSize(); specify alignment--getLayoutAlignmentX() and getLayoutAlignmentY(); destroy specific caches or reset some variables when invaliding container--invalidateLayout().</span><br />
<br />
<strong><span style="font-size: 12pt; font-family: Courier;">2. PyramidLayout</span></strong><br />
<span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; Now let's feature a simple and funny layout manager--PyramidLayout. The layout allows container to add components like building a Pyramid, as shown as the image below,</span><br />
<span style="font-size: 10pt;"></span><img alt="" src="http://www.blogjava.net/images/blogjava_net/jiangshachina/pyramidLayout.PNG" /><br />
<span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; As the above, PyramidLayout puts the first component on the bottom, then puts the second on top of the first, but its bounds is smaller, ... It looks like a Pyramid, doesn't it? Here is the full codes,</span><br />
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">class</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;PyramidLayout&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">implements</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;LayoutManager2&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">private</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;List</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&lt;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">Component</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&gt;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;comps&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">new</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;LinkedList</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&lt;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">Component</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&gt;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">void</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;addLayoutComponent(</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Component&nbsp;comp,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Object&nbsp;constraints)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">synchronized</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;(comp.getTreeLock())&nbsp;{<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;comps.add(comp);<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">void</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;addLayoutComponent(</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;String&nbsp;name,&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Component&nbsp;comp)&nbsp;{<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addLayoutComponent(comp,&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">null</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">);<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">void</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;removeLayoutComponent(</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Component&nbsp;comp)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">synchronized</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;(comp.getTreeLock())&nbsp;{<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;comps.remove(comp);<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">float</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;getLayoutAlignmentX(</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Container&nbsp;target)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">0.5F</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">;<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">float</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;getLayoutAlignmentY(</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Container&nbsp;target)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">0.5F</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">;<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">void</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;invalidateLayout(</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Container&nbsp;target)&nbsp;{<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">public</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Dimension&nbsp;preferredLayoutSize(</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Container&nbsp;parent)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">synchronized</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;(parent.getTreeLock())&nbsp;{<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insets&nbsp;insets&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;parent.getInsets();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">int</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;width&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;insets.left&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">+</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;insets.right;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">int</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;height&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;insets.top&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">+</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;insets.bottom;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">if</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;(comps.size()&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">==</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">0</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">new</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Dimension(width,&nbsp;height);<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dimension&nbsp;size&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;comps.get(</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">0</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">).getPreferredSize();<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">+=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;size.width;<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">+=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;size.height;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">new</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Dimension(width,&nbsp;height);<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">public</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Dimension&nbsp;minimumLayoutSize(</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Container&nbsp;parent)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">synchronized</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;(parent.getTreeLock())&nbsp;{<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insets&nbsp;insets&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;parent.getInsets();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">int</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;width&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;insets.left&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">+</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;insets.right;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">int</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;height&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;insets.top&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">+</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;insets.bottom;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">if</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;(comps.size()&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">==</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">0</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">new</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Dimension(width,&nbsp;height);<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dimension&nbsp;size&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;comps.get(</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">0</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">).getMinimumSize();<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">+=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;size.width;<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">+=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;size.height;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">new</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Dimension(width,&nbsp;height);<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">public</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Dimension&nbsp;maximumLayoutSize(</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Container&nbsp;target)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">new</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Dimension(Integer.MAX_VALUE,&nbsp;Integer.MAX_VALUE);<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">void</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;layoutContainer(</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">final</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Container&nbsp;parent)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">synchronized</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;(parent.getTreeLock())&nbsp;{<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dimension&nbsp;parentSize&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;parent.getSize();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">int</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;compsCount&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;comps.size();<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dimension&nbsp;step&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">new</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Dimension(parentSize.width&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">/</span><span style="color: #000000; "> </span><span style="color: #000000; font-size: 10pt; font-family: Courier;">(2</span><span style="color: #000000; font-family: Courier;"> *</span><span style="color: #000000; font-size: 10pt;"></span><span style="color: #000000; font-size: 10pt; font-family: Courier;"> compsCount),<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parentSize.height&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">/</span><span style="color: #000000; "> </span><span style="color: #000000; font-size: 10pt; font-family: Courier;">(2</span><span style="color: #000000; "> </span><span style="color: #000000; font-size: 10pt; font-family: Courier;">*</span><span style="color: #000000; font-size: 10pt; font-family: Courier;"> compsCount));<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">for</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;(</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">int</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;i&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">0</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">;&nbsp;i&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&lt;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;compsCount;&nbsp;i</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">++</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">)&nbsp;{<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Component&nbsp;comp&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;comps.get(i);<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;comp.setBounds(calcBounds(parentSize,&nbsp;step,&nbsp;i));<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parent.setComponentZOrder(comp,&nbsp;compsCount&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">-</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;i&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">-</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">1</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">);<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">private</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Rectangle&nbsp;calcBounds(Dimension&nbsp;parentSize,&nbsp;Dimension&nbsp;step,&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">int</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;index)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">int</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;x&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;step.width&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">*</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;index;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">int</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;y&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;step.height&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">*</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;index;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">int</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;width&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;parentSize.width&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">-</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;step.width&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">*</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">2</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">*</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;index;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">int</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;height&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">=</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;parentSize.height&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">-</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;step.height&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">*</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">2</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">*</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;index;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Courier;">new</span><span style="color: #000000; font-size: 10pt; font-family: Courier;">&nbsp;Rectangle(x,&nbsp;y,&nbsp;width,&nbsp;height);<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #000000; font-size: 10pt; font-family: Courier;">
}</span></div><span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; Collection instance "comps" manages all of components, in this case, I take a LinkedList object to add and remove UI components. The layout doesn't concern any constraint, so the two addLayoutComponent() methods have the same actions. Please see the codes for details.<br /></span><span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; As aforementioned, layoutContainer() method really takes charge of layouting the components. The key work is allocating space for each component, namely, specifying the bounds. Calculating bounds values just applies the simplest arithmetic operations.<br /></span><span style="font-size: 10pt; font-family: Courier;">&nbsp;&nbsp;&nbsp; According to the intention, the bottom component fills the whole parent container, so it determines the preferred and the minimum sizes. For details, please take a look at methods preferredLayoutSize() and minimumLayoutSize(). Since the layout manager doesn't take care of the maximum size, the maximumLayoutSize() method simply returns a constant value.<br /></span></div><img src ="http://www.blogjava.net/jiangshachina/aggbug/383156.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiangshachina/" target="_blank">Sha Jiang</a> 2012-07-15 22:14 <a href="http://www.blogjava.net/jiangshachina/archive/2012/07/15/383156.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>