/** * Tests string events. */ @Test public void testStringEvents() { ConfigurationEvent event; // Makes sure the value passed to the constructor is properly returned. event = new ConfigurationEvent(conf, VARIABLE_NAME, STRING_VALUE); assert STRING_VALUE.equals(event.getValue()); // Makes sure unset values are returned as null. event = new ConfigurationEvent(conf, VARIABLE_NAME, null); assert null == event.getValue(); }
public synchronized void configurationChanged(ConfigurationEvent event) { String var = event.getVariable(); if (var.equals(MuPreferences.DISPLAY_COMPACT_FILE_SIZE)) setSelectedFileSizeFormat(event.getBooleanValue()); } };
/** * Listens to certain configuration variables. */ public void configurationChanged(ConfigurationEvent event) { String var = event.getVariable(); // Rescale buttons icon if (var.equals(MuPreferences.TOOLBAR_ICON_SCALE)) { scaleFactor = event.getFloatValue(); Component components[] = getComponents(); int nbComponents = components.length; for(int i=0; i<nbComponents; i++) { if(components[i] instanceof JButton) { setButtonIcon((JButton)components[i]); } } } }
/** * Listens to certain configuration variables. */ public void configurationChanged(ConfigurationEvent event) { String var = event.getVariable(); // /!\ font.size is set after font.family in AppearancePrefPanel // that's why we only listen to this one in order not to change Font twice if (var.equals(MuPreferences.LOOK_AND_FEEL)) { String lnfName = event.getValue(); if(!UIManager.getLookAndFeel().getClass().getName().equals(lnfName)) setLookAndFeel(lnfName); } } }
/** * Tests event creation. */ @Test public void testConstructor() { ConfigurationEvent event; // Makes sure the constructor initialises events properly. event = new ConfigurationEvent(conf, VARIABLE_NAME, STRING_VALUE); assert conf.equals(event.getConfiguration()); assert VARIABLE_NAME.equals(event.getVariable()); } }
/** * Tests float events. */ @Test public void testFloatEvent() { ConfigurationEvent event; // Makes sure the value passed to the constructor is properly returned. event = new ConfigurationEvent(conf, VARIABLE_NAME, Float.toString(FLOAT_VALUE)); assert FLOAT_VALUE == event.getFloatValue(); // Makes sure unset values are returned as 0. event = new ConfigurationEvent(conf, VARIABLE_NAME, null); assert 0 == event.getFloatValue(); }
/** * Tests boolean events. */ @Test public void testBooleanEvent() { ConfigurationEvent event; // Makes sure the value passed to the constructor is properly returned. event = new ConfigurationEvent(conf, VARIABLE_NAME, Boolean.toString(BOOLEAN_VALUE)); assert BOOLEAN_VALUE == event.getBooleanValue(); // Makes sure unset values are returned as 0. event = new ConfigurationEvent(conf, VARIABLE_NAME, null); assert false == event.getBooleanValue(); }
/*************************************** * ConfigurationListener Implementation ***************************************/ public void configurationChanged(ConfigurationEvent event) { String var = event.getVariable(); // Update the button's icon if the system file icons policy has changed if (var.equals(MuPreferences.SHOW_SINGLE_TAB_HEADER)) refreshViewer(); }
/** * Adds the specified variable to the current section. * @param name name of the variable. * @param value value of the variable. */ public void addVariable(String name, String value) { // If the variable's value was modified, trigger an event. if(currentSection.setVariable(name, value)) { if(sectionNames.empty()) triggerEvent(new ConfigurationEvent(Configuration.this, name, value)); else triggerEvent(new ConfigurationEvent(Configuration.this, sectionNames.peek() + name, value)); } } }
/** * Tests long events. */ @Test public void testLongEvent() { ConfigurationEvent event; // Makes sure the value passed to the constructor is properly returned. event = new ConfigurationEvent(conf, VARIABLE_NAME, Long.toString(LONG_VALUE)); assert LONG_VALUE == event.getLongValue(); // Makes sure unset values are returned as 0. event = new ConfigurationEvent(conf, VARIABLE_NAME, null); assert 0 == event.getLongValue(); }
/** * Tests double events. */ @Test public void testDoubleEvent() { ConfigurationEvent event; // Makes sure the value passed to the constructor is properly returned. event = new ConfigurationEvent(conf, VARIABLE_NAME, Double.toString(DOUBLE_VALUE)); assert DOUBLE_VALUE == event.getDoubleValue(); // Makes sure unset values are returned as 0. event = new ConfigurationEvent(conf, VARIABLE_NAME, null); assert 0 == event.getDoubleValue(); }
/** * Tests integer events. */ @Test public void testIntegerEvent() { ConfigurationEvent event; // Makes sure the value passed to the constructor is properly returned. event = new ConfigurationEvent(conf, VARIABLE_NAME, Integer.toString(INTEGER_VALUE)); assert INTEGER_VALUE == event.getIntegerValue(); // Makes sure unset values are returned as 0. event = new ConfigurationEvent(conf, VARIABLE_NAME, null); assert 0 == event.getIntegerValue(); }
/** * Tests list events. */ @Test public void testListEvents() { ConfigurationEvent event; // Makes sure the value passed to the constructor is properly returned. event = new ConfigurationEvent(conf, VARIABLE_NAME, ValueList.toString(LIST_VALUE, ";")); assert LIST_VALUE.equals(event.getListValue(";")); // Makes sure unset values are returned as null. event = new ConfigurationEvent(conf, VARIABLE_NAME, null); assert null == event.getListValue(";"); }
/** * Reacts to configuration changes. */ public void configurationChanged(ConfigurationEvent event) { if(event.getVariable().startsWith(MuPreferences.SHELL_SECTION)) setShellCommand(); } }
/** * Sets the value of the specified variable. * <p> * This method will return <code>false</code> if it didn't modify <code>name</code>'s value. Note that this doesn't * mean the call failed, but that <code>name</code>'s value was already equal to <code>value</code>. * </p> * <p> * If the value of the specified variable is actually modified, an {@link ConfigurationEvent event} will be passed * to all LISTENERS. * </p> * @param name fully qualified name of the variable to set. * @param value new value for the variable. * @return <code>true</code> if this call resulted in a modification of the variable's value, * <code>false</code> otherwise. * @see #getVariable(String) * @see #getVariable(String,String) */ public synchronized boolean setVariable(String name, String value) { ConfigurationExplorer explorer; // Used to navigate to the variable's parent section. String buffer; // Buffer for the variable's name trimmed of section information. // Moves to the parent section. buffer = moveToParent(explorer = new ConfigurationExplorer(root), name, true); // If the variable's value was actually modified, triggers an event. if(explorer.getSection().setVariable(buffer, value)) { triggerEvent(new ConfigurationEvent(this, name, value)); return true; } return false; }
/** * Adds or removes filters based on configuration changes. */ public void configurationChanged(ConfigurationEvent event) { String var = event.getVariable(); // Show or hide hidden files if (var.equals(MuPreferences.SHOW_HIDDEN_FILES)) { if(event.getBooleanValue()) removeFileFilter(hiddenFileFilter); else addFileFilter(hiddenFileFilter); } // Show or hide .DS_Store files (Mac OS X option) else if (var.equals(MuPreferences.SHOW_DS_STORE_FILES)) { if(event.getBooleanValue()) removeFileFilter(dsFileFilter); else addFileFilter(dsFileFilter); } // Show or hide system folders (Mac OS X option) else if (var.equals(MuPreferences.SHOW_SYSTEM_FOLDERS)) { if(event.getBooleanValue()) removeFileFilter(systemFileFilter); else addFileFilter(systemFileFilter); } } }
/** * Listens to certain configuration variables. */ public void configurationChanged(ConfigurationEvent event) { String var = event.getVariable(); // Reload butons icon if the icon scale factor has changed if (var.equals(MuPreferences.COMMAND_BAR_ICON_SCALE)) { scaleFactor = event.getFloatValue(); // Change the button's icon but NOT the action's icon which has to remain in its original non-scaled size setIcon(IconManager.getScaledIcon(((MuAction) getAction()).getIcon(), scaleFactor)); } } }
/** * Listens to some configuration variables. */ public void configurationChanged(ConfigurationEvent event) { String var = event.getVariable(); if (var.equals(MuPreferences.TIME_FORMAT) || var.equals(MuPreferences.DATE_FORMAT) || var.equals(MuPreferences.DATE_SEPARATOR)) updateDateFormat(); } }
/** * Deletes the specified variable from the configuration. * <p> * If the variable was set, a configuration {@link ConfigurationEvent event} will be passed to * all registered LISTENERS. * </p> * @param name name of the variable to remove. * @return the variable's old value, or <code>null</code> if it wasn't set. */ public synchronized String removeVariable(String name) { BufferedConfigurationExplorer explorer; // Used to navigate to the variable's parent section. String buffer; // Buffer for the variable's name trimmed of section information. // If the variable's 'path' doesn't exist, return null. if((buffer = moveToParent(explorer = new BufferedConfigurationExplorer(root), name, false)) == null) return null; // If the variable was actually set, triggers an event. if((buffer = explorer.getSection().removeVariable(buffer)) != null) { prune(explorer); triggerEvent(new ConfigurationEvent(this, name, null)); } return buffer; }
/** * Listens to certain configuration variables. */ public void configurationChanged(ConfigurationEvent event) { String var = event.getVariable(); if (var.equals(MuPreferences.DISPLAY_COMPACT_FILE_SIZE)) { FileTableModel.setSizeFormat(event.getBooleanValue()); tableModel.fillCellCache(); resizeAndRepaint(); } else if (var.equals(MuPreferences.DATE_FORMAT) || var.equals(MuPreferences.DATE_SEPARATOR) || var.equals(MuPreferences.TIME_FORMAT)) { // Note: for the update to work properly, CustomDateFormat's configurationChanged() method has to be called // before FileTable's, so that CustomDateFormat gets notified of date format first. // Since listeners are stored by MuConfiguration in a hash map, order is pretty much random. // So CustomDateFormat#updateDateFormat() has to be called before to ensure that is uses the new date format. CustomDateFormat.updateDateFormat(); tableModel.fillCellCache(); resizeAndRepaint(); } // Repaint file icons if their size has changed else if (var.equals(MuPreferences.TABLE_ICON_SCALE)) { // Recalcule row height, revalidate and repaint the table setRowHeight(); } // Repaint file icons if the system file icons policy has changed else if (var.equals(MuPreferences.USE_SYSTEM_FILE_ICONS)) repaint(); }