Package java.awt

Examples of java.awt.Graphics2D


                                      // the
                                      // label's
                                      // ht
                                      // and
                                      // width
          Graphics2D graphics = image.createGraphics();// creating
                                  // the
                                  // graphics
                                  // for
                                  // buffered
                                  // image
          graphics.setComposite(AlphaComposite.getInstance(
              AlphaComposite.SRC_OVER, 0.5f)); // Sets the
                                // Composite for
                                // the
                                // Graphics2D
                                // context
          lbl.setOpaque(false);
          lbl.paint(graphics); // painting the graphics to label
          graphics.dispose();
        }
        dragSource.startDrag(dge, DragSource.DefaultMoveNoDrop, image,
            new Point(0, 0), new TransferableNode(draggedNode),
            this);
      }
View Full Code Here


      int x = bds.getX() + bds.getWidth() / 2;
      int y = bds.getY() + bds.getHeight() / 2;
      Graphics g = painter.getGraphics().create();
      double angle = Math.PI / 2 - (up.toRadians() - defaultFacing.toRadians()) - facing.toRadians();
      if (g instanceof Graphics2D && Math.abs(angle) > 0.01) {
        Graphics2D g2 = (Graphics2D) g;
        g2.rotate(angle, x, y);
      }
      g.setFont(font);
      if (lines == 1 && !backs) {
        GraphicsUtil.drawCenteredText(g, label, x, y);
      } else {
View Full Code Here

    // Create a buffered image in which to draw
    BufferedImage bufferedImage = new BufferedImage(width, height,
        BufferedImage.TYPE_INT_ARGB);

    // Create a graphics contents on the buffered image
    Graphics2D g2d = bufferedImage.createGraphics();

    g2d.drawImage(img, 0, 0, null);

    // Graphics context no longer needed so dispose it
    g2d.dispose();

    return bufferedImage;
  }
View Full Code Here

    }
  }

  public void paint(Graphics graphics) {
    super.paint(graphics);
    final Graphics2D g2 = (Graphics2D) graphics;

    int w = getWidth();
    int h = 70;
    GradientPaint gradient = new GradientPaint(0, 0, new Color(255, 255, 255, 255), 2, h, new Color(255, 255, 255, 0), false);
    g2.setPaint(gradient);
    g2.fillRect(0, 0, w, h);

    gradient = new GradientPaint(0, getHeight() - h, new Color(255, 255, 255, 0), 2, getHeight(), new Color(255, 255, 255, 255), false);
    g2.setPaint(gradient);
    g2.fillRect(0, getHeight() - h, w, h);
  }
View Full Code Here

    }
    try {
      // Create Image with Icon
      BufferedImage iconImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
          BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2 = iconImage.createGraphics();
      g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
          RenderingHints.VALUE_INTERPOLATION_BICUBIC);
      g2.setRenderingHint(RenderingHints.KEY_RENDERING,
          RenderingHints.VALUE_RENDER_QUALITY);
      AffineTransform z = g2.getTransform();
      g2.setTransform(z);
      icon.paintIcon(null, g2, 0, 0);
      g2.dispose();
      BufferedImage scaled = scaleDown(iconImage, width, height);
      // Return new Icon
      return new ImageIcon(scaled);
    } catch (Exception ex) {
      ex.printStackTrace();
View Full Code Here

    // Scale Image
    Image image = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);

    BufferedImage im = new BufferedImage(width, height, type);

    Graphics2D g2 = im.createGraphics();
    if (backgroundColor != null) {
      g2.setColor(backgroundColor);
      g2.fillRect(0, 0 , width, height);
    }

    g2.drawImage(image, null, null);
    g2.dispose();

    im.flush();
    return im;

  }
View Full Code Here

      if (h < targetHeight) {
        h = targetHeight;
      }

      BufferedImage tmp = new BufferedImage(w, h, type);
      Graphics2D g2 = tmp.createGraphics();
      g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      g2.drawImage(result, 0, 0, w, h, null);
      g2.dispose();

      result = tmp;
    } while (w != targetWidth || h != targetHeight);

    return result;
View Full Code Here

        height = (int) (iHeight * (40.0 / iWidth));
      }
    }
    ic = scaleIcon(ic, width, height);

    Graphics2D g = img.createGraphics();

    g.setColor(Color.WHITE);
    g.fillRect(1, 1, 40, 20);

    int x = 1 + 20 - ic.getIconWidth() / 2;
    int y = 1 + 10 - ic.getIconHeight() / 2;

    ic.paintIcon(null, g, x, y);

    g.setColor(Color.BLACK);
    g.drawRect(0, 0, 42, 22);

    return new ImageIcon(img);
  }
View Full Code Here

    if (getTextIconWidth(width) != mDescriptionIcon.getIconWidth()) {
      recreateTextIcons(width);
    }

    int height = USE_FULL_HEIGHT ? getHeight() : mHeight;
    Graphics2D grp = (Graphics2D) g;

    // if program table is anti-aliased, then this program panel too
    if (Settings.propEnableAntialiasing.getBoolean()) {
      grp.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
          RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }

    // Draw the background if this program is on air
    if (mProgram.isOnAir()) {
      int minutesAfterMidnight = IOUtilities.getMinutesAfterMidnight();
      int progLength = mProgram.getLength();
      int startTime = mProgram.getStartTime();
      int elapsedMinutes = minutesAfterMidnight - startTime;
      if (elapsedMinutes < 0) {
        // The next day has begun -> we have to add 24 * 60 minutes
        // Example: Start time was 23:50 = 1430 minutes after midnight
        // now it is 0:03 = 3 minutes after midnight
        // elapsedMinutes = (24 * 60) + 3 - 1430 = 13 minutes
        elapsedMinutes += 24 * 60;
      }

      // elapsed minutes can not be larger than run time
      if (progLength > 0) {
        if (elapsedMinutes > progLength) {
          mLog.severe("paint program panel: elapsed minutes to large; sT=" + startTime + " mAM=" + minutesAfterMidnight + " pL=" + progLength + " eM=" + elapsedMinutes);
        }
        elapsedMinutes = Math.min(elapsedMinutes, progLength);
      }

      int borderWidth = Settings.propProgramTableOnAirProgramsShowingBorder
          .getBoolean() ? 1 : 0;
      if (mAxis == ProgramPanelSettings.X_AXIS) {
        // horizontal filling panel
        int progressX = 0;
        if (progLength > 0) {
          progressX = elapsedMinutes * width / progLength;
        }

        Color c = Settings.propProgramTableColorOnAirDark.getColor();
        grp.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(c.getAlpha()*mProgramImportance/10.)));

        int fillWidth = progressX - borderWidth;
        if (fillWidth > 0) {
          grp.fillRect(borderWidth, borderWidth, fillWidth, height - borderWidth);
        }
        c = Settings.propProgramTableColorOnAirLight.getColor();
        grp.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(c.getAlpha()*mProgramImportance/10.)));

        fillWidth = width - progressX - borderWidth * 2;
        if (fillWidth > 0) {
          grp.fillRect(progressX, borderWidth, fillWidth, height - borderWidth);
        }

      } else {
        // vertical filling panel
        int progressY = 0;
        if (progLength > 0) {
          progressY = elapsedMinutes * height / progLength;
        }

        Color c = Settings.propProgramTableColorOnAirDark.getColor();
        grp.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(c.getAlpha()*mProgramImportance/10.)));

        int fillHeight = progressY - borderWidth;

        if (fillHeight > height) {
          mLog.severe("paint program panel: fill height 1 to large");
          fillHeight = height;
        }

        if (fillHeight > 0) {
          grp.fillRect(borderWidth, borderWidth, width - borderWidth * 2, fillHeight);
        }

        c = Settings.propProgramTableColorOnAirLight.getColor();
        grp.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(c.getAlpha()*mProgramImportance/10.)));

        fillHeight = height - progressY - borderWidth;

        if (fillHeight > height) {
          mLog.severe("paint program panel: fill height 2 to large");
          fillHeight = height;
        }

        if (fillHeight > 0) {
          grp.fillRect(borderWidth, progressY, width - borderWidth * 2, fillHeight);
        }
      }
      if (Settings.propProgramTableOnAirProgramsShowingBorder.getBoolean()) {
        grp.draw3DRect(0, 0, width - 1, height - 1, true);
      }
    }

    // If there are plugins that have marked the program -> paint the background
    Marker[] markedByPluginArr = mProgram.getMarkerArr();
    if (markedByPluginArr.length != 0) {
      Color c = Plugin.getPluginManager().getTvBrowserSettings().getColorForMarkingPriority(mProgram.getMarkPriority());

      if(c == null) {
        c = Settings.propProgramPanelMarkedMinPriorityColor.getColor();
      }

      int alphaValue = (int)(c.getAlpha()*mProgramImportance/10.);

      if(mProgram.isExpired()) {
        grp.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(alphaValue*6/10.)));
      }
      else {
        grp.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), alphaValue));
      }

      if(mProgram.getMarkPriority() > Program.NO_MARK_PRIORITY) {
        if(Settings.propProgramPanelWithMarkingsShowingBoder.getBoolean()) {
          grp.fill3DRect(0, 0, width, height, true);
        }
        else {
          grp.fillRect(0, 0, width, height);
        }
      }
    }

    if (mMouseOver || mIsSelected) {
      Color test = Settings.propProgramTableMouseOverColor.getColor();
      if (mIsSelected) {
        test = Settings.propKeyboardSelectedColor.getColor();
      }
      grp.setColor(test);
      grp.fillRect(0, 0, width - 1, height - 1);

      Stroke str = grp.getStroke();
      Color col = grp.getColor();
      float[] dash = { 2.0f };
      int lineWidth = 1;
      BasicStroke dashed = new BasicStroke(lineWidth, BasicStroke.CAP_BUTT,
          BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
      grp.setColor(Color.BLACK);
      grp.setStroke(dashed);

      grp.drawRect(lineWidth - 1, lineWidth - 1, width - lineWidth, height - lineWidth);

      grp.setStroke(str);
      grp.setColor(col);
    }

    // Draw all the text
    if (mPaintExpiredProgramsPale && mProgram.isExpired()) {
      Color c = new Color(Color.gray.getRed(), Color.gray.getGreen(), Color.gray.getBlue(), (int)(Color.gray.getAlpha()*mProgramImportance/10.));

      setForeground(c);
      grp.setColor(c);
    } else {
      Color c = new Color(mTextColor.getRed(), mTextColor.getGreen(), mTextColor.getBlue(), (int)(mTextColor.getAlpha()*mProgramImportance/10.));

      setForeground(c);
      grp.setColor(c);
    }
    grp.setFont(ProgramPanel.mTimeFont);
    grp.drawString(mProgramTimeAsString, 1, mTimeFont.getSize());

    mTitleIcon.paintIcon(this, grp, WIDTH_LEFT, 0);

    if (!mSettings.isShowingOnlyDateAndTitle()) {
      mPictureAreaIcon.paintIcon(this,grp, WIDTH_LEFT, mTitleIcon.getIconHeight());

      if (mHeight >= mPreferredHeight) {
        mDescriptionIcon.paintIcon(this, grp, WIDTH_LEFT, mTitleIcon
            .getIconHeight() + mPictureAreaIcon.getIconHeight());
      }

      // Paint the icons pale if the program is expired
      if (mPaintExpiredProgramsPale && mProgram.isExpired() && mProgramImportance == 10) {
        grp.setComposite(PALE_COMPOSITE);
      }
      else if (mProgramImportance != 10) {
        grp.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, mProgramImportance/10F));
      }
    }


    // paint the icons of the plugins that have marked the program (lower right corner)
    int x = width - 1;
    int y = mTitleIcon.getIconHeight() + mDescriptionIcon.getIconHeight()
        + mPictureAreaIcon.getIconHeight() + 18;
    y = Math.min(y, height - 1);
    for (Marker marker: markedByPluginArr) {
      Icon[] icons = marker.getMarkIcons(mProgram);
      if (icons != null) {
        for(int i = icons.length - 1; i >= 0 ; i--) {
          x -= icons[i].getIconWidth();

          icons[i].paintIcon(this, grp, x, y - icons[i].getIconHeight());
        }
      }
    }

    // Paint the icons on the left side
    if (mIconArr != null) {
      x = ICON_DISTANCE_X;
      y = mTimeFont.getSize() + 3;
      Point iconsTopLeft = new Point(x, y);

      // calculate height with double column layout
      int sumHeights = -ICON_DISTANCE_Y;
      int maxWidth = 0;
      int rowWidth = 0;
      for (int i = 0; i < mIconArr.length; i++) {
        sumHeights += mIconArr[i].getIconHeight() + ICON_DISTANCE_Y;
        if (i % 2 == 0) {
          rowWidth = mIconArr[i].getIconWidth();
        }
        else {
          rowWidth += mIconArr[i].getIconWidth();
        }
        if (rowWidth > maxWidth) {
          maxWidth = rowWidth;
        }
      }

      // single column of icons
      int colCount = 1;
      // layout icons in pairs
      if ((y + sumHeights >= mHeight) && (maxWidth + 3 * ICON_DISTANCE_X < WIDTH_LEFT)) {
        colCount = 2;
      }
      int iconHeight = 0;
      int currentX = x;
      for (int i = 0; i < mIconArr.length; i++) {
        Icon icon = mIconArr[i];
        boolean nextColumn = (colCount == 1) || (i % 2 == 0);
        if (nextColumn) {
          currentX = x;
          iconHeight = icon.getIconHeight();
        }
        else {
          iconHeight = Math.max(iconHeight, icon.getIconHeight());
        }
        if ((y + iconHeight) < mHeight) {
          icon.paintIcon(this, grp, currentX, y);
        }
        if (nextColumn) {
          currentX += icon.getIconWidth() + ICON_DISTANCE_X;
        }
        if (!nextColumn || (colCount == 1)) {
          y += iconHeight + ICON_DISTANCE_Y;
        }
      }
      // remember the size of this area for tooltip
      if (colCount == 1) {
        mInfoIconRect = new Rectangle(iconsTopLeft.x, iconsTopLeft.y, currentX
            - iconsTopLeft.x, y - iconsTopLeft.y);
      } else {
        mInfoIconRect = new Rectangle(iconsTopLeft.x, iconsTopLeft.y, maxWidth,
            y - iconsTopLeft.y + iconHeight);
      }
    }

    // Reset the old composite
    if (mPaintExpiredProgramsPale && mProgram.isExpired()) {
      grp.setComposite(NORMAL_COMPOSITE);
    }
  }
View Full Code Here

      int i = mCue.locationToIndex(p);
     
      if(i != -1) {
        Rectangle listRect = mCue.getCellBounds(mCue.locationToIndex(p),
            mCue.locationToIndex(p));
        Graphics2D g2 = (Graphics2D) mCue.getGraphics();
        boolean paint = false;
       
        if(listRect != null) {
          listRect.setSize(listRect.width,listRect.height/2);
          if(!listRect.contains(e.getLocation()) && !mSwitched && i == mOldIndex) {
            mCue.paintImmediately(mCueLine.getBounds());
            mCueLine.setRect(0,listRect.y + (listRect.height * 2) - 1,listRect.width,2);
            mSwitched = true;
            paint = true;
          }
          else if(listRect.contains(e.getLocation()) && i == mOldIndex && mSwitched) {
            mCue.paintImmediately(mCueLine.getBounds());
            mCueLine.setRect(0,listRect.y - 1,listRect.width,2);
            mSwitched = false;
            paint = true;
          }
          else if(i != mOldIndex && listRect.contains(e.getLocation())) {
            mCue.paintImmediately(mCueLine.getBounds());
            mCueLine.setRect(0,listRect.y - 1,listRect.width,2);
            mSwitched = false;
            mOldIndex = i;
            paint = true;
          }
          else if(i != mOldIndex && !listRect.contains(e.getLocation())) {
            mCue.paintImmediately(mCueLine.getBounds());
            mCueLine.setRect(0,listRect.y + (listRect.height * 2) - 1,listRect.width,2);
            mSwitched = true;
            mOldIndex = i;
            paint = true;
          }
          if(paint) {
            Color c = new Color(255,0,0,180);
            g2.setColor(c);
            g2.fill(mCueLine);
          }
        }
      }
      else {
        mOldIndex = -1;
View Full Code Here

TOP

Related Classes of java.awt.Graphics2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.