001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.crm.report.settings;
015:
016: import com.jgoodies.forms.layout.CellConstraints;
017: import com.jgoodies.forms.layout.FormLayout;
018: import org.jetbrains.annotations.NonNls;
019: import org.jetbrains.annotations.NotNull;
020: import org.pentaho.reportdesigner.crm.report.util.JOptionPaneHelper;
021: import org.pentaho.reportdesigner.lib.client.components.CenterPanelDialog;
022: import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
023:
024: import javax.swing.*;
025: import java.util.List;
026: import java.util.Locale;
027:
028: /**
029: * User: Martin
030: * Date: 01.03.2006
031: * Time: 18:15:58
032: */
033: public class LanguageSettingsPanel extends SettingsPanel {
034: @NotNull
035: private JComboBox comboBoxLanguage;
036:
037: public LanguageSettingsPanel() {
038: @NonNls
039: FormLayout formLayout = new FormLayout(
040: "4dlu, pref, 4dlu, pref:grow, 4dlu", "4dlu, "
041: + "pref, " + "10dlu, " + "pref, " + "4dlu, ");
042:
043: CellConstraints cc = new CellConstraints();
044:
045: setLayout(formLayout);
046:
047: List<Locale> list = ApplicationSettings.getInstance()
048: .getAvailableLocales();
049:
050: String[] languages = new String[list.size()];
051: int i = 0;
052: for (Locale availableLocale : list) {
053: languages[i] = availableLocale
054: .getDisplayName(availableLocale);
055: i++;
056: }
057: comboBoxLanguage = new JComboBox(languages);
058:
059: add(new JLabel(TranslationManager.getInstance().getTranslation(
060: "R", "LanguageSettingsPanel.Language")), cc.xy(2, 2));
061: add(comboBoxLanguage, cc.xy(4, 2));
062:
063: reset();
064: }
065:
066: @NotNull
067: public ValidationResult getValidationResult() {
068: return new ValidationResult();
069: }
070:
071: public void apply() {
072: if (hasChanged()) {
073: JOptionPaneHelper
074: .showMessageDialog(
075: this ,
076: TranslationManager
077: .getInstance()
078: .getTranslation("R",
079: "LanguageSettingsPanel.ChangedMessage.Text"),
080: TranslationManager
081: .getInstance()
082: .getTranslation("R",
083: "LanguageSettingsPanel.ChangedMessage.Title"),
084: JOptionPaneHelper.INFORMATION_MESSAGE,
085: CenterPanelDialog.ModalityType.DOCUMENT_MODAL);
086: }
087:
088: ApplicationSettings.getInstance().setLanguage(
089: ApplicationSettings.getInstance().getAvailableLocales()
090: .get(comboBoxLanguage.getSelectedIndex()));
091: }
092:
093: public void reset() {
094: boolean languageFound = false;
095: for (int i = 0; i < ApplicationSettings.getInstance()
096: .getAvailableLocales().size(); i++) {
097: Locale availableLocale = ApplicationSettings.getInstance()
098: .getAvailableLocales().get(i);
099: if (ApplicationSettings.getInstance().getLanguage().equals(
100: availableLocale)) {
101: comboBoxLanguage.setSelectedIndex(i);
102: languageFound = true;
103: break;
104: }
105: }
106: if (!languageFound) {
107: comboBoxLanguage.setSelectedIndex(0);
108: }
109: }
110:
111: public boolean hasChanged() {
112: Locale selectedLang = ApplicationSettings.getInstance()
113: .getAvailableLocales().get(
114: comboBoxLanguage.getSelectedIndex());
115: Locale oldLang = ApplicationSettings.getInstance()
116: .getLanguage();
117: return !oldLang.equals(selectedLang);
118:
119: }
120: }
|