Debian Codegraph @

src/com/bulenkov/iconloader/util/GraphicsUtil.java

raw symbols SCIP
1 /*
2 * Copyright 2000-2014 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.bulenkov.iconloader.util;
18
19 import java.awt.*;
20 import java.util.Map;
21
22 /**
23 * @author Konstantin Bulenkov
24 */
25 public class GraphicsUtil {
26 public static void setupAntialiasing(Graphics g2) {
27 setupAntialiasing(g2, true, false);
28 }
29
30 public static void setupAntialiasing(Graphics g2, boolean enableAA, boolean ignoreSystemSettings) {
31 if (g2 instanceof Graphics2D) {
32 Graphics2D g = (Graphics2D) g2;
33 Toolkit tk = Toolkit.getDefaultToolkit();
34 //noinspection HardCodedStringLiteral
35 Map map = (Map) tk.getDesktopProperty("awt.font.desktophints");
36
37 if (map != null && !ignoreSystemSettings) {
38 g.addRenderingHints(map);
39 } else {
40 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
41 enableAA ? RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HBGR : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
42 }
43 }
44 }
45
46 public static GraphicsConfig setupAAPainting(Graphics g) {
47 final GraphicsConfig config = new GraphicsConfig(g);
48 final Graphics2D g2 = (Graphics2D) g;
49 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
50 g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
51 return config;
52 }
53
54 public static GraphicsConfig paintWithAlpha(Graphics g, float alpha) {
55 assert 0.0f <= alpha && alpha <= 1.0f : "alpha should be in range 0.0f .. 1.0f";
56 final GraphicsConfig config = new GraphicsConfig(g);
57 final Graphics2D g2 = (Graphics2D) g;
58
59 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
60 return config;
61 }
62 }