スキップしてメイン コンテンツに移動

投稿

ラベル(Swing)が付いた投稿を表示しています

Drag & Drop Image File onto Java Swing Component

In this post I will show you how to achieve drag and drop image file onto Java Swing Component. In short, implment TransferHandler which can transfer image file. Code Here is the code I wrote. I defined common closure interface in order to give implementation flexibility. The exec method of imageAcceptor will be called with Image object when drag & drop is succeeded. package com.dukesoftware.utils.swing.drag; import java.awt.Image; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.imageio.ImageIO; import javax.swing.TransferHandler; import com.dukesoftware.utils.common.Closure; public class ImageFileTransferHandler extends TransferHandler { private final static Set<String> SUPPORTED_SUFIXES = new HashSet<>(Arr

Java 2D Animation on Swing

In this post, I will show you some tips (or tools) for 2D animation on Java Swing component. There are 2 ways to rendering animation on Swing compinent - Thread vs Timer. I think Swing rendering is based on single thread model, so we should use Timer. But I have used separate thread for executing animation and it works fine, so should be fine for not critical application. Animator class Ok then, I can show you a simple animator canvas class I created. The class takes Model2D for actual animate model and render it. One thing you should remember - AnimateCanvas calculate model of animation (coodinates or position or whatever) on animation rendering process, so if the calculation takes takes log time, the animation cannot meet the frame per second passed to constructor. package com.dukesoftware.utils.swing.others; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.aw

CMSL (Connected Multilayer Spring Layout)

I finally announce Java Web Start Demo for CMSL (Connected Multilayer Spring Layout) is available!! 2013/11 Sorry, looks like jnlp not works very well. I stopped make the demo public. I developed the CMSL originally in 2008. Screenshots Source Code The source code is available on CMSL on sourceforge. Future Plan I know I need to do a lot of refactoring for the code, put functionality for playing music, support more flexible data structure, etc.... X( I will keep updates on this blog if something of CMSL is improved. Currently In order to improve the calculation speed for layout of elements, am working on following tasks Cell division algorithm Multi-threading The limit of number of elements frame rate which meet achieving 30fps is about 1000. Am targeting to achieve 10000 elements. Not sure people can see 1000 elements at a time though :P

JavaでGUIアプリケーション開発: Swing, SWT, Java3D, Animation

JavaでもリッチなUIやアニメーションを作りたいという方向けにリンクと書籍を紹介します。 今は、JQueryやTwitter Bootstrapなどのjavascript、HTML5でリッチなUIを作る人が多いと思いますが、Javaも捨てたものじゃないということで参考にしていただければと思います。 Swing JavaのGUIといえばSwing! 2D系の処理は手軽に何でもできるので、非常に便利です。 Swing Tutorial Native Swing JGoodies Filthy Rich Clients アニメーションとグラフィカルエフェクトを使ったデスクトップJavaアプリケーション (The Java Series) JavaのSwingでColl & Richなアプリケーションを開発しようと思ったら、 絶対 にはずせない書籍です。 私にとってのJavaのSwing開発のバイブルです :) 特に画像のスケーリングについては、画像の補間方法、性能比較なども含め本当に詳しく紹介されています。 またアニメーションのタイミングフレームワークについても深く掘り下げて説明されています。 個人的にはもっと注目されてもいい書籍だと思うのですが。。。かなりお値段は張りますが、購入する価値の十分ある書籍です。 書籍中で出てくるソースコードは、下記リンクですべて公開されています。 http://filthyrichclients.org/ java.net上の http://java.net/projects/filthyrichclients/ からもチェックアウトできます。 Java Swing Hacks ―今日から使える驚きのGUIプログラミング集 2006年刊行の本ですが、Swingをここまで使いこなせている人は、未だに少ないのではないでしょうか。 テキストボックスのオートコンプリートの作成、ドラッグアンドロップ、サムネイル付JFileChooserの作成などなど。。すばらしい Hack が満載です!! SWT Eclipseで使われているライブラリです。良くも悪くもOSに依存したNativeなライブラリです。 私はJavaからIEのWebブラウザが使いたかったことがあり、触った