Package simtools.ui

Source Code of simtools.ui.DynamicColorChooser$DynamicColorChooserPanel

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*
* (C) Copyright 2001-2003, by :
*     Corporate:
*         Astrium SAS
*         EADS CRC
*     Individual:
*         Nicolas Brodu
*
* $Id: DynamicColorChooser.java,v 1.10 2008/09/29 10:05:43 ogor Exp $
*
* Changes
* -------
* 06-Oct-2003 : Initial version (NB);
*
*/
package simtools.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JPanel;
import simtools.data.DataSource;


/**
* @author nbrodu
*
* To change the template for this generated type comment go to Window -
* Preferences - Java - Code Generation - Code and Comments
*/
public class DynamicColorChooser extends JDialog implements MessageDisplayer{

    public static MenuResourceBundle resources = ResourceFinder.getMenu(DynamicColorChooser.class);


    protected HeaderPanel headerPanel;
    protected DynamicColorChooserPanel dynamicColorChooserPanel;
    protected JButton cancel, ok;
    protected boolean isOk;

    public DynamicColorChooser(
            Dialog parent,
            String title,
            JPanel preview,
            Color initialColor,
            DataSource ds,
            ColorMapper cm

    ){
        super(parent, title, true); // A color chooser is modal
       
        isOk = false;
       
        // Header
        headerPanel = new HeaderPanel();
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());
        contentPane.add(headerPanel, BorderLayout.NORTH);


        // Color chooser
        dynamicColorChooserPanel = new DynamicColorChooserPanel(
                this,
                preview,
                initialColor,
                ds,
                cm
        );
        contentPane.add(dynamicColorChooserPanel, BorderLayout.CENTER);
 
        // Bottom
        JPanel p = new JPanel();
        p.add(ok = new JButton(resources.getString("OK")));
        p.add(cancel = new JButton(resources.getString("Cancel")));


        ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dispose();
                isOk= true;
            }
        });

        cancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });

        contentPane.add(p, BorderLayout.SOUTH);
        pack();
    }

   
    public boolean isOk(){
        return isOk;
    }
   
    public ColorMapper getMapper() {
        return dynamicColorChooserPanel.getDynamicColorMapper();
    }

    public DataSource getSource() {
        return dynamicColorChooserPanel.getDynamicColorDataSource();
    }

    public Color getColor() {
        return dynamicColorChooserPanel.getColor();
    }

    public void clearAllMessages() {
        headerPanel.clearAllMessages();
    }

    public void displayError(String errorText) {
        headerPanel.displayError(errorText)
    }

    public void displayWarning(String warningText) {
        headerPanel.displayWarning(warningText)
    }

   
    public static class DynamicColorChooserPanel extends GridBagPanel{

        protected JColorChooser colorChooser;
        protected DynamicColorPanel dynamicColorPanel;
       
        DynamicColorChooserPanel(
                JDialog owner,
                JPanel preview,
                Color initialColor,
                DataSource source,
                ColorMapper mapper
        ) {
            super();

                colorChooser = ColorChooserProvider.colorChooserProvider.getColorChooser();
                if (initialColor != null) {
                    colorChooser.setColor(initialColor);
                }
                colorChooser.setBorder(BorderFactory.createTitledBorder(resources.getString("ChooseAStaticColor")));
                colorChooser.setPreviewPanel(preview);
               
              

                dynamicColorPanel = new DynamicColorPanel(owner, resources.getString("AllowDynamicColors"));
                dynamicColorPanel.setPropertyValue(DynamicColorPanel.DYNAMIC_COLOR_MAPPER, mapper);
                dynamicColorPanel.setPropertyValue(DynamicColorPanel.DYNAMIC_COLOR_SOURCE, source);

                addOnCurrentRow(colorChooser, 2, false, false, true);
                addOnCurrentRow(dynamicColorPanel, 2, true, true, true);

        }

        protected Color getColor(){
            Color res = null;
                res = colorChooser.getColor();
            return  res;
        }

        protected ColorMapper getDynamicColorMapper(){
            ColorMapper res = null;
            res = (ColorMapper)dynamicColorPanel.getPropertyValue(DynamicColorPanel.DYNAMIC_COLOR_MAPPER);
            return res;
        }

        protected DataSource getDynamicColorDataSource(){
            DataSource res = null;
                res = (DataSource)dynamicColorPanel.getPropertyValue(DynamicColorPanel.DYNAMIC_COLOR_SOURCE);
            return res;
        }

    }
TOP

Related Classes of simtools.ui.DynamicColorChooser$DynamicColorChooserPanel

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.