protected void writeContent(String language) throws IOException { write("PAGE,TYPE,TEXT\n"); List<OntologyElement> elements = getOntologyElements(); LanguageUtils.sortOntologyElements(elements); for (OntologyElement oe : elements) { for (Statement s : oe.getArticle().getStatements()) { write(LanguageUtils.getHeading(oe) + ","); write(getStatementType(s) + ","); write("\"" + s.getText(language).replaceAll("\"", "\"\"").replaceAll("\\s+", " ") + "\""); write("\n"); } } }
public LanguageWindow() { super(GUIMediator.getAppFrame()); this.currentLocale = GUIMediator.getLocale(); initializeWindow(); Font font = new Font("Dialog", Font.PLAIN, 11); Locale[] locales = LanguageUtils.getLocales(font); mainPanel = new JPanel(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); getContentPane().add(mainPanel, BorderLayout.CENTER); initializeContent(locales); initializeButtons(); initializeWindow(); updateLabels(currentLocale); pack(); if (getWidth() < MIN_DIALOG_WIDTH) { setSize(350, getHeight()); } }
private void initializeButtons() { okayAction = new OkayAction(); cancelAction = new CancelAction(); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING)); buttonPanel.add(new JButton(okayAction)); if (!LanguageUtils.isEnglishLocale(currentLocale)) { buttonPanel.add(new JButton(new UseEnglishAction())); } buttonPanel.add(new JButton(cancelAction)); mainPanel.add(buttonPanel, BorderLayout.SOUTH); }
private void switchLanguage(Locale locale, boolean showLanguageInStatusBar) { // if the selected locale is less specific than the default locale (e.g. // has no country or variant set), retain these properties, unless the user // specifically did not want to select the default locale if (!defaultLocaleSelectable && LanguageUtils.matchesDefaultLocale(locale)) { locale = Locale.getDefault(); } if (!locale.equals(GUIMediator.getLocale())) { LanguageUtils.setLocale(locale); GUIMediator.instance().getStatusLine().updateLanguage(); String message = I18n.trl("LimeWire must be restarted for the new language to take effect.", locale); GUIMediator.showMessage(message); } StatusBarSettings.LANGUAGE_DISPLAY_ENABLED.setValue(showLanguageInStatusBar); if (LanguageUtils.isEnglishLocale(locale)) { StatusBarSettings.LANGUAGE_DISPLAY_ENGLISH_ENABLED.setValue(showLanguageInStatusBar); } GUIMediator.instance().getStatusLine().refresh(); dispose(); }
private void initializeContent(Locale[] locales) { FormLayout layout = new FormLayout("pref:grow"); DefaultFormBuilder builder = new DefaultFormBuilder(layout); // add locales to model and select the best match DefaultComboBoxModel localeModel = new DefaultComboBoxModel(); int selectedScore = -1; int selectedIndex = -1; Locale systemLocale = Locale.getDefault(); for (int i = 0; i < locales.length; i++) { localeModel.addElement(locales[i]); int score = LanguageUtils.getMatchScore(currentLocale, locales[i]); if (score > selectedScore) { selectedScore = score; selectedIndex = i; } if (locales[i].equals(systemLocale)) { defaultLocaleSelectable = true; } } localeComboBox = new JComboBox(localeModel); localeComboBox.setRenderer(LanguageFlagFactory.getListRenderer()); localeComboBox.setMaximumRowCount(15); if (selectedIndex != -1) { localeComboBox.setSelectedIndex(selectedIndex); } builder.append(localeComboBox); builder.nextLine(); // reflect the changed language right away so someone who doesn't speak // English or whatever language it the default can understand what the // buttons say localeComboBox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { Locale selected = (Locale) e.getItem(); if (selected != null && !currentLocale.equals(selected)) { updateLabels(selected); // hide the flag by default for english locales to save // space in the status bar showLanguageCheckbox.setSelected(!LanguageUtils.isEnglishLocale(selected)); currentLocale = selected; } } } }); helpTranslateLabel = new URLLabel(TRANSLATE_URL, ""); builder.append(helpTranslateLabel); builder.nextLine(); builder.append(Box.createVerticalStrut(15)); builder.nextLine(); showLanguageCheckbox = new JCheckBox(); showLanguageCheckbox.setSelected(StatusBarSettings.LANGUAGE_DISPLAY_ENABLED.getValue()); builder.append(showLanguageCheckbox); builder.nextLine(); builder.append(Box.createVerticalStrut(5)); builder.nextLine(); mainPanel.add(builder.getPanel(), BorderLayout.CENTER); }