Package jsynoptic.builtin.ui

Source Code of jsynoptic.builtin.ui.PropertiesPanel2D

/* ========================
* 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
*        Jean-Baptiste Lièvremont
*
* $Id: PropertiesPanel2D.java,v 1.9 2008/09/29 08:59:59 ogor Exp $
*
* Changes
* -------
*
*/
package jsynoptic.builtin.ui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.JCheckBox;

import jsynoptic.builtin.Abstract2DShape;
import jsynoptic.builtin.Abstract2DShape.Abstract2DShapePropertiesNames;

import simtools.data.DataSource;
import simtools.diagram.DiagramParameters;
import simtools.ui.ColorMapper;
import simtools.ui.DynamicColorChooser;
import simtools.ui.ResourceFinder;

/**
* Properties panel for <code>Abstract2DShape</code>s
*
* @author Jean-Baptiste Li&egrave;vremont
* @see jsynoptic.builtin.Abstract2DShape
* @see simtools.ui.JPropertiesPanel
*/
public class PropertiesPanel2D extends PropertiesPanel1D {
    public static ResourceBundle resources = ResourceFinder.get(Abstract2DShape.class);

    protected JButton bfillcolor;

    protected JCheckBox cbfill;

    protected Color fillColor;

    protected ColorMapper fillMapper;

    protected transient DataSource fillMapperSource;

    protected boolean fillEnabled;

    public PropertiesPanel2D(String shapeName) {
        super(shapeName);
    }

    public PropertiesPanel2D(boolean showResize, boolean drawOptional, String shapeName) {
        super(showResize, drawOptional, shapeName);
    }

    public PropertiesPanel2D(boolean showResize, boolean drawOptional, boolean showStroke, boolean showTransform,
            String shapeName) {
        super(showResize, drawOptional, showStroke, showTransform, shapeName);
    }

    protected void setColorPanel(boolean drawOptional) {
        // Initialize our copy fields (allow users to cancel changes)
        fillColor = DiagramParameters.DEFAULT_COLOR;
        fillMapper = null;
        fillMapperSource = null;
        cbfill = new JCheckBox(fillColorLabel(), (fillColor != null)
                || ((fillMapper != null) && (fillMapperSource != null)));
        cbfill.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                displayFillCustomisation(cbfill.isSelected());
            }
        });
        bfillcolor = new JButton("    ");
        bfillcolor.setFocusPainted(false);
        if (fillColor == null) {
            fillColor = DiagramParameters.DEFAULT_COLOR;
        }
        bfillcolor.setBackground(fillColor);
        bfillcolor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
               
                DynamicColorChooser dialog = new DynamicColorChooser(
                        PropertiesPanel2D.this.getOwner(),
                        fillColorChooserTitle(),
                        null, fillColor, fillMapperSource, fillMapper);
               
                dialog.pack();
                dialog.setVisible(true);

                if (dialog.isOk()){

                    fillColor = dialog.getColor();
                    bfillcolor.setBackground(fillColor);

                    fillMapperSource = dialog.getSource();
                    fillMapper = dialog.getMapper();

                    cbfill.setSelected(true);
                }
            }
        });
        colorAndStrokePanel.addOnCurrentRow(cbfill);
        colorAndStrokePanel.addOnCurrentRow(bfillcolor);
        colorAndStrokePanel.carriageReturn();
       
        super.setColorPanel(drawOptional);
    }

    
    protected void displayFillCustomisation(boolean display) {
        fillEnabled = display;
        bfillcolor.setEnabled(display);
    }

    /** Allow subclasses to override default text easily : text for the label */
    protected String fillColorLabel() {
        return resources.getString("FillShapeColor");
    }

    /**
     * Allow subclasses to override default text easily : text for the color
     * chooser
     */
    protected String fillColorChooserTitle() {
        return resources.getString("FillShapeColorTitle");
    }

    public String[] getPropertyNames() {
        if (_propertyNames == null) {
            _propertyNames = new Abstract2DShapePropertiesNames().getPropertyNames();
        }
        return _propertyNames;
    }

    public void setPropertyValue(String name, Object value) {
        if (name.equalsIgnoreCase("FILL_COLOR")) {
            if (value instanceof Color) {
                fillColor = (Color) value;
                cbfill.setSelected(true);
            } else {
                fillColor = DiagramParameters.DEFAULT_COLOR;
                cbfill.setSelected(false);
            }
            displayFillCustomisation(cbfill.isSelected());
            bfillcolor.setBackground(fillColor);
        } else if (name.equalsIgnoreCase("FILL_MAPPER")) {
            if (value instanceof ColorMapper) {
                fillMapper = (ColorMapper) value;
            }
        } else if (name.equalsIgnoreCase("FILL_MAPPER_SOURCE")) {
            if (value instanceof DataSource) {
                fillMapperSource = (DataSource) value;
            }
        }
        super.setPropertyValue(name, value);
    }

    public Object getPropertyValue(String name) {
        Object res = super.getPropertyValue(name);
        if (name.equalsIgnoreCase("FILL_COLOR")) {
            res = cbfill.isSelected() ? fillColor : null;
        } else if (name.equalsIgnoreCase("FILL_MAPPER")) {
            res = fillMapper;
        } else if (name.equalsIgnoreCase("FILL_MAPPER_SOURCE")) {
            res = fillMapperSource;
        }
        return res;
    }
}
TOP

Related Classes of jsynoptic.builtin.ui.PropertiesPanel2D

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.