I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
ConfigUIHelper.java 3.74 KiB
Newer Older
  • Learn to ignore specific revisions
  • zzz's avatar
    zzz committed
    package net.i2p.router.web;
    
    
    zzz's avatar
    zzz committed
    import java.io.File;
    
    zzz's avatar
    zzz committed
    import java.util.Iterator;
    
    zzz's avatar
    zzz committed
    import java.util.TreeSet;
    import java.util.Set;
    
    
    zzz's avatar
    zzz committed
    public class ConfigUIHelper extends HelperBase {
    
        public String getSettings() {
            StringBuilder buf = new StringBuilder(512);
    
    zzz's avatar
    zzz committed
            String current = _context.getProperty(CSSHelper.PROP_THEME_NAME, CSSHelper.DEFAULT_THEME);
    
    zzz's avatar
    zzz committed
            Set<String> themes = themeSet();
    
    zzz's avatar
    zzz committed
            for (String theme : themes) {
    
                buf.append("<input type=\"radio\" class=\"optbox\" name=\"theme\" ");
    
    zzz's avatar
    zzz committed
                if (theme.equals(current))
                    buf.append("checked=\"true\" ");
    
    zzz's avatar
    zzz committed
                buf.append("value=\"").append(theme).append("\">").append(_(theme)).append("<br>\n");
            }
            return buf.toString();
        }
    
    
    zzz's avatar
    zzz committed
        static final String PROP_THEME_PFX = "routerconsole.theme.";
    
    
    zzz's avatar
    zzz committed
        /** @return standard and user-installed themes, sorted (untranslated) */
        private Set<String> themeSet() {
             Set<String> rv = new TreeSet();
             // add a failsafe even if we can't find any themes
             rv.add(CSSHelper.DEFAULT_THEME);
             File dir = new File(_context.getBaseDir(), "docs/themes/console");
             File[] files = dir.listFiles();
             if (files == null)
                 return rv;
             for (int i = 0; i < files.length; i++) {
                 String name = files[i].getName();
                 if (files[i].isDirectory() && ! name.equals("images"))
                     rv.add(name);
             }
    
    zzz's avatar
    zzz committed
             // user themes
             Set props = _context.getPropertyNames();
             for (Iterator iter = props.iterator(); iter.hasNext(); ) {
                  String prop = (String) iter.next();
                  if (prop.startsWith(PROP_THEME_PFX) && prop.length() > PROP_THEME_PFX.length())
                      rv.add(prop.substring(PROP_THEME_PFX.length()));
             }
    
    zzz's avatar
    zzz committed
             return rv;
        }
    
    
    zzz's avatar
    zzz committed
        /**
         *  Each language has the ISO code, the flag, and the name.
         *  Alphabetical by the ISO code please.
         *  See http://en.wikipedia.org/wiki/ISO_639-1 .
         *  Any language-specific flag added to the icon set must be
         *  added to the top-level build.xml for the updater.
         */
    
        private static final String langs[] = {"ar", "da", "de", "en", "es", "fi",
                                               "fr", "it", "nl", "pl", "pt", "ru",
                                               "sv", "uk", "vi", "zh"};
        private static final String flags[] = {"lang_ar", "dk", "de", "us", "es", "fi",
                                               "fr", "it", "nl", "pl", "pt", "ru",
                                               "se", "ua", "vn", "cn"};
        private static final String xlangs[] = {_x("Arabic"), _x("Danish"),
    
                                                _x("German"), _x("English"), _x("Spanish"),_x("Finnish"),
                                                _x("French"), _x("Italian"), _x("Dutch"), _x("Polish"),
                                                _x("Portuguese"), _x("Russian"), _x("Swedish"),
    
    zzz's avatar
    zzz committed
                                                _x("Ukrainian"), _x("Vietnamese"), _x("Chinese")};
    
    zzz's avatar
    zzz committed
    
    
    zzz's avatar
    zzz committed
        /** todo sort by translated string */
    
    zzz's avatar
    zzz committed
        public String getLangSettings() {
            StringBuilder buf = new StringBuilder(512);
            String current = Messages.getLanguage(_context);
            for (int i = 0; i < langs.length; i++) {
                // we use "lang" so it is set automagically in CSSHelper
                buf.append("<input type=\"radio\" class=\"optbox\" name=\"lang\" ");
                if (langs[i].equals(current))
                    buf.append("checked=\"true\" ");
    
    zzz's avatar
    zzz committed
                buf.append("value=\"").append(langs[i]).append("\">")
                   .append("<img height=\"11\" width=\"16\" alt=\"\" src=\"/flags.jsp?c=").append(flags[i]).append("\"> ")
                   .append(_(xlangs[i])).append("<br>\n");
    
    zzz's avatar
    zzz committed
            }
            return buf.toString();
        }
    }