Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
TextZoomPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2020 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.keywordsearch;
20 
21 import javax.swing.JLabel;
22 import javax.swing.JPanel;
23 import org.openide.util.NbBundle;
24 
28 class TextZoomPanel extends JPanel {
29  static final int DEFAULT_SIZE = new JLabel().getFont().getSize();
30 
31  private static final long serialVersionUID = 1L;
32 
33  private static final double[] ZOOM_STEPS = {
34  0.0625, 0.125, 0.25, 0.375, 0.5, 0.75,
35  1, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10};
36 
37  // Identifies the center index in zoom steps (what identifies 100%).
38  private static final int DEFAULT_STEP_IDX = 6;
39 
40  // The component to receive zoom updates.
41  private final ResizableTextPanel zoomable;
42 
43  // On initialization, set to 100%.
44  private int curStepIndex = DEFAULT_STEP_IDX;
45 
46 
51  TextZoomPanel(ResizableTextPanel zoomable) {
52  this.zoomable = zoomable;
53  initComponents();
54  updateEnabled();
55  setZoomText();
56  }
57 
58 
59  private void updateEnabled() {
60  boolean shouldEnable = this.zoomable != null;
61  this.zoomInButton.setEnabled(shouldEnable);
62  this.zoomOutButton.setEnabled(shouldEnable);
63  this.zoomResetButton.setEnabled(shouldEnable);
64  this.zoomTextField.setEnabled(shouldEnable);
65  }
66 
71  synchronized void resetSize() {
72  zoomStep(DEFAULT_STEP_IDX);
73  }
74 
75  private synchronized void zoomStep(int newStep) {
76  if (this.zoomable != null && newStep >= 0 && newStep < ZOOM_STEPS.length) {
77  curStepIndex = newStep;
78  zoomable.setTextSize((int)Math.round(ZOOM_STEPS[curStepIndex] * (double)DEFAULT_SIZE));
79  setZoomText();
80  }
81  }
82 
83  private synchronized void zoomDecrement() {
84  zoomStep(curStepIndex - 1);
85  }
86 
87  private synchronized void zoomIncrement() {
88  zoomStep(curStepIndex + 1);
89  }
90 
91  private void setZoomText() {
92  String percent = Long.toString(Math.round(ZOOM_STEPS[this.curStepIndex] * 100));
93  zoomTextField.setText(percent + "%");
94  }
95 
96 
97 
98  @NbBundle.Messages({
99  "TextZoomPanel.zoomTextField.text=",
100  "TextZoomPanel.zoomOutButton.text=",
101  "TextZoomPanel.zoomInButton.text=",
102  "TextZoomPanel.zoomResetButton.text=Reset"
103  })
109  @SuppressWarnings("unchecked")
110  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
111  private void initComponents() {
112 
113  zoomTextField = new javax.swing.JTextField();
114  zoomOutButton = new javax.swing.JButton();
115  zoomInButton = new javax.swing.JButton();
116  zoomResetButton = new javax.swing.JButton();
117 
118  setMaximumSize(null);
119  setMinimumSize(null);
120  setName(""); // NOI18N
121  setPreferredSize(null);
122  setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
123 
124  zoomTextField.setEditable(false);
125  zoomTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
126  zoomTextField.setText(org.openide.util.NbBundle.getMessage(TextZoomPanel.class, "TextZoomPanel.zoomTextField.text")); // NOI18N
127  zoomTextField.setMaximumSize(new java.awt.Dimension(50, 2147483647));
128  zoomTextField.setMinimumSize(new java.awt.Dimension(50, 20));
129  zoomTextField.setPreferredSize(new java.awt.Dimension(50, 20));
130  add(zoomTextField);
131 
132  zoomOutButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/zoom-out.png"))); // NOI18N
133  org.openide.awt.Mnemonics.setLocalizedText(zoomOutButton, org.openide.util.NbBundle.getMessage(TextZoomPanel.class, "TextZoomPanel.zoomOutButton.text")); // NOI18N
134  zoomOutButton.setBorderPainted(false);
135  zoomOutButton.setFocusable(false);
136  zoomOutButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
137  zoomOutButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
138  zoomOutButton.setMaximumSize(new java.awt.Dimension(20, 20));
139  zoomOutButton.setMinimumSize(new java.awt.Dimension(20, 20));
140  zoomOutButton.setPreferredSize(new java.awt.Dimension(20, 20));
141  zoomOutButton.addActionListener(new java.awt.event.ActionListener() {
142  public void actionPerformed(java.awt.event.ActionEvent evt) {
143  zoomOutButtonActionPerformed(evt);
144  }
145  });
146  add(zoomOutButton);
147 
148  zoomInButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/zoom-in.png"))); // NOI18N
149  org.openide.awt.Mnemonics.setLocalizedText(zoomInButton, org.openide.util.NbBundle.getMessage(TextZoomPanel.class, "TextZoomPanel.zoomInButton.text")); // NOI18N
150  zoomInButton.setBorderPainted(false);
151  zoomInButton.setFocusable(false);
152  zoomInButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
153  zoomInButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
154  zoomInButton.setMaximumSize(new java.awt.Dimension(20, 20));
155  zoomInButton.setMinimumSize(new java.awt.Dimension(20, 20));
156  zoomInButton.setPreferredSize(new java.awt.Dimension(20, 20));
157  zoomInButton.setRolloverEnabled(true);
158  zoomInButton.addActionListener(new java.awt.event.ActionListener() {
159  public void actionPerformed(java.awt.event.ActionEvent evt) {
160  zoomInButtonActionPerformed(evt);
161  }
162  });
163  add(zoomInButton);
164 
165  org.openide.awt.Mnemonics.setLocalizedText(zoomResetButton, org.openide.util.NbBundle.getMessage(TextZoomPanel.class, "TextZoomPanel.zoomResetButton.text")); // NOI18N
166  zoomResetButton.setBorderPainted(false);
167  zoomResetButton.setFocusable(false);
168  zoomResetButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
169  zoomResetButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
170  zoomResetButton.setMinimumSize(new java.awt.Dimension(50, 20));
171  zoomResetButton.setPreferredSize(new java.awt.Dimension(70, 20));
172  zoomResetButton.addActionListener(new java.awt.event.ActionListener() {
173  public void actionPerformed(java.awt.event.ActionEvent evt) {
174  zoomResetButtonActionPerformed(evt);
175  }
176  });
177  add(zoomResetButton);
178  }// </editor-fold>//GEN-END:initComponents
179 
180  private void zoomOutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomOutButtonActionPerformed
181  zoomDecrement();
182  }//GEN-LAST:event_zoomOutButtonActionPerformed
183 
184  private void zoomInButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomInButtonActionPerformed
185  zoomIncrement();
186  }//GEN-LAST:event_zoomInButtonActionPerformed
187 
188  private void zoomResetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomResetButtonActionPerformed
189  resetSize();
190  }//GEN-LAST:event_zoomResetButtonActionPerformed
191 
192 
193  // Variables declaration - do not modify//GEN-BEGIN:variables
194  private javax.swing.JButton zoomInButton;
195  private javax.swing.JButton zoomOutButton;
196  private javax.swing.JButton zoomResetButton;
197  private javax.swing.JTextField zoomTextField;
198  // End of variables declaration//GEN-END:variables
199 }

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