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

📄 settingspanel.java

📁 Delineate is a tool for converting bitmap raster images to SVG (Scalable Vector Graphics) using Auto
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * SettingsPanel.java * * Copyright (C) 2003 Robert McKinnon * * 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 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. */package net.sf.delineate.gui;import net.sf.delineate.command.Command;import net.sf.delineate.command.Parameter;import net.sf.delineate.utility.FileUtilities;import net.sf.delineate.utility.GuiUtilities;import net.sf.delineate.utility.XPathTool;import net.sf.delineate.utility.SettingUtilities;import javax.swing.AbstractAction;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JSpinner;import javax.swing.JTextField;import javax.swing.SpinnerNumberModel;import javax.swing.SpringLayout;import javax.swing.SpringUtilities;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.xml.transform.TransformerException;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.event.ActionEvent;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import java.io.File;import java.util.HashMap;import java.util.Map;import java.util.Properties;/** * Controls user defined settings. * @author robmckinnon@users.sourceforge.net */public class SettingsPanel implements RenderingListener {    private static final String INPUT_FILE_ACTION = "InputFileAction";    private static final String OUTPUT_FILE_ACTION = "OutputFileAction";    private static final String BACKGROUND_COLOR_ACTION = "BackgroundColorAction";    private final Map textFieldMap = new HashMap(5);    private final Map fileSizeLabelMap = new HashMap(5);    private final Map checkBoxMap = new HashMap(23);    private final Map spinnerSliderMap = new HashMap(23);    private final JPanel panel;    private Command command;    private JFileChooser tracingAppFileChooser;    private ColorEditor colorEditor;    private final ChangeListener changeListener = new ChangeListener() {        public void stateChanged(ChangeEvent e) {            Object source = e.getSource();            if(source instanceof SpinnerSlider) {                SpinnerSlider spinnerSlider = (SpinnerSlider)source;                command.setParameterValue(spinnerSlider.getName(), spinnerSlider.getValueAsString(), false);            } else {                JCheckBox checkBox = (JCheckBox)e.getSource();                command.setParameterEnabled(checkBox.getName(), checkBox.isSelected(), false);            }        }    };    private final KeyAdapter textFieldKeyListener = new KeyAdapter() {        public void keyReleased(KeyEvent e) {            JTextField textField = ((JTextField)e.getSource());            command.setParameterValue(textField.getName(), textField.getText(), false);            setFileSizeText(textField.getName(), textField.getText());        }    };    private static final String SETTINGS_FILE_NAME = "settings.prop";    public SettingsPanel(XPathTool xpathTool) throws Exception {        panel = new JPanel(new BorderLayout());        panel.setBorder(BorderFactory.createTitledBorder("Conversion settings"));        panel.add(initContentPane(xpathTool), BorderLayout.NORTH);        SaveSettingsPanel saveSettingsPanel = new SaveSettingsPanel(command);        panel.add(saveSettingsPanel.getPanel(), BorderLayout.SOUTH);    }    public void renderingCompleted() {        updateFileSize();    }    public JPanel getPanel() {        return panel;    }    public String getCommand() {        return command.getCommand();    }    public void setHeight(double height) {        command.setParameterValue("height", Double.toString(height), false);    }    public void setWidth(double width) {        command.setParameterValue("width", Double.toString(width), false);    }    public String getBackgroundColor() {        if(command.getParameterEnabled(Command.BACKGROUND_COLOR_PARAMETER)) {            return command.getParameterValue(Command.BACKGROUND_COLOR_PARAMETER);        } else {            return null;        }    }    public File getInputFile() {        String inputFile = command.getParameterValue(Command.INPUT_FILE_PARAMETER);        File file = new File(inputFile);        return file;    }    public void setInputFile(File file) {        command.setParameterValue(Command.INPUT_FILE_PARAMETER, file.getPath(), true);    }    public String getOutputFile() {        return command.getParameterValue(Command.OUTPUT_FILE_PARAMETER);    }    public void selectInputTextField() {        JTextField textField = getTextField(Command.INPUT_FILE_PARAMETER);        textField.selectAll();        textField.requestFocus();    }    public void updateFileSize() {        String file = command.getParameterValue(Command.OUTPUT_FILE_PARAMETER);        setFileSizeText(Command.OUTPUT_FILE_PARAMETER, file);    }    private JPanel initContentPane(XPathTool xpathTool) throws TransformerException {        final JPanel panel = new JPanel(new BorderLayout());        panel.setLayout(new SpringLayout());        String commandName = xpathTool.string("/parameters/command/name");        String optionIndicator = xpathTool.string("/parameters/command/option-indicator");        int descriptionCount = xpathTool.count("/parameters/parameter/description");        int parameterCount = xpathTool.count("/parameters/parameter");        command = new Command(commandName, optionIndicator, parameterCount, new Command.CommandChangeListener() {            public void enabledChanged(Parameter parameter) {                String name = parameter.getName();                JCheckBox checkBox = (JCheckBox)checkBoxMap.get(name);                if(checkBox != null) checkBox.setSelected(parameter.isEnabled());            }            public void valueChanged(Parameter parameter) {                String name = parameter.getName();                if(name.equals(Command.BACKGROUND_COLOR_PARAMETER)) {                    colorEditor.setColor(parameter.getValue());                } else {                    JTextField textField = (JTextField)textFieldMap.get(name);                    if(textField != null) {                        String path = parameter.getValue();                        textField.setText(path);                    }                    SpinnerSlider spinnerSlider = (SpinnerSlider)spinnerSliderMap.get(name);                    if(spinnerSlider != null) {                        spinnerSlider.setValue(parameter.getValue());                    }                }            }        });        loadTracingApplicationPath(panel);        for(int type = 0; type < 3; type++) {            for(int i = 0; i < parameterCount; i++) {                String xpathPrefix = "/parameters/parameter[" + (i + 1) + "]/";                xpathTool.setXpathPrefix(xpathPrefix);                String name = xpathTool.string("name");                boolean isFileParameter = name.endsWith("file");                boolean isNumberParameter = xpathTool.count("range") == 1;                switch(type) {                    case 0:                        if(isFileParameter)                            addParameter(panel, xpathTool, xpathPrefix, name);                        break;                    case 1:                        if(!isFileParameter && !isNumberParameter)                            addParameter(panel, xpathTool, xpathPrefix, name);                        break;                    case 2:                        if(!isFileParameter && isNumberParameter)                            addParameter(panel, xpathTool, xpathPrefix, name);                        break;                }            }        }        SpringUtilities.makeCompactGrid(panel, descriptionCount, 2, 6, 6, 6, 6);        return panel;    }    private void loadTracingApplicationPath(final JPanel parent) {        Properties properties = SettingUtilities.loadProperties(SETTINGS_FILE_NAME, parent);        String commandPath = properties.getProperty(command.getCommandName());        if(commandPath != null) {            command.setTracingApplication(commandPath);        }    }    public void showTracingApplicationSelectionDialog() {        if(tracingAppFileChooser == null) {            String dialogTitle = "Select location of " + command.getCommandName();            JFileChooser fileChooser = initFileChooser(dialogTitle);            this.tracingAppFileChooser = fileChooser;        }        int response = tracingAppFileChooser.showOpenDialog(panel);        if(response == JFileChooser.APPROVE_OPTION) {            File file = tracingAppFileChooser.getSelectedFile();            String commandPath = file.getPath();            command.setTracingApplication(commandPath);            Properties properties = SettingUtilities.loadProperties(SETTINGS_FILE_NAME, panel);            properties.setProperty(command.getCommandName(), commandPath);            SettingUtilities.saveProperties(properties, SETTINGS_FILE_NAME, "Delineate tracing application settings - http//delineate.sourceforge.net");

⌨️ 快捷键说明

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