Autopsy  4.14.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  javax.swing.JToolBar.Separator jSeparator2 = new javax.swing.JToolBar.Separator();
117  zoomResetButton = new javax.swing.JButton();
118 
119  setMinimumSize(new java.awt.Dimension(150, 20));
120  setPreferredSize(new java.awt.Dimension(200, 20));
121 
122  zoomTextField.setEditable(false);
123  zoomTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
124  zoomTextField.setText(org.openide.util.NbBundle.getMessage(TextZoomPanel.class, "TextZoomPanel.zoomTextField.text")); // NOI18N
125  zoomTextField.setMaximumSize(new java.awt.Dimension(50, 2147483647));
126  zoomTextField.setMinimumSize(new java.awt.Dimension(50, 20));
127  zoomTextField.setPreferredSize(new java.awt.Dimension(50, 20));
128 
129  zoomOutButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/zoom-out.png"))); // NOI18N
130  org.openide.awt.Mnemonics.setLocalizedText(zoomOutButton, org.openide.util.NbBundle.getMessage(TextZoomPanel.class, "TextZoomPanel.zoomOutButton.text")); // NOI18N
131  zoomOutButton.setBorderPainted(false);
132  zoomOutButton.setFocusable(false);
133  zoomOutButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
134  zoomOutButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
135  zoomOutButton.setMaximumSize(new java.awt.Dimension(20, 20));
136  zoomOutButton.setMinimumSize(new java.awt.Dimension(20, 20));
137  zoomOutButton.setPreferredSize(new java.awt.Dimension(20, 20));
138  zoomOutButton.addActionListener(new java.awt.event.ActionListener() {
139  public void actionPerformed(java.awt.event.ActionEvent evt) {
140  zoomOutButtonActionPerformed(evt);
141  }
142  });
143 
144  zoomInButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/zoom-in.png"))); // NOI18N
145  org.openide.awt.Mnemonics.setLocalizedText(zoomInButton, org.openide.util.NbBundle.getMessage(TextZoomPanel.class, "TextZoomPanel.zoomInButton.text")); // NOI18N
146  zoomInButton.setBorderPainted(false);
147  zoomInButton.setFocusable(false);
148  zoomInButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
149  zoomInButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
150  zoomInButton.setMaximumSize(new java.awt.Dimension(20, 20));
151  zoomInButton.setMinimumSize(new java.awt.Dimension(20, 20));
152  zoomInButton.setPreferredSize(new java.awt.Dimension(20, 20));
153  zoomInButton.setRolloverEnabled(true);
154  zoomInButton.addActionListener(new java.awt.event.ActionListener() {
155  public void actionPerformed(java.awt.event.ActionEvent evt) {
156  zoomInButtonActionPerformed(evt);
157  }
158  });
159 
160  jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
161  jSeparator2.setMaximumSize(new java.awt.Dimension(6, 20));
162 
163  org.openide.awt.Mnemonics.setLocalizedText(zoomResetButton, org.openide.util.NbBundle.getMessage(TextZoomPanel.class, "TextZoomPanel.zoomResetButton.text")); // NOI18N
164  zoomResetButton.setBorderPainted(false);
165  zoomResetButton.setFocusable(false);
166  zoomResetButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
167  zoomResetButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
168  zoomResetButton.setMinimumSize(new java.awt.Dimension(50, 20));
169  zoomResetButton.setPreferredSize(new java.awt.Dimension(70, 20));
170  zoomResetButton.addActionListener(new java.awt.event.ActionListener() {
171  public void actionPerformed(java.awt.event.ActionEvent evt) {
172  zoomResetButtonActionPerformed(evt);
173  }
174  });
175 
176  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
177  this.setLayout(layout);
178  layout.setHorizontalGroup(
179  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
180  .addGroup(layout.createSequentialGroup()
181  .addComponent(zoomTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
182  .addGap(0, 0, 0)
183  .addComponent(zoomOutButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
184  .addGap(0, 0, 0)
185  .addComponent(zoomInButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
186  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
187  .addComponent(zoomResetButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
188  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
189  .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
190  );
191  layout.setVerticalGroup(
192  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
193  .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
194  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
195  .addComponent(zoomTextField, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
196  .addComponent(zoomOutButton, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
197  .addComponent(zoomInButton, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
198  .addComponent(zoomResetButton, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
199  );
200  }// </editor-fold>//GEN-END:initComponents
201 
202  private void zoomOutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomOutButtonActionPerformed
203  zoomDecrement();
204  }//GEN-LAST:event_zoomOutButtonActionPerformed
205 
206  private void zoomInButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomInButtonActionPerformed
207  zoomIncrement();
208  }//GEN-LAST:event_zoomInButtonActionPerformed
209 
210  private void zoomResetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomResetButtonActionPerformed
211  resetSize();
212  }//GEN-LAST:event_zoomResetButtonActionPerformed
213 
214 
215  // Variables declaration - do not modify//GEN-BEGIN:variables
216  private javax.swing.JButton zoomInButton;
217  private javax.swing.JButton zoomOutButton;
218  private javax.swing.JButton zoomResetButton;
219  private javax.swing.JTextField zoomTextField;
220  // End of variables declaration//GEN-END:variables
221 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.