/*

 * Title: japlot.jaxodraw
 * Description: Graphical user interface for drawing Feynman diagrams
 * @author Daniele Binosi 
 * @author Lukas Theussl  

 Copyright (C) 2003-2006,  Daniele Binosi and Lukas Theussl

 See the file LICENSE in the source distribution home directory
 for a full copy of the GPL (GNU General Public License).

    This file is part of japlot.jaxodraw.

    japlot.jaxodraw 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.

    japlot.jaxodraw 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 japlot.jaxodraw;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;

import java.util.ResourceBundle;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.TitledBorder;

import jhplot.jadraw.JaObject;


/** A panel that allows the rescaling of a group. */
public class JaxoRescalePanel extends JPanel {
    private ResourceBundle language =
        ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));

    /** The group to be rescaled. */
    private JaxoGroup theGroup;

    //    private JPanel scalePanel;
    //private TitledBorder scalePanelTitle;
    //    private float scale;
    private boolean changed = false;

    /** Constructor: brings up the panel.
     * @param group The group to be rescaled.
     */
    public JaxoRescalePanel(JaxoGroup group) {
        this.theGroup = group;

        JPanel prad = new JPanel();
        prad.setLayout(new GridLayout(0, 2));

        SpinnerNumberModel modelrad =
            new SpinnerNumberModel(1.0, 0.0, 50.0, 0.05);
        JLabel rad =
            new JLabel(language.getString("Scale") + ": ", JLabel.RIGHT);
        prad.add(rad);

        JSpinner sprad = new JSpinner(modelrad);
        prad.add(sprad);

        JPanel dimSPanel = new JPanel();
        GridBagLayout gb = new GridBagLayout();
        GridBagConstraints sc = new GridBagConstraints();
        dimSPanel.setLayout(gb);
        sc.gridx = 0;
        sc.gridy = 0;
        sc.insets = new Insets(0, 5, 5, 5);
        prad.setPreferredSize(new Dimension(120, 20));
        gb.setConstraints(prad, sc);
        dimSPanel.add(prad, sc);

        JPanel finalDimSPanel = new JPanel();
        finalDimSPanel.setLayout(new BoxLayout(finalDimSPanel, BoxLayout.X_AXIS));

        TitledBorder dimSTitle =
            BorderFactory.createTitledBorder(language.getString("Scale_Factor"));
        finalDimSPanel.setBorder(dimSTitle);
        finalDimSPanel.add(dimSPanel);

        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();

        setLayout(gridbag);
        c.gridx = 0;
        c.gridy = 0;
        c.insets = new Insets(0, 0, 5, 5);
        gridbag.setConstraints(finalDimSPanel, c);
        add(finalDimSPanel, c);

        String[] optionButtonNames =
        {language.getString("Accept"), language.getString("Cancel")};
        int n =
            JOptionPane.showOptionDialog(this, this,
                language.getString("Rescale_Group"),
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE,
                null, optionButtonNames, optionButtonNames[0]);

        if (n == JOptionPane.OK_OPTION) {
            float newScale =
                (float) Math.abs(modelrad.getNumber().floatValue());
            rescaleGroup((JaxoGroup) theGroup, newScale);

            changed = true;
        }
    }

    /** Indicates whether the user actually changed any of the parameters.
     * @return True if any of the properties have been changed.
     */
    public final boolean hasChanged() {
        return changed;
    }

    private void rescaleGroup(JaxoGroup group, float scl) {
        double[] bbox = group.getBoundingBox();
        int orx = (int) Math.round(bbox[JaObject.BB_MIN_X]);
        int ory = (int) Math.round(bbox[JaObject.BB_MIN_Y]);

        theGroup.rescaleObject(orx, ory, scl);
    }
}

 

Ads help maintain this website.