Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ContentViewerHtmlStyles.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.contentviewers.layout;
20 
21 import java.awt.Font;
22 import javax.swing.JTextPane;
23 import javax.swing.text.EditorKit;
24 import javax.swing.text.html.HTMLEditorKit;
25 import javax.swing.text.html.StyleSheet;
26 
32 
33  // html stylesheet classnames for components
34  private static final String CLASS_PREFIX = ContentViewerHtmlStyles.class.getSimpleName();
35 
36  private static final String HEADER_CLASSNAME = CLASS_PREFIX + "header";
37  private static final String SUB_HEADER_CLASSNAME = CLASS_PREFIX + "subHeader";
38 
39  private static final String MESSAGE_CLASSNAME = CLASS_PREFIX + "message";
40  private static final String TEXT_CLASSNAME = CLASS_PREFIX + "text";
41  private static final String MONOSPACED_CLASSNAME = CLASS_PREFIX + "monospaced";
42  private static final String INDENTED_CLASSNAME = CLASS_PREFIX + "indent";
43  private static final String SPACED_SECTION_CLASSNAME = CLASS_PREFIX + "spacedSection";
44  private static final String KEY_COLUMN_TD_CLASSNAME = CLASS_PREFIX + "keyKolumn";
45 
46  private static final Font DEFAULT_FONT = ContentViewerDefaults.getFont();
47  private static final Font MESSAGE_FONT = ContentViewerDefaults.getMessageFont();
48  private static final Font HEADER_FONT = ContentViewerDefaults.getHeaderFont();
51 
52  // additional styling for components
53  private static final String STYLE_SHEET_RULE
54  = String.format(" .%s { font-family: %s; font-size: %dpt;font-style:italic; margin: 0px; padding: 0px 0px %dpt 0px; } ",
55  MESSAGE_CLASSNAME, MESSAGE_FONT.getFamily(), MESSAGE_FONT.getSize(), pxToPt(ContentViewerDefaults.getLineSpacing()))
56  + String.format(" .%s { font-family: %s; font-size: %dpt; font-weight: bold; margin: 0px; padding: 0px 0px %dpt 0px; } ",
57  HEADER_CLASSNAME, HEADER_FONT.getFamily(), HEADER_FONT.getSize(), pxToPt(ContentViewerDefaults.getLineSpacing()))
58  + String.format(" .%s { font-family: %s; font-size: %dpt; font-weight: bold; margin: 0px; padding: 0px 0px %dpt 0px; } ",
59  SUB_HEADER_CLASSNAME, SUB_HEADER_FONT.getFamily(), SUB_HEADER_FONT.getSize(), pxToPt(ContentViewerDefaults.getLineSpacing()))
60  + String.format(" .%s { font-family: %s; font-size: %dpt; margin: 0px; padding: 0px 0px %dpt 0px; } ",
61  TEXT_CLASSNAME, DEFAULT_FONT.getFamily(), DEFAULT_FONT.getSize(), pxToPt(ContentViewerDefaults.getLineSpacing()))
62  + String.format(" .%s { font-family: %s; font-size: %dpt; margin: 0px; padding: 0px 0px %dpt 0px; } ",
63  MONOSPACED_CLASSNAME, Font.MONOSPACED, MONOSPACED_FONT.getSize(), pxToPt(ContentViewerDefaults.getLineSpacing()))
64  + String.format(" .%s { padding-left: %dpt } ",
65  INDENTED_CLASSNAME, pxToPt(ContentViewerDefaults.getSectionIndent()))
66  + String.format(" .%s { padding-top: %dpt } ",
67  SPACED_SECTION_CLASSNAME, pxToPt(ContentViewerDefaults.getSectionSpacing()))
68  + String.format(" .%s { padding-right: %dpt; white-space: nowrap; } ",
69  KEY_COLUMN_TD_CLASSNAME, pxToPt(ContentViewerDefaults.getColumnSpacing()));
70 
71  private static final StyleSheet STYLE_SHEET = new StyleSheet();
72 
73  static {
74  // add the style rule to the style sheet.
75  STYLE_SHEET.addRule(STYLE_SHEET_RULE);
76  }
77 
86  private static int pxToPt(int px) {
87  return (int) Math.round(((double) px) / ContentViewerDefaults.getPtToPx());
88  }
89 
95  public static String getHeaderClassName() {
96  return HEADER_CLASSNAME;
97  }
98 
104  public static String getSubHeaderClassName() {
105  return SUB_HEADER_CLASSNAME;
106  }
107 
113  public static String getMessageClassName() {
114  return MESSAGE_CLASSNAME;
115  }
116 
122  public static String getTextClassName() {
123  return TEXT_CLASSNAME;
124  }
125 
131  public static String getMonospacedClassName() {
132  return MONOSPACED_CLASSNAME;
133  }
134 
140  public static String getIndentedClassName() {
141  return INDENTED_CLASSNAME;
142  }
143 
151  public static String getSpacedSectionClassName() {
153  }
154 
162  public static String getKeyColumnClassName() {
164  }
165 
172  public static void setStyles(JTextPane textPane) {
173  EditorKit editorKit = textPane.getEditorKit();
174  if (editorKit instanceof HTMLEditorKit) {
175  ((HTMLEditorKit) editorKit).setStyleSheet(STYLE_SHEET);
176  }
177  }
178 
186  public static void setupHtmlJTextPane(JTextPane textPane) {
187  textPane.setContentType("text/html;charset=UTF-8"); //NON-NLS
188  HTMLEditorKit kit = new HTMLEditorKit();
189  textPane.setEditorKit(kit);
190  kit.setStyleSheet(STYLE_SHEET);
191  textPane.setMargin(ContentViewerDefaults.getPanelInsets());
192  textPane.setBackground(ContentViewerDefaults.getPanelBackground());
193  }
194 }

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.