Search in sources :

Example 26 with UserPreferencesManager

use of jmri.UserPreferencesManager in project JMRI by JMRI.

the class AppConfigBase method savePressed.

/**
     * Handle the Save button: Backup the file, write a new one, prompt for what
     * to do next. To do that, the last step is to present a dialog box
     * prompting the user to end the program, if required.
     *
     * @param restartRequired true if JMRI should prompt user to restart
     */
public void savePressed(boolean restartRequired) {
    // true if port name OK
    if (!checkPortNames()) {
        return;
    }
    // true if there arn't any duplicates
    if (!checkDups()) {
        if (!(JOptionPane.showConfirmDialog(null, rb.getString("MessageLongDupsWarning"), rb.getString("MessageShortDupsWarning"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)) {
            return;
        }
    }
    saveContents();
    final UserPreferencesManager p;
    p = InstanceManager.getDefault(UserPreferencesManager.class);
    p.resetChangeMade();
    if (restartRequired && !InstanceManager.getDefault(ShutDownManager.class).isShuttingDown()) {
        JLabel question = new JLabel(MessageFormat.format(rb.getString("MessageLongQuitWarning"), Application.getApplicationName()));
        Object[] options = { rb.getString("RestartNow"), rb.getString("RestartLater") };
        int retVal = JOptionPane.showOptionDialog(this, question, MessageFormat.format(rb.getString("MessageShortQuitWarning"), Application.getApplicationName()), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null);
        switch(retVal) {
            case JOptionPane.YES_OPTION:
                dispose();
                Apps.handleRestart();
                break;
            case JOptionPane.NO_OPTION:
                break;
            default:
                break;
        }
    }
    // don't restart the program, just close the window
    if (getTopLevelAncestor() != null) {
        getTopLevelAncestor().setVisible(false);
    }
}
Also used : JLabel(javax.swing.JLabel) UserPreferencesManager(jmri.UserPreferencesManager) ShutDownManager(jmri.ShutDownManager)

Example 27 with UserPreferencesManager

use of jmri.UserPreferencesManager in project JMRI by JMRI.

the class DecoderPro3Action method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    mainFrame = new DecoderPro3Window(DecoderPro3.getMenuFile(), DecoderPro3.getToolbarFile());
    UserPreferencesManager p = InstanceManager.getDefault(jmri.UserPreferencesManager.class);
    if (!p.isWindowPositionSaved(mainFrame.getWindowFrameRef())) {
        mainFrame.setSize(new Dimension(1024, 600));
        mainFrame.setPreferredSize(new Dimension(1024, 600));
    }
    if (wi instanceof RosterGroupSelector) {
        mainFrame.setSelectedRosterGroup(((RosterGroupSelector) wi).getSelectedRosterGroup());
    }
    mainFrame.setVisible(true);
    mainFrame.setAllowQuit(allowQuit);
    mainFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
}
Also used : Dimension(java.awt.Dimension) UserPreferencesManager(jmri.UserPreferencesManager) RosterGroupSelector(jmri.jmrit.roster.rostergroup.RosterGroupSelector)

Example 28 with UserPreferencesManager

use of jmri.UserPreferencesManager in project JMRI by JMRI.

the class JmriUserPreferencesManagerTest method testGetWindowList.

@Test
public void testGetWindowList() {
    UserPreferencesManager m = new JmriUserPreferencesManager();
    m.setSaveAllowed(false);
    Assert.assertTrue(m.getWindowList().isEmpty());
    Point location = new Point(69, 96);
    m.setWindowLocation(strClass, location);
    Assert.assertEquals(1, m.getWindowList().size());
    Assert.assertEquals(strClass, m.getWindowList().get(0));
    Dimension windowSize = new Dimension(666, 999);
    m.setWindowSize(strClass, windowSize);
    Assert.assertEquals(1, m.getWindowList().size());
    Assert.assertEquals(strClass, m.getWindowList().get(0));
}
Also used : Point(java.awt.Point) Dimension(java.awt.Dimension) UserPreferencesManager(jmri.UserPreferencesManager) Test(org.junit.Test)

Example 29 with UserPreferencesManager

use of jmri.UserPreferencesManager in project JMRI by JMRI.

the class JmriUserPreferencesManagerTest method testSetClassDescription.

@Test
public void testSetClassDescription() {
    UserPreferencesManager m = new TestJmriUserPreferencesManager();
    m.setSaveAllowed(false);
    Assert.assertNotNull(m.getClassDescription(strClass));
    Assert.assertTrue(m.getClassDescription(strClass).isEmpty());
    m.setClassDescription(strClass);
    Assert.assertNotNull(m.getClassDescription(strClass));
    Assert.assertTrue(m.getClassDescription(strClass).isEmpty());
    m.setClassDescription(AppConfigBase.class.getName());
    String d = ResourceBundle.getBundle("apps.AppsConfigBundle").getString("Application");
    Assert.assertEquals(d, m.getClassDescription(AppConfigBase.class.getName()));
}
Also used : AppConfigBase(apps.AppConfigBase) UserPreferencesManager(jmri.UserPreferencesManager) Test(org.junit.Test)

Example 30 with UserPreferencesManager

use of jmri.UserPreferencesManager in project JMRI by JMRI.

the class JmriUserPreferencesManagerTest method testSaveElement.

@Test
public void testSaveElement() throws IOException {
    JUnitUtil.resetProfileManager(new NullProfile(folder.newFolder(Profile.PROFILE)));
    Point location = new Point(69, 96);
    Dimension windowSize = new Dimension(100, 200);
    UserPreferencesManager m1 = new TestJmriUserPreferencesManager();
    m1.setSaveAllowed(false);
    m1.setProperty(strClass, "test1", "value1");
    m1.setProperty(strClass, "intTest", 42);
    m1.setProperty(strClass, "doubleTest", Math.PI);
    m1.setProperty(strClass, "booleanTest", true);
    m1.setWindowLocation(strClass, location);
    m1.setWindowSize(strClass, windowSize);
    m1.setPreferenceState(strClass, "test2", true);
    m1.setPreferenceState(strClass, "test3", false);
    m1.setSimplePreferenceState(strClass, true);
    m1.setComboBoxLastSelection(strClass, "selection1");
    m1.setSaveAllowed(true);
    File target = new File(new File(new File(ProfileManager.getDefault().getActiveProfile().getPath(), "profile"), NodeIdentity.identity()), "user-interface.xml");
    Assert.assertTrue(target.exists());
    Assert.assertTrue(target.isFile());
    if (log.isDebugEnabled()) {
        Files.lines(target.toPath()).forEach((line) -> log.debug(line));
    }
    JUnitUtil.resetInstanceManager();
    JUnitUtil.resetPreferencesProviders();
    JmriUserPreferencesManager m2 = new JmriUserPreferencesManager();
    m2.readUserPreferences();
    Assert.assertEquals("value1", m2.getProperty(strClass, "test1"));
    Assert.assertEquals(42, m2.getProperty(strClass, "intTest"));
    Assert.assertEquals(Math.PI, m2.getProperty(strClass, "doubleTest"));
    Assert.assertEquals(true, m2.getProperty(strClass, "booleanTest"));
    Assert.assertEquals(location, m2.getWindowLocation(strClass));
    Assert.assertEquals(windowSize, m2.getWindowSize(strClass));
    Assert.assertEquals(true, m2.getPreferenceState(strClass, "test2"));
    Assert.assertEquals(false, m2.getPreferenceState(strClass, "test3"));
    Assert.assertEquals(true, m2.getSimplePreferenceState(strClass));
    Assert.assertEquals("selection1", m2.getComboBoxLastSelection(strClass));
}
Also used : NullProfile(jmri.profile.NullProfile) Point(java.awt.Point) Dimension(java.awt.Dimension) File(java.io.File) UserPreferencesManager(jmri.UserPreferencesManager) Test(org.junit.Test)

Aggregations

UserPreferencesManager (jmri.UserPreferencesManager)47 Test (org.junit.Test)43 HashMap (java.util.HashMap)10 Dimension (java.awt.Dimension)7 Point (java.awt.Point)5 AppConfigBase (apps.AppConfigBase)2 File (java.io.File)2 JLabel (javax.swing.JLabel)2 RosterGroupSelector (jmri.jmrit.roster.rostergroup.RosterGroupSelector)2 NullProfile (jmri.profile.NullProfile)2 BoxLayout (javax.swing.BoxLayout)1 JCheckBox (javax.swing.JCheckBox)1 JPanel (javax.swing.JPanel)1 ShutDownManager (jmri.ShutDownManager)1