java.awt.Rectangle#union ( )源码实例Demo

下面列出了java.awt.Rectangle#union ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: libreveris   文件: SystemPart.java
@Override
protected void computeBox ()
{
    // Use the union of staves boxes
    Rectangle newBox = null;

    for (TreeNode node : getStaves()) {
        Staff staff = (Staff) node;

        if (newBox == null) {
            newBox = staff.getBox();
        } else {
            newBox = newBox.union(staff.getBox());
        }
    }

    setBox(newBox);
}
 
源代码2 项目: TencentKona-8   文件: DiagramScene.java
public void gotoFigures(final List<Figure> figures) {
    Rectangle overall = null;
    showFigures(figures);
    for (Figure f : figures) {

        FigureWidget fw = getFigureWidget(f);
        if (fw != null) {
            Rectangle r = fw.getBounds();
            Point p = fw.getLocation();
            Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height);

            if (overall == null) {
                overall = r2;
            } else {
                overall = overall.union(r2);
            }
        }
    }
    if (overall != null) {
        centerRectangle(overall);
    }
}
 
源代码3 项目: megamek   文件: PMAreasGroup.java
/**
 * Returns bounding box which includes all elements in group.
 */
public Rectangle getBounds() {
    Rectangle bounds = null;
    Enumeration<PMElement> iter = gr.elements();
    while (iter.hasMoreElements()) {
        PMElement pme = iter.nextElement();
        if ((pme != null) && (pme.getBounds() != null)) {
            if (bounds == null) {
                bounds = pme.getBounds();
            } else {
                bounds = bounds.union(pme.getBounds());
            }
        }
    }
    return bounds;
}
 
源代码4 项目: Java8CN   文件: BasicGraphicsUtils.java
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
源代码5 项目: hottub   文件: BasicGraphicsUtils.java
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
源代码6 项目: jdk8u-jdk   文件: BasicGraphicsUtils.java
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
源代码7 项目: importer-exporter   文件: BBoxSelectionPainter.java
private Rectangle createDrawArea(Rectangle2D geo, int zoom) {		
	Point2D southWest = map.convertGeoPositionToPoint(new GeoPosition(geo.getMinX(), geo.getMinY()), zoom);
	Point2D northEast = map.convertGeoPositionToPoint(new GeoPosition(geo.getMaxX(), geo.getMaxY()), zoom);

	Rectangle drawArea = new Rectangle((int)southWest.getX(), (int)southWest.getY(), 0, 0);
	return drawArea.union(new Rectangle((int)northEast.getX(), (int)northEast.getY(), 0, 0));
}
 
源代码8 项目: audiveris   文件: BarFilamentFactory.java
private boolean canMerge (Filament fil,
                          Rectangle core,
                          Section section)
{
    // A section must always touch one of fil current member sections
    if (!fil.touches(section)) {
        return false;
    }

    // If this does not increase thickness beyond core, it's OK
    Rectangle oSct = VERTICAL.oriented(section.getBounds());

    return core.union(oSct).height <= core.height;
}
 
源代码9 项目: openjdk-8   文件: BasicGraphicsUtils.java
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
源代码10 项目: netbeans   文件: EditorCaret.java
private void updateRectangularSelectionPaintRect() {
    // Repaint current rect
    JTextComponent c = component;
    Rectangle repaintRect = rsPaintRect;
    if (rsDotRect == null || rsMarkRect == null) {
        return;
    }
    Rectangle newRect = new Rectangle();
    if (rsDotRect.x < rsMarkRect.x) { // Swap selection to left
        newRect.x = rsDotRect.x; // -1 to make the visual selection non-empty
        newRect.width = rsMarkRect.x - newRect.x;
    } else { // Extend or shrink on right
        newRect.x = rsMarkRect.x;
        newRect.width = rsDotRect.x - newRect.x;
    }
    if (rsDotRect.y < rsMarkRect.y) {
        newRect.y = rsDotRect.y;
        newRect.height = (rsMarkRect.y + rsMarkRect.height) - newRect.y;
    } else {
        newRect.y = rsMarkRect.y;
        newRect.height = (rsDotRect.y + rsDotRect.height) - newRect.y;
    }
    if (newRect.width < 2) {
        newRect.width = 2;
    }
    rsPaintRect = newRect;

    // Repaint merged region with original rect
    if (repaintRect == null) {
        repaintRect = rsPaintRect;
    } else {
        repaintRect = repaintRect.union(rsPaintRect);
    }
    c.repaint(repaintRect);
    
    updateRectangularSelectionPositionBlocks();
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: BasicGraphicsUtils.java
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
源代码12 项目: blog-codes   文件: mxVmlCanvas.java
/**
 * Draws the given lines as segments between all points of the given list
 * of mxPoints.
 * 
 * @param pts List of points that define the line.
 * @param style Style to be used for painting the line.
 */
public Element drawLine(List<mxPoint> pts, Map<String, Object> style)
{
	String strokeColor = mxUtils.getString(style,
			mxConstants.STYLE_STROKECOLOR);
	float strokeWidth = (float) (mxUtils.getFloat(style,
			mxConstants.STYLE_STROKEWIDTH, 1) * scale);

	Element elem = document.createElement("v:shape");

	if (strokeColor != null && strokeWidth > 0)
	{
		mxPoint pt = pts.get(0);
		Rectangle r = new Rectangle(pt.getPoint());

		StringBuilder buf = new StringBuilder("m " + Math.round(pt.getX())
				+ " " + Math.round(pt.getY()));

		for (int i = 1; i < pts.size(); i++)
		{
			pt = pts.get(i);
			buf.append(" l " + Math.round(pt.getX()) + " "
					+ Math.round(pt.getY()));

			r = r.union(new Rectangle(pt.getPoint()));
		}

		String d = buf.toString();
		elem.setAttribute("path", d);
		elem.setAttribute("filled", "false");
		elem.setAttribute("strokecolor", strokeColor);
		elem.setAttribute("strokeweight", String.valueOf(strokeWidth)
				+ "px");

		String s = "position:absolute;" + "left:" + String.valueOf(r.x)
				+ "px;" + "top:" + String.valueOf(r.y) + "px;" + "width:"
				+ String.valueOf(r.width) + "px;" + "height:"
				+ String.valueOf(r.height) + "px;";
		elem.setAttribute("style", s);

		elem.setAttribute("coordorigin",
				String.valueOf(r.x) + " " + String.valueOf(r.y));
		elem.setAttribute("coordsize", String.valueOf(r.width) + " "
				+ String.valueOf(r.height));
	}

	appendVmlElement(elem);

	return elem;
}
 
源代码13 项目: netbeans   文件: CompletionLayoutPopup.java
public Rectangle unionBounds(Rectangle bounds) {
    return isVisible() ? bounds.union(getPopupBounds()) : bounds;
}
 
源代码14 项目: audiveris   文件: AnnotationsBuilder.java
/**
 * (Try to) generate the symbol for the provided inter.
 *
 * @param inter the provided inter
 */
private void exportInter (Inter inter)
{
    final Class interClass = inter.getClass();

    // Excluded class?
    if (isExcluded(interClass)) {
        logger.debug("{} class is excluded.", inter);

        return;
    }

    Shape interShape = inter.getShape();
    Rectangle interBounds = inter.getBounds();
    Staff staff = inter.getStaff();
    OmrShape omrShape;

    // Specific classes
    if (inter instanceof TimePairInter) {
        exportTimePair((TimePairInter) inter);

        return;
    } else if (inter instanceof BarlineInter) {
        exportBarlineGroup((BarlineInter) inter);

        return;
    } else if (inter instanceof KeyAlterInter) {
        omrShape = getOmrShape((KeyAlterInter) inter);
    } else if (inter instanceof ArticulationInter) {
        omrShape = getOmrShape((ArticulationInter) inter);
    } else {
        omrShape = OmrShapeMapping.SHAPE_TO_OMRSHAPE.get(interShape);

        if (omrShape == null) {
            logger.info("{} shape is not mapped.", inter);

            return;
        }

        if (inter instanceof LedgerInter) {
            // Make sure we have no note head centered on this ledger
            if (ledgerHasHead((LedgerInter) inter)) {
                return;
            }
        } else if (inter instanceof BarlineInter) {
            // Substitute a barlineDouble when relevant
            BarlineInter sibling = ((BarlineInter) inter).getSibling();

            if (sibling != null) {
                if (inter.getCenter().x < sibling.getCenter().x) {
                    omrShape = OmrShape.barlineDouble;
                    interBounds = interBounds.union(sibling.getBounds());
                } else {
                    return;
                }
            }
        }
    }

    if (staff == null) {
        if (inter instanceof BraceInter) {
            // Simply pick up the first staff embraced by this brace
            staff = ((BraceInter) inter).getFirstStaff();
        } else if (inter instanceof StemInter) {
            // Use staff of first head found
            staff = getStemStaff((StemInter) inter);
        } else if (inter instanceof PedalInter) {
            // Use bottom staff of related chord if any
            staff = getPedalStaff((PedalInter) inter);
        }
    }

    if (omrShape == null) {
        logger.warn("{} has no OmrShape, ignored.", inter);

        return;
    }

    if (staff == null) {
        logger.info("{} has no related staff, ignored.", inter);

        return;
    }

    final int interline = staff.getSpecificInterline();
    annotations.addSymbol(new SymbolInfo(omrShape, interline, inter.getId(), null,
                                         interBounds));
}
 
源代码15 项目: FlatLaf   文件: FlatMenuItemRenderer.java
protected Dimension getPreferredMenuItemSize() {
	int width = 0;
	int height = 0;
	boolean isTopLevelMenu = isTopLevelMenu( menuItem );

	Rectangle viewRect = new Rectangle( 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE );
	Rectangle iconRect = new Rectangle();
	Rectangle textRect = new Rectangle();

	// layout icon and text
	SwingUtilities.layoutCompoundLabel( menuItem,
		menuItem.getFontMetrics( menuItem.getFont() ), menuItem.getText(), getIconForLayout(),
		menuItem.getVerticalAlignment(), menuItem.getHorizontalAlignment(),
		menuItem.getVerticalTextPosition(), menuItem.getHorizontalTextPosition(),
		viewRect, iconRect, textRect, scale( menuItem.getIconTextGap() ) );

	// union icon and text rectangles
	Rectangle labelRect = iconRect.union( textRect );
	width += labelRect.width;
	height = Math.max( labelRect.height, height );

	// accelerator size
	String accelText = getAcceleratorText();
	if( accelText != null ) {
		// gap between text and accelerator
		width += scale( !isTopLevelMenu ? textAcceleratorGap : menuItem.getIconTextGap() );

		FontMetrics accelFm = menuItem.getFontMetrics( acceleratorFont );
		width += SwingUtilities.computeStringWidth( accelFm, accelText );
		height = Math.max( accelFm.getHeight(), height );
	}

	// arrow size
	if( !isTopLevelMenu && arrowIcon != null ) {
		// gap between text and arrow
		if( accelText == null )
			width += scale( textNoAcceleratorGap );

		// gap between accelerator and arrow
		width += scale( acceleratorArrowGap );

		width += arrowIcon.getIconWidth();
		height = Math.max( arrowIcon.getIconHeight(), height );
	}

	// add insets
	Insets insets = menuItem.getInsets();
	width += insets.left + insets.right;
	height += insets.top + insets.bottom;

	// minimum width
	if( !isTopLevelMenu ) {
		int minimumWidth = FlatUIUtils.minimumWidth( menuItem, this.minimumWidth );
		width = Math.max( width, scale( minimumWidth ) );
	}

	return new Dimension( width, height );
}
 
源代码16 项目: TencentKona-8   文件: WindowsTextUI.java
/**
 * Paints a highlight.
 *
 * @param g the graphics context
 * @param offs0 the starting model offset >= 0
 * @param offs1 the ending model offset >= offs1
 * @param bounds the bounding box for the highlight
 * @param c the editor
 */
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
    Rectangle alloc = bounds.getBounds();
    try {
        // --- determine locations ---
        TextUI mapper = c.getUI();
        Rectangle p0 = mapper.modelToView(c, offs0);
        Rectangle p1 = mapper.modelToView(c, offs1);

        // --- render ---
        Color color = getColor();

        if (color == null) {
            g.setColor(c.getSelectionColor());
        }
        else {
            g.setColor(color);
        }
        boolean firstIsDot = false;
        boolean secondIsDot = false;
        if (c.isEditable()) {
            int dot = c.getCaretPosition();
            firstIsDot = (offs0 == dot);
            secondIsDot = (offs1 == dot);
        }
        if (p0.y == p1.y) {
            // same line, render a rectangle
            Rectangle r = p0.union(p1);
            if (r.width > 0) {
                if (firstIsDot) {
                    r.x++;
                    r.width--;
                }
                else if (secondIsDot) {
                    r.width--;
                }
            }
            g.fillRect(r.x, r.y, r.width, r.height);
        } else {
            // different lines
            int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
            if (firstIsDot && p0ToMarginWidth > 0) {
                p0.x++;
                p0ToMarginWidth--;
            }
            g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
            if ((p0.y + p0.height) != p1.y) {
                g.fillRect(alloc.x, p0.y + p0.height, alloc.width,
                           p1.y - (p0.y + p0.height));
            }
            if (secondIsDot && p1.x > alloc.x) {
                p1.x--;
            }
            g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
        }
    } catch (BadLocationException e) {
        // can't render
    }
}
 
源代码17 项目: openjdk-8-source   文件: WindowsTextUI.java
/**
 * Paints a highlight.
 *
 * @param g the graphics context
 * @param offs0 the starting model offset >= 0
 * @param offs1 the ending model offset >= offs1
 * @param bounds the bounding box for the highlight
 * @param c the editor
 */
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
    Rectangle alloc = bounds.getBounds();
    try {
        // --- determine locations ---
        TextUI mapper = c.getUI();
        Rectangle p0 = mapper.modelToView(c, offs0);
        Rectangle p1 = mapper.modelToView(c, offs1);

        // --- render ---
        Color color = getColor();

        if (color == null) {
            g.setColor(c.getSelectionColor());
        }
        else {
            g.setColor(color);
        }
        boolean firstIsDot = false;
        boolean secondIsDot = false;
        if (c.isEditable()) {
            int dot = c.getCaretPosition();
            firstIsDot = (offs0 == dot);
            secondIsDot = (offs1 == dot);
        }
        if (p0.y == p1.y) {
            // same line, render a rectangle
            Rectangle r = p0.union(p1);
            if (r.width > 0) {
                if (firstIsDot) {
                    r.x++;
                    r.width--;
                }
                else if (secondIsDot) {
                    r.width--;
                }
            }
            g.fillRect(r.x, r.y, r.width, r.height);
        } else {
            // different lines
            int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
            if (firstIsDot && p0ToMarginWidth > 0) {
                p0.x++;
                p0ToMarginWidth--;
            }
            g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
            if ((p0.y + p0.height) != p1.y) {
                g.fillRect(alloc.x, p0.y + p0.height, alloc.width,
                           p1.y - (p0.y + p0.height));
            }
            if (secondIsDot && p1.x > alloc.x) {
                p1.x--;
            }
            g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
        }
    } catch (BadLocationException e) {
        // can't render
    }
}
 
源代码18 项目: jdk8u60   文件: WindowsTextUI.java
/**
 * Paints a highlight.
 *
 * @param g the graphics context
 * @param offs0 the starting model offset >= 0
 * @param offs1 the ending model offset >= offs1
 * @param bounds the bounding box for the highlight
 * @param c the editor
 */
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
    Rectangle alloc = bounds.getBounds();
    try {
        // --- determine locations ---
        TextUI mapper = c.getUI();
        Rectangle p0 = mapper.modelToView(c, offs0);
        Rectangle p1 = mapper.modelToView(c, offs1);

        // --- render ---
        Color color = getColor();

        if (color == null) {
            g.setColor(c.getSelectionColor());
        }
        else {
            g.setColor(color);
        }
        boolean firstIsDot = false;
        boolean secondIsDot = false;
        if (c.isEditable()) {
            int dot = c.getCaretPosition();
            firstIsDot = (offs0 == dot);
            secondIsDot = (offs1 == dot);
        }
        if (p0.y == p1.y) {
            // same line, render a rectangle
            Rectangle r = p0.union(p1);
            if (r.width > 0) {
                if (firstIsDot) {
                    r.x++;
                    r.width--;
                }
                else if (secondIsDot) {
                    r.width--;
                }
            }
            g.fillRect(r.x, r.y, r.width, r.height);
        } else {
            // different lines
            int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
            if (firstIsDot && p0ToMarginWidth > 0) {
                p0.x++;
                p0ToMarginWidth--;
            }
            g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
            if ((p0.y + p0.height) != p1.y) {
                g.fillRect(alloc.x, p0.y + p0.height, alloc.width,
                           p1.y - (p0.y + p0.height));
            }
            if (secondIsDot && p1.x > alloc.x) {
                p1.x--;
            }
            g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
        }
    } catch (BadLocationException e) {
        // can't render
    }
}
 
源代码19 项目: mil-sym-java   文件: MilStdSymbol.java
/**
 *
 * @return a rectangle of the extent (pixels) of the symbol (not including
 * modifiers) and null if the shape collections wasn't created. TODO: only
 * works for single points. need to update for multipoints
 */
public Rectangle getSymbolExtent() {
    Rectangle bounds = null;
    Rectangle temp = null;
    if (_SymbolShapes != null && _SymbolShapes.size() > 0) {
        if (SymbolUtilities.isWarfighting(_symbolID)) {
            for (int i = 0; i < _SymbolShapes.size(); i++) {
                if (_SymbolShapes.get(i).getShapeType() == ShapeInfo.SHAPE_TYPE_UNIT_FILL
                        || _SymbolShapes.get(i).getShapeType() == ShapeInfo.SHAPE_TYPE_UNIT_FRAME
                        || _SymbolShapes.get(i).getShapeType() == ShapeInfo.SHAPE_TYPE_UNIT_OUTLINE) {
                    if (bounds == null) {
                        bounds = _SymbolShapes.get(i).getBounds();
                    } else {
                        temp = _SymbolShapes.get(i).getBounds();
                        bounds = bounds.union(temp);
                    }
                }
            }

            if (bounds == null) {
                for (int i = 0; i < _SymbolShapes.size(); i++) {
                    if (_SymbolShapes.get(i).getShapeType() == ShapeInfo.SHAPE_TYPE_UNIT_SYMBOL1
                            || _SymbolShapes.get(i).getShapeType() == ShapeInfo.SHAPE_TYPE_UNIT_SYMBOL2) {
                        if (bounds == null) {
                            bounds = _SymbolShapes.get(i).getBounds();
                        } else {
                            bounds = bounds.union(_SymbolShapes.get(i).getBounds());
                        }
                    }
                }
            }

        } else if (SymbolUtilities.isTacticalGraphic(_symbolID)) {
            //bounds = _SymbolShapes.get(0).getBounds();
            for (int i = 0; i < _SymbolShapes.size(); i++) {
                if (_SymbolShapes.get(i).getShapeType() == ShapeInfo.SHAPE_TYPE_TG_SP_FRAME
                        || _SymbolShapes.get(i).getShapeType() == ShapeInfo.SHAPE_TYPE_TG_SP_FILL
                        || _SymbolShapes.get(i).getShapeType() == ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE) {
                    if (bounds == null) {
                        bounds = _SymbolShapes.get(i).getBounds();
                    } else {
                        temp = _SymbolShapes.get(i).getBounds();
                        bounds = bounds.union(temp);
                    }
                }
            }
        } else {
            bounds = _SymbolShapes.get(0).getBounds();
        }

    }

    return bounds;
}
 
源代码20 项目: jdk8u-jdk   文件: WindowsTextUI.java
/**
 * Paints a highlight.
 *
 * @param g the graphics context
 * @param offs0 the starting model offset >= 0
 * @param offs1 the ending model offset >= offs1
 * @param bounds the bounding box for the highlight
 * @param c the editor
 */
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
    Rectangle alloc = bounds.getBounds();
    try {
        // --- determine locations ---
        TextUI mapper = c.getUI();
        Rectangle p0 = mapper.modelToView(c, offs0);
        Rectangle p1 = mapper.modelToView(c, offs1);

        // --- render ---
        Color color = getColor();

        if (color == null) {
            g.setColor(c.getSelectionColor());
        }
        else {
            g.setColor(color);
        }
        boolean firstIsDot = false;
        boolean secondIsDot = false;
        if (c.isEditable()) {
            int dot = c.getCaretPosition();
            firstIsDot = (offs0 == dot);
            secondIsDot = (offs1 == dot);
        }
        if (p0.y == p1.y) {
            // same line, render a rectangle
            Rectangle r = p0.union(p1);
            if (r.width > 0) {
                if (firstIsDot) {
                    r.x++;
                    r.width--;
                }
                else if (secondIsDot) {
                    r.width--;
                }
            }
            g.fillRect(r.x, r.y, r.width, r.height);
        } else {
            // different lines
            int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
            if (firstIsDot && p0ToMarginWidth > 0) {
                p0.x++;
                p0ToMarginWidth--;
            }
            g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
            if ((p0.y + p0.height) != p1.y) {
                g.fillRect(alloc.x, p0.y + p0.height, alloc.width,
                           p1.y - (p0.y + p0.height));
            }
            if (secondIsDot && p1.x > alloc.x) {
                p1.x--;
            }
            g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
        }
    } catch (BadLocationException e) {
        // can't render
    }
}