19 package org.sleuthkit.autopsy.keywordsearch;
 
   21 import javax.swing.JLabel;
 
   22 import javax.swing.JPanel;
 
   23 import org.openide.util.NbBundle;
 
   28 class TextZoomPanel 
extends JPanel {
 
   29     static final int DEFAULT_SIZE = 
new JLabel().getFont().getSize();
 
   31     private static final long serialVersionUID = 1L;
 
   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};
 
   38     private static final int DEFAULT_STEP_IDX = 6;
 
   41     private final ResizableTextPanel zoomable;
 
   44     private int curStepIndex = DEFAULT_STEP_IDX;
 
   51     TextZoomPanel(ResizableTextPanel zoomable) {
 
   52         this.zoomable = zoomable;
 
   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);
 
   71     synchronized void resetSize() {
 
   72         zoomStep(DEFAULT_STEP_IDX);
 
   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));
 
   83     private synchronized void zoomDecrement() {
 
   84         zoomStep(curStepIndex - 1);
 
   87     private synchronized void zoomIncrement() {
 
   88         zoomStep(curStepIndex + 1);
 
   91     private void setZoomText() {
 
   92         String percent = Long.toString(Math.round(ZOOM_STEPS[
this.curStepIndex] * 100));
 
   93         zoomTextField.setText(percent + 
"%");
 
   99         "TextZoomPanel.zoomTextField.text=",
 
  100         "TextZoomPanel.zoomOutButton.text=",
 
  101         "TextZoomPanel.zoomInButton.text=",
 
  102         "TextZoomPanel.zoomResetButton.text=Reset" 
  109     @SuppressWarnings(
"unchecked")
 
  111     private void initComponents() {
 
  113         zoomTextField = 
new javax.swing.JTextField();
 
  114         zoomOutButton = 
new javax.swing.JButton();
 
  115         zoomInButton = 
new javax.swing.JButton();
 
  116         zoomResetButton = 
new javax.swing.JButton();
 
  118         setMaximumSize(null);
 
  119         setMinimumSize(null);
 
  121         setPreferredSize(null);
 
  122         setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
 
  124         zoomTextField.setEditable(
false);
 
  125         zoomTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
 
  126         zoomTextField.setText(
org.openide.util.NbBundle.getMessage(TextZoomPanel.class, 
"TextZoomPanel.zoomTextField.text")); 
 
  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));
 
  132         zoomOutButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/zoom-out.png"))); 
 
  133         org.openide.awt.Mnemonics.setLocalizedText(zoomOutButton, 
org.openide.util.NbBundle.getMessage(TextZoomPanel.class, 
"TextZoomPanel.zoomOutButton.text")); 
 
  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);
 
  148         zoomInButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/zoom-in.png"))); 
 
  149         org.openide.awt.Mnemonics.setLocalizedText(zoomInButton, 
org.openide.util.NbBundle.getMessage(TextZoomPanel.class, 
"TextZoomPanel.zoomInButton.text")); 
 
  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);
 
  165         org.openide.awt.Mnemonics.setLocalizedText(zoomResetButton, 
org.openide.util.NbBundle.getMessage(TextZoomPanel.class, 
"TextZoomPanel.zoomResetButton.text")); 
 
  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);
 
  177         add(zoomResetButton);
 
  180     private void zoomOutButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  184     private void zoomInButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  188     private void zoomResetButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  194     private javax.swing.JButton zoomInButton;
 
  195     private javax.swing.JButton zoomOutButton;
 
  196     private javax.swing.JButton zoomResetButton;
 
  197     private javax.swing.JTextField zoomTextField;