Debian Codegraph @

src/com/bulenkov/iconloader/util/JBDimension.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
17 package com.bulenkov.iconloader.util;
18
19 import javax.swing.plaf.UIResource;
20 import java.awt.*;
21
22 /**
23 * @author Konstantin Bulenkov
24 */
25 public class JBDimension extends Dimension {
26 public final float originalScale = JBUI.scale(1f);
27
28 public JBDimension(int width, int height) {
29 super(scale(width), scale(height));
30 }
31
32 private static int scale(int size) {
33 return size == -1 ? -1 : JBUI.scale(size);
34 }
35
36 public static JBDimension create(Dimension from) {
37 if (from instanceof JBDimension) {
38 return ((JBDimension)from);
39 }
40 return new JBDimension(from.width, from.height);
41 }
42
43 public JBDimensionUIResource asUIResource() {
44 return new JBDimensionUIResource(this);
45 }
46
47 public static class JBDimensionUIResource extends JBDimension implements UIResource {
48 public JBDimensionUIResource(JBDimension size) {
49 super(0, 0);
50 width = size.width;
51 height = size.height;
52 }
53 }
54
55 public JBDimension withWidth(int width) {
56 JBDimension size = new JBDimension(0, 0);
57 size.width = scale(width);
58 size.height = height;
59 return size;
60 }
61
62 public JBDimension withHeight(int height) {
63 JBDimension size = new JBDimension(0, 0);
64 size.width = width;
65 size.height = scale(height);
66 return size;
67 }
68 }