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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
}
});
}
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);
});
});
}
Aggregations