package nc.pub.filesystem.newui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.border.EmptyBorder;

import nc.bs.logging.Logger;
import nc.desktop.ui.WorkbenchEnvironment;
import nc.funcnode.ui.ActionButton;
import nc.funcnode.ui.FuncletMenuBar;
import nc.funcnode.ui.action.AbstractNCAction;
import nc.funcnode.ui.action.INCAction;
import nc.pub.billcode.ui.ButtonPanel;
import nc.ui.ml.NCLangRes;
import nc.ui.pub.beans.IImageFetch;
import nc.ui.pub.beans.ImageBrowser;
import nc.ui.pub.beans.ImageObject;
import nc.ui.pub.beans.ImagePreviewPanel;
import nc.ui.pub.beans.ImageSelectionEvent;
import nc.ui.pub.beans.ImageSelectionListener;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pub.beans.ScaleSlider;
import nc.ui.pub.beans.UIButton;
import nc.ui.pub.beans.UIDialog;
import nc.ui.pub.beans.UIPanel;
import nc.ui.pub.filesystem.FileManageServletClient;
import nc.uitheme.ui.ThemeResourceCenter;
import nc.vo.pub.filesystem.FileImageProcess;
import nc.vo.pub.filesystem.NCFileNode;

public class TestFileBrowseGPYPotoDialog extends UIDialog{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ImageObject   currimageobj =null ;
	private TestFileContentPanel parentpanel ;
	TestTakePotoPanel takepotopane ;
	
	public TestFileBrowseGPYPotoDialog(TestTakePotoPanel panel,String ptempfolder,TestFileContentPanel ppane,ImageObject imageobject ) {
		super(panel, NCLangRes.getInstance().getStrByID("sftemp", "FileContentPanel-0000")/*浏览*/);
		takepotopane =panel;
		tempfolder =ptempfolder;
		parentpanel =ppane; 
//		this.imagebrower = browser;
		this.addWindowListener(new WindowAdapter(){
			@Override
			public void windowClosing(WindowEvent e) {
				File file = new File(tempfolder);
				File [] arrfile =file.listFiles(new FileFilter() {					
					@Override
					public boolean accept(File pathname) {
						if(pathname.getName().endsWith(".jpg")){
						return true;
						}else{
							return false;
						}
					}
				});
//				takepotopane.imagebrower.reset(arrfile.length);
//				takepotopane.imagebrower.refresh();
//				takepotopane.imagebrower.revalidate();
				takepotopane.setHasopen(false);
			}
		});
		initUI();
		
//		getpreviewPnl().setImage(image);
		getImagebrower().setSelectionByIcon(imageobject.getIcon());
	}
	
//	private FileContentPanel parentpanel = null;
	private JDialog pdialog = null;
	String tempfolder = "";
	int n = 1;
	private static ImageIcon menuBarBGIcon = ThemeResourceCenter.getInstance()
			.getImage("themeres/control/menu/menu_bg.png");
	private static ImageIcon menuBarBGFrameIcon = ThemeResourceCenter
			.getInstance().getImage("themeres/control/menu/menu_bg_frame.png");

	private static ImageIcon leftrotateicon = ThemeResourceCenter.getInstance()
			.getImage("themeres/control/accessory/rotate_left_normal.png");
	private static ImageIcon leftrotateovericon = ThemeResourceCenter
			.getInstance().getImage(
					"themeres/control/accessory/rotate_left_highligh.png");

	private static ImageIcon rightrotateicon = ThemeResourceCenter
			.getInstance().getImage(
					"themeres/control/accessory/rotate_right_normal.png");
	private static ImageIcon rightrotateovericon = ThemeResourceCenter
			.getInstance().getImage(
					"themeres/control/accessory/rotate_right_highligh.png");

	private static ImageIcon takepotoicon = ThemeResourceCenter.getInstance()
			.getImage("themeres/control/accessory/photos_noamal.png");
	private static ImageIcon takepotoovericon = ThemeResourceCenter
			.getInstance().getImage(
					"themeres/control/accessory/photos_highlight.png");

	private static ImageIcon uploadicon = ThemeResourceCenter.getInstance()
			.getImage("themeres/control/accessory/upload_noamal.png");
	private static ImageIcon uploadovericon = ThemeResourceCenter.getInstance()
			.getImage("themeres/control/accessory/upload_highlight.png");
	private int leftrotatecount = 0;
	private int rightrotatecount = 4;
	private int[] anglearr = { 0, 90, 270, 180 };

	// menubar菜单栏 外层
	private JPanel menuBarContainer;

	private JPanel bottombtnpanel;

	public JPanel getBottombtnpanel() {
		if (bottombtnpanel == null) {
			bottombtnpanel = new JPanel();
			bottombtnpanel.setBorder(new MyBorder(0, 0, 0, 0));
			FlowLayout layout = new FlowLayout();
			layout.setAlignment(FlowLayout.RIGHT);
			bottombtnpanel.setLayout(layout);
			bottombtnpanel.add(getbtnexit());
		}
		return bottombtnpanel;
	}

	private UIButton btnexit;

	public UIButton getbtnexit() {
		if (btnexit == null) {
			btnexit = new UIButton(NCLangRes.getInstance().getStrByID("sftemp", "TakePotoPanel-0001")/*退出*/);
			btnexit.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					TestFileBrowseGPYPotoDialog.this.closeOK();

				}
			});
		}
		return btnexit;
	}

	public UIPanel potobtnpanel;

	public UIPanel getPotobtnpanel() {
		if (potobtnpanel == null) {
			potobtnpanel = new UIPanel();
			potobtnpanel.add(getBtnleftturn());
			potobtnpanel.add(getBtnuploadpoto());
//			potobtnpanel.add(getBtntakepoto());
			potobtnpanel.add(getBtnrightturn());
			
		}
		return potobtnpanel;
	}

	// menubar
	private FuncletMenuBar bar;
	// 设置按钮
//	private ActionButton btnsetting;
	// 继续拍照按钮
	private ActionButton btngobackpoto;
	// 左转90
	private UIButton btnleftturn;
	// 右转90
	private UIButton btnrightturn;
	// 拍照
//	private UIButton btntakepoto;
	// 什么批量上传button？？
	private UIButton btnuploadpoto;

	// 缩率图
	private ImageBrowser imagebrower;
	// 牌照区域
//	private GaoPaiYiPanel gpypanel;
	// 高拍仪的尺寸属性
//	private int gpysize;
	// 分辨率（高拍仪厂商支持的不好）
//	private int resolution;
//	private String namerule;

//	private Action settingaction;

//	private class SettingAction extends AbstractNCAction {
//		public SettingAction() {
//			putValue(AbstractAction.NAME, "设置");
//			this.putValue(INCAction.CODE, "setting");
//			this.putValue(Action.SHORT_DESCRIPTION, "设置");
//		}
//		@Override
//		public void actionPerformed(ActionEvent e) {
//			GPYSettingDialog dlg = new GPYSettingDialog();
//			dlg.showModal();
//
//		}
//
//	}

	public UIButton getBtnuploadpoto() {
		if (btnuploadpoto == null) {
			btnuploadpoto = new UIButton();
			btnuploadpoto.setPreferredSize(new Dimension(25, 25));
			btnuploadpoto.setIcon(uploadicon);
			btnuploadpoto.setRolloverIcon(uploadovericon);
			btnuploadpoto.addActionListener(new ActionListener(){
				@Override
				public void actionPerformed(ActionEvent e) {
					
					UploadPotoDialog dlg = new UploadPotoDialog();
					dlg.showModal();
					// 
//					File file = new File(tempfolder);
//					if(file.exists()){
//						for(File subfile :file.listFiles()){
//							if(FileTypeConst.getFileTypeByFileName(subfile.getName()).equalsIgnoreCase(FileTypeConst.IMAGE)){								
//
//								String fileName = subfile.getName();
//								//校验是否同名
//								if(parentpanel.CheckTheSameFileName((NCFileNode)node, fileName)){
//									continue ;
//								}
//								//检查 附件大小 ,文件超过  参数设置的大小不能上传
//								if(FileBroseConst.getfilelimit()*1024*1024<subfile.length()){
//									MessageDialog.showErrorDlg(parentpanel, "文件超过限制", fileName+"大小超过限制不能上传！");
//									continue ;
//								}
//								input = new FileInputStream(subfile);
//								NCFileNode newNode = FileManageServletClient.uploadFile(dsName, pPath, fileName, input, creator, subfile.length());
//								if (newNode != null) {
//									NCFileVO  newfilevo = new NCFileVO();
////									
//									parentpanel.nodeToFileVO((NCFileNode)node, newNode);
//								}
//							
//							}
//						}
//					}
				}
			});
		}
		return btnuploadpoto;
	}

	private class returnAction extends AbstractNCAction {
		public returnAction() {
			putValue(AbstractAction.NAME, NCLangRes.getInstance().getStrByID("sftemp", "TakePotoPanel-0000")/*返回拍照*/);
			this.putValue(INCAction.CODE, "returnpoto");
			this.putValue(Action.SHORT_DESCRIPTION, NCLangRes.getInstance().getStrByID("sftemp", "TakePotoPanel-0000")/*返回拍照*/);
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			//
			TestFileBrowseGPYPotoDialog.this.close();
		}

	}
	private ActionButton btndeletepoto ;
	private ActionButton getBtndeletepoto() {
		if (btndeletepoto == null) {
			btndeletepoto = new ActionButton(new deletePotoAction());
		}
		return btndeletepoto;
	}
	private class deletePotoAction extends AbstractNCAction {
		public deletePotoAction() {
			putValue(AbstractAction.NAME, NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseGPYPotoDialog-0001")/*删除图片*/);
			this.putValue(INCAction.CODE, "deletepoto");
			this.putValue(Action.SHORT_DESCRIPTION, NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseGPYPotoDialog-0001")/*删除图片*/);
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			if(currimageobj!=null){
				try{
					getImagebrower().deleteImage(currimageobj);
					takepotopane.getImagebrower().deleteImage(currimageobj);
					takepotopane.getImageObjectlist().remove(currimageobj);
					getImagebrower().refresh();
					String filepath =currimageobj.getImageID();
					File file = new File(filepath);
					if(file.exists()){
						file.delete();
					}
					getpreviewPnl().setImage(null);
					currimageobj=null ;
				}catch (Exception e1) {
					Logger.error(e1);
				}
			}
		}

	}
	private ActionButton getBtngobackpoto() {
		if (btngobackpoto == null) {
			btngobackpoto = new ActionButton(new returnAction());
		}
		return btngobackpoto;
	}

	// 旋转
	public UIButton getBtnleftturn() {
		if (btnleftturn == null) {
			btnleftturn = new UIButton();
			btnleftturn.setPreferredSize(new Dimension(25, 25));
			btnleftturn.setIcon(leftrotateicon);
			btnleftturn.setRolloverIcon(leftrotateovericon);
			btnleftturn.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
//					leftrotatecount = leftrotatecount + 1;
//					int index = leftrotatecount % 4;
//					int angle = index * 90;
//					if(MYUISTATE==TakePotoState){
//						
//						int state = 0;
//						for (int i = 0; i < anglearr.length; i++) {
//							if (angle == anglearr[i]) {
//								state = i;
//							}
//						}
//						getGpypanel().SetVideoRotate(state);
//					}else{
						BufferedImage image =(BufferedImage) getpreviewPnl().getImage();
						if(image!=null){
							try {
								BufferedImage  bimage =FileImageProcess.rotateImg(image, 270, null);
								getpreviewPnl().setImage(bimage);
							} catch (IOException e1) {
								
							}
						}
//					}
				}
			});
		}
		return btnleftturn;
	}

	// 旋转
	public UIButton getBtnrightturn() {
		if (btnrightturn == null) {
			btnrightturn = new UIButton();
			btnrightturn.setPreferredSize(new Dimension(25, 25));
			btnrightturn.setIcon(rightrotateicon);
			btnrightturn.setRolloverIcon(rightrotateovericon);
			btnrightturn.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
//					rightrotatecount = rightrotatecount - 1;
//					int index = rightrotatecount % 4;
//					if(index<0){
//						index = 4+index ;
//					}
//					int angle = index * 90;
					BufferedImage image =(BufferedImage) getpreviewPnl().getImage();
					if(image!=null){
						try {
							BufferedImage  bimage =FileImageProcess.rotateImg(image, 90, null);
							getpreviewPnl().setImage(bimage);
						} catch (IOException e1) {
							
						}
					}
				}
			});
		}
		return btnrightturn;
	}

//	public UIButton getBtntakepoto() {
//		if (btntakepoto == null) {
//			btntakepoto = new UIButton();
//			btntakepoto.setPreferredSize(new Dimension(25, 25));
//			btntakepoto.setIcon(takepotoicon);
//			btntakepoto.setRolloverIcon(takepotoovericon);
//			btntakepoto.addActionListener(new ActionListener() {
//				@Override
//				public void actionPerformed(ActionEvent e) {
//					String path;
//					if (namerule == null || namerule.isEmpty()) {
//						path = tempfolder + File.separatorChar + (n++) + ".jpg";
//					} else {
//						path = tempfolder + File.separatorChar + namerule
//								+ (n++) + ".jpg";
//					}
//
//					File file = new File(path);
//
//					if (file.exists()) {
//						file.delete();
//					}
//					// else{
//					// file.mkdirs();
//					// }
//					
//					
//					getGpypanel().QuickScan(path);
//					// 刷新 imagebrowser
//					BufferedImage image=null;
//					BufferedImage samallimage=null;
//					try {
//						image = ImageIO.read(file);
//						samallimage =FileCompression.doCompressImage(image, 96.0, 96.0);
//					} catch (IOException e1) {
//						Logger.error(e1);
//					}
//					
//					ImageObject imageobj = new ImageObject(path, new ImageIcon(samallimage));
//					getImagebrower().addNewImage(imageobj);
////					
//
//				}
//			});
//		}
//		return btntakepoto;
//	}

//	private List<File> listfile = new ArrayList<File>();
//
//	public List<File> getfilelist() {
//		listfile.clear();
//		File file = new File(tempfolder);
//		if (file.exists()) {
//			File[] arrfiles = file.listFiles();
//			// 情况1：没文件，返回空
//			if (arrfiles == null) {
//				return null;
//			}
//			for (File f : arrfiles) {
//				if (f.isFile()
//						&& FileTypeConst.getFileTypeByFileName(f.getName())
//								.equals(FileTypeConst.IMAGE)) {
//					listfile.add(f);
//				}
//			}
//			Collections.sort(listfile ,new FileComparator());
//		}
//		return listfile;
//	}
//	private class  FileComparator implements Comparator{
//
//		@Override
//		public int compare(Object o1, Object o2) {
//			File f1 =(File)o1;
//			File f2 =(File)o2;
//			return Long.valueOf(f2.lastModified()).compareTo(Long.valueOf(f1.lastModified()));
//			
//		}
//		
//	}
	public ImageBrowser getImagebrower() {
		if (imagebrower == null) {
			imagebrower = new ImageBrowser(ImageBrowser.VERTICAL, takepotopane.getImageObjectlist()
					.size(), new PotoImageFetch());
			imagebrower.addChangeListener(new ImageSelectionListener(){
				@Override
				public void valueChanged(ImageSelectionEvent e) {	
					if(e.getImageObject()!=null){
						currimageobj = e.getImageObject();
						String filepath =e.getImageObject().getImageID();
						File file = new File(filepath);
						try {
							BufferedImage image = ImageIO.read(file);
							getpreviewPnl().setImage(image);
							getpreviewPnl().updateUI();
						} catch (IOException e1) {
							Logger.error(e1);
						}
						
					}
				}
			});
		}
		return imagebrower;
	}
	private ImagePreviewPanel previewPnl;

	private ImagePreviewPanel getpreviewPnl() {
		if (previewPnl == null) {
			previewPnl = new ImagePreviewPanel(new ScaleSlider());
		}
		return previewPnl;
	}
	private class PotoImageFetch implements IImageFetch {
		int pagenum = 5;

		@Override
		public ImageObject[] getImage(int page) {

			// 情况2： 没有图片类型文件 返回空
			if (takepotopane.getImageObjectlist().size() == 0) {
				return null;
			}
			int startindext = (page - 1) * pagenum;
			int end = page * pagenum - 1;

			if (end > (takepotopane.getImageObjectlist().size() - 1)) {
				end = takepotopane.getImageObjectlist().size() - 1;
			}
			ImageObject[] rtnimgObj = new ImageObject[end - startindext + 1];
		
			// 
			for (int i = startindext; i <= end; i++) {

				rtnimgObj[i-startindext] = takepotopane.getImageObjectlist().get(takepotopane.getImageObjectlist().size()-1-i);
			}
			return rtnimgObj;
		}
	}

	// 中间的图和右边条pane
	private UIPanel centerpanel;

	public UIPanel getCenterpanel() {
		if (centerpanel == null) {
			centerpanel = new UIPanel();
			centerpanel.setLayout(new BorderLayout());
			centerpanel.add(getGpyandimagepanel(), BorderLayout.CENTER);
			centerpanel.add(getImagebrower(), BorderLayout.EAST);
		}
		return centerpanel;
	}

	// 包装高拍仪或者imagepreview的pane
	private JPanel gpyandimagepanel;

	// 高拍仪或者图片浏览，外套的panel
	public JPanel getGpyandimagepanel() {
		if (gpyandimagepanel == null) {
			gpyandimagepanel = new JPanel();
			gpyandimagepanel.setLayout(new BorderLayout());
			gpyandimagepanel.add(getGpyborderpanel(), BorderLayout.CENTER);
			gpyandimagepanel.add(getPotobtnpanel(), BorderLayout.SOUTH);
		}
		return gpyandimagepanel;
	}

	private JPanel gpyborderpanel;

	public JPanel getGpyborderpanel() {
		if (gpyborderpanel == null) {
			gpyborderpanel = new UIPanel();
			gpyborderpanel.setBorder(new EmptyBorder(20, 20, 20, 20));
			gpyborderpanel.setLayout(new BorderLayout());
			gpyborderpanel.add(getpreviewPnl());
		}
		return gpyborderpanel;
	}

//	public GaoPaiYiPanel getGpypanel() {
//		if (gpypanel == null) {
//			gpypanel = new GaoPaiYiPanel();
//
//		}
//		return gpypanel;
//	}

	JPanel getMenuBarContainer() {
		if (menuBarContainer == null) {
			menuBarContainer = new JPanel() {

				private static final long serialVersionUID = 7130908951757832647L;

				@Override
				protected void paintComponent(Graphics g) {
					super.paintComponent(g);
					Dimension size = getSize();
					if (menuBarBGIcon != null && menuBarBGFrameIcon != null) {
						int frameW = menuBarBGFrameIcon.getIconWidth();
						g.drawImage(menuBarBGIcon.getImage(), frameW, 0,
								size.width - 2 * frameW, size.height, this);
						menuBarBGFrameIcon.paintIcon(this, g, 0, 0);
						menuBarBGFrameIcon.paintIcon(this, g, size.width
								- frameW, 0);
					}
				}

			};
			menuBarContainer.setOpaque(false);
			menuBarContainer.setBorder(BorderFactory.createEmptyBorder(6, 6, 6,
					6));
			menuBarContainer.setLayout(new BorderLayout());
			menuBarContainer.add(getBar(), BorderLayout.CENTER);

			getBar().setOpaque(false);
		}
		return menuBarContainer;
	}

	public FuncletMenuBar getBar() {
		if (bar == null) {
			bar = new FuncletMenuBar();
			bar.setPreferredSize(new Dimension(0, 30));
			bar.addMenuComp(getBtngobackpoto());
			bar.addMenuComp(getBtndeletepoto());

			bar.setOpaque(false);

		}
		return bar;
	}

	

	private void initUI() {
		setLayout(new BorderLayout());
		// add(comp,BorderLayout.CENTER);
		add(getMenuBarContainer(), BorderLayout.NORTH);
		add(getCenterpanel(), BorderLayout.CENTER);
		add(getBottombtnpanel(), BorderLayout.SOUTH);

	}

	/**
	 * 高拍仪设置 dlg
	 * 
	 * @author zhoujja
	 * 
	 */
	

	
	private class UploadPotoDialog extends UIDialog{
		public UploadPotoDialog(){
			initUI ();
		}
		private void initUI(){
			setSize(450, 200);
			setLayout(new BorderLayout());
			this.add(getMainpanel());
			
		}
		 private JPanel mainpanel;
			public JPanel getMainpanel(){
				if(mainpanel== null){
					mainpanel = new JPanel();
					SpringLayout layout = new SpringLayout();
					mainpanel.add(getLbluploadfolder());
					mainpanel.add(getComboxfolder());
					mainpanel.add(getlblFilename());
					mainpanel.add(getTxtfilename());
					mainpanel.add(getBottombtnPane());
					mainpanel.setLayout(layout);
					
					layout.putConstraint(SpringLayout.NORTH, getLbluploadfolder(), 35,SpringLayout.NORTH , mainpanel);
					layout.putConstraint(SpringLayout.EAST, getLbluploadfolder(), -10,SpringLayout.WEST , getComboxfolder());
//					
					
					layout.putConstraint(SpringLayout.WEST, getComboxfolder(), 100,SpringLayout.WEST , mainpanel);
					layout.putConstraint(SpringLayout.EAST, getComboxfolder(), -35,SpringLayout.EAST , mainpanel);
					layout.putConstraint(SpringLayout.NORTH, getComboxfolder(), 35,SpringLayout.NORTH , mainpanel);			
					
					layout.putConstraint(SpringLayout.NORTH, getlblFilename(), 10,SpringLayout.SOUTH , getLbluploadfolder());
					layout.putConstraint(SpringLayout.EAST, getlblFilename(), -10,SpringLayout.WEST , getTxtfilename());
					
					layout.putConstraint(SpringLayout.WEST, getTxtfilename(), 100,SpringLayout.WEST , mainpanel);
					layout.putConstraint(SpringLayout.EAST, getTxtfilename(), -35,SpringLayout.EAST , mainpanel);
					layout.putConstraint(SpringLayout.NORTH, getTxtfilename(), 10,SpringLayout.SOUTH , getLbluploadfolder());		
					
					layout.putConstraint(SpringLayout.WEST ,getBottombtnPane(), 0,SpringLayout.WEST , mainpanel);
					layout.putConstraint(SpringLayout.EAST ,getBottombtnPane(), 0,SpringLayout.EAST , mainpanel);
//					
					layout.putConstraint(SpringLayout.SOUTH, getBottombtnPane(), -0,SpringLayout.SOUTH , mainpanel);
					
				}
				return mainpanel ;
			}
			private JPanel bottombtnPane;
			public JPanel getBottombtnPane(){
				if(bottombtnPane==null){
					bottombtnPane = new JPanel();
//					bottombtnPane.setPreferredSize(new Dimension(290,40));
					FlowLayout  fl = new FlowLayout();
					fl.setAlignment(FlowLayout.RIGHT);
					bottombtnPane.setLayout(fl);
					bottombtnPane.add(getBtnpanel());
					
					bottombtnPane.setBackground(FileColorConst.BOTTOMCOLOR);
//					bottombtnPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
					bottombtnPane.setBorder(new MyBorder(0,0,0,0));
				}
				
				return bottombtnPane;
			}

			private ButtonPanel btnpanel ;
			public ButtonPanel getBtnpanel(){
				if(btnpanel == null){
					btnpanel = new ButtonPanel();
					btnpanel.setOpaque(false);
					btnpanel.getBtnOK().addActionListener(new ActionListener(){
						public void actionPerformed(ActionEvent e) {
							int i=1 ;
							for(ImageObject iobj :takepotopane.getImageObjectlist()){
								File subfile = new File(iobj.getImageID());
								try{
									String rulename =getTxtfilename().getText();
									rulename = rulename+(i++);
									int index = subfile.getName().lastIndexOf(".");//
									// 找出扩展名如 ".jpg"
									String filetype = subfile.getName().substring(index);
									String newfilename =rulename+filetype;
									
									//检查 附件大小 ,文件超过  参数设置的大小不能上传
									if(FileBroseConst.getfilelimit()*1024*1024<subfile.length()){
										MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("sftemp", "UploadAction-0001")/*文件超过限制*/, NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseGPYPotoDialog-0002")/*大小超过限制不能上传！*/);
										continue ;
									}
									String dsName = WorkbenchEnvironment.getInstance().getDSName();
									String pPath = ((MoveFolder)(getComboxfolder().getSelectedItem())).value;
									NCFileNode node =parentpanel.findNode(parentpanel.rootNode, pPath);
									////校验是否同名
									if(parentpanel.CheckTheSameFileName((NCFileNode)node, newfilename)){
										//TODO 记录重名的文件
										continue ;
									}
									FileInputStream input = new FileInputStream(subfile);
									String creator = WorkbenchEnvironment.getInstance().getLoginUser().getCuserid();
									NCFileNode newNode = FileManageServletClient.uploadFile(dsName, pPath, newfilename, input, creator, subfile.length());
									if (newNode != null) {										
										parentpanel.nodeToFileVO((NCFileNode)node, newNode);
									}
								}catch (Exception ex) {
									Logger.error(ex);
									Logger.error(NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseGPYPotoDialog-0003", null, new String[]{subfile.getName()})/*{0}上传失败，详细原因请检查日志!*/);
									MessageDialog.showHintDlg(parentpanel, NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseGPYPotoDialog-0004")/*上传失败*/, NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseGPYPotoDialog-0005", null, new String[]{subfile.getName()})/*{0}上传失败!*/);
								}
								}
							MessageDialog.showHintDlg(parentpanel, NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseGPYPotoDialog-0006")/*操作完成*/, NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseGPYPotoDialog-0007")/*操作完成!*/);
							UploadPotoDialog.this.closeOK();
							}
						
					});
					btnpanel.getBtnCancel().addActionListener(new ActionListener(){
						@Override
						public void actionPerformed(ActionEvent e) {
							UploadPotoDialog.this.closeCancel();
							
						}
					});
				}
				return btnpanel ;
			}
			private JLabel lblfilename ;
			private JTextField txtfilename ;
			private JLabel getlblFilename(){
				if(lblfilename ==null){
					lblfilename = new JLabel(NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseGPYPotoDialog-0008")/*文件名规则*/);
				}
				return lblfilename;
			}
			private JTextField getTxtfilename(){
				if(txtfilename == null){
					txtfilename = new JTextField();
				}
				return txtfilename ;				
			}
		private JLabel lbluploadfolder ;
		private JLabel getLbluploadfolder(){
			if(lbluploadfolder == null){
				lbluploadfolder = new JLabel(NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseGPYPotoDialog-0009")/*上传到*/);
			}
			return lbluploadfolder;
		}
		private JComboBox Comboxfile;
		private JComboBox getComboxfolder(){
			if(Comboxfile == null){
				Comboxfile = new JComboBox();
				
				NCFileNode node =(NCFileNode)parentpanel.getTreemodel().getRoot();
				String rootpath = node.getFullPath();
				//隐藏根目录前字符串
//				String unvisstr = "";
//				if(rootpath.contains("/")){
//					unvisstr=rootpath.substring(0,rootpath.lastIndexOf("/")+1);
//				}
				
				Enumeration<NCFileNode>  e =node.breadthFirstEnumeration();
				while(e.hasMoreElements()){
					NCFileNode enode =(NCFileNode)e.nextElement();
					if(!enode.isRoot()){
						MoveFolder mf = new MoveFolder();
						if(rootpath!=""){
							mf.dispname=NCLangRes.getInstance().getStrByID("sftemp", "FileBrowseGPYPotoDialog-0010", null, new String[]{enode.getFullPath().substring(rootpath.length())})/*全部{0}*/;							
						}else{
							mf.dispname=enode.getFullPath();	
						}
						mf.value=enode.getFullPath();
						Comboxfile.addItem( mf);					
					}
				}
				
			}
			return Comboxfile;
		}
	}
	
	private class MoveFolder{
		public String getValue() {
			return value;
		}
		public void setValue(String value) {
			this.value = value;
		}
		public String getDispname() {
			return dispname;
		}
		public void setDispname(String dispname) {
			this.dispname = dispname;
		}
		private String value ;
		private String dispname ;
		@Override
		public String toString() {
			
			return this.dispname;
		}
	}
	
}
