Search in sources :

Example 1 with PreferenceChangeEvent

use of java.util.prefs.PreferenceChangeEvent in project robovm by robovm.

the class OldPreferenceChangeEventTest method testGetNewValue.

public void testGetNewValue() {
    AbstractPreferences parent = (AbstractPreferences) Preferences.userNodeForPackage(Preferences.class);
    AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
    MockPreferenceChangeListener pl = new MockPreferenceChangeListener() {

        public void preferenceChange(PreferenceChangeEvent pce) {
            if (pce != null && pce.getNewValue().equals(Integer.toString(Integer.MAX_VALUE))) {
                result = true;
            }
            super.preferenceChange(pce);
        }
    };
    pref.addPreferenceChangeListener(pl);
    try {
        pref.putInt("key_int", Integer.MAX_VALUE);
        assertEquals(1, pl.getChanged());
        assertTrue(pl.getResult());
        pl.reset();
        pref.putInt("key_int", Integer.MAX_VALUE);
        assertEquals(1, pl.getChanged());
        assertTrue(pl.getResult());
        pl.reset();
    } finally {
        pref.removePreferenceChangeListener(pl);
    }
}
Also used : PreferenceChangeEvent(java.util.prefs.PreferenceChangeEvent) AbstractPreferences(java.util.prefs.AbstractPreferences) AbstractPreferences(java.util.prefs.AbstractPreferences) Preferences(java.util.prefs.Preferences)

Example 2 with PreferenceChangeEvent

use of java.util.prefs.PreferenceChangeEvent in project robovm by robovm.

the class OldPreferenceChangeEventTest method testGetNode.

public void testGetNode() {
    AbstractPreferences parent = (AbstractPreferences) Preferences.userNodeForPackage(Preferences.class);
    AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
    MockPreferenceChangeListener pl = new MockPreferenceChangeListener() {

        public void preferenceChange(PreferenceChangeEvent pce) {
            if (pce != null && "mock".equals(pce.getNode().name())) {
                result = true;
            }
            super.preferenceChange(pce);
        }
    };
    pref.addPreferenceChangeListener(pl);
    try {
        pref.putInt("key_int", Integer.MAX_VALUE);
        assertEquals(1, pl.getChanged());
        assertTrue(pl.getResult());
        pl.reset();
    } finally {
        pref.removePreferenceChangeListener(pl);
    }
}
Also used : PreferenceChangeEvent(java.util.prefs.PreferenceChangeEvent) AbstractPreferences(java.util.prefs.AbstractPreferences) AbstractPreferences(java.util.prefs.AbstractPreferences) Preferences(java.util.prefs.Preferences)

Example 3 with PreferenceChangeEvent

use of java.util.prefs.PreferenceChangeEvent in project robovm by robovm.

the class OldPreferenceChangeEventTest method testGetKey.

public void testGetKey() {
    AbstractPreferences parent = (AbstractPreferences) Preferences.userNodeForPackage(Preferences.class);
    AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
    MockPreferenceChangeListener pl = new MockPreferenceChangeListener() {

        public void preferenceChange(PreferenceChangeEvent pce) {
            if (pce != null && pce.getKey().equals("key_int")) {
                result = true;
            }
            super.preferenceChange(pce);
        }
    };
    pref.addPreferenceChangeListener(pl);
    try {
        pref.putInt("key_int", Integer.MAX_VALUE);
        assertEquals(1, pl.getChanged());
        assertTrue(pl.getResult());
        pl.reset();
    } finally {
        pref.removePreferenceChangeListener(pl);
    }
}
Also used : PreferenceChangeEvent(java.util.prefs.PreferenceChangeEvent) AbstractPreferences(java.util.prefs.AbstractPreferences) AbstractPreferences(java.util.prefs.AbstractPreferences) Preferences(java.util.prefs.Preferences)

Example 4 with PreferenceChangeEvent

use of java.util.prefs.PreferenceChangeEvent in project java-jotasync by trixon.

the class SpeedDialPanel method init.

private void init() {
    startButton.setIcon(MaterialIcon._Av.PLAY_ARROW.get(AlmondUI.ICON_SIZE_NORMAL, mAlmondOptions.getIconColor()));
    menuButton.setIcon(MaterialIcon._Navigation.MENU.get(AlmondUI.ICON_SIZE_NORMAL, mAlmondOptions.getIconColor()));
    startButton.setToolTipText(Dict.START.toString());
    menuButton.setToolTipText(Dict.MENU.toString());
    final ActionListener editActionListener = (ActionEvent e) -> {
        MainFrame mainFrame = (MainFrame) SwingUtilities.getRoot(SpeedDialPanel.this);
        mainFrame.showEditor(mButton.getJob().getId(), true);
    };
    final ActionListener editorActionListener = (ActionEvent e) -> {
        MainFrame mainFrame = (MainFrame) SwingUtilities.getRoot(SpeedDialPanel.this);
        mainFrame.showEditor(mButton.getJob().getId(), false);
    };
    mButtons.clear();
    int index = -1;
    for (Component component : centerPanel.getComponents()) {
        if (component instanceof SpeedDialButton) {
            index++;
            SpeedDialButton button = (SpeedDialButton) component;
            button.setIndex(index);
            button.addMouseListener(new MouseAdapter() {

                @Override
                public void mousePressed(MouseEvent evt) {
                    SwingUtilities.invokeLater(() -> {
                        if (mManager.hasJobs()) {
                            mButton = (SpeedDialButton) evt.getSource();
                            mResetMenuItem.setEnabled(mButton.getJob() != null);
                            mEditMenuItem.setEnabled(mButton.getJob() != null);
                            mEditorMenuItem.setEnabled(mButton.getJob() != null);
                            mEditorMenuItem.removeActionListener(editorActionListener);
                            mEditMenuItem.removeActionListener(editActionListener);
                            if (mButton.getJob() == null) {
                                mEditMenuItem.setText(Dict.EDIT.getString());
                            } else {
                                mEditMenuItem.setText(String.format("%s %s", Dict.EDIT.getString(), mButton.getJob().getName()));
                            }
                            if (!mButton.isEnabled() && evt.getButton() == MouseEvent.BUTTON1 || evt.getButton() == MouseEvent.BUTTON3) {
                                mEditMenuItem.addActionListener(editActionListener);
                                mEditorMenuItem.addActionListener(editorActionListener);
                                mPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
                            }
                        }
                    });
                }
            });
            button.addActionListener((ActionEvent evt) -> {
                mSpeedDialListeners.stream().forEach((se.trixon.jota.client.ui.SpeedDialListener speedDialListener) -> {
                    try {
                        speedDialListener.onSpeedDialButtonClicked(mButton);
                    } catch (Exception e) {
                    // nvm
                    }
                });
            });
            mButtons.add(button);
        }
    }
    mManager.addConnectionListeners(this);
    mManager.getClient().addServerEventListener(this);
    addSpeedDialListener(this);
    ClientOptions.INSTANCE.getPreferences().addPreferenceChangeListener((PreferenceChangeEvent evt) -> {
        String key = evt.getKey();
        if (key.equalsIgnoreCase(ClientOptions.KEY_CUSTOM_COLORS)) {
            if (mManager.isConnected() && mManager.hasJobs()) {
                for (int i = 0; i < mButtons.size(); i++) {
                    SpeedDialButton button = mButtons.get(i);
                    try {
                        button.setJobId(mManager.getServerCommander().getSpeedDial(i));
                        button.updateColor();
                    } catch (RemoteException ex) {
                        Logger.getLogger(SpeedDialPanel.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    });
}
Also used : PreferenceChangeEvent(java.util.prefs.PreferenceChangeEvent) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) RemoteException(java.rmi.RemoteException) ActionListener(java.awt.event.ActionListener) Component(java.awt.Component) RemoteException(java.rmi.RemoteException)

Example 5 with PreferenceChangeEvent

use of java.util.prefs.PreferenceChangeEvent in project java-jotasync by trixon.

the class Server method intiListeners.

private void intiListeners() {
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        notifyClientsShutdown();
    }));
    mOptions.getPreferences().addPreferenceChangeListener((PreferenceChangeEvent evt) -> {
        HashSet<ClientCallbacks> invalidClientCallbacks = new HashSet<>();
        for (ClientCallbacks clientCallback : mClientCallbacks) {
            switch(evt.getKey()) {
                case ServerOptions.KEY_CRON_ACTIVE:
                    {
                        try {
                            clientCallback.onServerEvent(ServerEvent.CRON_CHANGED);
                        } catch (RemoteException ex) {
                            // Add invalid reference for removal
                            invalidClientCallbacks.add(clientCallback);
                        }
                    }
                    break;
            }
        }
        invalidClientCallbacks.stream().forEach((invalidClientCallback) -> {
            // Remove invalid reference
            mClientCallbacks.remove(invalidClientCallback);
        });
    });
}
Also used : PreferenceChangeEvent(java.util.prefs.PreferenceChangeEvent) ClientCallbacks(se.trixon.jota.shared.ClientCallbacks) RemoteException(java.rmi.RemoteException) HashSet(java.util.HashSet)

Aggregations

PreferenceChangeEvent (java.util.prefs.PreferenceChangeEvent)5 AbstractPreferences (java.util.prefs.AbstractPreferences)3 Preferences (java.util.prefs.Preferences)3 RemoteException (java.rmi.RemoteException)2 Component (java.awt.Component)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 HashSet (java.util.HashSet)1 UnsupportedLookAndFeelException (javax.swing.UnsupportedLookAndFeelException)1 ClientCallbacks (se.trixon.jota.shared.ClientCallbacks)1