Examples of Graphics2D


Examples of java.awt.Graphics2D

        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

Examples of java.awt.Graphics2D

    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

Examples of java.awt.Graphics2D

      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

Examples of java.awt.Graphics2D

     * @return Icon with Color
     */
    private Icon createIcon() {
        BufferedImage img = new BufferedImage(50, 10, BufferedImage.TYPE_INT_RGB);
       
        Graphics2D g = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(img);
       
        g.setColor(Color.WHITE);
        g.fillRect(0,0,50,10);
        g.setColor(mColor);
        g.fillRect(0,0,50,10);
       
        ImageIcon icon = new ImageIcon(img);
       
        return icon;
    }
View Full Code Here

Examples of java.awt.Graphics2D

    }
   
    public void drawString(
            OutputDevice outputDevice, String string, float x, float y, JustificationInfo info) {
        Object prevHint = null;
        Graphics2D graphics = ((Java2DOutputDevice)outputDevice).getGraphics();
        if ( graphics.getFont().getSize() > threshold && level > NONE ) {
            prevHint = graphics.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
            graphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, antiAliasRenderingHint );
        }
       
        GlyphVector vector = graphics.getFont().createGlyphVector(
                graphics.getFontRenderContext(), string);
       
        adjustGlyphPositions(string, info, vector);
       
        graphics.drawGlyphVector(vector, x, y);
       
        if ( graphics.getFont().getSize() > threshold && level > NONE ) {
            graphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, prevHint );
        }
    }
View Full Code Here

Examples of java.awt.Graphics2D

        }
    }
   
    public void drawGlyphVector(OutputDevice outputDevice, FSGlyphVector fsGlyphVector, float x, float y ) {
        Object prevHint = null;
        Graphics2D graphics = ((Java2DOutputDevice)outputDevice).getGraphics();
       
        if ( graphics.getFont().getSize() > threshold && level > NONE ) {
            prevHint = graphics.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
            graphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, antiAliasRenderingHint );
        }
        GlyphVector vector = ((AWTFSGlyphVector)fsGlyphVector).getGlyphVector();
        graphics.drawGlyphVector(vector, (int)x, (int)y );
        if ( graphics.getFont().getSize() > threshold && level > NONE ) {
            graphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, prevHint );
        }
    }
View Full Code Here

Examples of java.awt.Graphics2D

    public void setSmoothingLevel( int level ) {
        this.level = level;
    }

    public FSFontMetrics getFSFontMetrics(FontContext fc, FSFont font, String string ) {
        Graphics2D graphics = ((Java2DFontContext)fc).getGraphics();
        return new LineMetricsAdapter(
                ((AWTFSFont)font).getAWTFont().getLineMetrics(
                        string, graphics.getFontRenderContext()));
    }
View Full Code Here

Examples of java.awt.Graphics2D

                ((AWTFSFont)font).getAWTFont().getLineMetrics(
                        string, graphics.getFontRenderContext()));
    }
   
    public int getWidth(FontContext fc, FSFont font, String string) {
        Graphics2D graphics = ((Java2DFontContext)fc).getGraphics();
        Font awtFont = ((AWTFSFont)font).getAWTFont();
        return (int)Math.ceil(
                graphics.getFontMetrics(awtFont).getStringBounds(string, graphics).getWidth());
    }
View Full Code Here

Examples of java.awt.Graphics2D

        this.antiAliasRenderingHint = renderingHints;
    }

    public float[] getGlyphPositions(OutputDevice outputDevice, FSFont font, String text) {
        Object prevHint = null;
        Graphics2D graphics = ((Java2DOutputDevice)outputDevice).getGraphics();
        Font awtFont = ((AWTFSFont)font).getAWTFont();
       
        if (awtFont.getSize() > threshold && level > NONE ) {
            prevHint = graphics.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
            graphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, antiAliasRenderingHint );
        }
       
        GlyphVector vector = awtFont.createGlyphVector(
                graphics.getFontRenderContext(),
                text);
        float[] result = vector.getGlyphPositions(0, text.length() + 1, null);
       
        if (awtFont.getSize() > threshold && level > NONE ) {
            graphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, prevHint );
        }
       
        return result;
    }
View Full Code Here

Examples of java.awt.Graphics2D

        return result;
    }

    public Rectangle getGlyphBounds(OutputDevice outputDevice, FSFont font, FSGlyphVector fsGlyphVector, int index, float x, float y) {
        Object prevHint = null;
        Graphics2D graphics = ((Java2DOutputDevice)outputDevice).getGraphics();
        Font awtFont = ((AWTFSFont)font).getAWTFont();
       
        if (awtFont.getSize() > threshold && level > NONE ) {
            prevHint = graphics.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
            graphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, antiAliasRenderingHint );
        }
       
        GlyphVector vector = ((AWTFSGlyphVector)fsGlyphVector).getGlyphVector();
       
        Rectangle result = vector.getGlyphPixelBounds(index, graphics.getFontRenderContext(), x, y);
       
        if (awtFont.getSize() > threshold && level > NONE ) {
            graphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, prevHint );
        }
       
        return result;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.