|
<Number>: [0000096B]
<Date>: 2015/12/22 10:24:06
<Title>:
<Name>: amanojaku@管理人
|
|
|
今回はマウスのダブル・クリックを検出してみる。
《参考》
『Java2 Appletcation 3 「キャンバス(Panel)、ボタン、イベント」』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+00000928.+&
(分かりやすければ他のファイル名でも良い)「MainPanelDesign」(MainPanelDesign.java)ファイルを Visual Swing for Eclipse でビジュアルに画面デザイン(GUI 部品の配置)を作成している(Java コードが自動生成される)。
「MainAppFrameObj、MainPanelImplementationObj」 からアプレット独自メソッドにアクセスする場合を想定すると、「MainAppFrameObj、MainPanelImplementationObj」はアプレット・クラス内に設置した方が良いだろう。
(アプリーケーションの初期実行用) main( ) メソッドで(MainAppFrameObjなどのような)クラス内クラスをインスタンス化したい場合(main( ) メソッド実行時には、まだアプレット自体のインスタンスが生成されておらず、通常のクラス内クラスではインスタンス化できないので) 、クラス内クラスには「static」修飾子を付与しなければならない(この場合、オブジェクトは1つだけしか作成できない)。
クリック時にマウス・カーソルが動いてしまった場合 mouseClicked イベントだとイベントが発生しない"仕様"になっているようなので、mouse イベントに関しては mouseReleased イベントを使用している。
今回はダブル・クリック検出用に mousePressed イベントも使用している。
変更した部分はイベント用メソッドの「Test_CbtNativeMouseMouseReleased、Test_CbtNativeMouseMousePressed」の private 修飾子を削除。
その他、「jLabel0」変数の private 修飾子を削除(Button など Component を直にイジる必要がなければ private 修飾子を削除しなくても良い)。
『MouseDoubleClicked.java』
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
//Event を使う場合は、その Event に対応する「〜Adapter、〜Event」を import しなければならない。
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JApplet;
import javax.swing.JFrame;
@SuppressWarnings("serial")
public class MouseDoubleClicked extends JApplet{
static MouseDoubleClicked oMainApp;
static boolean lApplication = false; // true;
static MainAppFrameObj oMainAppFrame;
MainPanelImplementationObj oMainPanelImp;
public static void main(String[] args) {
oMainApp = new MouseDoubleClicked( );
lApplication = true; // false;
oMainAppFrame =
new MainAppFrameObj( );
oMainAppFrame.oAppThread.start();
try{
oMainAppFrame.oAppThread.join();
}
catch(InterruptedException e){ }
System.exit(0);
}
public void init() {
System.out.println("init( );");
oMainApp = this;
oMainPanelImp = new MainPanelImplementationObj();
getContentPane().add(oMainPanelImp,"Center");
oMainPanelImp.setVisible(true);
if( lApplication ){
System.out.println("if(lApplication)");
oMainAppFrame.setPreSize(oMainPanelImp.getSize( ));
System.out.println("MainPanelWidth="+oMainPanelImp.getSize( ).getWidth());
System.out.println("MainPanelHeight="+oMainPanelImp.getSize( ).getHeight());
}
System.out.println("AppletWidth="+getSize( ).getWidth());
System.out.println("AppletHeight="+getSize( ).getHeight());
System.out.println("Hello, World!");
}
public void start(){
System.out.println("start( );");
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
System.out.println("ScreenWidth="+gc.getBounds().getWidth());
System.out.println("ScreenHeight="+gc.getBounds().getHeight());
repaint();
}
public void stop(){
System.out.println("stop( );");
}
public void destroy(){
System.out.println("destroy( );");
}
class MainPanelImplementationObj extends MainPanelDesign {
long ilDoubleClickedIntervalMax = 250; // 350; 300;
// volatile:最適化の抑制.
volatile byte ibCnt_Test_CbtMouseMouseDoubleClicked = 0;
Thread oThread_Test_CbtMouseMouseDoubleClicked;
Runnable oRunner_Test_CbtMouseMouseDoubleClicked;
MainPanelImplementationObj(){
super( );
oThread_Test_CbtMouseMouseDoubleClicked = new Thread(
oRunner_Test_CbtMouseMouseDoubleClicked = new Runnable( ) {
@Override
public synchronized void run() {
System.out.println("run.");
boolean lInterrupted = false; // true; //
while(true){
try {
wait( );
// ↑メソッドを synchronized 指定するか、
// synchronized(自分のインスタンス) ブロックで囲うかしないと
// 実行時に「IllegalMonitorStateException」が発生する。
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("wait:End.");
lInterrupted = false; // true; //
try {
Thread.sleep(ilDoubleClickedIntervalMax);
} catch (InterruptedException e) {
// e.printStackTrace();
System.out.println("sleep:InterruptedException.");
lInterrupted = true; // false; //
}
System.out.println("sleep:End.");
if( ! lInterrupted &&
ibCnt_Test_CbtMouseMouseDoubleClicked==2 ){
ibCnt_Test_CbtMouseMouseDoubleClicked = 0;
Test_CbtMouseMouseClicked( );
}
}
}
}
);
oThread_Test_CbtMouseMouseDoubleClicked.start( );
}
void Test_CbtMouseMouseClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:Test_CbtMouseMouseClicked.");
jLabel0.setText("SingleClicked");
}
void Test_CbtMouseMouseDoubleClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:Test_CbtMouseMouseDoubleClicked.");
jLabel0.setText("DoubleClicked");
}
@Override
void Test_CbtNativeMouseMousePressed(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:Test_CbtNativeMouseMousePressed.");
System.out.println("currentTimeMillis="+System.currentTimeMillis() );
if(oThread_Test_CbtMouseMouseDoubleClicked.getState()==Thread.State.TIMED_WAITING){
ibCnt_Test_CbtMouseMouseDoubleClicked = 3;
oThread_Test_CbtMouseMouseDoubleClicked.interrupt();
}else{
ibCnt_Test_CbtMouseMouseDoubleClicked = 1;
}
System.out.println("ibCnt_Test_CbtMouseMouseDoubleClicked="+ibCnt_Test_CbtMouseMouseDoubleClicked+"; ");
}
@Override
public void Test_CbtNativeMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:Test_CbtNativeMouseMouseReleased.");
System.out.println("currentTimeMillis="+System.currentTimeMillis() );
if(ibCnt_Test_CbtMouseMouseDoubleClicked==3){
ibCnt_Test_CbtMouseMouseDoubleClicked = 0;
Test_CbtMouseMouseDoubleClicked( );
}else if(oThread_Test_CbtMouseMouseDoubleClicked.getState()==Thread.State.WAITING){
ibCnt_Test_CbtMouseMouseDoubleClicked = 2;
synchronized(oRunner_Test_CbtMouseMouseDoubleClicked) {
oRunner_Test_CbtMouseMouseDoubleClicked.notify();
// ↑ synchronized(自分のインスタンス) ブロックで囲わないとないと
// 実行時に「IllegalMonitorStateException」が発生する。
// ここ(this)は他人なので、ここのメソッドを synchronized 指定してもダメ。
}
}
System.out.println("ibCnt_Test_CbtMouseMouseDoubleClicked="+ibCnt_Test_CbtMouseMouseDoubleClicked+"; ");
}
}
static class MainAppFrameObj extends JFrame implements Runnable {
// JApplet oApplet;
Thread oAppThread;
public MainAppFrameObj( ) {
super("Application frame.");
//setVisible(false);
System.out.println("Construct:Application frame window.");
// oApplet = oEntApplet; // new JAppletcation();
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent event){
// ユーザーがウインドウを閉じようとした時].
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosing.");
Close();
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowClosed(WindowEvent event){
// ウインドウが閉じた時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosed.");
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowDeiconified(WindowEvent event){
// ウィンドウが最小化された状態から通常の状態に変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowDeiconified.");
oMainApp.repaint();
}
}
}
);
addComponentListener(
new ComponentAdapter(){
public void componentResized(ComponentEvent event){
// コンポーネントのサイズが変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("ComponentEvent:componentResized.");
System.out.println("MainAppFrameObj: "+
"width="+Integer.toString(MainAppFrameObj.this.getSize( ).width)+"; "+
"Height="+Integer.toString(MainAppFrameObj.this.getSize( ).height)+"; "+
"");
oMainApp.repaint();
}
}
}
);
getContentPane().add(oMainApp,"Center");
oAppThread = new Thread(this);
}
public synchronized void setPreSize(Dimension oSize){
// dispose();
getContentPane().setPreferredSize(oSize);
pack();
setVisible(true);
requestFocus();
}
public synchronized void run(){
System.out.println("Open:Application frame window.");
oMainApp.init();
oMainApp.start();
oMainApp.repaint();
try{
wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
oMainApp.stop();
oMainApp.destroy();
oAppThread = null;
}
public synchronized void Close(){
System.out.println("Close:Application frame window.");
dispose();
notify();
}
}
}
『MainPanelDesign.java』
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class MainPanelDesign extends JPanel {
private static final long serialVersionUID = 1L;
private JButton jButton0;
JLabel jLabel0;
public MainPanelDesign() {
initComponents();
}
private void initComponents() {
setLayout(new GroupLayout());
add(getJLabel0(), new Constraints(new Leading(12, 259, 12, 12), new Leading(36, 10, 10)));
add(getJButton0(), new Constraints(new Leading(12, 12, 12), new Leading(83, 10, 10)));
setSize(288, 141);
}
private JLabel getJLabel0() {
if (jLabel0 == null) {
jLabel0 = new JLabel();
jLabel0.setText("jLabel0");
}
return jLabel0;
}
private JButton getJButton0() {
if (jButton0 == null) {
jButton0 = new JButton();
jButton0.setText("jButton0");
jButton0.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
Test_CbtNativeMouseMousePressed(event);
}
public void mouseReleased(MouseEvent event) {
Test_CbtNativeMouseMouseReleased(event);
}
});
}
return jButton0;
}
void Test_CbtNativeMouseMouseReleased(MouseEvent event) {
}
void Test_CbtNativeMouseMousePressed(MouseEvent event) {
}
}
|
|
|
<Number>: [0000096C]
<Date>: 2015/12/22 14:27:48
<Title>:
<Name>: amanojaku@管理人
|
|
|
今回はフォルダー単位の「アップロード、ダウンロード」(子フォルダーに対する再帰的な処理)
「ctfLocalFolder」には「絶対パス名、相対パス名」の どちらも指定可、パス名の先頭に"/"(スラシュ)が付いている場合は「絶対パス名」、パス名の先頭に"/"(スラシュ)が付いてない場合は「「相対パス名」となる(ファイル名を含める事はできない)。
「ctfHostFolder」は「絶対パス名」で指定して下さい、ファイル名を含める事も可能(ファイル名を含めた場合は「cltLocalFileList」はブランクになります)。
「ctfLocalFolder、ctfHostFolder」に対しダブル・クリックをサポート(「..」は親ディレクトリを表わしている、親ディレクトリを表示したい場合は「..」をダブル・クリックしてやる)。
《参考》
『Java2 FTP Connect 7』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+00000955.+&
『Java2 MouseDoubleClicked 1』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+0000096B.+&
クラスパスの設定
http://www.hot-surprise.org/IntroEclipse/Operation/N01/3_3.html
FTP に関するプログラムは下記ページを参照.
JavaによるFTP転送サンプル | Pa-kun plus idea
http://web.plus-idea.net/2011/06/javaftp/
> client.setControlEncoding("MS932");
↑ Host 側のキャラクター・セットを設定すれば良いと思われる。
Windows 系では「CP932」(Microsoft Windows CodePage 932)、UNIX 系では「UTF-8、EUC-JP(日本の場合)」などが大半のようだ、Android は「UTF-8」となる。
厳密に言うと Windows のキャラクター・セットは「shift_jis」と完全な互換ではない、今まで Windows のキャラクター・セットのスタンダードな表記法は「CP932」だったが、「commons-net-3.3」では「MS932」でないとエラーになるようだ.
JavaでFTPアップロードを行う。 - sinsengumi.net
http://sinsengumi.net/blog/2011/02/java%E3%81%A7ftp%E3%82%A2%E3%83%83%E3%83%97%E3%83%AD%E3%83%BC%E3%83%89%E3%82%92%E8%A1%8C%E3%81%86%E3%80%82/
(分かりやすければ他のファイル名でも良い)「MainPanelDesign」(MainPanelDesign.java)ファイルを Visual Swing for Eclipse でビジュアルに画面デザイン(GUI 部品の配置)を作成している(Java コードが自動生成される)。
「MainAppFrameObj、MainPanelImplementationObj」 からアプレット独自メソッドにアクセスしているので、「MainAppFrameObj、MainPanelImplementationObj」はアプレット・クラス内に設置している。
(アプリーケーションの初期実行用) main( ) メソッドで(MainAppFrameObjなどのような)クラス内クラスをインスタンス化したい場合(main( ) メソッド実行時には、まだアプレット自体のインスタンスが生成されておらず、通常のクラス内クラスではインスタンス化できないので) 、クラス内クラスには「static」修飾子を付与しなければならない(この場合、オブジェクトは1つだけしか作成できない)。
クリック時にマウス・カーソルが動いてしまった場合 mouseClicked イベントだとイベントが発生しない"仕様"になっているようなので、mouse イベントに関しては mouseReleased イベントを使用している。
なお、今回はダブル・クリック検出用に mousePressed イベントも使用している。
変更した部分はイベント用メソッドの「HostLogout_CbtMouseMouseReleased、HostLogin_CbtMouseMouseReleased、FTPFileList_CbtMouseMouseReleased、FTPDownload_CbtMouseMouseReleased、FTPUpload_CbtMouseMouseReleased、HostFileList_CbtNativeMouseMousePressed、HostFileList_CltNativeMouseMouseReleased、LocalFileList_CbtNativeMouseMousePressed、LocalFileList_CltNativeMouseMouseReleased、SetupFileList_HostFolder_CbtMouseMouseReleased、SetupFileList_LocalFolder_CbtMouseMouseReleased、FTPBreak_CbtMouseMouseReleased」の private 修飾子を削除。
その他、「ctfHostUserName、ctfHostName、cpfHostPassword、ctfHostFolder、ctfLocalFolder、ctfHostPortNum、ctaMessage、cltHostFileList、cltLocalFileList、ccbFTPFileDataType、ctpFileListTabs、cckHostPASVMode、ccbHostEncode」変数の private 修飾子を削除(Button など Component を直にイジる必要がなければ private 修飾子を削除しなくても良い)。
『FTPConnect.java』
import java.awt.Dimension;
//Event を使う場合は、その Event に対応する「〜Adapter、〜Event」を import しなければならない。
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.DefaultListModel;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
@SuppressWarnings("serial")
public class FTPConnect extends JApplet {
static FTPConnect oMainApp;
static boolean lApplication = false; // true; //
static MainAppFrameObj oMainAppFrame;
MainPanelImplementationObj oMainPanelImp;
// private final String fvsPathListType_Folder = ":+Folder:=";
private final String fvsPathListType_File = "-<File>=";
private final String fvsPathListType_Folder = "+<Directory>=";
private final String fvsReg_PathListType_File = "\\-<File>=";
private final String fvsReg_PathListType_Folder = "\\+<Directory>=";
Matcher matcher;
// Pattern pattern;
// Transfer // Connect
boolean lFTPConnection = false; // true; //
boolean lFTPBreak = false; // true; //
FTPClient client;
// Binary転送Modeを利用?(true=Yes、false=No)
// TransferFileDataType
private static boolean lFTPTransfer_Binary = false; // true; //
// PASV Modeを利用?(true=Yes、false=No)
private static boolean lFTPPassiveMode = true; // false; //
private static final String fvsFTPTransfer_Binary = "Binary";
// 連想配列
private HashMap<String,String> da1CharEncodeSets;
private String vsHostEncode;
private String vsLocalEncode;
private String vsHostName;
private String vsHostPortNum;
private int iHostPortNum;
private String vsHostUserName;
private String vsHostPassword;
private String vsHostCurrent;
private String vsHostFolder;
private String vsLocalCurrent;
private String vsLocalFolder;
public static void main(String[] args) {
oMainApp = new FTPConnect( );
lApplication = true; // false;
oMainAppFrame =
new MainAppFrameObj( );
oMainAppFrame.oAppThread.start();
try{
oMainAppFrame.oAppThread.join();
}
catch(InterruptedException e){ }
// oMainAppFrame.oAppThread = null;
System.exit(0);
}
public void AppRepaint() {
System.out.println("AppRepaint( );");
repaint();
}
public void init() {
System.out.println("init( );");
oMainApp = this;
oMainPanelImp = new MainPanelImplementationObj();
getContentPane().add(oMainPanelImp,"Center");
oMainPanelImp.setVisible(true);
if( oMainAppFrame!=null ){
System.out.println("if(lApplication)");
oMainAppFrame.setPreSize(oMainPanelImp.getSize( ));
System.out.println("MainPanelWidth="+oMainPanelImp.getSize( ).getWidth());
System.out.println("MainPanelHeight="+oMainPanelImp.getSize( ).getHeight());
}
System.out.println("Hello, World!");
// UTF8, Windows, EUC-JP, ASCII
da1CharEncodeSets = new HashMap<String, String>(){
{
put("UTF-8", "utf-8");
put("Windows", "MS932"); // Microsoft Windows CodePage 932
// ↑厳密に言うと Windows は「shift_jis」と完全な互換ではない.
// 今までスタンダードな表記法は「CP932」だったが、
// 「commons-net-3.3」では「MS932」でないとエラーになるようだ.
put("EUC-JP", "EUC-JP"); //
put("ASCII", "ISO-8859-1"); //
}
};
}
public void start(){
System.out.println("start( );");
repaint();
}
public void stop(){
System.out.println("stop( );");
}
public void destroy(){
System.out.println("destroy( );");
}
public void FTPLogin() {
System.out.println("FTPLogin( );");
oMainPanelImp.ctaMessage.setText("");
lFTPPassiveMode = oMainPanelImp.cckHostPASVMode.isSelected( );
vsHostEncode =
da1CharEncodeSets.get((String)oMainPanelImp.ccbHostEncode.getSelectedItem());
Pattern pattern = Pattern.compile("( |\n)$");
vsHostName = oMainPanelImp.ctfHostName.getText();
matcher = pattern.matcher(vsHostName);
vsHostName = matcher.replaceAll("");
vsHostPortNum = oMainPanelImp.ctfHostPortNum.getText( );
matcher = pattern.matcher(vsHostPortNum);
vsHostPortNum = matcher.replaceAll("");
if(vsHostPortNum.isEmpty( )){ vsHostPortNum = "0"; }
iHostPortNum = Integer.parseInt(vsHostPortNum);
vsHostUserName = oMainPanelImp.ctfHostUserName.getText();
matcher = pattern.matcher(vsHostUserName);
vsHostUserName = matcher.replaceAll("");
vsHostPassword = String.valueOf(oMainPanelImp.cpfHostPassword.getPassword( ));
matcher = pattern.matcher(vsHostPassword);
vsHostPassword = matcher.replaceAll("");
System.out.println("MainAppFrameObj: "+
"vsHostEncode="+vsHostEncode+"; "+
"vsHostName="+vsHostName+"; "+
"iHostPortNum="+iHostPortNum+"; "+
"vsHostUserName="+vsHostUserName+"; "+
"vsHostPassword="+vsHostPassword+"; "+
"");
try {
client = new FTPClient();
String vsEncode = client.getControlEncoding();
System.out.println("MainAppFrameObj: "+
"vsEncode="+vsEncode+"; "+
"");
client.setControlEncoding(vsHostEncode);
// ↑ Host 側のキャラクター・セットを設定してやれば良いようだ.
System.out.println("Connect...");
client.connect(vsHostName, iHostPortNum);
System.out.println("Connected to Server:" + vsHostName + " on "+client.getRemotePort());
System.out.println(client.getReplyString());
client.login(vsHostUserName,vsHostPassword);
System.out.println(client.getReplyString());
lFTPConnection = true; // false; //
if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
System.out.println("Success:Login.");
oMainPanelImp.ctaMessage.append("Success:Login.\n");
}else{
System.out.println("Error:FTP PositiveCompletion.");
oMainPanelImp.ctaMessage.append("Error:FTP PositiveCompletion.\n");
FTPLogout();
return;
}
if (lFTPPassiveMode) {
client.enterLocalPassiveMode();
System.out.println("PassiveMode = ON");
} else {
client.enterLocalActiveMode();
System.out.println("PassiveMode = OFF");
}
HostFileList("");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:Login.");
oMainPanelImp.ctaMessage.append("IOException:Login.\n");
}
}
public void FTPLogout() {
System.out.println("FTPLogout( );");
try {
lFTPConnection = false; // true; //
if( client!=null && client.isConnected( ) ){
client.disconnect( );
System.out.println("FTP Disconnect.");
oMainPanelImp.ctaMessage.append("FTP Disconnect.\n");
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPLogout.");
oMainPanelImp.ctaMessage.append("IOException:FTPLogout.\n");
}
}
public void HostFileList(String vsTargetFile){
System.out.println("HostFileList( );");
try {
Pattern pattern = Pattern.compile("( |\n)$");
vsHostFolder = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostFolder);
vsHostFolder = matcher.replaceAll("");
System.out.println("vsTargetFile="+vsTargetFile+"; ");
vsHostCurrent = "";
if( vsTargetFile.compareTo("..")==0 ){
System.out.println("if( vsTargetFile.compareTo(..)==0 )");
vsTargetFile = "";
client.changeToParentDirectory();
}else{
vsHostCurrent = vsHostFolder+(vsHostFolder.endsWith("/") ? "" : "/")+vsTargetFile;
// client.doCommand("CWD", vsHostCurrent);
client.changeWorkingDirectory(vsHostCurrent);
}
System.out.println(client.getReplyString());
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
String vsMsg = "Connection test => " + (lFTPConnection ? "OK" : "NG")+".";
System.out.println(vsMsg);
oMainPanelImp.ctaMessage.append(vsMsg+"\n");
vsHostCurrent = client.printWorkingDirectory();
oMainPanelImp.ctfHostFolder.setText(vsHostCurrent);
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).removeAllElements( );
// JScrollPane には暗黙の子 JViewport が存在するようだ。
// つまり、この場合の JList の親は JViewport になり、
// JList の親の親が JScrollPane となる。
JScrollPane oTabsSelectedComponent = (JScrollPane)(oMainPanelImp.cltHostFileList.getParent( ).getParent( ));
oMainPanelImp.ctpFileListTabs.setSelectedComponent(oTabsSelectedComponent);
if( vsHostCurrent.compareTo("/")!=0 ){
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).addElement(
fvsPathListType_Folder+"..");
}
String vsElement = "";
String[] d1vsHostFile = new String[client.listFiles().length];
int i = 0;
for (FTPFile oFTPFile : client.listFiles()) {
String vsHostFile = oFTPFile.getName();
String vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsHostFile;
if( oFTPFile.isFile( ) ){
vsElement = fvsPathListType_File;
}else if( oFTPFile.isDirectory( ) ){
vsElement = fvsPathListType_Folder;
}
d1vsHostFile[i] = vsElement+vsHostFile;
i++;
}
FileSort(d1vsHostFile);
for ( i = 0; i<d1vsHostFile.length; ++i) {
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).addElement(
d1vsHostFile[i]);
System.out.println(d1vsHostFile[i]);
char[] d1vcFileElement = d1vsHostFile[i].toCharArray();
System.out.print("Hex = ");
for(int j = 0; j<d1vcFileElement.length; j++){
int k = d1vcFileElement[j];
if( k<0 ){ k = 65536+k; }
// ↑2の補数の負の値を正の値に変換している.
System.out.print(Integer.toHexString(k)+"; ");
}
System.out.println("");
}
return;
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:Login.");
oMainPanelImp.ctaMessage.append("IOException:Login.\n");
return;
}
}
public void LocalFileList(String vsTargetFile){
System.out.println("LocalFileList( );");
Pattern pattern = Pattern.compile("( |\n)$");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
File oLocalCurrent = null;
System.out.println("vsTargetFile="+vsTargetFile+"; ");
vsHostCurrent = "";
oLocalCurrent = new File(vsLocalCurrent,vsTargetFile);
if( vsTargetFile.compareTo("..")==0 ){
System.out.println("if( vsTargetFile.compareTo(..)==0 )");
vsTargetFile = "";
}
try {
vsLocalCurrent = oLocalCurrent.getCanonicalPath( );
oMainPanelImp.ctfLocalFolder.setText(vsLocalCurrent);
System.out.println("vsLocalCurrent="+vsLocalCurrent+"; ");
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).removeAllElements( );
// JScrollPane には暗黙の子 JViewport が存在するようだ。
// つまり、この場合の JList の親は JViewport になり、
// JList の親の親が JScrollPane となる。
JScrollPane oTabsSelectedComponent = (JScrollPane)(oMainPanelImp.cltLocalFileList.getParent( ).getParent( ));
oMainPanelImp.ctpFileListTabs.setSelectedComponent(oTabsSelectedComponent);
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
oLocalCurrent = null;
}
if( oLocalCurrent!=null && oLocalCurrent.isDirectory( ) ){
pattern = Pattern.compile("^?(.:)(/|\\\\)$");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalCurrent);
System.out.println("pattern = Pattern.compile(^?(.:)(/|\\\\)$)");
if( ! matcher.find( ) ){
System.out.println("if( matcher.find( ) )");
// vsLocalCurrent = matcher.replaceAll("");
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).addElement(
fvsPathListType_Folder+"..");
}
String vsElement = "";
String[] d1vsLocalFile = new String[oLocalCurrent.listFiles().length];
int i = 0;
for (File oFile : oLocalCurrent.listFiles( )) {
String vsLocalFile = oFile.getName();
String vsLocalPath = vsLocalCurrent+(vsLocalCurrent.endsWith("/") ? "" : "/")+vsLocalFile;
if(oFile.isFile()){
vsElement = fvsPathListType_File;
}else if(oFile.isDirectory( )){
vsElement = fvsPathListType_Folder;
}
d1vsLocalFile[i] = vsElement+vsLocalFile;
i++;
}
FileSort(d1vsLocalFile);
for ( i = 0; i<d1vsLocalFile.length; ++i) {
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).addElement(
d1vsLocalFile[i]);
System.out.println(d1vsLocalFile[i]);
char[] d1vcFileElement = d1vsLocalFile[i].toCharArray( );
System.out.print("Hex = ");
for(int j = 0; j<d1vcFileElement.length; j++){
int k = d1vcFileElement[j];
if( k<0 ){ k = 65536+k; }
// ↑2の補数の負の値を正の値に変換している.
System.out.print(Integer.toHexString(k)+"; ");
}
System.out.println("");
}
}
return;
}
public void FileSort(String[] d1vsFile){
System.out.println("Arrays.sort( );");
Arrays.sort(d1vsFile, new Comparator<String>() {
@Override
public int compare(String vs0, String vs1) {
// このソートを Windows 的な File 名のソート順にカスタマイズしている.
String vs, vsAscTab = new String(Character.toChars(0x09));
vs = vs0;
vs0 = vs.toUpperCase( )+vsAscTab+vs;
vs = vs1;
vs1 = vs.toUpperCase( )+vsAscTab+vs;
return vs0.compareTo(vs1);
}
});
}
public void FTPDownload( ){
matcher = null;
Pattern pattern = null;
String vsTargetFile = null;
String vsHostPath = null;
pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
String vsLocalPath = vsLocalCurrent;
pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
if( ! oMainPanelImp.cltHostFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltHostFileList.getSelectedValue();
pattern = Pattern.compile("^"+fvsPathListType_File);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
pattern = Pattern.compile("^"+fvsPathListType_Folder);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
if(matcher.find()){
System.out.println("if(matcher.find( ))");
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsTargetFile = "";
}
}else{
vsTargetFile = "";
}
if( vsTargetFile!=null ){
// vsLocalPath= vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsTargetFile;
System.out.println("FTPDownload: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPatht="+vsLocalPath+"; "+
"");
FTPDownloadFolder( vsTargetFile, vsHostCurrent, vsLocalCurrent );
System.out.println("FTPDownload Completed.");
oMainPanelImp.ctaMessage.append("FTPDownload Completed.\n");
try {
client.changeWorkingDirectory(vsHostCurrent);
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
LocalFileList("");
lFTPBreak = false; // true; //
}
public void FTPDownloadFolder( String vsTargetFile, String vsHostCurrent, String vsLocalCurrent ){
System.out.println("FTPDownloadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
if( vsTargetFile!=null && vsTargetFile.compareTo("")!=0 ){
FTPDownloadFile( vsTargetFile, vsHostCurrent, vsLocalCurrent);
}else{
String vsHostPath = null;
try {
client.changeWorkingDirectory(vsHostCurrent);
System.out.println("client.changeWorkingDirectory(vsHostCurrent)");
// FTPFile[] d1oFTPFile = client.listFiles();
for (FTPFile oFTPFile : client.listFiles()) {
if( lFTPBreak ){
break;
}
String vsHostFile = oFTPFile.getName();
if( oFTPFile.isFile( ) ){
FTPDownloadFile( vsHostFile, vsHostCurrent, vsLocalCurrent);
}else if( oFTPFile.isDirectory( ) ){
String vsLocalPath = vsLocalCurrent;
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsHostFile;
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsHostFile;
System.out.println("FTPDownloadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
File oLocalPath = new File(vsLocalPath);
if( ! oLocalPath.exists( ) ){
oLocalPath.mkdir();
}
FTPDownloadFolder( "", vsHostPath, vsLocalPath );
client.changeWorkingDirectory(vsHostCurrent);
}
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
}
public void FTPDownloadFile(String vsTargetFile,String vsHostCurrent,String vsLocalCurrent){
String vsMsg;
String vsLocalPath = null;
String vsHostPath = null;
FileOutputStream oFOS = null;
try{
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
vsLocalPath = vsLocalCurrent;
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
// client.changeWorkingDirectory(vsHostCurrent);
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsTargetFile;
System.out.println("FTPDownloadFile: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
lFTPTransfer_Binary = false; // true; //
if( 0==fvsFTPTransfer_Binary.compareTo(
(String)oMainPanelImp.ccbFTPFileDataType.getSelectedItem( )) ){
lFTPTransfer_Binary = true; // false; //
}
if(lFTPTransfer_Binary){
client.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("Transfer:Binary.");
}else{
client.setFileType(FTP.ASCII_FILE_TYPE);
System.out.println("Transfer:ASCII.");
}
// FTP Download.
oFOS = new FileOutputStream(vsLocalPath);
client.retrieveFile(vsHostPath, oFOS);
oFOS.close();
oMainPanelImp.ctaMessage.append("vsHostPath = "+vsHostPath+";"+"\n");
oMainPanelImp.ctaMessage.append("vsLocalPath = "+vsLocalPath+";"+"\n");
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
vsMsg = "FTPDownloadFile Completed:Connection => " + (lFTPConnection ? "OK" : "NG")+".";
System.out.println(vsMsg);
oMainPanelImp.ctaMessage.append(vsMsg+"\n");
}catch(Exception e){
e.printStackTrace();
oMainPanelImp.ctaMessage.append("Exception:FTPDownload.\n");
}
}
public void FTPUpload( ){
matcher = null;
Pattern pattern = null;
String vsTargetFile = null;
String vsHostPath = null;
pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
String vsLocalPath = vsLocalCurrent;
pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
try {
File oLocalCurrent;
File oLocalPath = new File(vsLocalPath);
if( oLocalPath.isFile( ) ){
vsTargetFile = oLocalPath.getName( );
vsLocalCurrent = oLocalPath.getParent( );
oLocalCurrent = new File(vsLocalCurrent);
vsLocalCurrent = oLocalCurrent.getCanonicalPath();
}else if( ! oMainPanelImp.cltLocalFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltLocalFileList.getSelectedValue();
pattern = Pattern.compile("^"+fvsPathListType_File);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
pattern = Pattern.compile("^"+fvsPathListType_Folder);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
if(matcher.find()){
System.out.println("if(matcher.find( ))");
vsLocalPath = vsLocalCurrent+(vsLocalCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsTargetFile = "";
}
}else{
vsTargetFile = "";
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
vsTargetFile = null;
}
if( vsTargetFile!=null ){
System.out.println("FTPUpload: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPatht="+vsLocalPath+"; "+
"");
FTPUploadFolder( vsTargetFile, vsHostCurrent, vsLocalCurrent );
System.out.println("FTPUpload Completed.");
oMainPanelImp.ctaMessage.append("FTPUpload Completed.\n");
try {
client.changeWorkingDirectory(vsHostCurrent);
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
HostFileList("");
lFTPBreak = false; // true; //
}
public void FTPUploadFolder( String vsTargetFile, String vsHostCurrent, String vsLocalCurrent ){
System.out.println("FTPUploadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
if( vsTargetFile!=null && vsTargetFile.compareTo("")!=0 ){
FTPUploadFile( vsTargetFile, vsHostCurrent, vsLocalCurrent);
}else{
String vsHostPath = null;
try {
File oLocalCurrent = new File(vsLocalCurrent);
System.out.println("oLocalCurrent = new File(vsLocalCurrent)");
for (File oFile : oLocalCurrent.listFiles()) {
if( lFTPBreak ){
break;
}
String vsLocalFile = oFile.getName();
if( oFile.isFile( ) ){
FTPUploadFile( vsLocalFile, vsHostCurrent, vsLocalCurrent);
}else if( oFile.isDirectory( ) ){
String vsLocalPath = vsLocalCurrent;
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsLocalFile;
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsLocalFile;
System.out.println("FTPUploadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
try {
// client.changeWorkingDirectory(vsHostPath);
System.out.println("client.makeDirectory(vsHostPath).");
client.makeDirectory(vsHostPath);
} catch (IOException e) {
e.printStackTrace();
}
FTPUploadFolder( "", vsHostPath, vsLocalPath );
client.changeWorkingDirectory(vsHostCurrent);
}
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
}
public void FTPUploadFile(String vsTargetFile,String vsHostCurrent,String vsLocalCurrent){
String vsMsg;
String vsLocalPath = null;
String vsHostPath = null;
FileInputStream oFIS = null;
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
vsLocalPath = vsLocalCurrent;
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsTargetFile;
System.out.println("FTPUploadFile: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
lFTPTransfer_Binary = false; // true; //
if( 0==fvsFTPTransfer_Binary.compareTo(
(String)oMainPanelImp.ccbFTPFileDataType.getSelectedItem( )) ){
lFTPTransfer_Binary = true; // false; //
}
try{
if(lFTPTransfer_Binary){
client.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("Transfer:Binary.");
}else{
client.setFileType(FTP.ASCII_FILE_TYPE);
System.out.println("Transfer:ASCII.");
}
// FTP Upload.
oFIS = new FileInputStream(vsLocalPath);
client.storeFile(vsHostPath, oFIS);
oFIS.close();
oMainPanelImp.ctaMessage.append("FTPUploadFile: "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"\n");
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
vsMsg = "FTPUploadFile Completed:Connection = " + (lFTPConnection ? "OK" : "NG")+".";
System.out.println(vsMsg);
oMainPanelImp.ctaMessage.append(vsMsg+"\n");
}catch(Exception e){
e.printStackTrace();
oMainPanelImp.ctaMessage.append("Exception:FTPUpload.\n");
}
}
class MainPanelImplementationObj extends MainPanelDesign {
long ilDoubleClickedIntervalMax = 250; // 350; 300;
// volatile:最適化の抑制.
volatile byte ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 0;
Thread oThread_HostFileList_CbtMouseMouseDoubleClicked;
Runnable oRunner_HostFileList_CbtMouseMouseDoubleClicked;
// volatile:最適化の抑制.
volatile byte ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 0;
Thread oThread_LocalFileList_CbtMouseMouseDoubleClicked;
Runnable oRunner_LocalFileList_CbtMouseMouseDoubleClicked;
MainPanelImplementationObj(){
super( );
oThread_HostFileList_CbtMouseMouseDoubleClicked = new Thread(
oRunner_HostFileList_CbtMouseMouseDoubleClicked = new Runnable( ) {
@Override
public synchronized void run() {
System.out.println("run.");
boolean lInterrupted = false; // true; //
while(true){
try {
wait( );
// ↑メソッドを synchronized 指定するか、
// synchronized(自分のインスタンス) ブロックで囲うかしないと
// 実行時に「IllegalMonitorStateException」が発生する。
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("wait:End.");
lInterrupted = false; // true; //
try {
Thread.sleep(ilDoubleClickedIntervalMax);
} catch (InterruptedException e) {
// e.printStackTrace();
System.out.println("sleep:InterruptedException.");
lInterrupted = true; // false; //
}
System.out.println("sleep:End.");
if( ! lInterrupted &&
ibCnt_HostFileList_CbtMouseMouseDoubleClicked==2 ){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 0;
HostFileList_CbtMouseMouseClicked( );
}
}
}
}
);
oThread_HostFileList_CbtMouseMouseDoubleClicked.start( );
oThread_LocalFileList_CbtMouseMouseDoubleClicked = new Thread(
oRunner_LocalFileList_CbtMouseMouseDoubleClicked = new Runnable( ) {
@Override
public synchronized void run() {
System.out.println("run.");
boolean lInterrupted = false; // true; //
while(true){
try {
wait( );
// ↑メソッドを synchronized 指定するか、
// synchronized(自分のインスタンス) ブロックで囲うかしないと
// 実行時に「IllegalMonitorStateException」が発生する。
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("wait:End.");
lInterrupted = false; // true; //
try {
Thread.sleep(ilDoubleClickedIntervalMax);
} catch (InterruptedException e) {
// e.printStackTrace();
System.out.println("sleep:InterruptedException.");
lInterrupted = true; // false; //
}
System.out.println("sleep:End.");
if( ! lInterrupted &&
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked==2 ){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 0;
LocalFileList_CbtMouseMouseClicked( );
}
}
}
}
);
oThread_LocalFileList_CbtMouseMouseDoubleClicked.start( );
}
@Override
void HostLogin_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostLogin_CbtMouseMouseReleased.");
oMainApp.FTPLogin( );
}
@Override
void HostLogout_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostLogout_CbtMouseMouseReleased.");
oMainApp.FTPLogout( );
}
@Override
void FTPFileList_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPFileList_CbtMouseMouseReleased.");
Pattern pattern = Pattern.compile("( |\n)$");
vsHostFolder = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostFolder);
vsHostFolder = matcher.replaceAll("");
JScrollPane oTabsSelectedComponent = (JScrollPane)ctpFileListTabs.getSelectedComponent( );
System.out.println("oTabsSelectedComponent = "+oTabsSelectedComponent);
System.out.println("oTabsSelectedComponent.getViewport() = "+oTabsSelectedComponent.getViewport());
System.out.println("cltLocalFileList.getParent() = "+cltLocalFileList.getParent());
System.out.println("cltLocalFileList.getParent().getParent() = "+cltLocalFileList.getParent().getParent());
// JScrollPane には暗黙の子 JViewport が存在し、
// 「JScrollPane.getViewport( ) 」で(暗黙の子) JViewport のインスタンスを取得できる。
// つまり、この場合の JList の親は JViewport となる。
// ちなみに、この場合の JList の親の親が JScrollPane となる。
if( lFTPConnection &&
oTabsSelectedComponent.getViewport()==cltHostFileList.getParent( ) ){
// HostFileList0000();
}
if( oTabsSelectedComponent.getViewport()==cltLocalFileList.getParent( ) ){
// LocalFileList();
}
}
@Override
void FTPDownload_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPDownload_CbtMouseMouseReleased.");
FTPDownload( );
}
@Override
void FTPUpload_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPUpload_CbtMouseMouseReleased.");
FTPUpload( );
}
void HostFileList_CbtMouseMouseClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CbtMouseMouseClicked.");
}
void HostFileList_CbtMouseMouseDoubleClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CbtMouseMouseDoubleClicked.");
Pattern pattern = null;
String vsTargetFile = null;
if( ! oMainPanelImp.cltHostFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltHostFileList.getSelectedValue();
pattern = Pattern.compile("^("+fvsReg_PathListType_Folder+")");
matcher = pattern.matcher(vsTargetFile);
if(matcher.find()){
vsTargetFile = matcher.replaceAll("");
System.out.println("vsTargetFile = "+vsTargetFile+"; ");
HostFileList(vsTargetFile);
}
}else{
vsTargetFile = null;
oMainPanelImp.ctaMessage.append("HostFileList で項目が選択せれていません.\n");
}
}
@Override
void HostFileList_CbtNativeMouseMousePressed(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CbtNativeMouseMousePressed");
if(oThread_HostFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.TIMED_WAITING){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 3;
oThread_HostFileList_CbtMouseMouseDoubleClicked.interrupt();
}else{
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 1;
}
System.out.println("ibCnt_HostFileList_CbtMouseMouseDoubleClicked="+ibCnt_HostFileList_CbtMouseMouseDoubleClicked+"; ");
}
@Override
void HostFileList_CltNativeMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CltNativeMouseMouseReleased.");
if(ibCnt_HostFileList_CbtMouseMouseDoubleClicked==3){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 0;
HostFileList_CbtMouseMouseDoubleClicked( );
}else if(oThread_HostFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.WAITING){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 2;
synchronized(oRunner_HostFileList_CbtMouseMouseDoubleClicked) {
oRunner_HostFileList_CbtMouseMouseDoubleClicked.notify();
// ↑ synchronized(自分のインスタンス) ブロックで囲わないとないと
// 実行時に「IllegalMonitorStateException」が発生する。
// ここ(this)は他人なので、ここのメソッドを synchronized 指定してもダメ。
}
}
System.out.println("ibCnt_HostFileList_CbtMouseMouseDoubleClicked="+ibCnt_HostFileList_CbtMouseMouseDoubleClicked+"; ");
}
void LocalFileList_CbtMouseMouseClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CbtMouseMouseClicked.");
}
void LocalFileList_CbtMouseMouseDoubleClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CbtMouseMouseDoubleClicked.");
Pattern pattern = null;
String vsTargetFile = null;
if( ! oMainPanelImp.cltLocalFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltLocalFileList.getSelectedValue();
pattern = Pattern.compile("^("+fvsReg_PathListType_Folder+")");
matcher = pattern.matcher(vsTargetFile);
if(matcher.find()){
vsTargetFile = matcher.replaceAll("");
System.out.println("vsTargetFile = "+vsTargetFile+"; ");
LocalFileList(vsTargetFile);
}
}else{
vsTargetFile = null;
oMainPanelImp.ctaMessage.append("LocalFileList で項目が選択せれていません.\n");
}
}
@Override
void LocalFileList_CbtNativeMouseMousePressed(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CbtNativeMouseMousePressed");
if(oThread_LocalFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.TIMED_WAITING){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 3;
oThread_LocalFileList_CbtMouseMouseDoubleClicked.interrupt();
}else{
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 1;
}
System.out.println("ibCnt_LocalFileList_CbtMouseMouseDoubleClicked="+ibCnt_LocalFileList_CbtMouseMouseDoubleClicked+"; ");
}
@Override
void LocalFileList_CltNativeMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CltNativeMouseMouseReleased");
if(ibCnt_LocalFileList_CbtMouseMouseDoubleClicked==3){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 0;
LocalFileList_CbtMouseMouseDoubleClicked( );
}else if(oThread_LocalFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.WAITING){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 2;
synchronized(oRunner_LocalFileList_CbtMouseMouseDoubleClicked) {
oRunner_LocalFileList_CbtMouseMouseDoubleClicked.notify();
// ↑ synchronized(自分のインスタンス) ブロックで囲わないとないと
// 実行時に「IllegalMonitorStateException」が発生する。
// ここ(this)は他人なので、ここのメソッドを synchronized 指定してもダメ。
}
}
System.out.println("ibCnt_LocalFileList_CbtMouseMouseDoubleClicked="+ibCnt_LocalFileList_CbtMouseMouseDoubleClicked+"; ");
}
@Override
void SetupFileList_HostFolder_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:SetupFileList_HostFolder_CbtMouseMouseReleased.");
HostFileList("");
}
@Override
void SetupFileList_LocalFolder_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:SetupFileList_LocalFolder_CbtMouseMouseReleased.");
LocalFileList("");
}
void FTPBreak_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPBreak_CbtMouseMouseReleased.");
lFTPBreak = true; // false; //
}
}
static class MainAppFrameObj extends JFrame implements Runnable {
// JApplet oApplet;
Thread oAppThread;
public MainAppFrameObj( ) {
super("Application frame.");
//setVisible(false);
System.out.println("Construct:Application frame window.");
// oApplet = oEntApplet; // new JAppletcation();
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent event){
// ユーザーがウインドウを閉じようとした時].
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosing.");
oMainApp.FTPLogout();
Close();
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowClosed(WindowEvent event){
// ウインドウが閉じた時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosed.");
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowDeiconified(WindowEvent event){
// ウィンドウが最小化された状態から通常の状態に変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowDeiconified.");
oMainApp.repaint();
}
}
}
);
addComponentListener(
new ComponentAdapter(){
public void componentResized(ComponentEvent event){
// コンポーネントのサイズが変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("ComponentEvent:componentResized.");
System.out.println("MainAppFrameObj: "+
"width="+Integer.toString(MainAppFrameObj.this.getSize( ).width)+"; "+
"Height="+Integer.toString(MainAppFrameObj.this.getSize( ).height)+"; "+
"");
oMainApp.repaint();
}
}
}
);
getContentPane().add(oMainApp,"Center");
oAppThread= new Thread(this);
}
public synchronized void setPreSize(Dimension oSize){
// dispose();
getContentPane().setPreferredSize(oSize);
pack();
setVisible(true);
requestFocus();
}
public synchronized void run(){
System.out.println("Open:Application frame window.");
oMainApp.init();
oMainApp.start();
oMainApp.repaint();
try{
wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
oMainApp.stop();
oMainApp.destroy();
oAppThread = null;
}
public synchronized void Close(){
System.out.println("Close:Application frame window.");
dispose();
notify();
}
}
}
|
|
|
<Number>: [0000096D]
<Date>: 2015/12/22 14:17:09
<Title>:
<Name>: amanojaku@管理人
|
|
|
『MainPanelDesign.java』
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.dyno.visual.swing.layouts.Bilateral;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class MainPanelDesign extends JPanel {
private static final long serialVersionUID = 1L;
private JButton cbtHostLogin;
private JButton cbtHostLogout;
private JButton cbtFTPUpload;
private JButton cbtFTPBreak;
private JButton cbtFTPDownload;
private JButton cbtSetupFileList_HostFolder;
private JButton cbtSetupFileList_LocalFolder;
JTextField ctfHostUserName;
JTextField ctfHostName;
JPasswordField cpfHostPassword;
JTextField ctfHostFolder;
JTextField ctfLocalFolder;
JTextField ctfHostPortNum;
JTextArea ctaMessage;
JList cltHostFileList;
JList cltLocalFileList;
JComboBox ccbFTPFileDataType;
JTabbedPane ctpFileListTabs;
JCheckBox cckHostPASVMode;
JComboBox ccbHostEncode;
private JLabel jLabel2;
private JLabel jLabel6;
private JLabel jLabel5;
private JLabel jLabel0;
private JLabel jLabel1;
private JLabel jLabel7;
private JLabel jLabel9;
private JScrollPane jScrollPane0;
private JScrollPane jScrollPane1;
private JScrollPane jScrollPane2;
public MainPanelDesign() {
initComponents();
}
private void initComponents() {
setMinimumSize(new Dimension(479, 400));
setPreferredSize(new Dimension(479, 400));
setLayout(new GroupLayout());
add(getJScrollPane0(), new Constraints(new Leading(13, 219, 10, 10), new Leading(255, 131, 12, 12)));
add(getJLabel2(), new Constraints(new Leading(14, 12, 12), new Leading(185, 12, 12)));
add(getJLabel6(), new Constraints(new Leading(14, 12, 12), new Leading(153, 12, 12)));
add(getJLabel7(), new Constraints(new Leading(250, 12, 12), new Leading(151, 12, 12)));
add(getJLabel9(), new Constraints(new Leading(250, 12, 12), new Leading(51, 12, 12)));
add(getCcbFTPFileDataType(), new Constraints(new Leading(322, 12, 12), new Leading(47, 12, 12)));
add(getCckHostPASVMode(), new Constraints(new Leading(12, 12, 12), new Leading(12, 12, 12)));
add(getJLabel1(), new Constraints(new Leading(12, 12, 12), new Leading(51, 12, 12)));
add(getCtpFileListTabs(), new Constraints(new Bilateral(250, 12, 57), new Leading(169, 217, 10, 10)));
add(getCbtSetupFileList_HostFolder(), new Constraints(new Leading(253, 12, 12), new Leading(117, 12, 12)));
add(getJLabel5(), new Constraints(new Leading(15, 12, 12), new Leading(87, 12, 12)));
add(getCtfHostName(), new Constraints(new Leading(92, 142, 12, 12), new Leading(85, 12, 12)));
add(getCtfHostPortNum(), new Constraints(new Leading(92, 142, 12, 12), new Leading(119, 12, 12)));
add(getJLabel0(), new Constraints(new Leading(13, 12, 12), new Leading(121, 12, 12)));
add(getCtfHostUserName(), new Constraints(new Leading(92, 138, 75, 282), new Leading(151, 12, 12)));
add(getCpfHostPassword(), new Constraints(new Leading(93, 139, 75, 282), new Leading(183, 12, 12)));
add(getCbtHostLogin(), new Constraints(new Leading(15, 72, 75, 282), new Leading(215, 12, 12)));
add(getCbtHostLogout(), new Constraints(new Leading(95, 10, 10), new Leading(215, 12, 12)));
add(getCtfHostFolder(), new Constraints(new Leading(377, 144, 12, 12), new Leading(119, 12, 12)));
add(getCtfLocalFolder(), new Constraints(new Leading(377, 144, 12, 12), new Leading(85, 12, 12)));
add(getCbtSetupFileList_LocalFolder(), new Constraints(new Leading(253, 12, 12), new Leading(82, 12, 12)));
add(getCcbHostEncode(), new Constraints(new Leading(93, 12, 12), new Leading(47, 12, 12)));
add(getCbtFTPDownload(), new Constraints(new Leading(250, 12, 12), new Leading(11, 12, 12)));
add(getCbtFTPUpload(), new Constraints(new Leading(352, 12, 12), new Leading(11, 12, 12)));
add(getCbtFTPBreak(), new Constraints(new Leading(437, 12, 12), new Leading(11, 12, 12)));
setSize(536, 400);
}
private JButton getCbtFTPBreak() {
if (cbtFTPBreak == null) {
cbtFTPBreak = new JButton();
cbtFTPBreak.setText("Break");
cbtFTPBreak.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPBreak_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPBreak;
}
private JComboBox getCcbHostEncode() {
if (ccbHostEncode == null) {
ccbHostEncode = new JComboBox();
ccbHostEncode.setModel(new DefaultComboBoxModel(new Object[] { "UTF-8", "Windows", "EUC-JP", "ASCII" }));
ccbHostEncode.setDoubleBuffered(false);
ccbHostEncode.setBorder(null);
}
return ccbHostEncode;
}
private JButton getCbtSetupFileList_HostFolder() {
if (cbtSetupFileList_HostFolder == null) {
cbtSetupFileList_HostFolder = new JButton();
cbtSetupFileList_HostFolder.setText("HostFolder >");
cbtSetupFileList_HostFolder.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
SetupFileList_HostFolder_CbtMouseMouseReleased(event);
}
});
}
return cbtSetupFileList_HostFolder;
}
private JButton getCbtSetupFileList_LocalFolder() {
if (cbtSetupFileList_LocalFolder == null) {
cbtSetupFileList_LocalFolder = new JButton();
cbtSetupFileList_LocalFolder.setText("LocalFolder >");
cbtSetupFileList_LocalFolder.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
SetupFileList_LocalFolder_CbtMouseMouseReleased(event);
}
});
}
return cbtSetupFileList_LocalFolder;
}
private JButton getCbtFTPUpload() {
if (cbtFTPUpload == null) {
cbtFTPUpload = new JButton();
cbtFTPUpload.setText("Upload");
cbtFTPUpload.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPUpload_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPUpload;
}
private JComboBox getCcbFTPFileDataType() {
if (ccbFTPFileDataType == null) {
ccbFTPFileDataType = new JComboBox();
ccbFTPFileDataType.setModel(new DefaultComboBoxModel(new Object[] { "Binary", "ASCII" }));
ccbFTPFileDataType.setDoubleBuffered(false);
ccbFTPFileDataType.setBorder(null);
}
return ccbFTPFileDataType;
}
private JLabel getJLabel9() {
if (jLabel9 == null) {
jLabel9 = new JLabel();
jLabel9.setText("FileDtata");
}
return jLabel9;
}
private JCheckBox getCckHostPASVMode() {
if (cckHostPASVMode == null) {
cckHostPASVMode = new JCheckBox();
cckHostPASVMode.setSelected(true);
cckHostPASVMode.setText("PASVMode");
}
return cckHostPASVMode;
}
private JList getCltLocalFileList() {
if (cltLocalFileList == null) {
cltLocalFileList = new JList();
cltLocalFileList.setBackground(Color.white);
DefaultListModel listModel = new DefaultListModel();
cltLocalFileList.setModel(listModel);
cltLocalFileList.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
LocalFileList_CbtNativeMouseMousePressed(event);
}
public void mouseReleased(MouseEvent event) {
LocalFileList_CltNativeMouseMouseReleased(event);
}
});
}
return cltLocalFileList;
}
private JLabel getJLabel7() {
if (jLabel7 == null) {
jLabel7 = new JLabel();
jLabel7.setText("FileList");
}
return jLabel7;
}
private JTabbedPane getCtpFileListTabs() {
if (ctpFileListTabs == null) {
ctpFileListTabs = new JTabbedPane();
ctpFileListTabs.addTab("Host", getJScrollPane1());
ctpFileListTabs.addTab("Local", getJScrollPane2());
}
return ctpFileListTabs;
}
private JScrollPane getJScrollPane2() {
if (jScrollPane2 == null) {
jScrollPane2 = new JScrollPane();
jScrollPane2.setBackground(Color.white);
jScrollPane2.setViewportView(getCltLocalFileList());
}
return jScrollPane2;
}
private JList getJList0() {
if (cltLocalFileList == null) {
cltLocalFileList = new JList();
DefaultListModel listModel = new DefaultListModel();
listModel.addElement("item0");
listModel.addElement("item1");
listModel.addElement("item2");
listModel.addElement("item3");
cltLocalFileList.setModel(listModel);
}
return cltLocalFileList;
}
private JLabel getJLabel1() {
if (jLabel1 == null) {
jLabel1 = new JLabel();
jLabel1.setText("HostEncode");
}
return jLabel1;
}
private JButton getCbtFTPDownload() {
if (cbtFTPDownload == null) {
cbtFTPDownload = new JButton();
cbtFTPDownload.setText("Download");
cbtFTPDownload.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPDownload_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPDownload;
}
private JScrollPane getJScrollPane1() {
if (jScrollPane1 == null) {
jScrollPane1 = new JScrollPane();
jScrollPane1.setEnabled(false);
jScrollPane1.setViewportView(getCltHostFileList());
}
return jScrollPane1;
}
private JList getCltHostFileList() {
if (cltHostFileList == null) {
cltHostFileList = new JList();
DefaultListModel listModel = new DefaultListModel();
cltHostFileList.setModel(listModel);
cltHostFileList.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
HostFileList_CbtNativeMouseMousePressed(event);
}
public void mouseReleased(MouseEvent event) {
HostFileList_CltNativeMouseMouseReleased(event);
}
});
}
return cltHostFileList;
}
private JScrollPane getJScrollPane0() {
if (jScrollPane0 == null) {
jScrollPane0 = new JScrollPane();
jScrollPane0.setViewportView(getCtaMessage());
}
return jScrollPane0;
}
private JTextArea getCtaMessage() {
if (ctaMessage == null) {
ctaMessage = new JTextArea();
}
return ctaMessage;
}
private JTextField getCtfHostPortNum() {
if (ctfHostPortNum == null) {
ctfHostPortNum = new JTextField();
}
return ctfHostPortNum;
}
private JLabel getJLabel0() {
if (jLabel0 == null) {
jLabel0 = new JLabel();
jLabel0.setText("PortNo");
}
return jLabel0;
}
private JLabel getJLabel5() {
if (jLabel5 == null) {
jLabel5 = new JLabel();
jLabel5.setText("HostName");
}
return jLabel5;
}
private JLabel getJLabel6() {
if (jLabel6 == null) {
jLabel6 = new JLabel();
jLabel6.setText("UserName");
}
return jLabel6;
}
private JTextField getCtfLocalFolder() {
if (ctfLocalFolder == null) {
ctfLocalFolder = new JTextField();
ctfLocalFolder.setBackground(Color.white);
ctfLocalFolder.setText("");
}
return ctfLocalFolder;
}
private JButton getCbtHostLogin() {
if (cbtHostLogin == null) {
cbtHostLogin = new JButton();
cbtHostLogin.setText("Login");
cbtHostLogin.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
HostLogin_CbtMouseMouseReleased(event);
}
});
}
return cbtHostLogin;
}
private JTextField getCtfHostFolder() {
if (ctfHostFolder == null) {
ctfHostFolder = new JTextField();
ctfHostFolder.setBackground(Color.white);
}
return ctfHostFolder;
}
private JButton getCbtHostLogout() {
if (cbtHostLogout == null) {
cbtHostLogout = new JButton();
cbtHostLogout.setText("Logout");
cbtHostLogout.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
HostLogout_CbtMouseMouseReleased(event);
}
});
}
return cbtHostLogout;
}
private JLabel getJLabel2() {
if (jLabel2 == null) {
jLabel2 = new JLabel();
jLabel2.setText("Password");
}
return jLabel2;
}
private JTextField getCtfHostUserName() {
if (ctfHostUserName == null) {
ctfHostUserName = new JTextField();
}
return ctfHostUserName;
}
private JTextField getCtfHostName() {
if (ctfHostName == null) {
ctfHostName = new JTextField();
}
return ctfHostName;
}
private JPasswordField getCpfHostPassword() {
if (cpfHostPassword == null) {
cpfHostPassword = new JPasswordField();
cpfHostPassword.setEchoChar('?');
}
return cpfHostPassword;
}
void HostLogout_CbtMouseMouseReleased(MouseEvent event) {
}
void HostLogin_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPFileList_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPDownload_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPUpload_CbtMouseMouseReleased(MouseEvent event) {
}
void HostFileList_CbtNativeMouseMousePressed(MouseEvent event) {
}
void HostFileList_CltNativeMouseMouseReleased(MouseEvent event) {
}
void LocalFileList_CbtNativeMouseMousePressed(MouseEvent event) {
}
void LocalFileList_CltNativeMouseMouseReleased(MouseEvent event) {
}
void SetupFileList_HostFolder_CbtMouseMouseReleased(MouseEvent event) {
}
void SetupFileList_LocalFolder_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPBreak_CbtMouseMouseReleased(MouseEvent event) {
}
}
|
|
|
<Number>: [0000096E]
<Date>: 2015/12/22 15:50:47
<Title>:
<Name>: amanojaku@管理人
|
|
|
|
|
<Number>: [00000972]
<Date>: 2015/12/26 10:52:28
<Title>:
<Name>: amanojaku@管理人
|
|
|
今回はデータの(暗黙の)「セーブ、ロード」処理(ファイル名は「FTPConnect.sr」としている)。
また複数のフォルダーの登録と、複数のフォルダーの単位の「アップロード、ダウンロード」(子フォルダーに対する再帰的な処理)。
TransferList にデータが存在する場合は「HostFolder、LocalFolder」のデータは無視され、TransferList にデータが存在しない場合は「HostFolder、LocalFolder」のデータで処理される。
《参考》
『Java2 FTP Connect 7』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+00000955.+&
『Java2 MouseDoubleClicked 1』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+0000096B.+&
『Java2 FTP Connect 8』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+0000096C-0000096D&
クラスパスの設定
http://www.hot-surprise.org/IntroEclipse/Operation/N01/3_3.html
FTP に関するプログラムは下記ページを参照.
JavaによるFTP転送サンプル | Pa-kun plus idea
http://web.plus-idea.net/2011/06/javaftp/
> client.setControlEncoding("MS932");
↑ Host 側のキャラクター・セットを設定すれば良いと思われる。
Windows 系では「CP932」(Microsoft Windows CodePage 932)、UNIX 系では「UTF-8、EUC-JP(日本の場合)」などが大半のようだ、Android は「UTF-8」となる。
厳密に言うと Windows のキャラクター・セットは「shift_jis」と完全な互換ではない、今まで Windows のキャラクター・セットのスタンダードな表記法は「CP932」だったが、「commons-net-3.3」では「MS932」でないとエラーになるようだ.
JavaでFTPアップロードを行う。 - sinsengumi.net
http://sinsengumi.net/blog/2011/02/java%E3%81%A7ftp%E3%82%A2%E3%83%83%E3%83%97%E3%83%AD%E3%83%BC%E3%83%89%E3%82%92%E8%A1%8C%E3%81%86%E3%80%82/
(分かりやすければ他のファイル名でも良い)「MainPanelDesign」(MainPanelDesign.java)ファイルを Visual Swing for Eclipse でビジュアルに画面デザイン(GUI 部品の配置)を作成している(Java コードが自動生成される)。
「MainAppFrameObj、MainPanelImplementationObj」 からアプレット独自メソッドにアクセスしているので、「MainAppFrameObj、MainPanelImplementationObj」はアプレット・クラス内に設置している。
(アプリーケーションの初期実行用) main( ) メソッドで(MainAppFrameObjなどのような)クラス内クラスをインスタンス化したい場合(main( ) メソッド実行時には、まだアプレット自体のインスタンスが生成されておらず、通常のクラス内クラスではインスタンス化できないので) 、クラス内クラスには「static」修飾子を付与しなければならない(この場合、オブジェクトは1つだけしか作成できない)。
クリック時にマウス・カーソルが動いてしまった場合 mouseClicked イベントだとイベントが発生しない"仕様"になっているようなので、mouse イベントに関しては mouseReleased イベントを使用している。
なお、ダブル・クリック検出用に mousePressed イベントも使用している。
変更した部分はイベント用メソッドの「ctfHostUserName、ctfHostName、cpfHostPassword、ctfHostFolder、ctfLocalFolder、ctfHostPortNum、ctaMessage、cltHostFileList、cltLocalFileList、ccbFTPFileDataType、ctpFileListTabs、cckHostPASVMode、ccbHostEncode、cpnFTPSetting、ctpBaseTabs、cltHostTransferList、cltLocalTransferList、ctpTransferListTabs」の private 修飾子を削除。
その他、「HostLogout_CbtMouseMouseReleased、HostLogin_CbtMouseMouseReleased、FTPFileList_CbtMouseMouseReleased、FTPDownload_CbtMouseMouseReleased、FTPUpload_CbtMouseMouseReleased、HostFileList_CbtNativeMouseMousePressed、HostFileList_CltNativeMouseMouseReleased、LocalFileList_CbtNativeMouseMousePressed、LocalFileList_CltNativeMouseMouseReleased、SetupFileList_HostFolder_CbtMouseMouseReleased、SetupFileList_LocalFolder_CbtMouseMouseReleased、FTPBreak_CbtMouseMouseReleased、TransferListEntry_CbtMouseMouseReleased、TransferListDelete_CbtMouseMouseReleased」変数の private 修飾子を削除(Button など Component を直にイジる必要がなければ private 修飾子を削除しなくても良い)。
『FTPConnect.java』
import java.awt.Dimension;
//Event を使う場合は、その Event に対応する「〜Adapter、〜Event」を import しなければならない。
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.SocketException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.DefaultListModel;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
@SuppressWarnings("serial")
public class FTPConnect extends JApplet {
private static FTPConnect oMainApp;
private static boolean lApplication = false; // true; //
private static MainAppFrameObj oMainAppFrame;
private MainPanelImplementationObj oMainPanelImp;
private final String fvsSerialFile = "FTPConnect.sr";
private final String fvsSerialVersion = "1.1";
private final String fvsSnapShotFile = ".FTPConnect.SnapShot";
// private final String fvsPathListTag_Folder = ":+Folder:=";
private final String fvsPathListTag_File = "-<File>=";
private final String fvsReg_PathListTag_File = "\\-<File>=";
private final String fvsPathListTag_Folder = "+<Directory>=";
private final String fvsReg_PathListTag_Folder = "\\+<Directory>=";
private final String fvsPathListTag_TimeStamp = " <TimeStamp>=";
private final String fvsReg_PathListTag_TimeStamp = " <TimeStamp>=";
private Matcher matcher;
// Pattern pattern;
// Transfer // Connect
private boolean lFTPConnection = false; // true; //
private boolean lFTPBreak = false; // true; //
private FTPClient client;
// Binary転送Modeを利用?(true=Yes、false=No)
// TransferFileDataType
private static boolean lFTPTransfer_Binary = false; // true; //
// PASV Modeを利用?(true=Yes、false=No)
private static boolean lFTPPassiveMode = true; // false; //
private static final String fvsFTPTransfer_Binary = "Binary";
// 連想配列
private HashMap<String,String> da1CharEncodeSets;
private String vsHostEncode;
private String vsLocalEncode;
private String vsHostName;
private String vsHostPortNum;
private int iHostPortNum;
private String vsHostUserName;
private String vsHostPassword;
private String vsHostCurrent;
private String vsHostFolder;
private String vsLocalCurrent;
private String vsLocalFolder;
public static void main(String[] args) {
oMainApp = new FTPConnect( );
lApplication = true; // false;
oMainAppFrame =
new MainAppFrameObj( );
oMainAppFrame.oAppThread.start();
try{
oMainAppFrame.oAppThread.join();
}
catch(InterruptedException e){ }
// oMainAppFrame.oAppThread = null;
System.exit(0);
}
public void AppRepaint() {
System.out.println("AppRepaint( );");
repaint();
}
public void init() {
System.out.println("init( );");
oMainApp = this;
oMainPanelImp = new MainPanelImplementationObj();
Read( );
getContentPane().add(oMainPanelImp,"Center");
oMainPanelImp.setVisible(true);
if( oMainAppFrame!=null ){
System.out.println("if(lApplication)");
oMainAppFrame.setPreSize(oMainPanelImp.getSize( ));
System.out.println("MainPanelWidth="+oMainPanelImp.getSize( ).getWidth());
System.out.println("MainPanelHeight="+oMainPanelImp.getSize( ).getHeight());
}
System.out.println("Hello, World!");
// UTF8, Windows, EUC-JP, ASCII
da1CharEncodeSets = new HashMap<String, String>(){
{
put("UTF-8", "utf-8");
put("Windows", "MS932"); // Microsoft Windows CodePage 932
// ↑厳密に言うと Windows は「shift_jis」と完全な互換ではない.
// 今までスタンダードな表記法は「CP932」だったが、
// 「commons-net-3.3」では「MS932」でないとエラーになるようだ.
put("EUC-JP", "EUC-JP"); //
put("ASCII", "ISO-8859-1"); //
}
};
}
public void start(){
System.out.println("start( );");
repaint();
}
public void stop(){
System.out.println("stop( );");
}
public void destroy(){
System.out.println("destroy( );");
Write( );
}
public void Write() {
try {
int iListSize;
ObjectOutputStream oOOSSerial = new ObjectOutputStream(new FileOutputStream(fvsSerialFile));
oOOSSerial.writeObject(fvsSerialVersion);
oOOSSerial.writeBoolean(oMainPanelImp.cckHostPASVMode.isSelected( ));
oOOSSerial.writeObject(oMainPanelImp.ccbHostEncode.getSelectedObjects( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostName.getText( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostPortNum.getText( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostUserName.getText( ));
oOOSSerial.writeObject(new String(oMainPanelImp.cpfHostPassword.getPassword( )));
oOOSSerial.writeObject(oMainPanelImp.ccbFTPFileDataType.getSelectedObjects( ));
oOOSSerial.writeObject(oMainPanelImp.ctfLocalFolder.getText( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostFolder.getText( ));
iListSize = ((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( );
oOOSSerial.writeInt(iListSize );
for(int i=0; i<iListSize; i++ ){
oOOSSerial.writeObject(
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getElementAt(i));
}
iListSize = ((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).getSize( );
oOOSSerial.writeInt(iListSize );
for(int i=0; i<iListSize; i++ ){
oOOSSerial.writeObject(
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).getElementAt(i));
}
oOOSSerial.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:Write.");
PutMessage("FileNotFoundException:Write.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:Write.");
PutMessage("IOException:Write.\n");
}
}
public void Read() {
try {
ObjectInputStream oOISSerial = new ObjectInputStream(new FileInputStream(fvsSerialFile));
String vsVersion = (String)oOISSerial.readObject( );
if( fvsSerialVersion.compareTo("")==0){
// Non-Operation
}else if( fvsSerialVersion.compareTo(vsVersion)!=0){
System.out.println("Error:SerialVersion.");
PutMessage("Error:SerialVersion.\n");
}else{
int iListSize;
oMainPanelImp.cckHostPASVMode.setSelected(oOISSerial.readBoolean( ));
oMainPanelImp.ccbHostEncode.setSelectedItem(oOISSerial.readObject( ));
oMainPanelImp.ctfHostName.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ctfHostPortNum.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ctfHostUserName.setText((String)oOISSerial.readObject( ));
oMainPanelImp.cpfHostPassword.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ccbFTPFileDataType.setSelectedItem(oOISSerial.readObject( ));
oMainPanelImp.ctfLocalFolder.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ctfHostFolder.setText((String)oOISSerial.readObject( ));
iListSize = oOISSerial.readInt( );
for(int i=0; i<iListSize; i++ ){
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).addElement(
oOISSerial.readObject( ));
}
iListSize = oOISSerial.readInt( );
for(int i=0; i<iListSize; i++ ){
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).addElement(
oOISSerial.readObject( ));
}
oOISSerial.close( );
}
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:Read.");
// PutMessage("FileNotFoundException:Read.\n");
// PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:Read.");
PutMessage("IOException:Read.\n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("ClassNotFoundException:Read.");
PutMessage("ClassNotFoundException:Read.\n");
}
}
public void PutMessage(String vsMsg){
// System.out.println("PutMessage( );");
// JScrollPane には暗黙の子 JViewport が存在するようだ。
// つまり、この場合の ctaMessage の親は JViewport になり、
// JList の親の親が JScrollPane となる。
JScrollPane oTabsSelectedComponent = (JScrollPane)(oMainPanelImp.ctaMessage.getParent( ).getParent( ));
oMainPanelImp.ctpBaseTabs.setSelectedComponent(oTabsSelectedComponent);
oMainPanelImp.ctaMessage.append(vsMsg);
}
public void FTPLogin() {
System.out.println("FTPLogin( );");
oMainPanelImp.ctaMessage.setText("");
lFTPPassiveMode = oMainPanelImp.cckHostPASVMode.isSelected( );
vsHostEncode =
da1CharEncodeSets.get((String)oMainPanelImp.ccbHostEncode.getSelectedItem());
Pattern pattern = Pattern.compile("( |\n)$");
vsHostName = oMainPanelImp.ctfHostName.getText();
matcher = pattern.matcher(vsHostName);
vsHostName = matcher.replaceAll("");
vsHostPortNum = oMainPanelImp.ctfHostPortNum.getText( );
matcher = pattern.matcher(vsHostPortNum);
vsHostPortNum = matcher.replaceAll("");
if(vsHostPortNum.isEmpty( )){ vsHostPortNum = "0"; }
iHostPortNum = Integer.parseInt(vsHostPortNum);
vsHostUserName = oMainPanelImp.ctfHostUserName.getText();
matcher = pattern.matcher(vsHostUserName);
vsHostUserName = matcher.replaceAll("");
vsHostPassword = String.valueOf(oMainPanelImp.cpfHostPassword.getPassword( ));
matcher = pattern.matcher(vsHostPassword);
vsHostPassword = matcher.replaceAll("");
System.out.println("MainAppFrameObj: "+
"vsHostEncode="+vsHostEncode+"; "+
"vsHostName="+vsHostName+"; "+
"iHostPortNum="+iHostPortNum+"; "+
"vsHostUserName="+vsHostUserName+"; "+
"vsHostPassword="+vsHostPassword+"; "+
"");
try {
client = new FTPClient();
String vsEncode = client.getControlEncoding();
System.out.println("MainAppFrameObj: "+
"vsEncode="+vsEncode+"; "+
"");
client.setControlEncoding(vsHostEncode);
// ↑ Host 側のキャラクター・セットを設定してやれば良いようだ.
System.out.println("Connect...");
client.connect(vsHostName, iHostPortNum);
System.out.println("Connected to Server:" + vsHostName + " on "+client.getRemotePort());
System.out.println(client.getReplyString());
client.login(vsHostUserName,vsHostPassword);
System.out.println(client.getReplyString());
lFTPConnection = true; // false; //
if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
System.out.println("Success:Login.");
PutMessage("Success:Login.\n");
}else{
System.out.println("Error:FTP PositiveCompletion.");
PutMessage("Error:FTP PositiveCompletion.\n");
FTPLogout();
return;
}
if (lFTPPassiveMode) {
client.enterLocalPassiveMode();
System.out.println("PassiveMode = ON");
} else {
client.enterLocalActiveMode();
System.out.println("PassiveMode = OFF");
}
HostFileList("");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPLogin.");
PutMessage("NumberFormatException:FTPLogin.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPLogin.");
PutMessage("SocketException:FTPLogin.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPLogin.");
PutMessage("FileNotFoundException:FTPLogin.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPLogin.");
PutMessage("IOException:FTPLogin.\n");
}
}
public void FTPLogout() {
System.out.println("FTPLogout( );");
try {
lFTPConnection = false; // true; //
if( client!=null && client.isConnected( ) ){
client.disconnect( );
System.out.println("FTP Disconnect.");
PutMessage("FTP Disconnect.\n");
}
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPLogout.");
PutMessage("NumberFormatException:FTPLogout.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPLogout.");
PutMessage("SocketException:FTPLogout.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPLogout.");
PutMessage("FileNotFoundException:FTPLogout.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPLogout.");
PutMessage("IOException:FTPLogout.\n");
}
}
public void HostFileList(String vsTargetFile){
System.out.println("HostFileList( );");
if( client==null || ! client.isConnected( ) ){
oMainPanelImp.ctaMessage.append("Login されていません。\n");
return;
}
try {
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).removeAllElements( );
// JScrollPane には暗黙の子 JViewport が存在するようだ。
// つまり、この場合の JList の親は JViewport になり、
// JList の親の親が JScrollPane となる。
JScrollPane oTabsSelectedComponent = (JScrollPane)(oMainPanelImp.cltHostFileList.getParent( ).getParent( ));
oMainPanelImp.ctpFileListTabs.setSelectedComponent(oTabsSelectedComponent);
if( client==null ){
System.out.println("if(client==null)");
PutMessage("if(client==null)\n");
return;
}
Pattern pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
System.out.println("vsTargetFile="+vsTargetFile+"; ");
if( vsTargetFile.compareTo("..")==0 ){
System.out.println("if( vsTargetFile.compareTo(..)==0 )");
vsTargetFile = "";
client.changeToParentDirectory();
}else{
if( vsTargetFile.compareTo("")!=0 ){
vsHostCurrent = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
}
// client.doCommand("CWD", vsHostCurrent);
client.changeWorkingDirectory(vsHostCurrent);
}
System.out.println(client.getReplyString());
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
String vsMsg = "Connection test => " + (lFTPConnection ? "OK" : "NG")+".";
System.out.println(vsMsg);
PutMessage(vsMsg+"\n");
vsHostCurrent = client.printWorkingDirectory();
oMainPanelImp.ctfHostFolder.setText(vsHostCurrent);
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
if( vsHostCurrent.compareTo("/")!=0 ){
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).addElement(
fvsPathListTag_Folder+"..");
}
SimpleDateFormat oSDF = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String vsElement = "";
String[] d1vsHostFile = new String[client.listFiles().length];
HashMap<String, String> da1PathListSets = new HashMap<String, String>( );
int i = 0;
for (FTPFile oFTPFile : client.listFiles()) {
String vsTimeStamp = fvsPathListTag_TimeStamp+oSDF.format(oFTPFile.getTimestamp().getTime());
String vsHostFile = oFTPFile.getName();
String vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsHostFile;
if( oFTPFile.isFile( ) ){
vsElement = fvsPathListTag_File;
}else if( oFTPFile.isDirectory( ) ){
vsElement = fvsPathListTag_Folder;
}
d1vsHostFile[i] = vsElement+vsHostFile;
da1PathListSets.put(d1vsHostFile[i], vsTimeStamp);
System.out.println(d1vsHostFile[i]);
System.out.println(vsTimeStamp);
i++;
}
FileSort(d1vsHostFile);
for ( i = 0; i<d1vsHostFile.length; ++i) {
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).addElement(
d1vsHostFile[i]);
String vsTimeStamp = da1PathListSets.get(d1vsHostFile[i]);
System.out.println(d1vsHostFile[i]);
System.out.println(vsTimeStamp);
char[] d1vcFileElement = d1vsHostFile[i].toCharArray();
System.out.print("Hex = ");
for(int j = 0; j<d1vcFileElement.length; j++){
int k = d1vcFileElement[j];
if( k<0 ){ k = 65536+k; }
// ↑2の補数の負の値を正の値に変換している.
System.out.print(Integer.toHexString(k)+"; ");
}
System.out.println("");
}
// return;
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:HostFileList.");
PutMessage("NumberFormatException:HostFileList.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:HostFileList.");
PutMessage("SocketException:HostFileList.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:HostFileList.");
PutMessage("FileNotFoundException:HostFileList.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:HostFileList.");
PutMessage("IOException:HostFileList.\n");
}
}
public void LocalFileList(String vsTargetFile){
System.out.println("LocalFileList( );");
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).removeAllElements( );
// JScrollPane には暗黙の子 JViewport が存在するようだ。
// つまり、この場合の JList の親は JViewport になり、
// JList の親の親が JScrollPane となる。
JScrollPane oTabsSelectedComponent = (JScrollPane)(oMainPanelImp.cltLocalFileList.getParent( ).getParent( ));
oMainPanelImp.ctpFileListTabs.setSelectedComponent(oTabsSelectedComponent);
Pattern pattern = Pattern.compile("( |\n)$");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
File oLocalCurrent = null;
System.out.println("vsTargetFile="+vsTargetFile+"; ");
try {
vsHostCurrent = "";
oLocalCurrent = new File(vsLocalCurrent,vsTargetFile);
vsLocalCurrent = oLocalCurrent.getCanonicalPath( );
if( vsTargetFile.compareTo("..")==0 ){
System.out.println("if( vsTargetFile.compareTo(..)==0 )");
vsTargetFile = "";
}
oMainPanelImp.ctfLocalFolder.setText(vsLocalCurrent);
System.out.println("vsLocalCurrent="+vsLocalCurrent+"; ");
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
System.out.println("IOException:LocalFileList.");
PutMessage("IOException:LocalFileList.\n");
oLocalCurrent = null;
}
if( oLocalCurrent!=null && oLocalCurrent.isDirectory( ) ){
pattern = Pattern.compile("^?(.:)(/|\\\\)$");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalCurrent);
System.out.println("pattern = Pattern.compile(^?(.:)(/|\\\\)$)");
if( ! matcher.find( ) ){
System.out.println("if( matcher.find( ) )");
// vsLocalCurrent = matcher.replaceAll("");
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).addElement(
fvsPathListTag_Folder+"..");
}
String vsElement = "";
String[] d1vsLocalFile = new String[oLocalCurrent.listFiles().length];
int i = 0;
for (File oFile : oLocalCurrent.listFiles( )) {
String vsLocalFile = oFile.getName();
String vsLocalPath = vsLocalCurrent+(vsLocalCurrent.endsWith("/") ? "" : "/")+vsLocalFile;
if(oFile.isFile()){
vsElement = fvsPathListTag_File;
}else if(oFile.isDirectory( )){
vsElement = fvsPathListTag_Folder;
}
d1vsLocalFile[i] = vsElement+vsLocalFile;
i++;
}
FileSort(d1vsLocalFile);
for ( i = 0; i<d1vsLocalFile.length; ++i) {
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).addElement(
d1vsLocalFile[i]);
System.out.println(d1vsLocalFile[i]);
char[] d1vcFileElement = d1vsLocalFile[i].toCharArray( );
System.out.print("Hex = ");
for(int j = 0; j<d1vcFileElement.length; j++){
int k = d1vcFileElement[j];
if( k<0 ){ k = 65536+k; }
// ↑2の補数の負の値を正の値に変換している.
System.out.print(Integer.toHexString(k)+"; ");
}
System.out.println("");
}
}
}
public void FileSort(String[] d1vsFile){
System.out.println("Arrays.sort( );");
Arrays.sort(d1vsFile, new Comparator<String>() {
@Override
public int compare(String vs0, String vs1) {
// このソートを Windows 的な File 名のソート順にカスタマイズしている.
String vs, vsAscTab = new String(Character.toChars(0x09));
vs = vs0;
vs0 = vs.toUpperCase( )+vsAscTab+vs;
vs = vs1;
vs1 = vs.toUpperCase( )+vsAscTab+vs;
return vs0.compareTo(vs1);
}
});
}
public void FTPDownloadTransfer( ){
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
String vsSaveBuf_HostFolder, vsSaveBuf_LocalFolder;
String vsHostPath, vsLocalPath;
vsSaveBuf_HostFolder = oMainPanelImp.ctfHostFolder.getText( );
vsSaveBuf_LocalFolder = oMainPanelImp.ctfLocalFolder.getText( );
int iListSize = ((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( );
for(int i = 0; i<iListSize; i++){
oMainPanelImp.ctfHostFolder.setText( (String)
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getElementAt(i));
oMainPanelImp.ctfLocalFolder.setText( (String)
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).getElementAt(i));
System.out.println("FTPDownloadTransfer( ): "+
"oMainPanelImp.ctfHostFolder.getText="+oMainPanelImp.ctfHostFolder.getText()+"; "+
"oMainPanelImp.ctfHostFolder.getText="+oMainPanelImp.ctfLocalFolder.getText()+"; "+
"");
FTPDownload( );
}
oMainPanelImp.ctfHostFolder.setText(vsSaveBuf_HostFolder);
oMainPanelImp.ctfLocalFolder.setText(vsSaveBuf_LocalFolder);
System.out.println("FTPDownloadTransfer Completed.");
}
public void FTPDownload( ){
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
matcher = null;
Pattern pattern = null;
String vsTargetFile = null;
String vsHostPath = null;
pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
String vsLocalPath = vsLocalCurrent;
pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
if( ! oMainPanelImp.cltHostFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltHostFileList.getSelectedValue();
pattern = Pattern.compile("^"+fvsPathListTag_File);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
pattern = Pattern.compile("^"+fvsPathListTag_Folder);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
if(matcher.find()){
System.out.println("if(matcher.find( ))");
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsTargetFile = "";
}
}else{
vsTargetFile = "";
}
if( vsTargetFile!=null ){
// vsLocalPath= vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsTargetFile;
System.out.println("FTPDownload: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPatht="+vsLocalPath+"; "+
"");
FTPDownloadFolder( vsTargetFile, vsHostCurrent, vsLocalCurrent );
System.out.println("FTPDownload Completed.");
PutMessage("FTPDownload Completed.\n");
try {
client.changeWorkingDirectory(vsHostCurrent);
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPDownload.");
PutMessage("NumberFormatException:FTPDownload.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPDownload.");
PutMessage("SocketException:FTPDownload.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPDownload.");
PutMessage("FileNotFoundException:FTPDownload.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPDownload.");
PutMessage("IOException:FTPDownload.\n");
}
}
LocalFileList("");
lFTPBreak = false; // true; //
}
public void FTPDownloadFolder( String vsTargetFile, String vsHostCurrent, String vsLocalCurrent ){
System.out.println("FTPDownloadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
if( vsTargetFile!=null && vsTargetFile.compareTo("")!=0 ){
FTPDownloadFile( vsTargetFile, vsHostCurrent, vsLocalCurrent);
}else{
String vsHostPath = null;
try {
client.changeWorkingDirectory(vsHostCurrent);
System.out.println("client.changeWorkingDirectory(vsHostCurrent)");
// FTPFile[] d1oFTPFile = client.listFiles();
for (FTPFile oFTPFile : client.listFiles()) {
if( lFTPBreak ){
break;
}
String vsHostFile = oFTPFile.getName();
if( oFTPFile.isFile( ) ){
FTPDownloadFile( vsHostFile, vsHostCurrent, vsLocalCurrent);
}else if( oFTPFile.isDirectory( ) ){
String vsLocalPath = vsLocalCurrent;
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsHostFile;
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsHostFile;
System.out.println("FTPDownloadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
File oLocalPath = new File(vsLocalPath);
if( ! oLocalPath.exists( ) ){
oLocalPath.mkdir();
}
FTPDownloadFolder( "", vsHostPath, vsLocalPath );
client.changeWorkingDirectory(vsHostCurrent);
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPDownloadFolder.");
PutMessage("NumberFormatException:FTPDownloadFolder.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPDownloadFolder.");
PutMessage("SocketException:FTPDownloadFolder.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPDownloadFolder.");
PutMessage("FileNotFoundException:FTPDownloadFolder.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPDownloadFolder.");
PutMessage("IOException:FTPDownloadFolder.\n");
}
}
}
public void FTPDownloadFile(String vsTargetFile,String vsHostCurrent,String vsLocalCurrent){
String vsMsg;
String vsLocalPath = null;
String vsHostPath = null;
FileOutputStream oFOS = null;
try{
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
vsLocalPath = vsLocalCurrent;
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
// client.changeWorkingDirectory(vsHostCurrent);
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsTargetFile;
System.out.println("FTPDownloadFile: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
lFTPTransfer_Binary = false; // true; //
if( 0==fvsFTPTransfer_Binary.compareTo(
(String)oMainPanelImp.ccbFTPFileDataType.getSelectedItem( )) ){
lFTPTransfer_Binary = true; // false; //
}
if(lFTPTransfer_Binary){
client.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("Transfer:Binary.");
}else{
client.setFileType(FTP.ASCII_FILE_TYPE);
System.out.println("Transfer:ASCII.");
}
// FTP Download.
oFOS = new FileOutputStream(vsLocalPath);
client.retrieveFile(vsHostPath, oFOS);
oFOS.close();
PutMessage("vsHostPath = "+vsHostPath+";"+"\n");
PutMessage("vsLocalPath = "+vsLocalPath+";"+"\n");
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
vsMsg = "FTPDownloadFile Completed:Connection => " + (lFTPConnection ? "OK" : "NG")+".";
System.out.println(vsMsg);
PutMessage(vsMsg+"\n");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPDownloadFile.");
PutMessage("NumberFormatException:FTPDownloadFile.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPDownloadFile.");
PutMessage("SocketException:FTPDownloadFile.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPDownloadFile.");
PutMessage("FileNotFoundException:FTPDownloadFile.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPDownloadFile.");
PutMessage("IOException:FTPDownloadFile.\n");
}
}
public void FTPUploadTransfer( ){
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
String vsSaveBuf_HostFolder, vsSaveBuf_LocalFolder;
String vsHostPath, vsLocalPath;
vsSaveBuf_HostFolder = oMainPanelImp.ctfHostFolder.getText( );
vsSaveBuf_LocalFolder = oMainPanelImp.ctfLocalFolder.getText( );
int iListSize = ((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( );
for(int i = 0; i<iListSize; i++){
oMainPanelImp.ctfHostFolder.setText( (String)
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getElementAt(i));
oMainPanelImp.ctfLocalFolder.setText( (String)
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).getElementAt(i));
FTPUpload( );
}
oMainPanelImp.ctfHostFolder.setText(vsSaveBuf_HostFolder);
oMainPanelImp.ctfLocalFolder.setText(vsSaveBuf_LocalFolder);
System.out.println("FTPUploadTransfer Completed.");
}
public void FTPUpload( ){
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
matcher = null;
Pattern pattern = null;
String vsTargetFile = null;
String vsHostPath = null;
pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
String vsLocalPath = vsLocalCurrent;
pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
try {
File oLocalCurrent;
File oLocalPath = new File(vsLocalPath);
if( oLocalPath.isFile( ) ){
vsTargetFile = oLocalPath.getName( );
vsLocalCurrent = oLocalPath.getParent( );
oLocalCurrent = new File(vsLocalCurrent);
vsLocalCurrent = oLocalCurrent.getCanonicalPath();
}else if( ! oMainPanelImp.cltLocalFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltLocalFileList.getSelectedValue();
pattern = Pattern.compile("^"+fvsPathListTag_File);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
pattern = Pattern.compile("^"+fvsPathListTag_Folder);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
if(matcher.find()){
System.out.println("if(matcher.find( ))");
vsLocalPath = vsLocalCurrent+(vsLocalCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsTargetFile = "";
}
}else{
vsTargetFile = "";
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
System.out.println("IOException:FTPUpload.");
PutMessage("IOException:FTPUpload.\n");
vsTargetFile = null;
}
if( vsTargetFile!=null ){
System.out.println("FTPUpload: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPatht="+vsLocalPath+"; "+
"");
FTPUploadFolder( vsTargetFile, vsHostCurrent, vsLocalCurrent );
System.out.println("FTPUpload Completed.");
PutMessage("FTPUpload Completed.\n");
try {
client.changeWorkingDirectory(vsHostCurrent);
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPUpload.");
PutMessage("NumberFormatException:FTPUpload.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPUpload.");
PutMessage("SocketException:FTPUpload.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPUpload.");
PutMessage("FileNotFoundException:FTPUpload.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPUpload.");
PutMessage("IOException:FTPUpload.\n");
}
}
HostFileList("");
lFTPBreak = false; // true; //
}
public void FTPUploadFolder( String vsTargetFile, String vsHostCurrent, String vsLocalCurrent ){
System.out.println("FTPUploadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
if( vsTargetFile!=null && vsTargetFile.compareTo("")!=0 ){
FTPUploadFile( vsTargetFile, vsHostCurrent, vsLocalCurrent);
}else{
String vsHostPath = null;
try {
File oLocalCurrent = new File(vsLocalCurrent);
System.out.println("oLocalCurrent = new File(vsLocalCurrent)");
for (File oFile : oLocalCurrent.listFiles()) {
if( lFTPBreak ){
break;
}
String vsLocalFile = oFile.getName();
if( oFile.isFile( ) ){
FTPUploadFile( vsLocalFile, vsHostCurrent, vsLocalCurrent);
}else if( oFile.isDirectory( ) ){
String vsLocalPath = vsLocalCurrent;
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsLocalFile;
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsLocalFile;
System.out.println("FTPUploadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
try {
// client.changeWorkingDirectory(vsHostPath);
System.out.println("client.makeDirectory(vsHostPath).");
client.makeDirectory(vsHostPath);
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPUploadFolder");
PutMessage("IOException:FTPUploadFolder.\n");
}
FTPUploadFolder( "", vsHostPath, vsLocalPath );
client.changeWorkingDirectory(vsHostCurrent);
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPUploadFolder.");
PutMessage("NumberFormatException:FTPUploadFolder.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPUploadFolder.");
PutMessage("SocketException:FTPUploadFolder.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPUploadFolder.");
PutMessage("FileNotFoundException:FTPUploadFolder.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPUploadFolder.");
PutMessage("IOException:FTPUploadFolder.\n");
}
}
}
public void FTPUploadFile(String vsTargetFile,String vsHostCurrent,String vsLocalCurrent){
String vsMsg;
String vsLocalPath = null;
String vsHostPath = null;
FileInputStream oFIS = null;
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
vsLocalPath = vsLocalCurrent;
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsTargetFile;
System.out.println("FTPUploadFile: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
lFTPTransfer_Binary = false; // true; //
if( 0==fvsFTPTransfer_Binary.compareTo(
(String)oMainPanelImp.ccbFTPFileDataType.getSelectedItem( )) ){
lFTPTransfer_Binary = true; // false; //
}
try{
if(lFTPTransfer_Binary){
client.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("Transfer:Binary.");
}else{
client.setFileType(FTP.ASCII_FILE_TYPE);
System.out.println("Transfer:ASCII.");
}
// FTP Upload.
oFIS = new FileInputStream(vsLocalPath);
client.storeFile(vsHostPath, oFIS);
oFIS.close();
PutMessage("FTPUploadFile: "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"\n");
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
vsMsg = "FTPUploadFile Completed:Connection = " + (lFTPConnection ? "OK" : "NG")+".";
System.out.println(vsMsg);
PutMessage(vsMsg+"\n");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPUploadFile.");
PutMessage("NumberFormatException:FTPUploadFile.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPUploadFile.");
PutMessage("SocketException:FTPUploadFile.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPUploadFile.");
PutMessage("FileNotFoundException:FTPUploadFile.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPUploadFile.");
PutMessage("IOException:FTPUploadFile.\n");
}
}
class MainPanelImplementationObj extends MainPanelDesign {
long ilDoubleClickedIntervalMax = 250; // 350; 300;
// volatile:最適化の抑制.
volatile byte ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 0;
Thread oThread_HostFileList_CbtMouseMouseDoubleClicked;
Runnable oRunner_HostFileList_CbtMouseMouseDoubleClicked;
// volatile:最適化の抑制.
volatile byte ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 0;
Thread oThread_LocalFileList_CbtMouseMouseDoubleClicked;
Runnable oRunner_LocalFileList_CbtMouseMouseDoubleClicked;
MainPanelImplementationObj(){
super( );
oThread_HostFileList_CbtMouseMouseDoubleClicked = new Thread(
oRunner_HostFileList_CbtMouseMouseDoubleClicked = new Runnable( ) {
@Override
public synchronized void run() {
System.out.println("run.");
boolean lInterrupted = false; // true; //
while(true){
try {
wait( );
// ↑メソッドを synchronized 指定するか、
// synchronized(自分のインスタンス) ブロックで囲うかしないと
// 実行時に「IllegalMonitorStateException」が発生する。
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("wait:End.");
lInterrupted = false; // true; //
try {
Thread.sleep(ilDoubleClickedIntervalMax);
} catch (InterruptedException e) {
// e.printStackTrace();
System.out.println("sleep:InterruptedException.");
lInterrupted = true; // false; //
}
System.out.println("sleep:End.");
if( ! lInterrupted &&
ibCnt_HostFileList_CbtMouseMouseDoubleClicked==2 ){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 0;
HostFileList_CbtMouseMouseClicked( );
}
}
}
}
);
oThread_HostFileList_CbtMouseMouseDoubleClicked.start( );
oThread_LocalFileList_CbtMouseMouseDoubleClicked = new Thread(
oRunner_LocalFileList_CbtMouseMouseDoubleClicked = new Runnable( ) {
@Override
public synchronized void run() {
System.out.println("run.");
boolean lInterrupted = false; // true; //
while(true){
try {
wait( );
// ↑メソッドを synchronized 指定するか、
// synchronized(自分のインスタンス) ブロックで囲うかしないと
// 実行時に「IllegalMonitorStateException」が発生する。
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("wait:End.");
lInterrupted = false; // true; //
try {
Thread.sleep(ilDoubleClickedIntervalMax);
} catch (InterruptedException e) {
// e.printStackTrace();
System.out.println("sleep:InterruptedException.");
lInterrupted = true; // false; //
}
System.out.println("sleep:End.");
if( ! lInterrupted &&
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked==2 ){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 0;
LocalFileList_CbtMouseMouseClicked( );
}
}
}
}
);
oThread_LocalFileList_CbtMouseMouseDoubleClicked.start( );
}
@Override
void HostLogin_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostLogin_CbtMouseMouseReleased.");
oMainApp.FTPLogin( );
}
@Override
void HostLogout_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostLogout_CbtMouseMouseReleased.");
oMainApp.FTPLogout( );
}
@Override
void FTPFileList_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPFileList_CbtMouseMouseReleased.");
Pattern pattern = Pattern.compile("( |\n)$");
vsHostFolder = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostFolder);
vsHostFolder = matcher.replaceAll("");
JScrollPane oTabsSelectedComponent = (JScrollPane)oMainPanelImp.ctpFileListTabs.getSelectedComponent( );
System.out.println("oTabsSelectedComponent = "+oTabsSelectedComponent);
System.out.println("oTabsSelectedComponent.getViewport() = "+oTabsSelectedComponent.getViewport());
System.out.println("cltLocalFileList.getParent() = "+oMainPanelImp.cltLocalFileList.getParent());
System.out.println("cltLocalFileList.getParent().getParent() = "+oMainPanelImp.cltLocalFileList.getParent().getParent());
// JScrollPane には暗黙の子 JViewport が存在し、
// 「JScrollPane.getViewport( ) 」で(暗黙の子) JViewport のインスタンスを取得できる。
// つまり、この場合の JList の親は JViewport となる。
// ちなみに、この場合の JList の親の親が JScrollPane となる。
if( lFTPConnection &&
oTabsSelectedComponent.getViewport()==oMainPanelImp.cltHostFileList.getParent( ) ){
//
}
if( oTabsSelectedComponent.getViewport()==oMainPanelImp.cltLocalFileList.getParent( ) ){
//
}
}
@Override
void FTPDownload_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPDownload_CbtMouseMouseReleased.");
if( 0==((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( ) ){
FTPDownload( );
}else{
FTPDownloadTransfer( );
}
}
@Override
void FTPUpload_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPUpload_CbtMouseMouseReleased.");
if( 0==((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( ) ){
FTPUpload( );
}else{
FTPUploadTransfer( );
}
}
void HostFileList_CbtMouseMouseClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CbtMouseMouseClicked.");
}
void HostFileList_CbtMouseMouseDoubleClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CbtMouseMouseDoubleClicked.");
Pattern pattern = null;
String vsTargetFile = null;
if( ! oMainPanelImp.cltHostFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltHostFileList.getSelectedValue();
pattern = Pattern.compile("^("+fvsReg_PathListTag_Folder+")");
matcher = pattern.matcher(vsTargetFile);
if(matcher.find()){
vsTargetFile = matcher.replaceAll("");
System.out.println("vsTargetFile = "+vsTargetFile+"; ");
HostFileList(vsTargetFile);
}
}else{
vsTargetFile = null;
PutMessage("HostFileList で項目が選択せれていません.\n");
}
}
@Override
void HostFileList_CbtNativeMouseMousePressed(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CbtNativeMouseMousePressed");
if(oThread_HostFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.TIMED_WAITING){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 3;
oThread_HostFileList_CbtMouseMouseDoubleClicked.interrupt();
}else{
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 1;
}
System.out.println("ibCnt_HostFileList_CbtMouseMouseDoubleClicked="+ibCnt_HostFileList_CbtMouseMouseDoubleClicked+"; ");
}
@Override
void HostFileList_CltNativeMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CltNativeMouseMouseReleased.");
if(ibCnt_HostFileList_CbtMouseMouseDoubleClicked==3){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 0;
HostFileList_CbtMouseMouseDoubleClicked( );
}else if(oThread_HostFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.WAITING){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 2;
synchronized(oRunner_HostFileList_CbtMouseMouseDoubleClicked) {
oRunner_HostFileList_CbtMouseMouseDoubleClicked.notify();
// ↑ synchronized(自分のインスタンス) ブロックで囲わないとないと
// 実行時に「IllegalMonitorStateException」が発生する。
// ここ(this)は他人なので、ここのメソッドを synchronized 指定してもダメ。
}
}
System.out.println("ibCnt_HostFileList_CbtMouseMouseDoubleClicked="+ibCnt_HostFileList_CbtMouseMouseDoubleClicked+"; ");
}
void LocalFileList_CbtMouseMouseClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CbtMouseMouseClicked.");
}
void LocalFileList_CbtMouseMouseDoubleClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CbtMouseMouseDoubleClicked.");
Pattern pattern = null;
String vsTargetFile = null;
if( ! oMainPanelImp.cltLocalFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltLocalFileList.getSelectedValue();
pattern = Pattern.compile("^("+fvsReg_PathListTag_Folder+")");
matcher = pattern.matcher(vsTargetFile);
if(matcher.find()){
vsTargetFile = matcher.replaceAll("");
System.out.println("vsTargetFile = "+vsTargetFile+"; ");
LocalFileList(vsTargetFile);
}
}else{
vsTargetFile = null;
PutMessage("LocalFileList で項目が選択せれていません.\n");
}
}
@Override
void LocalFileList_CbtNativeMouseMousePressed(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CbtNativeMouseMousePressed");
if(oThread_LocalFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.TIMED_WAITING){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 3;
oThread_LocalFileList_CbtMouseMouseDoubleClicked.interrupt();
}else{
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 1;
}
System.out.println("ibCnt_LocalFileList_CbtMouseMouseDoubleClicked="+ibCnt_LocalFileList_CbtMouseMouseDoubleClicked+"; ");
}
@Override
void LocalFileList_CltNativeMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CltNativeMouseMouseReleased");
if(ibCnt_LocalFileList_CbtMouseMouseDoubleClicked==3){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 0;
LocalFileList_CbtMouseMouseDoubleClicked( );
}else if(oThread_LocalFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.WAITING){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 2;
synchronized(oRunner_LocalFileList_CbtMouseMouseDoubleClicked) {
oRunner_LocalFileList_CbtMouseMouseDoubleClicked.notify();
// ↑ synchronized(自分のインスタンス) ブロックで囲わないとないと
// 実行時に「IllegalMonitorStateException」が発生する。
// ここ(this)は他人なので、ここのメソッドを synchronized 指定してもダメ。
}
}
System.out.println("ibCnt_LocalFileList_CbtMouseMouseDoubleClicked="+ibCnt_LocalFileList_CbtMouseMouseDoubleClicked+"; ");
}
@Override
void SetupFileList_HostFolder_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:SetupFileList_HostFolder_CbtMouseMouseReleased.");
HostFileList("");
}
@Override
void SetupFileList_LocalFolder_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:SetupFileList_LocalFolder_CbtMouseMouseReleased.");
LocalFileList("");
}
@Override
void FTPBreak_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPBreak_CbtMouseMouseReleased.");
lFTPBreak = true; // false; //
}
@Override
void TransferListEntry_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:TransferListEntry_CbtMouseMouseReleased.");
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).addElement(
ctfHostFolder.getText( ));
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).addElement(
ctfLocalFolder.getText( ));
}
@Override
void TransferListDelete_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:TransferListDelete_CbtMouseMouseReleased.");
int iSelectedIndex = -1;
JScrollPane oTabsSelectedComponent = (JScrollPane)oMainPanelImp.ctpTransferListTabs.getSelectedComponent( );
// JScrollPane には暗黙の子 JViewport が存在し、
// 「JScrollPane.getViewport( ) 」で(暗黙の子) JViewport のインスタンスを取得できる。
// つまり、この場合の JList の親は JViewport となる。
// ちなみに、この場合の JList の親の親が JScrollPane となる。
if( oTabsSelectedComponent.getViewport( )==oMainPanelImp.cltHostTransferList.getParent( ) ){
System.out.println("if(oTabsSelectedComponent.getViewport( )==cltHostTransferList.getParent( )).");
if( oMainPanelImp.cltHostTransferList.isSelectionEmpty( ) ){
PutMessage("cltHostTransferList:表示されているタブに選択されている項目がありません。\n");
}else{
iSelectedIndex = oMainPanelImp.cltHostTransferList.getSelectedIndex( );
}
}
if( oTabsSelectedComponent.getViewport( )==oMainPanelImp.cltLocalTransferList.getParent( ) ){
System.out.println("(oTabsSelectedComponent.getViewport( )==cltLocalTransferList.getParent( )).");
if( oMainPanelImp.cltLocalTransferList.isSelectionEmpty( ) ){
PutMessage("cltLocalTransferList:表示されているタブに選択されている項目がありません。\n");
}else{
iSelectedIndex = oMainPanelImp.cltLocalTransferList.getSelectedIndex( );
}
}
System.out.println("iSelectedIndex="+iSelectedIndex+"; ");
if( 0<=iSelectedIndex ){
System.out.println("if( 0<=iSelectedIndex )");
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).remove(iSelectedIndex);
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).remove(iSelectedIndex);
}
}
}
static class MainAppFrameObj extends JFrame implements Runnable {
// JApplet oApplet;
Thread oAppThread;
public MainAppFrameObj( ) {
super("Application frame.");
//setVisible(false);
System.out.println("Construct:Application frame window.");
// oApplet = oEntApplet; // new JAppletcation();
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent event){
// ユーザーがウインドウを閉じようとした時].
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosing.");
oMainApp.FTPLogout();
Close();
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowClosed(WindowEvent event){
// ウインドウが閉じた時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosed.");
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowDeiconified(WindowEvent event){
// ウィンドウが最小化された状態から通常の状態に変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowDeiconified.");
oMainApp.repaint();
}
}
}
);
addComponentListener(
new ComponentAdapter(){
public void componentResized(ComponentEvent event){
// コンポーネントのサイズが変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("ComponentEvent:componentResized.");
System.out.println("MainAppFrameObj: "+
"width="+Integer.toString(MainAppFrameObj.this.getSize( ).width)+"; "+
"Height="+Integer.toString(MainAppFrameObj.this.getSize( ).height)+"; "+
"");
oMainApp.repaint();
}
}
}
);
getContentPane().add(oMainApp,"Center");
oAppThread= new Thread(this);
}
public synchronized void setPreSize(Dimension oSize){
// dispose();
getContentPane().setPreferredSize(oSize);
pack();
setVisible(true);
requestFocus();
}
public synchronized void run(){
System.out.println("Open:Application frame window.");
oMainApp.init();
oMainApp.start();
oMainApp.repaint();
try{
wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
oMainApp.stop();
oMainApp.destroy();
oAppThread = null;
}
public synchronized void Close(){
System.out.println("Close:Application frame window.");
dispose();
notify();
}
}
}
|
|
|
<Number>: [00000973]
<Date>: 2015/12/26 10:18:56
<Title>:
<Name>: amanojaku@管理人
|
|
|
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.dyno.visual.swing.layouts.Bilateral;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class MainPanelDesign extends JPanel {
private static final long serialVersionUID = 1L;
private JButton cbtHostLogin;
private JButton cbtHostLogout;
private JButton cbtFTPUpload;
private JButton cbtFTPBreak;
private JButton cbtFTPDownload;
private JButton cbtSetupFileList_HostFolder;
private JButton cbtSetupFileList_LocalFolder;
private JButton cbtTransferListDelete;
private JButton cbtTransferListEntry;
JTextField ctfHostUserName;
JTextField ctfHostName;
JPasswordField cpfHostPassword;
JTextField ctfHostFolder;
JTextField ctfLocalFolder;
JTextField ctfHostPortNum;
JTextArea ctaMessage;
JList cltHostFileList;
JList cltLocalFileList;
JComboBox ccbFTPFileDataType;
JTabbedPane ctpFileListTabs;
JCheckBox cckHostPASVMode;
JComboBox ccbHostEncode;
JPanel cpnFTPSetting;
JTabbedPane ctpBaseTabs;
JList cltHostTransferList;
JList cltLocalTransferList;
JTabbedPane ctpTransferListTabs;
private JLabel jLabel2;
private JLabel jLabel6;
private JLabel jLabel5;
private JLabel jLabel0;
private JLabel jLabel1;
private JLabel jLabel7;
private JLabel jLabel9;
private JScrollPane jScrollPane0;
private JScrollPane jScrollPane1;
private JScrollPane jScrollPane2;
private JScrollPane jScrollPane3;
private JScrollPane jScrollPane4;
private JLabel jLabel3;
public MainPanelDesign() {
initComponents();
}
private void initComponents() {
setMinimumSize(new Dimension(479, 400));
setPreferredSize(new Dimension(479, 400));
setLayout(new GroupLayout());
add(getCbtHostLogin(), new Constraints(new Leading(10, 72, 75, 282), new Leading(254, 12, 12)));
add(getCbtHostLogout(), new Constraints(new Leading(90, 10, 10), new Leading(254, 12, 12)));
add(getJLabel7(), new Constraints(new Leading(289, 12, 12), new Leading(195, 12, 12)));
add(getCtpFileListTabs(), new Constraints(new Leading(289, 266, 10, 10), new Bilateral(217, 12, 69)));
add(getCbtFTPDownload(), new Constraints(new Leading(10, 12, 12), new Leading(292, 12, 12)));
add(getCbtFTPBreak(), new Constraints(new Leading(191, 10, 10), new Leading(292, 12, 12)));
add(getCbtFTPUpload(), new Constraints(new Leading(109, 10, 10), new Leading(292, 12, 12)));
add(getCcbFTPFileDataType(), new Constraints(new Leading(135, 12, 12), new Leading(330, 12, 12)));
add(getCtpBaseTabs(), new Constraints(new Leading(8, 271, 23, 23), new Leading(7, 237, 10, 10)));
add(getCbtTransferListDelete(), new Constraints(new Leading(443, 10, 10), new Leading(10, 10, 10)));
add(getCbtTransferListEntry(), new Constraints(new Leading(373, 12, 12), new Leading(10, 87, 177)));
add(getJLabel3(), new Constraints(new Leading(289, 12, 12), new Leading(15, 87, 177)));
add(getCtpTransferListTabs(), new Constraints(new Bilateral(289, 12, 57), new Leading(46, 139, 10, 10)));
add(getJLabel9(), new Constraints(new Leading(10, 12, 12), new Leading(333, 18, 12, 12)));
add(getCbtSetupFileList_HostFolder(), new Constraints(new Leading(8, 12, 12), new Leading(367, 12, 12)));
add(getCtfHostFolder(), new Constraints(new Leading(135, 144, 12, 12), new Leading(370, 12, 12)));
add(getCtfLocalFolder(), new Constraints(new Leading(135, 144, 12, 12), new Leading(408, 12, 12)));
add(getCbtSetupFileList_LocalFolder(), new Constraints(new Leading(8, 12, 12), new Leading(405, 12, 12)));
setSize(565, 487);
}
private JLabel getJLabel3() {
if (jLabel3 == null) {
jLabel3 = new JLabel();
jLabel3.setText("TransferList");
}
return jLabel3;
}
private JScrollPane getJScrollPane4() {
if (jScrollPane4 == null) {
jScrollPane4 = new JScrollPane();
jScrollPane4.setViewportView(getCltLocalTransferList());
}
return jScrollPane4;
}
private JList getCltLocalTransferList() {
if (cltLocalTransferList == null) {
cltLocalTransferList = new JList();
DefaultListModel listModel = new DefaultListModel();
cltLocalTransferList.setModel(listModel);
}
return cltLocalTransferList;
}
private JScrollPane getJScrollPane3() {
if (jScrollPane3 == null) {
jScrollPane3 = new JScrollPane();
jScrollPane3.setViewportView(getCltHostTransferList());
}
return jScrollPane3;
}
private JList getCltHostTransferList() {
if (cltHostTransferList == null) {
cltHostTransferList = new JList();
DefaultListModel listModel = new DefaultListModel();
cltHostTransferList.setModel(listModel);
}
return cltHostTransferList;
}
private JButton getCbtTransferListEntry() {
if (cbtTransferListEntry == null) {
cbtTransferListEntry = new JButton();
cbtTransferListEntry.setText("Entry");
cbtTransferListEntry.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
TransferListEntry_CbtMouseMouseReleased(event);
}
});
}
return cbtTransferListEntry;
}
private JButton getCbtTransferListDelete() {
if (cbtTransferListDelete == null) {
cbtTransferListDelete = new JButton();
cbtTransferListDelete.setText("Delete");
cbtTransferListDelete.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
TransferListDelete_CbtMouseMouseReleased(event);
}
});
}
return cbtTransferListDelete;
}
private JTabbedPane getCtpTransferListTabs() {
if (ctpTransferListTabs == null) {
ctpTransferListTabs = new JTabbedPane();
ctpTransferListTabs.addTab("Host", getJScrollPane3());
ctpTransferListTabs.addTab("Local", getJScrollPane4());
}
return ctpTransferListTabs;
}
private JTabbedPane getCtpBaseTabs() {
if (ctpBaseTabs == null) {
ctpBaseTabs = new JTabbedPane();
ctpBaseTabs.addTab("FTP", getCpnFTPSetting());
ctpBaseTabs.addTab("Message", getJScrollPane0());
}
return ctpBaseTabs;
}
private JPanel getCpnFTPSetting() {
if (cpnFTPSetting == null) {
cpnFTPSetting = new JPanel();
cpnFTPSetting.setLayout(new GroupLayout());
cpnFTPSetting.add(getJLabel1(), new Constraints(new Leading(7, 12, 12), new Leading(42, 134, 134)));
cpnFTPSetting.add(getJLabel2(), new Constraints(new Leading(7, 12, 12), new Leading(176, 12, 12)));
cpnFTPSetting.add(getJLabel6(), new Constraints(new Leading(7, 12, 12), new Leading(140, 12, 12)));
cpnFTPSetting.add(getJLabel5(), new Constraints(new Leading(7, 12, 12), new Leading(74, 12, 12)));
cpnFTPSetting.add(getCckHostPASVMode(), new Constraints(new Leading(7, 12, 12), new Leading(8, 12, 12)));
cpnFTPSetting.add(getCtfHostName(), new Constraints(new Leading(96, 142, 10, 10), new Leading(72, 12, 12)));
cpnFTPSetting.add(getCpfHostPassword(), new Constraints(new Leading(97, 140, 12, 12), new Leading(172, 12, 12)));
cpnFTPSetting.add(getCcbHostEncode(), new Constraints(new Leading(97, 12, 12), new Leading(38, 12, 12)));
cpnFTPSetting.add(getCtfHostPortNum(), new Constraints(new Leading(96, 142, 12, 12), new Leading(104, 12, 12)));
cpnFTPSetting.add(getJLabel0(), new Constraints(new Leading(7, 12, 12), new Leading(106, 12, 12)));
cpnFTPSetting.add(getCtfHostUserName(), new Constraints(new Leading(97, 142, 12, 12), new Leading(138, 12, 12)));
}
return cpnFTPSetting;
}
private JButton getCbtFTPBreak() {
if (cbtFTPBreak == null) {
cbtFTPBreak = new JButton();
cbtFTPBreak.setText("Break");
cbtFTPBreak.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPBreak_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPBreak;
}
private JComboBox getCcbHostEncode() {
if (ccbHostEncode == null) {
ccbHostEncode = new JComboBox();
ccbHostEncode.setModel(new DefaultComboBoxModel(new Object[] { "UTF-8", "Windows", "EUC-JP", "ASCII" }));
ccbHostEncode.setDoubleBuffered(false);
ccbHostEncode.setBorder(null);
}
return ccbHostEncode;
}
private JButton getCbtSetupFileList_HostFolder() {
if (cbtSetupFileList_HostFolder == null) {
cbtSetupFileList_HostFolder = new JButton();
cbtSetupFileList_HostFolder.setText("HostFolder >");
cbtSetupFileList_HostFolder.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
SetupFileList_HostFolder_CbtMouseMouseReleased(event);
}
});
}
return cbtSetupFileList_HostFolder;
}
private JButton getCbtSetupFileList_LocalFolder() {
if (cbtSetupFileList_LocalFolder == null) {
cbtSetupFileList_LocalFolder = new JButton();
cbtSetupFileList_LocalFolder.setText("LocalFolder >");
cbtSetupFileList_LocalFolder.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
SetupFileList_LocalFolder_CbtMouseMouseReleased(event);
}
});
}
return cbtSetupFileList_LocalFolder;
}
private JButton getCbtFTPUpload() {
if (cbtFTPUpload == null) {
cbtFTPUpload = new JButton();
cbtFTPUpload.setText("Upload");
cbtFTPUpload.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPUpload_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPUpload;
}
private JComboBox getCcbFTPFileDataType() {
if (ccbFTPFileDataType == null) {
ccbFTPFileDataType = new JComboBox();
ccbFTPFileDataType.setModel(new DefaultComboBoxModel(new Object[] { "Binary", "ASCII" }));
ccbFTPFileDataType.setDoubleBuffered(false);
ccbFTPFileDataType.setBorder(null);
}
return ccbFTPFileDataType;
}
private JLabel getJLabel9() {
if (jLabel9 == null) {
jLabel9 = new JLabel();
jLabel9.setText("FileDtata");
}
return jLabel9;
}
private JCheckBox getCckHostPASVMode() {
if (cckHostPASVMode == null) {
cckHostPASVMode = new JCheckBox();
cckHostPASVMode.setSelected(true);
cckHostPASVMode.setText("PASVMode");
}
return cckHostPASVMode;
}
private JList getCltLocalFileList() {
if (cltLocalFileList == null) {
cltLocalFileList = new JList();
cltLocalFileList.setBackground(Color.white);
DefaultListModel listModel = new DefaultListModel();
cltLocalFileList.setModel(listModel);
cltLocalFileList.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
LocalFileList_CbtNativeMouseMousePressed(event);
}
public void mouseReleased(MouseEvent event) {
LocalFileList_CltNativeMouseMouseReleased(event);
}
});
}
return cltLocalFileList;
}
private JLabel getJLabel7() {
if (jLabel7 == null) {
jLabel7 = new JLabel();
jLabel7.setText("FileList");
}
return jLabel7;
}
private JTabbedPane getCtpFileListTabs() {
if (ctpFileListTabs == null) {
ctpFileListTabs = new JTabbedPane();
ctpFileListTabs.addTab("Host", getJScrollPane1());
ctpFileListTabs.addTab("Local", getJScrollPane2());
}
return ctpFileListTabs;
}
private JScrollPane getJScrollPane2() {
if (jScrollPane2 == null) {
jScrollPane2 = new JScrollPane();
jScrollPane2.setBackground(Color.white);
jScrollPane2.setViewportView(getCltLocalFileList());
}
return jScrollPane2;
}
private JList getJList0() {
if (cltLocalFileList == null) {
cltLocalFileList = new JList();
DefaultListModel listModel = new DefaultListModel();
listModel.addElement("item0");
listModel.addElement("item1");
listModel.addElement("item2");
listModel.addElement("item3");
cltLocalFileList.setModel(listModel);
}
return cltLocalFileList;
}
private JLabel getJLabel1() {
if (jLabel1 == null) {
jLabel1 = new JLabel();
jLabel1.setText("HostEncode");
}
return jLabel1;
}
private JButton getCbtFTPDownload() {
if (cbtFTPDownload == null) {
cbtFTPDownload = new JButton();
cbtFTPDownload.setText("Download");
cbtFTPDownload.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPDownload_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPDownload;
}
private JScrollPane getJScrollPane1() {
if (jScrollPane1 == null) {
jScrollPane1 = new JScrollPane();
jScrollPane1.setEnabled(false);
jScrollPane1.setViewportView(getCltHostFileList());
}
return jScrollPane1;
}
private JList getCltHostFileList() {
if (cltHostFileList == null) {
cltHostFileList = new JList();
DefaultListModel listModel = new DefaultListModel();
cltHostFileList.setModel(listModel);
cltHostFileList.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
HostFileList_CbtNativeMouseMousePressed(event);
}
public void mouseReleased(MouseEvent event) {
HostFileList_CltNativeMouseMouseReleased(event);
}
});
}
return cltHostFileList;
}
private JScrollPane getJScrollPane0() {
if (jScrollPane0 == null) {
jScrollPane0 = new JScrollPane();
jScrollPane0.setViewportView(getCtaMessage());
}
return jScrollPane0;
}
private JTextArea getCtaMessage() {
if (ctaMessage == null) {
ctaMessage = new JTextArea();
}
return ctaMessage;
}
private JTextField getCtfHostPortNum() {
if (ctfHostPortNum == null) {
ctfHostPortNum = new JTextField();
}
return ctfHostPortNum;
}
private JLabel getJLabel0() {
if (jLabel0 == null) {
jLabel0 = new JLabel();
jLabel0.setText("PortNo");
}
return jLabel0;
}
private JLabel getJLabel5() {
if (jLabel5 == null) {
jLabel5 = new JLabel();
jLabel5.setText("HostName");
}
return jLabel5;
}
private JLabel getJLabel6() {
if (jLabel6 == null) {
jLabel6 = new JLabel();
jLabel6.setText("UserName");
}
return jLabel6;
}
private JTextField getCtfLocalFolder() {
if (ctfLocalFolder == null) {
ctfLocalFolder = new JTextField();
ctfLocalFolder.setBackground(Color.white);
ctfLocalFolder.setText("");
}
return ctfLocalFolder;
}
private JButton getCbtHostLogin() {
if (cbtHostLogin == null) {
cbtHostLogin = new JButton();
cbtHostLogin.setText("Login");
cbtHostLogin.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
HostLogin_CbtMouseMouseReleased(event);
}
});
}
return cbtHostLogin;
}
private JTextField getCtfHostFolder() {
if (ctfHostFolder == null) {
ctfHostFolder = new JTextField();
ctfHostFolder.setBackground(Color.white);
}
return ctfHostFolder;
}
private JButton getCbtHostLogout() {
if (cbtHostLogout == null) {
cbtHostLogout = new JButton();
cbtHostLogout.setText("Logout");
cbtHostLogout.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
HostLogout_CbtMouseMouseReleased(event);
}
});
}
return cbtHostLogout;
}
private JLabel getJLabel2() {
if (jLabel2 == null) {
jLabel2 = new JLabel();
jLabel2.setText("Password");
}
return jLabel2;
}
private JTextField getCtfHostUserName() {
if (ctfHostUserName == null) {
ctfHostUserName = new JTextField();
}
return ctfHostUserName;
}
private JTextField getCtfHostName() {
if (ctfHostName == null) {
ctfHostName = new JTextField();
}
return ctfHostName;
}
private JPasswordField getCpfHostPassword() {
if (cpfHostPassword == null) {
cpfHostPassword = new JPasswordField();
cpfHostPassword.setEchoChar('*');
}
return cpfHostPassword;
}
void HostLogout_CbtMouseMouseReleased(MouseEvent event) {
}
void HostLogin_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPFileList_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPDownload_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPUpload_CbtMouseMouseReleased(MouseEvent event) {
}
void HostFileList_CbtNativeMouseMousePressed(MouseEvent event) {
}
void HostFileList_CltNativeMouseMouseReleased(MouseEvent event) {
}
void LocalFileList_CbtNativeMouseMousePressed(MouseEvent event) {
}
void LocalFileList_CltNativeMouseMouseReleased(MouseEvent event) {
}
void SetupFileList_HostFolder_CbtMouseMouseReleased(MouseEvent event) {
}
void SetupFileList_LocalFolder_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPBreak_CbtMouseMouseReleased(MouseEvent event) {
}
void TransferListEntry_CbtMouseMouseReleased(MouseEvent event) {
}
void TransferListDelete_CbtMouseMouseReleased(MouseEvent event) {
}
}
|
|
|
<Number>: [00000974]
<Date>: 2015/12/31 17:58:01
<Title>:
<Name>: amanojaku@管理人
|
|
|
|
|
<Number>: [00000976]
<Date>: 2016/01/03 21:59:32
<Title>:
<Name>: amanojaku@管理人
|
|
|
今回は複数のフォルダーの単位のファイルの Synchronize(同期) です(子フォルダーに対する再帰的な処理)。
TransferList にデータが存在する場合は「HostFolder、LocalFolder」のデータは無視され、TransferList にデータが存在しない場合は「HostFolder、LocalFolder」のデータで処理される。
ファイルを Synchronize(同期) したい場合は LocalFolder にはファイル名は含めずにフォルダー名だけにして下さい。
処理の実行中に[Break]ボタンをクリックしても その時点でマウス・イベントが発生しなかったが、時間のかかる処理を別の Thread として実行させてやることで その時点で[Break]ボタンのマウス・イベントを処理できるようにしている。
マウスのダブル・クリック検出用プログラムを変更、少しばかり冗長的でスマートとは言えないが、以前のように力技でゴリ押していたよりはマシ。
(Android OS のバージョンによって違うかもしれないが) Android端末にファイルをコピーすると その時点のタイム・スタンプに変更されてしまうが、それはファイルの Synchronize(同期) の障害となり、ファイルのムダなダウンロードが発生してしまう。
それを回避するためには『Local側から Android側にアップロードした時に、(ファイルのタイム・スタンプではなく実際の)ファイルの製作 年月日が Local側と Android側のファイルが同じか古い』事がチェックできるように それらのファイルのタイム・スタンプを別途 保存してしてやれば良い(ここでは便宜的に それを SnapShot と呼ぶ)。
SnapShot のファイル名は".FTPConnect.SnapShot"としており、対象となる各フォルダー内(子フォルダー内にも)に作成される(一旦 Local側で作成し Host側(Server側) にアップロードしている)。
このプログラムは あくまでも Android用での使用を前提としている(ファイル転送モードに Auto が無いので他の FTP Server は想定外となる)。
現状で『「Host側(Server側)、Local側」の双方のファイルが完全に Synchronize(同期) されている』事が判っているなら SnapShot の[Make]を実行することにより、ムダなファイルのダウンロードを回避できる。
手動で Synchronize(同期) してから SnapShot の[Make]を実行してやると言う手もある。
《参考》
『Java2 FTP Connect 9』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+00000972-00000972&
『Java2 MouseDoubleClicked 1』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+0000096B.+&
クラスパスの設定
http://www.hot-surprise.org/IntroEclipse/Operation/N01/3_3.html
FTP に関するプログラムは下記ページを参照.
JavaによるFTP転送サンプル | Pa-kun plus idea
http://web.plus-idea.net/2011/06/javaftp/
> client.setControlEncoding("MS932");
↑ Host 側のキャラクター・セットを設定すれば良いと思われる。
Windows 系では「CP932」(Microsoft Windows CodePage 932)、UNIX 系では「UTF-8、EUC-JP(日本の場合)」などが大半のようだ、Android は「UTF-8」となる。
厳密に言うと Windows のキャラクター・セットは「shift_jis」と完全な互換ではない、今まで Windows のキャラクター・セットのスタンダードな表記法は「CP932」だったが、「commons-net-3.3」では「MS932」でないとエラーになるようだ.
JavaでFTPアップロードを行う。 - sinsengumi.net
http://sinsengumi.net/blog/2011/02/java%E3%81%A7ftp%E3%82%A2%E3%83%83%E3%83%97%E3%83%AD%E3%83%BC%E3%83%89%E3%82%92%E8%A1%8C%E3%81%86%E3%80%82/
(分かりやすければ他のファイル名でも良い)「MainPanelDesign」(MainPanelDesign.java)ファイルを Visual Swing for Eclipse でビジュアルに画面デザイン(GUI 部品の配置)を作成している(Java コードが自動生成される)。
「MainAppFrameObj、MainPanelImplementationObj」 からアプレット独自メソッドにアクセスしているので、「MainAppFrameObj、MainPanelImplementationObj」はアプレット・クラス内に設置している。
(アプリーケーションの初期実行用) main( ) メソッドで(MainAppFrameObjなどのような)クラス内クラスをインスタンス化したい場合(main( ) メソッド実行時には、まだアプレット自体のインスタンスが生成されておらず、通常のクラス内クラスではインスタンス化できないので) 、クラス内クラスには「static」修飾子を付与しなければならない(この場合、オブジェクトは1つだけしか作成できない)。
クリック時にマウス・カーソルが動いてしまった場合 mouseClicked イベントだとイベントが発生しない"仕様"になっているようなので、mouse イベントに関しては mouseReleased イベントを使用している。
なお、ダブル・クリック検出用に mousePressed イベントも使用している。
変更した部分はイベント用メソッドの「HostLogout_CbtMouseMouseReleased、HostLogin_CbtMouseMouseReleased、FTPFileList_CbtMouseMouseReleased、FTPDownload_CbtMouseMouseReleased、FTPUpload_CbtMouseMouseReleased、HostFileList_CbtNativeMouseMousePressed、HostFileList_CltNativeMouseMouseReleased、LocalFileList_CbtNativeMouseMousePressed、LocalFileList_CltNativeMouseMouseReleased、SetupFileList_HostFolder_CbtMouseMouseReleased、SetupFileList_LocalFolder_CbtMouseMouseReleased、FTPBreak_CbtMouseMouseReleased、TransferList_Entry_CbtMouseMouseReleased、TransferList_Delete_CbtMouseMouseReleased、FTPSnapShot_Makera_CbtMouseMouseReleased、FTPSnapShot_Delete_CbtMouseMouseReleased、FTPSynchronize_CbtMouseMouseReleased」の private 修飾子を削除。
その他、「ctfHostUserName、ctfHostName、cpfHostPassword、ctfHostFolder、ctfLocalFolder、ctfHostPortNum、ctaMessage、cltHostFileList、cltLocalFileList、ccbFTPFileDataType、ctpFileListTabs、cckHostPASVMode、ccbHostEncode、cpnFTPSetting、ctpBaseTabs、cltHostTransferList、cltLocalTransferList、ctpTransferListTabs」変数の private 修飾子を削除(Button など Component を直にイジる必要がなければ private 修飾子を削除しなくても良い)。
『FTPConnect.java』
import java.awt.Dimension;
//Event を使う場合は、その Event に対応する「〜Adapter、〜Event」を import しなければならない。
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.net.SocketException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.DefaultListModel;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
@SuppressWarnings("serial")
public class FTPConnect extends JApplet {
// volatile:最適化の抑制.
private static volatile FTPConnect oMainApp;
private static volatile boolean lApplication = false; // true; //
private static volatile MainAppFrameObj oMainAppFrame;
private volatile MainPanelImplementationObj oMainPanelImp;
private final String fvsSerialFile = "FTPConnect.sr";
private final String fvsSerialVersion = "1.1";
private final String fvsFTPSnapShotFile = ".FTPConnect.SnapShot";
private SimpleDateFormat oSDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
// private final String fvsPathListTag_Folder = ":+Folder:=";
private final String fvsPathListTag_Error = "*<Error>";
private final String fvsPathListTag_File = "-<File>";
private final String fvsReg_PathListTag_File = "\\-<File>";
private final String fvsPathListTag_Folder = "+<Directory>";
private final String fvsReg_PathListTag_Folder = "\\+<Directory>";
private final String fvsPathListTag_TimeStamp = " <TimeStamp>";
private final String fvsReg_PathListTag_TimeStamp = fvsPathListTag_TimeStamp;
private enum FTPTransfer_Enum { feFTPUpload, feFTPDownload, feFTPSnapShot_Makera, feFTPSnapShot_Delete, feFTPSynchronize, };
private volatile Thread oThread_FTPTransfer;
private volatile Thread oThread_FTPDownload;
private volatile Thread oThread_FTPUpload;
private volatile Thread oThread_FTPSnapShot_Makera;
private volatile Thread oThread_FTPSnapShot_Delete;
private volatile Thread oThread_FTPSynchronize;
private volatile Matcher matcher;
// Pattern pattern;
// Transfer // Connect
private volatile boolean lFTPConnection = false; // true; //
private volatile boolean lFTPBreak = false; // true; //
private volatile boolean lFTPThread = false; // true; //
private volatile FTPClient client;
// Binary転送Modeを利用?(true=Yes、false=No)
// TransferFileDataType
private static volatile boolean lFTPTransfer_Binary = false; // true; //
// PASV Modeを利用?(true=Yes、false=No)
private static volatile boolean lFTPPassiveMode = true; // false; //
private static final String fvsFTPTransfer_Binary = "Binary";
// 連想配列
private volatile HashMap<String,String> da1CharEncodeSets;
private volatile String vsHostEncode;
private volatile String vsLocalEncode;
private volatile String vsHostName;
private volatile String vsHostPortNum;
private volatile int iHostPortNum;
private volatile String vsHostUserName;
private volatile String vsHostPassword;
private volatile String vsHostCurrent;
private volatile String vsHostFolder;
private volatile String vsLocalCurrent;
private volatile String vsLocalFolder;
public static void main(String[] args) {
oMainApp = new FTPConnect( );
lApplication = true; // false;
oMainAppFrame =
new MainAppFrameObj( );
oMainAppFrame.oAppThread.start();
try{
oMainAppFrame.oAppThread.join();
}
catch(InterruptedException e){ }
// oMainAppFrame.oAppThread = null;
System.exit(0);
}
public void AppRepaint() {
System.out.println("AppRepaint( );");
repaint();
}
public void init() {
System.out.println("init( );");
oMainApp = this;
oMainPanelImp = new MainPanelImplementationObj();
Read( );
getContentPane().add(oMainPanelImp,"Center");
oMainPanelImp.setVisible(true);
if( oMainAppFrame!=null ){
System.out.println("if(lApplication)");
oMainAppFrame.setPreSize(oMainPanelImp.getSize( ));
System.out.println("MainPanelWidth="+oMainPanelImp.getSize( ).getWidth());
System.out.println("MainPanelHeight="+oMainPanelImp.getSize( ).getHeight());
}
System.out.println("Hello, World!");
// UTF8, Windows, EUC-JP, ASCII
da1CharEncodeSets = new HashMap<String, String>(){
{
put("UTF-8", "utf-8");
put("Windows", "MS932"); // Microsoft Windows CodePage 932
// ↑厳密に言うと Windows は「shift_jis」と完全な互換ではない.
// 今までスタンダードな表記法は「CP932」だったが、
// 「commons-net-3.3」では「MS932」でないとエラーになるようだ.
put("EUC-JP", "EUC-JP"); //
put("ASCII", "ISO-8859-1"); //
}
};
}
public void start(){
System.out.println("start( );");
repaint();
}
public void stop(){
System.out.println("stop( );");
}
public void destroy(){
System.out.println("destroy( );");
Write( );
}
public void Write( ) {
String vsProcessName = "Write";
System.out.println(vsProcessName+"( ).");
try {
int iListSize;
ObjectOutputStream oOOSSerial = new ObjectOutputStream(new FileOutputStream(fvsSerialFile));
oOOSSerial.writeObject(fvsSerialVersion);
oOOSSerial.writeBoolean(oMainPanelImp.cckHostPASVMode.isSelected( ));
oOOSSerial.writeObject(oMainPanelImp.ccbHostEncode.getSelectedObjects( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostName.getText( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostPortNum.getText( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostUserName.getText( ));
oOOSSerial.writeObject(new String(oMainPanelImp.cpfHostPassword.getPassword( )));
oOOSSerial.writeObject(oMainPanelImp.ccbFTPFileDataType.getSelectedObjects( ));
oOOSSerial.writeObject(oMainPanelImp.ctfLocalFolder.getText( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostFolder.getText( ));
iListSize = ((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( );
oOOSSerial.writeInt(iListSize );
for(int i=0; i<iListSize; i++ ){
oOOSSerial.writeObject(
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getElementAt(i));
}
iListSize = ((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).getSize( );
oOOSSerial.writeInt(iListSize );
for(int i=0; i<iListSize; i++ ){
oOOSSerial.writeObject(
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).getElementAt(i));
}
oOOSSerial.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
PutMessage("FileNotFoundException:"+vsProcessName+".\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
}
public void Read() {
String vsProcessName = "Read";
System.out.println(vsProcessName+"( ).");
try {
ObjectInputStream oOISSerial = new ObjectInputStream(new FileInputStream(fvsSerialFile));
String vsVersion = (String)oOISSerial.readObject( );
if( 0==fvsSerialVersion.compareTo("") ){
// Non-Operation
}else if( fvsSerialVersion.compareTo(vsVersion)!=0){
System.out.println("Error:SerialVersion.");
PutMessage("Error:SerialVersion.\n");
}else{
int iListSize;
oMainPanelImp.cckHostPASVMode.setSelected(oOISSerial.readBoolean( ));
oMainPanelImp.ccbHostEncode.setSelectedItem(oOISSerial.readObject( ));
oMainPanelImp.ctfHostName.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ctfHostPortNum.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ctfHostUserName.setText((String)oOISSerial.readObject( ));
oMainPanelImp.cpfHostPassword.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ccbFTPFileDataType.setSelectedItem(oOISSerial.readObject( ));
oMainPanelImp.ctfLocalFolder.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ctfHostFolder.setText((String)oOISSerial.readObject( ));
iListSize = oOISSerial.readInt( );
for(int i=0; i<iListSize; i++ ){
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).addElement(
oOISSerial.readObject( ));
}
iListSize = oOISSerial.readInt( );
for(int i=0; i<iListSize; i++ ){
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).addElement(
oOISSerial.readObject( ));
}
oOISSerial.close( );
}
} catch (FileNotFoundException e) {
// e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
// PutMessage("FileNotFoundException:"+vsProcessName+".\n");
// PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("ClassNotFoundException:"+vsProcessName+".");
PutMessage("ClassNotFoundException:"+vsProcessName+".\n");
}
}
public void PutMessage(String vsMsg){
String vsProcessName = "PutMessage";
// JScrollPane には暗黙の子 JViewport が存在するようだ。
// つまり、この場合の ctaMessage の親は JViewport になり、
// JList の親の親が JScrollPane となる。
JScrollPane oTabSelectedComponent = (JScrollPane)(oMainPanelImp.ctaMessage.getParent( ).getParent( ));
oMainPanelImp.ctpBaseTabs.setSelectedComponent(oTabSelectedComponent);
oMainPanelImp.ctaMessage.append(vsMsg);
}
public void FTPLogin( ) {
String vsProcessName = "FTPLogin";
System.out.println(vsProcessName+"( ).");
oMainPanelImp.ctaMessage.setText("");
PutMessage("FTPLogin.\n");
lFTPPassiveMode = oMainPanelImp.cckHostPASVMode.isSelected( );
vsHostEncode =
da1CharEncodeSets.get((String)oMainPanelImp.ccbHostEncode.getSelectedItem());
Pattern pattern = Pattern.compile("( |\n)$");
vsHostName = oMainPanelImp.ctfHostName.getText();
matcher = pattern.matcher(vsHostName);
vsHostName = matcher.replaceAll("");
vsHostPortNum = oMainPanelImp.ctfHostPortNum.getText( );
matcher = pattern.matcher(vsHostPortNum);
vsHostPortNum = matcher.replaceAll("");
if(vsHostPortNum.isEmpty( )){ vsHostPortNum = "0"; }
iHostPortNum = Integer.parseInt(vsHostPortNum);
vsHostUserName = oMainPanelImp.ctfHostUserName.getText();
matcher = pattern.matcher(vsHostUserName);
vsHostUserName = matcher.replaceAll("");
vsHostPassword = String.valueOf(oMainPanelImp.cpfHostPassword.getPassword( ));
matcher = pattern.matcher(vsHostPassword);
vsHostPassword = matcher.replaceAll("");
try {
client = new FTPClient();
String vsEncode = client.getControlEncoding();
System.out.println("vsEncode="+vsEncode+"; ");
System.out.println(
"vsHostEncode="+vsHostEncode+"; "+
"vsHostName="+vsHostName+"; "+
"iHostPortNum="+iHostPortNum+"; "+
"vsHostUserName="+vsHostUserName+"; "+
"vsHostPassword="+vsHostPassword+"; "+
"");
client.setControlEncoding(vsHostEncode);
// ↑ Host 側のキャラクター・セットを設定してやれば良いようだ.
System.out.println("Connect...");
client.connect(vsHostName, iHostPortNum);
System.out.println("Connected to Server:" + vsHostName + " on "+client.getRemotePort());
System.out.println(client.getReplyString());
client.login(vsHostUserName,vsHostPassword);
System.out.println(client.getReplyString());
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
String vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
if( ! FTPReply.isPositiveCompletion(client.getReplyCode( )) ){
lFTPConnection = true; // false; //
FTPLogout();
return;
}
if (lFTPPassiveMode) {
client.enterLocalPassiveMode();
System.out.println("PassiveMode = ON");
} else {
client.enterLocalActiveMode();
System.out.println("PassiveMode = OFF");
}
HostFileList(null, true); // lTabSelected : true; / false; //
LocalFileList(null, false); // lTabSelected : true; / false; //
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:"+vsProcessName+".");
PutMessage("NumberFormatException:"+vsProcessName+".\n");
PutMessage("FTP ポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:"+vsProcessName+".");
PutMessage("SocketException:"+vsProcessName+".\n");
PutMessage("Socket 通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
PutMessage("FileNotFoundException:"+vsProcessName+".\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
}
public void FTPLogout() {
String vsProcessName = "FTPLogout";
System.out.println(vsProcessName+"( ).");
PutMessage("FTPLogout.\n");
try {
lFTPConnection = false; // true; //
if( client!=null && client.isConnected( ) ){
client.disconnect( );
System.out.println("FTP Disconnect.");
PutMessage("FTP Disconnect.\n");
}
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:"+vsProcessName+".");
PutMessage("NumberFormatException:"+vsProcessName+".\n");
PutMessage("FTP ポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:"+vsProcessName+".");
PutMessage("SocketException:"+vsProcessName+".\n");
PutMessage("Socket 通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
PutMessage("FileNotFoundException:"+vsProcessName+".\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
}
public void HostFileList(String vsTargetFile, boolean lTabSelected){ // lTabSelected : true; / false; //
String vsProcessName = "HostFileList";
System.out.println(vsProcessName+"( ).");
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
try {
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).removeAllElements( );
if( lTabSelected ){
// JScrollPane には暗黙の子 JViewport が存在するようだ。
// つまり、この場合の JList の親は JViewport になり、
// JList の親の親が JScrollPane となる。
JScrollPane oTabSelectedComponent = (JScrollPane)(oMainPanelImp.cltHostFileList.getParent( ).getParent( ));
oMainPanelImp.ctpFileListTabs.setSelectedComponent(oTabSelectedComponent);
}
Pattern pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
System.out.println("vsTargetFile="+vsTargetFile+"; ");
if( null==vsTargetFile ){
vsTargetFile = "";
}
if( 0==vsTargetFile.compareTo("..") ){
System.out.println("if( 0==vsTargetFile.compareTo(..) )");
vsTargetFile = "";
client.changeToParentDirectory();
}else{
if( vsTargetFile.compareTo("")!=0 ){
vsHostCurrent = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
}
// client.doCommand("CWD", vsHostCurrent);
client.changeWorkingDirectory(vsHostCurrent);
}
vsHostCurrent = client.printWorkingDirectory( );
oMainPanelImp.ctfHostFolder.setText(vsHostCurrent);
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
if( vsHostCurrent.compareTo("/")!=0 ){
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).addElement(
fvsPathListTag_Folder+"..");
}
String vsElement = "";
String[] d1vsHostFile = new String[client.listFiles().length];
HashMap<String, String> da1PathListSets = new HashMap<String, String>( );
int i = 0;
for (FTPFile oFTPFile : client.listFiles()) {
String vsTimeStamp = fvsPathListTag_TimeStamp+oSDateFormat.format(oFTPFile.getTimestamp().getTime());
String vsHostFile = oFTPFile.getName();
String vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsHostFile;
if( oFTPFile.isFile( ) ){
vsElement = fvsPathListTag_File;
}else if( oFTPFile.isDirectory( ) ){
vsElement = fvsPathListTag_Folder;
}
d1vsHostFile[i] = vsElement+vsHostFile;
da1PathListSets.put(d1vsHostFile[i], vsTimeStamp);
System.out.println(d1vsHostFile[i]);
System.out.println(vsTimeStamp);
i++;
}
FileSort(d1vsHostFile);
for ( i = 0; i<d1vsHostFile.length; ++i) {
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).addElement(
d1vsHostFile[i]);
String vsTimeStamp = da1PathListSets.get(d1vsHostFile[i]);
System.out.println(d1vsHostFile[i]);
System.out.println(vsTimeStamp);
char[] d1vcFileElement = d1vsHostFile[i].toCharArray();
System.out.print("Hex = ");
for(int j = 0; j<d1vcFileElement.length; j++){
int k = d1vcFileElement[j];
if( k<0 ){ k = 65536+k; }
// ↑2の補数の負の値を正の値に変換している.
System.out.print(Integer.toHexString(k)+"; ");
}
System.out.println("");
}
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
String vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:"+vsProcessName+".");
PutMessage("NumberFormatException:"+vsProcessName+".\n");
PutMessage("FTP ポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:"+vsProcessName+".");
PutMessage("SocketException:"+vsProcessName+".\n");
PutMessage("Socket 通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
PutMessage("FileNotFoundException:"+vsProcessName+".\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
}
public void LocalFileList(String vsTargetFile, boolean lTabSelected){ // lTabSelected : true; / false; //
String vsProcessName = "LocalFileList";
System.out.println(vsProcessName+"( ).");
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).removeAllElements( );
if( lTabSelected ){
// JScrollPane には暗黙の子 JViewport が存在するようだ。
// つまり、この場合の JList の親は JViewport になり、
// JList の親の親が JScrollPane となる。
JScrollPane oTabSelectedComponent = (JScrollPane)(oMainPanelImp.cltLocalFileList.getParent( ).getParent( ));
oMainPanelImp.ctpFileListTabs.setSelectedComponent(oTabSelectedComponent);
}
Pattern pattern = Pattern.compile("( |\n)$");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
File oLocalCurrent = null;
System.out.println("vsTargetFile="+vsTargetFile+"; ");
try {
vsHostCurrent = "";
if( null==vsTargetFile ){
vsTargetFile = "";
}
oLocalCurrent = new File(vsLocalCurrent,vsTargetFile);
vsLocalCurrent = oLocalCurrent.getCanonicalPath( );
if( 0==vsTargetFile.compareTo("..") ){
System.out.println("if( 0==vsTargetFile.compareTo(..) )");
vsTargetFile = "";
}
oMainPanelImp.ctfLocalFolder.setText(vsLocalCurrent);
System.out.println("vsLocalCurrent="+vsLocalCurrent+"; ");
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
oLocalCurrent = null;
}
if( oLocalCurrent!=null && oLocalCurrent.isDirectory( ) ){
pattern = Pattern.compile("^?(.:)(/|\\\\)$");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalCurrent);
System.out.println("pattern = Pattern.compile(^?(.:)(/|\\\\)$)");
if( ! matcher.find( ) ){
System.out.println("if( matcher.find( ) )");
// vsLocalCurrent = matcher.replaceAll("");
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).addElement(
fvsPathListTag_Folder+"..");
}
String[] d1vsLocalFile = new String[oLocalCurrent.listFiles().length];
File oLocalPath;
String vsLocalFile;
String vsLocalPath;
String vsElement = "";
int i = 0;
for (File oFile : oLocalCurrent.listFiles( )) {
vsLocalFile = oFile.getName();
// vsLocalPath = vsLocalCurrent+(vsLocalCurrent.endsWith("/") ? "" : "/")+vsLocalFile;
try {
oLocalPath = new File(vsLocalCurrent,vsLocalFile);
vsLocalPath = oLocalPath.getCanonicalPath( );
if( 0==vsLocalFile.compareTo("..") ){
System.out.println("if( 0==vsLocalFile.compareTo(..) )");
vsLocalFile = "";
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
if(oFile.isFile()){
vsElement = fvsPathListTag_File;
}else if(oFile.isDirectory( )){
vsElement = fvsPathListTag_Folder;
}
d1vsLocalFile[i] = vsElement+vsLocalFile;
i++;
}
FileSort(d1vsLocalFile);
for ( i = 0; i<d1vsLocalFile.length; ++i) {
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).addElement(
d1vsLocalFile[i]);
System.out.println(d1vsLocalFile[i]);
char[] d1vcFileElement = d1vsLocalFile[i].toCharArray( );
System.out.print("Hex = ");
for(int j = 0; j<d1vcFileElement.length; j++){
int k = d1vcFileElement[j];
if( k<0 ){ k = 65536+k; }
// ↑2の補数の負の値を正の値に変換している.
System.out.print(Integer.toHexString(k)+"; ");
}
System.out.println("");
}
}
}
public void FileSort(String[] d1vsFile){
String vsProcessName = "FileSort";
System.out.println(vsProcessName+"( ).");
Arrays.sort(d1vsFile, new Comparator<String>() {
@Override
public int compare(String vs0, String vs1) {
// このソートを Windows 的な File 名のソート順にカスタマイズしている.
String vs, vsAscTab = new String(Character.toChars(0x09));
vs = vs0;
vs0 = vs.toUpperCase( )+vsAscTab+vs;
vs = vs1;
vs1 = vs.toUpperCase( )+vsAscTab+vs;
return vs0.compareTo(vs1);
}
});
}
public void FTPTransfer( FTPTransfer_Enum eFTPTransfer ){
String vsProcessName = "FTPDownloadTransfer";
System.out.println(vsProcessName+"( ).");
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
String vsSaveBuf_HostFolder, vsSaveBuf_LocalFolder;
String vsHostPath, vsLocalPath;
vsSaveBuf_HostFolder = oMainPanelImp.ctfHostFolder.getText( );
vsSaveBuf_LocalFolder = oMainPanelImp.ctfLocalFolder.getText( );
int iListSize = ((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( );
for(int i = 0; i<iListSize; i++){
oMainPanelImp.ctfHostFolder.setText( (String)
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getElementAt(i));
oMainPanelImp.ctfLocalFolder.setText( (String)
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).getElementAt(i));
System.out.println(
"oMainPanelImp.ctfHostFolder.getText="+oMainPanelImp.ctfHostFolder.getText()+"; "+
"oMainPanelImp.ctfHostFolder.getText="+oMainPanelImp.ctfLocalFolder.getText()+"; "+
"");
switch (eFTPTransfer) {
case feFTPUpload :{
FTPUpload( );
} break;
case feFTPDownload :{
FTPDownload( );
} break;
case feFTPSnapShot_Makera :{
FTPSnapShot(true); // lMakera : true; / false;
} break;
case feFTPSnapShot_Delete :{
FTPSnapShot(false); // lMakera : true; / false;
} break;
case feFTPSynchronize :{
FTPSynchronize( );
} break;
default:{
//
} break;
};
}
oMainPanelImp.ctfHostFolder.setText(vsSaveBuf_HostFolder);
oMainPanelImp.ctfLocalFolder.setText(vsSaveBuf_LocalFolder);
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
String vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
}
public void FTPDownload( ){
String vsProcessName = "FTPDownload";
System.out.println(vsProcessName+"( ).");
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
matcher = null;
Pattern pattern = null;
String vsTargetFile = null;
String vsHostPath = null;
pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
String vsLocalPath = vsLocalCurrent;
if( ! oMainPanelImp.cltHostFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltHostFileList.getSelectedValue();
pattern = Pattern.compile("^"+fvsPathListTag_File);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
pattern = Pattern.compile("^"+fvsPathListTag_Folder);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
if(matcher.find()){
System.out.println("if(matcher.find( ))");
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsTargetFile = "";
}
}else{
vsTargetFile = "";
}
if( vsTargetFile!=null ){
System.out.println(
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPatht="+vsLocalPath+"; "+
"");
FTPDownloadFolder( vsTargetFile, vsHostCurrent, vsLocalCurrent );
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
String vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
// client.changeWorkingDirectory(vsHostCurrent);
}
LocalFileList(null, true); // lTabSelected : true; / false; //
}
public void FTPDownloadFolder( String vsTargetFile, String vsHostCurrent, String vsLocalCurrent ){
String vsProcessName = "FTPDownloadFolder";
System.out.println(vsProcessName+"( ).");
System.out.println(
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
if( vsTargetFile!=null && 0!=vsTargetFile.compareTo("") ){
FTPDownloadFile( vsTargetFile, vsHostCurrent, vsLocalCurrent, -1);
}else{
String vsHostPrevious = "";
String vsHostPath = null;
Body : try {
vsHostPrevious = client.printWorkingDirectory( );
System.out.println("vsHostPrevious="+vsHostPrevious+"; ");
client.changeWorkingDirectory(vsHostCurrent);
if( lFTPBreak ){
break Body;
}
System.out.println("client.printWorkingDirectory( )="+client.printWorkingDirectory( )+"; ");
// FTPFile[] d1oFTPFile = client.listFiles();
File oLocalPath;
for (FTPFile oFTPFile : client.listFiles()) {
if( lFTPBreak ){
break Body;
}
System.out.println("lFTPBreak="+lFTPBreak+"; ");
String vsHostFile = oFTPFile.getName();
if( oFTPFile.isFile( ) ){
FTPDownloadFile( vsHostFile, vsHostCurrent, vsLocalCurrent, -1);
}else if( oFTPFile.isDirectory( ) ){
String vsLocalPath = vsLocalCurrent;
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsHostFile;
// vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsHostFile;
oLocalPath = new File(vsLocalCurrent,vsHostFile);
vsLocalPath = oLocalPath.getCanonicalPath( );
if( 0==vsHostFile.compareTo("..") ){
System.out.println("if( 0==vsHostFile.compareTo(..) )");
vsHostFile = "";
}
System.out.println(
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
oLocalPath = new File(vsLocalPath);
if( ! oLocalPath.exists( ) ){
oLocalPath.mkdir();
}
FTPDownloadFolder( "", vsHostPath, vsLocalPath );
// client.changeWorkingDirectory(vsHostCurrent);
}
}
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
String vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:"+vsProcessName+".");
PutMessage("NumberFormatException:"+vsProcessName+".\n");
PutMessage("FTP ポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:"+vsProcessName+".");
PutMessage("SocketException:"+vsProcessName+".\n");
PutMessage("Socket 通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
PutMessage("FileNotFoundException:"+vsProcessName+".\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
try {
Pattern pattern = Pattern.compile("^/");
matcher = pattern.matcher(vsHostPrevious);
if( matcher.find( ) ){
client.changeWorkingDirectory(vsHostPrevious);
System.out.println("client.printWorkingDirectory( )="+client.printWorkingDirectory( )+"; ");
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
}
}
public void FTPDownloadFile(String vsTargetFile,String vsHostCurrent,String vsLocalCurrent, int iFTPTransferMode){
String vsProcessName = "FTPDownloadFile";
System.out.println(vsProcessName+"( ).");
File oLocalPath;
String vsHostPrevious = "";
String vsMsg;
String vsLocalPath = null;
String vsHostPath = null;
try{
vsHostPrevious = client.printWorkingDirectory( );
System.out.println("vsHostPrevious="+vsHostPrevious+"; ");
vsLocalPath = vsLocalCurrent;
if( 0==vsLocalPath.compareTo("") ){
vsLocalPath = ".";
}
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
// vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsTargetFile;
oLocalPath = new File(vsLocalPath,vsTargetFile);
// ↑「File( )」コンストラクターの第1引数がブランクだとルートになってしまうようだ。
// カレントにしたい場合は第1引数に明示的に"."(ピリオッド)を指定しなければならないようだ。
vsLocalPath = oLocalPath.getCanonicalPath( );
if( 0==vsTargetFile.compareTo("..") ){
System.out.println("if( 0==vsTargetFile.compareTo(..) )");
vsTargetFile = "";
}
System.out.println(
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
lFTPTransfer_Binary = false; // true; //
if( 0==fvsFTPTransfer_Binary.compareTo(
(String)oMainPanelImp.ccbFTPFileDataType.getSelectedItem( )) ){
lFTPTransfer_Binary = true; // false; //
}
if( FTP.BINARY_FILE_TYPE==iFTPTransferMode ||
FTP.ASCII_FILE_TYPE==iFTPTransferMode ){
client.setFileType(iFTPTransferMode);
}else if(lFTPTransfer_Binary){
client.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("Transfer:Binary.");
}else{
client.setFileType(FTP.ASCII_FILE_TYPE);
System.out.println("Transfer:ASCII.");
}
// FTP Download.
PutMessage("HostPath="+vsHostPath+"; "+"\n");
PutMessage("LocalPath="+vsLocalPath+"; "+"\n");
FileOutputStream oFOS = null;
oFOS = new FileOutputStream(vsLocalPath);
client.retrieveFile(vsHostPath, oFOS);
oFOS.close();
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:"+vsProcessName+".");
PutMessage("NumberFormatException:"+vsProcessName+".\n");
PutMessage("FTP ポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:"+vsProcessName+".");
PutMessage("SocketException:"+vsProcessName+".\n");
PutMessage("Socket 通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
PutMessage("FileNotFoundException:"+vsProcessName+".\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
}
public void FTPUpload( ){
String vsProcessName = "FTPUpload";
System.out.println(vsProcessName+"( ).");
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
matcher = null;
Pattern pattern = null;
String vsTargetFile = null;
String vsHostPath = null;
pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
String vsLocalPath = vsLocalCurrent;
try {
File oLocalCurrent;
File oLocalPath = new File(vsLocalPath);
if( oLocalPath.isFile( ) ){
vsTargetFile = oLocalPath.getName( );
vsLocalCurrent = oLocalPath.getParent( );
oLocalCurrent = new File(vsLocalCurrent);
vsLocalCurrent = oLocalCurrent.getCanonicalPath();
}else if( ! oMainPanelImp.cltLocalFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltLocalFileList.getSelectedValue();
pattern = Pattern.compile("^"+fvsPathListTag_File);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
pattern = Pattern.compile("^"+fvsPathListTag_Folder);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
if(matcher.find()){
System.out.println("if(matcher.find( ))");
// vsLocalPath = vsLocalCurrent+(vsLocalCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
oLocalPath = new File(vsLocalCurrent,vsTargetFile);
vsLocalPath = oLocalPath.getCanonicalPath( );
if( 0==vsTargetFile.compareTo("..") ){
System.out.println("if( 0==vsTargetFile.compareTo(..) )");
// vsTargetFile = "";
}
vsTargetFile = "";
}
}else{
vsTargetFile = "";
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
vsTargetFile = null;
}
if( vsTargetFile!=null ){
System.out.println(
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPatht="+vsLocalPath+"; "+
"");
FTPUploadFolder( vsTargetFile, vsHostCurrent, vsLocalCurrent );
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
String vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
// client.changeWorkingDirectory(vsHostCurrent);
}
HostFileList(null, true); // lTabSelected : true; / false; //
}
public void FTPUploadFolder( String vsTargetFile, String vsHostCurrent, String vsLocalCurrent ){
String vsProcessName = "FTPUploadFolder";
System.out.println(vsProcessName+"( ).");
System.out.println(
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
if( vsTargetFile!=null && 0!=vsTargetFile.compareTo("") ){
FTPUploadFile( vsTargetFile, vsHostCurrent, vsLocalCurrent, -1);
}else{
String vsHostPrevious = "";
String vsHostPath = null;
Body : try {
vsHostPrevious = client.printWorkingDirectory( );
System.out.println("vsHostPrevious="+vsHostPrevious+"; ");
if( lFTPBreak ){
break Body;
}
File oLocalCurrent = new File(vsLocalCurrent);
File oLocalPath;
System.out.println("oLocalCurrent = new File(vsLocalCurrent)");
for (File oFile : oLocalCurrent.listFiles()) {
if( lFTPBreak ){
break Body;
}
System.out.println("lFTPBreak="+lFTPBreak+"; ");
String vsLocalFile = oFile.getName();
if( oFile.isFile( ) ){
FTPUploadFile( vsLocalFile, vsHostCurrent, vsLocalCurrent, -1);
}else if( oFile.isDirectory( ) ){
String vsLocalPath = vsLocalCurrent;
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsLocalFile;
// vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsLocalFile;
oLocalPath = new File(vsLocalCurrent,vsLocalFile);
vsLocalPath = oLocalPath.getCanonicalPath( );
if( 0==vsLocalFile.compareTo("..") ){
System.out.println("if( 0==vsLocalFile.compareTo(..) )");
vsLocalFile = "";
}
System.out.println(
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
try {
// client.changeWorkingDirectory(vsHostPath);
System.out.println("client.makeDirectory(vsHostPath).");
client.makeDirectory(vsHostPath);
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
FTPUploadFolder( "", vsHostPath, vsLocalPath );
// client.changeWorkingDirectory(vsHostCurrent);
}
}
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
String vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:"+vsProcessName+".");
PutMessage("NumberFormatException:"+vsProcessName+".\n");
PutMessage("FTP ポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:"+vsProcessName+".");
PutMessage("SocketException:"+vsProcessName+".\n");
PutMessage("Socket 通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
PutMessage("FileNotFoundException:"+vsProcessName+".\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
try {
Pattern pattern = Pattern.compile("^/");
matcher = pattern.matcher(vsHostPrevious);
if( matcher.find( ) ){
client.changeWorkingDirectory(vsHostPrevious);
System.out.println("client.printWorkingDirectory( )="+client.printWorkingDirectory( )+"; ");
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
}
}
public void FTPUploadFile(String vsTargetFile,String vsHostCurrent,String vsLocalCurrent, int iFTPTransferMode){
String vsProcessName = "FTPUploadFile";
System.out.println(vsProcessName+"( ).");
String vsHostPrevious = "";
try{
vsHostPrevious = client.printWorkingDirectory( );
System.out.println("vsHostPrevious="+vsHostPrevious+"; ");
String vsMsg;
String vsLocalPath = null;
// String vsLocalAbsolute = null;
String vsHostPath = null;
FileInputStream oFIS = null;
File oLocalPath;
vsLocalPath = vsLocalCurrent;
if( 0==vsLocalPath.compareTo("") ){
vsLocalPath = ".";
}
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
// vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsTargetFile;
oLocalPath = new File(vsLocalPath,vsTargetFile);
// ↑「File( )」コンストラクターの第1引数がブランクだとルートになってしまうようだ。
// カレントにしたい場合は第1引数に明示的に"."(ピリオッド)を指定しなければならないようだ。
vsLocalPath = oLocalPath.getCanonicalPath( );
// vsLocalAbsolute = oLocalPath.getAbsolutePath( );
if( 0==vsTargetFile.compareTo("..") ){
System.out.println("if( 0==vsTargetFile.compareTo(..) )");
vsTargetFile = "";
}
System.out.println(
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
lFTPTransfer_Binary = false; // true; //
if( 0==fvsFTPTransfer_Binary.compareTo(
(String)oMainPanelImp.ccbFTPFileDataType.getSelectedItem( )) ){
lFTPTransfer_Binary = true; // false; //
}
if( FTP.BINARY_FILE_TYPE==iFTPTransferMode ||
FTP.ASCII_FILE_TYPE==iFTPTransferMode ){
client.setFileType(iFTPTransferMode);
}else if(lFTPTransfer_Binary){
client.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("Transfer:Binary.");
}else{
client.setFileType(FTP.ASCII_FILE_TYPE);
System.out.println("Transfer:ASCII.");
}
// FTP Upload.
PutMessage("vsHostPath="+vsHostPath+";\n");
PutMessage("vsLocalPath="+vsLocalPath+";\n");
oFIS = new FileInputStream(vsLocalPath);
client.storeFile(vsHostPath, oFIS);
oFIS.close();
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:"+vsProcessName+".");
PutMessage("NumberFormatException:"+vsProcessName+".\n");
PutMessage("FTP ポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:"+vsProcessName+".");
PutMessage("SocketException:"+vsProcessName+".\n");
PutMessage("Socket 通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
PutMessage("FileNotFoundException:"+vsProcessName+".\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
}
public void FTPSnapShot(boolean lMakera){ // lMakera : true; / false;
String vsProcessName = "FTPSnapShot";
System.out.println(vsProcessName+"( ).");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
if(lMakera){
vsProcessName = vsProcessName+":Makera";
FTPSnapShotFolder_Makera(vsHostCurrent);
}else{
vsProcessName = vsProcessName+":Delete";
FTPSnapShotFolder_Delete(vsHostCurrent);
}
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
String vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
HostFileList(null, true); // lTabSelected : true; / false; //
}
public void FTPSnapShotFolder_Makera(String vsHostCurrent){
String vsProcessName = "FTPSnapShotFolder_Makera";
System.out.println(vsProcessName+"( ).");
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
int i;
String vsElement = "";
String vsHostPrevious = "";
String vsHostPath = null;
String vsPathListTag;
String vsFTPSnapShotPath;
String vsHostFileInform;
String vsTimeStampInform;
Body : try {
vsHostPrevious = client.printWorkingDirectory( );
System.out.println("vsHostPrevious="+vsHostPrevious+"; ");
if( lFTPBreak ){
break Body;
}
client.changeWorkingDirectory(vsHostCurrent);
vsHostCurrent = client.printWorkingDirectory( );
System.out.println("client.printWorkingDirectory( )="+client.printWorkingDirectory( )+"; ");
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
HashMap<String, String[]> da1PathListSets = new HashMap<String, String[]>( );
String[] d1vsHostFile = new String[client.listFiles().length];
// FTPFile[] d1oHostFile = new FTPFile[client.listFiles().length];
String vsHostFile;
String vsTimeStamp;
i = 0;
for (FTPFile oFTPFile : client.listFiles( )) {
if( lFTPBreak ){
break Body;
}
vsHostFile = oFTPFile.getName();
System.out.println("vsHostFile="+vsHostFile+"; ");
// d1oHostFile[i] = null;
vsElement = "";
vsPathListTag = null;
vsTimeStamp = null;
if( 0!=fvsFTPSnapShotFile.compareTo(vsHostFile) ){
vsTimeStamp = oSDateFormat.format(oFTPFile.getTimestamp().getTime());
if( oFTPFile.isFile( ) ){
vsPathListTag = fvsPathListTag_File;
}else if( oFTPFile.isDirectory( ) ){
vsPathListTag = fvsPathListTag_Folder;
}
}
// d1oHostFile[i] = oFTPFile;
d1vsHostFile[i] = vsPathListTag+vsHostFile;
da1PathListSets.put(d1vsHostFile[i],
new String[]{vsPathListTag, vsHostFile, vsTimeStamp});
// System.out.println(vsElement);
System.out.println(
"i="+i+"; "+
"vsPathListTag="+vsPathListTag+"; "+
"d1vsHostFile[i]="+d1vsHostFile[i]+"; "+
"vsTimeStamp="+vsTimeStamp+"; "+
"");
i++;
}
FileSort(d1vsHostFile);
// client.setFileType(FTP.BINARY_FILE_TYPE);
// client.setFileType(FTP.ASCII_FILE_TYPE);
vsFTPSnapShotPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+fvsFTPSnapShotFile;
// OutputStream oOSFTPSnapShot = client.storeFileStream(vsFTPSnapShotPath);
// ↑「client.storeFileStream( )」による Stream で WorkingDirectory が null になってしまう場合があるようだ。
FileOutputStream oFOSFTPSnapShot = new FileOutputStream(fvsFTPSnapShotFile);
OutputStreamWriter oOSWFTPSnapShot = new OutputStreamWriter(oFOSFTPSnapShot);
BufferedWriter oBWFTPSnapShot = new BufferedWriter(oOSWFTPSnapShot);
// ArrayList<String[]> dl1oHostFile = new ArrayList<String[]>();
String[] d1svFileInform;
for (i = 0; i<d1vsHostFile.length; i++) {
if( lFTPBreak ){
break Body;
}
vsHostFileInform = d1vsHostFile[i];
d1svFileInform = da1PathListSets.get(vsHostFileInform);
vsPathListTag = d1svFileInform[0];
vsHostFile = d1svFileInform[1];
vsTimeStampInform = fvsPathListTag_TimeStamp+d1svFileInform[2];
System.out.println(
"vsHostFile="+vsHostFile+"; "+
"vsPathListTag="+vsPathListTag+"; "+
"vsTimeStampInform="+vsTimeStampInform+"; "+
"");
vsElement = "";
if( null!=vsPathListTag ){
vsElement = vsPathListTag;
oBWFTPSnapShot.write(vsHostFileInform+vsTimeStampInform);
oBWFTPSnapShot.newLine( );
System.out.println(vsHostFileInform+vsTimeStampInform);
}
}
oBWFTPSnapShot.close( );
// client.setFileType(FTP.BINARY_FILE_TYPE);
// client.setFileType(FTP.ASCII_FILE_TYPE);
FTPUploadFile(fvsFTPSnapShotFile, vsHostCurrent, "", FTP.ASCII_FILE_TYPE);
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
String vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
for (i = 0; i<d1vsHostFile.length; i++) {
if( lFTPBreak ){
break Body;
}
vsHostFileInform = d1vsHostFile[i];
d1svFileInform = da1PathListSets.get(vsHostFileInform);
vsPathListTag = d1svFileInform[0];
vsHostFile = d1svFileInform[1];
if( vsPathListTag!=null ){
if( 0==fvsPathListTag_File.compareTo(vsPathListTag) ){
//
}
if( 0==fvsPathListTag_Folder.compareTo(vsPathListTag) ){
System.out.println("vsHostFile="+vsHostFile+"; ");
FTPSnapShotFolder_Makera(vsHostFile);
}
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:"+vsProcessName+".");
PutMessage("NumberFormatException:"+vsProcessName+".\n");
PutMessage("FTP ポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:"+vsProcessName+".");
PutMessage("SocketException:"+vsProcessName+".\n");
PutMessage("Socket 通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
PutMessage("FileNotFoundException:"+vsProcessName+".\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
try {
Pattern pattern = Pattern.compile("^/");
matcher = pattern.matcher(vsHostPrevious);
if( matcher.find( ) ){
client.changeWorkingDirectory(vsHostPrevious);
System.out.println("client.printWorkingDirectory( )="+client.printWorkingDirectory( )+"; ");
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
}
public void FTPSnapShotFolder_Delete(String vsHostCurrent){
String vsProcessName = "FTPSnapShotFolder_Delete";
System.out.println(vsProcessName+"( ).");
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
int i;
String vsElement = "";
String vsHostPrevious = "";
String vsHostPath = null;
try {
vsHostPrevious = client.printWorkingDirectory( );
System.out.println("vsHostPrevious="+vsHostPrevious+"; ");
client.changeWorkingDirectory(vsHostCurrent);
vsHostCurrent = client.printWorkingDirectory( );
System.out.println("client.printWorkingDirectory( )="+client.printWorkingDirectory( )+"; ");
PutMessage("Current="+vsHostCurrent+";\n");
client.deleteFile(fvsFTPSnapShotFile);
for (FTPFile oFTPFile : client.listFiles( )) {
String vsHostFile = oFTPFile.getName();
if( oFTPFile.isFile( ) ){
//
}else if( oFTPFile.isDirectory( ) ){
System.out.println("vsHostFile="+vsHostFile+"; ");
FTPSnapShotFolder_Delete(vsHostFile);
}
}
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
String vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:"+vsProcessName+".");
PutMessage("NumberFormatException:"+vsProcessName+".\n");
PutMessage("FTP ポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:"+vsProcessName+".");
PutMessage("SocketException:"+vsProcessName+".\n");
PutMessage("Socket 通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
PutMessage("FileNotFoundException:"+vsProcessName+".\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
try {
Pattern pattern = Pattern.compile("^/");
matcher = pattern.matcher(vsHostPrevious);
if( matcher.find( ) ){
client.changeWorkingDirectory(vsHostPrevious);
System.out.println("client.printWorkingDirectory( )="+client.printWorkingDirectory( )+"; ");
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
}
public void FTPSynchronize( ){
String vsProcessName = "FTPSynchronize";
System.out.println(vsProcessName+"( ).");
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
Pattern pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
FTPSynchronizeFolder( "", vsHostCurrent, vsLocalCurrent );
FTPSnapShot(true); // lMakera : true; / false;
HostFileList(null, false); // lTabSelected : true; / false; //
LocalFileList(null, false); // lTabSelected : true; / false; //
}
public void FTPSynchronizeFolder( String vsTargetFile, String vsHostCurrent, String vsLocalCurrent ){
String vsProcessName = "FTPSynchronizeFolder";
System.out.println(vsProcessName+"( ).");
System.out.println(
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
int i;
String vsElement = "";
String vsFTPSnapShotLine = "";
String vsHostPrevious = "";
String vsHostPath = null;
String vsLocalPath = null;
// String vsTimeStamp;
String vsHostTimeStamp, vsLocalTimeStamp;
String vsSnapShotCurrent, vsSnapShotPath, vsSnapShotTimeStamp;
String vsHostFile = "";
String vsLocalFile = "";
String vsPathListTag;
String vsHostPathListTag = "";
String vsLocalPathListTag = "";
File oLocalPath;
boolean lFTPSnapShotFile = false; // true; //
Body : try {
vsHostPrevious = client.printWorkingDirectory( );
System.out.println(
"lFTPBreak="+lFTPBreak+"; "+
"vsHostPrevious="+vsHostPrevious+"; "+
"");
if( lFTPBreak ){
break Body;
}
if( 0!=vsTargetFile.compareTo("") ){
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
// vsLocalPath = vsLocalCurrent+(vsLocalCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
oLocalPath = new File(vsLocalCurrent, vsTargetFile);
vsLocalPath = oLocalPath.getCanonicalPath( );
if( 0==vsTargetFile.compareTo("..") ){
System.out.println("if( 0==vsTargetFile.compareTo(..) )");
vsTargetFile = "";
}
vsHostCurrent = vsHostPath;
vsLocalCurrent = vsLocalPath;
}
System.out.println(
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
client.changeWorkingDirectory(vsHostCurrent);
vsHostCurrent = client.printWorkingDirectory( );
System.out.println("client.printWorkingDirectory( )="+client.printWorkingDirectory( )+"; ");
PutMessage("HostCurrent="+vsHostCurrent+";\n");
PutMessage("LocalCurrent="+vsLocalCurrent+";\n");
System.out.println("◆client.listFiles( )");
// HashMap<String, String> da1SnapShotSets = new HashMap<String, String>( );
// HashMap<String, String> da1HostPathListSets = new HashMap<String, String>( );
HashMap<String, String[]> da1FileListSets = new HashMap<String, String[]>( );
String[] d1vsHostFile = new String[client.listFiles().length];
FTPFile[] d1oHostFile = new FTPFile[client.listFiles().length];
i = 0;
for (FTPFile oFTPFile : client.listFiles( )) {
if( lFTPBreak ){
break Body;
}
System.out.println("lFTPBreak="+lFTPBreak+"; ");
vsHostTimeStamp = oSDateFormat.format(oFTPFile.getTimestamp( ).getTime( ));
vsHostFile = oFTPFile.getName( );
// System.out.println("vsHostFile="+vsHostFile+"; ");
d1oHostFile[i] = null;
vsLocalPath = null;
vsHostPathListTag = null;
vsLocalPathListTag = null;
vsElement = "";
if( oFTPFile.isFile( ) ){
vsElement = fvsPathListTag_File;
vsHostPathListTag = fvsPathListTag_File;
da1FileListSets.put(vsHostFile,
new String[]{fvsPathListTag_File, null, vsHostTimeStamp, null});
}else if( oFTPFile.isDirectory( ) ){
vsElement = fvsPathListTag_Folder;
vsHostPathListTag = fvsPathListTag_Folder;
da1FileListSets.put(vsHostFile,
new String[]{fvsPathListTag_Folder, null, vsHostTimeStamp, null});
// vsLocalPath = vsLocalCurrent+(vsLocalCurrent.endsWith("/") ? "" : "/")+vsHostFile;
oLocalPath = new File(vsLocalCurrent,vsHostFile);
vsLocalPath = oLocalPath.getCanonicalPath( );
if( 0==vsHostFile.compareTo("..") ){
System.out.println("if( 0==vsHostFile.compareTo(..) )");
vsHostFile = "";
}
// oLocalPath = new File(vsLocalPath);
if( ! oLocalPath.exists( ) ){
oLocalPath.mkdir();
}
}
d1oHostFile[i] = oFTPFile;
d1vsHostFile[i] = vsHostFile;
vsElement = vsElement+vsHostFile;
System.out.println(
"vsHostPathListTag="+vsHostPathListTag+"; "+
"vsHostFile="+vsHostFile+"; "+
"vsHostTimeStamp="+vsHostTimeStamp+"; "+
"vsElement="+vsElement+"; "+
"");
i++;
}
// String[] d1vsSnapShotFile = new String[d1oHostFile[i].length];
// HashMap<String, String> da1SnapShotSets = new HashMap<String, String>( );
// ArrayList<String> dl1vsSnapShotFile = new ArrayList<String>( );
// ArrayList<String> dl1vsSnapShotTimeStamp = new ArrayList<String>( );
String[] d1svFileInform;
System.out.println("◆BufferedReader oBRFTPSnapShot");
if( null!=da1FileListSets.get(fvsFTPSnapShotFile) ){
// 「client.retrieveFileStream( )」による Stream で WorkingDirectory が null になってしまう場合があるようだ。
// client.setFileType(FTP.BINARY_FILE_TYPE);
// client.setFileType(FTP.ASCII_FILE_TYPE);
FTPDownloadFile( fvsFTPSnapShotFile, vsHostCurrent, "", FTP.ASCII_FILE_TYPE );
System.out.println(
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
FileInputStream oFISFTPSnapShot = new FileInputStream(fvsFTPSnapShotFile);
InputStreamReader oISRFTPSnapShot = new InputStreamReader(oFISFTPSnapShot);
BufferedReader oBRFTPSnapShot = new BufferedReader(oISRFTPSnapShot);
Pattern pattern = Pattern.compile(fvsReg_PathListTag_File+"(.*)"+fvsReg_PathListTag_TimeStamp+"(.*)$");
vsFTPSnapShotLine = "";
i = 0;
while(true){
if( lFTPBreak ){
break Body;
}
System.out.println("lFTPBreak="+lFTPBreak+"; ");
vsFTPSnapShotLine = oBRFTPSnapShot.readLine( );
if( null==vsFTPSnapShotLine ){
break;
}
matcher = pattern.matcher(vsFTPSnapShotLine);
if( matcher.find( ) ){
vsSnapShotPath = matcher.group(1);
vsSnapShotTimeStamp = matcher.group(2);
d1svFileInform = da1FileListSets.get(vsSnapShotPath);
vsHostPathListTag = d1svFileInform[0];
vsHostTimeStamp = d1svFileInform[2];
System.out.println(
"i="+i+"; "+
"vsHostPathListTag="+vsHostPathListTag+"; "+
"vsSnapShotPath="+vsSnapShotPath+"; "+
"vsHostTimeStamp="+vsHostTimeStamp+"; "+
"");
if( 0==fvsPathListTag_File.compareTo(vsHostPathListTag) &&
0==vsSnapShotTimeStamp.compareTo(vsHostTimeStamp) ){
d1svFileInform[1] = vsSnapShotTimeStamp;
d1svFileInform[2] = null;
da1FileListSets.put(vsSnapShotPath, d1svFileInform);
System.out.println(
"vsSnapShotTimeStamp="+vsSnapShotTimeStamp+"; "+
"");
}
// dl1vsSnapShotFile.add(vsSnapShotPath);
// d1svFileInform = da1FileListSets.get(matcher.group(1));
// da1SnapShotSets.put(matcher.group(1), matcher.group(2));
i++;
}
}
oBRFTPSnapShot.close( );
}
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
client.changeWorkingDirectory(vsHostCurrent);
System.out.println("client.printWorkingDirectory="+client.printWorkingDirectory( )+"; ");
System.out.println("◆oLocalCurrent.listFiles( )");
// File[] d1oLocalFile = new File[oLocalCurrent.listFiles().length];
File oLocalCurrent = new File(vsLocalCurrent);
vsHostPathListTag = "";
vsLocalPathListTag = "";
vsLocalTimeStamp = "";
i = 0;
vsLocalTimeStamp = "";
i = 0;
for (File oFile : oLocalCurrent.listFiles( )) {
if( lFTPBreak ){
break Body;
}
vsLocalTimeStamp = oSDateFormat.format(oFile.lastModified( ));
vsLocalFile = oFile.getName( );
System.out.println(
"lFTPBreak="+lFTPBreak+"; "+
"vsLocalFile="+vsLocalFile+"; "+
"vsLocalTimeStamp="+vsLocalTimeStamp+"; "+
"");
vsLocalPathListTag = fvsPathListTag_File;
d1svFileInform = da1FileListSets.get(vsLocalFile);
vsPathListTag = null;
vsSnapShotTimeStamp = null;
vsHostTimeStamp = null;
if(null!=d1svFileInform){
vsPathListTag = d1svFileInform[0];
vsSnapShotTimeStamp = d1svFileInform[1];
vsHostTimeStamp = d1svFileInform[2];
}
System.out.println(
"d1svFileInform="+d1svFileInform+"; "+
"vsPathListTag="+vsPathListTag+"; "+
"vsLocalFile="+vsLocalFile+"; "+
"vsSnapShotTimeStamp="+vsSnapShotTimeStamp+"; "+
"vsHostTimeStamp="+vsHostTimeStamp+"; "+
"");
vsElement = "";
if( oFile.isFile( ) ){
vsLocalPathListTag = fvsPathListTag_File;
}
if( oFile.isDirectory( ) ){
vsLocalPathListTag = fvsPathListTag_Folder;
}
if( null==vsPathListTag ){
vsPathListTag = vsLocalPathListTag;
}
if( 0!=vsLocalPathListTag.compareTo(vsPathListTag) ){
PutMessage(vsProcessName+":Error.\n");
PutMessage("PathListTag="+vsPathListTag+"\n");
PutMessage("LocalPathListTag="+vsLocalPathListTag+"\n");
PutMessage("HostCurrent="+vsHostCurrent+"\n");
PutMessage("LocalCurrent="+vsLocalCurrent+"\n");
PutMessage("LocalFile="+vsLocalFile+"\n");
vsPathListTag = fvsPathListTag_Error;
}
da1FileListSets.put(vsLocalFile,
new String[]{vsPathListTag, vsSnapShotTimeStamp, vsHostTimeStamp, vsLocalTimeStamp});
if( 0==fvsPathListTag_Folder.compareTo(vsPathListTag) ){
if( null==vsSnapShotTimeStamp && null==vsHostTimeStamp &&
null!=vsLocalTimeStamp ){
client.makeDirectory(vsLocalFile);
}
}
i++;
}
System.out.println("◆da1FileListSets.keySet( )");
// PutMessage("◆da1FileListSets.keySet( )"+"\n"); // dbg //
System.out.println(
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
// dbg //
// PutMessage(
// "vsHostCurrent="+vsHostCurrent+"; "+
// "vsLocalCurrent="+vsLocalCurrent+"; "+
// "\n");
for ( String vsFileListKeySet : da1FileListSets.keySet( ) ) {
if( lFTPBreak ){
break Body;
}
if( 0!=fvsFTPSnapShotFile.compareTo(vsFileListKeySet) ){
d1svFileInform = da1FileListSets.get(vsFileListKeySet);
vsPathListTag = d1svFileInform[0];
vsSnapShotTimeStamp = d1svFileInform[1];
vsHostTimeStamp = d1svFileInform[2];
vsLocalTimeStamp = d1svFileInform[3];
System.out.println("◆Operation.");
System.out.println(
"lFTPBreak="+lFTPBreak+"; "+
"vsPathListTag="+vsPathListTag+"; "+
"vsFileListKeySet="+vsFileListKeySet+"; "+
"vsSnapShotTimeStamp="+vsSnapShotTimeStamp+"; "+
"vsHostTimeStamp="+vsHostTimeStamp+"; "+
"vsLocalTimeStamp="+vsLocalTimeStamp+"; "+
"");
if( null!=vsPathListTag &&
0==fvsPathListTag_File.compareTo(vsPathListTag) ){
if( null!=vsSnapShotTimeStamp ){
if( null==vsLocalTimeStamp ){
// Download
System.out.println("▼ 1 Download.");
// PutMessage("▼ 1 Download."+"\n"); // dbg //
FTPDownloadFile(vsFileListKeySet, vsHostCurrent,vsLocalCurrent, -1);
}else if( vsSnapShotTimeStamp.compareTo(vsLocalTimeStamp)<0 ){
// Upload
System.out.println("▲ 2 Upload.");
// PutMessage("▲ 2 Upload."+"\n"); // dbg //
FTPUploadFile(vsFileListKeySet, vsHostCurrent,vsLocalCurrent, -1);
}
}else if( null!=vsHostTimeStamp ){
if( null==vsLocalTimeStamp ||
vsHostTimeStamp.compareTo(vsLocalTimeStamp)>0 ){
// Download
System.out.println("▼ 3 Download.");
// PutMessage("▼ 3 Download."+"\n"); // dbg //
FTPDownloadFile(vsFileListKeySet, vsHostCurrent,vsLocalCurrent, -1);
}else if( vsHostTimeStamp.compareTo(vsLocalTimeStamp)<0 ){
// Upload
System.out.println("▲ 4 Upload.");
// PutMessage("▲ 4 Upload."+"\n"); // dbg //
FTPUploadFile(vsFileListKeySet, vsHostCurrent,vsLocalCurrent, -1);
}
}else {
if( null==vsLocalTimeStamp ){
PutMessage("Program:Error.\n");
PutMessage(vsProcessName+".\n");
PutMessage("PathListTag="+vsPathListTag+"\n");
PutMessage("LocalPathListTag="+vsLocalPathListTag+"\n");
PutMessage("HostCurrent="+vsHostCurrent+"\n");
PutMessage("LocalCurrent="+vsLocalCurrent+"\n");
PutMessage("LocalFile="+vsLocalFile+"\n");
}else{
// Upload
System.out.println("▲ 5 Upload.");
// PutMessage("▲ 5 Upload."+"\n"); // dbg //
FTPUploadFile(vsFileListKeySet, vsHostCurrent,vsLocalCurrent, -1);
}
}
}
}
}
PutMessage(client.getReplyString( ));
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
PutMessage(vsProcessName+" Completed.\n");
String vsMsg = "Connection Check => " + (lFTPConnection ? "OK." : "NG:一旦 Logout してみて下さい。");
PutMessage(vsMsg+"\n");
for ( String vsFileListKeySet : da1FileListSets.keySet( ) ) {
if( lFTPBreak ){
break Body;
}
d1svFileInform = da1FileListSets.get(vsFileListKeySet);
vsPathListTag = d1svFileInform[0];
System.out.println(
"lFTPBreak="+lFTPBreak+"; "+
"vsPathListTag="+vsPathListTag+"; "+
"vsFileListKeySet="+vsFileListKeySet+"; "+
"");
if( 0==fvsPathListTag_Folder.compareTo(vsPathListTag) ){
FTPSynchronizeFolder( vsFileListKeySet, vsHostCurrent, vsLocalCurrent );
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:"+vsProcessName+".");
PutMessage("NumberFormatException:"+vsProcessName+".\n");
PutMessage("FTP ポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:"+vsProcessName+".");
PutMessage("SocketException:"+vsProcessName+".\n");
PutMessage("Socket 通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:"+vsProcessName+".");
PutMessage("FileNotFoundException:"+vsProcessName+".\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
try {
Pattern pattern = Pattern.compile("^/");
matcher = pattern.matcher(vsHostPrevious);
if( matcher.find( ) ){
client.changeWorkingDirectory(vsHostPrevious);
System.out.println("client.printWorkingDirectory( )="+client.printWorkingDirectory( )+"; ");
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
System.out.println("IOException:"+vsProcessName+".");
PutMessage("IOException:"+vsProcessName+".\n");
}
}
public boolean FTPThreadCheck( ){
boolean lThread = false; // true; //
if(null!=oThread_FTPDownload){
lThread = true; // false; //
System.out.println("現在、すでに FTPDownload が実行中です。");
PutMessage("現在、すでに FTPDownload が実行中です。\n");
}
if(null!=oThread_FTPUpload){
lThread = true; // false; //
System.out.println("現在、すでに FTPUpload が実行中です。");
PutMessage("現在、すでに FTPUpload が実行中です。\n");
}
if(null!=oThread_FTPSnapShot_Makera){
lThread = true; // false; //
System.out.println("現在、すでに FTPSnapShot_Makera が実行中です。");
PutMessage("現在、すでに FTPSnapShot_Makera が実行中です。\n");
}
if(null!=oThread_FTPSnapShot_Delete){
lThread = true; // false; //
System.out.println("現在、すでに FTPSnapShot_Delete が実行中です。");
PutMessage("現在、すでに FTPSnapShot_Delete が実行中です。\n");
}
if(null!=oThread_FTPSynchronize){
lThread = true; // false; //
System.out.println("現在、すでに FTPSynchronize が実行中です。");
PutMessage("現在、すでに FTPSynchronize が実行中です。\n");
}
return lThread; // true; // false; //
}
enum MouseMouseDoubleClicked_Enum { feHostFileList, feLocalFileList };
class MainPanelImplementationObj extends MainPanelDesign {
private long ilMouseDoubleClickedIntervalMax = 250; // 350; 300;
private HashMap<MouseMouseDoubleClicked_Enum, Runner_MouseMouseDoubleClicked> da1oRunnable_MouseMouseDoubleClicked =
new HashMap<MouseMouseDoubleClicked_Enum, Runner_MouseMouseDoubleClicked>( );
class Runner_MouseMouseDoubleClicked implements Runnable {
private Thread oThread;
volatile private MouseMouseDoubleClicked_Enum eMouseDoubleClicked;
// volatile:最適化の抑制.
volatile byte ibCnt_MouseEvent = 0;
MouseEvent oEvent_MouseClicked = null;
Runner_MouseMouseDoubleClicked( MouseMouseDoubleClicked_Enum eMMDC ){
eMouseDoubleClicked = eMMDC;
oThread = new Thread(this);
oThread.start();
}
void NativeMouseMousePressed(MouseEvent event) {
System.out.println("NativeMouseMousePressed( ).");
System.out.println(
"eMouseDoubleClicked.name( )="+eMouseDoubleClicked.name( )+"; "+
"ibCnt_MouseEvent="+ibCnt_MouseEvent+"; "+
"");
oEvent_MouseClicked = null;
if(oThread.getState()==Thread.State.TIMED_WAITING){
ibCnt_MouseEvent = 3;
oThread.interrupt();
}else{
ibCnt_MouseEvent = 1;
}
System.out.println(
"eMouseDoubleClicked.name( )="+eMouseDoubleClicked.name( )+"; "+
"ibCnt_MouseEvent="+ibCnt_MouseEvent+"; "+
"");
}
boolean NativeMouseMouseReleased(MouseEvent event) {
System.out.println("NativeMouseMouseReleased( ).");
System.out.println(
"eMouseDoubleClicked.name( )="+eMouseDoubleClicked.name( )+"; "+
"ibCnt_MouseEvent="+ibCnt_MouseEvent+"; "+
"");
oEvent_MouseClicked = event;
boolean lDoubleClicked = false; // true; //
if(ibCnt_MouseEvent==3){
ibCnt_MouseEvent = 0;
lDoubleClicked = true; // false; //
}else if(oThread.getState()==Thread.State.WAITING){
ibCnt_MouseEvent = 2;
synchronized(this) {
notify();
// ↑メソッドを synchronized 指定するか、
// synchronized(自分のインスタンス) ブロックで囲うかしないと
// 実行時に「IllegalMonitorStateException」が発生する。
}
}
System.out.println(
"eMouseDoubleClicked.name( )="+eMouseDoubleClicked.name( )+"; "+
"ibCnt_MouseEvent="+ibCnt_MouseEvent+"; "+
"lDoubleClicked="+lDoubleClicked+"; "+
"");
return lDoubleClicked;
}
@Override
public void run( ) {
System.out.println("run.");
boolean lInterrupted = false; // true; //
while(true){
try {
synchronized(this) {
wait( );
// ↑メソッドを synchronized 指定するか、
// synchronized(自分のインスタンス) ブロックで囲うかしないと
// 実行時に「IllegalMonitorStateException」が発生する。
}
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("wait:End.");
lInterrupted = false; // true; //
try {
Thread.sleep(ilMouseDoubleClickedIntervalMax);
} catch (InterruptedException e) {
// e.printStackTrace();
System.out.println("sleep:InterruptedException.");
lInterrupted = true; // false; //
}
System.out.println("sleep:End.");
if( ! lInterrupted &&
ibCnt_MouseEvent==2 ){
ibCnt_MouseEvent = 0;
switch(eMouseDoubleClicked){
case feHostFileList :
HostFileList_CltMouseMouseClicked(oEvent_MouseClicked);
break;
case feLocalFileList :
LocalFileList_CltMouseMouseClicked(oEvent_MouseClicked);
break;
default:
System.out.println(
"★Error:MouseDoubleClicked="+eMouseDoubleClicked.name( )+"; "+
"");
PutMessage(
"★Error:MouseDoubleClicked="+eMouseDoubleClicked.name( )+"; "+
"\n");
}
oEvent_MouseClicked = null;
}
}
}
}
MainPanelImplementationObj( ){
super( );
for( MouseMouseDoubleClicked_Enum eEnum : MouseMouseDoubleClicked_Enum.values( ) ){
da1oRunnable_MouseMouseDoubleClicked.put(eEnum,
new Runner_MouseMouseDoubleClicked(eEnum));
}
}
@Override
synchronized void FTPLogin_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostLogin_CbtMouseMouseReleased.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("FTPLogin は実行できませんでした。\n");
return;
}
oMainApp.FTPLogin( );
}
@Override
synchronized void FTPLogout_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostLogout_CbtMouseMouseReleased.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("FTPLogou は実行できませんでした。\n");
return;
}
oMainApp.FTPLogout( );
}
@Override
@SuppressWarnings("rawtypes")
synchronized void FTPDownload_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPDownload_CbtMouseMouseReleased.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("FTPDownload は実行できませんでした。\n");
return;
}
oThread_FTPDownload = new Thread( ){
@Override
public void run( ){
if( 0==((DefaultListModel)
oMainPanelImp.cltHostTransferList.getModel( )).getSize( ) ){
FTPDownload( );
}else{
FTPTransfer( FTPTransfer_Enum.feFTPDownload);
}
lFTPBreak = false; // true; //
oThread_FTPDownload = null;
}
};
oThread_FTPDownload.start();
}
@Override
@SuppressWarnings("rawtypes")
synchronized void FTPUpload_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPUpload_CbtMouseMouseReleased.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("FTPUpload は実行できませんでした。\n");
return;
}
oThread_FTPUpload = new Thread( ){
@Override
public void run( ){
if( 0==((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( ) ){
FTPUpload( );
}else{
FTPTransfer( FTPTransfer_Enum.feFTPUpload );
}
lFTPBreak = false; // true; //
oThread_FTPUpload = null;
}
};
oThread_FTPUpload.start();
}
synchronized void HostFileList_CltMouseMouseClicked(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CltMouseMouseClicked.");
}
synchronized void HostFileList_CltMouseMouseDoubleClicked(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CltMouseMouseDoubleClicked.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("HostFileList は実行できませんでした。\n");
return;
}
Pattern pattern = null;
String vsTargetFile = null;
if( ! oMainPanelImp.cltHostFileList.isSelectionEmpty( ) ){
vsTargetFile = (String)oMainPanelImp.cltHostFileList.getSelectedValue( );
pattern = Pattern.compile("^("+fvsReg_PathListTag_Folder+")");
matcher = pattern.matcher(vsTargetFile);
if(matcher.find()){
vsTargetFile = matcher.replaceAll("");
System.out.println("vsTargetFile = "+vsTargetFile+"; ");
HostFileList(vsTargetFile, true); // lTabSelected : true; / false; //
}
}else{
vsTargetFile = null;
PutMessage("HostFileList で項目が選択せれていません.\n");
}
}
@Override
void HostFileList_CltNativeMouseMousePressed(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CltNativeMouseMousePressed");
da1oRunnable_MouseMouseDoubleClicked.get(
MouseMouseDoubleClicked_Enum.feHostFileList).NativeMouseMousePressed(event);
}
@Override
void HostFileList_CltNativeMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CltNativeMouseMouseReleased.");
boolean lDoubleClicked = da1oRunnable_MouseMouseDoubleClicked.get(
MouseMouseDoubleClicked_Enum.feHostFileList).NativeMouseMouseReleased(event);
if( lDoubleClicked ){
HostFileList_CltMouseMouseDoubleClicked(event);
}
}
synchronized void LocalFileList_CltMouseMouseClicked(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CltMouseMouseClicked.");
}
synchronized void LocalFileList_CltMouseMouseDoubleClicked(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CltMouseMouseDoubleClicked.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("LocalFileList は実行できませんでした。\n");
return;
}
Pattern pattern = null;
String vsTargetFile = null;
if( ! oMainPanelImp.cltLocalFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltLocalFileList.getSelectedValue();
pattern = Pattern.compile("^("+fvsReg_PathListTag_Folder+")");
matcher = pattern.matcher(vsTargetFile);
if(matcher.find()){
vsTargetFile = matcher.replaceAll("");
System.out.println("vsTargetFile = "+vsTargetFile+"; ");
LocalFileList(vsTargetFile, true); // lTabSelected : true; / false; //
}
}else{
vsTargetFile = null;
PutMessage("LocalFileList で項目が選択せれていません.\n");
}
}
@Override
void LocalFileList_CltNativeMouseMousePressed(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CltNativeMouseMousePressed");
da1oRunnable_MouseMouseDoubleClicked.get(
MouseMouseDoubleClicked_Enum.feLocalFileList).NativeMouseMousePressed(event);
}
@Override
void LocalFileList_CltNativeMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CltNativeMouseMouseReleased");
boolean lDoubleClicked = da1oRunnable_MouseMouseDoubleClicked.get(
MouseMouseDoubleClicked_Enum.feLocalFileList).NativeMouseMouseReleased(event);
if( lDoubleClicked ){
LocalFileList_CltMouseMouseDoubleClicked(event);
}
}
@Override
synchronized void SetupFileList_HostFolder_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:SetupFileList_HostFolder_CbtMouseMouseReleased.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("HostFileList は実行できませんでした。\n");
return;
}
HostFileList(null, true); // lTabSelected : true; / false; //
}
@Override
synchronized void SetupFileList_LocalFolder_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:SetupFileList_LocalFolder_CbtMouseMouseReleased.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("LocalFileList は実行できませんでした。\n");
return;
}
LocalFileList(null, true); // lTabSelected : true; / false; //
}
@Override
void FTPBreak_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPBreak_CbtMouseMouseReleased.");
lFTPBreak = true; // false; //
System.out.println("lFTPBreak="+lFTPBreak+"; ");
}
@Override
synchronized void TransferList_Entry_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:TransferListEntry_CbtMouseMouseReleased.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("TransferList_Entry は実行できませんでした。\n");
return;
}
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).addElement(
ctfHostFolder.getText( ));
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).addElement(
ctfLocalFolder.getText( ));
}
@Override
synchronized void TransferList_Delete_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:TransferListDelete_CbtMouseMouseReleased.");
int iSelectedIndex = -1;
JScrollPane oTabSelectedComponent = (JScrollPane)oMainPanelImp.ctpTransferListTabs.getSelectedComponent( );
// JScrollPane には暗黙の子 JViewport が存在し、
// 「JScrollPane.getViewport( ) 」で(暗黙の子) JViewport のインスタンスを取得できる。
// つまり、この場合の JList の親は JViewport となる。
// ちなみに、この場合の JList の親の親が JScrollPane となる。
if( oTabSelectedComponent.getViewport( )==oMainPanelImp.cltHostTransferList.getParent( ) ){
System.out.println("if(oTabSelectedComponent.getViewport( )==cltHostTransferList.getParent( )).");
if( oMainPanelImp.cltHostTransferList.isSelectionEmpty( ) ){
PutMessage("cltHostTransferList:表示されているタブに選択されている項目がありません。\n");
}else{
iSelectedIndex = oMainPanelImp.cltHostTransferList.getSelectedIndex( );
}
}
if( oTabSelectedComponent.getViewport( )==oMainPanelImp.cltLocalTransferList.getParent( ) ){
System.out.println("(oTabSelectedComponent.getViewport( )==cltLocalTransferList.getParent( )).");
if( oMainPanelImp.cltLocalTransferList.isSelectionEmpty( ) ){
PutMessage("cltLocalTransferList:表示されているタブに選択されている項目がありません。\n");
}else{
iSelectedIndex = oMainPanelImp.cltLocalTransferList.getSelectedIndex( );
}
}
System.out.println("iSelectedIndex="+iSelectedIndex+"; ");
if( 0<=iSelectedIndex ){
System.out.println("if( 0<=iSelectedIndex )");
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).remove(iSelectedIndex);
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).remove(iSelectedIndex);
}
}
@Override
synchronized void FTPSnapShot_Makera_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPSnapShot_Make_CbtMouseMouseReleased.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("FTPSnapShot_Makera は実行できませんでした。\n");
return;
}
oThread_FTPSnapShot_Makera = new Thread( ){
@Override
public void run( ){
if( 0==((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( ) ){
FTPSnapShot(true); // lMakera : true; / false;
}else{
FTPTransfer( FTPTransfer_Enum.feFTPSnapShot_Makera );
}
lFTPBreak = false; // true; //
oThread_FTPSnapShot_Makera = null;
}
};
oThread_FTPSnapShot_Makera.start();
}
@Override
synchronized void FTPSnapShot_Delete_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPSnapShot_Make_CbtMouseMouseReleased.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("FTPSnapShot_Delete は実行できませんでした。\n");
return;
}
oThread_FTPSnapShot_Delete = new Thread( ){
@Override
public void run( ){
if( 0==((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( ) ){
FTPSnapShot(false); // lMakera : true; / false;
}else{
FTPTransfer( FTPTransfer_Enum.feFTPSnapShot_Delete );
}
lFTPBreak = false; // true; //
oThread_FTPSnapShot_Delete = null;
}
};
oThread_FTPSnapShot_Delete.start();
}
@Override
@SuppressWarnings("rawtypes")
synchronized void FTPSynchronize_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:Synchronize_CbtMouseMouseReleased.");
if( oMainApp.FTPThreadCheck( ) ){
PutMessage("FTPSynchronize は実行できませんでした。\n");
return;
}
oThread_FTPSynchronize = new Thread( ){
@Override
public void run( ){
if( 0==((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( ) ){
FTPSynchronize( );
}else{
FTPTransfer( FTPTransfer_Enum.feFTPSynchronize );
}
lFTPBreak = false; // true; //
oThread_FTPSynchronize = null;
}
};
oThread_FTPSynchronize.start();
}
}
static class MainAppFrameObj extends JFrame implements Runnable {
// JApplet oApplet;
Thread oAppThread;
public MainAppFrameObj( ) {
super("Application frame.");
//setVisible(false);
System.out.println("Construct:Application frame window.");
// oApplet = oEntApplet; // new JAppletcation();
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent event){
// ユーザーがウインドウを閉じようとした時].
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosing.");
oMainApp.FTPLogout();
Close();
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowClosed(WindowEvent event){
// ウインドウが閉じた時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosed.");
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowDeiconified(WindowEvent event){
// ウィンドウが最小化された状態から通常の状態に変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowDeiconified.");
oMainApp.repaint();
}
}
}
);
addComponentListener(
new ComponentAdapter(){
public void componentResized(ComponentEvent event){
// コンポーネントのサイズが変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("ComponentEvent:componentResized.");
System.out.println("MainAppFrameObj:"+
"width="+Integer.toString(MainAppFrameObj.this.getSize( ).width)+"; "+
"Height="+Integer.toString(MainAppFrameObj.this.getSize( ).height)+"; "+
"");
oMainApp.repaint();
}
}
}
);
getContentPane().add(oMainApp,"Center");
oAppThread = new Thread(this);
}
public synchronized void setPreSize(Dimension oSize){
// dispose();
getContentPane().setPreferredSize(oSize);
pack();
setVisible(true);
requestFocus();
}
public synchronized void run(){
System.out.println("Open:Application frame window.");
oMainApp.init();
oMainApp.start();
oMainApp.repaint();
try{
wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
oMainApp.stop();
oMainApp.destroy();
oAppThread = null;
}
public synchronized void Close(){
System.out.println("Close:Application frame window.");
dispose();
notify();
}
}
}
|
|
|
<Number>: [00000977]
<Date>: 2015/12/31 17:51:41
<Title>:
<Name>: amanojaku@管理人
|
|
|
『MainPanelDesign.java』
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.dyno.visual.swing.layouts.Bilateral;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class MainPanelDesign extends JPanel {
private static final long serialVersionUID = 1L;
private JButton cbtHostLogin;
private JButton cbtHostLogout;
private JButton cbtFTPUpload;
private JButton cbtFTPBreak;
private JButton cbtFTPDownload;
private JButton cbtSetupFileList_HostFolder;
private JButton cbtSetupFileList_LocalFolder;
private JButton cbtTransferList_Delete;
private JButton cbtTransferList_Entry;
private JButton cbtFTPSnapShot_Make;
private JButton cbtFTPSnapShot_Delete;
private JButton cbtFTPSynchronize;
JTextField ctfHostUserName;
JTextField ctfHostName;
JPasswordField cpfHostPassword;
JTextField ctfHostFolder;
JTextField ctfLocalFolder;
JTextField ctfHostPortNum;
JTextArea ctaMessage;
JList cltHostFileList;
JList cltLocalFileList;
JComboBox ccbFTPFileDataType;
JTabbedPane ctpFileListTabs;
JCheckBox cckHostPASVMode;
JComboBox ccbHostEncode;
JPanel cpnFTPSetting;
JTabbedPane ctpBaseTabs;
JList cltHostTransferList;
JList cltLocalTransferList;
JTabbedPane ctpTransferListTabs;
private JLabel jLabel2;
private JLabel jLabel6;
private JLabel jLabel5;
private JLabel jLabel0;
private JLabel jLabel1;
private JLabel jLabel7;
private JLabel jLabel9;
private JScrollPane jScrollPane0;
private JScrollPane jScrollPane1;
private JScrollPane jScrollPane2;
private JScrollPane jScrollPane3;
private JScrollPane jScrollPane4;
private JLabel jLabel3;
private JLabel jLabel4;
public MainPanelDesign() {
initComponents();
}
private void initComponents() {
setMinimumSize(new Dimension(479, 400));
setPreferredSize(new Dimension(479, 400));
setLayout(new GroupLayout());
add(getCbtHostLogin(), new Constraints(new Leading(10, 72, 75, 282), new Leading(254, 12, 12)));
add(getJLabel7(), new Constraints(new Leading(289, 12, 12), new Leading(195, 12, 12)));
add(getCtpBaseTabs(), new Constraints(new Leading(8, 271, 23, 23), new Leading(7, 237, 10, 10)));
add(getJLabel3(), new Constraints(new Leading(289, 12, 12), new Leading(15, 87, 177)));
add(getCtpTransferListTabs(), new Constraints(new Bilateral(289, 12, 57), new Leading(46, 139, 10, 10)));
add(getCbtHostLogout(), new Constraints(new Leading(94, 12, 12), new Leading(254, 12, 12)));
add(getCbtTransferList_Entry(), new Constraints(new Leading(368, 12, 12), new Leading(10, 12, 12)));
add(getCbtTransferList_Delete(), new Constraints(new Leading(443, 12, 12), new Leading(10, 12, 12)));
add(getCcbFTPFileDataType(), new Constraints(new Leading(135, 12, 12), new Leading(292, 12, 12)));
add(getJLabel9(), new Constraints(new Leading(10, 12, 12), new Leading(295, 18, 12, 12)));
add(getCbtSetupFileList_HostFolder(), new Constraints(new Leading(8, 12, 12), new Leading(330, 12, 12)));
add(getCtfHostFolder(), new Constraints(new Leading(135, 144, 12, 12), new Leading(333, 12, 12)));
add(getCbtSetupFileList_LocalFolder(), new Constraints(new Leading(8, 12, 12), new Leading(368, 12, 12)));
add(getCtfLocalFolder(), new Constraints(new Leading(136, 144, 12, 12), new Leading(371, 12, 12)));
add(getCbtFTPSynchronize(), new Constraints(new Leading(10, 12, 12), new Leading(445, 10, 10)));
add(getJLabel4(), new Constraints(new Leading(8, 12, 12), new Leading(411, 12, 12)));
add(getCbtFTPUpload(), new Constraints(new Leading(228, 12, 12), new Leading(445, 12, 12)));
add(getCbtFTPDownload(), new Constraints(new Leading(126, 12, 12), new Leading(445, 12, 12)));
add(getCbtFTPBreak(), new Constraints(new Leading(313, 12, 12), new Leading(445, 12, 12)));
add(getCtpFileListTabs(), new Constraints(new Leading(289, 266, 10, 10), new Leading(217, 220, 10, 10)));
add(getCbtFTPSnapShot_Delete(), new Constraints(new Leading(172, 12, 12), new Leading(406, 12, 12)));
add(getCbtFTPSnapShot_Make(), new Constraints(new Leading(94, 12, 12), new Leading(406, 12, 12)));
setSize(565, 486);
}
private JButton getCbtFTPSynchronize() {
if (cbtFTPSynchronize == null) {
cbtFTPSynchronize = new JButton();
cbtFTPSynchronize.setText("Synchronize");
cbtFTPSynchronize.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPSynchronize_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPSynchronize;
}
private JButton getJButton0() {
if (cbtFTPSynchronize == null) {
cbtFTPSynchronize = new JButton();
cbtFTPSynchronize.setText("Synchronize");
}
return cbtFTPSynchronize;
}
private JLabel getJLabel4() {
if (jLabel4 == null) {
jLabel4 = new JLabel();
jLabel4.setText("FTPSnapShot");
}
return jLabel4;
}
private JButton getCbtFTPSnapShot_Delete() {
if (cbtFTPSnapShot_Delete == null) {
cbtFTPSnapShot_Delete = new JButton();
cbtFTPSnapShot_Delete.setText("Delete");
cbtFTPSnapShot_Delete.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPSnapShot_Delete_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPSnapShot_Delete;
}
private JButton getCbtFTPSnapShot_Make() {
if (cbtFTPSnapShot_Make == null) {
cbtFTPSnapShot_Make = new JButton();
cbtFTPSnapShot_Make.setText("Make");
cbtFTPSnapShot_Make.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPSnapShot_Makera_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPSnapShot_Make;
}
private JLabel getJLabel3() {
if (jLabel3 == null) {
jLabel3 = new JLabel();
jLabel3.setText("TransferList");
}
return jLabel3;
}
private JScrollPane getJScrollPane4() {
if (jScrollPane4 == null) {
jScrollPane4 = new JScrollPane();
jScrollPane4.setViewportView(getCltLocalTransferList());
}
return jScrollPane4;
}
private JList getCltLocalTransferList() {
if (cltLocalTransferList == null) {
cltLocalTransferList = new JList();
DefaultListModel listModel = new DefaultListModel();
cltLocalTransferList.setModel(listModel);
}
return cltLocalTransferList;
}
private JScrollPane getJScrollPane3() {
if (jScrollPane3 == null) {
jScrollPane3 = new JScrollPane();
jScrollPane3.setViewportView(getCltHostTransferList());
}
return jScrollPane3;
}
private JList getCltHostTransferList() {
if (cltHostTransferList == null) {
cltHostTransferList = new JList();
DefaultListModel listModel = new DefaultListModel();
cltHostTransferList.setModel(listModel);
}
return cltHostTransferList;
}
private JButton getCbtTransferList_Entry() {
if (cbtTransferList_Entry == null) {
cbtTransferList_Entry = new JButton();
cbtTransferList_Entry.setText("Entry");
cbtTransferList_Entry.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
TransferList_Entry_CbtMouseMouseReleased(event);
}
});
}
return cbtTransferList_Entry;
}
private JButton getCbtTransferList_Delete() {
if (cbtTransferList_Delete == null) {
cbtTransferList_Delete = new JButton();
cbtTransferList_Delete.setText("Delete");
cbtTransferList_Delete.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
TransferList_Delete_CbtMouseMouseReleased(event);
}
});
}
return cbtTransferList_Delete;
}
private JTabbedPane getCtpTransferListTabs() {
if (ctpTransferListTabs == null) {
ctpTransferListTabs = new JTabbedPane();
ctpTransferListTabs.addTab("Host", getJScrollPane3());
ctpTransferListTabs.addTab("Local", getJScrollPane4());
}
return ctpTransferListTabs;
}
private JTabbedPane getCtpBaseTabs() {
if (ctpBaseTabs == null) {
ctpBaseTabs = new JTabbedPane();
ctpBaseTabs.addTab("FTP", getCpnFTPSetting());
ctpBaseTabs.addTab("Message", getJScrollPane0());
}
return ctpBaseTabs;
}
private JPanel getCpnFTPSetting() {
if (cpnFTPSetting == null) {
cpnFTPSetting = new JPanel();
cpnFTPSetting.setLayout(new GroupLayout());
cpnFTPSetting.add(getJLabel1(), new Constraints(new Leading(7, 12, 12), new Leading(42, 134, 134)));
cpnFTPSetting.add(getJLabel2(), new Constraints(new Leading(7, 12, 12), new Leading(176, 12, 12)));
cpnFTPSetting.add(getJLabel6(), new Constraints(new Leading(7, 12, 12), new Leading(140, 12, 12)));
cpnFTPSetting.add(getJLabel5(), new Constraints(new Leading(7, 12, 12), new Leading(74, 12, 12)));
cpnFTPSetting.add(getCckHostPASVMode(), new Constraints(new Leading(7, 12, 12), new Leading(8, 12, 12)));
cpnFTPSetting.add(getCtfHostName(), new Constraints(new Leading(96, 142, 10, 10), new Leading(72, 12, 12)));
cpnFTPSetting.add(getCpfHostPassword(), new Constraints(new Leading(97, 140, 12, 12), new Leading(172, 12, 12)));
cpnFTPSetting.add(getCtfHostPortNum(), new Constraints(new Leading(96, 142, 12, 12), new Leading(104, 12, 12)));
cpnFTPSetting.add(getJLabel0(), new Constraints(new Leading(7, 12, 12), new Leading(106, 12, 12)));
cpnFTPSetting.add(getCtfHostUserName(), new Constraints(new Leading(97, 142, 12, 12), new Leading(138, 12, 12)));
cpnFTPSetting.add(getCcbHostEncode(), new Constraints(new Leading(96, 12, 12), new Leading(38, 12, 12)));
}
return cpnFTPSetting;
}
private JButton getCbtFTPBreak() {
if (cbtFTPBreak == null) {
cbtFTPBreak = new JButton();
cbtFTPBreak.setText("Break");
cbtFTPBreak.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPBreak_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPBreak;
}
private JComboBox getCcbHostEncode() {
if (ccbHostEncode == null) {
ccbHostEncode = new JComboBox();
ccbHostEncode.setModel(new DefaultComboBoxModel(new Object[] { "UTF-8", "Windows", "EUC-JP", "ASCII" }));
ccbHostEncode.setDoubleBuffered(false);
ccbHostEncode.setBorder(null);
}
return ccbHostEncode;
}
private JButton getCbtSetupFileList_HostFolder() {
if (cbtSetupFileList_HostFolder == null) {
cbtSetupFileList_HostFolder = new JButton();
cbtSetupFileList_HostFolder.setText("HostFolder >");
cbtSetupFileList_HostFolder.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
SetupFileList_HostFolder_CbtMouseMouseReleased(event);
}
});
}
return cbtSetupFileList_HostFolder;
}
private JButton getCbtSetupFileList_LocalFolder() {
if (cbtSetupFileList_LocalFolder == null) {
cbtSetupFileList_LocalFolder = new JButton();
cbtSetupFileList_LocalFolder.setText("LocalFolder >");
cbtSetupFileList_LocalFolder.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
SetupFileList_LocalFolder_CbtMouseMouseReleased(event);
}
});
}
return cbtSetupFileList_LocalFolder;
}
private JButton getCbtFTPUpload() {
if (cbtFTPUpload == null) {
cbtFTPUpload = new JButton();
cbtFTPUpload.setText("Upload");
cbtFTPUpload.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPUpload_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPUpload;
}
private JComboBox getCcbFTPFileDataType() {
if (ccbFTPFileDataType == null) {
ccbFTPFileDataType = new JComboBox();
ccbFTPFileDataType.setModel(new DefaultComboBoxModel(new Object[] { "Binary", "ASCII" }));
ccbFTPFileDataType.setDoubleBuffered(false);
ccbFTPFileDataType.setBorder(null);
}
return ccbFTPFileDataType;
}
private JLabel getJLabel9() {
if (jLabel9 == null) {
jLabel9 = new JLabel();
jLabel9.setText("FileDtata");
}
return jLabel9;
}
private JCheckBox getCckHostPASVMode() {
if (cckHostPASVMode == null) {
cckHostPASVMode = new JCheckBox();
cckHostPASVMode.setSelected(true);
cckHostPASVMode.setText("PASVMode");
}
return cckHostPASVMode;
}
private JList getCltLocalFileList() {
if (cltLocalFileList == null) {
cltLocalFileList = new JList();
cltLocalFileList.setBackground(Color.white);
DefaultListModel listModel = new DefaultListModel();
cltLocalFileList.setModel(listModel);
cltLocalFileList.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
LocalFileList_CltNativeMouseMousePressed(event);
}
public void mouseReleased(MouseEvent event) {
LocalFileList_CltNativeMouseMouseReleased(event);
}
});
}
return cltLocalFileList;
}
private JLabel getJLabel7() {
if (jLabel7 == null) {
jLabel7 = new JLabel();
jLabel7.setText("FileList");
}
return jLabel7;
}
private JTabbedPane getCtpFileListTabs() {
if (ctpFileListTabs == null) {
ctpFileListTabs = new JTabbedPane();
ctpFileListTabs.addTab("Host", getJScrollPane1());
ctpFileListTabs.addTab("Local", getJScrollPane2());
}
return ctpFileListTabs;
}
private JScrollPane getJScrollPane2() {
if (jScrollPane2 == null) {
jScrollPane2 = new JScrollPane();
jScrollPane2.setBackground(Color.white);
jScrollPane2.setViewportView(getCltLocalFileList());
}
return jScrollPane2;
}
private JList getJList0() {
if (cltLocalFileList == null) {
cltLocalFileList = new JList();
DefaultListModel listModel = new DefaultListModel();
listModel.addElement("item0");
listModel.addElement("item1");
listModel.addElement("item2");
listModel.addElement("item3");
cltLocalFileList.setModel(listModel);
}
return cltLocalFileList;
}
private JLabel getJLabel1() {
if (jLabel1 == null) {
jLabel1 = new JLabel();
jLabel1.setText("HostEncode");
}
return jLabel1;
}
private JButton getCbtFTPDownload() {
if (cbtFTPDownload == null) {
cbtFTPDownload = new JButton();
cbtFTPDownload.setText("Download");
cbtFTPDownload.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
FTPDownload_CbtMouseMouseReleased(event);
}
});
}
return cbtFTPDownload;
}
private JScrollPane getJScrollPane1() {
if (jScrollPane1 == null) {
jScrollPane1 = new JScrollPane();
jScrollPane1.setEnabled(false);
jScrollPane1.setViewportView(getCltHostFileList());
}
return jScrollPane1;
}
private JList getCltHostFileList() {
if (cltHostFileList == null) {
cltHostFileList = new JList();
DefaultListModel listModel = new DefaultListModel();
cltHostFileList.setModel(listModel);
cltHostFileList.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
HostFileList_CltNativeMouseMousePressed(event);
}
public void mouseReleased(MouseEvent event) {
HostFileList_CltNativeMouseMouseReleased(event);
}
});
}
return cltHostFileList;
}
private JScrollPane getJScrollPane0() {
if (jScrollPane0 == null) {
jScrollPane0 = new JScrollPane();
jScrollPane0.setViewportView(getCtaMessage());
}
return jScrollPane0;
}
private JTextArea getCtaMessage() {
if (ctaMessage == null) {
ctaMessage = new JTextArea();
}
return ctaMessage;
}
private JTextField getCtfHostPortNum() {
if (ctfHostPortNum == null) {
ctfHostPortNum = new JTextField();
}
return ctfHostPortNum;
}
private JLabel getJLabel0() {
if (jLabel0 == null) {
jLabel0 = new JLabel();
jLabel0.setText("PortNo");
}
return jLabel0;
}
private JLabel getJLabel5() {
if (jLabel5 == null) {
jLabel5 = new JLabel();
jLabel5.setText("HostName");
}
return jLabel5;
}
private JLabel getJLabel6() {
if (jLabel6 == null) {
jLabel6 = new JLabel();
jLabel6.setText("UserName");
}
return jLabel6;
}
private JTextField getCtfLocalFolder() {
if (ctfLocalFolder == null) {
ctfLocalFolder = new JTextField();
ctfLocalFolder.setBackground(Color.white);
ctfLocalFolder.setText("");
}
return ctfLocalFolder;
}
private JButton getCbtHostLogin() {
if (cbtHostLogin == null) {
cbtHostLogin = new JButton();
cbtHostLogin.setText("Login");
cbtHostLogin.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
HostLogin_CbtMouseMouseReleased(event);
}
});
}
return cbtHostLogin;
}
private JTextField getCtfHostFolder() {
if (ctfHostFolder == null) {
ctfHostFolder = new JTextField();
ctfHostFolder.setBackground(Color.white);
}
return ctfHostFolder;
}
private JButton getCbtHostLogout() {
if (cbtHostLogout == null) {
cbtHostLogout = new JButton();
cbtHostLogout.setText("Logout");
cbtHostLogout.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
HostLogout_CbtMouseMouseReleased(event);
}
});
}
return cbtHostLogout;
}
private JLabel getJLabel2() {
if (jLabel2 == null) {
jLabel2 = new JLabel();
jLabel2.setText("Password");
}
return jLabel2;
}
private JTextField getCtfHostUserName() {
if (ctfHostUserName == null) {
ctfHostUserName = new JTextField();
}
return ctfHostUserName;
}
private JTextField getCtfHostName() {
if (ctfHostName == null) {
ctfHostName = new JTextField();
}
return ctfHostName;
}
private JPasswordField getCpfHostPassword() {
if (cpfHostPassword == null) {
cpfHostPassword = new JPasswordField();
cpfHostPassword.setEchoChar('*');
}
return cpfHostPassword;
}
void HostLogout_CbtMouseMouseReleased(MouseEvent event) {
}
void HostLogin_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPDownload_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPUpload_CbtMouseMouseReleased(MouseEvent event) {
}
void HostFileList_CltNativeMouseMousePressed(MouseEvent event) {
}
void HostFileList_CltNativeMouseMouseReleased(MouseEvent event) {
}
void LocalFileList_CltNativeMouseMousePressed(MouseEvent event) {
}
void LocalFileList_CltNativeMouseMouseReleased(MouseEvent event) {
}
void SetupFileList_HostFolder_CbtMouseMouseReleased(MouseEvent event) {
}
void SetupFileList_LocalFolder_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPBreak_CbtMouseMouseReleased(MouseEvent event) {
}
void TransferList_Entry_CbtMouseMouseReleased(MouseEvent event) {
}
void TransferList_Delete_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPSnapShot_Makera_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPSnapShot_Delete_CbtMouseMouseReleased(MouseEvent event) {
}
void FTPSynchronize_CbtMouseMouseReleased(MouseEvent event) {
}
}
|
|
|
<Number>: [00000978]
<Date>: 2016/01/03 21:52:57
<Title>:
<Name>: amanojaku@管理人
|
|
|
|
|
<Number>: [00000984]
<Date>: 2016/01/02 20:57:53
<Title>:
<Name>: amanojaku@管理人
|
|
|
《参考》
Java ジェネリクスのポイント - Qiita
http://qiita.com/pebblip/items/1206f866980f2ff91e77
Javaジェネリクス再入門 - プログラマーの脳みそ
http://d.hatena.ne.jp/Nagise/20101105/1288938415
ジェネリック : 総称 | Java プログラミング解説 - so-zou.jp
http://so-zou.jp/software/tech/programming/java/generic/
Javaのジェネリック(総称型)の使い方まとめ -- ぺけみさお
http://www.xmisao.com/2013/12/08/java-generics-summary.html
「Java SE5.0」から Generics なる機能が導入されていたようですが、(かなり以前に java でプログラミングしただけなので)最近になって Generics なるモノを知りましたが、良く分からんので、実際にコードを書いてみる事に(下記参照)。
なるほど、ワイルドカードは Element(要素) ではなく、Container(容器)に対して擬似的な親子関係をサポートすると言う事なのか。
ここでは「Box」がContainer(容器)、仮型パラメータ「T」で宣言された変数がElement(要素)に対応する。
class Box<T> {
T objT = null;
// public Box<? super T> getSuper(){ }
// ↑返り値には「super」を指定したワイルドカードは使うべきではないようです。
public T getT(){
return objT;
}
public Box<T> getBox(){
return this; // あくまでテスト用なので適当に処理。
}
public void setT(T o){
objT = o;
}
public void setBox(Box<?extends T> box){
objT = box.getT();
}
}
Box<Number> boxN = new Box<Number>( );
Box<Integer> boxI = new Box<Integer>( );
boxI.setT(new Integer(1)); // 当然、正常にコンパイルされる。
boxI.setT(boxI.getT()); // 当然、正常にコンパイルされる。
boxI.setBox(boxI); // 当然、正常にコンパイルされる。
boxI.setBox(boxI.getBox()); // 当然、正常にコンパイルされる。
boxN.setT((Number)new Integer(1)); // 当然、正常にコンパイルされる。
boxN.setT(new Integer(1)); // 当然、正常にコンパイルされる。
boxN.setT(boxN.getT()); // 当然、正常にコンパイルされる。
boxN.setT(boxI.getT()); // 当然、正常にコンパイルされる。
boxN.setBox(boxN); // 当然、正常にコンパイルされる。
boxN.setBox(boxI); // Container(容器)に対して擬似的な親子関係がサポートされ、正常にコンパイルされる。
boxN.setBox(boxN.getBox()); // 当然、正常にコンパイルされる。
boxN.setBox(boxI.getBox()); // Container(容器)に対して擬似的な親子関係がサポートされ、正常にコンパイルされる。
|
|
|
<Number>: [00000986]
<Date>: 2016/01/02 23:59:59
<Title>:
<Name>: amanojaku@管理人
|
|
|
Generics を使って基本的な Node クラスを考えてみると、下記のようになる。
class Node<T> {
Node oCoupler;
T oHook;
public void SetNext(Node oN){
oCoupler = oN;
}
public Node GetNext( ){
return oCoupler;
}
public void SetHook(T oH){
oHook = oH;
}
public T GetHook( ){
return oHook;
}
}
|
|
|
<Number>: [00000991]
<Date>: 2016/01/10 08:33:13
<Title>:
<Name>: amanojaku@管理人
|
|
|
Sin グラフを横スクロールさせる、ComboBox で「波長の数、カラー」を指定して、[Make]ボタンで新しい Sin グラフを追加できます。
「MainAppFrameObj」 からアプレット独自メソッドにアクセスする場合を想定すると、「MainAppFrameObj」はアプレット・クラス内に設置した方が良いだろう。
(アプリーケーションの初期実行用) main( ) メソッドで(MainAppFrameObjなどのような)クラス内クラスをインスタンス化したい場合(main( ) メソッド実行時には、まだアプレット自体のインスタンスが生成されておらず、通常のクラス内クラスではインスタンス化できないので) 、クラス内クラスには「static」修飾子を付与しなければならない(この場合、オブジェクトは1つだけしか作成できない)。
クリック時にマウス・カーソルが動いてしまった場合 mouseClicked イベントだとイベントが発生しない"仕様"になっているようなので、mouse イベントに関しては mouseReleased イベントを使用している。
『Appletcation.java』
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
//Event を使う場合は、その Event に対応する「〜Adapter、〜Event」を import しなければならない。
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class Appletcation extends JApplet{
static Appletcation oMainApp;
static boolean lApplication = false; // true;
static MainAppFrameObj oMainAppFrame;
int iLayoutX, iLayoutY;
CanvasObj oCanvas;
int iCanvasWidth,iCanvasHeight;
JComboBox ccbSinGraph_WaveQnt;
int iCbSinGraph_WaveQnt_Width,iCbSinGraph_WaveQnt_Height;
JComboBox ccbSinGraph_Color;
int iCbSinGraph_Color_Width,iCbSinGraph_Color_Height;
Color[] d1oCbSinGraph_ColorSets;
JButton cbtSinGraph_Make;
int iBtSinGraph_Make_Width, iBtSinGraph_Make_Height;
public static void main(String[] args) {
oMainApp = new Appletcation( );
lApplication = true; // false;
oMainAppFrame =
new MainAppFrameObj( );
oMainAppFrame.oAppThread.start();
try{
oMainAppFrame.oAppThread.join();
}
catch(InterruptedException e){ }
System.exit(0);
}
public void init() {
System.out.println("init( );");
oMainApp = this;
getContentPane().setLayout(null); // Layout 座標指定モード
ccbSinGraph_WaveQnt = new JComboBox( );
ccbSinGraph_WaveQnt.setModel(new DefaultComboBoxModel(new Object[] { " 1 ", " 2 ", " 3 " }));
ccbSinGraph_WaveQnt.setDoubleBuffered(false);
ccbSinGraph_WaveQnt.setBorder(null);
System.out.println(
"ccbSinGraph_WaveQnt.getWidth()="+Integer.toString(ccbSinGraph_WaveQnt.getWidth())+"; "+
"ccbSinGraph_WaveQnt.getHeight()="+Integer.toString(ccbSinGraph_WaveQnt.getHeight())+"; "+
"ccbSinGraph_WaveQnt.getMinimumSize().width="+Integer.toString(ccbSinGraph_WaveQnt.getMinimumSize().width)+"; "+
"ccbSinGraph_WaveQnt.getMinimumSize().height="+Integer.toString(ccbSinGraph_WaveQnt.getMinimumSize().height)+"; "+
"");
iCbSinGraph_WaveQnt_Width = ccbSinGraph_WaveQnt.getMinimumSize().width;
iCbSinGraph_WaveQnt_Height = ccbSinGraph_WaveQnt.getMinimumSize().height;
d1oCbSinGraph_ColorSets = new Color[]{
Color.GREEN, Color.PINK,
Color.RED, Color.YELLOW,
};
ccbSinGraph_Color = new JComboBox( );
ccbSinGraph_Color.setModel(new DefaultComboBoxModel(new Object[]
{ "グリーン", "ピンク", "赤", "黄色", }));
ccbSinGraph_Color.setDoubleBuffered(false);
ccbSinGraph_Color.setBorder(null);
iCbSinGraph_Color_Width = ccbSinGraph_Color.getMinimumSize().width;
iCbSinGraph_Color_Height = ccbSinGraph_Color.getMinimumSize().height;
cbtSinGraph_Make = new JButton( );
cbtSinGraph_Make.setText("Make");
System.out.println(
"cbtSinGraph_Make.getWidth()="+Integer.toString(cbtSinGraph_Make.getWidth())+"; "+
"cbtSinGraph_Make.getHeight()="+Integer.toString(cbtSinGraph_Make.getHeight())+"; "+
"cbtSinGraph_Make.getMinimumSize().width="+Integer.toString(cbtSinGraph_Make.getMinimumSize().width)+"; "+
"cbtSinGraph_Make.getMinimumSize().height="+Integer.toString(cbtSinGraph_Make.getMinimumSize().height)+"; "+
"");
iBtSinGraph_Make_Width = cbtSinGraph_Make.getMinimumSize().width;
iBtSinGraph_Make_Height = cbtSinGraph_Make.getMinimumSize().height;
cbtSinGraph_Make.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
if(null!=oCanvas){
oCanvas.SinGraph_Make( );
}
}
});
iCanvasWidth = 500;
iCanvasHeight = 300;
iLayoutX = 0; iLayoutY = 0;
getContentPane().add(ccbSinGraph_WaveQnt);
ccbSinGraph_WaveQnt.setBounds(iLayoutX,iLayoutY, iCbSinGraph_WaveQnt_Width, iCbSinGraph_WaveQnt_Height);
iLayoutX = iLayoutX+iCbSinGraph_WaveQnt_Width; // iLayoutY = 0;
getContentPane().add(ccbSinGraph_Color);
ccbSinGraph_Color.setBounds(iLayoutX,iLayoutY, iCbSinGraph_Color_Width, iCbSinGraph_Color_Height);
iLayoutX = iLayoutX+iCbSinGraph_Color_Width; // iLayoutY = 0;
getContentPane().add(cbtSinGraph_Make);
cbtSinGraph_Make.setBounds(iLayoutX,iLayoutY, iBtSinGraph_Make_Width, iBtSinGraph_Make_Height);
iLayoutX = 0; iLayoutY = iLayoutY+iBtSinGraph_Make_Height;
oCanvas = new CanvasObj(iLayoutX, iLayoutY, iCanvasWidth, iCanvasHeight);
getContentPane().add(oCanvas);
// oCanvas.setVisible(true);
iLayoutX = iCanvasWidth; iLayoutY = iLayoutY+iCanvasHeight;
// this.setSize(iLayoutX, iLayoutY);
System.out.println(
"this.getWidth()="+Integer.toString(this.getWidth())+"; "+
"this.getHeight()="+Integer.toString(this.getHeight())+"; "+
"this.getMinimumSize().width="+Integer.toString(this.getMinimumSize().width)+"; "+
"this.getMinimumSize().height="+Integer.toString(this.getMinimumSize().height)+"; "+
"");
if( lApplication ){
System.out.println("if(lApplication)");
oMainAppFrame.setPreSize(new Dimension(iLayoutX, iLayoutY));
System.out.println("PanelWidth="+oCanvas.getSize( ).getWidth());
System.out.println("PanelHeight="+oCanvas.getSize( ).getHeight());
}
System.out.println("AppletWidth="+getSize( ).getWidth());
System.out.println("AppletHeight="+getSize( ).getHeight());
}
public void start(){
System.out.println("start( );");
repaint();
}
public void stop(){
System.out.println("stop( );");
}
public void destroy(){
System.out.println("destroy( );");
}
class SinGraph {
int iWidth;
int iHeight;
int iMoveStride = 3;
// volatile:最適化の抑制.
volatile int iMoveDistance = 0;
int iWaveQnt = 1;
double vdWaveHeightRate = iWaveQnt;
int iWaveStep = 0;
int iWaveWidth;
int iWaveHeight;
Color oColor = Color.BLUE;
double vdRadian;
double vdWaveWidth,vdWaveHeight;
double vdWaveX1,vdWaveX2;
double vdWaveY1,vdWaveY2;
double vdRate,vdRateInt;
SinGraph( int iW, int iH, int iWQ, Color oC ){
// コンストラクター自体には synchronized 修飾子を付与できないので、
// synchronized ブロックで囲う。
synchronized(this){
// iMoveDistance に対する競合(描画中の変更)を回避する。
// 対象は SinGraph("自分")内の変数です。
iWidth = iW;
iHeight = iH;
iWaveQnt = iWQ;
vdWaveHeightRate = iWaveQnt; // sin グラフの高さの調整。
oColor = oC;
}
}
synchronized void Draw(Graphics oGraphic){
// iMoveDistance に対する競合(描画中の変更)を回避する。
// 対象は SinGraph("自分")内の変数です。
Graphics2D oGraphic2D = (Graphics2D)oGraphic;
oGraphic2D.setColor(oColor);
vdWaveWidth = (double)iWidth/iWaveQnt;
vdWaveHeight = vdWaveWidth/(2*Math.PI)*vdWaveHeightRate;
iWaveStep = 0;
vdWaveX1 = -1; vdWaveX2 = -1;
while( iWaveStep<iWidth ){ // true / false
vdWaveX1 = vdWaveX2;
vdWaveY1 = vdWaveY2;
vdRate = (double)
(iWaveStep+iWidth-iMoveDistance)/iWidth*iWaveQnt;
vdRateInt = Math.floor(vdRate);
vdRate = vdRate-vdRateInt;
vdWaveX2 = iWaveStep;
vdRadian = 2*Math.PI*vdRate;
vdWaveY2 = iHeight/2-Math.sin(vdRadian)*vdWaveHeight;
iWaveStep++;
if(0<=vdWaveX1){
oGraphic2D.drawLine(
(int)Math.round(vdWaveX1), (int)Math.round(vdWaveY1),
(int)Math.round(vdWaveX2), (int)Math.round(vdWaveY2));
}
}
}
}
class CanvasObj extends JPanel {
// Java2 には JCanvas は存在しないので、
// グラフィックの描画には JPanel を継承して Canvas の代わりに使う。
Thread oThread;
// SinGraph oSinGraph;
int iWidth;
int iHeight;
ArrayList<SinGraph> dl1oSinGraph = new ArrayList<SinGraph>( );
CanvasObj(int x, int y, int w, int h ) {
super( );
System.out.println("oApplet:CanvasObj:");
setBounds(x, y, w, h);
iWidth = getWidth( );
iHeight = getHeight( );
SinGraph_Make( );
oThread = new Thread( ){
@Override
public void run( ){
while( true ){ // true / false
repaint();
try {
Thread.sleep(50); // ←50ミリ秒の sleep。
} catch (InterruptedException e) {
e.printStackTrace();
}
for( SinGraph oSinGraph : dl1oSinGraph.toArray(new SinGraph[0])){
// ↑この「new SinGraph[0]」の部分は要素がゼロ個の配列を指定しなければならないらしい。
// それにより指定された型と同一の型が返されるらしい。
synchronized(oSinGraph) {
// SinGraph内の iMoveDistance変数に対する競合(描画中の変更)を回避する。
// 対象は SinGraph内の変数なので、当然 ここは"他人"となります。
oSinGraph.iMoveDistance = oSinGraph.iMoveDistance+oSinGraph.iMoveStride;
if( iWidth<=oSinGraph.iMoveDistance ){ oSinGraph.iMoveDistance = oSinGraph.iMoveDistance-iWidth; }
}
}
}
}
};
oThread.start( );
}
void SinGraph_Make( ){
dl1oSinGraph.add(new SinGraph(iWidth, iHeight,
ccbSinGraph_WaveQnt.getSelectedIndex( )+1,
d1oCbSinGraph_ColorSets[ccbSinGraph_Color.getSelectedIndex( )]));
}
@Override
public void paint(Graphics oGraphic){
Graphics2D oGraphic2D = (Graphics2D)oGraphic;
// ↑(JPanel を継承しているので)ここの Graphics の実態は Graphics2D となるから、
// キャストしてやれば Graphics2D が使える.
oGraphic2D.setBackground(Color.BLACK);
oGraphic2D.clearRect(0, 0, iWidth, iHeight);
oGraphic2D.setColor(Color.WHITE);
oGraphic2D.drawLine(0, iHeight/2, iWidth, iHeight/2);
for( SinGraph oSinGraph : dl1oSinGraph.toArray(new SinGraph[0])){
// ↑この「new SinGraph[0]」の部分は要素がゼロ個の配列を指定しなければならないらしい。
// それにより指定された型と同一の型が返されるらしい。
oSinGraph.Draw(oGraphic2D);
}
}
@Override
public void update(Graphics oGraphic){
System.out.println("updat( );");
// Java のバージョンによって違うかもしれないが、
// 動的なグラフィック表示をする場合は
// update メソッドが存在しないと表示のチラツキの原因になる場合がある.
paint(oGraphic);
}
}
static class MainAppFrameObj extends JFrame implements Runnable {
// JApplet oApplet;
Thread oAppThread;
public MainAppFrameObj( ) {
super("Application frame.");
//setVisible(false);
System.out.println("Construct:Application frame window.");
// oApplet = oEntApplet; // new JAppletcation();
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent event){
// ユーザーがウインドウを閉じようとした時].
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosing.");
Close();
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowClosed(WindowEvent event){
// ウインドウが閉じた時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosed.");
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowDeiconified(WindowEvent event){
// ウィンドウが最小化された状態から通常の状態に変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowDeiconified.");
oMainApp.repaint();
}
}
}
);
addComponentListener(
new ComponentAdapter(){
public void componentResized(ComponentEvent event){
// コンポーネントのサイズが変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("ComponentEvent:componentResized.");
System.out.println("MainAppFrameObj: "+
"width="+Integer.toString(MainAppFrameObj.this.getSize( ).width)+"; "+
"Height="+Integer.toString(MainAppFrameObj.this.getSize( ).height)+"; "+
"");
oMainApp.repaint();
}
}
}
);
getContentPane().add(oMainApp,"Center");
oAppThread = new Thread(this);
}
public synchronized void setPreSize(Dimension oSize){
// dispose();
getContentPane().setPreferredSize(oSize);
pack();
setVisible(true);
requestFocus();
}
public synchronized void run(){
System.out.println("Open:Application frame window.");
oMainApp.init();
oMainApp.start();
oMainApp.repaint();
try{
wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
oMainApp.stop();
oMainApp.destroy();
oAppThread = null;
}
public synchronized void Close(){
System.out.println("Close:Application frame window.");
dispose();
notify();
}
}
}
|
|
|
<Number>: [00000998]
<Date>: 2016/01/10 08:55:27
<Title>:
<Name>: amanojaku@管理人
|
|
|
|
|
<Number>: [0000099D]
<Date>: 2016/01/10 13:45:17
<Title>:
<Name>: amanojaku@管理人
|
|
|
Appletcation を ほんのチョッピリ修正、「Java2 FTP Connect 12」と同様のマウスのダブル・クリック検出用プログラムを実装。
マウスのダブル・クリック用インターバル「ilMouseDoubleClickedIntervalMax = 180;」に設定。
《参考》
『Java2 MouseDoubleClicked 1』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+0000096B.+&
『Java2 FTP Connect 12』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+00000976-00000978&
(分かりやすければ他のファイル名でも良い)「MainPanelDesign」(MainPanelDesign.java)ファイルを Visual Swing for Eclipse でビジュアルに画面デザイン(GUI 部品の配置)を作成している(Java コードが自動生成される)。
「MainAppFrameObj、MainPanelImplementationObj」 からアプレット独自メソッドにアクセスする場合を想定すると、「MainAppFrameObj、MainPanelImplementationObj」はアプレット・クラス内に設置した方が良いだろう。
(アプリーケーションの初期実行用) main( ) メソッドで(MainAppFrameObjなどのような)クラス内クラスをインスタンス化したい場合(main( ) メソッド実行時には、まだアプレット自体のインスタンスが生成されておらず、通常のクラス内クラスではインスタンス化できないので) 、クラス内クラスには「static」修飾子を付与しなければならない(この場合、オブジェクトは1つだけしか作成できない)。
クリック時にマウス・カーソルが動いてしまった場合 mouseClicked イベントだとイベントが発生しない"仕様"になっているようなので、mouse イベントに関しては mouseReleased イベントを使用している。
今回はダブル・クリック検出用に mousePressed イベントも使用している。
変更した部分はイベント用メソッドの「Test_CbtNativeMouseMouseReleased、Test_CbtNativeMouseMousePressed」の private 修飾子を削除。
その他、「jLabel0」変数の private 修飾子を削除(Button など Component を直にイジる必要がなければ private 修飾子を削除しなくても良い)。
『MouseDoubleClicked.java』
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
//Event を使う場合は、その Event に対応する「〜Adapter、〜Event」を import しなければならない。
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.HashMap;
import javax.swing.JApplet;
import javax.swing.JFrame;
@SuppressWarnings("serial")
public class MouseDoubleClicked extends JApplet{
static String vsApplicationTitle = "Application MouseDoubleClicked 2.";
static MouseDoubleClicked oMainApp;
static boolean lApplication = false; // true;
static MainAppFrameObj oMainAppFrame;
MainPanelImplementationObj oMainPanelImp;
public static void main(String[] args) {
oMainApp = new MouseDoubleClicked( );
lApplication = true; // false;
oMainAppFrame =
new MainAppFrameObj(vsApplicationTitle);
oMainAppFrame.oAppThread.start();
try{
oMainAppFrame.oAppThread.join();
}
catch(InterruptedException e){ }
System.exit(0);
}
public void init() {
System.out.println("init( );");
oMainApp = this;
oMainPanelImp = new MainPanelImplementationObj();
getContentPane().add(oMainPanelImp,"Center");
// oMainPanelImp.setVisible(true);
System.out.println(
"oMainApp.getWidth( )="+Integer.toString(oMainApp.getWidth())+"; "+
"oMainApp.getHeight( )="+Integer.toString(oMainApp.getHeight())+"; "+
"oMainApp.getSize( ).width="+Integer.toString(oMainApp.getSize( ).width)+"; "+
"oMainApp.getSize( ).height="+Integer.toString(oMainApp.getSize( ).height)+"; "+
"oMainApp.getMinimumSize( ).width="+Integer.toString(oMainApp.getMinimumSize().width)+"; "+
"oMainApp.getMinimumSize( ).height="+Integer.toString(oMainApp.getMinimumSize().height)+"; "+
"");
if( lApplication ){
System.out.println("if(lApplication)");
oMainAppFrame.SetPreSize(this);
System.out.println("MainPanelWidth="+oMainPanelImp.getSize( ).getWidth());
System.out.println("MainPanelHeight="+oMainPanelImp.getSize( ).getHeight());
}
System.out.println("AppletWidth="+getSize( ).getWidth());
System.out.println("AppletHeight="+getSize( ).getHeight());
System.out.println("Hello, World!");
}
public void start(){
System.out.println("start( );");
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
System.out.println("ScreenWidth="+gc.getBounds().getWidth());
System.out.println("ScreenHeight="+gc.getBounds().getHeight());
repaint();
}
public void stop(){
System.out.println("stop( );");
}
public void destroy(){
System.out.println("destroy( );");
}
enum MouseMouseDoubleClicked_Enum { feTest };
class MainPanelImplementationObj extends MainPanelDesign {
long ilMouseDoubleClickedIntervalMax = 180; // 200; 250; 300; 350;
private HashMap<MouseMouseDoubleClicked_Enum, Runner_MouseMouseDoubleClicked> da1oRunnable_MouseMouseDoubleClicked =
new HashMap<MouseMouseDoubleClicked_Enum, Runner_MouseMouseDoubleClicked>( );
// volatile:最適化の抑制.
volatile byte ibCnt_Test_CbtMouseMouseDoubleClicked = 0;
Thread oThread_Test_CbtMouseMouseDoubleClicked;
Runnable oRunner_Test_CbtMouseMouseDoubleClicked;
class Runner_MouseMouseDoubleClicked implements Runnable {
private Thread oThread;
// volatile:最適化の抑制.
volatile private MouseMouseDoubleClicked_Enum eMouseDoubleClicked;
volatile byte ibCnt_MouseEvent = 0;
MouseEvent oEvent_MouseClicked = null;
Runner_MouseMouseDoubleClicked( MouseMouseDoubleClicked_Enum eMMDC ){
eMouseDoubleClicked = eMMDC;
oThread = new Thread(this);
oThread.start();
}
void NativeMouseMousePressed(MouseEvent event) {
System.out.println("NativeMouseMousePressed( ).");
System.out.println(
"eMouseDoubleClicked.name( )="+eMouseDoubleClicked.name( )+"; "+
"ibCnt_MouseEvent="+ibCnt_MouseEvent+"; "+
"");
oEvent_MouseClicked = null;
if(oThread.getState()==Thread.State.TIMED_WAITING){
ibCnt_MouseEvent = 3;
oThread.interrupt();
}else{
ibCnt_MouseEvent = 1;
}
System.out.println(
"eMouseDoubleClicked.name( )="+eMouseDoubleClicked.name( )+"; "+
"ibCnt_MouseEvent="+ibCnt_MouseEvent+"; "+
"");
}
boolean NativeMouseMouseReleased(MouseEvent event) {
System.out.println("NativeMouseMouseReleased( ).");
System.out.println(
"eMouseDoubleClicked.name( )="+eMouseDoubleClicked.name( )+"; "+
"ibCnt_MouseEvent="+ibCnt_MouseEvent+"; "+
"");
oEvent_MouseClicked = event;
boolean lDoubleClicked = false; // true; //
if(ibCnt_MouseEvent==3){
ibCnt_MouseEvent = 0;
lDoubleClicked = true; // false; //
}else if(oThread.getState()==Thread.State.WAITING){
ibCnt_MouseEvent = 2;
synchronized(this) {
notify();
// ↑メソッドを synchronized 指定するか、
// synchronized(自分のインスタンス) ブロックで囲うかしないと
// 実行時に「IllegalMonitorStateException」が発生する。
}
}
System.out.println(
"eMouseDoubleClicked.name( )="+eMouseDoubleClicked.name( )+"; "+
"ibCnt_MouseEvent="+ibCnt_MouseEvent+"; "+
"lDoubleClicked="+lDoubleClicked+"; "+
"");
return lDoubleClicked;
}
@Override
public void run( ) {
System.out.println("run.");
boolean lInterrupted = false; // true; //
while(true){
try {
synchronized(this) {
wait( );
// ↑メソッドを synchronized 指定するか、
// synchronized(自分のインスタンス) ブロックで囲うかしないと
// 実行時に「IllegalMonitorStateException」が発生する。
}
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("wait:End.");
lInterrupted = false; // true; //
try {
Thread.sleep(ilMouseDoubleClickedIntervalMax);
} catch (InterruptedException e) {
// e.printStackTrace();
System.out.println("sleep:InterruptedException.");
lInterrupted = true; // false; //
}
System.out.println("sleep:End.");
if( ! lInterrupted &&
ibCnt_MouseEvent==2 ){
ibCnt_MouseEvent = 0;
switch(eMouseDoubleClicked){
case feTest :
Test_CbtMouseMouseClicked(oEvent_MouseClicked);
break;
default:
System.out.println(
"★Error:MouseDoubleClicked="+eMouseDoubleClicked.name( )+"; "+
"");
}
oEvent_MouseClicked = null;
}
}
}
}
MainPanelImplementationObj( ){
super( );
for( MouseMouseDoubleClicked_Enum eEnum : MouseMouseDoubleClicked_Enum.values( ) ){
da1oRunnable_MouseMouseDoubleClicked.put(eEnum,
new Runner_MouseMouseDoubleClicked(eEnum));
}
}
void Test_CbtMouseMouseClicked(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:Test_CbtMouseMouseClicked.");
jLabel0.setText("SingleClicked");
}
void Test_CbtMouseMouseDoubleClicked(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:Test_CbtMouseMouseDoubleClicked.");
jLabel0.setText("DoubleClicked");
}
@Override
void Test_CbtNativeMouseMousePressed(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:Test_CbtNativeMouseMousePressed.");
System.out.println("currentTimeMillis="+System.currentTimeMillis() );
da1oRunnable_MouseMouseDoubleClicked.get(
MouseMouseDoubleClicked_Enum.feTest).NativeMouseMousePressed(event);
}
@Override
public void Test_CbtNativeMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:Test_CbtNativeMouseMouseReleased.");
System.out.println("currentTimeMillis="+System.currentTimeMillis() );
boolean lDoubleClicked = da1oRunnable_MouseMouseDoubleClicked.get(
MouseMouseDoubleClicked_Enum.feTest).NativeMouseMouseReleased(event);
if( lDoubleClicked ){
Test_CbtMouseMouseDoubleClicked(event);
}
}
}
static class MainAppFrameObj extends JFrame implements Runnable {
// JApplet oApplet;
Thread oAppThread;
public MainAppFrameObj(String vsAppTitle) {
super(vsAppTitle);
//setVisible(false);
System.out.println("MainAppFrameObj:Construct:Application frame window.");
// oApplet = oEntApplet; // new JAppletcation();
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent event){
// ユーザーがウインドウを閉じようとした時].
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosing.");
Close();
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowClosed(WindowEvent event){
// ウインドウが閉じた時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosed.");
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowDeiconified(WindowEvent event){
// ウィンドウが最小化された状態から通常の状態に変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowDeiconified.");
oMainApp.repaint();
}
}
}
);
addComponentListener(
new ComponentAdapter(){
public void componentResized(ComponentEvent event){
// コンポーネントのサイズが変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:ComponentEvent:componentResized.");
System.out.println("MainAppFrameObj: "+
"width="+Integer.toString(MainAppFrameObj.this.getSize( ).width)+"; "+
"Height="+Integer.toString(MainAppFrameObj.this.getSize( ).height)+"; "+
"");
oMainApp.repaint();
}
}
}
);
getContentPane().add(oMainApp,"Center");
oAppThread = new Thread(this);
}
public synchronized void SetPreSize(Component oComponent){
System.out.println("MainAppFrameObj:SetPreSize.");
// dispose();
System.out.println(
"oComponent.getWidth( )="+Integer.toString(oComponent.getWidth())+"; "+
"oComponent.getHeight( )="+Integer.toString(oComponent.getHeight())+"; "+
"oComponent.getSize( ).width="+Integer.toString(oComponent.getSize( ).width)+"; "+
"oComponent.getSize( ).height="+Integer.toString(oComponent.getSize( ).height)+"; "+
"oComponent.getMinimumSize( ).width="+Integer.toString(oComponent.getMinimumSize().width)+"; "+
"oComponent.getMinimumSize( ).height="+Integer.toString(oComponent.getMinimumSize().height)+"; "+
"");
getContentPane( ).setPreferredSize(
new Dimension(Math.max(oComponent.getSize( ).width, oComponent.getMinimumSize( ).width),
Math.max(oComponent.getSize( ).height, oComponent.getMinimumSize( ).height)));
pack( );
setVisible(true);
requestFocus( );
}
public synchronized void run(){
System.out.println("MainAppFrameObj:run.");
oMainApp.init();
oMainApp.start();
oMainApp.repaint();
try{
wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
oMainApp.stop();
oMainApp.destroy();
oAppThread = null;
}
public synchronized void Close(){
System.out.println("MainAppFrameObj:Close:Application frame window.");
dispose();
notify();
}
}
}
『MainPanelDesign.java』
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class MainPanelDesign extends JPanel {
private static final long serialVersionUID = 1L;
private JButton jButton0;
JLabel jLabel0;
public MainPanelDesign() {
initComponents();
}
private void initComponents() {
setLayout(new GroupLayout());
add(getJLabel0(), new Constraints(new Leading(12, 259, 12, 12), new Leading(36, 10, 10)));
add(getJButton0(), new Constraints(new Leading(12, 12, 12), new Leading(83, 10, 10)));
setSize(288, 141);
}
private JLabel getJLabel0() {
if (jLabel0 == null) {
jLabel0 = new JLabel();
jLabel0.setText("jLabel0");
}
return jLabel0;
}
private JButton getJButton0() {
if (jButton0 == null) {
jButton0 = new JButton();
jButton0.setText("jButton0");
jButton0.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
Test_CbtNativeMouseMousePressed(event);
}
public void mouseReleased(MouseEvent event) {
Test_CbtNativeMouseMouseReleased(event);
}
});
}
return jButton0;
}
void Test_CbtNativeMouseMouseReleased(MouseEvent event) {
}
void Test_CbtNativeMouseMousePressed(MouseEvent event) {
}
}
|
|
|
<Number>: [000009A2]
<Date>: 2016/01/10 21:03:35
<Title>:
<Name>: amanojaku@管理人
|
|
|
Sin グラフを横スクロールさせる、ComboBox で「波長の数、カラー」を指定して、[Make]ボタンで新しい Sin グラフを追加できます。
2つ以上の Sin グラフを表示すると、白色で合成波を表示します。
なお、SinGraph の Draw メソッドは使用していません。
「MainAppFrameObj」 からアプレット独自メソッドにアクセスする場合を想定すると、「MainAppFrameObj」はアプレット・クラス内に設置した方が良いだろう。
(アプリーケーションの初期実行用) main( ) メソッドで(MainAppFrameObjなどのような)クラス内クラスをインスタンス化したい場合(main( ) メソッド実行時には、まだアプレット自体のインスタンスが生成されておらず、通常のクラス内クラスではインスタンス化できないので) 、クラス内クラスには「static」修飾子を付与しなければならない(この場合、オブジェクトは1つだけしか作成できない)。
クリック時にマウス・カーソルが動いてしまった場合 mouseClicked イベントだとイベントが発生しない"仕様"になっているようなので、mouse イベントに関しては mouseReleased イベントを使用している。
『Appletcation.java』
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
//Event を使う場合は、その Event に対応する「〜Adapter、〜Event」を import しなければならない。
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class Appletcation extends JApplet{
static String vsApplicationTitle = "Application SinGraph 6.";
static Appletcation oMainApp;
static boolean lApplication = false; // true;
static MainAppFrameObj oMainAppFrame;
int iLayoutX, iLayoutY;
CanvasObj oCanvas;
int iCanvasWidth,iCanvasHeight;
JComboBox ccbSinGraph_WaveQnt;
int iCbSinGraph_WaveQnt_Width,iCbSinGraph_WaveQnt_Height;
JComboBox ccbSinGraph_Color;
int iCbSinGraph_Color_Width,iCbSinGraph_Color_Height;
Color[] d1oCbSinGraph_ColorSets;
JButton cbtSinGraph_Make;
int iBtSinGraph_Make_Width, iBtSinGraph_Make_Height;
public static void main(String[] args) {
oMainApp = new Appletcation( );
lApplication = true; // false;
oMainAppFrame =
new MainAppFrameObj(vsApplicationTitle);
oMainAppFrame.oAppThread.start();
try{
oMainAppFrame.oAppThread.join();
}
catch(InterruptedException e){ }
System.exit(0);
}
public void init() {
System.out.println("init( );");
oMainApp = this;
getContentPane().setLayout(null); // Layout 座標指定モード
ccbSinGraph_WaveQnt = new JComboBox( );
ccbSinGraph_WaveQnt.setModel(new DefaultComboBoxModel(new Object[] { " 1 ", " 2 ", " 3 " }));
ccbSinGraph_WaveQnt.setDoubleBuffered(false);
ccbSinGraph_WaveQnt.setBorder(null);
System.out.println(
"ccbSinGraph_WaveQnt.getWidth()="+Integer.toString(ccbSinGraph_WaveQnt.getWidth())+"; "+
"ccbSinGraph_WaveQnt.getHeight()="+Integer.toString(ccbSinGraph_WaveQnt.getHeight())+"; "+
"ccbSinGraph_WaveQnt.getMinimumSize().width="+Integer.toString(ccbSinGraph_WaveQnt.getMinimumSize().width)+"; "+
"ccbSinGraph_WaveQnt.getMinimumSize().height="+Integer.toString(ccbSinGraph_WaveQnt.getMinimumSize().height)+"; "+
"");
iCbSinGraph_WaveQnt_Width = ccbSinGraph_WaveQnt.getMinimumSize().width;
iCbSinGraph_WaveQnt_Height = ccbSinGraph_WaveQnt.getMinimumSize().height;
d1oCbSinGraph_ColorSets = new Color[]{
Color.GREEN, Color.PINK,
Color.RED, Color.YELLOW,
};
ccbSinGraph_Color = new JComboBox( );
ccbSinGraph_Color.setModel(new DefaultComboBoxModel(new Object[]
{ "グリーン", "ピンク", "赤", "黄色", }));
ccbSinGraph_Color.setDoubleBuffered(false);
ccbSinGraph_Color.setBorder(null);
iCbSinGraph_Color_Width = ccbSinGraph_Color.getMinimumSize().width;
iCbSinGraph_Color_Height = ccbSinGraph_Color.getMinimumSize().height;
cbtSinGraph_Make = new JButton( );
cbtSinGraph_Make.setText("Make");
System.out.println(
"cbtSinGraph_Make.getWidth()="+Integer.toString(cbtSinGraph_Make.getWidth())+"; "+
"cbtSinGraph_Make.getHeight()="+Integer.toString(cbtSinGraph_Make.getHeight())+"; "+
"cbtSinGraph_Make.getMinimumSize().width="+Integer.toString(cbtSinGraph_Make.getMinimumSize().width)+"; "+
"cbtSinGraph_Make.getMinimumSize().height="+Integer.toString(cbtSinGraph_Make.getMinimumSize().height)+"; "+
"");
iBtSinGraph_Make_Width = cbtSinGraph_Make.getMinimumSize().width;
iBtSinGraph_Make_Height = cbtSinGraph_Make.getMinimumSize().height;
cbtSinGraph_Make.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
if(null!=oCanvas){
oCanvas.SinGraph_Make( );
}
}
});
iCanvasWidth = 500;
iCanvasHeight = 500;
iLayoutX = 0; iLayoutY = 0;
getContentPane().add(ccbSinGraph_WaveQnt);
ccbSinGraph_WaveQnt.setBounds(iLayoutX,iLayoutY, iCbSinGraph_WaveQnt_Width, iCbSinGraph_WaveQnt_Height);
iLayoutX = iLayoutX+iCbSinGraph_WaveQnt_Width; // iLayoutY = 0;
getContentPane().add(ccbSinGraph_Color);
ccbSinGraph_Color.setBounds(iLayoutX,iLayoutY, iCbSinGraph_Color_Width, iCbSinGraph_Color_Height);
iLayoutX = iLayoutX+iCbSinGraph_Color_Width; // iLayoutY = 0;
getContentPane().add(cbtSinGraph_Make);
cbtSinGraph_Make.setBounds(iLayoutX,iLayoutY, iBtSinGraph_Make_Width, iBtSinGraph_Make_Height);
iLayoutX = 0; iLayoutY = iLayoutY+iBtSinGraph_Make_Height;
oCanvas = new CanvasObj(iLayoutX, iLayoutY, iCanvasWidth, iCanvasHeight);
getContentPane().add(oCanvas);
// oCanvas.setVisible(true);
iLayoutX = iCanvasWidth; iLayoutY = iLayoutY+iCanvasHeight;
this.setSize(iLayoutX, iLayoutY);
System.out.println(
"this.getWidth()="+Integer.toString(this.getWidth())+"; "+
"this.getHeight()="+Integer.toString(this.getHeight())+"; "+
"this.getMinimumSize().width="+Integer.toString(this.getMinimumSize().width)+"; "+
"this.getMinimumSize().height="+Integer.toString(this.getMinimumSize().height)+"; "+
"");
if( lApplication ){
System.out.println("if(lApplication)");
oMainAppFrame.SetPreSize(this);
System.out.println("PanelWidth="+oCanvas.getSize( ).getWidth());
System.out.println("PanelHeight="+oCanvas.getSize( ).getHeight());
}
System.out.println("AppletWidth="+getSize( ).getWidth());
System.out.println("AppletHeight="+getSize( ).getHeight());
}
public void start(){
System.out.println("start( );");
repaint();
}
public void stop(){
System.out.println("stop( );");
}
public void destroy(){
System.out.println("destroy( );");
}
class SinGraph {
CanvasObj oCanvas;
// int iWidth, iHeight;
int iMoveStride = 3;
// volatile:最適化の抑制.
volatile int iMoveDistance = 0;
int iWaveQnt = 1;
double vdWaveHeightRate = iWaveQnt;
int iGraphXStep = 0;
int iWaveWidth;
int iWaveHeight;
Color oColor = Color.BLUE;
double vdRadian;
double vdWaveWidth, vdWaveHeight;
double vdGraphX1, vdGraphX2;
double vdGraphY1, vdGraphY2;
double vdWaveY1, vdWaveY2;
double vdRate, vdRateInt;
SinGraph( CanvasObj ccv, int iWQ, Color oC ){
// コンストラクター自体には synchronized 修飾子を付与できないので、
// synchronized ブロックで囲う。
synchronized(this){
// iMoveDistance に対する競合(描画中の変更)を回避する。
// 対象は SinGraph("自分")内の変数です。
oCanvas = ccv;
iWaveQnt = iWQ;
vdWaveHeightRate = iWaveQnt; // sin グラフの高さの調整。
oColor = oC;
}
}
synchronized void Draw(Graphics oGraphic){
// iMoveDistance に対する競合(描画中の変更)を回避する。
// 対象は SinGraph("自分")内の変数です。
Graphics2D oGraphic2D = (Graphics2D)oGraphic;
vdGraphX1 = -1; vdGraphX2 = -1;
oGraphic2D.setColor(oColor);
vdWaveWidth = (double)oCanvas.iWidth/iWaveQnt;
vdWaveHeight = vdWaveWidth/(2*Math.PI)*vdWaveHeightRate;
iGraphXStep = 0;
while( iGraphXStep<oCanvas.iWidth ){ // true / false
DrawBullet(oGraphic, iGraphXStep);
iGraphXStep++;
}
}
void DrawBullet(Graphics oGraphic, int iBulletGraphXStep){
Graphics2D oGraphic2D = (Graphics2D)oGraphic;
oGraphic2D.setColor(oColor);
if( 0==iBulletGraphXStep ){
vdGraphX1 = -1;
vdGraphX2 = -1;
}
vdWaveWidth = (double)oCanvas.iWidth/iWaveQnt;
vdWaveHeight = vdWaveWidth/(2*Math.PI)*vdWaveHeightRate;
vdGraphX1 = vdGraphX2;
vdGraphY1 = vdGraphY2;
vdWaveY1 = vdWaveY2;
vdRate = (double)
(iBulletGraphXStep+oCanvas.iWidth-iMoveDistance)/oCanvas.iWidth*iWaveQnt;
vdRateInt = Math.floor(vdRate);
vdRate = vdRate-vdRateInt;
vdGraphX2 = iBulletGraphXStep;
vdRadian = 2*Math.PI*vdRate;
vdWaveY2 = Math.sin(vdRadian)*vdWaveHeight;
vdGraphY2 = oCanvas.iHeight/2-vdWaveY2;
if(0<=vdGraphX1){
oGraphic2D.drawLine(
(int)Math.round(vdGraphX1), (int)Math.round(vdGraphY1),
(int)Math.round(vdGraphX2), (int)Math.round(vdGraphY2));
// oCanvas.vdGraphX1 = oCanvas.vdGraphX1+vdGraphX1;
// oCanvas.vdGraphX2 = oCanvas.vdGraphX2+vdGraphX2;
oCanvas.vdWaveY1 = oCanvas.vdWaveY1+vdWaveY1;
oCanvas.vdWaveY2 = oCanvas.vdWaveY2+vdWaveY2;
}
}
}
class CanvasObj extends JPanel {
// Java2 には JCanvas は存在しないので、
// グラフィックの描画には JPanel を継承して Canvas の代わりに使う。
Thread oThread;
// SinGraph oSinGraph;
int iWidth;
int iHeight;
ArrayList<SinGraph> dl1oSinGraph = new ArrayList<SinGraph>( );
int iGraphXStep;
double vdGraphX1,vdGraphX2;
double vdGraphY1,vdGraphY2;
double vdWaveY1,vdWaveY2;
double vdWaveYRate = 0.666; // 合成波のY軸の倍率。
CanvasObj(int x, int y, int w, int h ) {
super( );
System.out.println("oApplet:CanvasObj:");
setBounds(x, y, w, h);
iWidth = getWidth( );
iHeight = getHeight( );
SinGraph_Make( );
oThread = new Thread( ){
@Override
public void run( ){
while( true ){ // true / false
repaint();
try {
Thread.sleep(50); // ←50ミリ秒の sleep。
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized(CanvasObj.this) {
// SinGraph内の iMoveDistance変数に対する競合(描画中の変更)を回避する。
// 対象は SinGraph内の変数なのだが、
// (CanvasObj の) paint内のループ全体の処理を1つと見なす必要があるので
// 実際の対象は CanvasObj とする必要がある。
for( SinGraph oSinGraph : dl1oSinGraph.toArray(new SinGraph[0])){
// ↑この「new SinGraph[0]」の部分は要素がゼロ個の配列を指定しなければならないらしい。
// それにより指定された型と同一の型が返されるらしい。
oSinGraph.iMoveDistance = oSinGraph.iMoveDistance+oSinGraph.iMoveStride;
if( iWidth<=oSinGraph.iMoveDistance ){ oSinGraph.iMoveDistance = oSinGraph.iMoveDistance-iWidth; }
}
}
}
}
};
oThread.start( );
}
void SinGraph_Make( ){
dl1oSinGraph.add(new SinGraph(this,
ccbSinGraph_WaveQnt.getSelectedIndex( )+1,
d1oCbSinGraph_ColorSets[ccbSinGraph_Color.getSelectedIndex( )]));
}
@Override
public synchronized void paint(Graphics oGraphic){
Graphics2D oGraphic2D = (Graphics2D)oGraphic;
// ↑(JPanel を継承しているので)ここの Graphics の実態は Graphics2D となるから、
// キャストしてやれば Graphics2D が使える.
oGraphic2D.setBackground(Color.BLACK);
oGraphic2D.clearRect(0, 0, iWidth, iHeight);
oGraphic2D.setColor(Color.WHITE);
oGraphic2D.drawLine(0, iHeight/2, iWidth, iHeight/2);
iGraphXStep = 0;
vdGraphX1 = 0; vdGraphX2 = 0;
while( iGraphXStep<iWidth ){ // true / false
vdWaveY1 = 0; vdWaveY2 = 0;
vdGraphX1 = vdGraphX2;
for( SinGraph oSinGraph : dl1oSinGraph.toArray(new SinGraph[0])){
// ↑この「new SinGraph[0]」の部分は要素がゼロ個の配列を指定しなければならないらしい。
// それにより指定された型と同一の型が返されるらしい。
oSinGraph.DrawBullet(oGraphic, iGraphXStep);
}
vdGraphX2 = iGraphXStep;
if( 2<=dl1oSinGraph.size( ) && 0<iGraphXStep ){
vdGraphY1 = iHeight/2-vdWaveY1*vdWaveYRate;
vdGraphY2 = iHeight/2-vdWaveY2*vdWaveYRate;
oGraphic2D.setColor(Color.WHITE);
oGraphic2D.drawLine(
(int)Math.round(vdGraphX1), (int)Math.round(vdGraphY1),
(int)Math.round(vdGraphX2), (int)Math.round(vdGraphY2));
}
iGraphXStep++;
}
}
@Override
public void update(Graphics oGraphic){
System.out.println("updat( );");
// Java のバージョンによって違うかもしれないが、
// 動的なグラフィック表示をする場合は
// update メソッドが存在しないと表示のチラツキの原因になる場合がある.
paint(oGraphic);
}
}
static class MainAppFrameObj extends JFrame implements Runnable {
// JApplet oApplet;
Thread oAppThread;
public MainAppFrameObj(String vsAppTitle) {
super(vsAppTitle);
//setVisible(false);
System.out.println("MainAppFrameObj:Construct:Application frame window.");
// oApplet = oEntApplet; // new JAppletcation();
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent event){
// ユーザーがウインドウを閉じようとした時].
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosing.");
Close();
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowClosed(WindowEvent event){
// ウインドウが閉じた時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosed.");
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowDeiconified(WindowEvent event){
// ウィンドウが最小化された状態から通常の状態に変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowDeiconified.");
oMainApp.repaint();
}
}
}
);
addComponentListener(
new ComponentAdapter(){
public void componentResized(ComponentEvent event){
// コンポーネントのサイズが変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:ComponentEvent:componentResized.");
System.out.println("MainAppFrameObj: "+
"width="+Integer.toString(MainAppFrameObj.this.getSize( ).width)+"; "+
"Height="+Integer.toString(MainAppFrameObj.this.getSize( ).height)+"; "+
"");
oMainApp.repaint();
}
}
}
);
getContentPane().add(oMainApp,"Center");
oAppThread = new Thread(this);
}
public synchronized void SetPreSize(Component oComponent){
System.out.println("MainAppFrameObj:SetPreSize.");
// dispose();
System.out.println(
"oComponent.getWidth( )="+Integer.toString(oComponent.getWidth())+"; "+
"oComponent.getHeight( )="+Integer.toString(oComponent.getHeight())+"; "+
"oComponent.getSize( ).width="+Integer.toString(oComponent.getSize( ).width)+"; "+
"oComponent.getSize( ).height="+Integer.toString(oComponent.getSize( ).height)+"; "+
"oComponent.getMinimumSize( ).width="+Integer.toString(oComponent.getMinimumSize().width)+"; "+
"oComponent.getMinimumSize( ).height="+Integer.toString(oComponent.getMinimumSize().height)+"; "+
"");
getContentPane( ).setPreferredSize(
new Dimension(Math.max(oComponent.getSize( ).width, oComponent.getMinimumSize( ).width),
Math.max(oComponent.getSize( ).height, oComponent.getMinimumSize( ).height)));
pack( );
setVisible(true);
requestFocus( );
}
public synchronized void run(){
System.out.println("MainAppFrameObj:run.");
oMainApp.init();
oMainApp.start();
oMainApp.repaint();
try{
wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
oMainApp.stop();
oMainApp.destroy();
oAppThread = null;
}
public synchronized void Close(){
System.out.println("MainAppFrameObj:Close:Application frame window.");
dispose();
notify();
}
}
}
|
|
|
<Number>: [000009A7]
<Date>: 2016/01/10 21:09:47
<Title>:
<Name>: amanojaku@管理人
|
|
|
|
|
<Number>: [000009AF]
<Date>: 2016/01/18 19:17:54
<Title>:
<Name>: amanojaku@管理人
|
|
|
以前、作成した「キャンバス(Panel)、ボタン、イベント」Appletcation を(Appletcation 部分を ほんのチョッピリ変更した) Appletcation 10 に換装。
Frame(ウインドウ)の「マウス・ドラッグによるサイズ変更時、最小化・状態から通常・状態への変更時」に Applet を repaint してやる。
普通に Frame のサイズを設定するとタイトルバーの高さのサイズだけ内部の領域が狭くなってしまうが、「getContentPane().setPreferredSize」で内部の領域のサイズが設定でき、その後に「pack()」してやれば良い。
「MainAppFrameObj、MainPanelImplementationObj」 からアプレット独自メソッドにアクセスする場合を想定すると、「MainAppFrameObj、MainPanelImplementationObj」はアプレット・クラス内に設置した方が良いだろう。
(アプリーケーションの初期実行用) main( ) メソッドで(MainAppFrameObjなどのような)クラス内クラスをインスタンス化したい場合(main( ) メソッド実行時には、まだアプレット自体のインスタンスが生成されておらず、通常のクラス内クラスではインスタンス化できないので) 、クラス内クラスには「static」修飾子を付与しなければならない(この場合、オブジェクトは1つだけしか作成できない)。
(分かりやすければ他のファイル名でも良い)「MainPanelDesign」(MainPanelDesign.java)ファイルを Visual Swing for Eclipse でビジュアルに画面デザイン(GUI 部品の配置)を作成している(Java コードが自動生成される)。
クリック時にマウス・カーソルが動いてしまった場合 mouseClicked イベントだとイベントが発生しない"仕様"になっているようなので、mouseReleased イベントを使用している。
変更した部分は mouseReleased イベント用の「jButton0MouseMouseReleased、jButton1MouseMouseReleased、jButton2MouseMouseReleased」メソッドの private 修飾子を削除。
その他、「jPanel0」変数、「getJPanel0」メソッドの private 修飾子を削除。
『Appletcation.java』
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
//Event を使う場合は、その Event に対応する「〜Adapter、〜Event」を import しなければならない。
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class Appletcation extends JApplet{
static String vsApplicationTitle = "Application 11 MouseDoubleClicked 1.";
static Appletcation oMainApp;
static boolean lApplication = false; // true;
static MainAppFrameObj oMainAppFrame;
MainPanelImplementationObj oMainPanelImp;
public static void main(String[] args) {
oMainApp = new Appletcation( );
lApplication = true; // false;
oMainAppFrame =
new MainAppFrameObj(vsApplicationTitle);
oMainAppFrame.oAppThread.start();
try{
oMainAppFrame.oAppThread.join();
}
catch(InterruptedException e){ }
System.exit(0);
}
public void init() {
System.out.println("init( );");
oMainApp = this;
// getContentPane().setLayout(null); // Layout 座標指定モード
oMainPanelImp = new MainPanelImplementationObj();
getContentPane().add(oMainPanelImp,"Center");
if( lApplication ){
System.out.println("if(lApplication)");
oMainAppFrame.SetPreSize(this);
}
}
public void start(){
System.out.println("start( );");
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
System.out.println("ScreenWidth="+gc.getBounds().getWidth());
System.out.println("ScreenHeight="+gc.getBounds().getHeight());
repaint();
}
public void stop(){
System.out.println("stop( );");
}
public void destroy(){
System.out.println("destroy( );");
}
class CanvasObj extends JPanel {
int x,y,d;
Color oColor;
@Override
public void paint(Graphics oGraphic){
System.out.println("paint( );");
Graphics2D oGraphic2D = (Graphics2D)oGraphic;
// ↑ここの Graphics の実態は Graphics2D なので、
// キャストしてやれば Graphics2D のメソッドが使える.
System.out.println("oApplet: "+
"width="+Integer.toString(getSize( ).width)+"; "+
"Height="+Integer.toString(getSize( ).height)+"; "+
"");
oGraphic2D.setBackground(Color.WHITE);
oGraphic2D.clearRect(0, 0, getWidth(), getHeight());
if( 0<d ){
oGraphic2D.setColor(oColor);
oGraphic2D.fillOval(x, y, d, d);
}
}
@Override
public void update(Graphics oGraphic){
System.out.println("updat( );");
// Java のバージョンによって違うかもしれないが、
// 動的なグラフィック表示をする場合は
// update メソッドが存在しないと表示のチラツキの原因になる場合がある.
paint(oGraphic);
}
}
class MainPanelImplementationObj extends MainPanelDesign {
public MainPanelImplementationObj( ) {
super( );
}
@Override
JPanel getJPanel0() {
if (jPanel0 == null) {
jPanel0 = new CanvasObj();
jPanel0.setLayout(new org.dyno.visual.swing.layouts.GroupLayout());
// ↑「org.dyno.visual.swing.layouts.GroupLayout」は Java 標準の Layout パッケージではない。
// 「MainPanelDesign.java」で import されているパッケージ名を使用している。
}
return jPanel0;
}
@Override
void jButton0MouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:jButton0MouseMouseReleased.");
CanvasObj oCv = (CanvasObj)jPanel0;
oCv.oColor = Color.BLUE;
oCv.x = 5;
oCv.y = 5;
oCv.d = 80;
oCv.repaint();
}
@Override
void jButton1MouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:jButton1MouseMouseReleased.");
CanvasObj oCv = (CanvasObj)jPanel0;
oCv.oColor = Color.YELLOW;
oCv.x = 95;
oCv.y = 5;
oCv.d = 80;
oCv.repaint();
}
@Override
void jButton2MouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:jButton2MouseMouseReleased.");
CanvasObj oCv = (CanvasObj)jPanel0;
oCv.oColor = Color.RED;
oCv.x = 190;
oCv.y = 5;
oCv.d = 80;
oCv.repaint();
}
}
static class MainAppFrameObj extends JFrame implements Runnable {
// JApplet oApplet;
Thread oAppThread;
public MainAppFrameObj(String vsAppTitle) {
super(vsAppTitle);
//setVisible(false);
System.out.println("MainAppFrameObj:Construct:Application frame window.");
// oApplet = oEntApplet; // new JAppletcation();
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent event){
// ユーザーがウインドウを閉じようとした時].
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosing.");
Close();
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowClosed(WindowEvent event){
// ウインドウが閉じた時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosed.");
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowDeiconified(WindowEvent event){
// ウィンドウが最小化された状態から通常の状態に変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowDeiconified.");
oMainApp.repaint();
}
}
}
);
addComponentListener(
new ComponentAdapter(){
public void componentResized(ComponentEvent event){
// コンポーネントのサイズが変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:ComponentEvent:componentResized.");
System.out.println("MainAppFrameObj: "+
"width="+Integer.toString(MainAppFrameObj.this.getSize( ).width)+"; "+
"Height="+Integer.toString(MainAppFrameObj.this.getSize( ).height)+"; "+
"");
oMainApp.repaint();
}
}
}
);
getContentPane().add(oMainApp,"Center");
oAppThread = new Thread(this);
}
public synchronized void SetPreSize(Component oComponent){
System.out.println("MainAppFrameObj:SetPreSize.");
// dispose();
System.out.println(
"oComponent.getWidth( )="+Integer.toString(oComponent.getWidth())+"; "+
"oComponent.getHeight( )="+Integer.toString(oComponent.getHeight())+"; "+
"oComponent.getSize( ).width="+Integer.toString(oComponent.getSize( ).width)+"; "+
"oComponent.getSize( ).height="+Integer.toString(oComponent.getSize( ).height)+"; "+
"oComponent.getMinimumSize( ).width="+Integer.toString(oComponent.getMinimumSize().width)+"; "+
"oComponent.getMinimumSize( ).height="+Integer.toString(oComponent.getMinimumSize().height)+"; "+
"");
getContentPane( ).setPreferredSize(
new Dimension(Math.max(oComponent.getSize( ).width, oComponent.getMinimumSize( ).width),
Math.max(oComponent.getSize( ).height, oComponent.getMinimumSize( ).height)));
pack( );
setVisible(true);
requestFocus( );
}
public synchronized void run(){
System.out.println("MainAppFrameObj:run.");
oMainApp.init();
oMainApp.start();
oMainApp.repaint();
try{
wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
oMainApp.stop();
oMainApp.destroy();
oAppThread = null;
}
public synchronized void Close(){
System.out.println("MainAppFrameObj:Close:Application frame window.");
dispose();
notify();
}
}
}
『MainPanelDesign.java』
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JPanel;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class MainPanelDesign extends JPanel {
private static final long serialVersionUID = 1L;
private JButton jButton0;
private JButton jButton2;
private JButton jButton1;
JPanel jPanel0;
public MainPanelDesign() {
initComponents();
}
private void initComponents() {
setLayout(new GroupLayout());
add(getJButton0(), new Constraints(new Leading(5, 10, 10), new Leading(210, 10, 10)));
add(getJButton2(), new Constraints(new Leading(189, 12, 12), new Leading(210, 12, 12)));
add(getJButton1(), new Constraints(new Leading(96, 12, 12), new Leading(210, 12, 12)));
add(getJPanel0(), new Constraints(new Leading(5, 278, 10, 10), new Leading(5, 199, 12, 12)));
setSize(288, 248);
}
JPanel getJPanel0() {
if (jPanel0 == null) {
jPanel0 = new JPanel();
jPanel0.setLayout(new GroupLayout());
}
return jPanel0;
}
private JButton getJButton0() {
if (jButton0 == null) {
jButton0 = new JButton();
jButton0.setText("jButton0");
jButton0.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
jButton0MouseMouseReleased(event);
}
});
}
return jButton0;
}
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("jButton1");
jButton1.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
jButton1MouseMouseReleased(event);
}
});
}
return jButton1;
}
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setText("jButton2");
jButton2.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event) {
jButton2MouseMouseReleased(event);
}
});
}
return jButton2;
}
void jButton2MouseMouseReleased(MouseEvent event) {
}
void jButton1MouseMouseReleased(MouseEvent event) {
}
void jButton0MouseMouseReleased(MouseEvent event) {
}
}
|
|
|