Example #1
0
  @SuppressWarnings("deprecation")
  public final void runOneComponent(
      Component comp, Rectangle bounds, Graphics g, Shape clip, int weightFlags) {
    if (comp == null || comp.getPeer() == null || !comp.isVisible()) {
      return;
    }
    boolean lightweight = comp.isLightweight();
    if ((lightweight && (weightFlags & LIGHTWEIGHTS) == 0)
        || (!lightweight && (weightFlags & HEAVYWEIGHTS) == 0)) {
      return;
    }

    if (bounds == null) {
      bounds = comp.getBounds();
    }

    if (clip == null || clip.intersects(bounds)) {
      Graphics cg = g.create();
      try {
        constrainGraphics(cg, bounds);
        cg.setFont(comp.getFont());
        cg.setColor(comp.getForeground());
        if (cg instanceof Graphics2D) {
          ((Graphics2D) cg).setBackground(comp.getBackground());
        } else if (cg instanceof Graphics2Delegate) {
          ((Graphics2Delegate) cg).setBackground(comp.getBackground());
        }
        run(comp, cg);
      } finally {
        cg.dispose();
      }
    }
  }
  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();
   }
 }
Example #4
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);
 }
Example #5
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;
 }
  @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;
    }