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

The following examples show how to use java.util.Dictionary#elements() . 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: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private static JSlider makeSlider(String title) {
  JSlider slider = new JSlider(0, 100, 40);
  slider.setBorder(BorderFactory.createTitledBorder(title));
  slider.setMajorTickSpacing(10);
  slider.setPaintTicks(true);
  slider.setPaintLabels(true);
  Dictionary<?, ?> dictionary = slider.getLabelTable();
  if (Objects.nonNull(dictionary)) {
    Enumeration<?> elements = dictionary.elements();
    while (elements.hasMoreElements()) {
      JLabel label = (JLabel) elements.nextElement();
      int v = Integer.parseInt(label.getText());
      if (v > MAXI || v < MINI) {
        label.setForeground(Color.RED);
      }
    }
  }
  slider.getModel().addChangeListener(e -> {
    BoundedRangeModel m = (BoundedRangeModel) e.getSource();
    m.setValue(Math.max(MINI, Math.min(m.getValue(), MAXI)));
  });
  return slider;
}
 
Example 2
Source File: DarkSliderUI.java    From darklaf with MIT License 6 votes vote down vote up
public Dimension getPreferredHorizontalSize() {
    Dimension dim = super.getPreferredHorizontalSize();
    Rectangle rect = new Rectangle(0, 0, 0, 0);
    rect.setSize(dim);
    adjustRect(rect, true);
    Dictionary<?, ?> dict = slider.getLabelTable();
    if (dict != null && !dict.isEmpty()) {
        int totalLabelWidth = 0;
        Enumeration<?> labels = dict.elements();
        while (labels.hasMoreElements()) {
            Object obj = labels.nextElement();
            if (obj instanceof Component) {
                totalLabelWidth += ((Component) obj).getPreferredSize().width;
            }
        }
        totalLabelWidth += getThumbWidth();
        rect.width = Math.max(rect.width, totalLabelWidth);
    }
    return rect.getSize();
}
 
Example 3
Source File: BasicSliderUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 4
Source File: BasicSliderUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 5
Source File: BasicSliderUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 6
Source File: RequestImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Cookie[] getCookies()
{
  Dictionary<String, Cloneable> d;
  if (cookies == null && !(d = base.getCookies()).isEmpty()) {
    cookies = new Cookie[d.size()];
    final Enumeration<Cloneable> e = d.elements();
    for (int i = 0; i < cookies.length; i++) {
      cookies[i] = (Cookie) e.nextElement();
    }
  }

  return cookies;
}
 
Example 7
Source File: BasicSliderUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 8
Source File: BasicSliderUI.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 9
Source File: BasicSliderUI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 10
Source File: BasicSliderUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 11
Source File: BasicSliderUI.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 12
Source File: BasicSliderUI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        @SuppressWarnings("rawtypes")
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration<?> elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 13
Source File: BasicSliderUI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        @SuppressWarnings("rawtypes")
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration<?> elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 14
Source File: BasicSliderUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 15
Source File: BasicSliderUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 16
Source File: BasicSliderUI.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 17
Source File: BasicSliderUI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 18
Source File: BasicSliderUI.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 19
Source File: BasicSliderUI.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}
 
Example 20
Source File: BasicSliderUI.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if all the labels from the label table have the same
 * baseline.
 *
 * @return true if all the labels from the label table have the
 *         same baseline
 * @since 1.6
 */
protected boolean labelsHaveSameBaselines() {
    if (!checkedLabelBaselines) {
        checkedLabelBaselines = true;
        Dictionary dictionary = slider.getLabelTable();
        if (dictionary != null) {
            sameLabelBaselines = true;
            Enumeration elements = dictionary.elements();
            int baseline = -1;
            while (elements.hasMoreElements()) {
                JComponent label = (JComponent) elements.nextElement();
                Dimension pref = label.getPreferredSize();
                int labelBaseline = label.getBaseline(pref.width,
                                                      pref.height);
                if (labelBaseline >= 0) {
                    if (baseline == -1) {
                        baseline = labelBaseline;
                    }
                    else if (baseline != labelBaseline) {
                        sameLabelBaselines = false;
                        break;
                    }
                }
                else {
                    sameLabelBaselines = false;
                    break;
                }
            }
        }
        else {
            sameLabelBaselines = false;
        }
    }
    return sameLabelBaselines;
}