/**
   * Implements the <tt>ListCellRenderer</tt> method. Returns this panel that has been configured to
   * display bundle name, version and description.
   *
   * @param table the parent table
   * @param value the value of the rendered cell
   * @param isSelected indicates if the rendered cell is selected
   * @param hasFocus indicates if the rendered cell has the focus
   * @param rowIndex the row index of the rendered cell
   * @param vColIndex the column index of the rendered cell
   * @return the rendering component
   */
  public Component getTableCellRendererComponent(
      JTable table,
      Object value,
      boolean isSelected,
      boolean hasFocus,
      int rowIndex,
      int vColIndex) {
    Bundle bundle = (Bundle) value;

    Dictionary<?, ?> headers = bundle.getHeaders();
    Object bundleName = headers.get(Constants.BUNDLE_NAME);
    Object bundleVersion = headers.get(Constants.BUNDLE_VERSION);
    Object bundleDescription = headers.get(Constants.BUNDLE_DESCRIPTION);

    Icon stateIcon = getStateIcon(bundle.getState());

    if (bundleName != null) this.nameLabel.setText(bundleName.toString());
    else this.nameLabel.setText("unknown");

    if (bundleVersion != null) this.versionLabel.setText(bundleVersion.toString());
    else this.versionLabel.setText("");

    if (bundleDescription != null) this.descriptionLabel.setText(bundleDescription.toString());
    else this.descriptionLabel.setText("");

    if (stateIcon != null) this.stateLabel.setIcon(stateIcon);

    this.nameVersionPanel.remove(systemLabel);

    if (PluginManagerActivator.isSystemBundle(bundle)) this.nameVersionPanel.add(systemLabel);

    this.isSelected = isSelected;

    return this;
  }
Esempio n. 2
0
 private void updateLabelSizes() {
   Dictionary labelTable = getLabelTable();
   if (labelTable != null) {
     Enumeration labels = labelTable.elements();
     while (labels.hasMoreElements()) {
       JComponent component = (JComponent) labels.nextElement();
       component.setSize(component.getPreferredSize());
     }
   }
 }
Esempio n. 3
0
  /**
   * Updates the UIs for the labels in the label table by calling {@code updateUI} on each label.
   * The UIs are updated from the current look and feel. The labels are also set to their preferred
   * size.
   *
   * @see #setLabelTable
   * @see JComponent#updateUI
   */
  protected void updateLabelUIs() {
    Dictionary labelTable = getLabelTable();

    if (labelTable == null) {
      return;
    }
    Enumeration labels = labelTable.keys();
    while (labels.hasMoreElements()) {
      JComponent component = (JComponent) labelTable.get(labels.nextElement());
      component.updateUI();
      component.setSize(component.getPreferredSize());
    }
  }
Esempio n. 4
0
  /**
   * {@inheritDoc}
   *
   * @since 1.7
   */
  public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
    if (!isShowing()) {
      return false;
    }

    // Check that there is a label with such image
    Enumeration elements = labelTable.elements();

    while (elements.hasMoreElements()) {
      Component component = (Component) elements.nextElement();

      if (component instanceof JLabel) {
        JLabel label = (JLabel) component;

        if (SwingUtilities.doesIconReferenceImage(label.getIcon(), img)
            || SwingUtilities.doesIconReferenceImage(label.getDisabledIcon(), img)) {
          return super.imageUpdate(img, infoflags, x, y, w, h);
        }
      }
    }

    return false;
  }
Esempio n. 5
0
  public SliderTestFrame() {
    setTitle("SliderTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    sliderPanel = new JPanel();
    sliderPanel.setLayout(new FlowLayout(FlowLayout.LEFT));

    // common listener for all sliders
    listener =
        new ChangeListener() {
          public void stateChanged(ChangeEvent event) {
            // update text field when the slider value changes
            JSlider source = (JSlider) event.getSource();
            textField.setText("" + source.getValue());
          }
        };

    // add a plain slider

    JSlider slider = new JSlider();
    addSlider(slider, "Plain");

    // add a slider with major and minor ticks

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);
    addSlider(slider, "Ticks");

    // add a slider that snaps to ticks

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setSnapToTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);
    addSlider(slider, "Snap to ticks");

    // add a slider with no track

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);
    slider.setPaintTrack(false);
    addSlider(slider, "No track");

    // add an inverted slider

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);
    slider.setInverted(true);
    addSlider(slider, "Inverted");

    // add a slider with numeric labels

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);
    addSlider(slider, "Labels");

    // add a slider with alphabetic labels

    slider = new JSlider();
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);

    Dictionary<Integer, Component> labelTable = new Hashtable<Integer, Component>();
    labelTable.put(0, new JLabel("A"));
    labelTable.put(20, new JLabel("B"));
    labelTable.put(40, new JLabel("C"));
    labelTable.put(60, new JLabel("D"));
    labelTable.put(80, new JLabel("E"));
    labelTable.put(100, new JLabel("F"));

    slider.setLabelTable(labelTable);
    addSlider(slider, "Custom labels");

    // add a slider with icon labels

    slider = new JSlider();
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    slider.setSnapToTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(20);

    labelTable = new Hashtable<Integer, Component>();

    // add card images

    labelTable.put(0, new JLabel(new ImageIcon("nine.gif")));
    labelTable.put(20, new JLabel(new ImageIcon("ten.gif")));
    labelTable.put(40, new JLabel(new ImageIcon("jack.gif")));
    labelTable.put(60, new JLabel(new ImageIcon("queen.gif")));
    labelTable.put(80, new JLabel(new ImageIcon("king.gif")));
    labelTable.put(100, new JLabel(new ImageIcon("ace.gif")));

    slider.setLabelTable(labelTable);
    addSlider(slider, "Icon labels");

    // add the text field that displays the slider value

    textField = new JTextField();
    add(sliderPanel, BorderLayout.CENTER);
    add(textField, BorderLayout.SOUTH);
  }