Java Code Examples for java.util.Dictionary#keys()

The following examples show how to use java.util.Dictionary#keys() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SliderPainter.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the biggest value that has an entry in the label table.
 *
 * @return biggest value that has an entry in the label table, or
 * null.
 */
protected Integer getHighestValue ()
{
    final Dictionary dictionary = component.getLabelTable ();

    if ( dictionary == null )
    {
        return null;
    }

    final Enumeration keys = dictionary.keys ();

    Integer max = null;

    while ( keys.hasMoreElements () )
    {
        final Integer i = ( Integer ) keys.nextElement ();

        if ( max == null || i > max )
        {
            max = i;
        }
    }

    return max;
}
 
Example 2
Source File: BasicSliderUI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the smallest value that has an entry in the label table.
 *
 * @return smallest value that has an entry in the label table, or
 *         null.
 * @since 1.6
 */
protected Integer getLowestValue() {
    Dictionary dictionary = slider.getLabelTable();

    if (dictionary == null) {
        return null;
    }

    Enumeration keys = dictionary.keys();

    Integer min = null;

    while (keys.hasMoreElements()) {
        Integer i = (Integer) keys.nextElement();

        if (min == null || i < min) {
            min = i;
        }
    }

    return min;
}
 
Example 3
Source File: BasicSliderUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the biggest value that has an entry in the label table.
 *
 * @return biggest value that has an entry in the label table, or
 *         null.
 * @since 1.6
 */
protected Integer getHighestValue() {
    Dictionary dictionary = slider.getLabelTable();

    if (dictionary == null) {
        return null;
    }

    Enumeration keys = dictionary.keys();

    Integer max = null;

    while (keys.hasMoreElements()) {
        Integer i = (Integer) keys.nextElement();

        if (max == null || i > max) {
            max = i;
        }
    }

    return max;
}
 
Example 4
Source File: BasicSliderUI.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns the biggest value that has an entry in the label table.
 *
 * @return biggest value that has an entry in the label table, or
 *         null.
 * @since 1.6
 */
protected Integer getHighestValue() {
    Dictionary dictionary = slider.getLabelTable();

    if (dictionary == null) {
        return null;
    }

    Enumeration keys = dictionary.keys();

    Integer max = null;

    while (keys.hasMoreElements()) {
        Integer i = (Integer) keys.nextElement();

        if (max == null || i > max) {
            max = i;
        }
    }

    return max;
}
 
Example 5
Source File: Spin.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void paintInfo(Graphics g, double x, double y) {

    StringBuffer sb = new StringBuffer();

    sb.append(b.getLocation() + ", id=" + b.getBundleId() + "\n");

    Dictionary<String, String> headers = b.getHeaders();

    for(Enumeration<String> e = headers.keys(); e.hasMoreElements(); ) {
      final String key = e.nextElement();
      final String val = (String)headers.get(key);

      sb.append(key + ": " + val + "\n");
    }
    spin.paintBox(sb.toString(), g, Color.white, Color.black, (int)x, (int)y,
                  .8, 300, 300);
  }
 
Example 6
Source File: BasicSliderUI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the smallest value that has an entry in the label table.
 *
 * @return smallest value that has an entry in the label table, or
 *         null.
 * @since 1.6
 */
protected Integer getLowestValue() {
    Dictionary dictionary = slider.getLabelTable();

    if (dictionary == null) {
        return null;
    }

    Enumeration keys = dictionary.keys();

    Integer min = null;

    while (keys.hasMoreElements()) {
        Integer i = (Integer) keys.nextElement();

        if (min == null || i < min) {
            min = i;
        }
    }

    return min;
}
 
Example 7
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static public void printDictionary(PrintWriter out, Dictionary<?, ?> d)
    throws IOException
{
  out.println("<table border=0>");
  for (final Enumeration<?> e = d.keys(); e.hasMoreElements();) {
    final Object key = e.nextElement();
    final Object val = d.get(key);
    out.println("<tr>");

    out.println("<td valign=top>");
    printObject(out, key);
    out.println("</td>");

    out.println("<td valign=top>");
    printObject(out, val);
    out.println("</td>");

    out.println("</tr>");
  }
  out.println("</table>");
}
 
Example 8
Source File: BasicSliderUI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected int getHeightOfTallestLabel() {
    Dictionary dictionary = slider.getLabelTable();
    int tallest = 0;
    if ( dictionary != null ) {
        Enumeration keys = dictionary.keys();
        while ( keys.hasMoreElements() ) {
            JComponent label = (JComponent) dictionary.get(keys.nextElement());
            tallest = Math.max( label.getPreferredSize().height, tallest );
        }
    }
    return tallest;
}
 
Example 9
Source File: BasicSliderUI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected int getWidthOfWidestLabel() {
    Dictionary dictionary = slider.getLabelTable();
    int widest = 0;
    if ( dictionary != null ) {
        Enumeration keys = dictionary.keys();
        while ( keys.hasMoreElements() ) {
            JComponent label = (JComponent) dictionary.get(keys.nextElement());
            widest = Math.max( label.getPreferredSize().width, widest );
        }
    }
    return widest;
}
 
Example 10
Source File: BasicSliderUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected int getWidthOfWidestLabel() {
    Dictionary dictionary = slider.getLabelTable();
    int widest = 0;
    if ( dictionary != null ) {
        Enumeration keys = dictionary.keys();
        while ( keys.hasMoreElements() ) {
            JComponent label = (JComponent) dictionary.get(keys.nextElement());
            widest = Math.max( label.getPreferredSize().width, widest );
        }
    }
    return widest;
}
 
Example 11
Source File: Baseline.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
private static Integer getMaxSliderValue(JSlider slider) {
	Dictionary dictionary = slider.getLabelTable();
	if (dictionary != null) {
		Enumeration keys = dictionary.keys();
		int max = slider.getMinimum() - 1;
		while (keys.hasMoreElements()) {
			max = Math.max(max, ((Integer) keys.nextElement()).intValue());
		}
		if (max == slider.getMinimum() - 1) {
			return null;
		}
		return new Integer(max);
	}
	return null;
}
 
Example 12
Source File: YamahaReceiverBinding.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug(BINDING_NAME + " updated");
    try {
        // Process device configuration
        if (config != null) {
            String refreshIntervalString = (String) config.get("refresh");
            if (StringUtils.isNotBlank(refreshIntervalString)) {
                refreshInterval = Long.parseLong(refreshIntervalString);
            }
            // parse all configured receivers
            // ( yamahareceiver:<uid>.host=10.0.0.2 )
            Enumeration<String> keys = config.keys();
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                if (key.endsWith(CONFIG_KEY_HOST)) {
                    // parse host
                    String host = (String) config.get(key);
                    int separatorIdx = key.indexOf('.');
                    // no uid => one device => use default UID
                    String uid = separatorIdx == -1 ? DEFAULT_DEVICE_UID : key.substring(0, separatorIdx);
                    // proxy is stateless. keep them in a map in the
                    // binding.
                    proxies.put(uid, new YamahaReceiverProxy(host));
                }
            }
            setProperlyConfigured(true);
        }
    } catch (Throwable t) {
        logger.error("Error configuring " + getName(), t);
    }
}
 
Example 13
Source File: TestBase.java    From Karaf-Cassandra with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private static String explode(Dictionary dictionary) {
    Enumeration keys = dictionary.keys();
    StringBuffer result = new StringBuffer();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        result.append(String.format("%s=%s", key, dictionary.get(key)));
        if (keys.hasMoreElements()) {
            result.append(", ");
        }
    }
    return result.toString();
}
 
Example 14
Source File: PreferencesMngrImpl.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked by iPojo when one or several properties were updated from Config Admin.
 * @param properties
 */
@Override
public void updateProperties( Dictionary<?,?> properties ) {

	// Ignore iPojo properties
	final List<String> propertiesToSkip = Arrays.asList(
			"component",
			"felix.fileinstall.filename" );

	Map<String,String> map = new HashMap<> ();
	for( Enumeration<?> en = properties.keys(); en.hasMoreElements(); ) {

		Object key = en.nextElement();
		String keyAsString = String.valueOf( key );
		if( propertiesToSkip.contains( keyAsString ))
			continue;

		// "null" are not acceptable values in dictionaries
		// (OSGi often use Hash tables)
		Object value = properties.get( key );
		map.put( keyAsString, String.valueOf( value ));
	}

	this.cache.clear();
	this.cache.putAll( map );
	this.logger.fine( "Preferences were updated in bulk mode." );
}
 
Example 15
Source File: CmApplication.java    From osgi.enroute.examples with Apache License 2.0 5 votes vote down vote up
<K, V> Map<K, V> toMap(Dictionary<K, V> properties, Map<K, V> map) {
	if (properties != null) {
		for (Enumeration<K> e = properties.keys(); e.hasMoreElements();) {
			K key = e.nextElement();
			map.put(key, properties.get(key));
		}
	}
	return map;
}
 
Example 16
Source File: HTTPUndertowTransportActivator.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void configure(UndertowHTTPServerEngine e, Dictionary<String, ?> properties) {
    ThreadingParameters threading = createThreadingParameters(properties);
    if (threading != null) {
        e.setThreadingParameters(threading);
    }
    Enumeration<String> keys = properties.keys();
    while (keys.hasMoreElements()) {
        String k = keys.nextElement();
        if ("continuationsEnabled".equals(k)) {
            e.setContinuationsEnabled(Boolean.parseBoolean((String)properties.get(k)));
        } else if ("maxIdleTime".equals(k)) {
            e.setMaxIdleTime(Integer.parseInt((String)properties.get(k)));
        }
    }
}
 
Example 17
Source File: EpsonProjectorBinding.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {

    logger.debug("Configuration updated, config {}", config != null ? true : false);

    if (config != null) {
        if (deviceConfigCache == null) {
            deviceConfigCache = new HashMap<String, DeviceConfig>();
        }

        String granularityString = (String) config.get("granularity");
        if (StringUtils.isNotBlank(granularityString)) {
            granularity = Integer.parseInt(granularityString);
        }

        Enumeration<String> keys = config.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();

            // the config-key enumeration contains additional keys that we
            // don't want to process here ...
            if ("service.pid".equals(key)) {
                continue;
            }

            Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key);

            if (!matcher.matches()) {
                logger.warn(
                        "given config key '" + key + "' does not follow the expected pattern '<id>.<host|port>'");
                continue;
            }

            matcher.reset();
            matcher.find();

            String deviceId = matcher.group(1);

            DeviceConfig deviceConfig = deviceConfigCache.get(deviceId);

            if (deviceConfig == null) {
                logger.debug("Added new device {}", deviceId);
                deviceConfig = new DeviceConfig(deviceId);
                deviceConfigCache.put(deviceId, deviceConfig);
            }

            String configKey = matcher.group(2);
            String value = (String) config.get(key);

            if ("serialPort".equals(configKey)) {
                deviceConfig.serialPort = value;
            } else if ("host".equals(configKey)) {
                deviceConfig.host = value;
            } else if ("port".equals(configKey)) {
                deviceConfig.port = Integer.valueOf(value);
            } else {
                throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown");
            }
        }

        setProperlyConfigured(true);
    }
}
 
Example 18
Source File: TelnetConfig.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void mergeConfiguration(Dictionary<String,?> configuration)
    throws ConfigurationException
{
  if (configuration == null) {
    return;
  }

  final Enumeration<String> e = configuration.keys();
  while (e.hasMoreElements()) {
    final String key = e.nextElement();
    final Object value = configuration.get(key);
    try {
      if (key.equals(PORT_KEY)) {
        if (value instanceof Short) {
          port = ((Short) value).intValue();
        } else {
          port = ((Integer) value).intValue();
        }
        TelnetConfig.configuration.put(key, value);
      } else if (key.equals(HOST_KEY)) {
        host = ((String) value);
        TelnetConfig.configuration.put(key, value);
      } else if (key.equals(UM_KEY)) {
        um = ((Boolean) value).booleanValue();
        TelnetConfig.configuration.put(key, value);
      } else if (key.equals(REQUIRED_GROUP_KEY)) {
        requiredGroup = ((String) value).trim();
        TelnetConfig.configuration.put(key, value);
      } else if (key.equals(FORBIDDEN_GROUP_KEY)) {
        forbiddenGroup = ((String) value).trim();
        TelnetConfig.configuration.put(key, value);
      } else if (key.equals(BUSYWAIT_KEY)) {
        busyWait = ((Boolean) value).booleanValue();
        TelnetConfig.configuration.put(key, value);
      } else if (key.equals(DEFAULT_USER_KEY)) {
        defaultUser = ((String) value).trim();
        TelnetConfig.configuration.put(key, value);
      } else if (key.equals(DEFAULT_PASSWORD_KEY)) {
        defaultPassword = ((String) value).trim();
        TelnetConfig.configuration.put(key, value);
      } else {
        TelnetConfig.configuration.put(key, value);
      }
    } catch (final IndexOutOfBoundsException ioobe) {
      throw new ConfigurationException(key, "Wrong type");
    } catch (final ClassCastException cce) {
      throw new ConfigurationException(key, "Wrong type: "
                                            + value.getClass().getName());
    }
  }
}
 
Example 19
Source File: BasicSliderUI.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Paints the labels.
 * @param g the graphics
 */
public void paintLabels( Graphics g ) {
    Rectangle labelBounds = labelRect;

    @SuppressWarnings("rawtypes")
    Dictionary dictionary = slider.getLabelTable();
    if ( dictionary != null ) {
        Enumeration<?> keys = dictionary.keys();
        int minValue = slider.getMinimum();
        int maxValue = slider.getMaximum();
        boolean enabled = slider.isEnabled();
        while ( keys.hasMoreElements() ) {
            Integer key = (Integer)keys.nextElement();
            int value = key.intValue();
            if (value >= minValue && value <= maxValue) {
                JComponent label = (JComponent) dictionary.get(key);
                label.setEnabled(enabled);

                if (label instanceof JLabel) {
                    Icon icon = label.isEnabled() ? ((JLabel) label).getIcon() : ((JLabel) label).getDisabledIcon();

                    if (icon instanceof ImageIcon) {
                        // Register Slider as an image observer. It allows to catch notifications about
                        // image changes (e.g. gif animation)
                        Toolkit.getDefaultToolkit().checkImage(((ImageIcon) icon).getImage(), -1, -1, slider);
                    }
                }

                if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
                    g.translate( 0, labelBounds.y );
                    paintHorizontalLabel( g, value, label );
                    g.translate( 0, -labelBounds.y );
                }
                else {
                    int offset = 0;
                    if (!BasicGraphicsUtils.isLeftToRight(slider)) {
                        offset = labelBounds.width -
                            label.getPreferredSize().width;
                    }
                    g.translate( labelBounds.x + offset, 0 );
                    paintVerticalLabel( g, value, label );
                    g.translate( -labelBounds.x - offset, 0 );
                }
            }
        }
    }

}
 
Example 20
Source File: SamsungTvBinding.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @{inheritDoc
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {

    if (config != null) {
        Enumeration<String> keys = config.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();

            // the config-key enumeration contains additional keys that we
            // don't want to process here ...
            if ("service.pid".equals(key)) {
                continue;
            }

            Matcher matcher = EXTRACT_TV_CONFIG_PATTERN.matcher(key);

            if (!matcher.matches()) {
                logger.debug(
                        "given config key '" + key + "' does not follow the expected pattern '<id>.<host|port>'");
                continue;
            }

            matcher.reset();
            matcher.find();

            String deviceId = matcher.group(1);

            DeviceConfig deviceConfig = deviceConfigCache.get(deviceId);

            if (deviceConfig == null) {
                deviceConfig = new DeviceConfig(deviceId);
                deviceConfigCache.put(deviceId, deviceConfig);
            }

            String configKey = matcher.group(2);
            String value = (String) config.get(key);

            if ("host".equals(configKey)) {
                deviceConfig.host = value;
            } else if ("port".equals(configKey)) {
                deviceConfig.port = Integer.valueOf(value);
            } else {
                throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown");
            }
        }
    }
}