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.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
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.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.ScaleSlider;
import nc.ui.pub.beans.UIButton;
import nc.ui.pub.beans.UIDialog;
import nc.ui.pub.beans.UIPanel;
import nc.ui.pub.filesystem.GaoPaiYiPanel;
import nc.uitheme.ui.ThemeResourceCenter;
import nc.vo.pub.filesystem.FileCompression;
import nc.vo.pub.filesystem.FileTypeConst;
import net.miginfocom.swing.MigLayout;

public class ThTakePotoPanel extends JPanel {
	//现在的状态
	private  int MYUISTATE =0 ;
	/**拍摄状态*/
	private static final int TakePotoState=0 ;	
	/**点击照片浏览状态*/
	private static final int BrowseState=1 ;
	/**异常状态*/
	private static final int EXCEPTIONState=-1 ;	
	private ThFileContentPanel 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 };
	private List<ImageObject> imageObjectlist= new ArrayList<ImageObject>() ;
	public List<ImageObject>  getImageObjectlist(){
		if(imageObjectlist==null){
			imageObjectlist = new ArrayList<ImageObject>();			
		}
		return imageObjectlist ;
	}
	// menubar菜单栏 外层
	private JPanel menuBarContainer;
	private boolean hasopen =false;
	public boolean GetHasopen(){
		return hasopen;
	}
	public void setHasopen(boolean phasopen){
		hasopen=phasopen;
	}
	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;
	}

	public ActionButton getBtngobackpoto() {
		if (btngobackpoto == null) {
			btngobackpoto = new ActionButton(new returnAction());
		}
		return btngobackpoto;
	}
	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) {
			//在一个界面不行
			if(MYUISTATE==1){
				MYUISTATE =0;
				getGpyborderpanel().removeAll();
				getGpyborderpanel().add(getGpypanel());
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e1) {
					
				}
				getGpypanel().OpenScanner();
				getGpypanel().StartPreview();
			}
		}

	}
	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) {
					try{
						getGpypanel().StopPreview();
						if(getGpypanel().IsConnect()){						
							getGpypanel().CloseScanner();
						}
						// 删除临时文件,
						try {
							FileBroseConst.deleteFile(tempfolder);
						} catch (Exception e1) {
							// MessageDialog.showErrorDlg(parentpanel, "错误",
							// "删除临时文件出错");
						}
					}catch (Exception e2) {
						// MessageDialog.showErrorDlg(parentpanel, "错误",
						// "删除临时文件出错");
					}
					finally{
						pdialog.dispose();
					}

					

				}
			});
		}
		return btnexit;
	}

	public UIPanel potobtnpanel;

	public UIPanel getPotobtnpanel() {
		if (potobtnpanel == null) {
			potobtnpanel = new UIPanel();
			potobtnpanel.add(getBtnleftturn());
			potobtnpanel.add(getBtntakepoto());
			potobtnpanel.add(getBtnrightturn());
//			potobtnpanel.add(getBtnuploadpoto());
		}
		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;

	// 缩率图
	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, NCLangRes.getInstance().getStrByID("sftemp", "TakePotoPanel-0002")/*设置*/);
			this.putValue(INCAction.CODE, "setting");
			this.putValue(Action.SHORT_DESCRIPTION, NCLangRes.getInstance().getStrByID("sftemp", "TakePotoPanel-0002")/*设置*/);
		}
		@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) {
					// 
					
				}
			});
		}
		return btnuploadpoto;
	}

//	private class returnAction extends AbstractNCAction {
//		public returnAction() {
//			putValue(AbstractAction.NAME, "返回拍照");
//			this.putValue(INCAction.CODE, "returnpoto");
//			this.putValue(Action.SHORT_DESCRIPTION, "返回拍照");
//		}
//
//		@Override
//		public void actionPerformed(ActionEvent e) {
//			//
//			if(MYUISTATE==BrowseState){
//				MYUISTATE =TakePotoState;
//				getGpyborderpanel().removeAll();
//				getGpyborderpanel().add(getGpypanel());
//				getGpypanel().OpenScanner();
//				getGpypanel().StartPreview();
//				
//				
//				
//			}
//		}
//
//	}

	public Action getSettingaction() {
		if (settingaction == null) {
			settingaction = new SettingAction();
		}
		return settingaction;
	}

	public ActionButton getBtnsetting() {
		if (btnsetting == null) {
			btnsetting = new ActionButton(getSettingaction());
			
		}
		return btnsetting;
	}


	// 旋转
	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;
								break;
							}
						}
						getGpypanel().SetVideoRotate(state);
//					}else{
//						BufferedImage image =(BufferedImage) getpreviewPnl().getImage();
//						if(image!=null){
//							try {
//								BufferedImage  bimage =FileImageProcess.rotateImg(image, angle, 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 mod =rightrotatecount % 4;
					if(mod<0){
						rightrotatecount =4+mod;
					}
					
					
					int index =rightrotatecount;
					int angle = index * 90;
					int state = 0;
					for (int i = 0; i < anglearr.length; i++) {
						if (angle == anglearr[i]) {
							state = i;
							break;
						}
					}
					getGpypanel().SetVideoRotate(state);
				}
			});
		}
		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();
					// }
					
					
					if(getGpypanel().IsConnect()&&getGpypanel().Scan(path)){
						// 刷新 imagebrowser
						BufferedImage image=null;
						BufferedImage samallimage=null;
						try {
							try {
								//高拍仪在使用文件
		 						Thread.sleep(500);
								image = ImageIO.read(file);
								if(image==null){							
									Thread.sleep(1000);							
									image = ImageIO.read(file);
								}
								} catch (InterruptedException e1) {
									
								}
							samallimage =FileCompression.doCompressImage(image, 96.0, 96.0);
						} catch (IOException e1) {
							Logger.error(e1);
						}
						
						ImageObject imageobj = new ImageObject(path, new ImageIcon(samallimage));
						getImageObjectlist().add(imageobj);
						getImagebrower().addNewImage(imageobj);
						getImagebrower().refresh();
					}else{
						JOptionPane.showMessageDialog(null,NCLangRes.getInstance().getStrByID("sftemp", "TakePotoPanel-0007")/*扫描失败*/);
					}

				}
			});
		}
		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);
				}
			}
		}
		return listfile;
	}

	public ImageBrowser getImagebrower() {
		if (imagebrower == null) {
			imagebrower = new ImageBrowser(ImageBrowser.VERTICAL, getfilelist()
					.size(), new PotoImageFetch());
			imagebrower.addChangeListener(new ImageSelectionListener(){
				@Override
				public void valueChanged(ImageSelectionEvent e) {
					if(e.getImageObject()!=null){
//					//方案1 ：浏览图片在一个界面里，界面好理解，代码复杂
					//按照方案1 高拍仪bug 无解 ，虽然设置 状态，但是调用CloseScanner 时会JVM异常 
//					if(MYUISTATE==TakePotoState){
//						MYUISTATE=BrowseState;
//						getGpypanel().StopPreview();
//						getGpypanel().CloseScanner();
//						getGpyborderpanel().removeAll();
//						getGpyborderpanel().add(getpreviewPnl());
//					}
//					try{
//						BufferedImage image = ImageIO.read(new File(e.getImageObject().getImageID()));
//						getpreviewPnl().setImage(image);
//						
//					}catch (Exception e1) {
//						// 
//					}

//						//方案2  浏览图片在两个界面
						if(!hasopen){
							
							try {
//								BufferedImage image = ImageIO.read(new File(e.getImageObject().getImageID()));
								ThFileBrowseGPYPotoDialog dlg = new ThFileBrowseGPYPotoDialog(ThTakePotoPanel.this,tempfolder,parentpanel, e.getImageObject());
								dlg.setSize(new Dimension(850,670));
								hasopen=true;
								dlg.showModal();							
							} catch (Exception e1) {
								Logger.error(e);
							}
							
						}
					}
				}
			});
		}
		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 (listfile.size() == 0) {
				return null;
			}
			int startindext = (page - 1) * pagenum;
			int end = page * pagenum - 1;

			if (end > (listfile.size() - 1)) {
				end = listfile.size() - 1;
			}
			ImageObject[] rtnimgObj = new ImageObject[end - startindext + 1];

			ArrayList<String> pklist = new ArrayList<String>();
			String dsName = WorkbenchEnvironment.getInstance()
					.getLoginBusiCenter().getDataSourceName();

			String strpkcom = "";
			// 
			for (int i = startindext; i <= end; i++) {
				String filename = listfile.get(i).getAbsolutePath();

				File imagefile = new File(filename);
				BufferedImage image = null;
				BufferedImage smallimage = null ;
				try {
					image = ImageIO.read(imagefile);
					smallimage = FileCompression.doCompressImage(image, 96.0, 96.0);
				} catch (IOException e) {
					Logger.error(e);
				}
				rtnimgObj[end - i] = new ImageObject(filename, new ImageIcon(
						smallimage));
			}
			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(getGpypanel());
		}
		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(getBtnsetting());
//			if(MYUISTATE==TakePotoState){
//				bar.addMenuComp(getBtngobackpoto());
//			}
			
			bar.setOpaque(false);

		}
		return bar;
	}

	ThTakePotoPanel(ThFileContentPanel para, String path, JDialog parentdialog) {
		tempfolder = path;
		pdialog = parentdialog;
		parentpanel = para;
		initUI();
		
	}

	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 GPYSettingDialog extends UIDialog {
		public GPYSettingDialog() {
			super(ThTakePotoPanel.this, NCLangRes.getInstance().getStrByID("sftemp", "TakePotoPanel-0002")/*设置*/);
			initUI();
			initData();
			
		}
		private void initData(){
			getChangescansize().removeAllItems(); 
			int num = getGpypanel().GetScanSizeCount();
			if(num==8)
			{
				getChangescansize().addItem("All");
				getChangescansize().addItem("A3");
				getChangescansize().addItem("A4");
				getChangescansize().addItem("A5");
				getChangescansize().addItem("A6");
				getChangescansize().addItem("A7");
				getChangescansize().addItem(NCLangRes.getInstance().getStrByID("sfbase", "ScanUIDialog-000002")/*名片*/);
				getChangescansize().addItem(NCLangRes.getInstance().getStrByID("sfbase", "ScanUIDialog-000003")/*身份证*/);
				getChangescansize().addItem(NCLangRes.getInstance().getStrByID("sfbase", "ScanUIDialog-000004")/*自定义*/);
				getChangescansize().setSelectedIndex(0);
			}
			else
			{
				
				getChangescansize().addItem("All");
				getChangescansize().addItem("A4");
				getChangescansize().addItem("A5");
				getChangescansize().addItem("A6");
				getChangescansize().addItem("A7");
				getChangescansize().addItem(NCLangRes.getInstance().getStrByID("sfbase", "ScanUIDialog-000002")/*名片*/);
				getChangescansize().addItem(NCLangRes.getInstance().getStrByID("sfbase", "ScanUIDialog-000003")/*身份证*/);
				getChangescansize().addItem(NCLangRes.getInstance().getStrByID("sfbase", "ScanUIDialog-000004")/*自定义*/);	
				getChangescansize().setSelectedIndex(0);
				
			}
			
			 int i=0;
			 int num1= getGpypanel().GetResolutionCount();
			 int selindex=0;
			 int width = getGpypanel().GetResolutionWidth(0);
			 int height= getGpypanel().GetResolutionHeight(0); 

			 getcomboxresolution().removeAllItems(); 
			 for(i=0;i<num1;i++)
			 {
				int w=getGpypanel().GetResolutionWidth(i);
				int h=getGpypanel().GetResolutionHeight(i);
				Integer w1=w;
				Integer h1=h;
				String str=w1.toString()+"x"+h1.toString();
				getcomboxresolution().addItem(str);
				if(w==width)selindex=i;
			 }    
			 getcomboxresolution().setSelectedIndex(selindex);		
		
			 getcomboxresolution().addItemListener(new ItemListener(){
			@Override
			public void itemStateChanged(ItemEvent e) {
				// 
				if(e.getStateChange() == ItemEvent.SELECTED){
					int num=	getcomboxresolution().getItemCount();
					int index=	getcomboxresolution().getSelectedIndex();
					if(index<num)
					{
						getGpypanel().SetResolution(index);
					}  
				}
			}
		});
		}

		private JPanel mainpane;
		private JPanel toppane;
		private JPanel btnpaPanel;
		
		private JLabel lblsize; 
//		private JTextField txtsize;
		private JLabel lblresolution ;
//		private JTextField txtresolution ;
		private JComboBox comboxresolution ;
		private JLabel lblnamerule;
		private JTextField txtnamerule;
		private JButton btnsave;
		private JButton btncancel;
		private JComboBox changescansize ;
		public JComboBox getChangescansize(){
			if(changescansize==null){
				changescansize =new JComboBox();
//				changescansize.addItemListener(new ItemListener(){
//					@Override
//					public void itemStateChanged(ItemEvent e) {
//						// 
//						if (e.getStateChange() != ItemEvent.SELECTED)
//							return;
//						//
//						
//					}
//				});
			}
			return changescansize;
		}
		public JLabel getLblresolution(){
			if(lblresolution == null){
				lblresolution = new JLabel(NCLangRes.getInstance().getStrByID("sftemp", "TakePotoPanel-0003")/*分辨率*/);
				lblresolution.setHorizontalAlignment(SwingConstants.RIGHT);   
			}
			return lblresolution;
		}
//		public JTextField getTxtresolution(){
//			if(txtresolution == null){
//				txtresolution = new JTextField();
//				txtresolution.setEnabled(false);
//				txtresolution.setText("1600*1200");
//			}
//			return txtresolution;
//		}
		public JComboBox getcomboxresolution(){
			if(comboxresolution == null){
				comboxresolution = new JComboBox();
			}
			return comboxresolution ;
		}
		public JPanel getMainpane() {
			if (mainpane == null) {
				mainpane = new JPanel();
				mainpane.setLayout(new BorderLayout());
				mainpane.add(getToppane(), BorderLayout.CENTER);
				mainpane.add(getBtnpaPanel(), BorderLayout.SOUTH);
			}
			return mainpane;
		}

		public JPanel getToppane() {
			if (toppane == null) {
				toppane = new JPanel();
				MigLayout miglayout = new MigLayout("insets 30 20 20 30",
						"[]10[]10[]", "[]20[]");
				toppane.setLayout(miglayout);
				toppane.add(getLblsize(), "w 100:100:100,left");
				toppane.add(getChangescansize(), "w 200:200:200,wrap");
				toppane.add(getLblresolution(), "w 100:100:100,left");
				toppane.add(getcomboxresolution(), "w 200:200:200,wrap");
				getcomboxresolution().setEnabled(false);
				
//				toppane.add(getLblnamerule(), "w 100:100:100,left");
//				toppane.add(getTxtnamerule(), "w 200:200:200,wrap");
			}
			return toppane;
		}

		public JPanel getBtnpaPanel() {
			if (btnpaPanel == null) {
				btnpaPanel = new JPanel();
				btnpaPanel.setBorder(new MyBorder(0,0,0,0));
				FlowLayout mgr = new FlowLayout();
				mgr.setAlignment(FlowLayout.RIGHT);
				btnpaPanel.setLayout(mgr);
				btnpaPanel.add(getBtnsave());
				btnpaPanel.add(getBtncancel());
			}
			return btnpaPanel;
		}

		public JLabel getLblsize() {
			if (lblsize == null) {
				lblsize = new JLabel(NCLangRes.getInstance().getStrByID("sftemp", "TakePotoPanel-0004")/*尺寸*/);
				lblsize.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			return lblsize;
		}

//		public JTextField getTxtsize() {
//			if (txtsize == null) {
//				txtsize = new JTextField();
//			}
//			return txtsize;
//		}

//		public JLabel getLblnamerule() {
//			if (lblnamerule == null) {
//				lblnamerule = new JLabel(NCLangRes.getInstance().getStrByID("sftemp", "TakePotoPanel-0005")/*命名规则*/);
//				lblnamerule.setHorizontalAlignment(SwingConstants.RIGHT);
//			}
//			return lblnamerule;
//		}
//
//		public JTextField getTxtnamerule() {
//			if (txtnamerule == null) {
//				txtnamerule = new JTextField();
//			}
//			return txtnamerule;
//		}

		public JButton getBtnsave() {
			if (btnsave == null) {
				btnsave = new JButton(NCLangRes.getInstance().getStrByID("sftemp", "TakePotoPanel-0006")/*保存*/);
				btnsave.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						int selindex = getChangescansize().getSelectedIndex();
						if(selindex==-1){
							selindex = 0 ;
						}
						//暂时保存到
						System.setProperty(FileBroseConst.GPYSIZE, selindex+"");
						//高拍仪设置
						getGpypanel().SetScanSize(selindex);
						GPYSettingDialog.this.close();

					}
				});
			}
			return btnsave;
		}

		public JButton getBtncancel() {
			if (btncancel == null) {
				btncancel = new JButton(NCLangRes.getInstance().getStrByID("sftemp", "UploadURLAction-0004")/*取消*/);
				btncancel.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						GPYSettingDialog.this.close();
					}
				});
			}
			return btncancel;
		}

		void initUI() {
			this.getContentPane().add(getMainpane());

		}

	}

//	@Override
//	public void repaint() {
//		// 
//		if(imagebrower!=null){
//			imagebrower=null;
//			getImagebrower();
//		}
//		super.repaint();
//	}
	
}
