Search in sources :

Example 6 with Memory

use of jmri.Memory in project JMRI by JMRI.

the class LayoutBlock method setMemoryName.

/**
     * Add Memory by name
     */
public void setMemoryName(String name) {
    if ((name == null) || name.equals("")) {
        namedMemory = null;
        memoryName = "";
        return;
    }
    memoryName = name;
    Memory memory = jmri.InstanceManager.memoryManagerInstance().getMemory(name);
    if (memory != null) {
        namedMemory = jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(name, memory);
    }
}
Also used : Memory(jmri.Memory)

Example 7 with Memory

use of jmri.Memory in project JMRI by JMRI.

the class AbstractMemoryManager method newMemory.

@Override
public Memory newMemory(String systemName, String userName) {
    if (log.isDebugEnabled()) {
        log.debug("new Memory:" + ((systemName == null) ? "null" : systemName) + ";" + ((userName == null) ? "null" : userName));
    }
    // return existing if there is one
    Memory s;
    if ((userName != null) && ((s = getByUserName(userName)) != null)) {
        if (getBySystemName(systemName) != s) {
            log.error("inconsistent user (" + userName + ") and system name (" + systemName + ") results; userName related to (" + s.getSystemName() + ")");
        }
        return s;
    }
    if ((s = getBySystemName(systemName)) != null) {
        // handle user name from request
        if (userName != null) {
            // check if already on set in Object, might be inconsistent
            if (!userName.equals(s.getUserName())) {
                // this is a problem
                log.warn("newMemory request for system name \"{}\" user name \"{}\" found memory with existing user name \"{}\"", systemName, userName, s.getUserName());
            } else {
                s.setUserName(userName);
            }
        }
        return s;
    }
    // doesn't exist, make a new one
    s = createNewMemory(systemName, userName);
    // if that failed, blame it on the input arguements
    if (s == null) {
        throw new IllegalArgumentException();
    }
    // save in the maps
    register(s);
    /*The following keeps trace of the last created auto system name.  
         currently we do not reuse numbers, although there is nothing to stop the 
         user from manually recreating them*/
    if (systemName.startsWith("IM:AUTO:")) {
        try {
            int autoNumber = Integer.parseInt(systemName.substring(8));
            if (autoNumber > lastAutoMemoryRef) {
                lastAutoMemoryRef = autoNumber;
            }
        } catch (NumberFormatException e) {
            log.warn("Auto generated SystemName " + systemName + " is not in the correct format");
        }
    }
    return s;
}
Also used : Memory(jmri.Memory)

Example 8 with Memory

use of jmri.Memory in project JMRI by JMRI.

the class IconEditorWindowTest method testMemoryEditor.

public void testMemoryEditor() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // can't Assume in TestCase
        return;
    }
    Editor.JFrameItem iconEditorFrame = _editor.getIconFrame("Memory");
    IconAdder iconEditor = iconEditorFrame.getEditor();
    Assert.assertNotNull(iconEditor);
    iconEditor._sysNametext.setText("IM0");
    iconEditor.addToTable();
    MemoryIcon memIcon = _editor.putMemory();
    Assert.assertNotNull(memIcon);
    Memory memory = memIcon.getMemory();
    Assert.assertNotNull(memory);
    int x = 20;
    int y = 10;
    memIcon.setLocation(x, y);
    _panel.repaint();
    java.awt.Point location = new java.awt.Point(x + memIcon.getSize().width / 2, y + memIcon.getSize().height / 2);
    getHelper().enterClickAndLeave(new MouseEventData(this, // component
    _panel, // number clicks
    1, // modifiers
    EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
    false, // sleeptime
    10, // position
    EventDataConstants.CUSTOM, location));
    iconEditor._sysNametext.setText("IM1");
    iconEditor.addToTable();
    MemorySpinnerIcon memSpinIcon = _editor.addMemorySpinner();
    Assert.assertNotNull(memSpinIcon);
    memory = memSpinIcon.getMemory();
    Assert.assertNotNull(memory);
    x = 70;
    y = 10;
    memSpinIcon.setLocation(x, y);
    _panel.repaint();
    location = new java.awt.Point(x + memSpinIcon.getSize().width / 2, y + memSpinIcon.getSize().height / 2);
    getHelper().enterClickAndLeave(new MouseEventData(this, // component
    _panel, // number clicks
    1, // modifiers
    EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
    false, // sleeptime
    10, // position
    EventDataConstants.CUSTOM, location));
    iconEditor._sysNametext.setText("IM2");
    iconEditor.addToTable();
    MemoryInputIcon memInputIcon = _editor.addMemoryInputBox();
    Assert.assertNotNull(memInputIcon);
    memory = memInputIcon.getMemory();
    Assert.assertNotNull(memory);
    x = 150;
    y = 10;
    memInputIcon.setLocation(x, y);
    _panel.repaint();
    location = new java.awt.Point(x + memInputIcon.getSize().width / 2, y + memInputIcon.getSize().height / 2);
    getHelper().enterClickAndLeave(new MouseEventData(this, // component
    _panel, // number clicks
    1, // modifiers
    EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
    false, // sleeptime
    10, // position
    EventDataConstants.CUSTOM, location));
    TestHelper.disposeWindow(iconEditorFrame, this);
}
Also used : Memory(jmri.Memory) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) PanelEditor(jmri.jmrit.display.panelEditor.PanelEditor)

Example 9 with Memory

use of jmri.Memory in project JMRI by JMRI.

the class AbstractMemoryManagerConfigXML method loadMemories.

/**
     * Utility method to load the individual Memory objects. If there's no
     * additional info needed for a specific Memory type, invoke this with the
     * parent of the set of Memory elements.
     *
     * @param memories Element containing the Memory elements to load.
     */
@SuppressWarnings("unchecked")
public void loadMemories(Element memories) {
    List<Element> memoryList = memories.getChildren("memory");
    if (log.isDebugEnabled()) {
        log.debug("Found " + memoryList.size() + " Memory objects");
    }
    MemoryManager tm = InstanceManager.memoryManagerInstance();
    for (int i = 0; i < memoryList.size(); i++) {
        String sysName = getSystemName(memoryList.get(i));
        if (sysName == null) {
            log.warn("unexpected null in systemName " + (memoryList.get(i)));
            break;
        }
        String userName = getUserName(memoryList.get(i));
        checkNameNormalization(sysName, userName, tm);
        if (log.isDebugEnabled()) {
            log.debug("create Memory: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        Memory m = tm.newMemory(sysName, userName);
        if (memoryList.get(i).getAttribute("value") != null) {
            loadValue(memoryList.get(i), m);
        }
        // load common parts
        loadCommon(m, memoryList.get(i));
    }
}
Also used : Memory(jmri.Memory) Element(org.jdom2.Element) MemoryManager(jmri.MemoryManager)

Example 10 with Memory

use of jmri.Memory in project JMRI by JMRI.

the class JsonMemorySocketService method onMessage.

@Override
public void onMessage(String type, JsonNode data, Locale locale) throws IOException, JmriException, JsonException {
    this.locale = locale;
    String name = data.path(NAME).asText();
    if (data.path(METHOD).asText().equals(PUT)) {
        this.connection.sendMessage(this.service.doPut(type, name, data, locale));
    } else {
        this.connection.sendMessage(this.service.doPost(type, name, data, locale));
    }
    if (!this.memories.containsKey(name)) {
        Memory memory = InstanceManager.getDefault(MemoryManager.class).getMemory(name);
        if (memory != null) {
            MemoryListener listener = new MemoryListener(memory);
            memory.addPropertyChangeListener(listener);
            this.memories.put(name, listener);
        }
    }
}
Also used : Memory(jmri.Memory) MemoryManager(jmri.MemoryManager)

Aggregations

Memory (jmri.Memory)31 MemoryManager (jmri.MemoryManager)7 Sensor (jmri.Sensor)5 JsonException (jmri.server.json.JsonException)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Element (org.jdom2.Element)4 Conditional (jmri.Conditional)3 JmriException (jmri.JmriException)3 SignalHead (jmri.SignalHead)3 Turnout (jmri.Turnout)3 Editor (jmri.jmrit.display.Editor)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 Block (jmri.Block)2 ConfigureManager (jmri.ConfigureManager)2 Light (jmri.Light)2 Logix (jmri.Logix)2 NamedBean (jmri.NamedBean)2 Path (jmri.Path)2