Package de.timefinder.core.ui.command

Source Code of de.timefinder.core.ui.command.ChangeSettingsCommand

/*
*  Copyright 2009 Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net.
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*  under the License.
*/
package de.timefinder.core.ui.command;

import de.timefinder.data.algo.DataPoolSettings;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.springframework.beans.factory.annotation.Autowired;

/**
* This UI class provides the Import class to the user
*
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class ChangeSettingsCommand extends AbstractImportCommand {

    public static final String ID = "changeSettings";
    private DataPoolSettings settings;

    public ChangeSettingsCommand() {
        super(ID);
    }

    @Autowired
    public void setSettings(DataPoolSettings settings) {
        this.settings = settings;
    }

    public static void main(String[] args) {
        new ChangeSettingsCommand().doOnce();
    }

    @Override
    protected void doOnce() {
        closeAllViews();

        // TODO move to jgoodies layout / miglayout
        JPanel panel = new JPanel(new GridLayout(0, 2));
        JTextField daysTextField = new JTextField(20);
        daysTextField.setText("" + settings.getNumberOfDays());

        JLabel daysLabel = new JLabel(tr.get(ID + ".days"));
        JTextField slotsTextField = new JTextField(20);
        slotsTextField.setText("" + settings.getTimeslotsPerDay());
        JLabel slotsLabel = new JLabel(tr.get(ID + ".slots"));

        panel.add(daysLabel);
        panel.add(daysTextField);
        panel.add(slotsLabel);
        panel.add(slotsTextField);

        JOptionPane.showMessageDialog(null, panel);
        Exception daysError = null;
        Exception slotsError = null;

        try {
            settings.setNumberOfDays(Integer.parseInt(daysTextField.getText()));
        } catch (Exception ex) {
            daysError = ex;
        }

        try {
            settings.setTimeslotsPerDay(Integer.parseInt(slotsTextField.getText()));
        } catch (Exception ex) {
            slotsError = ex;
        }

        if (slotsError != null || daysError != null) {
            panel = new JPanel(new GridLayout(0, 1));

            if (slotsError != null)
                panel.add(new JLabel(tr.get(ID + ".daysError") + slotsError.getMessage()));
            if (daysError != null)
                panel.add(new JLabel(tr.get(ID + ".slotsError") + daysError.getMessage()));

            JOptionPane.showMessageDialog(null, panel, tr.get(ID + ".inputError"), JOptionPane.ERROR_MESSAGE);
        }
    }
}
TOP

Related Classes of de.timefinder.core.ui.command.ChangeSettingsCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.