/*
 * SendButtonActionCallback
 * 送信ボタン関係のコールバック
 */
package org.logical_paradox.rss.test.dsync;

import java.awt.event.ActionEvent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.logical_paradox.rss.dsync.SyncCommand;

public class SendButtonActionCallback extends ButtonActionCallback {
	private static final Log log = LogFactory.getLog(SendButtonActionCallback.class);
	public SendButtonActionCallback( DelayedSyncTestGUI gui ) {
		super( gui );
	}

	public void actionPerformed( ActionEvent event ) {
		if( (event.getSource() == parent.sendBtn || event.getSource() == parent.tf) && parent.tf.getText().trim().length() > 0 ) {
			// コマンドの送信
			int commandType = 0;
			String commandTypeStr = null;

			switch( parent.commandListBox.getSelectedIndex() ) {
				case 0:
					commandType = SyncCommand.COMMAND_LOCK;
					commandTypeStr = "ロック信号";
					break;
				case 1:
					commandType = SyncCommand.COMMAND_UNLOCK;
					commandTypeStr = "ロック解除信号";
					break;
				case 2:
					commandType = SyncCommand.COMMAND_FORWARD_URL;
					commandTypeStr = "未処理URL転送信号";
					break;
				case 3:
					commandType = SyncCommand.COMMAND_UNFORWARD_URL;
					commandTypeStr = "未処理URL解除信号";
					break;
				default:
					log.info( "未定義のコマンドが選択されました: " + parent.commandListBox.getSelectedIndex() );
			}

			// ロック情報の送信
			log.info( commandTypeStr + "を遅延同期デーモンのバッファに格納しました" );
			addSyncCommand( parent.tf.getText().trim(), commandType );
			parent.tf.setText( "" );
		}
	}

	public void addSyncCommand( String ptn, int type ) {
		parent.commandQueue.addElement( new SyncCommand( ptn, type, null, null ) );
		parent.commandQueueList.setListData( parent.commandQueue );
	}
}

// end of SendButtonActionCallback.java
