ä»æ¥ã¯ãJavaã§ã°ã©ãã£ãã¯ã¹ãæäœããéã®ããã€ãã®åŽé¢ãšåŸ®åŠãªç¹ã«åã³æ³šæãåããããšããŸãã ååã®èšäºã§ãã³ã³ããŒãã³ããšUIãäœæããããã®å©çšå¯èœãªããŒã«ãšæ¹æ³ã®ããã€ããç°¡åã«èª¬æããŸããããããã¯æ°·å±±ã®äžè§ã«ãããŸããã ãã®ãããã°ã©ãã£ãã¯ã¹ãæ±ãããã«ç¹å¥ãªæ³šæïŒããã³èšäºïŒãæãããã®ã§ãã ãã¡ãããGraphics2Dãæå³ããŸã-Java 3Dã¯å¥ã®å€§ããªãããã¯ã§ãïŒå€åããã¯å°æ¥è°è«ãããã§ãããããä»æ¥ã¯è°è«ãããªãã§ãããïŒã
ãããã£ãŠãåã®èšäºãããã³ã³ããŒãã³ãã®æ§ç¯ã®åºæ¬ããã§ã«ç¥ã£ãŠããã¯ãã§ã-ãã®ç¥èãåºããããšããŸãã
ãŸãã MVCã®èŠ³ç¹ããã³ã³ããŒãã³ããèŠããšã3ã€ã®éšåã§æ§æãããŠããŸãã
ã¢ãã« -ã³ã³ããŒãã³ãã®ç¶æ ã«é¢ããããŒã¿ãæ ŒçŽããããã«åºã¥ããŠå€èŠ³ãæ§ç¯ãããã¢ãã«
衚瀺 -ã³ã³ããŒãã³ããçŽæ¥èŠèŠçã«è¡šç€º
ã³ã³ãããŒã©ãŒ -ã³ã³ããŒãã³ãïŒããŒããŒããããŠã¹ããã®ä»ã®å ¥åããã€ã¹ããã®ã€ãã³ãïŒã®ç®¡çãæ åœããŸã
å®éããã¹ãŠã®æšæºSwingã³ã³ããŒãã³ãã¯MVCãã¿ãŒã³ã䜿çšããŠæ§ç¯ãããŠããŸãã ããšãã°ãJButtonã®å ŽåãButtonModelã¯ãã¿ã³ã®åäœãšç¶æ ïŒControllerãšModelïŒãButtonUIã¯å€éšè¡šçŸïŒViewïŒãæ åœããŸãã ãã®çµæãJButtonã¯ã©ã¹èªäœã«ã¯ã»ãšãã©äœãæ®ããŸããã ããã¯äž»ã«ãã³ã³ããŒãã³ãã®å€éšè¡šçŸïŒViewïŒã®å®è£ ãæ±ããGraphics2Dãæå®ããå Žåãå®éã«ã¯ããã«åºã¥ããŠã€ã³ã¿ãŒãã§ãŒã¹å šäœãæç»ãããŸãã
ç§ã¯ãã®ãããã¯ã«å€ãã®ç°ãªãè³æããããšäž»åŒµããŸããããããã¯éåžžã«æçåãããŠããããããã¯ãŒã¯ã®åºå€§ãªåºããã®åšãã«æ£ãã°ã£ãŠããããã1ã€ã®å Žæã«ãã¹ãŠãéããŠäžè²«ããŠè¿°ã¹ãããšã¯å Žéãã§ã¯ãªãããã§ãã
æã§äŒããŸããã
誰ãèšã£ããšããŠããã€ã³ã¿ãŒãã§ãŒã¹ã¯åžžã«ã¢ããªã±ãŒã·ã§ã³ã®æåã«éèŠãªåœ¹å²ãæãããæãããæãããŸãã ã¢ããªã±ãŒã·ã§ã³ã®å¯Ÿè±¡è ã«å¿ããŠãã€ã³ã¿ãŒãã§ãŒã¹ã®åœ¹å²ã¯äºæ¬¡çã§ãããããã®éã§ã-äž»èŠã§æãéèŠã§ãã ããšãã°ãã²ãŒã ãããŸããŸãªãšãã£ã¿ãŒã¢ããªã±ãŒã·ã§ã³ã®å Žåãã€ã³ã¿ãŒãã§ã€ã¹ãšäœ¿ããããããã¹ãŠã決å®ããŸãïŒããã¯ãååé »ç¹ã«ããŸãã¯é·æé䜿çšããã¢ããªã±ãŒã·ã§ã³ã§ããããã§ãïŒããã®ãããæ¬æ¥ã¯ãGraphics2DãæäŸããæšæºããŒã«ãšãè€éãªã³ã³ããŒãã³ããã¬ã³ããªã³ã°ããããã®ãã¯ããã¯ãšããªãã¯ãåæããŸãã
è³¢æãªèãããªããã°ãäœãããã®ãå©ããæ段ã¯ãªãããšã¯æããã§ãããæ®å¿µãªãããç§ã¯ç¡åã§ãã ãããããã¡ã³ã¿ãžãŒã§ãã¹ãŠãæ¬åœã«æªãã®ã§ããã°ããããããã¶ã€ããŒ/ UXã®å°é家ãããªããå©ããããšãã§ããŸãã æ£çŽãªãšãããæ°ããã³ã³ããŒãã³ããã©ã®ããã«èŠããããèªåã§ãçµãåºããã®ã¯é£ããå ŽåããããŸãã äœæ¥ã³ãŒããçŽæ¥èšè¿°ããŠãããã°ãããããããã«è€éã§æéãããããŸãã
ãããã«ãããããžãã¹ã«åãããããŸããã...
å°ããªç®æ¬¡
- ãã£ã®ã¥ã¢
- ã¬ã³ããªã³ã°ãã³ã
- 泚ã
- å³é¢ã®é 眮
- ã¹ãããŒã¯
- 圱
- æ£ããã¯ãªããã³ã°
- ã¢ãã¡ãŒã·ã§ã³
- ããã€ãã®ããªãã¯
- WebLookAndFeel
- çµè«ãšããŠ...
- è³æº
ãã£ã®ã¥ã¢
æ°åãªãã§ã¯ã©ãã«ããããŸããã ã³ã³ããŒãã³ããæãåçŽãªãã®ã«ã€ããŠã¯ãããŒãã®èŒªéãæãå¿ èŠããããŸãã æåã§ãã¯ã»ã«åäœã§å®è¡ããã®ã¯æ¥œããäœæ¥ã§ã¯ãããŸããã ç¹ã«ãã¬ã³ããªã³ã°ã«ã¹ã ãŒãžã³ã°ãŸãã¯ãã®ä»ã®å¹æãè¿œå ããå¿ èŠãããå Žåã æåã§ãããè¡ãå¿ èŠã¯ãããŸãã-ã¬ã³ããªã³ã°ã«å¿ èŠãªãã¹ãŠã®æšæºå³åœ¢ïŒLine2DãRectangle2DãRoundRectangle2DãEllipse2DãArc2Dãªã©ïŒã¯æ¢ã«å®è£ ãããŠããŸã-ç¹å®ã®å Žæã«æç»ããããã®åº§æšãšãµã€ãºãæå®ããã ãã§ãæšæºã®ã·ã§ã€ãã«å ããŠãç¬èªã®ã·ã§ã€ãããã°ããäœæã§ããç¹å®ã®ã·ã§ã€ãïŒGeneralPathãªã©ïŒããããŸãã
ããŸããŸãªç¹å®ã®åœ¢åŒãæã€ããã€ãã®åå¥ã®ãããžã§ã¯ãããããŸãã
http://java-sl.com/shapes.html
http://geosoft.no/graphics/
http://designervista.com/shapes/index.php
http://www.jfree.org/jcommon/
åã ã®å³ã説æããããšã¯æå³ããããŸãã- ãããŸãã¯ããã§è©³çŽ°ã«èªãããšãã§ããŸã ïŒäž¡æ¹ã®èª¬æã«ã¯äœ¿çšäŸããããŸãïŒã
ããã§ãå³ãã©ã®ããã«æãããæçµçµæã«ã©ã®ãããªåœ±é¿ããããã«ã€ããŠå°ãæ確ã«ããããšæããŸãã ç¹å®ã®åœ¢ç¶ïŒåœ¢ç¶ïŒããããšããŸãïŒ
- 2ã€ã®ç°ãªãæ¹æ³-g2d.fillïŒåœ¢ç¶ïŒãšg2d.drawïŒåœ¢ç¶ïŒã䜿çšã§ããŸãã Fill-ã·ã§ã€ãå ã®ãã¹ãŠã®ãã¯ã»ã«ãå¡ãã€ã¶ããŸããdraw-ã·ã§ã€ãã®ã¢ãŠãã©ã€ã³ãæç»ããŸãã
- Paintã¯ã©ã¹ã®ã€ã³ã¹ããŒã«ãããåå«ïŒg2d.setPaintïŒãã€ã³ããã€ã³ãïŒïŒã¯ãã¬ã³ããªã³ã°ãå®è¡ãããè²ãæ åœããŸããã¬ã³ãã©ãŒã«é åã®åã ã®ãã¯ã»ã«ã®è²ãæäŸããŸãã ãã®ã¢ãŒãã®æãåçŽãªããŒãžã§ã³ã¯ä»»æã®è²ïŒè²ïŒã§ã-åãã¯ã»ã«ã«åãè²ãè¿ãã ãã§ãã ããè€éãªäŸã¯ãããšãã°ãã°ã©ããŒã·ã§ã³ãšãã¯ã¹ãã£ã®å¡ãã€ã¶ãïŒGradientPaintãTexturePaintãªã©ïŒã§ãã
- Figureã®ã¢ãŠãã©ã€ã³ã®å¢çç·ã®ã³ãŒããŒãšãšããžã§ã®å€ªããé »åºŠïŒãŸãã¯ããã·ã¥ïŒãããã³é¢é£ä»ãã®ã¿ã€ãã¯ãã¹ãããŒã¯ã®èšå®ïŒg2d.setStrokeïŒã¹ãããŒã¯ïŒïŒã®åœ±é¿ãåããŸãã
- å³ãããã¹ãã®ã¹ã ãŒãžã³ã°ãã¬ã³ããªã³ã°å質ãããã³ãã®ä»ã®ãã€ã³ãã¯ã以äžã®ç« ã§èª¬æããããŸããŸãªãã©ã¡ãŒã¿ãŒã®åœ±é¿ãåããŸãã
ã¬ã³ããªã³ã°ãã³ã
ã¢ã³ããšã€ãªã¢ã¹ã¯ãGraphics2Dã«ãã³ãã«ãããŠããæšæºããŒã«ã®ã»ããã«å«ãŸããŠããŸããg2d.setRenderingHintïŒRenderingHints.KEY_ANTIALIASINGãRenderingHints.VALUE_ANTIALIAS_ONïŒ;
ããã¯ãå°æ¥æç»ããããã¹ãŠã®åœ¢ç¶ã®å¹³æ»åãå¯èœã«ããã®ã«ååã§ãã
èŠããŠããã¹ãäž»ãªããšã¯ãæäœåŸã«ã¢ã³ããšã€ãªã¢ã¹ããªãã«ããããšã§ããåŸã«ã¬ã³ããªã³ã°ããããã¹ãŠã®ãã®ã«ã¢ã³ããšã€ãªã¢ã¹ã䜿çšããããªãå Žå-ããšãã°ããã¿ã³ã®èæ¯ã¬ã³ããªã³ã°ãå®è£ ããããã©ã«ãã§æç»ãããããã¹ãã®ã¹ã ãŒãžã³ã°ãçºçãããããªãå Žåã
ãã®ãã©ã¡ãŒã¿ãŒã®å€ïŒRenderingHints.KEY_ANTIALIASINGïŒã¯ãããã©ã«ãã®éžæãããå Žåãããã¹ãã®å¹³æ»åã«ã圱é¿ããŸãã
ããã¹ãã¹ã ãŒãžã³ã°ã®å¿ èŠæ§ãåå¥ã«æå¹å/ç¡å¹åããããšãã§ããŸãã
g2d.setRenderingHintïŒRenderingHints.KEY_TEXT_ANTIALIASINGãRenderingHints.VALUE_TEXT_ANTIALIAS_ONïŒ;
ãã®ãã©ã¡ãŒã¿ãŒãVALUE_TEXT_ANTIALIAS_DEFAULT以å€ã«èšå®ãããŠããå Žåãå€RenderingHints.KEY_ANTIALIASINGã¯ç¡èŠãããŸãã
以äžã¯ãã¢ã³ããšã€ãªã¢ã¹ã䜿çšããå Žåãšäœ¿çšããªãå Žåã®ã¬ã³ããªã³ã°ã®éãã瀺ãå°ããã·ã³ãã«ãªäŸã§ãã
ïŒäŸãšãœãŒã¹ã³ãŒãã¯ãã¡ãããããŠã³ããŒãã§ããŸã ïŒ
ããèŠããšãRenderingHintsã§å©çšå¯èœãªä»ã®å€ãã®èšå®ã«ãæ°ä»ãã§ãããã
KEY_ANTIALIASING-圢ç¶ïŒããã³ããã¹ãïŒãå¹³æ»åããããã®èšå®
KEY_RENDERING-å質/ã¬ã³ããªã³ã°é床ã®èšå®
KEY_DITHERING-å¶éããããã¬ããã§ã®è²ã®æ··å
KEY_TEXT_ANTIALIASING-ããã¹ãã®ã¢ã³ããšã€ãªã¢ã¹èšå®
KEY_TEXT_LCD_CONTRAST-ç¹æ®ãªããã¹ãã¹ã ãŒãžã³ã°ã䜿çšããŠã¬ã³ããªã³ã°ãããšãã®ããã¹ãã³ã³ãã©ã¹ãïŒ100ã250ïŒ
KEY_FRACTIONALMETRICS-ããã¹ãæåã®ã¬ã³ããªã³ã°ã®ã粟床ãã®èšå®
KEY_INTERPOLATION-ã¬ã³ããªã³ã°äžã®ã€ã¡ãŒãžãã¯ã»ã«ã®å€æŽãæ åœããèšå®ïŒããšãã°ãã€ã¡ãŒãžãå転ããå ŽåïŒ
KEY_ALPHA_INTERPOLATION-ã¢ã«ãã¡å€ã®å質/åŠçé床ã®èšå®
KEY_COLOR_RENDERING-å質/ã«ã©ãŒåŠçé床ã®èšå®
KEY_STROKE_CONTROL-ã·ã§ã€ãã®ãžãªã¡ããªãå€æŽããŠæçµãã¥ãŒãæ¹åããæ©èœãèšå®ãã
éåžžããããã®èšå®ã®ã»ãšãã©ã¯ããã©ã«ãç¶æ ã®ãŸãŸã§ãã ãã ããç¹å®ã®ã±ãŒã¹ã§ã¯éåžžã«åœ¹ç«ã¡ãŸãã
ããšãã°ãKEY_INTERPOLATIONãVALUE_INTERPOLATION_BILINEARã«èšå®ãããšãå€æŽæã®ç»è³ªã®äœäžïŒå転/å§çž®/ã·ãããªã©ïŒãåé¿ããããããã¹ãã¬ã³ããªã³ã°ã³ãŒãã«åœ±é¿ãäžããã«KEY_TEXT_LCD_CONTRASTãå€æŽããŠèæ¯ã®ããã¹ãã®ã³ã³ãã©ã¹ããæ¹åã§ããŸãã
ãããã®å Žåãããããã®èšå®ãæ éã«äœ¿çšããã¬ã³ããªã³ã°ã¡ãœããã®ç¯å²ãè¶ ããªãããã«ããŠãã ãããããšãã°ãJTextFieldã«å«ãŸããåãã¢ã³ããšã€ãªã¢ã·ã³ã°ã¯ãããã¹ãã®å¹³æ»åãšãã®å€æŽïŒããã³ããããã·ããïŒã«ã€ãªããããã§ãã
泚ã
Paintã¯ã©ã¹ã®ããã€ãã®ã¢ã¯ã»ã¹å¯èœãªåå«ããããã¬ã³ããªã³ã°ãããå³åœ¢ãããŸããŸãªæ¹æ³ã§ãã€ã³ã/å¡ãã€ã¶ãããšãã§ããŸãã- è² -æãåçŽãªã1ã€ã®è²ã§å³åœ¢ãæç»ãŸãã¯å¡ãã€ã¶ããŸãã
- TexturePaint-æ¢åã®BufferedImageãå¡ãã€ã¶ã/ã¬ã³ããªã³ã°ã®èæ¯ç»åãšããŠäœ¿çšã§ããŸãã
- GradientPaint -1ã€ã®ãã€ã³ãããå¥ã®ãã€ã³ããžã®åçŽãªç·åœ¢ã°ã©ããŒã·ã§ã³ã§ãéå§è²ãšçµäºè²ããããŸãã
- LinearGradientPaint-ããç¹ããå¥ã®ç¹ãžã®ããè€éãªç·åœ¢ã°ã©ããŒã·ã§ã³ã§ããããã®éã®è·é¢ãåå®çŸ©ãããä»»æã®æ°ã®äžéè²ã
- RadialGradientPaint -LinearGradientPaintãšåæ§ã«ãåã®äžå¿ãšååŸãããã³ãããã®éã®è²ãšè·é¢ã瀺ãå圢ã°ã©ããŒã·ã§ã³ã
ããããããããããã«ã3ã€ã®ç°ãªãã°ã©ããŒã·ã§ã³ã䜿çšããŠã³ã³ããŒãã³ãã®3ã€ã®çããéšåãåããå°ããªäŸã瀺ããŸãã
ïŒäŸãšãœãŒã¹ã³ãŒãã¯ãã¡ãããããŠã³ããŒãã§ããŸã ïŒ
ã¡ãªã¿ã«ãè²ãæå®ããéã®å¡ãã€ã¶ã/ã¬ã³ããªã³ã°ã§ã¯ãéæ床ïŒã¢ã«ãã¡ïŒãæå®ã§ããããšã誰ããç¥ã£ãŠãããšã¯éããŸããã
ããšãã°ãæ°ããè²ïŒ255ã255ã255ã128ïŒ-50ïŒ ã®çœè²ãŸã§éæã§ãã ãã®å Žåã®ã¢ã«ãã¡ã¯128ã§ãã0ãã255ãŸã§å€åã§ããŸãã0ã¯å®å šã«éæãªè²ã§ã255ã¯å®å šã«äžéæã§ãïŒããã©ã«ãã§äœ¿çšïŒã
å³é¢ã®é 眮
ããã§ãç§ãã¡ã¯äœç³»çã«ãã£ãšè€éãªããšã«ç§»è¡ããŠããŸã...AlignmentïŒèšãæããã°ãCompositeïŒã䜿çšãããšããã£ã³ãã¹ã«æ¢ã«ãã¯ã»ã«ãé 眮ãããŠããæ°ããæç»å³åœ¢/ç»åã®ããŸããŸãªãã¢ãŒããã®é 眮ãæå®ã§ããŸãã
ããã§ã¯ãããŸããŸãªã¢ã©ã€ã¡ã³ãã®ãã¢ãŒããã®æãæåããã€ã©ã¹ããšãæããã人ç©ã«å¯Ÿããå®éã®åœ±é¿ã®äŸãèŠã€ããããšãã§ããŸãã ã åãã¢ãŒããã®è©³çŽ°ãªèª¬æããããŸãã
å®éã«ã¯ãå人çã«ã¯ãAlphaComposite.SRC_OVERãªãã·ã§ã³ã䜿çšããæ¢ã«æç»ãããŠãããã®ã®äžã«ç¹å®ã®éæ床ã§ããã«èŠçŽ ãæç»ããããã«éæ床ãæå®ããããšãã»ãšãã©ã§ãã ãŸããç»åãæäœãããšãã«ããã€ãã®ã¢ãŒããé©çšããéåžžã«èå³æ·±ãäŸããããŸãããããã«ã€ããŠã¯åŸã§è©³ãã説æããŸãã
ã³ã³ããžããã«å ããŠãæšæºã®ã·ã§ã€ãã䜿çšããŠç¬èªã®ã·ã§ã€ããäœæããããŸããŸãªå¹ŸäœåŠçæäœãšçµã¿åãããããšãã§ããŸãã ãã®ãããã¯ã«é¢ããå°ããªäŸïŒ
ïŒäŸãšãœãŒã¹ã³ãŒãã¯ãã¡ãããããŠã³ããŒãã§ããŸã ïŒ
ãã®å³ãäœæããã®ã«å¿ èŠãªã®ã¯2è¡ã ãã§ãã
Area area = new Area ( new Ellipse2D.Double ( 0, 0, 75, 75 ) );
area.add ( new Area ( new Ellipse2D.Double ( 0, 50, 75, 75 ) ) );
æãèå³æ·±ãã®ã¯ãæ°ããå³åœ¢ã®å¢çç·ã«ã¯ãæ¥åã®å¢çç·ïŒæ¥åã®å察åŽã«ããå¢çç·ïŒã®å éšéšåãå«ãŸããŠããªãããšã§ãã
äžè¬çã«ãAreaã¯ããŸããŸãªçšéã«äœ¿çšã§ããŸããæ¢åã®å³åœ¢ã«æ°ããå³åœ¢ãè¿œå ã§ããã ãã§ãªãã亀差é åãäœæããããäžéšã®å³åœ¢ãä»ã®å³åœ¢ããé€å€ããããããããå³åœ¢ã®å ±éã®å¢çïŒå¢çïŒãåŠç¿ããããšãã§ããŸãã ãŸãããã®å©ããåããŠãä»ã®å©çšå¯èœãªåçŽãªåœ¢ç¶ããè€éãªåœ¢ç¶ããã°ããç°¡åã«äœæã§ããŸãã
é »ç¹ã«äœ¿çšããç¹å®ã®åœ¢ç¶ãå¿ èŠãªå Žåãããããæåã®æ¹æ³ã¯ãShapeã¯ã©ã¹ã®ç¶æ¿è ãäœæããå¿ èŠãªåœ¢ç¶ããã®ã¯ã©ã¹ã«å®è£ ããããšã§ãã å°æ¥çã«ã¯ãããã«ããè²»ããããæéãšã³ãŒãèªäœã®ãµã€ãºã®äž¡æ¹ãåæžãããŸãã
ã¹ãããŒã¯
...ãŸãã¯TheShockãææ¡ãããã¹ãããŒã¯ããå®éãStrokeã¯ãã°ã©ãã£ãã¯ã¹ã®drawã¡ãœããã®åŒã³åºãã«ãã£ãŠæç»ãããå¢çç·ã®ã¹ã¿ã€ã«ãèšå®ããæ©èœãæäŸããŸãã
æšæºJDKã«ã¯ãStrokeã€ã³ã¿ãŒãã§ãŒã¹ã®å®è£ ã1ã€ãããããŸãã-BasicStrokeã ç·ã®å¹ ãç·ãè§ã§ã©ã®ããã«çµåããããã端ã§ã©ã®ããã«èŠããããèšå®ããç Žç·ãäœæã§ããŸãã
ã³ãŒãã§ã¹ãããŒã¯ãèšå®ããã«ã¯ã次ã®æé ãå®è¡ããŸãã
ãã®äŸã§ã¯ãåŸç¶ã®ãã¹ãŠã®ããŒããŒããŒãã匷å¶çã«2ãã¯ã»ã«å¹ ã§æç»ããŸããg2d.setStroke ( new BasicStroke ( 2f ) );
ã¡ãªã¿ã«ãå¹ ããã®ä»ã®ãã©ã¡ãŒã¿ã¯ãããŒãã§èšå®ã§ããããšãæããªãã§ãã ããïŒãã¯ã»ã«ã¯æŽæ°ã§ãªããã°ãªããŸããïŒ-éæŽæ°ã®æ°å€ã¯ãã¬ã³ããªã³ã°æã«ãã¹ãã¢ãç·/ã¢ãŠãã©ã€ã³ã®ã¿ãäœæããå Žåã«ãã£ãŠã¯äŸ¿å©ã«ãªãããšããããŸãã
BasicStrokeã®å¯èœæ§ã«é¢ãã詳现æ å ±ã¯ãããšãã°ããã«ãããŸã ã
JDKã«ã¯Strokeã®å®è£ ã1ã€ããå«ãŸããŠããŸãããããã®ããŒã«ã®å®éã®æ©èœã説æããä»ã®ãããžã§ã¯ããšäŸããããŸãããããã«ã€ããŠã¯åŸã§è©³ãã説æããŸãã
圱
Java2Dã«ã¯åœ±ã®æšæºçãªå®è£ ã¯ãããŸãããã圱ã®ãå¹æããéæããæ¹æ³ã¯ããªããããŸãããããã«ã€ããŠã¯ãã®ç« ã§èª¬æããŸããæãç°¡åãªãªãã·ã§ã³ããå§ããŸããã...
å ã®åœ¢ç¶ã®ããããªã·ãã/å€æŽã«ãã£ãŠåŸããã圱
2çªç®ã®ç»å-ãã®ã¿ã€ãã®åœ±ã®çŽ°ããŠããããªããŒãžã§ã³ã
ïŒäŸãšãœãŒã¹ã³ãŒãã¯ãã¡ãããããŠã³ããŒãã§ããŸã ïŒ
ãã®æ¹æ³ã§åŸããã圱ã¯ãå ã®åœ¢ç¶ã®ç«¯ãã1ã3ãã¯ã»ã«ãè¶ ããªãç¯å²ã§ã®ã¿é©çšã§ããŸãããã以å€ã®å Žåãäžèªç¶ã«èŠãå§ããŸãã ãŸãããã®æ¹æ³ã«ã¯ããªãé¢åãªã³ãŒããå¿ èŠã§ããåã ã®å³ã«ã€ããŠã¯ã圱ãç¹°ãè¿ããã§ãã¯ããŠéžæããå¿ èŠããããŸãã
å埩çãªåœ±
å€æŽããã圢ç¶ãç¹°ãè¿ãã¬ã³ããªã³ã°ããããšã«ãã£ãŠåŸããã圱ã ããã«ãåŸç¶ã®åå埩ã§ãïŒãªãã·ã§ã³ã®1ã€ãšããŠïŒå³åœ¢ã®ãµã€ãºã倧ãããªããéæ床ãäœäžããŸãïŒãŸãã¯è²ãå€ãããŸãïŒã
ïŒäŸãšãœãŒã¹ã³ãŒãã¯ãã¡ãããããŠã³ããŒãã§ããŸã ïŒ
ãã®ãªãã·ã§ã³ã¯ãã·ã£ããŠã®ãµã€ãºãå¶éããªããšããç¹ã§åªããŠããŸãããåæã«ããé¢åã§ä¿®æ£ãããã«å°é£ã§ãã ãŸããã¬ã³ããªã³ã°é床ã®ç¹ã§ãã¹ãŠã®ãªãã·ã§ã³ã®äžã§æãæé©ã§ã¯ãããŸããã
ã°ã©ããŒã·ã§ã³ã·ã£ããŠ
ãã®ãªãã·ã§ã³ã¯ãFigureã®ãšããžã«æ²¿ã£ãã°ã©ããŒã·ã§ã³å¡ãã€ã¶ãã®äœ¿çšã«åºã¥ããŠããŸãã
å®éãå¡ãã€ã¶ããå¿ èŠãªé·æ¹åœ¢ã®å Žåããšããžã®åšãã«8ã€ã®éšåããããŸãã
4ã€ã®å Žå-LinearGradientPaintãä»ã®4ã€ã®å Žå-RadialGradientPaintã çµæã¯ããã®ãããªãã¡ããšãã圱ã«ãªããŸãã
ïŒäŸãšãœãŒã¹ã³ãŒãã¯ãã¡ãããããŠã³ããŒãã§ããŸã ïŒ
ãŸããã°ã©ããŒã·ã§ã³ã®äœçœ®ãå€æŽããŠã次ã®ãããªä»ã®èå³æ·±ããªãã·ã§ã³ãååŸããããšãã§ããŸãã
ïŒäŸãšãœãŒã¹ã³ãŒãã¯ãã¡ãããããŠã³ããŒãã§ããŸã ïŒ
ãã®ãªãã·ã§ã³ã®å©ç¹ã¯ãã·ã£ããŠã¬ã³ããªã³ã°ã®é床ãšå質ã§ãã ãã ããäŸãããããããã«ãã³ãŒãã®ãµã€ãºã¯åã³äœäžããŸãã
ã¬ã³ããªã³ã°æã«ã¹ãããŒã¯ãå€æŽããŠåŸããã圱
ããæ£ç¢ºã«ã¯ãå¯å€ã®è²/éæ床ãšã¹ãããŒã¯ã䜿çšããŠãå³ããµã€ã¯ã«ã§æ°åæç»ããŸããããã«ãããäžçš®ã®åœ±ãäœæã§ããŸãã
ïŒäŸãšãœãŒã¹ã³ãŒãã¯ãã¡ãããããŠã³ããŒãã§ããŸã ïŒ
å³åœ¢ã®åœ¢ç¶ã¯åœ±ã®ã¬ã³ããªã³ã°ã«çµ¶å¯Ÿã«åœ±é¿ããªãããããã®ææ³ã¯æãããªãããŒãªå³åœ¢ã§ã䜿çšã§ããŸãã
ïŒäŸãšãœãŒã¹ã³ãŒãã¯ãã¡ãããããŠã³ããŒãã§ããŸã ïŒ
ãŸããã·ã£ããŠã¬ã³ããªã³ã°èªäœãå¥ã®ç¬ç«ããã¡ãœããã«ç°¡åã«ç§»åã§ããŸãã
private void drawShade ( Graphics2D g2d, RoundRectangle2D rr, Color shadeColor, int width )
{
Composite comp = g2d.getComposite ();
Stroke old = g2d.getStroke ();
width = width * 2;
for ( int i = width; i >= 2; i -= 2 )
{
float opacity = ( float ) ( width - i ) / ( width - 1 );
g2d.setColor ( shadeColor );
g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_OVER, opacity ) );
g2d.setStroke ( new BasicStroke ( i ) );
g2d.draw ( rr );
}
g2d.setStroke ( old );
g2d.setComposite ( comp );
}
ç»åã®åœ±
ç»åã®å Žåã以åã®æ¹æ³ã§åœ±ãã¬ã³ããªã³ã°ããããã®å³åœ¢ãååŸããããšã¯ã§ããŸããããããé·æ¹åœ¢ã§ããã ãã§ãªããããšãã°å圢ãŸãã¯äžå®åœ¢ã®å Žåã§ãã§ãã ãã®å Žåã«åœ±ãäœæããã«ã¯ãããå°ãã¢ãããŒãããŸã-AlphaCompositeã䜿çšããŠãå ã®ç»åã®åè²ã³ããŒãäœæããããã圱ãšããŠäœ¿çšããŸãã
ïŒäŸãšãœãŒã¹ã³ãŒãã¯ãã¡ãããããŠã³ããŒãã§ããŸã ïŒ
ãã¡ãããå Žåã«ãã£ãŠã¯ããã®ãããªåœ±ã§ååã§ãããããã§ãã圱èªäœã®è¿ãã§ããæ»ãããª/ã°ã©ããŒã·ã§ã³ã®ãšããžãååŸããããšæããŸãã ãã®åé¡ã解決ããã«ã¯ããã£ã«ã¿ãªã³ã°ã圹ç«ã¡ãŸãã ããæ£ç¢ºã«ã¯ãçµæã®ç»åã®ã圱ãã«ç¹å¥ãªãã£ã«ã¿ãŒã䜿çšããŠããããªã¢ã«ãªå€èŠ³ã«ããŸãã
ïŒäŸãšãœãŒã¹ã³ãŒãã¯ãã¡ãããããŠã³ããŒãã§ããŸã ïŒ
ççŽã«èšã£ãŠããã®äŸã§ã¯ã ããã§æå®ãããã£ã«ã¿ãŒã®å®æçã䜿çšããŸãã ã ãã ããè¿œå ã®è³éããªããŠããæåã®äŸã§ååŸãã圱ããã°ããç°¡åã«ããŒããããç»åã®äžã«é 眮ã§ããŸãã
ã¡ãªã¿ã«ããã®åœ±ã¯ãæåã«å¥ã®ç»åã«é©çšãããšããã£ã«ã¿ãŒãæ©èœããããšã«åºã¥ããŠãå³ã«äœ¿çšããããšãã§ããŸãã ããã¯ãããšãã°ãã¢ããªã±ãŒã·ã§ã³ã®å®è¡äžã«å³ãåçã«å€åããªãå Žåã«é©çšã§ããŸããäžåºŠããã£ããã£ãããŠãã¬ã³ããªã³ã°æã«çµæã®ã€ã¡ãŒãžã䜿çšããã ãã§ãã ãã ããå人çã«ã¯ããªãœãŒã¹ã³ã¹ãã®èŠ³ç¹ãããã®ãªãã·ã§ã³ãããŸã奜ãã§ã¯ãªãããããªã¹ãããåé€ããŸããã
æ£ããã¯ãªããã³ã°
ã°ã©ãã£ãã¯ã¹ãæäœãããæ£ãããã³ã³ããŒãã³ããäœæãããšãã«å¿ èŠãªå¥ã®éèŠãªåŽé¢ãã¯ãªããã®æäœããŸãã¯ã¬ã³ããªã³ã°äžã®äžèŠãªéšåã®åæã«ã€ããŠåå¥ã«èª¬æããããšæããŸãããã®ããŒã«ã䜿çšããã«ã¯ããã¯ãªããã³ã°ããçºçãããã©ãŒã ãæå®ããã ãã§ååã§ãã
ãããã®3ã€ã®æ¹æ³ã¯ãã¹ãŠãåãé·æ¹åœ¢ã®ã¯ãªããã³ã°é åã®ç¢ºç«ã«ã€ãªãããŸããg.setClip ( x, y, width, height );
g.setClip ( new Rectangle ( x, y, width, height ) );
g.setClip ( new Rectangle2D.Double ( x, y, width, height ) );
ãã®ããŒã«ã圹ç«ã€å Žåãå€ããããŸãã
ãŸããã³ã³ããŒãã³ããã¬ã³ããªã³ã°ãããšããç¹å®ã®ã¯ãªããã³ã°ãã©ãŒã ãåžžã«äºåå®çŸ©ãããŠããŸãïŒéåžžãããã¯ã³ã³ããŒãã³ãã®å¢çã§ãïŒ-ã³ã³ããŒãã³ããå¢çãããã¯ããŒã«ã¢ãŠããããããšãèš±å¯ããŸããã ç¹å®ã®ã¯ãªããã³ã°é åãèšå®ãããšãã¯ããããèæ ®ããå¿ èŠããããŸãã ç°¡åã«èšããšã次ã®ããã«ã§ããŸãã
å®éãæ¢åã®ã¯ãªããã³ã°é åãæ°ããé åãšçµã¿åãããŸãã ãã®æ¹æ³ã§ã¯ãã³ã³ããŒãã³ãã®å¢çã®åœ¢ã§å¶éã倱ãããšã¯ãããŸããããå¿ èŠãªæ°ããå¶éãè¿œå ããŸããShape oldClip = g.getClip ();
Shape newClip = new Rectangle ( x, y, width, height );
Area clip = new Area ( oldClip );
clip.intersect ( new Area ( newClip ) );
g.setClip ( clip );
圱ã®äœæã«é¢ããç« ã«æ»ã£ãŠããã€ã³ã4ãããæ£ç¢ºã«èšãã°ã圱ã®äžéšãåãåãã ãã§æ¹åã§ããŸãã
public static void drawShade ( Graphics2D g2d, Shape shape, Color shadeColor, int width,
Shape clip, boolean round )
{
Shape oldClip = g2d.getClip ();
if ( clip != null )
{
Area finalClip = new Area ( clip );
finalClip.intersect ( new Area ( oldClip ) );
g2d.setClip ( finalClip );
}
Composite comp = g2d.getComposite ();
float currentComposite = 1f;
if ( comp instanceof AlphaComposite )
{
currentComposite = ( ( AlphaComposite ) comp ).getAlpha ();
}
Stroke old = g2d.getStroke ();
width = width * 2;
for ( int i = width; i >= 2; i -= 2 )
{
float opacity = ( float ) ( width - i ) / ( width - 1 );
g2d.setColor ( shadeColor );
g2d.setComposite ( AlphaComposite
.getInstance ( AlphaComposite.SRC_OVER, opacity * currentComposite ) );
g2d.setStroke (
new BasicStroke ( i, round ? BasicStroke.CAP_ROUND : BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND ) );
g2d.draw ( shape );
}
g2d.setStroke ( old );
g2d.setComposite ( comp );
if ( clip != null )
{
g2d.setClip ( oldClip );
}
}
ãããã£ãŠãç®çã®ã¯ãªããã³ã°é åããã®ã¡ãœããã«è¿œå ã§è»¢éããããšãå¯èœã«ãªããŸããã¡ãœããèªäœãæ®ããè¡ããŸãã
å®è¡ãããããã€ãã®ãã¹ãã瀺ãããã«ãæç»äžå¯èœãªéšåïŒããšãã°ãç»é¢ããæ¶ããéšåïŒãåãåã£ãŠããäœæ¥é床ãå€§å¹ ã«åäžããããšã¯ãããŸããã ãã ãããäœããã©ãã§ãã©ã®ããã«æç»ãããããªã©ã®ãã¹ãŠã®èšç®ãšã¬ã³ããªã³ã°èªäœã¯ãã¯ãªããã1ã€ã®ã䜿çšå¯èœãªããã¯ã»ã«ã«èšå®ãããŠããå Žåã§ãæ©èœããŸãã ãã®ããããã®ãããªå Žåã«ã¯ãæåãæé©åãã¯ããã«åœ¹ç«ã¡ãŸãã
ã»ãšãã©ã®å Žåãã¯ãªããã¯ãè€éãªããŒããã¬ã³ããªã³ã°ããé£æ¥ããã³ã³ããŒãã³ããäºãã«éãªããªãããã«å¢çãæ£ããå¶éããããã«äœæãããŸããã
ã¢ãã¡ãŒã·ã§ã³
ããã§ãåŸãããç¥èã®äžéšãçµã¿åãããŠããã£ãšé¢çœãããšãããæãæ¥ãŸãããã¢ãã¡ãŒã·ã§ã³èªäœã¯éåžžã«ç解ãããããã¬ã³ããªã³ã°ããããªããžã§ã¯ãã®çµæçãªå€åã®ã¿ãè¡šããŸãã ãã ããå®éã«ã¯ããã«å€ãã®è³ªåãšåé¡ããããŸãã
ã¢ãã¡ãŒã·ã§ã³ã®çš®é¡ã«ãã£ãŠã¯ããã€ãã³ãã®éçºããæ åœããå€æŽã衚瀺ããå€ãã®è¿œå ã³ãŒããå¿ èŠã«ãªãå ŽåããããŸãã åæç»æã«æé©åãå¿ããªãããšãéèŠã§ããã€ãŸããå€æŽãçºçããã¢ãã¡ãŒã·ã§ã³ã³ã³ããŒãã³ãã®é åã®ã¿ãåæç»ããããšããå§ãããŸãã ãããè¡ãã«ã¯ãrepaintïŒæ°ããRectangleïŒxãyãwidthãheightïŒïŒã¡ãœãããåŒã³åºãã ãã§ãã
ã¢ãã¡ãŒã·ã§ã³ã®å®è£ ã®å°ããªäŸãèããŠã¿ãŸããã-JLabelã®ããã¹ããä»ããŠã°ã¬ã¢ã®å¹æãäœæããŸãã ãããè¡ãã«ã¯ããŸããå®è£ ã«å¿ èŠãªãã®ãæ確ã«ç解ããããã«ããã®å€èŠ³ã決å®ããå¿ èŠããããŸãã
ããã€ã©ã€ããã®åºç€ãšããŠãã°ã©ããŒã·ã§ã³ã§æºããããåïŒäžå€®ã®æããç°è²ãã端ã®ãã©ã³ãã®è²ïŒé»ïŒãŸã§ïŒãèŠãŠã¿ãŸãããã ãŸãããã®åãã³ã³ããŒãã³ãã®æåããæåŸãŸã§ç§»åãããããã®å¥ã®ã¿ã€ããŒãå¿ èŠã§ãã
ãããã£ãŠã次ã®ãããªãã®ãã³ã³ããŒãã³ããã¬ã³ããªã³ã°ããŸãã
ãã€ã©ã€ããã¬ã³ããªã³ã°ãããšãã«Compositeãã€ã³ã¹ããŒã«ããã®ãšåæ§ã«ãããã¹ããæç»ãããå¥ã®ç»åãäœæããéã«äž»èŠãªãã€ã³ãã¯é ãããŸããprivate boolean animating = false ;
private int animationX = 0;
private int animationLength = 140;
private float [] fractions = { 0f, 1f };
private Color[] colors = new Color[]{ new Color ( 200, 200, 200 ), new Color ( 0, 0, 0 ) };
protected void paintComponent ( Graphics g )
{
// ,
BufferedImage bi =
new BufferedImage ( getWidth (), getHeight (), BufferedImage.TYPE_INT_ARGB );
Graphics2D g2d = bi.createGraphics ();
g2d.setFont ( g.getFont () );
//
super.paintComponent ( g2d );
//
if ( animating )
{
g2d.setRenderingHint ( RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON );
g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_IN ) );
g2d.setPaint ( new RadialGradientPaint ( animationX - animationLength / 2,
getHeight () / 2, animationLength / 2, fractions, colors ) );
g2d.fillRect ( animationX - animationLength, 0, animationLength, getHeight () );
}
//
g2d.dispose ();
g.drawImage ( bi, 0, 0, null );
}
ç»åã¯ãããã¹ããå«ããã¯ã»ã«ã®ã¿ãå æãããããã«å¿ èŠã§ããããã§ãªãå ŽåãGraphics AlphaComposite.SRC_INã¡ãœããã®æšæºã¬ã³ããªã³ã°ã§ã¯ãå¡ãã€ã¶ãããé·æ¹åœ¢å šäœãæå®ãããã°ã©ããŒã·ã§ã³ã§å¡ãã€ã¶ããŸãããã£ãŒãäžã®ããã¹ãã«å ããŠãæç»ããã«ããã§ã«ååšããããã§ãã ïŒããã«ïŒèæ¯ã
ãã®ãããããšãã°ã«ãŒãœã«ãJLabelé åã«å ¥ã£ããšãã«æ©èœããã¿ã€ããŒãå®è£ ããããšã¯ä»ãæ®ã£ãŠããŸãã
ãã®ã³ãŒãã§ã¯ãïŒã³ã¡ã³ãã«èšèŒãããŠãããã®ã«å ããŠïŒäœãã説æããå¿ èŠããããšã¯æããŸãããprivate static class AnimatedLabel extends JLabel
{
public AnimatedLabel ( String text )
{
super ( text );
setupSettings ();
}
private void setupSettings ()
{
//
setOpaque ( false );
//
setFont ( getFont ().deriveFont ( Font .BOLD ).deriveFont ( 30f ) );
// ,
addMouseListener ( new MouseAdapter()
{
public void mouseEntered ( MouseEvent e )
{
startAnimation ();
}
} );
}
private Timer animator = null ;
private boolean animating = false ;
private int animationX = 0;
private int animationLength = 140;
private float [] fractions = { 0f, 1f };
private Color[] colors = new Color[]{ new Color ( 200, 200, 200 ), new Color ( 0, 0, 0 ) };
private void startAnimation ()
{
// ,
if ( animator != null && animator.isRunning () )
{
return ;
}
//
animating = true ;
animationX = 0;
animator = new Timer ( 1000 / 48, new ActionListener()
{
public void actionPerformed ( ActionEvent e )
{
//
if ( animationX < getWidth () + animationLength )
{
animationX += 10;
AnimatedButton. this .repaint ();
}
else
{
animator.stop ();
}
}
} );
animator.start ();
}
protected void paintComponent ( Graphics g )
{
//
}
}
ãã®çµæã ãã®ãããªé¢çœãå¹æãåŸãããŸãã
ãã¡ããããã®äŸã¯æ°·å±±ã®äžè§ã«ãããŸããã æ³ååãããã°ãå€ãã®èå³æ·±ãéçãªãã®ãã¢ãã¡ãŒã·ã§ã³åããããã®ãäœæã§ããŸãã
ããã€ãã®ããªãã¯
å¿ èŠãªãã¹ãŠãå®è¡ããããã®æšæºããŒã«ãç¥ã£ãŠããã ãã§ã¯äžååãªå ŽåããããŸãã ããŸããŸãªãããªãããŒãªããã®ãçºæããªããã°ãªããŸããã ããã€ãã®å¥ã ã®äŸã§ããããã§èŠã€ãããããã®ãšãçºæãããèªè»¢è»ããçãããšå ±æããããšæããŸãã ããã§ã¯ãããžãã¹ã«åãæãããŸããã...ãšããžã¹ã ãŒãžã³ã°
ç¹å®ã®åœ¢ç¶ã«åŸã£ãŠç»åãåãæãå¿ èŠããããšä»®å®ããŸãããã¬ã³ããªã³ã°æã®ã¯ãªãããªã©ã®æšæºçãªæ段ã¯åããããçµæã«ã€ãªãããŸãã ãã®å ŽåãAlphaCompositeã䜿çšããå¿ èŠããããŸãã
ãããã£ãŠããŸãè§ãæ»ããã«ããè§äžžé·æ¹åœ¢ãæç»ãããããã¹ãã³ã·ã«ãšããŠäœ¿çšããŠãç»åãäžã«éããŸããImageIcon icon = new ImageIcon ( iconPath );
BufferedImage roundedImage = new BufferedImage ( icon.getIconWidth (), icon.getIconHeight (),
BufferedImage.TYPE_INT_ARGB );
Graphics2D g2d = roundedImage.createGraphics ();
g2d.setRenderingHint ( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
g2d.setPaint ( Color.WHITE );
g2d.fillRoundRect ( 0, 0, icon.getIconWidth (), icon.getIconHeight (), 10, 10 );
g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_IN ) );
g2d.drawImage ( icon.getImage (), 0, 0, null );
g2d.dispose ();
ImageIcon roundedIcon = new ImageIcon ( roundedImage );
ã«ã¹ã¿ã ã¹ãããŒã¯ã®äœ¿çš
ãã£ãšåã«ãç§ã¯èªåã®Strokeã¯ã©ã¹ã®äœæã«é¢ããéåžžã«èå³æ·±ãèšäºãèŠã€ããŸããã
å Žåã«ãã£ãŠã¯ãåæ§ã®ã¹ãããŒã¯ã§ã¬ã³ããªã³ã°ãå€§å¹ ã«ä¿é²ã§ããŸãã
ãŒãã/ã·ã£ããŠãã£ã«ã¿ãŒã®äœ¿çš
åããªãœãŒã¹ã§ãblur'uã«é¢ããéåžžã«èå³æ·±ãèšäºãèŠã€ããããšãã§ããŸãã
ç»åãæ±ã人ã«ã¯äŸ¿å©ãããããŸããã
GlyphVectorã䜿çšãã
ã°ã©ãã£ãã¯ãæäœããéã®ãã¹ãã¬ã¹ã®å€ããç¬éã®1ã€ã¯ãç¹ã«ãã®ããã¹ããå€æŽãããå¯èœæ§ãããå Žåã«ãããã¹ãã®ã¬ã³ããªã³ã°ã§ãã ããã¹ããæ£ããé 眮ããã«ã¯ããã®ãµã€ãºãèšç®ããããã«åºã¥ããŠæç»ããå¿ èŠããããŸãã
ãã®ãããªèšç®ã«ã¯2ã€ã®ããŒã«ããããŸãã
1. FontMetrics
Graphics2Dã€ã³ã¹ã¿ã³ã¹ïŒg2d.getFontMetricsïŒïŒïŒããçŽæ¥ååŸã§ããŸãã
ã€ã³ãã³ãã®ããŸããŸãªãµã€ãºãšã€ã³ã¹ããŒã«ãããŠãããã©ã³ãã®é«ããå®çŸ©ã§ããŸãã
2. GlyphVector
ãã®ãªãã·ã§ã³ã¯ãç¹å®ã®ããã¹ãã®ãµã€ãºãæ£ç¢ºã«ç¥ãããšãã§ãããããY座æšãäžå¿ã«ããã¹ããé 眮ããå¿ èŠãããå Žåã«äŸ¿å©ã§ãã
ãŸããGlyphVectorããå€ãã®æçšãªæ å ±ãããšãã°ããã¹ãã®å€åŽã®å¢çç·ïŒçŽæ¥ãã®åœ¢ç¶ïŒãååŸã§ããŸããFontMetrics fm = g2d.getFontMetrics ();
GlyphVector gv = g2d.getFont ().createGlyphVector ( fm.getFontRenderContext (), "Text" );
Rectangle visualBounds = gv.getVisualBounds ().getBounds ();
Shape textOutline = gv.getOutline ();
ç¬èªã®ããŒã«ããããããŒãžã£ãŒãäœæãã
Swingã«ã¯èŠèŠãããã®ããããããããŸãããã³ã³ããŒãã³ãã®UIãå€æŽããããã¬ã€ã¢ãŠããæäœãããããããšã§ç°¡åã«ã¹ã ãŒãºã«ããããšãã§ããŸãã å Žåã«ãã£ãŠã¯ãç©äºã¯ããã»ã©åçŽã§ã¯ãããŸããã
ãã¹ãŠã®Jã³ã³ããŒãã³ãã«å®è£ ãããããŒã«ãããã®ã·ã¹ãã ã¯ããã®ãããªå Žåã«ã®ã¿é©çšãããŸãã 衚瀺ããããã¹ãŠã®ããŒã«ãããã¯ãåå¥ã®å³å¯ãªé·æ¹åœ¢ã®ãããã¢ããïŒããŒã«ãããããŠã£ã³ããŠå ã«åãŸããã©ããã«å¿ããŠè»œéãŸãã¯ééïŒã«è¡šç€ºãããããããã®é åãšåœ¢ç¶ã«ãã£ãŠå¶éãããŸãã ãããŠãããã¯ãã¡ããšããWebã€ã³ã¿ãŒãã§ã€ã¹ãšäžžã¿ã垯ã³ã圢ç¶ã®æ代ã§ãïŒ
ãã¡ãããæšæºã®TooltipManagerãå£ãããŠã£ã³ããŠãäœæããå ŽæãèŠã€ããŠãæ°ããæ©èœã䜿çšããŠãŠã£ã³ããŠã«å¿ èŠãªåœ¢ç¶ãèšå®ã§ããŸããã第äžã«ããã¹ãŠã®OSã§ãŸã æ©èœããªãã第äºã«ãéåžžã«è¯ãæé©ãªãªãã·ã§ã³ã§ã¯ãããŸããã
ãã®ããããã¹ãŠã®æšæºãŠã£ã³ããŠã«ååšããGlassPaneãããŒã«ããã衚瀺é åãšããŠïŒãããŠåŸã§ãã¹ãŠã®çš®é¡ã®å éšãŠã£ã³ããŠã§ïŒäœ¿çšãããšããã¢ã€ãã¢ãæãã€ããŸããã
ã¢ã€ãã¢èªäœã¯ããã€ãã®éšåã§æ§æãããŠããŸãã
1.å¥ã®ãããŒãžã£ãŒïŒ TooltipManager.java ïŒãå¿ èŠã«å¿ããŠãããŒã«ããããéããŠèšæ¶ããç¹å®ã®ãŠã£ã³ããŠã®GlassPaneãäœæããŸãã ããŒã«ãããã®è¿œå äœæã¯ãGlassPaneã§çŽæ¥è¡ãããŸãã
2. GlassPaneïŒ TooltipGlassPane.java ïŒã¯ãã€ãã³ããã¹ãããããŠé©åãªã¿ã€ãã³ã°ã§ããŒã«ãããã衚瀺ããéæãªããã«ã§ã
3.ããŒã«ãããèªäœïŒ CustomTooltip.java ïŒã¯ãGlassPaneã®å Žæã«å¿ããŠãå¿«é©ãªãã¶ã€ã³ã§ã³ã³ãã³ãã衚瀺ããæšæºã®Jã³ã³ããŒãã³ãã§ãã
ãã®çµæã衚瀺ãããããŒã«ã¿ã€ãã¯æ¬¡ã®ããã«ãªããŸãã
ãã®ã¢ã€ãã¢ã®å®å šãªå®è£ ã¯ã以äžã§èª¬æããã©ã€ãã©ãªã§èŠãããšãã§ããŸãã éåžžã«å€§éã®ã³ãŒãããããããåŒçšããŸããã§ããã ã¢ã€ãã¢ãå®è£ ããã¯ã©ã¹ã®ååã¯äžèšã«èšèŒãããŠããããããžã§ã¯ãå ã®ã¯ã©ã¹ã®ååã«å¯Ÿå¿ããŠããŸãã
ç·šéå¯èœãªãªã¹ã
å Žåã«ãã£ãŠã¯ç¬èªã®ãèªè»¢è»ããè¿œå ããããšã«å ããŠãæ¢åã®ã³ã³ããŒãã³ãã®æ©èœãè£å®ããæšæºããŒã«ã䜿çšããã®ã¯éåžžã«ç°¡åã§ãšã¬ã¬ã³ãã§ãã
誰ããJlistã³ã³ããŒãã³ããç¥ã£ãŠãããšæããŸãããæåã¯ç·šéãæäŸããŠããŸããã§ããã ãããã£ãŠãä»ããã®æ¬ ç¹ãä¿®æ£ããæ¹æ³ã瀺ããŸãã
ãŸãããšãã£ã¿ãŒèªäœãå®è£ ããã€ã³ã¿ãŒãã§ãŒã¹ãäœæããå¿ èŠããããŸãã
ãã®ã€ã³ã¿ãŒãã§ã€ã¹ã®çžç¶äººã¯ããªã¹ãã«ãšãã£ã¿ãŒãäœæããŠè¡šç€ºããããã«å¿ èŠãªãã¹ãŠãæäŸããŸãã ãããã®é¢æ°ã®å®å šãªã»ãããæ¯åç¶æ¿ããŠå®çŸ©ããã®ã¯éåžžã«ã³ã¹ããããããŸããããŸããŸãªãšãã£ã¿ãŒã«å€ããå°ãªããå ±éã®éšåãå®è£ ããæœè±¡ã¯ã©ã¹ãäœæããŸããããpublic interface ListEditor
{
public void installEditor ( JList list, Runnable startEdit );
public boolean isCellEditable ( JList list, int index, Object value );
public JComponent createEditor ( JList list, int index, Object value );
public Rectangle getEditorBounds ( JList list, int index, Object value , Rectangle cellBounds );
public void setupEditorActions ( JList list, Object value , Runnable cancelEdit,
Runnable finishEdit );
public Object getEditorValue ( JList list, int index, Object oldValue );
public boolean updateModelValue ( JList list, int index, Object value , boolean updateSelection );
public void editStarted ( JList list, int index );
public void editFinished ( JList list, int index, Object oldValue, Object newValue );
public void editCancelled ( JList list, int index );
}
ããã§ããã®æœè±¡ã¯ã©ã¹ã«åºã¥ããŠãããšãã°ãªã¹ãçšã®ããã¹ããšãã£ã¿ãªã©ã WebStringListEditor.javaã®ãããªå®è£ ãéåžžã«ç°¡åã«ãªããŸããpublic abstract class AbstractListEditor implements ListEditor
{
protected int editedCell = -1;
public void installEditor ( final JList list, final Runnable startEdit )
{
// ,
list.addMouseListener ( new MouseAdapter()
{
public void mouseClicked ( MouseEvent e )
{
if ( e.getClickCount () == 2 && SwingUtilities.isLeftMouseButton ( e ) )
{
startEdit.run ();
}
}
} );
list.addKeyListener ( new KeyAdapter()
{
public void keyReleased ( KeyEvent e )
{
if ( e.getKeyCode () == KeyEvent.VK_F2 )
{
startEdit.run ();
}
}
} );
}
public boolean isCellEditable ( JList list, int index, Object value )
{
return true ;
}
public Rectangle getEditorBounds ( JList list, int index, Object value , Rectangle cellBounds )
{
//
return new Rectangle ( 0, 0, cellBounds.width, cellBounds.height + 1 );
}
public boolean updateModelValue ( JList list, int index, Object value , boolean updateSelection )
{
//
ListModel model = list.getModel ();
if ( model instanceof DefaultListModel )
{
( ( DefaultListModel ) model ).setElementAt ( value , index );
list.repaint ();
return true ;
}
else if ( model instanceof AbstractListModel )
{
final Object[] values = new Object[ model.getSize () ];
for ( int i = 0; i < model.getSize (); i++ )
{
if ( editedCell != i )
{
values[ i ] = model.getElementAt ( i );
}
else
{
values[ i ] = value ;
}
}
list.setModel ( new AbstractListModel()
{
public int getSize ()
{
return values.length;
}
public Object getElementAt ( int index )
{
return values[ index ];
}
} );
return true ;
}
else
{
return false ;
}
}
public void editStarted ( JList list, int index )
{
//
editedCell = index;
}
public void editFinished ( JList list, int index, Object oldValue, Object newValue )
{
//
editedCell = -1;
}
public void editCancelled ( JList list, int index )
{
//
editedCell = -1;
}
public boolean isEditing ()
{
//
return editedCell != -1;
}
}
æåŸã®ç¬éãæ®ããŸã-ãªã¹ãã«ãšãã£ã¿ãŒãã€ã³ã¹ããŒã«ããæ¹æ³ã ãããå¥ã®ã¯ã©ã¹ã«å ¥ããŠã䟿å®äžéçã«ããŸãã
public class ListUtils
{
public static void installEditor ( final JList list, final ListEditor listEditor )
{
// ,
final Runnable startEdit = new Runnable()
{
public void run ()
{
//
final int index = list.getSelectedIndex ();
if ( list.getSelectedIndices ().length != 1 || index == -1 )
{
return ;
}
//
final Object value = list.getModel ().getElementAt ( index );
if ( !listEditor.isCellEditable ( list, index, value ) )
{
return ;
}
//
final JComponent editor = listEditor.createEditor ( list, index, value );
//
editor.setBounds ( computeCellEditorBounds ( index, value , list, listEditor ) );
list.addComponentListener ( new ComponentAdapter()
{
public void componentResized ( ComponentEvent e )
{
checkEditorBounds ();
}
private void checkEditorBounds ()
{
Rectangle newBounds =
computeCellEditorBounds ( index, value , list, listEditor );
if ( newBounds != null && !newBounds.equals ( editor.getBounds () ) )
{
editor.setBounds ( newBounds );
list.revalidate ();
list.repaint ();
}
}
} );
//
list.add ( editor );
list.revalidate ();
list.repaint ();
//
if ( editor.isFocusable () )
{
editor.requestFocus ();
editor.requestFocusInWindow ();
}
//
final Runnable cancelEdit = new Runnable()
{
public void run ()
{
list.remove ( editor );
list.revalidate ();
list.repaint ();
listEditor.editCancelled ( list, index );
}
};
final Runnable finishEdit = new Runnable()
{
public void run ()
{
Object newValue = listEditor.getEditorValue ( list, index, value );
boolean changed =
listEditor.updateModelValue ( list, index, newValue, true );
list.remove ( editor );
list.revalidate ();
list.repaint ();
if ( changed )
{
listEditor.editFinished ( list, index, value , newValue );
}
else
{
listEditor.editCancelled ( list, index );
}
}
};
listEditor.setupEditorActions ( list, value , cancelEdit, finishEdit );
//
listEditor.editStarted ( list, index );
}
};
listEditor.installEditor ( list, startEdit );
}
private static Rectangle computeCellEditorBounds ( int index, Object value , JList list,
ListEditor listEditor )
{
//
Rectangle cellBounds = list.getCellBounds ( index, index );
if ( cellBounds != null )
{
Rectangle editorBounds = listEditor.getEditorBounds ( list, index, value , cellBounds );
return new Rectangle ( cellBounds.x + editorBounds.x, cellBounds.y + editorBounds.y,
editorBounds.width, editorBounds.height );
}
else
{
return null ;
}
}
}
以äžã§ã1è¡ã®ã³ãŒãã§äœ¿çšå¯èœãªãªã¹ãã«ãšãã£ã¿ãŒãã€ã³ã¹ããŒã«ã§ããŸãã
äž»ãªããšã¯ãã¢ãã«ã§éString'amiã䜿çšããå Žåããšãã£ã¿ãŒãžã®å€ã®èšå®/ååŸæ¹æ³ãå€æŽããããšãå¿ããªãããšã§ãã ãããè¡ãã«ã¯ã WebStringListEditor.javaã® 2ã€ã®ã¡ãœããïŒãã¡ãããå¿ èŠãªãšãã£ã¿ãŒã®è€éãã«å¿ããŠïŒ-createEditorããã³getEditorValueããªãŒããŒã©ã€ãããã ãã§ååã§ãã
Webã®ã«ãã¯ã¢ã³ããã£ãŒã«
ïŒç¹ã«æè¿ïŒSwingãšã°ã©ãã£ãã¯ã¹ã®äœæ¥ã«å€ãã®æéãè²»ããããããã³ãŒãã®ããŸããŸãªå Žæã§å¿ èŠã«ãªãããšãå€ããå¥ã®UIã©ã€ãã©ãªãé«åºŠãªã³ã³ããŒãã³ãããŠãŒãã£ãªãã£ãäœæãããšããã¢ã€ãã¢ãæãã€ããŸããã ãããŠããã®ã¢ã€ãã¢ã¯å°ããã€ãç¬ç«ããã©ã€ãã©ãª-WebLookAndFeelã®åœ¢ã§å®çŸããå§ããŸãããåºç€ãšããŠãç§ã¯ãã®èšäºã§ãã§ã«æžããããŸããŸãªãã¯ããã¯ãšéçºãåããŸããããŸããä»ã®ããã€ãã®ãã¯ããã¯ãéçºã«ã€ããŠãåŸã§è©³ãã説æããŸãã
ãšããã§ãç§ã¯ç§ãã¡ã®åçšè£œåã®ç¬¬2ããŒãžã§ã³ã®éçºã錻ã«æã£ãŠããããšãèãããšããã®ã¢ã€ãã¢ã¯ããã®ãããªæ©èœãšèœåã®é¢èª¿ããå¿ èŠæ§ã«ãã£ãŠåã³æè»ããããããŸããã
å®éããã®ã©ã€ãã©ãªã«ã¯ããã®èšäºã§èª¬æãããã¯ããã¯ã®ã»ãšãã©ãå«ãŸããŠããã ãã§ãªããã°ã©ãã£ãã¯ã¹ã®æäœã«é¢ããä»ã®å€ãã®èå³æ·±ãæçšãªãã®ãå«ãŸããŠããŸãã
- å®éã«Web LaF-ç¬ç«ããæ¬æ Œçãªã¯ãã¹ãã©ãããã©ãŒã pure-java LaF
- è¿œå ã®ã³ã³ããŒãã³ãã®ã»ããïŒWeb LaFãšããŠãå®ååãããŠããïŒ-FileChooser / ColorChooser / Gallery / Calendarããã³ãã®ä»å€æ°ïŒéåžžã«å€æ°ïŒïŒ
- äžé£ã®ãŠãŒãã£ãªãã£ã¯ã©ã¹ïŒã°ã©ãã£ãã¯ããã¡ã€ã«ãããã¹ããç»åãããã³ãã®ä»ã®å€ãã®åŽé¢ã®æäœïŒããšãã°ãURLã«ãããã¡ã€ã«ã®ããŠã³ããŒããç»åã®èªã¿åãããããã䜿çšããããŸããŸãªæäœãªã©ïŒ
ãŸããããã€ãã®æè¡çãªãå©ç¹ããšæ©èœããããŸãã
- å®å šã«ã¯ãã¹ãã©ãããã©ãŒã ã§ç°¡åã«ã«ã¹ã¿ãã€ãºã§ããLookAndFeelïŒçŽæ¥-Windows XP / Vista / 7ãMac OS X 10.6.7ãUbuntu 9/11ã§ãã¹ãæžã¿ïŒ
- æå°ã¡ã¢ãªèŠä»¶ïŒ-Xms16m -Xmx16mã§ç°¡åã«å®è¡ã§ããLaFãããŸããŸãªãŠãŒãã£ãªãã£ã®äœæ¥ã¯èšããŸã§ããªããã€ã¡ãŒãžã䜿çšããéãæäœãå®è¡ã§ããŸãïŒ
- åäžã®jarãã³ãã«-ã€ãŸããå¿ èŠãªãã®ã¯ãã¹ãŠããã¹ãŠã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§æ©èœããåäžã®jarã©ã€ãã©ãªã«å«ãŸããŠããŸã
- JDK 1.6 update 20以éãå¿ èŠã§ãïŒJDK 7ã«ã€ããŠã¯ãŸã äœãèšããŸãã-è©Šããããšã¯ãããŸããããçè«çã«ã¯éæšå¥šã®ãã®ããã¹ãæ©èœã¯ã³ãŒãã§äœ¿çšãããŠããŸããïŒ
å¥ã®ãµã€ãã§è©³çŽ°ãèªãããšãã§ããŸãã
å€ãã®äººã«ãšã£ãŠããã®ã©ã€ãã©ãªã¯äžçš®ã®ãèªè»¢è»ãã®ããã«èŠãããããããã誰ãããã®ãããªæ©èœãä»ã®æåãªã©ã€ãã©ãªã«ãã§ã«ååšããŠãããšäž»åŒµãããããããŸãã...
ããã«ç§ã¯2ã€ã®ããšãèšãããšãã§ããŸãïŒ
æåã« ãä»ã®ã©ã€ãã©ãªã¯ãç¹å®ã®UIïŒå€ãã®å ŽåãæŸèæã䜿çšïŒã®ã¹ã¿ã€ãªã³ã°ã®å¯èœæ§ãåããŠãããããã³ã³ããŒãã³ããæäŸããŸãã åãã©ã€ãã©ãªã«ã¯ãWebLaFã®äžè¬çãªå€èŠ³ã®ããã«æ¢ã«æ§åŒåãããè¿œå ã³ã³ããŒãã³ãã®ã»ãããå«ãŸããŠããŸãã
第äºã« -ç§ãè¿œå ãããã®ã¯äœããããŸããããã©ã€ãã©ãªã«è¿œå ããã ãã§ãããããã¯ãŒã¯ã®åºå€§ãã®äžã§ãæãããJColorChooserã眮ãæããå¯èœæ§ã®ããColorChooserã®è³¢æãªå®è£ ã¯1ã€ãèŠã€ãããŸããã§ãããä»ã«JFileChooserå®è£ ã¯ãŸã£ãããããŸããããã¡ããSWTããããŸãããæ£çŽã«èšããšãä»ã®åé¡ãå°é£ãå¶éããããŸãããã®ãªãã·ã§ã³ã«æ·±ãå ¥ã蟌ãã§æšãŠãªãããšããå§ãããŸã-ãã¹ãŠåãããã«ãSwingã«ã€ããŠè©±ããŸãã
ã ãããç§ã¯å®æéšåã®å°ããªãã¢ã§ã©ã€ãã©ãªã¯ã©ã¹ã«è¿œå ããã€ã³ã¿ãŒãã§ãŒã¹ãšæ©èœãæãããããšãã§ããããã«ïŒ
ïŒãœãŒã¹ã³ãŒãã®äŸãããŠã³ããŒãããããšãã§ããããã§ïŒã
å®å šãªãœãŒã¹ã³ãŒããšã©ã€ãã©ãªã®é åžããããšã¯ã§å ¥æã§ããŸãã
http://weblookandfeel.com/download/
çŸæç¹ã§ã¯ãã©ã€ãã©ãªã¯ãŸã å®å šã§ã¯ãªããLookAndFeelã«ãã€ããŒãªæ¬ é¥ããããŸããã³ãŒãã«ãæ€åºãããªããå Žæããããäžéšã®æ©èœãšå€èŠ³ã¯éåžžã«ãè«äºã®çãã§ãããæé«ã®é¢ã
äžèšã®ãã¹ãŠã«é¢é£ããŠããããã¯ã«é¢ããã³ã¡ã³ããææ¡ã建èšçãªæ¹å€ãèããŠããããã§ã:)
çµè«ãšããŠ...
Javaã®ã°ã©ãã£ãã¯ã¹ã«é¢ããããªãã®ç¥èããããã«æ§é åãããå®éã«ããå ·äœçã§é©çšå¯èœã«ãªã£ãããšãé¡ã£ãŠããŸããäžèšã®WebLookAndFeelã©ã€ãã©ãªã®ãœãŒã¹ã³ãŒãããã°ã©ãã£ãã¯ã䜿ã£ãäœæ¥ã®ç¿åŸã«åœ¹ç«ã€ããšãé¡ã£ãŠããŸãããã®èšäºã§åãäžãã以å€ã«ããããŸããŸãªèå³æ·±ããã®ïŒããšãã°ãåæšæºSwingã³ã³ããŒãã³ãã®UIã¯ã©ã¹ã®å®è£ ãLookAndFeelã®çµç¹ãã°ããŒãã«ãããŒãžã£ãŒãªã©ïŒããããŸãã®ã§ãããããå匷ããããšã匷ããå§ãããŸãïŒæéãšåžæãããå ŽåïŒ ããã¡ããïŒã
ãŸããèšäºã®å ¬éãååã«é·ãéäžæãããããšããpoã³ããŸã-æ®å¿µãªãããè³æã®åéã¯äºæ³ä»¥äžã«é·ãããããŸãããWebLaFã©ã€ãã©ãªãå€å°ãªããšã䜿ããããããããšã¯èšããŸã§ããããŸããã
次ã®èšäºã¯ãããããç¬èªã®LookAndFeelïŒãã¡ããäŸãšåçä»ãïŒã®äœæãšãåã ã®Jã³ã³ããŒãã³ãã®UIã®ããã€ãã®æ©èœã«å°å¿µããŸãã
è³æº
ãããã¯ã«é¢ããããŸããŸãªãµãŒãããŒãã£ã®ãªãœãŒã¹ïŒïŒèšäºã«ãªã¹ããããŠãããã®ãå«ãïŒ
MVC
http://lib.juga.ru/article/articleview/163/1/68/
Shapes
http://java.sun.com/developer/technicalArticles/GUI/ java2d / java2dpart1.html
http://www.datadisk.co.uk/html_docs/java/graphics_java2d.htm
Extended Shapes
http://java-sl.com/shapes.html
http://geosoft.no/graphics/
http ïŒ//designervista.com/shapes/index.php
http://www.jfree.org/jcommon/
Composite
http://download.oracle.com/javase/tutorial/2d/advanced/compositing.html
BasicStroke
httpïŒ/ /www.projava.net/Glava9/Index13.htm
æ¡åŒµã¹ãããŒã¯
http://www.jhlabs.com/java/java2d/strokes/
ãŒãã
http://www.jhlabs.com/ip/blurring.html
WebLookAndFeelã§äœ¿çšãããã©ã€ãã©ãªã¯æ¬¡ã®ãšããã§ããjava
-image-scaling
http://code.google.com/p/java-image-scaling/
TableLayout
httpïŒ// javaã net / projects / tablelayout
ããŒã¿ã®ãã³ã
æ®å¿µãªãããçŸåšãã®ã©ã€ãã©ãªã§å©çšã§ãããªãœãŒã¹ã¯ãããŸãããJericho
HTML Parser
http://jericho.htmlparser.net/docs/index.html
ããã³ã¢ã€ã³ã³ã»ããïŒ
Fugueã¢ã€ã³ã³
http://code.googleã com / p / fugue-icons-src /
Fatcowã¢ã€ã³ã³
http://www.fatcow.com/free-icons
ç¹å¥ãªæè¬...
ãããžã§ã¯ãã®ãœãŒã¹ã³ãŒãã®èå ãã³ïŒèªã¿åãå¯èœãªã³ãŒãã®ãã€ã©ã€ãã®ããã®
http://virtser.net/blog/post/source-code-highlighter.aspx
ãšãã¹ãã£ã³ã°ç»åç»åä¿åçšïŒ
http://hostingkartinok.com/
UPD1ïŒå°ãã®åŸ®èª¿æŽãšãªã³ã¯ã€ã©ã¹ã
Upd2ïŒããŸããŸãªäžæ£ç¢ºãããã³çºçããåé¡ã®ä¿®æ£ãå«ãæŽæ°ãããã©ã€ãã©ãªãŒé åž
Upd3ïŒèšäºå ã®èšæ£ãããäžæ£ç¢ºãããã³æ²ãã£ãç»å