Package lazy8ledger

Source Code of lazy8ledger.LedgerGeneralOptionPane

/*
* :tabSize=2:indentSize=2:noTabs=true:
* :folding=explicit:collapseFolds=1:
*
*  Copyright (C) 2009 Chaniel AB, Thomas Dilts This program 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. 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 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 For more
*  information, surf to www.lazy8.nu or email support@lazy8.nu
*/
package lazy8ledger;
//{{{ imports
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import nu.lazy8.ledger.forms.ChangeLanguagesDialogs;
import nu.lazy8.ledger.forms.CompanyComponents;
import nu.lazy8.ledger.main.Lazy8Ledger;
import nu.lazy8.util.gen.SetupInfo;
import nu.lazy8.util.gen.Translator;
import nu.lazy8.util.help.HelpedButton;
import nu.lazy8.util.help.HelpedLabel;
import nu.lazy8.util.help.HelpedRadioButton;
import nu.lazy8.util.help.HelpedTextField;
import org.gjt.sp.jedit.AbstractOptionPane;
import org.gjt.sp.jedit.gui.FontSelector;
import org.gjt.sp.jedit.jEdit;
//}}}

/**
*  Description of the Class
*
* @author     thomas
* @created    den 2 juli 2004
*/
public class LedgerGeneralOptionPane extends AbstractOptionPane {
  //{{{ members
  public final static int NUM_MENU_LEVELS = 3;
  //private JButton button1; // commented out since never used

  // private JCheckBox checkShowAdvancedMenus; // commented out since never used
  JCheckBox checkShowPassword;
  // private CompanyComponents companyComponents; // commented out since never used

  // private members
  JRadioButton[] menuButtonLevels;
  private FontSelector reportFont;
  private JTextField textField5;
  // private JTextField textFont; // commented out since never used
  private JFrame view;
  //}}}

  //{{{ +LedgerGeneralOptionPane(JFrame) : <init>
  /**
   *Constructor for the LedgerGeneralOptionPane object
   *
   * @param  view  Description of the Parameter
   */
  public LedgerGeneralOptionPane(JFrame view) {
    super("lazy8ledger-general");
    this.view = view;
  }//}}}

  //{{{ #_init() : void
  /**
   *  Description of the Method
   */
  protected void _init() {
    addComponent(new JLabel(
        Translator.getTranslation("After making any changes here you must restart jEdit")));
    addComponent(new JLabel(" "));

    String nameOfFont = SetupInfo.getProperty(SetupInfo.NAME_OF_REPORT_FONT);
    if (nameOfFont == null || nameOfFont.length() == 0) {
      nameOfFont = "SansSerif";
    }
    reportFont = new FontSelector(new Font(nameOfFont, Font.PLAIN, 12));
    MouseListener l1 =
      new MouseListener() {
        //{{{ +mouseClicked(MouseEvent) : void
        public void mouseClicked(MouseEvent e) { }//}}}


        //{{{ +mouseEntered(MouseEvent) : void
        public void mouseEntered(MouseEvent e) {
          Lazy8Ledger.ShowContextHelp(view, "setup", "reportfont");
        }//}}}


        //{{{ +mouseExited(MouseEvent) : void
        public void mouseExited(MouseEvent e) { }//}}}


        //{{{ +mousePressed(MouseEvent) : void
        public void mousePressed(MouseEvent e) { }//}}}


        //{{{ +mouseReleased(MouseEvent) : void
        public void mouseReleased(MouseEvent e) { }//}}}
      };
    reportFont.addMouseListener(l1);

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

    jpFont.add(new HelpedLabel(Translator.getTranslation("Font used in reports (font name only)"),
        "reportfont", "setup", view), BorderLayout.WEST);
    jpFont.add(reportFont, BorderLayout.CENTER);
    addComponent(jpFont);

    menuButtonLevels = new JRadioButton[NUM_MENU_LEVELS];
    addComponent(createMenuSelectionPanel(menuButtonLevels, view));
    textField5 = new HelpedTextField("WordProcesser", "setup", view);

    JButton butLang = new HelpedButton(Translator.getTranslation("Default language"),
        "Languages", "setup", view);
    addComponent(butLang);
    butLang.addActionListener(
      new java.awt.event.ActionListener() {
        //{{{ +actionPerformed(java.awt.event.ActionEvent) : void
        public void actionPerformed(java.awt.event.ActionEvent evt) {
          //Get file name
          new ChangeLanguagesDialogs(view, true);
        }//}}}
      }
        );

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

    jpSearch.add(new HelpedLabel(Translator.getTranslation("External word processor"),
        "WordProcesser", "setup", view), BorderLayout.WEST);

    JButton butsearch = new HelpedButton(Translator.getTranslation("Browse"),
        "Browse", "setup", view);

    butsearch.addActionListener(
      new java.awt.event.ActionListener() {
        //{{{ +actionPerformed(java.awt.event.ActionEvent) : void
        public void actionPerformed(java.awt.event.ActionEvent evt) {
          //Get file name
          JFileChooser fileDialog = new JFileChooser();
          fileDialog.setDialogTitle(
              Translator.getTranslation("Select a word processor"));
          if (fileDialog.showOpenDialog(null) ==
              JFileChooser.APPROVE_OPTION) {
            textField5.setText(fileDialog.getSelectedFile().getPath());
          }
        }//}}}
      }
        );
    jpSearch.add(butsearch, BorderLayout.CENTER);
    Dimension dm = textField5.getPreferredSize();
    dm.setSize(125, dm.height);
    textField5.setPreferredSize(dm);
    textField5.setMaximumSize(dm);
    textField5.setMinimumSize(dm);
    textField5.setText(SetupInfo.getProperty(SetupInfo.WORDPROCESSOR));
    jpSearch.add(textField5, BorderLayout.EAST);
    addComponent(jpSearch);
  }//}}}

  //{{{ #_save() : void
  /**
   *  Description of the Method
   */
  protected void _save() {
    saveMenuLevel(menuButtonLevels);
    //companyComponents.saveDefaults();
    SetupInfo.setProperty(SetupInfo.WORDPROCESSOR,
        textField5.getText().trim());
    SetupInfo.setProperty(SetupInfo.NAME_OF_REPORT_FONT, reportFont.getFont().getFontName());

    SetupInfo.store();

  }//}}}

  //{{{ +_createMenuSelectionPanel(JRadioButton[], JFrame)_ : JPanel
  /**
   *  Description of the Method
   *
   * @param  menuButton  Description of the Parameter
   * @param  view        Description of the Parameter
   * @return             Description of the Return Value
   */
  public static JPanel createMenuSelectionPanel(JRadioButton[] menuButton, JFrame view) {
    ButtonGroup group = new ButtonGroup();
    JPanel menuPanel = new JPanel();
    menuPanel.setBorder(new javax.swing.border.TitledBorder(
        Translator.getTranslation("Menu difficulty level")));
    menuPanel.setLayout(new GridLayout(NUM_MENU_LEVELS, 1));
    for (int i = 0; i < NUM_MENU_LEVELS; i++) {
      menuButton[i] = new HelpedRadioButton(Translator.getTranslation("menu.level." + i),
          "menulevel", "setup", view);
      group.add(menuButton[i]);
      menuPanel.add(menuButton[i]);
    }

    if (jEdit.getIntegerProperty("lazy8ledger.menu.level", 0) < NUM_MENU_LEVELS) {
      menuButton[jEdit.getIntegerProperty("lazy8ledger.menu.level", 0)].setSelected(true);
    } else {
      menuButton[0].setSelected(true);
    }
    return menuPanel;
  }//}}}

  //{{{ +_saveMenuLevel(JRadioButton[])_ : void
  /**
   *  Description of the Method
   *
   * @param  menuButton  Description of the Parameter
   */
  public static void saveMenuLevel(JRadioButton[] menuButton) {
    //save the menu value
    //int menuLevelBefore = jEdit.getIntegerProperty("lazy8ledger.menu.level", -1); // commented out since never used
    int menuLevel = 0; // FIXME: menuLevel is never used
    for (int i = 0; i < NUM_MENU_LEVELS; i++) {
      if (menuButton[i].isSelected()) {
        jEdit.setIntegerProperty("lazy8ledger.menu.level", i);
        menuLevel = i;
        break;
      }
    }
  }//}}}
}

TOP

Related Classes of lazy8ledger.LedgerGeneralOptionPane

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.