Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
VerticalLabelUI.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2019 Basis Technology Corp.
6  * contact: carrier <at> sleuthkit <dot> org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 package org.sleuthkit.autopsy.geolocation;
21 
22 import java.awt.Dimension;
23 import java.awt.FontMetrics;
24 import java.awt.Graphics;
25 import java.awt.Graphics2D;
26 import java.awt.Insets;
27 import java.awt.Rectangle;
28 import java.awt.geom.AffineTransform;
29 
30 import javax.swing.Icon;
31 import javax.swing.JComponent;
32 import javax.swing.JLabel;
33 import javax.swing.plaf.basic.BasicLabelUI;
34 
35 
43 final class VerticalLabelUI extends BasicLabelUI {
44 
45  private static final Rectangle paintIconR = new Rectangle();
46  private static final Rectangle paintTextR = new Rectangle();
47  private static final Rectangle paintViewR = new Rectangle();
48  private static Insets paintViewInsets = new Insets(0, 0, 0, 0);
49 
50  static {
51  labelUI = new VerticalLabelUI(false);
52  }
53 
54  final boolean clockwise;
55 
60  VerticalLabelUI(boolean clockwise) {
61  super();
62  this.clockwise = clockwise;
63  }
64 
65  @Override
66  public Dimension getPreferredSize(JComponent c) {
67  Dimension dim = super.getPreferredSize(c);
68  return new Dimension( dim.height, dim.width );
69  }
70 
71  @Override
72  public void paint(Graphics g, JComponent c) {
73  JLabel label = (JLabel)c;
74  String text = label.getText();
75  Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
76 
77  if ((icon == null) && (text == null)) {
78  return;
79  }
80 
81  FontMetrics fm = g.getFontMetrics();
82  paintViewInsets = c.getInsets(paintViewInsets);
83 
84  paintViewR.x = paintViewInsets.left;
85  paintViewR.y = paintViewInsets.top;
86 
87  // Use inverted height &amp; width
88  paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right);
89  paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);
90 
91  paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
92  paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
93 
94  String clippedText = layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR);
95 
96  Graphics2D g2 = (Graphics2D) g;
97  AffineTransform tr = g2.getTransform();
98  if (clockwise) {
99  g2.rotate( Math.PI / 2 );
100  g2.translate( 0, - c.getWidth() );
101  } else {
102  g2.rotate( - Math.PI / 2 );
103  g2.translate( - c.getHeight(), 0 );
104  }
105 
106  if (icon != null) {
107  icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
108  }
109 
110  if (text != null) {
111  int textX = paintTextR.x;
112  int textY = paintTextR.y + fm.getAscent();
113 
114  if (label.isEnabled()) {
115  paintEnabledText(label, g, clippedText, textX, textY);
116  } else {
117  paintDisabledText(label, g, clippedText, textX, textY);
118  }
119  }
120  g2.setTransform( tr );
121  }
122 
123 }
124 

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.