package  client;
import java.awt.*;
//import java.awt.event.*;


import javax.swing.*;
//import javax.swing.event.*;


class Chooser_Font extends JFrame {
	
	public String[] styleList = new String[] { "Plain", "Bold", "Italic" ,"Bold+Italic"};

	public String[] sizeList = new String[] {  "8", "9", "10","11", "12", "13", "14", "15", "16"};
	
	public String enviroment[]=GraphicsEnvironment.getLocalGraphicsEnvironment()
	.getAvailableFontFamilyNames();
	
	public NwList StyleList;

	public NwList FontList;

	public NwList SizeList;
	
	JLabel styletitle;
	JLabel fonttitle;
	JLabel sizetitle;
	//=========================color============================
	JComboBox colorcomboBox;
	JLabel colortitle;
	String colorname[]={"黑色","白色","紅色","藍色","紫紅色","暗灰色","粉紅色",
			"灰色","橘色","黃色","青色","亮灰色","綠色"};
	public Color colorsetting[]={Color.BLACK,Color.WHITE,Color.RED,Color.BLUE,
			Color.MAGENTA,Color.DARK_GRAY,Color.PINK,Color.GRAY,Color.ORANGE,Color.YELLOW,
			Color.CYAN,Color.LIGHT_GRAY,Color.GREEN};
	Color fontcolor=Color.BLACK;
	//===========================================================
	Container c=getContentPane();
	
	public JLabel Sample = new JLabel();
	public JButton ok;
	public JButton ca;
//	boolean ob = false;
	public Font initial=null;

	public Chooser_Font() {
	////////////////////////
//		initAll();
		super("選擇字型");
		c.setLayout(null);
		setBounds(50, 50, 425, 405);
		addLists();
		addButtons();
		Sample.setBounds(10, 320, 240, 40);
		Sample.setFont(new Font("Helvetica" ,0 ,12 ));
		Sample.setBorder(BorderFactory.createTitledBorder("字型範例"));
		Sample.setForeground(Color.black);
		c.add(Sample);	
		setVisible(false);
		/////////////////////////
//		Sample.setFont(new Font("Helvetica" ,0 ,12 ));
//		setTitle("Font Choosr");
//		if (font == null)
		///in order to initial it;
		initial = Sample.getFont();	
//		font = Sample.getFont();
		///////////////////////////
//		FontList.setSelectedItem(font.getName());
//		SizeList.setSelectedItem(font.getSize() + "");
//		StyleList.setSelectedItem(styleList[font.getStyle()]);

	}

//	public static Font showDialog(Frame parent, String s, Font font) {
//		chooser_font fd = new chooser_font(parent, true, font);
//		if (s != null)
//			fd.setTitle(s);
//		fd.setVisible(true);
//		Font fo = null;
//		if (fd.ob)
//			fo = Sample.getFont();
//		else {
//			Sample.setFont(new Font("Helvetica" ,0 ,12 ));;
//			fo=Sample.getFont();
//		}fd.dispose();	
//		return (fo);
//	}

//	private void initAll() {
//		c.setLayout(null);
//		setBounds(50, 50, 425, 405);
//		addLists();
//		addButtons();
//		Sample.setBounds(10, 320, 240, 40);
//		Sample.setBorder(BorderFactory.createTitledBorder("字型範例"));
//		Sample.setForeground(Color.black);
//		c.add(Sample);
////		addWindowListener(new WindowAdapter() {
////			public void windowClosing(java.awt.event.WindowEvent e) {
//		setVisible(false);
////			}
////		});
//	}

	private void addLists() {
//		String enviroment[]=GraphicsEnvironment.getLocalGraphicsEnvironment()
//		.getAvailableFontFamilyNames();
//		FontList = new NwList(GraphicsEnvironment.getLocalGraphicsEnvironment()
//				.getAvailableFontFamilyNames());
		FontList=new NwList(enviroment);
		StyleList = new NwList(styleList);
		SizeList = new NwList(sizeList);
		FontList.setBounds(10, 20, 260, 295);
		StyleList.setBounds(280, 20, 80, 255);
		SizeList.setBounds(370, 20, 40, 255);
		fonttitle = new JLabel("字型");
		styletitle=new JLabel("字型樣式");
		sizetitle=new JLabel("大小");
		fonttitle.setBounds(10,8,260,12);
		styletitle.setBounds(280,8,80,12);
		sizetitle.setBounds(370,8,40,12);
		c.add(styletitle);
		c.add(fonttitle);
		c.add(sizetitle);
		c.add(FontList);
		c.add(StyleList);
		c.add(SizeList);
		////////////////
		colortitle=new JLabel("顏色");
		colortitle.setBounds(280,278,30,12);
		colorcomboBox=new JComboBox(colorname);
		colorcomboBox.setMaximumRowCount(14);
		colorcomboBox.setBounds(280,295,130,20);
//		colorcomboBox.addItemListener(
//				new ItemListener(){
//					public void itemStateChanged(ItemEvent e){
//						if(e.getStateChange()==ItemEvent.SELECTED){
//							fontcolor=colorsetting[colorcomboBox.getSelectedIndex()];
//							Sample.setForeground(fontcolor);
//						}
//					}
//				}
//		);
		c.add(colortitle);
		c.add(colorcomboBox);
		////////////////		
	}
//	public Color getfontColor(){
//		return Sample.getForeground();
//	}

	private void addButtons() {
		ok = new JButton("Ok");
		ok.setMargin(new Insets(0, 0, 0, 0));
		ca = new JButton("Cancel");
		ca.setMargin(new Insets(0, 0, 0, 0));
		ok.setBounds(260, 330, 70, 20);
		ok.setFont(new Font(" ", 1, 11));
		ca.setBounds(340, 330, 70, 20);
		ca.setFont(new Font(" ", 1, 12));
		getContentPane().add(ok);
		getContentPane().add(ca);
//		ok.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent e) {
//				setVisible(false);
//				ob = true;
//			}
//		});
//		ca.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent e) {
//				setVisible(false);
//				ob = false;
//			}
//		});
	}

//	private void showSample() {
//		int g = 0;
//		try {
//			g = Integer.parseInt(SizeList.getSelectedValue());
//		} catch (NumberFormatException nfe) {
//		}
//		String st = StyleList.getSelectedValue();
//		int s = 0;//Font.PLAIN;
//		if (st.equalsIgnoreCase("Bold"))
//			s = 1;//Font.BOLD;
//		if (st.equalsIgnoreCase("Italic"))
//			s = 2;//Font.ITALIC;
//		if(st.equalsIgnoreCase("Bold+Italic")){
//			s = 3;//Font.ITALIC+Font.BOLD;;
//		}
//		//fo=FontList.getSelectedValue();
//		Sample.setFont(new Font(FontList.getSelectedValue(), s, g));
//	
//	//	Sample.setText("The quick brown fox jumped over the lazy dog.");
//		Sample.setText(" choose Font and Size ");
//	}


	//////////////////////////////////////////////////////////////////////
	public class NwList extends JPanel {
		public JList jl;

		JScrollPane sp;

		public JLabel jt;

		public String si = " ";

		public NwList(String[] values) {
			setLayout(null);
			jl = new JList(values);
			sp = new JScrollPane(jl);
			jt = new JLabel();
			jt.setBackground(Color.white);
			jt.setForeground(Color.black);
			jt.setOpaque(true);
			jt.setBorder(new JTextField().getBorder());
			jt.setFont(getFont());
			jl.setBounds(0, 0, 100, 1000);
			jl.setBackground(Color.white);
//			jl.addListSelectionListener(new ListSelectionListener() {
//				public void valueChanged(ListSelectionEvent e) {
//					jt.setText((String) jl.getSelectedValue());
//					si = (String) jl.getSelectedValue();
//					showSample();
//				}
//			});
			add(sp);
			add(jt);
		}

		public String getSelectedValue() {
			return (si);
		}

		public void setSelectedItem(String s) {
			jl.setSelectedValue(s, true);
		}

		public void setBounds(int x, int y, int w, int h) {
			super.setBounds(x, y, w, h);
			sp.setBounds(0, y + 1, w, h-23);
			sp.revalidate();
			jt.setBounds(0, 0, w, 20);
		}
	}
}

