public Component getTreeCellRendererComponent(
      JTree tree,
      Object value,
      boolean selected,
      boolean expanded,
      boolean leaf,
      int row,
      boolean hasFocus) {
    installMouseHandler();
    TreePath path = getPathForRow(row);
    state = UNCHECKABLE;
    if (path != null) {
      if (isChecked(path)) {
        state = FULLCHECKED;
      } else if (isPartiallyChecked(path)) {
        state = PARTIALCHECKED;
      } else if (isSelectable(path)) {
        state = UNCHECKED;
      }
    }
    checkBox.setSelected(state == FULLCHECKED);
    checkBox.getModel().setArmed(mouseRow == row && pressedRow == row && mouseInCheck);
    checkBox.getModel().setPressed(pressedRow == row && mouseInCheck);
    checkBox.getModel().setRollover(mouseRow == row && mouseInCheck);

    Component c =
        renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    checkBox.setForeground(c.getForeground());
    if (c instanceof JLabel) {
      JLabel label = (JLabel) c;
      // Augment the icon to include the checkbox
      setAppropriateLabelAndIcon(value, label, selected, expanded);
    }
    return c;
  }
Esempio n. 2
0
 /**
  * base interaction with list: renderer uses list's unselected colors
  *
  * <p>currently, this test fails because the assumptions are wrong! Core renderer behaves slightly
  * unexpected.
  */
 public void testTreeRendererExtColors() {
   // prepare standard
   Component coreComponent =
       coreTreeRenderer.getTreeCellRendererComponent(tree, null, false, false, false, 0, false);
   // sanity: known standard behaviour
   assertNull(coreComponent.getBackground());
   //        assertNull(coreComponent.getForeground());
   assertNull(tree.getForeground());
   Color uiForeground = UIManager.getColor("Tree.textForeground");
   assertEquals(uiForeground, coreComponent.getForeground());
   // prepare extended
   Component xComponent =
       xTreeRenderer.getTreeCellRendererComponent(tree, null, false, false, false, 0, false);
   // assert behaviour same as standard
   //        assertEquals(coreComponent.getBackground(), xComponent.getBackground());
   assertEquals(coreComponent.getForeground(), xComponent.getForeground());
 }
Esempio n. 3
0
 /**
  * base interaction with list: renderer uses list's unselected custom colors.
  *
  * <p>currently, this test fails because the assumptions are wrong! Core renderer behaves slightly
  * unexpected.
  */
 public void testTreeRendererExtTreeColors() {
   Color background = Color.MAGENTA;
   Color foreground = Color.YELLOW;
   tree.setBackground(background);
   tree.setForeground(foreground);
   coreTreeRenderer.setBackgroundNonSelectionColor(background);
   coreTreeRenderer.setTextNonSelectionColor(foreground);
   // prepare standard
   Component coreComponent =
       coreTreeRenderer.getTreeCellRendererComponent(tree, null, false, false, false, 0, false);
   // sanity: known standard behaviour
   // background is manually painted
   assertEquals(background, coreComponent.getBackground());
   assertEquals(tree.getForeground(), coreComponent.getForeground());
   // prepare extended
   Component xComponent =
       xTreeRenderer.getTreeCellRendererComponent(tree, null, false, false, false, 0, false);
   // assert behaviour same as standard
   assertEquals(background, xComponent.getBackground());
   assertEquals(foreground, xComponent.getForeground());
 }
  private VcsLogHighlighter.VcsCommitStyle getStyle(
      int row, int column, String text, boolean hasFocus, final boolean selected) {
    Component dummyRendererComponent =
        myDummyRenderer.getTableCellRendererComponent(this, text, selected, hasFocus, row, column);

    VisibleGraph<Integer> visibleGraph = getVisibleGraph();
    if (row < 0 || row >= visibleGraph.getVisibleCommitCount()) {
      LOG.error(
          "Visible graph has "
              + visibleGraph.getVisibleCommitCount()
              + " commits, yet we want row "
              + row);
      return VcsCommitStyleFactory.createStyle(
          dummyRendererComponent.getForeground(),
          dummyRendererComponent.getBackground(),
          VcsLogHighlighter.TextStyle.NORMAL);
    }

    final RowInfo<Integer> rowInfo = visibleGraph.getRowInfo(row);

    VcsLogHighlighter.VcsCommitStyle defaultStyle =
        VcsCommitStyleFactory.createStyle(
            rowInfo.getRowType() == RowType.UNMATCHED
                ? JBColor.GRAY
                : dummyRendererComponent.getForeground(),
            dummyRendererComponent.getBackground(),
            VcsLogHighlighter.TextStyle.NORMAL);

    List<VcsLogHighlighter.VcsCommitStyle> styles =
        ContainerUtil.map(
            myHighlighters,
            new Function<VcsLogHighlighter, VcsLogHighlighter.VcsCommitStyle>() {
              @Override
              public VcsLogHighlighter.VcsCommitStyle fun(VcsLogHighlighter highlighter) {
                return highlighter.getStyle(rowInfo.getCommit(), selected);
              }
            });

    return VcsCommitStyleFactory.combine(ContainerUtil.append(styles, defaultStyle));
  }
 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
   float size = this.stroke.getLineWidth();
   if (size > 0.0f) {
     g = g.create();
     if (g instanceof Graphics2D) {
       Graphics2D g2d = (Graphics2D) g;
       g2d.setStroke(this.stroke);
       g2d.setPaint(color != null ? color : c == null ? null : c.getForeground());
       g2d.draw(new Rectangle2D.Float(x + size / 2, y + size / 2, width - size, height - size));
     }
     g.dispose();
   }
 }
Esempio n. 6
0
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Color color = c.getForeground();
   Color saveColor = g.getColor();
   CRectangle bg = new CRectangle(x, y, width, height);
   bg.setFilled(false);
   bg.paint(g);
   polyline
       .setReferencePoint(0, 0)
       .translateTo(x + sideStartingPoint / 2 + 1, y + sideStartingPoint / 2 + 1);
   polyline.setOutlinePaint(color).setAntialiased(true);
   polyline.paint(g);
   startPoint.paint(g);
   g.setColor(saveColor);
 }
 @Override
 protected void applyForeground(Component renderer, ComponentAdapter adapter) {
   if (!adapter.isSelected()) {
     Object colorMemory =
         ((JComponent) renderer).getClientProperty("rendererColorMemory.foreground");
     if (colorMemory instanceof ColorMemory) {
       renderer.setForeground(((ColorMemory) colorMemory).color);
     } else {
       ((JComponent) renderer)
           .putClientProperty(
               "rendererColorMemory.foreground", new ColorMemory(renderer.getForeground()));
     }
   }
 }
Esempio n. 8
0
 public static BufferedImage componentToImage(Component component, Rectangle region) {
   BufferedImage img =
       new BufferedImage(
           component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
   Graphics g = img.getGraphics();
   g.setColor(component.getForeground());
   g.setFont(component.getFont());
   component.paintAll(g);
   g.dispose();
   if (region == null) {
     return img;
   }
   return img.getSubimage(region.x, region.y, region.width, region.height);
 }
Esempio n. 9
0
 /**
  * Draw the icon at the specified location. Icon implementations may use the Component argument to
  * get properties useful for painting, e.g. the foreground or background color.
  */
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Graphics2D g2 = (Graphics2D) g;
   Toolkit tk = Toolkit.getDefaultToolkit();
   Map<?, ?> map = (Map<?, ?>) (tk.getDesktopProperty("awt.font.desktophints"));
   if (map != null) {
     g2.addRenderingHints(map);
   }
   // We don't insist that it be on the same Component
   g2.setColor(c.getForeground());
   g2.setFont(c.getFont());
   if (fRotation == ROTATE_NONE) {
     int yPos = y + fCharHeight;
     for (int i = 0; i < fCharStrings.length; i++) {
       // Special rules for Japanese - "half-height" characters (like ya, yu, yo in combinations)
       // should draw in the top-right quadrant when drawn vertically
       // - they draw in the bottom-left normally
       int tweak;
       switch (fPosition[i]) {
         case POSITION_NORMAL:
           // Roman fonts should be centered. Japanese fonts are always monospaced.
           g2.drawString(fCharStrings[i], x + ((fWidth - fCharWidths[i]) / 2), yPos);
           break;
         case POSITION_TOP_RIGHT:
           tweak = fCharHeight / 3; // Should be 2, but they aren't actually half-height
           g2.drawString(fCharStrings[i], x + (tweak / 2), yPos - tweak);
           break;
         case POSITION_FAR_TOP_RIGHT:
           tweak = fCharHeight - fCharHeight / 3;
           g2.drawString(fCharStrings[i], x + (tweak / 2), yPos - tweak);
           break;
         default:
           throw new Error();
       }
       yPos += fCharHeight;
     }
   } else if (fRotation == ROTATE_LEFT) {
     g2.translate(x + fWidth, y + fHeight);
     g2.rotate(-NINETY_DEGREES);
     g2.drawString(fLabel, K_BUFFER_SPACE, -fDescent);
     g2.rotate(NINETY_DEGREES);
     g2.translate(-(x + fWidth), -(y + fHeight));
   } else if (fRotation == ROTATE_RIGHT) {
     g2.translate(x, y);
     g2.rotate(NINETY_DEGREES);
     g2.drawString(fLabel, K_BUFFER_SPACE, -fDescent);
     g2.rotate(-NINETY_DEGREES);
     g2.translate(-x, -y);
   }
 }
Esempio n. 10
0
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   Component comp =
       super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
   if (value != null && highlight(table, value, isSelected, hasFocus, row, column)) {
     if (isSelected) {
       comp.setBackground(new Color((HIGHLIGHT_COLOR.getRGB() ^ comp.getBackground().getRGB())));
       comp.setForeground(new Color(Color.BLACK.getRGB() ^ comp.getForeground().getRGB()));
     } else {
       comp.setBackground(HIGHLIGHT_COLOR);
       comp.setForeground(Color.BLACK);
     }
   } else {
     if (!isSelected) {
       comp.setBackground(Color.WHITE);
       comp.setForeground(Color.BLACK);
     }
   }
   return comp;
 }
Esempio n. 11
0
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    Color color = c.getForeground();
    g.setColor(color);

    // draw horizontal lines
    g.drawLine(x, y, x + 8, y);
    g.drawLine(x, y + 2, x + 8, y + 2);
    g.drawLine(x, y + 8, x + 2, y + 8);

    // draw vertical lines
    g.drawLine(x, y + 1, x, y + 7);
    g.drawLine(x + 4, y + 1, x + 4, y + 4);
    g.drawLine(x + 8, y + 1, x + 8, y + 4);

    // draw arrow
    g.drawLine(x + 3, y + 6, x + 9, y + 6);
    g.drawLine(x + 4, y + 7, x + 8, y + 7);
    g.drawLine(x + 5, y + 8, x + 7, y + 8);
    g.drawLine(x + 6, y + 9, x + 6, y + 9);
  }
Esempio n. 12
0
  /**
   * Constructs a Graphics context with the following graphics state:
   *
   * <UL>
   *   <LI>Paint: The color of the component.
   *   <LI>Font: The font of the component.
   *   <LI>Stroke: Linewidth 1.0; No Dashing; Miter Join Style; Miter Limit 10; Square Endcaps;
   *   <LI>Transform: The getDefaultTransform for the GraphicsConfiguration of the component.
   *   <LI>Composite: AlphaComposite.SRC_OVER
   *   <LI>Clip: The size of the component, Rectangle(0, 0, size.width, size.height)
   * </UL>
   *
   * @param component to be used to initialize the values of the graphics state
   * @param doRestoreOnDispose true if writeGraphicsRestore() should be called when this graphics
   *     context is disposed of.
   */
  protected AbstractVectorGraphicsIO(Component component, boolean doRestoreOnDispose) {
    super();

    this.size = component.getSize();
    this.component = component;
    this.doRestoreOnDispose = doRestoreOnDispose;

    deviceClip = (size != null ? new Rectangle(0, 0, size.width, size.height) : null);
    userClip = null;
    GraphicsConfiguration gc = component.getGraphicsConfiguration();
    currentTransform = (gc != null) ? gc.getDefaultTransform() : new AffineTransform();
    currentComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
    currentStroke =
        new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, null, 0.0f);

    super.setFont(component.getFont());
    super.setBackground(component.getBackground());
    super.setColor(component.getForeground());

    // Initialize the rendering hints.
    hints = new RenderingHints(null);
  }
  @Override
  public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    int titleHeight = getTitleHeight(c);

    // create image with vertical gradient and then use alpha composite to
    // render the image with a horizontal fade
    BufferedImage titleImage = Utilities.createTranslucentImage(width, titleHeight);
    GradientPaint gradient =
        new GradientPaint(
            0, 0, titleGradientColors[0], 0, titleHeight, titleGradientColors[1], false);
    Graphics2D g2 = (Graphics2D) titleImage.getGraphics();
    g2.setPaint(gradient);
    g2.fillRoundRect(x, y, width, height, 10, 10);
    g2.setColor(Utilities.deriveColorHSB(titleGradientColors[1], 0, 0, -.2f));
    g2.drawLine(x + 1, titleHeight - 1, width - 2, titleHeight - 1);
    g2.setColor(Utilities.deriveColorHSB(titleGradientColors[1], 0, -.5f, .5f));
    g2.drawLine(x + 1, titleHeight, width - 2, titleHeight);
    g2.setPaint(
        new GradientPaint(
            0, 0, new Color(0.0f, 0.0f, 0.0f, 1.0f), width, 0, new Color(0.0f, 0.0f, 0.0f, 0.0f)));
    g2.setComposite(AlphaComposite.DstIn);
    g2.fillRect(x, y, width, titleHeight);
    g2.dispose();

    g.drawImage(titleImage, x, y, c);

    // draw rounded border
    super.paintBorder(c, g, x, y, width, height);

    // draw title string
    g2 = (Graphics2D) g;
    g2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setColor(c.getForeground());
    g2.setFont(c.getFont());
    FontMetrics metrics = c.getFontMetrics(c.getFont());
    g2.drawString(title, x + 8, y + (titleHeight - metrics.getHeight()) / 2 + metrics.getAscent());
  }
    @Override
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      final Component orig =
          super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
      if (myPluginDescriptor != null) {
        myNameLabel.setText(myPluginDescriptor.getName());
        final PluginId pluginId = myPluginDescriptor.getPluginId();
        final String idString = pluginId.getIdString();
        if (myPluginDescriptor.isBundled()) {
          myBundledLabel.setText("Bundled");
        } else {
          final String host = myPlugin2host.get(idString);
          if (host != null) {
            String presentableUrl = VfsUtil.urlToPath(host);
            final int idx = presentableUrl.indexOf('/');
            if (idx > -1) {
              presentableUrl = presentableUrl.substring(0, idx);
            }
            myBundledLabel.setText("From " + presentableUrl);
          } else {
            if (PluginManagerUISettings.getInstance().getInstalledPlugins().contains(idString)) {
              myBundledLabel.setText("From repository");
            } else {
              myBundledLabel.setText("Custom");
            }
          }
        }
        if (myPluginDescriptor instanceof IdeaPluginDescriptorImpl
            && ((IdeaPluginDescriptorImpl) myPluginDescriptor).isDeleted()) {
          myNameLabel.setIcon(AllIcons.Actions.Clean);
        } else if (hasNewerVersion(pluginId)) {
          myNameLabel.setIcon(AllIcons.Nodes.Pluginobsolete);
          myPanel.setToolTipText("Newer version of the plugin is available");
        } else {
          myNameLabel.setIcon(AllIcons.Nodes.Plugin);
        }

        final Color fg = orig.getForeground();
        final Color bg = orig.getBackground();
        final Color grayedFg = isSelected ? fg : Color.GRAY;

        myPanel.setBackground(bg);
        myNameLabel.setBackground(bg);
        myBundledLabel.setBackground(bg);

        myNameLabel.setForeground(fg);
        final boolean wasUpdated = wasUpdated(pluginId);
        if (wasUpdated || PluginManager.getPlugin(pluginId) == null) {
          if (!isSelected) {
            myNameLabel.setForeground(FileStatus.COLOR_ADDED);
          }
          if (wasUpdated) {
            myPanel.setToolTipText(
                "Plugin was updated to the newest version. Changes will be available after restart");
          } else {
            myPanel.setToolTipText("Plugin will be activated after restart.");
          }
        }
        myBundledLabel.setForeground(grayedFg);

        final Set<PluginId> required = myDependentToRequiredListMap.get(pluginId);
        if (required != null && required.size() > 0) {
          myNameLabel.setForeground(Color.RED);

          final StringBuilder s = new StringBuilder();
          if (myEnabled.get(pluginId) == null) {
            s.append("Plugin was not loaded.\n");
          }
          if (required.contains(PluginId.getId("com.intellij.modules.ultimate"))) {
            s.append("The plugin requires IntelliJ IDEA Ultimate");
          } else {
            s.append("Required plugin").append(required.size() == 1 ? " \"" : "s \"");
            s.append(
                StringUtil.join(
                    required,
                    new Function<PluginId, String>() {
                      @Override
                      public String fun(final PluginId id) {
                        final IdeaPluginDescriptor plugin = PluginManager.getPlugin(id);
                        return plugin == null ? id.getIdString() : plugin.getName();
                      }
                    },
                    ","));

            s.append(required.size() == 1 ? "\" is not enabled!" : "\" are not enabled!");
          }
          myPanel.setToolTipText(s.toString());
        }

        if (PluginManager.isIncompatible(myPluginDescriptor)) {
          myPanel.setToolTipText(
              IdeBundle.message(
                  "plugin.manager.incompatible.tooltip.warning",
                  ApplicationNamesInfo.getInstance().getFullProductName()));
          myNameLabel.setForeground(Color.red);
        }
      }

      return myPanel;
    }
 /**
  * Returns the foreground color of the cell renderer for the given table cell.
  *
  * <p><b>Note:</b> This method is <b>not</b> executed in the event dispatch thread (EDT.) Clients
  * are responsible for invoking this method in the EDT.
  *
  * @param table the given <code>JTable</code>.
  * @param row the row index of the cell.
  * @param column the column index of the cell.
  * @return the foreground color of the cell renderer for the given table cell.
  */
 @RunsInCurrentThread
 public Color foregroundAt(JTable table, int row, int column) {
   Component c = cellRendererIn(table, row, column);
   return c != null ? c.getForeground() : null;
 }