001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.wizard;
019:
020: import java.util.HashMap;
021: import java.util.Locale;
022: import java.util.Map;
023:
024: import javax.swing.JLabel;
025: import javax.swing.JPanel;
026: import javax.swing.JScrollPane;
027: import javax.swing.JTabbedPane;
028: import javax.swing.JTextArea;
029:
030: import de.finix.contelligent.client.base.Description;
031: import de.finix.contelligent.client.i18n.Resources;
032: import de.finix.contelligent.client.util.JTextUtil;
033: import de.finix.contelligent.client.util.RestrictedDocument;
034: import de.finix.contelligent.client.util.RestrictedTextField;
035: import de.finix.contelligent.client.util.TableLayout;
036:
037: public class DescriptionPane extends JTabbedPane {
038: private Locale[] supportedLocales = Resources.getSupportedLocales();
039:
040: private RestrictedTextField[] descriptionTitleField = new RestrictedTextField[supportedLocales.length];
041:
042: private RestrictedTextField[] descriptionHelpURLField = new RestrictedTextField[supportedLocales.length];
043:
044: private JTextArea[] descriptionArea = new JTextArea[supportedLocales.length];
045:
046: private static final String allowString = RestrictedDocument.ALPHA
047: + RestrictedDocument.NUM + " :+[]().,;=-_/!$%*?\n";
048:
049: public DescriptionPane(Map descriptions) {
050: super ();
051: for (int i = 0; i < supportedLocales.length; i++) {
052: JPanel descriptionPanel = new JPanel(new TableLayout(
053: new double[][] {
054: { 100, TableLayout.FILL },
055: { TableLayout.PREFERRED,
056: TableLayout.PREFERRED, 5,
057: TableLayout.PREFERRED,
058: TableLayout.FILL } }));
059: String language = supportedLocales[i].getLanguage();
060: Description description;
061: if (descriptions.containsKey(language)) {
062: description = (Description) descriptions.get(language);
063: } else {
064: description = new Description(language, "", "", "");
065: descriptions.put(language, description);
066: }
067: JLabel descriptionTitle = JTextUtil
068: .createTitle(Resources
069: .getLocalString("description_wizard_description_title"));
070: descriptionPanel.add(descriptionTitle, "0,0,l,b");
071: descriptionTitleField[i] = new RestrictedTextField(
072: description.getTitle());
073: descriptionTitleField[i].setAllowString(allowString);
074: descriptionPanel.add(descriptionTitleField[i], "1,0,f,b");
075: JLabel descriptionHelpURL = JTextUtil
076: .createTitle(Resources
077: .getLocalString("description_wizard_description_helpURL"));
078: descriptionPanel.add(descriptionHelpURL, "0,1,l,b");
079: descriptionHelpURLField[i] = new RestrictedTextField(
080: description.getHelpURL());
081: descriptionHelpURLField[i].setAllowString(allowString);
082: descriptionPanel.add(descriptionHelpURLField[i], "1,1,f,b");
083: JLabel descriptionDescription = JTextUtil
084: .createTitle(Resources
085: .getLocalString("description_wizard_description_description"));
086: descriptionPanel.add(descriptionDescription, "0,3,l,b");
087: RestrictedDocument rDoc = new RestrictedDocument();
088: descriptionArea[i] = new JTextArea(rDoc, description
089: .getText(), 5, 0);
090: // Setting the allow string only after initialization allows us
091: // to load legacy content even if we would not allow it to be
092: // entered
093: // anymore.
094: rDoc.setAllowString(allowString);
095: descriptionArea[i].setWrapStyleWord(true);
096: descriptionArea[i].setLineWrap(true);
097: JScrollPane descriptionScroller = new JScrollPane(
098: descriptionArea[i]);
099: descriptionPanel.add(descriptionScroller, "0,4,1,4");
100: addTab(supportedLocales[i].getDisplayLanguage(Resources
101: .getLocale()), descriptionPanel);
102: }
103: }
104:
105: public Map getDescriptions() {
106: Map descriptions = new HashMap();
107: ;
108: for (int i = 0; i < supportedLocales.length; i++) {
109: String language = supportedLocales[i].getLanguage();
110: Description description = new Description(language,
111: descriptionTitleField[i].getText(),
112: descriptionArea[i].getText(),
113: descriptionHelpURLField[i].getText());
114: descriptions.put(language, description);
115: }
116: return descriptions;
117: }
118: }
|