< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java

Print this page




  77 
  78         g.setColor(darkShadow);
  79         g.drawLine(1, 1, w-3, 1);      // inner border, top
  80         g.drawLine(1, 2, 1, h-3);      // inner border, left
  81 
  82         g.setColor(lightHighlight);
  83         g.drawLine(w-1, 0, w-1, h-1);  // outer border, bottom
  84         g.drawLine(0, h-1, w-1, h-1);  // outer border, right
  85 
  86         g.setColor(highlight);
  87         g.drawLine(w-2, 1, w-2, h-3);  // inner border, right
  88         g.drawLine(1, h-2, w-2, h-2);  // inner border, bottom
  89 
  90         g.translate(-x, -y);
  91         g.setColor(oldColor);
  92     }
  93 
  94 
  95     /**
  96      * Returns the amount of space taken up by a border drawn by
  97      * <code>drawEtchedRect()</code>
  98      *
  99      * @return  the inset of an etched rect
 100      */
 101     public static Insets getEtchedInsets() {
 102         return ETCHED_INSETS;
 103     }
 104 
 105 
 106     /**
 107      * Draws a groove.
 108      *
 109      * @param g an instance of {@code Graphics}
 110      * @param x an X coordinate
 111      * @param y an Y coordinate
 112      * @param w a width
 113      * @param h a height
 114      * @param shadow a color of shadow
 115      * @param highlight a color highlighting
 116      */
 117     public static void drawGroove(Graphics g, int x, int y, int w, int h,


 119     {
 120         Color oldColor = g.getColor();  // Make no net change to g
 121         g.translate(x, y);
 122 
 123         g.setColor(shadow);
 124         g.drawRect(0, 0, w-2, h-2);
 125 
 126         g.setColor(highlight);
 127         g.drawLine(1, h-3, 1, 1);
 128         g.drawLine(1, 1, w-3, 1);
 129 
 130         g.drawLine(0, h-1, w-1, h-1);
 131         g.drawLine(w-1, h-1, w-1, 0);
 132 
 133         g.translate(-x, -y);
 134         g.setColor(oldColor);
 135     }
 136 
 137     /**
 138      * Returns the amount of space taken up by a border drawn by
 139      * <code>drawGroove()</code>
 140      *
 141      * @return  the inset of a groove border
 142      */
 143     public static Insets getGrooveInsets() {
 144         return GROOVE_INSETS;
 145     }
 146 
 147 
 148     /**
 149      * Draws a bezel.
 150      *
 151      * @param g an instance of {@code Graphics}
 152      * @param x an X coordinate
 153      * @param y an Y coordinate
 154      * @param w a width
 155      * @param h a height
 156      * @param isPressed is component pressed
 157      * @param isDefault is default drawing
 158      * @param shadow a color of shadow
 159      * @param darkShadow a color of dark shadow


 268         if (underlinedChar != '\0') {
 269             char uc = Character.toUpperCase((char)underlinedChar);
 270             char lc = Character.toLowerCase((char)underlinedChar);
 271             int uci = text.indexOf(uc);
 272             int lci = text.indexOf(lc);
 273 
 274             if(uci == -1) {
 275                 index = lci;
 276             }
 277             else if(lci == -1) {
 278                 index = uci;
 279             }
 280             else {
 281                 index = (lci < uci) ? lci : uci;
 282             }
 283         }
 284         drawStringUnderlineCharAt(g, text, index, x, y);
 285     }
 286 
 287     /**
 288      * Draw a string with the graphics <code>g</code> at location
 289      * (<code>x</code>, <code>y</code>)
 290      * just like <code>g.drawString</code> would.
 291      * The character at index <code>underlinedIndex</code>
 292      * in text will be underlined. If <code>index</code> is beyond the
 293      * bounds of <code>text</code> (including &lt; 0), nothing will be
 294      * underlined.
 295      *
 296      * @param g Graphics to draw with
 297      * @param text String to draw
 298      * @param underlinedIndex Index of character in text to underline
 299      * @param x x coordinate to draw at
 300      * @param y y coordinate to draw at
 301      * @since 1.4
 302      */
 303     public static void drawStringUnderlineCharAt(Graphics g, String text,
 304                            int underlinedIndex, int x,int y) {
 305         SwingUtilities2.drawStringUnderlineCharAt(null, g, text,
 306                 underlinedIndex, x, y);
 307     }
 308 
 309     /**
 310      * Draws dashed rectangle.
 311      *
 312      * @param g an instance of {@code Graphics}
 313      * @param x an X coordinate




  77 
  78         g.setColor(darkShadow);
  79         g.drawLine(1, 1, w-3, 1);      // inner border, top
  80         g.drawLine(1, 2, 1, h-3);      // inner border, left
  81 
  82         g.setColor(lightHighlight);
  83         g.drawLine(w-1, 0, w-1, h-1);  // outer border, bottom
  84         g.drawLine(0, h-1, w-1, h-1);  // outer border, right
  85 
  86         g.setColor(highlight);
  87         g.drawLine(w-2, 1, w-2, h-3);  // inner border, right
  88         g.drawLine(1, h-2, w-2, h-2);  // inner border, bottom
  89 
  90         g.translate(-x, -y);
  91         g.setColor(oldColor);
  92     }
  93 
  94 
  95     /**
  96      * Returns the amount of space taken up by a border drawn by
  97      * {@code drawEtchedRect()}
  98      *
  99      * @return  the inset of an etched rect
 100      */
 101     public static Insets getEtchedInsets() {
 102         return ETCHED_INSETS;
 103     }
 104 
 105 
 106     /**
 107      * Draws a groove.
 108      *
 109      * @param g an instance of {@code Graphics}
 110      * @param x an X coordinate
 111      * @param y an Y coordinate
 112      * @param w a width
 113      * @param h a height
 114      * @param shadow a color of shadow
 115      * @param highlight a color highlighting
 116      */
 117     public static void drawGroove(Graphics g, int x, int y, int w, int h,


 119     {
 120         Color oldColor = g.getColor();  // Make no net change to g
 121         g.translate(x, y);
 122 
 123         g.setColor(shadow);
 124         g.drawRect(0, 0, w-2, h-2);
 125 
 126         g.setColor(highlight);
 127         g.drawLine(1, h-3, 1, 1);
 128         g.drawLine(1, 1, w-3, 1);
 129 
 130         g.drawLine(0, h-1, w-1, h-1);
 131         g.drawLine(w-1, h-1, w-1, 0);
 132 
 133         g.translate(-x, -y);
 134         g.setColor(oldColor);
 135     }
 136 
 137     /**
 138      * Returns the amount of space taken up by a border drawn by
 139      * {@code drawGroove()}
 140      *
 141      * @return  the inset of a groove border
 142      */
 143     public static Insets getGrooveInsets() {
 144         return GROOVE_INSETS;
 145     }
 146 
 147 
 148     /**
 149      * Draws a bezel.
 150      *
 151      * @param g an instance of {@code Graphics}
 152      * @param x an X coordinate
 153      * @param y an Y coordinate
 154      * @param w a width
 155      * @param h a height
 156      * @param isPressed is component pressed
 157      * @param isDefault is default drawing
 158      * @param shadow a color of shadow
 159      * @param darkShadow a color of dark shadow


 268         if (underlinedChar != '\0') {
 269             char uc = Character.toUpperCase((char)underlinedChar);
 270             char lc = Character.toLowerCase((char)underlinedChar);
 271             int uci = text.indexOf(uc);
 272             int lci = text.indexOf(lc);
 273 
 274             if(uci == -1) {
 275                 index = lci;
 276             }
 277             else if(lci == -1) {
 278                 index = uci;
 279             }
 280             else {
 281                 index = (lci < uci) ? lci : uci;
 282             }
 283         }
 284         drawStringUnderlineCharAt(g, text, index, x, y);
 285     }
 286 
 287     /**
 288      * Draw a string with the graphics {@code g} at location
 289      * ({@code x}, {@code y})
 290      * just like {@code g.drawString} would.
 291      * The character at index {@code underlinedIndex}
 292      * in text will be underlined. If {@code index} is beyond the
 293      * bounds of {@code text} (including &lt; 0), nothing will be
 294      * underlined.
 295      *
 296      * @param g Graphics to draw with
 297      * @param text String to draw
 298      * @param underlinedIndex Index of character in text to underline
 299      * @param x x coordinate to draw at
 300      * @param y y coordinate to draw at
 301      * @since 1.4
 302      */
 303     public static void drawStringUnderlineCharAt(Graphics g, String text,
 304                            int underlinedIndex, int x,int y) {
 305         SwingUtilities2.drawStringUnderlineCharAt(null, g, text,
 306                 underlinedIndex, x, y);
 307     }
 308 
 309     /**
 310      * Draws dashed rectangle.
 311      *
 312      * @param g an instance of {@code Graphics}
 313      * @param x an X coordinate


< prev index next >