/**
     * Return a component that has been configured to display the specified value.
     *
     * @param list The JList we're painting.
     * @param value The value returned by list.getModel().getElementAt(index).
     * @param index The cells index.
     * @param isSelected True if the specified cell was selected.
     * @param cellHasFocus True if the specified cell has the focus.
     * @return A component whose paint() method will render the specified value.
     * @todo Implement this javax.swing.ListCellRenderer method
     */
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      HostItem hi = (HostItem) value;
      JLabel c = new JLabel(hi.name);
      if (isSelected && hi.eavesDroppingEnabled) {
        c.setBackground(Color.magenta);
        c.setForeground(list.getSelectionForeground());
      } else if (!isSelected && hi.eavesDroppingEnabled) {
        c.setBackground(Color.red);
        c.setForeground(list.getForeground());
      } else if (isSelected) {
        c.setBackground(list.getSelectionBackground());
        c.setForeground(list.getSelectionForeground());
      } else {
        c.setBackground(list.getBackground());
        c.setForeground(list.getForeground());
      }

      c.setEnabled(list.isEnabled());
      c.setFont(list.getFont());
      c.setOpaque(true);

      return c;
    }
  /**
   * Does Nothing
   *
   * @param selected, true to enable, false to disable.
   */
  public void setNodeOrLinkSelected(boolean selected) {
    if (tbrToolBar != null) {

      UIViewFrame frame = ProjectCompendium.APP.getCurrentFrame();
      if (selected && frame instanceof UIMapViewFrame) {
        UIMapViewFrame oMapFrame = (UIMapViewFrame) frame;
        UIViewPane pane = oMapFrame.getViewPane();

        int nLinkCount = pane.getNumberOfSelectedLinks();
        if (nLinkCount == 0) return;

        bJustSetting = true;

        int i = 0;
        UILink link = null;
        LinkProperties linkProps = null;
        boolean bDefaultLinkStyle = false;
        boolean bDefaultLinkDashed = false;
        boolean bDefaultLinkWeight = false;
        boolean bDefaultLinkColour = false;
        boolean bDefaultArrowType = false;

        LinkProperties defaultprops = UIUtilities.getLinkProperties("");
        int linkstyle = defaultprops.getLinkStyle();
        int linkdashed = defaultprops.getLinkDashed();
        int linkweight = defaultprops.getLinkWeight();
        int linkcolour = defaultprops.getLinkColour();
        int arrowtype = defaultprops.getArrowType();

        for (Enumeration e = pane.getSelectedLinks(); e.hasMoreElements(); ) {
          link = (UILink) e.nextElement();
          linkProps = link.getLinkProperties();
          if (i == 0) {
            linkstyle = linkProps.getLinkStyle();
            linkdashed = linkProps.getLinkDashed();
            linkweight = linkProps.getLinkWeight();
            linkcolour = linkProps.getLinkColour();
            arrowtype = linkProps.getArrowType();
            i++;
          } else {
            if (arrowtype != linkProps.getArrowType()) {
              bDefaultArrowType = true;
            }
            if (linkstyle != linkProps.getLinkStyle()) {
              bDefaultLinkStyle = true;
            }
            if (linkdashed != linkProps.getLinkDashed()) {
              bDefaultLinkDashed = true;
            }
            if (linkweight != linkProps.getLinkWeight()) {
              bDefaultLinkWeight = true;
            }
            if (linkcolour != linkProps.getLinkColour()) {
              bDefaultLinkColour = true;
            }
          }
        }

        tbrToolBar.setEnabled(true);

        if (bDefaultLinkColour) {
          selectedLinkColour = new Color(defaultprops.getLinkColour());
        } else {
          selectedLinkColour = new Color(linkcolour);
        }

        linkColourPanel.setEnabled(true);
        txtLinkColour.setEnabled(true);

        cbLineWeight.setEnabled(true);
        if (bDefaultLinkWeight) {
          cbLineWeight.setSelectedIndex(defaultprops.getLinkWeight() - 1);
        } else {
          cbLineWeight.setSelectedIndex(linkweight - 1);
        }

        cbArrows.setEnabled(true);
        if (bDefaultArrowType) {
          cbArrows.setSelectedIndex(defaultprops.getArrowType());
        } else {
          cbArrows.setSelectedIndex(arrowtype);
        }

        cbLinkStyle.setEnabled(true);
        if (bDefaultLinkStyle) {
          cbLinkStyle.setSelectedIndex(defaultprops.getLinkStyle());
        } else {
          cbLinkStyle.setSelectedIndex(linkstyle);
        }

        cbLinkDashed.setEnabled(true);
        if (bDefaultLinkDashed) {
          cbLinkDashed.setSelectedIndex(defaultprops.getLinkDashed());
        } else {
          cbLinkDashed.setSelectedIndex(linkdashed);
        }

        bJustSetting = false;

      } else if (!selected) {

        bJustSetting = true;

        linkColourPanel.setEnabled(false);
        txtLinkColour.setEnabled(false);
        tbrToolBar.setEnabled(false);
        cbArrows.setEnabled(false);
        cbLineWeight.setEnabled(false);
        cbLinkStyle.setEnabled(false);
        cbLinkDashed.setEnabled(false);

        bJustSetting = false;
      }
    }
  }
  /**
   * Create and return the toolbar with the node formatting options.
   *
   * @return UIToolBar, the toolbar with all the node formatting options.
   */
  private UIToolBar createToolBar(int orientation) {

    tbrToolBar =
        new UIToolBar(
            LanguageProperties.getString(
                LanguageProperties.TOOLBARS_BUNDLE, "UIToolBarFormatLink.name"),
            UIToolBar.NORTHSOUTH); // $NON-NLS-1$
    tbrToolBar.setOrientation(orientation);
    tbrToolBar.setEnabled(false);
    CSH.setHelpIDString(tbrToolBar, "toolbars.formatlink"); // $NON-NLS-1$

    GridBagLayout grid = new GridBagLayout();
    linkPanel = new JPanel(grid);
    linkColourPanel = new JPanel(new BorderLayout());
    linkColourPanel.setBackground(Color.black);

    JLabel label = new JLabel(" "); // $NON-NLS-1$
    GridBagConstraints con5 = new GridBagConstraints();
    con5.fill = GridBagConstraints.NONE;
    con5.anchor = GridBagConstraints.CENTER;
    grid.addLayoutComponent(label, con5);
    linkPanel.add(label);

    txtLinkColour = new JLabel(UIImages.get(BACKGROUND_COLOUR));
    txtLinkColour.setBorder(null);
    txtLinkColour.setToolTipText(
        LanguageProperties.getString(
            LanguageProperties.TOOLBARS_BUNDLE,
            "UIToolBarFormatLink.selectLinkColour")); //$NON-NLS-1$
    txtLinkColour.setEnabled(false);
    txtLinkColour.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            int clickCount = e.getClickCount();
            if (clickCount == 1 && txtLinkColour.isEnabled()) {
              onUpdateLinkColour(linkColourPanel.getBackground().getRGB());
            }
          }
        });
    linkColourPanel.add(txtLinkColour, BorderLayout.CENTER);

    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.NONE;
    con.anchor = GridBagConstraints.CENTER;
    grid.addLayoutComponent(linkColourPanel, con);
    linkPanel.add(linkColourPanel);

    btLinkColour = new UIImageButton(UIImages.get(RIGHT_ARROW_ICON));
    btLinkColour.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            int clickCount = e.getClickCount();
            if (clickCount == 1 && txtLinkColour.isEnabled()) {
              if (oColorChooserDialog != null) {
                oColorChooserDialog.setColour(selectedLinkColour);
              } else {
                oColorChooserDialog =
                    new UIColorChooserDialog(ProjectCompendium.APP, selectedLinkColour);
              }
              oColorChooserDialog.setVisible(true);
              Color oColour = oColorChooserDialog.getColour();
              oColorChooserDialog.setVisible(false);
              if (oColour != null) {
                linkColourPanel.setBackground(oColour);
                onUpdateLinkColour(oColour.getRGB());
              }
            }
          }
        });
    linkPanel.add(btLinkColour);

    label = new JLabel(" "); // $NON-NLS-1$
    GridBagConstraints con4 = new GridBagConstraints();
    con4.fill = GridBagConstraints.NONE;
    con4.anchor = GridBagConstraints.CENTER;
    grid.addLayoutComponent(label, con4);
    linkPanel.add(label);

    tbrToolBar.add(linkPanel);
    CSH.setHelpIDString(txtLinkColour, "toolbars.formatlink"); // $NON-NLS-1$

    tbrToolBar.add(createWeightChoiceBox());
    tbrToolBar.add(createArrowChoiceBox());
    tbrToolBar.add(createLinkStyleChoiceBox());
    tbrToolBar.add(createLinkDashedChoiceBox());

    return tbrToolBar;
  }
Beispiel #4
0
  public Component getTableCellRendererComponent(
      JTable table,
      Setting owner,
      Object value,
      boolean isSelected,
      boolean hasFocus,
      boolean isEnabled,
      int row,
      int column) {
    // renderer.setMargin(new Insets(0, 2, 4, 2));

    if (isSelected) {
      renderer.setForeground(table.getSelectionForeground());
      panel.setBackground(table.getSelectionBackground());
      blank1.setBackground(table.getSelectionBackground());
      blank2.setBackground(table.getSelectionBackground());
    } else {
      renderer.setForeground(table.getForeground());
      panel.setBackground(table.getBackground());
      blank1.setBackground(table.getBackground());
      blank2.setBackground(table.getBackground());
    }

    if (hasFocus) {
      panel.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
    } else {
      panel.setBorder(new EmptyBorder(1, 2, 2, 1));
    }

    if (value instanceof Color) {
      Color col = (Color) value;

      // System.out.println("setting background to "+col.toString());

      renderer.setText("[" + col.getRed() + "," + col.getGreen() + "," + col.getBlue() + "]");

      renderer.setEnabled(isEnabled);

      renderer.setFont(font);

      colourPanel.setBackground(col);
    } else if (value instanceof ArrayList) {
      ArrayList values = (ArrayList) value;
      if (values.size() > 0) {
        // if we have multiple properties selected.
        Color last = null;
        boolean allSame = true;
        for (int i = 0; i < values.size(); i++) {
          if (values.get(i) instanceof Color) {
            Color str = (Color) values.get(i);
            if (last != null) {
              if (!str.equals(last)) {
                allSame = false;
                break;
              }
              last = str;
            } else {
              last = str;
            }
          }
        }
        if (allSame) {
          renderer.setText(
              "[" + last.getRed() + "," + last.getGreen() + "," + last.getBlue() + "]");

          renderer.setEnabled(isEnabled);

          renderer.setFont(font);

          colourPanel.setBackground(last);
        } else {
          renderer.setText("(Different values)");

          renderer.setEnabled(isEnabled);

          renderer.setFont(font);

          colourPanel.setBackground(Color.lightGray);
          panel.setBackground(Color.lightGray);
          blank1.setBackground(Color.lightGray);
          blank2.setBackground(Color.lightGray);
        }
      }
    }

    return panel;
  }