Search in sources :

Example 1 with Profile

use of jmri.profile.Profile in project JMRI by JMRI.

the class JUnitUtil method resetProfileManager.

/**
     * Use only if profile contents are not to be verified or modified in test.
     * If a profile will be written to and its contents verified as part of a
     * test use {@link #resetProfileManager(jmri.profile.Profile)} with a
     * provided profile.
     *
     * The new profile will have the name {@literal TestProfile }, the id
     * {@literal 00000000 }, and will be in the directory {@literal temp }
     * within the sources working copy.
     */
public static void resetProfileManager() {
    try {
        Profile profile = new NullProfile("TestProfile", "00000000", FileUtil.getFile(FileUtil.SETTINGS));
        resetProfileManager(profile);
    } catch (FileNotFoundException ex) {
        log.error("Settings directory \"{}\" does not exist", FileUtil.SETTINGS);
    } catch (IOException | IllegalArgumentException ex) {
        log.error("Unable to create profile", ex);
    }
}
Also used : NullProfile(jmri.profile.NullProfile) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Profile(jmri.profile.Profile) NullProfile(jmri.profile.NullProfile)

Example 2 with Profile

use of jmri.profile.Profile in project JMRI by JMRI.

the class WebAppServlet method processApp.

private void processApp(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType(UTF8_TEXT_HTML);
    Profile profile = ProfileManager.getDefault().getActiveProfile();
    File cache = new File(ProfileUtils.getCacheDirectory(profile, this.getClass()), request.getLocale().toString());
    FileUtil.createDirectory(cache);
    // NOI18N
    File index = new File(cache, "index.html");
    if (!index.exists()) {
        // NOI18N
        String inComments = "-->\n%s<!--";
        WebAppManager manager = getWebAppManager();
        // Format elements for index.html
        // 1 = railroad name
        // 2 = scripts (in comments)
        // 3 = stylesheets (in comments)
        // 4 = body content (divs)
        // 5 = help menu title
        // 6 = help menu contents (in comments)
        // 7 = personal menu title
        // 8 = personal menu contents (in comments)
        // 9 = power menu title
        FileUtil.appendTextToFile(index, String.format(request.getLocale(), FileUtil.readURL(FileUtil.findURL("web/app/index.html")), // railroad name
        ServletUtil.getInstance().getRailroadName(false), // scripts (in comments)
        String.format(inComments, manager.getScriptTags(profile)), // stylesheets (in comments)
        String.format(inComments, manager.getStyleTags(profile)), // body content (divs)
        "<!-- -->", // help menu title
        Bundle.getMessage(request.getLocale(), "help"), // help menu contents (in comments)
        String.format(inComments, manager.getHelpMenuItems(profile, request.getLocale())), // personal menu title
        Bundle.getMessage(request.getLocale(), "user"), // personal menu contents (in comments)
        String.format(inComments, manager.getUserMenuItems(profile, request.getLocale())), // power menu title
        Bundle.getMessage(request.getLocale(), "power")));
    }
    response.getWriter().print(FileUtil.readFile(index));
}
Also used : File(java.io.File) Profile(jmri.profile.Profile)

Example 3 with Profile

use of jmri.profile.Profile in project JMRI by JMRI.

the class WebAppServlet method processScript.

private void processScript(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType(UTF8_APPLICATION_JAVASCRIPT);
    Profile profile = ProfileManager.getDefault().getActiveProfile();
    File cache = new File(ProfileUtils.getCacheDirectory(profile, this.getClass()), request.getLocale().toString());
    FileUtil.createDirectory(cache);
    // NOI18N
    File script = new File(cache, "script.js");
    if (!script.exists()) {
        WebAppManager manager = getWebAppManager();
        FileUtil.appendTextToFile(script, String.format(request.getLocale(), // NOI18N
        FileUtil.readURL(FileUtil.findURL("web/app/script.js")), manager.getAngularDependencies(profile, request.getLocale()), manager.getAngularRoutes(profile, request.getLocale()), // NOI18N
        String.format("\n    $scope.navigationItems = %s;\n", manager.getNavigation(profile, request.getLocale())), manager.getAngularSources(profile, request.getLocale())));
    }
    response.getWriter().print(FileUtil.readFile(script));
}
Also used : File(java.io.File) Profile(jmri.profile.Profile)

Example 4 with Profile

use of jmri.profile.Profile in project JMRI by JMRI.

the class WebAppServlet method processAbout.

private void processAbout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType(UTF8_APPLICATION_JSON);
    Profile profile = ProfileManager.getDefault().getActiveProfile();
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode about = mapper.createObjectNode();
    // NOI18N
    about.put("additionalInfo", "TRADEMARKS AND LICENSE GO HERE");
    // NOI18N
    about.put("copyright", Version.getCopyright());
    // NOI18N
    about.put("title", WebServerPreferences.getDefault().getRailRoadName());
    // NOI18N
    about.put("imgAlt", Application.getApplicationName());
    // assuming Application.getLogo() is relative to program:
    // NOI18N
    about.put("imgSrc", "/" + Application.getLogo());
    // NOI18N
    ArrayNode productInfo = about.putArray("productInfo");
    productInfo.add(mapper.createObjectNode().put(NAME, Application.getApplicationName()).put(VALUE, Version.name()));
    // NOI18N
    productInfo.add(mapper.createObjectNode().put(NAME, Bundle.getMessage(request.getLocale(), "ActiveProfile")).put(VALUE, profile.getName()));
    productInfo.add(mapper.createObjectNode().put(NAME, // NOI18N
    "Java").put(VALUE, Bundle.getMessage(request.getLocale(), "JavaVersion", // NOI18N
    System.getProperty("java.version", Bundle.getMessage(request.getLocale(), "Unknown")), // NOI18N
    System.getProperty("java.vm.name", Bundle.getMessage(request.getLocale(), "Unknown")), // NOI18N
    System.getProperty("java.vm.version", ""), // NOI18N
    System.getProperty("java.vendor", Bundle.getMessage(request.getLocale(), "Unknown")))));
    productInfo.add(mapper.createObjectNode().put(NAME, Bundle.getMessage(request.getLocale(), "Runtime")).put(VALUE, Bundle.getMessage(request.getLocale(), "RuntimeVersion", // NOI18N
    System.getProperty("java.runtime.name", Bundle.getMessage(request.getLocale(), "Unknown")), // NOI18N
    System.getProperty("java.runtime.version", ""))));
    for (ConnectionConfig conn : InstanceManager.getDefault(ConnectionConfigManager.class)) {
        if (!conn.getDisabled()) {
            productInfo.add(mapper.createObjectNode().put(NAME, Bundle.getMessage(request.getLocale(), "ConnectionName", conn.getConnectionName())).put(VALUE, Bundle.getMessage(request.getLocale(), "ConnectionValue", conn.name(), conn.getInfo())));
        }
    }
    response.getWriter().print(mapper.writeValueAsString(about));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Profile(jmri.profile.Profile) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConnectionConfig(jmri.jmrix.ConnectionConfig)

Example 5 with Profile

use of jmri.profile.Profile in project JMRI by JMRI.

the class JmriJTablePersistenceManager method savePreferences.

@Override
public synchronized void savePreferences(Profile profile) {
    log.debug("Saving preferences (dirty={})...", this.dirty);
    Element element = new Element(TABLES_ELEMENT, TABLES_NAMESPACE);
    if (!this.columns.isEmpty()) {
        this.columns.entrySet().stream().map((entry) -> {
            Element table = new Element("table").setAttribute("name", entry.getKey());
            Element columnsElement = new Element("columns");
            entry.getValue().entrySet().stream().map((column) -> {
                Element columnElement = new Element("column").setAttribute("name", column.getKey());
                if (column.getValue().getOrder() != -1) {
                    columnElement.setAttribute("order", Integer.toString(column.getValue().getOrder()));
                }
                if (column.getValue().getWidth() != -1) {
                    columnElement.setAttribute("width", Integer.toString(column.getValue().getWidth()));
                }
                columnElement.setAttribute("hidden", Boolean.toString(column.getValue().getHidden()));
                return columnElement;
            }).forEach((columnElement) -> {
                columnsElement.addContent(columnElement);
            });
            table.addContent(columnsElement);
            List<SortKey> keys = this.sortKeys.get(entry.getKey());
            if (keys != null) {
                Element sorter = new Element(SORT_ORDER);
                keys.stream().forEach((key) -> {
                    sorter.addContent(new Element("sortKey").setAttribute("column", Integer.toString(key.getColumn())).setAttribute(SORT_ORDER, key.getSortOrder().name()));
                });
                table.addContent(sorter);
            }
            return table;
        }).forEach((table) -> {
            element.addContent(table);
        });
    }
    try {
        ProfileUtils.getUserInterfaceConfiguration(ProfileManager.getDefault().getActiveProfile()).putConfigurationFragment(JDOMUtil.toW3CElement(element), false);
    } catch (JDOMException ex) {
        log.error("Unable to save user preferences", ex);
    }
    this.dirty = false;
}
Also used : Arrays(java.util.Arrays) TableColumnModel(javax.swing.table.TableColumnModel) Enumeration(java.util.Enumeration) SortKey(javax.swing.RowSorter.SortKey) XTableColumnModel(jmri.util.swing.XTableColumnModel) AbstractPreferencesManager(jmri.util.prefs.AbstractPreferencesManager) LoggerFactory(org.slf4j.LoggerFactory) ProfileManager(jmri.profile.ProfileManager) HashMap(java.util.HashMap) Timer(java.util.Timer) InitializationException(jmri.util.prefs.InitializationException) ArrayList(java.util.ArrayList) JDOMException(org.jdom2.JDOMException) JDOMUtil(jmri.util.jdom.JDOMUtil) ProfileUtils(jmri.profile.ProfileUtils) Map(java.util.Map) Profile(jmri.profile.Profile) TableColumnModelEvent(javax.swing.event.TableColumnModelEvent) RowSorter(javax.swing.RowSorter) TimerTask(java.util.TimerTask) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Nonnull(javax.annotation.Nonnull) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChangeEvent(javax.swing.event.ChangeEvent) Logger(org.slf4j.Logger) TableColumn(javax.swing.table.TableColumn) RowSorterListener(javax.swing.event.RowSorterListener) Set(java.util.Set) Objects(java.util.Objects) SortOrder(javax.swing.SortOrder) List(java.util.List) TableColumnModelListener(javax.swing.event.TableColumnModelListener) PropertyChangeListener(java.beans.PropertyChangeListener) JTable(javax.swing.JTable) DataConversionException(org.jdom2.DataConversionException) CheckForNull(javax.annotation.CheckForNull) RowSorterEvent(javax.swing.event.RowSorterEvent) Element(org.jdom2.Element) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) List(java.util.List) JDOMException(org.jdom2.JDOMException)

Aggregations

Profile (jmri.profile.Profile)23 File (java.io.File)14 Date (java.util.Date)7 ArrayList (java.util.ArrayList)6 InitializationException (jmri.util.prefs.InitializationException)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Set (java.util.Set)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 IOException (java.io.IOException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 HashSet (java.util.HashSet)3 Locale (java.util.Locale)3 Map (java.util.Map)3 ServiceLoader (java.util.ServiceLoader)3 ProfileUtils (jmri.profile.ProfileUtils)3 AbstractPreferencesManager (jmri.util.prefs.AbstractPreferencesManager)3 Test (org.junit.Test)3