Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright 2000-2016 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 package com.bulenkov.iconloader.util;
17
18 import javax.swing.plaf.UIResource;
19 import java.awt.*;
20
21 /**
22 * @author Konstantin Bulenkov
23 */
24 public class JBFont extends Font {
25 private JBFont(Font font) {
26 super(font);
27 }
28
29 public static JBFont create(Font font) {
30 return create(font, true);
31 }
32
33 public static JBFont create(Font font, boolean tryToScale) {
34 if (font instanceof JBFont) {
35 return ((JBFont)font);
36 }
37 Font scaled = font;
38 if (tryToScale) {
39 scaled = font.deriveFont(font.getSize() * JBUI.scale(1f));
40 }
41
42 if (font instanceof UIResource) {
43 return new JBFontUIResource(scaled);
44 }
45
46 return new JBFont(scaled);
47 }
48
49 public JBFont asBold() {
50 return deriveFont(BOLD, getSize());
51 }
52
53 public JBFont asItalic() {
54 return deriveFont(ITALIC, getSize());
55 }
56
57 public JBFont asPlain() {
58 return deriveFont(PLAIN, getSize());
59 }
60
61 @Override
62 public JBFont deriveFont(int style, float size) {
63 return create(super.deriveFont(style, size), false);
64 }
65
66 @Override
67 public JBFont deriveFont(float size) {
68 return create(super.deriveFont(size), false);
69 }
70
71 public JBFont biggerOn(float size) {
72 return deriveFont(getSize() + JBUI.scale(size));
73 }
74
75 public JBFont lessOn(float size) {
76 return deriveFont(getSize() - JBUI.scale(size));
77 }
78
79 private static class JBFontUIResource extends JBFont implements UIResource {
80 private JBFontUIResource(Font font) {
81 super(font);
82 }
83 }
84 }