⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optionpanel.java

📁 思维导图(Mind Mapping)以放射性思考(Radiant Thinking)为基础的收放自如方式
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*FreeMind - A Program for creating and viewing Mindmaps *Copyright (C) 2005   Christian Foltin. * *See COPYING for Details * *This program is free software; you can redistribute it and/or *modify it under the terms of the GNU General Public License *as published by the Free Software Foundation; either version 2 *of the License, or (at your option) any later version. * *This program is distributed in the hope that it will be useful, *but WITHOUT ANY WARRANTY; without even the implied warranty of *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *GNU General Public License for more details. * *You should have received a copy of the GNU General Public License *along with this program; if not, write to the Free Software *Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * Created on 06.05.2005 *//*$Id: OptionPanel.java,v 1.1.2.16 2005/08/13 21:36:46 christianfoltin Exp $*/package freemind.preferences.layout;import java.awt.BorderLayout;import java.awt.CardLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.io.IOException;import java.util.Arrays;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;import java.util.Properties;import java.util.Vector;import javax.swing.DefaultComboBoxModel;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JColorChooser;import javax.swing.JComboBox;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax.swing.JScrollPane;import javax.swing.JSlider;import javax.swing.JSpinner;import javax.swing.JSplitPane;import javax.swing.JTextField;import javax.swing.SpinnerNumberModel;import javax.swing.UIManager;import javax.swing.UIManager.LookAndFeelInfo;import javax.xml.bind.JAXBException;import com.jgoodies.forms.builder.DefaultFormBuilder;import com.jgoodies.forms.factories.ButtonBarFactory;import com.jgoodies.forms.layout.FormLayout;import freemind.controller.Controller;import freemind.controller.actions.generated.instance.OptionPanelWindowConfigurationStorage;import freemind.controller.actions.generated.instance.OptionPanelWindowConfigurationStorageType;import freemind.controller.actions.generated.instance.WindowConfigurationStorage;import freemind.main.FreeMind;import freemind.main.FreeMindMain;import freemind.main.Tools;import freemind.modes.MindMapNode;/** * @author foltin *   */public class OptionPanel {	//TODO: Cancel and windowClose => Are you sure, or save.	//FIXME: key dialog	//FIXME: Translate me and html	private static final Color MARKED_BUTTON_COLOR = Color.BLUE;	private Vector controls;	private final JDialog frame;	private HashMap tabButtonMap = new HashMap();	private HashMap tabActionMap = new HashMap();	private String selectedPanel = null;	private static JColorChooser colorChooser;	private final OptionPanelFeedback feedback;	private static FreeMindMain fmMain;	private static final String PREFERENCE_STORAGE_PROPERTY = "OptionPanel_Window_Properties";    private static final String DEFAULT_LAYOUT_FORMAT = "right:max(40dlu;p), 4dlu, 120dlu, 7dlu";	/**	 * @param frame	 * @param feedback	 * @throws IOException	 *  	 */	public OptionPanel(FreeMindMain fm, JDialog frame,			OptionPanelFeedback feedback) {		super();		if (fmMain == null) {			fmMain = fm;		}		this.frame = frame;		this.feedback = feedback;		//Retrieve window size and column positions.		WindowConfigurationStorage storage = fm.getController().decorateDialog(				frame, PREFERENCE_STORAGE_PROPERTY);		if (storage == null) {			frame.getRootPane().setPreferredSize(new Dimension(800, 600));		} else {			if (storage instanceof OptionPanelWindowConfigurationStorageType) {				OptionPanelWindowConfigurationStorageType oWindowSettings = (OptionPanelWindowConfigurationStorageType) storage;				selectedPanel = oWindowSettings.getPanel();			}		}	}	public interface OptionPanelFeedback {		void writeProperties(Properties props);	}	public static Vector changeListeners = new Vector();	private static Properties getProperties() {		checkConnectionToFreeMindMain();		return fmMain.getProperties();	}	/**	 * @param properties	 */	public void setProperties(Properties properties) {		for (Iterator i = controls.iterator(); i.hasNext();) {			PropertyControl control = (PropertyControl) i.next();			if (control instanceof PropertyBean) {				PropertyBean bean = (PropertyBean) control;				//				System.out.println("grep -n -e \""+bean.getLabel()+"\" -r * |				// grep -e \"\\.(java|xml):\"");				String value = properties.getProperty(bean.getLabel());				//				System.out.println("Setting property " + bean.getLabel()				//						+ " to " + value);				bean.setValue(value);			}		}	}	private Properties getOptionProperties() {		Properties p = new Properties();		for (Iterator i = controls.iterator(); i.hasNext();) {			PropertyControl control = (PropertyControl) i.next();			if (control instanceof PropertyBean) {				PropertyBean bean = (PropertyBean) control;				p.setProperty(bean.getLabel(), bean.getValue());			}		}		return p;	}	public void buildPanel() {		FormLayout leftLayout = new FormLayout("80dlu", "");		DefaultFormBuilder leftBuilder = new DefaultFormBuilder(leftLayout);		CardLayout cardLayout = new CardLayout();		JPanel rightStack = new JPanel(cardLayout);		FormLayout rightLayout = null; // add rows dynamically		DefaultFormBuilder rightBuilder = null;		String lastTabName = null;		controls = getControls();		for (Iterator i = controls.iterator(); i.hasNext();) {			PropertyControl control = (PropertyControl) i.next();			//			System.out.println("layouting : " + control.getLabel());			if (control instanceof NewTabProperty) {				NewTabProperty newTab = (NewTabProperty) control;				if (rightBuilder != null) {					// terminate old panel:					rightStack.add(rightBuilder.getPanel(), lastTabName);				}				rightLayout = new FormLayout(newTab.getDescription(), "");				rightBuilder = new DefaultFormBuilder(rightLayout);				rightBuilder.setDefaultDialogBorder();				lastTabName = newTab.getLabel();				// add a button to the left side:				JButton tabButton = new JButton(getText(lastTabName));				ChangeTabAction changeTabAction = new ChangeTabAction(						cardLayout, rightStack, lastTabName);				tabButton.addActionListener(changeTabAction);				registerTabButton(tabButton, lastTabName, changeTabAction);				leftBuilder.append(tabButton);			} else {				control.layout(rightBuilder);			}		}		// add the last one, too		rightStack.add(rightBuilder.getPanel(), lastTabName);		// select one panel:		if(selectedPanel != null && tabActionMap.containsKey(selectedPanel)){			((ChangeTabAction) tabActionMap.get(selectedPanel)).actionPerformed(null);		}		JSplitPane centralPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,				leftBuilder.getPanel(), new JScrollPane(rightStack));		frame.getContentPane().add(centralPanel, BorderLayout.CENTER);		JButton cancelButton = new JButton(getText("Cancel"));		cancelButton.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent arg0) {				closeWindow();			}		});		JButton okButton = new JButton(getText("OK"));		okButton.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent arg0) {				feedback.writeProperties(getOptionProperties());				closeWindow();			}		});		frame.getRootPane().setDefaultButton(okButton);		frame.getContentPane().add(				ButtonBarFactory.buildOKCancelBar(cancelButton, okButton),				BorderLayout.SOUTH);	}	private static String lastKey = "";	/**	 * @param string	 * @return	 */	private static String getText(String string) {		if (string == null)			return null;		checkConnectionToFreeMindMain();		return fmMain.getResourceString("OptionPanel." + string);	}	private static void checkConnectionToFreeMindMain() {		if (fmMain == null) {			throw new IllegalArgumentException("FreeMindMain not set yet.");		}	}	/**	 * @param tabButton	 * @param changeTabAction	 * @param lastTabName	 */	private void registerTabButton(JButton tabButton, String name,			ChangeTabAction changeTabAction) {		tabButtonMap.put(name, tabButton);		tabActionMap.put(name, changeTabAction);		// if no default panel was given, we use the first.		if(selectedPanel == null){			selectedPanel = name;		}	}	private JButton getTabButton(String name) {		return (JButton) tabButtonMap.get(name);	}	private Collection getAllButtons() {		return tabButtonMap.values();	}	private final class ChangeTabAction implements ActionListener {		private CardLayout cardLayout;		private JPanel centralPanel;		private String tabName;		private ChangeTabAction(CardLayout cardLayout, JPanel centralPanel,				String tabName) {			super();			this.cardLayout = cardLayout;			this.centralPanel = centralPanel;			this.tabName = tabName;		}		public void actionPerformed(ActionEvent arg0) {			cardLayout.show(centralPanel, tabName);			// design: mark selected button with a color			Collection c = getAllButtons();			for (Iterator i = c.iterator(); i.hasNext();) {				JButton button = (JButton) i.next();				button.setForeground(null);			}			getTabButton(tabName).setForeground(MARKED_BUTTON_COLOR);			selectedPanel = tabName;		}	}	private interface PropertyControl {		String getDescription();		String getLabel();		void layout(DefaultFormBuilder builder);	}	private interface PropertyBean {		/** The key of the property. */		String getLabel();		void setValue(String value);		String getValue();	}	private static class SeparatorProperty implements PropertyControl {		private String label;		public SeparatorProperty(String label) {			super();			this.label = label;		}		public String getDescription() {			return null;		}		public String getLabel() {			return label;		}		public void layout(DefaultFormBuilder builder) {			builder.appendSeparator(getText("separator." + getLabel()));		}	}	private static class NewTabProperty implements PropertyControl {		private String label;        private String layoutFormat;		public NewTabProperty(String label) {			this(label, DEFAULT_LAYOUT_FORMAT);		}		public NewTabProperty(String label, String layoutFormat) {			super();			this.label = label;			this.layoutFormat = layoutFormat;		}		public String getDescription() {			return layoutFormat;		}		public String getLabel() {			return label;		}		public void layout(DefaultFormBuilder builder) {		}	}	private static class NextLineProperty implements PropertyControl {		public NextLineProperty() {			super();		}		public String getDescription() {			return null;		}		public String getLabel() {			return null;		}		public void layout(DefaultFormBuilder builder) {			builder.nextLine();		}	}	private static class StringProperty extends JTextField implements			PropertyControl, PropertyBean {		String description;		String label;		/**		 * @param description		 * @param label		 */		public StringProperty(String description, String label) {			super();			this.description = description;			this.label = label;		}		public String getDescription() {			return description;		}		public String getLabel() {			return label;		}		public void setValue(String value) {			setText(value);		}		public String getValue() {			return getText();		}		public void layout(DefaultFormBuilder builder) {			JLabel label = builder					.append(OptionPanel.getText(getLabel()), this);			label.setToolTipText(OptionPanel.getText(getDescription()));		}	}	private static class NumberProperty implements	PropertyControl, PropertyBean {	    String description;	    JSlider slider;	    String label;        private JSpinner spinner;	    	    /**	     * @param description	     * @param label	     */	    public NumberProperty(String description, String label, int min, int max, int step) {	        slider = new JSlider(JSlider.HORIZONTAL, 5, 1000, 100);	        spinner = new JSpinner(              new SpinnerNumberModel(min, min, max, step));	        this.description = description;	        this.label = label;	    }	    	    public String getDescription() {	        return description;	    }	    	    public String getLabel() {	        return label;	    }	    	    public void setValue(String value) {            int intValue = 100;            try {                intValue = Integer.parseInt(value);            } catch(NumberFormatException e){                e.printStackTrace();            }            spinner.setValue(new Integer(intValue));	    }	    	    public String getValue() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -