Example #1
0
 public void paintBackground(Graphics g, JComponent c) {
   if (c.isOpaque()) {
     if (c.getBackground() instanceof ColorUIResource) {
       g.setColor(AbstractLookAndFeel.getBackgroundColor());
     } else {
       g.setColor(c.getBackground());
     }
     g.fillRect(0, 0, c.getWidth(), c.getHeight());
   }
 }
 public void paintBackground(Graphics g, JComponent c) {
   if (c.isOpaque()) {
     if ((c.getBackground().equals(AbstractLookAndFeel.getBackgroundColor()))
         && (c.getBackground() instanceof ColorUIResource)) {
       HiFiUtils.fillComponent(g, c);
     } else {
       g.setColor(c.getBackground());
       g.fillRect(0, 0, c.getWidth(), c.getHeight());
     }
   }
 }
  public void paint(Graphics g, JComponent c) {
    Dimension s = c.getSize();
    if (WindowsMenuItemUI.isVistaPainting()) {
      int x = 1;
      Component parent = c.getParent();
      if (parent instanceof JComponent) {
        Object gutterOffsetObject =
            ((JComponent) parent).getClientProperty(WindowsPopupMenuUI.GUTTER_OFFSET_KEY);
        if (gutterOffsetObject instanceof Integer) {
          /*
           * gutter offset is in parent's coordinates.
           * See comment in
           * WindowsPopupMenuUI.getTextOffset(JComponent)
           */
          x = ((Integer) gutterOffsetObject).intValue() - c.getX();
          x += WindowsPopupMenuUI.getGutterWidth();
        }
      }
      Skin skin = XPStyle.getXP().getSkin(c, Part.MP_POPUPSEPARATOR);
      int skinHeight = skin.getHeight();
      int y = (s.height - skinHeight) / 2;
      skin.paintSkin(g, x, y, s.width - x - 1, skinHeight, State.NORMAL);
    } else {
      int y = s.height / 2;
      g.setColor(c.getForeground());
      g.drawLine(1, y - 1, s.width - 2, y - 1);

      g.setColor(c.getBackground());
      g.drawLine(1, y, s.width - 2, y);
    }
  }
Example #4
0
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   JComponent c =
       (JComponent)
           render.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
   c.setBorder(null);
   JCheckBox lab = new JCheckBox();
   ListElement le = (ListElement) value;
   // if("r1-print".equals(le.getCategory()))
   //
   // lab.setIcon(ResourceManager.getIcon(com.kingdee.bos.ctrl.report.forapp.kdnote.client.ui.NoteFileDialogEx.class, "res.r1_print.gif"));
   // else
   //
   // lab.setIcon(ResourceManager.getIcon(com.kingdee.bos.ctrl.report.forapp.kdnote.client.ui.NoteFileDialogEx.class, "res/empty.gif"));
   lab.setSelected(le.isSelected());
   lab.setOpaque(true);
   lab.setBackground(c.getBackground());
   TableLayout tl = TableLayout.splitCol(2);
   tl.colStyle(0).setWidth(22);
   tl.colStyle(1).setPriX(1);
   KDPanel pan = new KDPanel(tl);
   pan.add(lab, tl.cell(0));
   pan.add(c, tl.cell(1));
   return pan;
 }
Example #5
0
    QuickDocInfoPane(
        @NotNull PsiElement documentationAnchor,
        @NotNull PsiElement elementUnderMouse,
        @NotNull JComponent baseDocControl) {
      myBaseDocControl = baseDocControl;

      PresentationFactory presentationFactory = new PresentationFactory();
      for (AbstractDocumentationTooltipAction action : ourTooltipActions) {
        Icon icon = action.getTemplatePresentation().getIcon();
        Dimension minSize = new Dimension(icon.getIconWidth(), icon.getIconHeight());
        myButtons.add(
            new ActionButton(
                action,
                presentationFactory.getPresentation(action),
                IdeTooltipManager.IDE_TOOLTIP_PLACE,
                minSize));
        action.setDocInfo(documentationAnchor, elementUnderMouse);
      }
      Collections.reverse(myButtons);

      setPreferredSize(baseDocControl.getPreferredSize());
      setMaximumSize(baseDocControl.getMaximumSize());
      setMinimumSize(baseDocControl.getMinimumSize());
      setBackground(baseDocControl.getBackground());

      add(baseDocControl, Integer.valueOf(0));
      int minWidth = 0;
      int minHeight = 0;
      int buttonWidth = 0;
      for (JComponent button : myButtons) {
        button.setBorder(null);
        button.setBackground(baseDocControl.getBackground());
        add(button, Integer.valueOf(1));
        button.setVisible(false);
        Dimension preferredSize = button.getPreferredSize();
        minWidth += preferredSize.width;
        minHeight = Math.max(minHeight, preferredSize.height);
        buttonWidth = Math.max(buttonWidth, preferredSize.width);
      }
      myButtonWidth = buttonWidth;

      int margin = 2;
      myMinWidth = minWidth + margin * 2 + (myButtons.size() - 1) * BUTTON_HGAP;
      myMinHeight = minHeight + margin * 2;
    }
Example #6
0
 private void drawLine(JComponent c, int x, int y) {
   _xedit = x;
   _yedit = y;
   Graphics g = c.getGraphics();
   g.setColor(Color.BLACK);
   g.setXORMode(c.getBackground());
   g.drawLine(_xdown, _ydown, _xedit, _yedit);
   g.dispose();
 }
  @NotNull
  private JComponent createHintComponent(
      @NotNull String text,
      @NotNull final FindUsagesHandler handler,
      @NotNull final RelativePoint popupPosition,
      final Editor editor,
      @NotNull final Runnable cancelAction,
      final int maxUsages,
      @NotNull final FindUsagesOptions options) {
    JComponent label =
        HintUtil.createInformationLabel(suggestSecondInvocation(options, handler, text + " "));
    InplaceButton button =
        createSettingsButton(handler, popupPosition, editor, maxUsages, cancelAction);

    JPanel panel =
        new JPanel(new BorderLayout()) {
          @Override
          public void addNotify() {
            mySearchEverywhereRunnable =
                new Runnable() {
                  @Override
                  public void run() {
                    searchEverywhere(options, handler, editor, popupPosition, maxUsages);
                  }
                };
            super.addNotify();
          }

          @Override
          public void removeNotify() {
            mySearchEverywhereRunnable = null;
            super.removeNotify();
          }
        };
    button.setBackground(label.getBackground());
    panel.setBackground(label.getBackground());
    label.setOpaque(false);
    label.setBorder(null);
    panel.setBorder(HintUtil.createHintBorder());
    panel.add(label, BorderLayout.CENTER);
    panel.add(button, BorderLayout.EAST);
    return panel;
  }
 public void update(Graphics g, JComponent c) {
   if (c.isOpaque()) {
     g.setColor(c.getBackground());
     g.fillRect(0, 0, c.getWidth(), c.getHeight());
     if (isToolBarComboBox(c)) {
       c.setOpaque(false);
     }
   }
   paint(g, c);
 }
Example #9
0
  @Override
  public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
    final Component result = super.prepareRenderer(renderer, row, column);
    final boolean selected =
        myExpandableItemsHandler.getExpandedItems().contains(new TableCell(row, column));

    // Fix GTK background
    if (UIUtil.isUnderGTKLookAndFeel()) {
      UIUtil.changeBackGround(this, UIUtil.getTreeTextBackground());
    }

    if (isTableDecorationSupported() && isStriped() && result instanceof JComponent) {
      final Color bg = row % 2 == 1 ? getBackground() : DECORATED_ROW_BG_COLOR;
      final JComponent c = (JComponent) result;
      final boolean cellSelected = isCellSelected(row, column);
      if (!cellSelected || (!hasFocus() && !getSelectionBackground().equals(c.getBackground()))) {
        c.setOpaque(true);
        c.setBackground(bg);
        for (Component child : c.getComponents()) {
          child.setBackground(bg);
        }
      }
    }

    if (!selected) return result;

    return new JComponent() {
      {
        add(result);
        setOpaque(false);
        setLayout(
            new AbstractLayoutManager() {
              @Override
              public Dimension preferredLayoutSize(Container parent) {
                return result.getPreferredSize();
              }

              @Override
              public void layoutContainer(Container parent) {
                Dimension size = parent.getSize();
                Insets i = parent.getInsets();
                Dimension pref = result.getPreferredSize();
                result.setBounds(
                    i.left,
                    i.top,
                    Math.max(pref.width, size.width - i.left - i.right),
                    size.height - i.top - i.bottom);
              }
            });
      }
    };
  }
Example #10
0
  @Override
  public Color getColor(SynthContext context, ColorType type) {
    JComponent c = context.getComponent();
    Region id = context.getRegion();
    int state = context.getComponentState();

    if (c.getName() == "Table.cellRenderer") {
      if (type == ColorType.BACKGROUND) {
        return c.getBackground();
      }
      if (type == ColorType.FOREGROUND) {
        return c.getForeground();
      }
    }

    if (id == Region.LABEL && type == ColorType.TEXT_FOREGROUND) {
      type = ColorType.FOREGROUND;
    }

    // For the enabled state, prefer the widget's colors
    if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) {
      if (type == ColorType.BACKGROUND) {
        return c.getBackground();
      } else if (type == ColorType.FOREGROUND) {
        return c.getForeground();
      } else if (type == ColorType.TEXT_FOREGROUND) {
        // If getForeground returns a non-UIResource it means the
        // developer has explicitly set the foreground, use it over
        // that of TEXT_FOREGROUND as that is typically the expected
        // behavior.
        Color color = c.getForeground();
        if (color != null && !(color instanceof UIResource)) {
          return color;
        }
      }
    }
    return getColorForState(context, type);
  }
Example #11
0
  /**
   * Returns the color for the specified state.
   *
   * @param context SynthContext identifying requestor
   * @param state to get the color for
   * @param type of the color
   * @return Color to render with
   */
  Color getGTKColor(SynthContext context, int state, ColorType type) {
    if (context != null) {
      JComponent c = context.getComponent();
      Region id = context.getRegion();

      state = GTKLookAndFeel.synthStateToGTKState(id, state);
      if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) {
        if (type == ColorType.BACKGROUND || type == ColorType.TEXT_BACKGROUND) {
          Color bg = c.getBackground();
          if (!(bg instanceof UIResource)) {
            return bg;
          }
        } else if (type == ColorType.FOREGROUND || type == ColorType.TEXT_FOREGROUND) {
          Color fg = c.getForeground();
          if (!(fg instanceof UIResource)) {
            return fg;
          }
        }
      }
    }

    return getStyleSpecificColor(context, state, type);
  }
Example #12
0
 /**
  * If necessary paints the background of the component, then invokes <code>paint</code>.
  *
  * @param g Graphics to paint to
  * @param c JComponent painting on
  * @throws NullPointerException if <code>g</code> or <code>c</code> is null
  * @see javax.swing.plaf.ComponentUI#update
  * @see javax.swing.plaf.ComponentUI#paint
  * @since 1.5
  */
 public void update(Graphics g, JComponent c) {
   AbstractButton button = (AbstractButton) c;
   if ((c.getBackground() instanceof UIResource)
       && button.isContentAreaFilled()
       && c.isEnabled()) {
     ButtonModel model = button.getModel();
     if (!MetalUtils.isToolBarButton(c)) {
       if (!model.isArmed()
           && !model.isPressed()
           && MetalUtils.drawGradient(
               c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) {
         paint(g, c);
         return;
       }
     } else if (model.isRollover()
         && MetalUtils.drawGradient(
             c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) {
       paint(g, c);
       return;
     }
   }
   super.update(g, c);
 }
  public void paint(final Graphics g, final JComponent c) {
    final AnchoredButton button = (AnchoredButton) c;

    final String text = button.getText();
    final Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return;
    }

    final FontMetrics fm = button.getFontMetrics(button.getFont());
    ourViewInsets = c.getInsets(ourViewInsets);

    ourViewRect.x = ourViewInsets.left;
    ourViewRect.y = ourViewInsets.top;

    final ToolWindowAnchor anchor = button.getAnchor();

    // Use inverted height & width
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      ourViewRect.height = c.getWidth() - (ourViewInsets.left + ourViewInsets.right);
      ourViewRect.width = c.getHeight() - (ourViewInsets.top + ourViewInsets.bottom);
    } else {
      ourViewRect.height = c.getHeight() - (ourViewInsets.left + ourViewInsets.right);
      ourViewRect.width = c.getWidth() - (ourViewInsets.top + ourViewInsets.bottom);
    }

    ourIconRect.x = ourIconRect.y = ourIconRect.width = ourIconRect.height = 0;
    ourTextRect.x = ourTextRect.y = ourTextRect.width = ourTextRect.height = 0;

    final String clippedText =
        SwingUtilities.layoutCompoundLabel(
            c,
            fm,
            text,
            icon,
            button.getVerticalAlignment(),
            button.getHorizontalAlignment(),
            button.getVerticalTextPosition(),
            button.getHorizontalTextPosition(),
            ourViewRect,
            ourIconRect,
            ourTextRect,
            button.getText() == null ? 0 : button.getIconTextGap());

    // Paint button's background

    final Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    final ButtonModel model = button.getModel();

    final Color background = button.getBackground();

    Color toBorder = model.isRollover() ? new Color(0, 0, 0, 50) : null;
    final boolean vertical = anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT;

    if (model.isArmed() && model.isPressed() || model.isSelected()) {
      g2.setColor(new Color(0, 0, 0, 30));
      g2.fillRect(3, 3, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6);

      g2.setColor(new Color(0, 0, 0, 120));
      g2.drawLine(2, 2, 3 + button.getWidth() - (vertical ? 7 : 6), 2);
      g2.drawLine(2, 3, 2, 3 + button.getHeight() - 7);

      g2.setColor(new Color(0, 0, 0, 40));
      g2.drawRect(3, 3, button.getWidth() - (vertical ? 7 : 6), button.getHeight() - 7);

      g2.setColor(new Color(255, 255, 255, 110));
      g2.drawLine(
          3,
          button.getHeight() - 3,
          3 + button.getWidth() - (vertical ? 6 : 5),
          button.getHeight() - 3);
      g2.drawLine(
          3 + button.getWidth() - (vertical ? 6 : 5),
          2,
          3 + button.getWidth() - (vertical ? 6 : 5),
          3 + button.getHeight() - 7);

      toBorder = null;
    }

    if (toBorder != null) {
      g.setColor(toBorder);
      g.drawRect(2, 2, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6);
    }

    AffineTransform tr = null;
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      tr = g2.getTransform();
      if (ToolWindowAnchor.RIGHT == anchor) {
        if (icon != null) { // do not rotate icon
          icon.paintIcon(c, g2, ourIconRect.y, ourIconRect.x);
        }
        g2.rotate(Math.PI / 2);
        g2.translate(0, -c.getWidth());
      } else {
        if (icon != null) { // do not rotate icon
          icon.paintIcon(
              c, g2, ourIconRect.y, c.getHeight() - ourIconRect.x - icon.getIconHeight());
        }
        g2.rotate(-Math.PI / 2);
        g2.translate(-c.getHeight(), 0);
      }
    } else {
      if (icon != null) {
        icon.paintIcon(c, g2, ourIconRect.x, ourIconRect.y);
      }
    }

    // paint text

    if (text != null) {
      if (model.isEnabled()) {
        if (model.isArmed() && model.isPressed() || model.isSelected()) {
          g.setColor(background);
        } else {
          g.setColor(button.getForeground());
        }
      } else {
        g.setColor(background.darker());
      }
      /* Draw the Text */
      if (model.isEnabled()) {
        /** * paint the text normally */
        g.setColor(button.getForeground());
        BasicGraphicsUtils.drawString(
            g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent());
      } else {
        /** * paint the text disabled ** */
        if (model.isSelected()) {
          g.setColor(c.getBackground());
        } else {
          g.setColor(getDisabledTextColor());
        }
        BasicGraphicsUtils.drawString(
            g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent());
      }
    }
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      g2.setTransform(tr);
    }
  }
  public static void main(String args[]) {
    JComponent ch = new JComponent() {};
    ch.getAccessibleContext();
    ch.isFocusTraversable();
    ch.setEnabled(false);
    ch.setEnabled(true);
    ch.requestFocus();
    ch.requestFocusInWindow();
    ch.getPreferredSize();
    ch.getMaximumSize();
    ch.getMinimumSize();
    ch.contains(1, 2);
    Component c1 = ch.add(new Component() {});
    Component c2 = ch.add(new Component() {});
    Component c3 = ch.add(new Component() {});
    Insets ins = ch.getInsets();
    ch.getAlignmentY();
    ch.getAlignmentX();
    ch.getGraphics();
    ch.setVisible(false);
    ch.setVisible(true);
    ch.setForeground(Color.red);
    ch.setBackground(Color.red);
    for (String font : Toolkit.getDefaultToolkit().getFontList()) {
      for (int j = 8; j < 17; j++) {
        Font f1 = new Font(font, Font.PLAIN, j);
        Font f2 = new Font(font, Font.BOLD, j);
        Font f3 = new Font(font, Font.ITALIC, j);
        Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);

        ch.setFont(f1);
        ch.setFont(f2);
        ch.setFont(f3);
        ch.setFont(f4);

        ch.getFontMetrics(f1);
        ch.getFontMetrics(f2);
        ch.getFontMetrics(f3);
        ch.getFontMetrics(f4);
      }
    }
    ch.enable();
    ch.disable();
    ch.reshape(10, 10, 10, 10);
    ch.getBounds(new Rectangle(1, 1, 1, 1));
    ch.getSize(new Dimension(1, 2));
    ch.getLocation(new Point(1, 2));
    ch.getX();
    ch.getY();
    ch.getWidth();
    ch.getHeight();
    ch.isOpaque();
    ch.isValidateRoot();
    ch.isOptimizedDrawingEnabled();
    ch.isDoubleBuffered();
    ch.getComponentCount();
    ch.countComponents();
    ch.getComponent(1);
    ch.getComponent(2);
    Component[] cs = ch.getComponents();
    ch.getLayout();
    ch.setLayout(new FlowLayout());
    ch.doLayout();
    ch.layout();
    ch.invalidate();
    ch.validate();
    ch.remove(0);
    ch.remove(c2);
    ch.removeAll();
    ch.preferredSize();
    ch.minimumSize();
    ch.getComponentAt(1, 2);
    ch.locate(1, 2);
    ch.getComponentAt(new Point(1, 2));
    ch.isFocusCycleRoot(new Container());
    ch.transferFocusBackward();
    ch.setName("goober");
    ch.getName();
    ch.getParent();
    ch.getGraphicsConfiguration();
    ch.getTreeLock();
    ch.getToolkit();
    ch.isValid();
    ch.isDisplayable();
    ch.isVisible();
    ch.isShowing();
    ch.isEnabled();
    ch.enable(false);
    ch.enable(true);
    ch.enableInputMethods(false);
    ch.enableInputMethods(true);
    ch.show();
    ch.show(false);
    ch.show(true);
    ch.hide();
    ch.getForeground();
    ch.isForegroundSet();
    ch.getBackground();
    ch.isBackgroundSet();
    ch.getFont();
    ch.isFontSet();
    Container c = new Container();
    c.add(ch);
    ch.getLocale();
    for (Locale locale : Locale.getAvailableLocales()) ch.setLocale(locale);

    ch.getColorModel();
    ch.getLocation();

    boolean exceptions = false;
    try {
      ch.getLocationOnScreen();
    } catch (IllegalComponentStateException e) {
      exceptions = true;
    }
    if (!exceptions)
      throw new RuntimeException("IllegalComponentStateException did not occur when expected");

    ch.location();
    ch.setLocation(1, 2);
    ch.move(1, 2);
    ch.setLocation(new Point(1, 2));
    ch.getSize();
    ch.size();
    ch.setSize(1, 32);
    ch.resize(1, 32);
    ch.setSize(new Dimension(1, 32));
    ch.resize(new Dimension(1, 32));
    ch.getBounds();
    ch.bounds();
    ch.setBounds(10, 10, 10, 10);
    ch.setBounds(new Rectangle(10, 10, 10, 10));
    ch.isLightweight();
    ch.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
    ch.getCursor();
    ch.isCursorSet();
    ch.inside(1, 2);
    ch.contains(new Point(1, 2));
    ch.isFocusable();
    ch.setFocusable(true);
    ch.setFocusable(false);
    ch.transferFocus();
    ch.getFocusCycleRootAncestor();
    ch.nextFocus();
    ch.transferFocusUpCycle();
    ch.hasFocus();
    ch.isFocusOwner();
    ch.toString();
    ch.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    ch.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    ch.setComponentOrientation(ComponentOrientation.UNKNOWN);
    ch.getComponentOrientation();
  }
  protected void paintBackground(
      Graphics g, int x, int y, int w, int h, boolean horizontal, JComponent component) {
    Graphics2D g2d = (Graphics2D) g.create();
    CEclipseBorder ec = null;
    Insets ins = getOutsideInsets();

    x = ins.left;
    y = ins.top;
    if (getOrientation().isHorizontal()) {
      w -= ins.left + ins.right;
      h -= ins.top + ins.bottom;
    } else {
      w -= ins.top + ins.bottom;
      h -= ins.left + ins.right;
    }

    if (component.getBorder() instanceof CompoundBorder) {
      CompoundBorder cb = (CompoundBorder) component.getBorder();
      CompoundBorder bb = (CompoundBorder) cb.getInsideBorder();

      ec = (CEclipseBorder) bb.getOutsideBorder();
    }

    if (w > 0 && h > 0) {
      if (glassStrip != null) {
        BufferedImage im = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

        Graphics2D gg = im.createGraphics();
        gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        gg.setColor(component.getBackground());
        if (ec != null) {
          gg.fill(ec.createShape(0, 0, w, h, ec.getCornerRadius()));

        } else {
          gg.fillRect(0, 0, w, h);
        }

        if (!isSelected()) {
          gg.setComposite(AlphaComposite.SrcIn);
        } else {
          gg.setComposite(AlphaComposite.SrcAtop);
        }

        try {
          glass.Render2Graphics(new Dimension(w, h), gg, glassStrip, true);
        } catch (Exception e) {
          glass.Render2Graphics(new Dimension(w, h), gg, CGlassFactory.VALUE_STEEL, true);
        }

        gg.dispose();

        if (!getOrientation().isHorizontal()) {
          AffineTransform atTrans = AffineTransform.getTranslateInstance(x /* + h */, y + w);
          atTrans.concatenate(COutlineHelper.tRot90CCW);
          g2d.drawImage(im, atTrans, null);
        } else {
          g2d.drawImage(im, x, y, null);
        }
      }

      g2d.dispose();
    }
  }