jdk/src/share/classes/sun/swing/SwingUtilities2.java
changeset 24163 d56df89854c4
parent 23298 1c729daf92a0
child 24969 afa6934dd8e8
equal deleted inserted replaced
24162:0fe6fb6759ab 24163:d56df89854c4
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package sun.swing;
    26 package sun.swing;
    27 
    27 
    28 import java.security.*;
       
    29 import java.lang.reflect.*;
    28 import java.lang.reflect.*;
    30 import java.awt.*;
    29 import java.awt.*;
    31 import static java.awt.RenderingHints.*;
    30 import static java.awt.RenderingHints.*;
    32 import java.awt.event.*;
    31 import java.awt.event.*;
    33 import java.awt.font.*;
    32 import java.awt.font.*;
    34 import java.awt.geom.*;
       
    35 import java.awt.print.PrinterGraphics;
    33 import java.awt.print.PrinterGraphics;
    36 import java.text.CharacterIterator;
    34 import java.text.CharacterIterator;
    37 import java.text.AttributedCharacterIterator;
    35 import java.text.AttributedCharacterIterator;
    38 import java.text.AttributedString;
    36 import java.text.AttributedString;
    39 
    37 
    46 import javax.swing.table.TableCellRenderer;
    44 import javax.swing.table.TableCellRenderer;
    47 import javax.swing.table.TableColumnModel;
    45 import javax.swing.table.TableColumnModel;
    48 import javax.swing.tree.TreeModel;
    46 import javax.swing.tree.TreeModel;
    49 import javax.swing.tree.TreePath;
    47 import javax.swing.tree.TreePath;
    50 
    48 
    51 import sun.swing.PrintColorUIResource;
       
    52 import sun.swing.ImageIconUIResource;
       
    53 import sun.print.ProxyPrintGraphics;
    49 import sun.print.ProxyPrintGraphics;
    54 import sun.awt.*;
    50 import sun.awt.*;
    55 import sun.security.action.GetPropertyAction;
       
    56 import java.io.*;
    51 import java.io.*;
    57 import java.util.*;
    52 import java.util.*;
    58 import sun.font.FontDesignMetrics;
    53 import sun.font.FontDesignMetrics;
    59 import sun.font.FontUtilities;
    54 import sun.font.FontUtilities;
    60 import sun.java2d.SunGraphicsEnvironment;
    55 import sun.java2d.SunGraphicsEnvironment;
   922         }
   917         }
   923 
   918 
   924         return retVal;
   919         return retVal;
   925     }
   920     }
   926 
   921 
       
   922     /**
       
   923      * This method should be used for drawing a borders over a filled rectangle.
       
   924      * Draws vertical line, using the current color, between the points {@code
       
   925      * (x, y1)} and {@code (x, y2)} in graphics context's coordinate system.
       
   926      * Note: it use {@code Graphics.fillRect()} internally.
       
   927      *
       
   928      * @param g  Graphics to draw the line to.
       
   929      * @param x  the <i>x</i> coordinate.
       
   930      * @param y1 the first point's <i>y</i> coordinate.
       
   931      * @param y2 the second point's <i>y</i> coordinate.
       
   932      */
       
   933     public static void drawVLine(Graphics g, int x, int y1, int y2) {
       
   934         if (y2 < y1) {
       
   935             final int temp = y2;
       
   936             y2 = y1;
       
   937             y1 = temp;
       
   938         }
       
   939         g.fillRect(x, y1, 1, y2 - y1 + 1);
       
   940     }
       
   941 
       
   942     /**
       
   943      * This method should be used for drawing a borders over a filled rectangle.
       
   944      * Draws horizontal line, using the current color, between the points {@code
       
   945      * (x1, y)} and {@code (x2, y)} in graphics context's coordinate system.
       
   946      * Note: it use {@code Graphics.fillRect()} internally.
       
   947      *
       
   948      * @param g  Graphics to draw the line to.
       
   949      * @param x1 the first point's <i>x</i> coordinate.
       
   950      * @param x2 the second point's <i>x</i> coordinate.
       
   951      * @param y  the <i>y</i> coordinate.
       
   952      */
       
   953     public static void drawHLine(Graphics g, int x1, int x2, int y) {
       
   954         if (x2 < x1) {
       
   955             final int temp = x2;
       
   956             x2 = x1;
       
   957             x1 = temp;
       
   958         }
       
   959         g.fillRect(x1, y, x2 - x1 + 1, 1);
       
   960     }
       
   961 
       
   962     /**
       
   963      * This method should be used for drawing a borders over a filled rectangle.
       
   964      * Draws the outline of the specified rectangle. The left and right edges of
       
   965      * the rectangle are at {@code x} and {@code x + w}. The top and bottom
       
   966      * edges are at {@code y} and {@code y + h}. The rectangle is drawn using
       
   967      * the graphics context's current color. Note: it use {@code
       
   968      * Graphics.fillRect()} internally.
       
   969      *
       
   970      * @param g Graphics to draw the rectangle to.
       
   971      * @param x the <i>x</i> coordinate of the rectangle to be drawn.
       
   972      * @param y the <i>y</i> coordinate of the rectangle to be drawn.
       
   973      * @param w the w of the rectangle to be drawn.
       
   974      * @param h the h of the rectangle to be drawn.
       
   975      * @see SwingUtilities2#drawVLine(java.awt.Graphics, int, int, int)
       
   976      * @see SwingUtilities2#drawHLine(java.awt.Graphics, int, int, int)
       
   977      */
       
   978     public static void drawRect(Graphics g, int x, int y, int w, int h) {
       
   979         if (w < 0 || h < 0) {
       
   980             return;
       
   981         }
       
   982 
       
   983         if (h == 0 || w == 0) {
       
   984             g.fillRect(x, y, w + 1, h + 1);
       
   985         } else {
       
   986             g.fillRect(x, y, w, 1);
       
   987             g.fillRect(x + w, y, 1, h);
       
   988             g.fillRect(x + 1, y + h, w, 1);
       
   989             g.fillRect(x, y + 1, 1, h);
       
   990         }
       
   991     }
       
   992 
   927     private static TextLayout createTextLayout(JComponent c, String s,
   993     private static TextLayout createTextLayout(JComponent c, String s,
   928                                             Font f, FontRenderContext frc) {
   994                                             Font f, FontRenderContext frc) {
   929         Object shaper = (c == null ?
   995         Object shaper = (c == null ?
   930                     null : c.getClientProperty(TextAttribute.NUMERIC_SHAPING));
   996                     null : c.getClientProperty(TextAttribute.NUMERIC_SHAPING));
   931         if (shaper == null) {
   997         if (shaper == null) {