/*

 * 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.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.MemoryImageSource;

import java.io.File;

import java.util.ResourceBundle;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.LookAndFeel;
import javax.swing.SpinnerNumberModel;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.TitledBorder;


/** Responsible for importing/exporting user preferences. */
public class JaxoPrefsPanel extends JFrame implements ActionListener,
    ItemListener {
    private ResourceBundle language =
        ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));
    private Color newColor =
        JaxoColor.getColor(JaxoPrefs.getPref(JaxoPrefs.PREF_COLOR));
    private Color newTColor;
    private ImageIcon colorPreviewIcon;
    private ImageIcon colorTPreviewIcon;
    private JButton colorbt;
    private JButton colorTbt;
    private Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    private JSpinner sprot;
    private JSpinner sprot1;
    private SpinnerNumberModel modelgrid;
    private SpinnerNumberModel modelwidth;
    private SpinnerNumberModel modelamp;
    private SpinnerNumberModel modelXin;
    private SpinnerNumberModel modelYin;
    private SpinnerNumberModel modelsep;
    private SpinnerNumberModel modelrot;
    private SpinnerNumberModel modelrot1;
    private JaxoMainPanel thePanel;
    private JTextField psTextField;
    private JTextField editorTextField;
    private JTextField htmlTextField;
    private JTextField latexPathTextField;
    private JTextField dvipsPathTextField;
    private JCheckBox statusbarCheckBox;
    private JCheckBox toolbarCheckBox;
    private JCheckBox antialiasCheckBox;
    private JCheckBox arrowCheckBox;
    private JCheckBox gridCheckBox;
    private JRadioButton[] lookAndFeelRB;
    private JComboBox chooselanguage;
    private JComboBox chooseGridType;
    private String[] humanReadableName;
    private int num; // the number of Look and Feels
    private Vector knownLanguages;
    private Vector gridTypes;
    private JComboBox famcomb;
    private JComboBox sizecomb;
    private JComboBox stycomb;
    private JComboBox allicomb;
    private JComboBox defcomb;
    private JComboBox fscomb;
    private String fontChoice = JaxoPrefs.getPref(JaxoPrefs.PREF_PSFAMILY);
    private int sizeChoiceInt = JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSIZE);
    private int styleChoice = JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSTYLE);
    private int newAlli = JaxoPrefs.getIntPref(JaxoPrefs.PREF_TEXALIGN);
    private int newDef = JaxoPrefs.getIntPref(JaxoPrefs.PREF_DEFAULTACTION);
    private int newLatexFS = JaxoPrefs.getIntPref(JaxoPrefs.PREF_TEXSIZE);
    private int newPSRot = -JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSROTANGLE);
    private int newTeXRot = -JaxoPrefs.getIntPref(JaxoPrefs.PREF_TEXROTANGLE);
    private Font dialogFont = new Font("Dialog", 1, 12);

    /** Creates new JaxoPrefs dialog.
     * @param panel The current JaxoMainPanel.
     */
    public JaxoPrefsPanel(JaxoMainPanel panel) {
        this.thePanel = panel;
        initComponents();
    }

    private void initComponents() {
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setKnownLanguages();
        setGridTypes();

        // General tab
        JPanel fPreviewCont = createOptionContainer();
        fPreviewCont.add(getFPreviewPanel(), BorderLayout.CENTER);

        // Appearence tab
        JPanel fAppearenceCont = createOptionContainer();
        fAppearenceCont.add(getFAppearencePanel(), BorderLayout.CENTER);

        // Behavior tab
        JTabbedPane fBehaviorPanel = new JTabbedPane(JTabbedPane.LEFT);
        fBehaviorPanel.add(language.getString("Default"), getBDefCont());
        fBehaviorPanel.add(language.getString("Grid"), getBGridCont());
        fBehaviorPanel.add(language.getString("Objects"), getBObjectCont());
        fBehaviorPanel.add(language.getString("Text"), getBTextCont());

        // Main frame
        JTabbedPane jtb = new JTabbedPane();
        jtb.add(language.getString("General"), fPreviewCont);
        jtb.add(language.getString("Appearence"), fAppearenceCont);
        jtb.add(language.getString("Behavior"), fBehaviorPanel);

        setTitle(language.getString("Preferences"));
        getContentPane().add(jtb, BorderLayout.CENTER);
        pack();

        Dimension frameSize = this.getSize();

        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }

        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }

        setLocation((screenSize.width - frameSize.width) / 2,
            (screenSize.height - frameSize.height) / 2);
    }

    private void cancelButtonClicked() {
        dispose();
    }

    private void resetButtonClicked() {
        psTextField.setText(JaxoPrefs.getStringPref(JaxoPrefs.PREF_PSVIEWER));
        htmlTextField.setText(JaxoPrefs.getStringPref(JaxoPrefs.PREF_BROWSER));
        editorTextField.setText(JaxoPrefs.getStringPref(JaxoPrefs.PREF_EDITOR));
        latexPathTextField.setText(JaxoPrefs.getStringPref(
                JaxoPrefs.PREF_LATEXPATH));
        dvipsPathTextField.setText(JaxoPrefs.getStringPref(
                JaxoPrefs.PREF_DVIPSPATH));

        // laf
        for (int i = 0; i < num; i++) {
            lookAndFeelRB[i].setSelected(false);

            String prefLOOKNFEEL =
                JaxoPrefs.getStringPref(JaxoPrefs.PREF_LOOKNFEEL);

            if (prefLOOKNFEEL.equals(humanReadableName[i])) {
                lookAndFeelRB[i].setSelected(true);
            }
        }

        // language
        int selected = 0;

        for (int i = 0; i < knownLanguages.size(); i++) {
            if (knownLanguages.elementAt(i).equals(JaxoPrefs.getPref(
                            JaxoPrefs.PREF_LANGUAGE))) {
                selected = i;
            }
        }

        chooselanguage.setSelectedIndex(selected);

        // grid type
        int selectedg = 0;

        for (int i = 0; i < gridTypes.size(); i++) {
            if (gridTypes.elementAt(i).equals(JaxoPrefs.getPref(
                            JaxoPrefs.PREF_GRIDTYPE))) {
                selectedg = i;
            }
        }

        chooseGridType.setSelectedIndex(selectedg);

        // color
        colorbt.setIcon(new ImageIcon(getChooserImage(JaxoColor.getColor(
                        JaxoPrefs.getPref(JaxoPrefs.PREF_COLOR)))));

        // PS font
        famcomb.setSelectedIndex(getFamilyIndex(JaxoPrefs.getPref(
                    JaxoPrefs.PREF_PSFAMILY)));
        stycomb.setSelectedIndex(JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSTYLE));
        sizecomb.setSelectedIndex(getSizeIndex(
                (new Integer(JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSIZE)))
                .toString()));

        // TeX alignment/size
        allicomb.setSelectedIndex(JaxoPrefs.getIntPref(JaxoPrefs.PREF_TEXALIGN));
        fscomb.setSelectedIndex(JaxoPrefs.getIntPref(JaxoPrefs.PREF_TEXSIZE));

        // Default action
        defcomb.setSelectedIndex(JaxoPrefs.getIntPref(
                JaxoPrefs.PREF_DEFAULTACTION));

        int prefGRIDSIZE = JaxoPrefs.getIntPref(JaxoPrefs.PREF_GRIDSIZE);
        float prefLINEWIDTH = JaxoPrefs.getFloatPref(JaxoPrefs.PREF_LINEWIDTH);

        int prefAMPLITUDE = JaxoPrefs.getIntPref(JaxoPrefs.PREF_AMPLITUDE);
        float prefDLSEP = JaxoPrefs.getFloatPref(JaxoPrefs.PREF_DLSEP);
        boolean prefSHOWTOOL =
            JaxoPrefs.getBooleanPref(JaxoPrefs.PREF_SHOWTOOL);
        boolean prefSHOWSTATUS =
            JaxoPrefs.getBooleanPref(JaxoPrefs.PREF_SHOWSTATUS);
        boolean prefANTIALIASON =
            JaxoPrefs.getBooleanPref(JaxoPrefs.PREF_ANTIALIAS);
        boolean prefARROW = JaxoPrefs.getBooleanPref(JaxoPrefs.PREF_ARROW);

        //boolean prefGRIDONOFF =
        //    JaxoPrefs.getBooleanPref(JaxoPrefs.PREF_GRIDONOFF);
        modelgrid.setValue(new Integer(prefGRIDSIZE));
        modelwidth.setValue(new Float(prefLINEWIDTH));

        modelamp.setValue(new Integer(prefAMPLITUDE));
        modelXin.setValue(new Integer(JaxoPrefs.getIntPref(
                    JaxoPrefs.PREF_SCREENSIZEX)));
        modelYin.setValue(new Integer(JaxoPrefs.getIntPref(
                    JaxoPrefs.PREF_SCREENSIZEY)));
        modelsep.setValue(new Float(prefDLSEP));

        toolbarCheckBox.setSelected(prefSHOWTOOL);
        statusbarCheckBox.setSelected(prefSHOWSTATUS);
        antialiasCheckBox.setSelected(prefANTIALIASON);
        arrowCheckBox.setSelected(prefARROW);
    }

    private void clearButtonClicked() {
        psTextField.setText("");
        htmlTextField.setText("");
        editorTextField.setText("");
        latexPathTextField.setText("");
        dvipsPathTextField.setText("");
    }

    private void saveButtonClicked() {

        String prefFileName=jhplot.HPlotJa.PREFS_FILENAME;
        // temporarily save the current settings in case a user
        // wants to save the preferences without applying them
        String tmpEditor = JaxoPrefs.getPref(JaxoPrefs.PREF_EDITOR);
        String tmpBrowser = JaxoPrefs.getPref(JaxoPrefs.PREF_BROWSER);
        String tmpPSViewer = JaxoPrefs.getPref(JaxoPrefs.PREF_PSVIEWER);
        String tmpLAF = JaxoPrefs.getPref(JaxoPrefs.PREF_LOOKNFEEL);
        String tmpLang = JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE);
        String tmpGridT = JaxoPrefs.getPref(JaxoPrefs.PREF_GRIDTYPE);
        String tmpColor = JaxoPrefs.getPref(JaxoPrefs.PREF_COLOR);
        String tmpPSFamily = JaxoPrefs.getPref(JaxoPrefs.PREF_PSFAMILY);
        String tmpTColor = JaxoPrefs.getPref(JaxoPrefs.PREF_TEXTCOLOR);
        String tmpLatexPath = JaxoPrefs.getPref(JaxoPrefs.PREF_LATEXPATH);
        String tmpDvipsPath = JaxoPrefs.getPref(JaxoPrefs.PREF_DVIPSPATH);
        String tmpscreenX = JaxoPrefs.getPref(JaxoPrefs.PREF_SCREENSIZEX);
        String tmpscreenY = JaxoPrefs.getPref(JaxoPrefs.PREF_SCREENSIZEY);
        String tmpGrid = JaxoPrefs.getPref(JaxoPrefs.PREF_GRIDSIZE);
        String tmpPSStyle = JaxoPrefs.getPref(JaxoPrefs.PREF_PSSTYLE);
        String tmpPSSize = JaxoPrefs.getPref(JaxoPrefs.PREF_PSSIZE);
        String tmpTeXSize = JaxoPrefs.getPref(JaxoPrefs.PREF_TEXSIZE);
        String tmpTeXAlign = JaxoPrefs.getPref(JaxoPrefs.PREF_TEXALIGN);
        String tmpLineWidth = JaxoPrefs.getPref(JaxoPrefs.PREF_LINEWIDTH);
        String tmpDLSep = JaxoPrefs.getPref(JaxoPrefs.PREF_DLSEP);

        String tmpAmp = JaxoPrefs.getPref(JaxoPrefs.PREF_AMPLITUDE);
        String tmptool = JaxoPrefs.getPref(JaxoPrefs.PREF_SHOWTOOL);
        String tmpanti = JaxoPrefs.getPref(JaxoPrefs.PREF_ANTIALIAS);
        String tmparrow = JaxoPrefs.getPref(JaxoPrefs.PREF_ARROW);
        String tmpstatus = JaxoPrefs.getPref(JaxoPrefs.PREF_SHOWSTATUS);
        String tmpGridOnOff = JaxoPrefs.getPref(JaxoPrefs.PREF_GRIDONOFF);

        String tmpPSRotAngle = JaxoPrefs.getPref(JaxoPrefs.PREF_PSROTANGLE);
        String tmpTeXRotAngle = JaxoPrefs.getPref(JaxoPrefs.PREF_TEXROTANGLE);

        String tmpDef = JaxoPrefs.getPref(JaxoPrefs.PREF_DEFAULTACTION);

        setPrefs(); // Preferences have to be set for exporting
        JaxoPrefs.exportPrefs(prefFileName);

        // set back to saved values
        JaxoPrefs.setPref(JaxoPrefs.PREF_EDITOR, tmpEditor);
        JaxoPrefs.setPref(JaxoPrefs.PREF_BROWSER, tmpBrowser);
        JaxoPrefs.setPref(JaxoPrefs.PREF_PSVIEWER, tmpPSViewer);
        JaxoPrefs.setPref(JaxoPrefs.PREF_LOOKNFEEL, tmpLAF);
        JaxoPrefs.setPref(JaxoPrefs.PREF_GRIDTYPE, tmpGridT);
        JaxoPrefs.setPref(JaxoPrefs.PREF_COLOR, tmpColor);
        JaxoPrefs.setPref(JaxoPrefs.PREF_PSFAMILY, tmpPSFamily);
        JaxoPrefs.setPref(JaxoPrefs.PREF_TEXTCOLOR, tmpTColor);
        JaxoPrefs.setPref(JaxoPrefs.PREF_LATEXPATH, tmpLatexPath);
        JaxoPrefs.setPref(JaxoPrefs.PREF_DVIPSPATH, tmpDvipsPath);
        JaxoPrefs.setPref(JaxoPrefs.PREF_SCREENSIZEX, tmpscreenX);
        JaxoPrefs.setPref(JaxoPrefs.PREF_SCREENSIZEY, tmpscreenY);
        JaxoPrefs.setPref(JaxoPrefs.PREF_GRIDSIZE, tmpGrid);
        JaxoPrefs.setPref(JaxoPrefs.PREF_PSSTYLE, tmpPSStyle);
        JaxoPrefs.setPref(JaxoPrefs.PREF_PSSIZE, tmpPSSize);
        JaxoPrefs.setPref(JaxoPrefs.PREF_TEXSIZE, tmpTeXSize);
        JaxoPrefs.setPref(JaxoPrefs.PREF_TEXALIGN, tmpTeXAlign);
        JaxoPrefs.setPref(JaxoPrefs.PREF_LINEWIDTH, tmpLineWidth);
        JaxoPrefs.setPref(JaxoPrefs.PREF_DLSEP, tmpDLSep);

        JaxoPrefs.setPref(JaxoPrefs.PREF_SHOWTOOL, tmptool);
        JaxoPrefs.setPref(JaxoPrefs.PREF_SHOWSTATUS, tmpstatus);
        JaxoPrefs.setPref(JaxoPrefs.PREF_ANTIALIAS, tmpanti);
        JaxoPrefs.setPref(JaxoPrefs.PREF_ARROW, tmparrow);
        JaxoPrefs.setPref(JaxoPrefs.PREF_AMPLITUDE, tmpAmp);
        JaxoPrefs.setPref(JaxoPrefs.PREF_LANGUAGE, tmpLang);
        JaxoPrefs.setPref(JaxoPrefs.PREF_GRIDONOFF, tmpGridOnOff);

        JaxoPrefs.setPref(JaxoPrefs.PREF_PSROTANGLE, tmpPSRotAngle);
        JaxoPrefs.setPref(JaxoPrefs.PREF_TEXROTANGLE, tmpTeXRotAngle);
        JaxoPrefs.setPref(JaxoPrefs.PREF_DEFAULTACTION, tmpDef);
    }

    private void okButtonClicked() {
        int gridSize = modelgrid.getNumber().intValue();

        if (gridSize != JaxoPrefs.getIntPref(JaxoPrefs.PREF_GRIDSIZE)) {
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            double[] newbb = {5, 5, d.width, d.height};

            for (int i = 0; i < thePanel.getCanvasPanel().getTabCount();
                    i++) {
                ((JaxoCanvas) thePanel.getCanvasPanel().getComponentAt(i))
                .setGridSize(gridSize);
                ((JaxoCanvas) thePanel.getCanvasPanel().getComponentAt(i))
                .setOldbb(newbb);
                ((JaxoCanvas) thePanel.getCanvasPanel().getComponentAt(i))
                .updateOffScreenImage();
            }
        }

        if (!((String) gridTypes.elementAt(chooseGridType.getSelectedIndex()))
                .equals(JaxoPrefs.getPref(JaxoPrefs.PREF_GRIDTYPE))) {
            boolean type = false;

            if (((String) gridTypes.elementAt(
                        chooseGridType.getSelectedIndex())).equals("hexagonal")) {
                type = true;
            }

            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            double[] newbb = {5, 5, d.width, d.height};

            for (int i = 0; i < thePanel.getCanvasPanel().getTabCount();
                    i++) {
                ((JaxoCanvas) thePanel.getCanvasPanel().getComponentAt(i))
                .setGridType(type);
                ((JaxoCanvas) thePanel.getCanvasPanel().getComponentAt(i))
                .setOldbb(newbb);
                ((JaxoCanvas) thePanel.getCanvasPanel().getComponentAt(i))
                .updateOffScreenImage();
            }
        }

        if (gridCheckBox.isSelected() != JaxoPrefs.getBooleanPref(
                    JaxoPrefs.PREF_GRIDONOFF)) {
            JaxoOptionsMenu optionsmenu = thePanel.getOptMenu();
            optionsmenu.gridOn(gridCheckBox.isSelected());
        }

        setPrefs();
        applyPrefs();
        dispose();
    }

    /** Sets the preferences indicated in the preferences dialog to be permanent for the
     * current session.
     */
    private void setPrefs() {
        int screenSizeX = modelXin.getNumber().intValue();
        int screenSizeY = modelYin.getNumber().intValue();
        int gridSize = modelgrid.getNumber().intValue();
        float lineWidth = modelwidth.getNumber().floatValue();
        float dlSep = modelsep.getNumber().floatValue();
        int amp = modelamp.getNumber().intValue();
        String lang =
            (String) knownLanguages.elementAt(chooselanguage.getSelectedIndex());
        String gridType =
            (String) gridTypes.elementAt(chooseGridType.getSelectedIndex());

        String col = JaxoColor.getColorName(newColor);
        String colT = JaxoColor.getColorName(newTColor);
        newPSRot = modelrot.getNumber().intValue();
        newTeXRot = modelrot1.getNumber().intValue();

        JaxoPrefs.setPref(JaxoPrefs.PREF_BROWSER, htmlTextField.getText());
        JaxoPrefs.setPref(JaxoPrefs.PREF_EDITOR, editorTextField.getText());
        JaxoPrefs.setPref(JaxoPrefs.PREF_PSVIEWER, psTextField.getText());

        for (int i = 0; i < num; i++) {
            if (lookAndFeelRB[i].isSelected()) {
                JaxoPrefs.setPref(JaxoPrefs.PREF_LOOKNFEEL,
                    humanReadableName[i]);
            }
        }

        JaxoPrefs.setPref(JaxoPrefs.PREF_LANGUAGE, lang);
        JaxoPrefs.setPref(JaxoPrefs.PREF_GRIDTYPE, gridType);
        JaxoPrefs.setPref(JaxoPrefs.PREF_COLOR, col);
        JaxoPrefs.setPref(JaxoPrefs.PREF_PSFAMILY, fontChoice);
        JaxoPrefs.setPref(JaxoPrefs.PREF_TEXTCOLOR, colT);
        JaxoPrefs.setPref(JaxoPrefs.PREF_LATEXPATH,
            latexPathTextField.getText());
        JaxoPrefs.setPref(JaxoPrefs.PREF_DVIPSPATH,
            dvipsPathTextField.getText());

        JaxoPrefs.setIntPref(JaxoPrefs.PREF_SCREENSIZEX, screenSizeX);
        JaxoPrefs.setIntPref(JaxoPrefs.PREF_SCREENSIZEY, screenSizeY);
        JaxoPrefs.setIntPref(JaxoPrefs.PREF_GRIDSIZE, gridSize);

        JaxoPrefs.setIntPref(JaxoPrefs.PREF_AMPLITUDE, amp);
        JaxoPrefs.setIntPref(JaxoPrefs.PREF_PSSTYLE, styleChoice);
        JaxoPrefs.setIntPref(JaxoPrefs.PREF_PSSIZE, sizeChoiceInt);
        JaxoPrefs.setIntPref(JaxoPrefs.PREF_TEXSIZE, newLatexFS);
        JaxoPrefs.setIntPref(JaxoPrefs.PREF_TEXALIGN, newAlli);

        JaxoPrefs.setFloatPref(JaxoPrefs.PREF_LINEWIDTH, lineWidth);
        JaxoPrefs.setFloatPref(JaxoPrefs.PREF_DLSEP, dlSep);
        JaxoPrefs.setBooleanPref(JaxoPrefs.PREF_SHOWTOOL,
            toolbarCheckBox.isSelected());
        JaxoPrefs.setBooleanPref(JaxoPrefs.PREF_SHOWSTATUS,
            statusbarCheckBox.isSelected());
        JaxoPrefs.setBooleanPref(JaxoPrefs.PREF_ANTIALIAS,
            antialiasCheckBox.isSelected());
        JaxoPrefs.setBooleanPref(JaxoPrefs.PREF_ARROW,
            arrowCheckBox.isSelected());
        JaxoPrefs.setBooleanPref(JaxoPrefs.PREF_GRIDONOFF,
            gridCheckBox.isSelected());
        JaxoPrefs.setIntPref(JaxoPrefs.PREF_PSROTANGLE, -newPSRot);
        JaxoPrefs.setIntPref(JaxoPrefs.PREF_TEXROTANGLE, -newTeXRot);
        JaxoPrefs.setIntPref(JaxoPrefs.PREF_DEFAULTACTION, newDef);
    }

    private void applyPrefs() {
        thePanel.applyPrefs();
    }

    /** Checks for ActionEvents that have ocurred on the panel,
     *  presently only whether the color button has been pressed in which
     *  case a new color chooser panel is popped up.
     * @param evt The ActionEvent that has ocurred.
     */
    public final void actionPerformed(ActionEvent evt) {
        if (evt.getSource() == colorbt) {
            JaxoColorChooser colorChooser = new JaxoColorChooser();
            newColor = colorChooser.color(newColor, false);

            if (newColor != null) {
                colorPreviewIcon = new ImageIcon(getChooserImage(newColor));
                colorbt.setIcon(colorPreviewIcon);
            }
        } else if (evt.getSource() == colorTbt) {
            JaxoColorChooser colorChooser = new JaxoColorChooser();
            newTColor = colorChooser.color(newTColor, false);

            if (newTColor != null) {
                colorTPreviewIcon = new ImageIcon(getChooserImage(newTColor));
                colorTbt.setIcon(colorTPreviewIcon);
            }
        } else if (evt.getSource() == allicomb) {
            newAlli = allicomb.getSelectedIndex();
        } else if (evt.getSource() == fscomb) {
            newLatexFS = fscomb.getSelectedIndex();
        } else if (evt.getSource() == defcomb) {
            newDef = defcomb.getSelectedIndex();
        }
    }

    private JPanel createOptionContainer() {
        JButton okBt = new JButton();
        okBt.setText(language.getString("OK"));
        okBt.setToolTipText(language.getString(
                "Set_the_preferences_for_the_current_session"));
        okBt.addMouseListener(new MouseAdapter() {
                public final void mouseClicked(MouseEvent evt) {
                    okButtonClicked();
                }
            });

        JButton saveBt = new JButton();
        saveBt.setText(language.getString("Save"));
        saveBt.setToolTipText(language.getString(
                "Save_the_current_settings_to_make_them_permanent"));
        saveBt.addMouseListener(new MouseAdapter() {
                public final void mouseClicked(MouseEvent evt) {
                    saveButtonClicked();
                }
            });

        JButton clearBt = new JButton();
        clearBt.setText(language.getString("Clear"));
        clearBt.setToolTipText(language.getString("Clear_all_the_text_fields"));
        clearBt.addMouseListener(new MouseAdapter() {
                public final void mouseClicked(MouseEvent evt) {
                    clearButtonClicked();
                }
            });

        JButton resetBt = new JButton();
        resetBt.setText(language.getString("Reset"));
        resetBt.setToolTipText(language.getString("Reset_the_initial_values"));
        resetBt.addMouseListener(new MouseAdapter() {
                public final void mouseClicked(MouseEvent evt) {
                    resetButtonClicked();
                }
            });

        JButton cancelBt = new JButton();
        cancelBt.setText(language.getString("Cancel"));
        cancelBt.setToolTipText(language.getString(
                "Abondon_the_current_dialog"));
        cancelBt.addMouseListener(new MouseAdapter() {
                public final void mouseClicked(MouseEvent evt) {
                    cancelButtonClicked();
                }
            });

        JPanel btPanel = new JPanel();
        btPanel.add(okBt);
        btPanel.add(saveBt);
        btPanel.add(clearBt);
        btPanel.add(resetBt);
        btPanel.add(cancelBt);

        JPanel opCont = new JPanel();
        opCont.setLayout(new BorderLayout());
        opCont.add(btPanel, BorderLayout.SOUTH);

        return opCont;
    }

    private Image getChooserImage(Color iconColor) {
        MemoryImageSource source;
        int[] pixels;
        int width = 40;
        int height = 15;
        int size = width * height;
        pixels = new int[size];

        for (int i = 0; i < size; i++) {
            pixels[i] = iconColor.getRGB();
        }

        source = new MemoryImageSource(width, height, pixels, 0, width);

        Image jaxColorBox = createImage(source);

        return jaxColorBox;
    }

    /** Defines the font that corresponds to the selected font from the pull down lists.
     * @param e The ItemEvent
     */
    public final void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() != ItemEvent.SELECTED) {
            return;
        }

        Object list = e.getSource();
        String sizeChoice;

        if (list == famcomb) {
            fontChoice = (String) famcomb.getSelectedItem();
        } else if (list == stycomb) {
            styleChoice = stycomb.getSelectedIndex();
        } else {
            sizeChoice = (String) sizecomb.getSelectedItem();

            Integer thisSize = new Integer(sizeChoice);
            sizeChoiceInt = thisSize.intValue();
        }
    }

    private int getSizeIndex(String s) {
        String[] sizes =
        {
            "4", "6", "8", "10", "12", "14", "16", "18", "20", "22", "24", "26",
            "28", "30", "32", "34", "36", "38", "40", "42", "44", "46", "48",
            "50", "52", "54", "56", "58", "60", "62", "64"
        };
        int i = 0;

        while (sizes[i].compareTo(s) != 0) {
            i++;
        }

        if (sizes[i].compareTo(s) == 0) {
            return i;
        }

        return -1;
    }

    private int getFamilyIndex(String s) {
        String[] envFonts = JaxoStaticCanvasMethods.getSystemFonts();
        int i = envFonts.length;

        for (int j = 0; j < i; j++) {
            if ((envFonts[j]).compareTo(s) == 0) {
                i = j;

                break;
            }
        }

        if (i < envFonts.length) {
            return i;
        } else {
            return 0;
        }
    }

    private JPanel getLanguagePanel() {
        Vector i18nKnownLanguages = new Vector();
        i18nKnownLanguages.addElement(language.getString("English"));
        i18nKnownLanguages.addElement(language.getString("German"));
        i18nKnownLanguages.addElement(language.getString("French"));
        i18nKnownLanguages.addElement(language.getString("Spanish"));
        i18nKnownLanguages.addElement(language.getString("Italian"));

        chooselanguage = new JComboBox(i18nKnownLanguages);

        int selected = 0;

        for (int i = 0; i < knownLanguages.size(); i++) {
            if (knownLanguages.elementAt(i).equals(JaxoPrefs.getPref(
                            JaxoPrefs.PREF_LANGUAGE))) {
                selected = i;
            }
        }

        chooselanguage.setSelectedIndex(selected);

        JPanel languagePanel = new JPanel();
        languagePanel.setBorder(new TitledBorder(null,
                language.getString("Language"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));

        JLabel languageLabel = new JLabel();
        languageLabel.setText(language.getString("Default_language"));
        languagePanel.add(languageLabel);
        languagePanel.add(chooselanguage);

        return languagePanel;
    }

    private void setKnownLanguages() {
        knownLanguages = new Vector(5);
        knownLanguages.addElement("english");
        knownLanguages.addElement("german");
        knownLanguages.addElement("french");
        knownLanguages.addElement("spanish");
        knownLanguages.addElement("italian");
    }

    private void setGridTypes() {
        gridTypes = new Vector();
        gridTypes.addElement("rectangular");
        gridTypes.addElement("hexagonal");
    }

    private JPanel getLookNFeelPanel() {
        JPanel lookNFeelPanel = new JPanel();
        lookNFeelPanel.setBorder(new TitledBorder(null,
                language.getString("Look_and_Feel"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));

        String currentLookAndFeel = UIManager.getLookAndFeel().getName();

        ButtonGroup group = new ButtonGroup();
        LookAndFeelInfo[] info = UIManager.getInstalledLookAndFeels();
        LookAndFeel thisLaF = UIManager.getLookAndFeel();
        num = info.length;
        humanReadableName = new String[num];

        String[] className = new String[num];
        lookAndFeelRB = new JRadioButton[num];

        for (int i = 0; i < num; i++) {
            humanReadableName[i] = info[i].getName();
            className[i] = info[i].getClassName();
            lookAndFeelRB[i] = new JRadioButton(humanReadableName[i]);

            try { // check whether this LaF is supported
                UIManager.setLookAndFeel(className[i]);
            } catch (Exception exc) {
                lookAndFeelRB[i].setEnabled(false);
            }

            try { // set back the current one
                UIManager.setLookAndFeel(thisLaF);
            } catch (Exception exc) {
                // this should work in any case
                if (JaxoPrefs.verbose()) {
                    System.out.println(exc);
                }
            }

            lookNFeelPanel.add(lookAndFeelRB[i]);
            group.add(lookAndFeelRB[i]);
            lookAndFeelRB[i].setActionCommand(humanReadableName[i]);

            if (humanReadableName[i].equals(currentLookAndFeel)) {
                lookAndFeelRB[i].setSelected(true);
            }
        }

        return lookNFeelPanel;
    }

    private JPanel getLafPanel() {
        JPanel lafPanel = new JPanel();
        lafPanel.setLayout(new FlowLayout());
        lafPanel.add(getLookNFeelPanel());
        lafPanel.add(getLanguagePanel());

        return lafPanel;
    }

    private JPanel getFAppearencePanel() {
        JPanel fAppearencePanel = new JPanel();
        fAppearencePanel.setLayout(new BoxLayout(fAppearencePanel,
                BoxLayout.Y_AXIS));
        fAppearencePanel.add(getLafPanel());
        fAppearencePanel.add(getInitScreenPanel());
        fAppearencePanel.add(getCheckBoxPanel());

        return fAppearencePanel;
    }

    private JPanel getCheckBoxPanel() {
        JPanel checkBoxPanel = new JPanel();
        checkBoxPanel.setBorder(new TitledBorder(null,
                language.getString("Other_options"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));
        checkBoxPanel.setLayout(new GridLayout(2, 2));

        toolbarCheckBox = new JCheckBox();
        toolbarCheckBox.setSelected(JaxoPrefs.getBooleanPref(
                JaxoPrefs.PREF_SHOWTOOL));
        toolbarCheckBox.setText(language.getString("Show_toolbar"));
        checkBoxPanel.add(toolbarCheckBox);

        statusbarCheckBox = new JCheckBox();
        statusbarCheckBox.setSelected(JaxoPrefs.getBooleanPref(
                JaxoPrefs.PREF_SHOWSTATUS));
        statusbarCheckBox.setText(language.getString("Show_status_bar"));
        checkBoxPanel.add(statusbarCheckBox);

        antialiasCheckBox = new JCheckBox();
        antialiasCheckBox.setSelected(JaxoPrefs.getBooleanPref(
                JaxoPrefs.PREF_ANTIALIAS));
        antialiasCheckBox.setText(language.getString("Antialias_on"));
        checkBoxPanel.add(antialiasCheckBox);

        return checkBoxPanel;
    }

    private JPanel getInitScreenPanel() {
        JPanel pxin = new JPanel();
        pxin.setLayout(new GridLayout(0, 2));
        modelXin =
            new SpinnerNumberModel(JaxoPrefs.getIntPref(
                    JaxoPrefs.PREF_SCREENSIZEX), 0, screenSize.width, 1);

        JLabel xin =
            new JLabel(language.getString("Size_X:") + " ", JLabel.RIGHT);
        pxin.add(xin);

        JSpinner spxin = new JSpinner(modelXin);
        pxin.add(spxin);

        JPanel pyin = new JPanel();
        pyin.setLayout(new GridLayout(0, 2));
        modelYin =
            new SpinnerNumberModel(JaxoPrefs.getIntPref(
                    JaxoPrefs.PREF_SCREENSIZEY), 0, screenSize.height, 1);

        JLabel yin =
            new JLabel(language.getString("Size_Y:") + " ", JLabel.RIGHT);
        pyin.add(yin);

        JSpinner spyin = new JSpinner(modelYin);
        pyin.add(spyin);

        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, 0, 5, 0);
        pxin.setPreferredSize(new Dimension(145, 20));
        gb.setConstraints(pxin, sc);
        dimSPanel.add(pxin, sc);

        sc.gridx = 1;
        sc.gridy = 0;
        sc.insets = new Insets(0, 0, 5, 5);
        pyin.setPreferredSize(new Dimension(145, 20));
        gb.setConstraints(pyin, sc);
        dimSPanel.add(pyin, sc);

        JPanel initScreenPanel = new JPanel();
        initScreenPanel.setBorder(new TitledBorder(null,
                language.getString("Initial_screen_size"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));
        initScreenPanel.add(dimSPanel);

        return initScreenPanel;
    }

    private JPanel getPreviewPanel() {
        JPanel previewPanel = new JPanel();
        previewPanel.setBorder(new TitledBorder(null,
                language.getString("Preview_options"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));

        JLabel htmlLabel = new JLabel();
        htmlLabel.setText(language.getString("Preferred_HTML_viewer"));
        htmlTextField =
            new JTextField(JaxoPrefs.getStringPref(JaxoPrefs.PREF_BROWSER));
        htmlTextField.setPreferredSize(new Dimension(130, 20));

        JLabel editorLabel = new JLabel();
        editorLabel.setText(language.getString("Preferred_text_editor"));
        editorTextField =
            new JTextField(JaxoPrefs.getStringPref(JaxoPrefs.PREF_EDITOR));
        editorTextField.setPreferredSize(new Dimension(130, 20));

        JLabel psLabel = new JLabel();
        psLabel.setText(language.getString("Preferred_postscript_viewer___"));
        psTextField =
            new JTextField(JaxoPrefs.getStringPref(JaxoPrefs.PREF_PSVIEWER));
        psTextField.setPreferredSize(new Dimension(130, 20));

        GridBagLayout grba = new GridBagLayout();
        GridBagConstraints con = new GridBagConstraints();

        previewPanel.setLayout(grba);

        con.gridx = 0;
        con.gridy = 0;
        con.anchor = GridBagConstraints.LINE_START;
        grba.setConstraints(htmlLabel, con);
        previewPanel.add(htmlLabel);

        con.gridx = 0;
        con.gridy = 1;
        con.anchor = GridBagConstraints.LINE_START;
        grba.setConstraints(editorLabel, con);
        previewPanel.add(editorLabel);

        con.gridx = 0;
        con.gridy = 2;
        con.anchor = GridBagConstraints.LINE_START;
        grba.setConstraints(psLabel, con);
        previewPanel.add(psLabel);

        con.gridx = 1;
        con.gridy = 0;
        grba.setConstraints(htmlTextField, con);
        previewPanel.add(htmlTextField);

        con.gridx = 1;
        con.gridy = 1;
        grba.setConstraints(editorTextField, con);
        previewPanel.add(editorTextField);

        con.gridx = 1;
        con.gridy = 2;
        grba.setConstraints(psTextField, con);
        previewPanel.add(psTextField);

        return previewPanel;
    }

    private JPanel getPathPanel() {
        JPanel pathPanel = new JPanel();
        pathPanel.setBorder(new TitledBorder(null,
                language.getString("Paths"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));

        JLabel latexPathLabel = new JLabel();
        latexPathLabel.setText(language.getString("LaTeX_path:"));
        latexPathTextField =
            new JTextField(JaxoPrefs.getStringPref(JaxoPrefs.PREF_LATEXPATH));
        latexPathTextField.setPreferredSize(new Dimension(130, 20));

        JLabel dvipsPathLabel = new JLabel();
        dvipsPathLabel.setText(language.getString("dvips_path:"));
        dvipsPathTextField =
            new JTextField(JaxoPrefs.getStringPref(JaxoPrefs.PREF_DVIPSPATH));
        dvipsPathTextField.setPreferredSize(new Dimension(130, 20));

        GridBagLayout grba1 = new GridBagLayout();
        GridBagConstraints con1 = new GridBagConstraints();

        pathPanel.setLayout(grba1);

        con1.gridx = 0;
        con1.gridy = 0;
        con1.anchor = GridBagConstraints.LINE_START;
        grba1.setConstraints(latexPathLabel, con1);
        pathPanel.add(latexPathLabel);

        con1.gridx = 0;
        con1.gridy = 1;
        con1.anchor = GridBagConstraints.LINE_START;
        grba1.setConstraints(dvipsPathLabel, con1);
        pathPanel.add(dvipsPathLabel);

        con1.gridx = 1;
        con1.gridy = 0;
        grba1.setConstraints(latexPathTextField, con1);
        pathPanel.add(latexPathTextField);

        con1.gridx = 1;
        con1.gridy = 1;
        grba1.setConstraints(dvipsPathTextField, con1);
        pathPanel.add(dvipsPathTextField);

        return pathPanel;
    }

    private JPanel getFPreviewPanel() {
        JPanel fPreviewPanel = new JPanel();
        fPreviewPanel.setLayout(new BoxLayout(fPreviewPanel, BoxLayout.Y_AXIS));
        fPreviewPanel.add(getPreviewPanel());
        fPreviewPanel.add(getPathPanel());

        return fPreviewPanel;
    }

    private JPanel getGridOnOffPanel() {
        JPanel gridCheckBoxPanel = new JPanel();
        gridCheckBox = new JCheckBox();
        gridCheckBox.setSelected(JaxoPrefs.getBooleanPref(
                JaxoPrefs.PREF_GRIDONOFF));
        gridCheckBox.setText(language.getString("Grid_on"));
        gridCheckBoxPanel.add(gridCheckBox);
        gridCheckBoxPanel.setBorder(new TitledBorder(null,
                language.getString("Grid_on_off"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));

        return gridCheckBoxPanel;
    }

    private JPanel getGridTypePanel() {
        Vector gridCombTypes = new Vector();
        gridCombTypes.addElement(language.getString("Rectangular"));
        gridCombTypes.addElement(language.getString("Hexagonal"));

        chooseGridType = new JComboBox(gridCombTypes);

        int selectedg = 0;

        for (int i = 0; i < gridTypes.size(); i++) {
            if (gridTypes.elementAt(i).equals(JaxoPrefs.getPref(
                            JaxoPrefs.PREF_GRIDTYPE))) {
                selectedg = i;
            }
        }

        chooseGridType.setSelectedIndex(selectedg);

        JPanel gridTypePanel = new JPanel();
        gridTypePanel.setBorder(new TitledBorder(null,
                language.getString("Grid_type"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));

        JLabel gridTypeLabel = new JLabel();
        gridTypeLabel.setText(language.getString("Type"));
        gridTypePanel.add(gridTypeLabel);
        gridTypePanel.add(chooseGridType);

        return gridTypePanel;
    }

    private JPanel getGridSizePanel() {
        JPanel pgrid = new JPanel();
        pgrid.setLayout(new GridLayout(0, 2));

        int prefGRIDSIZE = JaxoPrefs.getIntPref(JaxoPrefs.PREF_GRIDSIZE);
        modelgrid = new SpinnerNumberModel(prefGRIDSIZE, 1, 75, 1);

        JLabel lgrid =
            new JLabel(language.getString("Size_:") + " ", JLabel.RIGHT);
        pgrid.add(lgrid);

        JSpinner spgrid = new JSpinner(modelgrid);
        pgrid.add(spgrid);

        JPanel gridSizePanel = new JPanel();
        gridSizePanel.setBorder(new TitledBorder(null,
                language.getString("Grid_size"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));
        gridSizePanel.add(pgrid);

        return gridSizePanel;
    }

    private JPanel getColorPanel() {
        Image colorPreview = getChooserImage(newColor);
        colorPreviewIcon = new ImageIcon(colorPreview);

        colorbt = new JButton(colorPreviewIcon);
        colorbt.addActionListener(this);

        JPanel colorPanel = new JPanel();
        TitledBorder colorPanelTitle =
            BorderFactory.createTitledBorder(language.getString("Line_color"));

        colorPanel.setBorder(colorPanelTitle);
        colorPanel.add(colorbt);

        return colorPanel;
    }

    private JPanel getLineWidthPanel() {
        JPanel pwidth = new JPanel();
        pwidth.setLayout(new GridLayout(0, 2));
        modelwidth =
            new SpinnerNumberModel(JaxoPrefs.getFloatPref(
                    JaxoPrefs.PREF_LINEWIDTH), 0.2, 100.0, 0.2);

        JLabel lwidth =
            new JLabel(language.getString("Width_:") + " ", JLabel.RIGHT);
        pwidth.add(lwidth);

        JSpinner spwidth = new JSpinner(modelwidth);
        pwidth.add(spwidth);

        JPanel lineWidthPanel = new JPanel();
        lineWidthPanel.setBorder(new TitledBorder(null,
                language.getString("Line_width"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));
        lineWidthPanel.add(pwidth);

        return lineWidthPanel;
    }

    private JPanel getArrowPanel() {
        arrowCheckBox = new JCheckBox();
        arrowCheckBox.setSelected(JaxoPrefs.getBooleanPref(
                JaxoPrefs.PREF_ARROW));
        arrowCheckBox.setText(language.getString("Arrows"));

        JPanel arrowPanel = new JPanel();
        arrowPanel.setBorder(new TitledBorder(null,
                language.getString("Arrows"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));
        arrowPanel.add(arrowCheckBox);

        return arrowPanel;
    }

    private JPanel getSepPanel() {
        JPanel psep = new JPanel();
        psep.setLayout(new GridLayout(0, 2));
        modelsep =
            new SpinnerNumberModel(JaxoPrefs.getFloatPref(JaxoPrefs.PREF_DLSEP),
                0.2, 100.0, 0.5);

        JLabel lsep =
            new JLabel(language.getString("Separation1"), JLabel.RIGHT);
        psep.add(lsep);

        JSpinner spsep = new JSpinner(modelsep);
        psep.add(spsep);

        JPanel sepPanel = new JPanel();
        sepPanel.setBorder(new TitledBorder(null,
                language.getString("Double_line_separation:"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));
        sepPanel.add(psep);

        return sepPanel;
    }

    private JPanel getAmpPanel() {
        JPanel pamp = new JPanel();
        pamp.setLayout(new GridLayout(0, 2));
        modelamp =
            new SpinnerNumberModel(JaxoPrefs.getIntPref(
                    JaxoPrefs.PREF_AMPLITUDE), -500.0, 500.0, 1);

        JLabel lamp =
            new JLabel(language.getString("Size_:") + " ", JLabel.RIGHT);
        pamp.add(lamp);

        JSpinner spamp = new JSpinner(modelamp);
        pamp.add(spamp);

        JPanel ampPanel = new JPanel();
        ampPanel.setBorder(new TitledBorder(null,
                language.getString("Amplitude1"),
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION, dialogFont, JaxoColor.BLACK));
        ampPanel.add(pamp);

        return ampPanel;
    }

    private JPanel getColorTPanel() {
        newTColor =
            JaxoColor.getColor(JaxoPrefs.getPref(JaxoPrefs.PREF_TEXTCOLOR));

        Image colorTPreview = getChooserImage(newTColor);
        colorTPreviewIcon = new ImageIcon(colorTPreview);

        colorTbt = new JButton(colorTPreviewIcon);
        colorTbt.addActionListener(this);

        JPanel colorTPanel = new JPanel();
        TitledBorder colorTPanelTitle =
            BorderFactory.createTitledBorder(language.getString("Text_color"));

        colorTPanel.setBorder(colorTPanelTitle);
        colorTPanel.add(colorTbt);

        return colorTPanel;
    }

    private JPanel getTextFinalFontPanel() {
        JPanel textFamilyPanel = new JPanel();
        JLabel textFamilyLabel = new JLabel();
        textFamilyLabel.setText(language.getString("Font"));
        textFamilyLabel.setHorizontalAlignment(JLabel.CENTER);

        JPanel textSizePanel = new JPanel();
        JLabel textSizeLabel = new JLabel();
        textSizeLabel.setText(language.getString("Size"));
        textSizeLabel.setHorizontalAlignment(JLabel.CENTER);

        JPanel textStylePanel = new JPanel();
        JLabel textStyleLabel = new JLabel();
        textStyleLabel.setText(language.getString("Style"));
        textStyleLabel.setHorizontalAlignment(JLabel.CENTER);

        famcomb = new JComboBox(JaxoStaticCanvasMethods.getSystemFonts());
        famcomb.addItemListener(this);
        famcomb.setSelectedIndex(getFamilyIndex(JaxoPrefs.getPref(
                    JaxoPrefs.PREF_PSFAMILY)));
        textFamilyPanel.add(famcomb);

        String[] sizes =
        {
            "4", "6", "8", "10", "12", "14", "16", "18", "20", "22", "24", "26",
            "28", "30", "32", "34", "36", "38", "40", "42", "44", "46", "48",
            "50", "52", "54", "56", "58", "60", "62", "64"
        };
        sizecomb = new JComboBox(sizes);
        sizecomb.addItemListener(this);
        sizecomb.setSelectedIndex(getSizeIndex(
                (new Integer(JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSIZE)))
                .toString()));
        textSizePanel.add(sizecomb);

        String[] styles = {"Plain", "Bold", "Italic", "Bold & Italic"};
        stycomb = new JComboBox(styles);
        stycomb.addItemListener(this);
        stycomb.setSelectedIndex(JaxoPrefs.getIntPref(JaxoPrefs.PREF_PSSTYLE));
        textStylePanel.add(stycomb);

        JPanel textFinalFontPanel = new JPanel();
        textFinalFontPanel.setLayout(new BorderLayout());

        TitledBorder textFontTitle =
            BorderFactory.createTitledBorder(language.getString(
                    "Font_properties"));

        textFinalFontPanel.setBorder(textFontTitle);
        textFinalFontPanel.add(BorderLayout.WEST, textFamilyPanel);
        textFinalFontPanel.add(BorderLayout.CENTER, textSizePanel);
        textFinalFontPanel.add(BorderLayout.EAST, textStylePanel);

        return textFinalFontPanel;
    }

    private JPanel getFinalRotSPanel() {
        JPanel prot = new JPanel();
        GridBagLayout rotgb = new GridBagLayout();
        GridBagConstraints rotc = new GridBagConstraints();
        prot.setLayout(rotgb);
        modelrot = new SpinnerNumberModel(newPSRot, -360, 360, 1);

        JLabel rot =
            new JLabel("PS " + language.getString("Rot._Angle") + ":  ",
                JLabel.RIGHT);
        sprot = new JSpinner(modelrot);

        rotc.gridx = 0;
        rotc.gridy = 0;
        rotc.insets = new Insets(0, 5, 0, 5);
        rotgb.setConstraints(rot, rotc);
        prot.add(rot, rotc);

        rotc.gridx = 1;
        rotc.gridy = 0;
        sprot.setPreferredSize(new Dimension(55, 20));
        rotgb.setConstraints(sprot, rotc);
        prot.add(sprot, rotc);

        JPanel prot1 = new JPanel();
        GridBagLayout rotgb1 = new GridBagLayout();
        GridBagConstraints rotc1 = new GridBagConstraints();
        prot1.setLayout(rotgb1);
        modelrot1 = new SpinnerNumberModel(newTeXRot, -360, 360, 1);

        JLabel rot1 =
            new JLabel("TeX " + language.getString("Rot._Angle") + ": ",
                JLabel.RIGHT);
        sprot1 = new JSpinner(modelrot1);

        rotc1.gridx = 0;
        rotc1.gridy = 0;
        rotc1.insets = new Insets(0, 5, 0, 5);
        rotgb1.setConstraints(rot1, rotc1);
        prot1.add(rot1, rotc1);

        rotc1.gridx = 1;
        rotc1.gridy = 0;
        sprot1.setPreferredSize(new Dimension(55, 20));
        rotgb1.setConstraints(sprot1, rotc1);
        prot1.add(sprot1, rotc1);

        JPanel rotSPanel = new JPanel();
        GridBagLayout gbrot = new GridBagLayout();
        GridBagConstraints scrot = new GridBagConstraints();
        rotSPanel.setLayout(gbrot);

        scrot.gridx = 0;
        scrot.gridy = 0;
        scrot.insets = new Insets(0, 0, 5, 0);
        gbrot.setConstraints(prot, scrot);
        rotSPanel.add(prot, scrot);

        scrot.gridx = 0;
        scrot.gridy = 1;
        scrot.insets = new Insets(5, 0, 0, 5);
        gbrot.setConstraints(prot1, scrot);
        rotSPanel.add(prot1, scrot);

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

        TitledBorder rotSTitle =
            BorderFactory.createTitledBorder(language.getString("Rotation"));
        finalRotSPanel.setBorder(rotSTitle);
        finalRotSPanel.add(rotSPanel);

        return finalRotSPanel;
    }

    private JPanel getAlliPanel() {
        String[] possible =
        {
            language.getString("Left-Top"), language.getString("Left-Center"),
            language.getString("Left-Bottom"), language.getString("Center-Top"),
            language.getString("Center-Center"),
            language.getString("Center-Bottom"),
            language.getString("Right-Top"), language.getString("Right-Center"),
            language.getString("Right-Bottom")
        };
        allicomb = new JComboBox(possible);
        allicomb.setSelectedIndex(JaxoPrefs.getIntPref(JaxoPrefs.PREF_TEXALIGN));
        allicomb.addActionListener(this);

        JPanel alliPanel = new JPanel();
        TitledBorder alliPanelTitle =
            BorderFactory.createTitledBorder("TeX "
                + language.getString("Alignment"));
        alliPanel.setBorder(alliPanelTitle);
        alliPanel.add(allicomb);

        return alliPanel;
    }

    private JPanel getFsPanel() {
        String[] allowed =
        {
            "tiny", "scriptsize", "footnotesize", "small", "normalsize",
            "large", "Large", "LARGE", "huge", "Huge"
        };

        fscomb = new JComboBox(allowed);
        fscomb.setSelectedIndex(JaxoPrefs.getIntPref(JaxoPrefs.PREF_TEXSIZE));
        fscomb.addActionListener(this);

        JPanel fsPanel = new JPanel();
        TitledBorder fsPanelTitle =
            BorderFactory.createTitledBorder("TeX"
                + language.getString("Font_size"));
        fsPanel.setBorder(fsPanelTitle);
        fsPanel.add(fscomb);

        return fsPanel;
    }

    private JPanel getBGridCont() {
        JPanel gridPanel = new JPanel();
        gridPanel.add(getGridOnOffPanel());
        gridPanel.add(getGridTypePanel());
        gridPanel.add(getGridSizePanel());

        JPanel bGrid = new JPanel();
        bGrid.setLayout(new BoxLayout(bGrid, BoxLayout.Y_AXIS));
        bGrid.add(gridPanel);

        JPanel bGridCont = createOptionContainer();
        bGridCont.add(bGrid, BorderLayout.CENTER);

        return bGridCont;
    }

    private JPanel getBDefCont() {
        JPanel bDef = new JPanel();
        bDef.setLayout(new BoxLayout(bDef, BoxLayout.Y_AXIS));
        bDef.add(getDefPanel());

        JPanel bDefCont = createOptionContainer();
        bDefCont.add(bDef, BorderLayout.CENTER);

        return bDefCont;
    }

    private JPanel getBObjectCont() {
        JPanel objectPanel = new JPanel();
        objectPanel.add(getColorPanel());
        objectPanel.add(getLineWidthPanel());
        objectPanel.add(getArrowPanel());
        objectPanel.add(getSepPanel());

        JPanel objectPanel1 = new JPanel();
        objectPanel1.add(getAmpPanel());

        JPanel bObject = new JPanel();
        bObject.setLayout(new BoxLayout(bObject, BoxLayout.Y_AXIS));
        bObject.add(objectPanel);
        bObject.add(objectPanel1);

        JPanel bObjectCont = createOptionContainer();
        bObjectCont.add(bObject, BorderLayout.CENTER);

        return bObjectCont;
    }

    private JPanel getBTextCont() {
        JPanel textPanel = new JPanel();
        textPanel.add(getColorTPanel());
        textPanel.add(getTextFinalFontPanel());

        JPanel textPanel1 = new JPanel();
        textPanel1.add(getFinalRotSPanel());
        textPanel1.add(getAlliPanel());
        textPanel1.add(getFsPanel());

        JPanel bText = new JPanel();
        bText.setLayout(new BoxLayout(bText, BoxLayout.Y_AXIS));
        bText.add(textPanel);
        bText.add(textPanel1);

        JPanel bTextCont = createOptionContainer();
        bTextCont.add(bText, BorderLayout.CENTER);

        return bTextCont;
    }

    private JPanel getDefPanel() {
        String[] defaults =
        {
            language.getString("None"), language.getString("Fermion_Line"),
            language.getString("Fermion_Loop"),
            language.getString("Fermion_Arc"),
            language.getString("Scalar_Line"),
            language.getString("Scalar_Loop"), language.getString("Scalar_Arc"),
            language.getString("Ghost_Line"), language.getString("Ghost_Loop"),
            language.getString("Ghost_Arc"), language.getString("Photon_Line"),
            language.getString("Photon_Loop"), language.getString("Photon_Arc"),
            language.getString("Gluon_Line"), language.getString("Gluon_Loop"),
            language.getString("Gluon_Arc"), language.getString("Box"),
            language.getString("Blob"), language.getString("Vertex"),
            language.getString("Zigzag"), language.getString("Text"),
            language.getString("LaTex"), language.getString("Move"),
            language.getString("Resize"), language.getString("Copy"),
            language.getString("Color"), language.getString("Edit"),
        };
        defcomb = new JComboBox(defaults);
        defcomb.setSelectedIndex(JaxoPrefs.getIntPref(
                JaxoPrefs.PREF_DEFAULTACTION));
        defcomb.addActionListener(this);

        JPanel defPanel = new JPanel();
        TitledBorder defPanelTitle =
            BorderFactory.createTitledBorder(language.getString(
                    "After_an_action_default_to"));
        defPanel.setBorder(defPanelTitle);
        defPanel.add(defcomb);

        return defPanel;
    }
}

 

Ads help maintain this website.