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 javax.swing.JToolBar.Separator jSeparator2 =
new javax.swing.JToolBar.Separator();
117 zoomResetButton =
new javax.swing.JButton();
119 setMinimumSize(
new java.awt.Dimension(150, 20));
120 setPreferredSize(
new java.awt.Dimension(200, 20));
122 zoomTextField.setEditable(
false);
123 zoomTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
124 zoomTextField.setText(
org.openide.util.NbBundle.getMessage(TextZoomPanel.class,
"TextZoomPanel.zoomTextField.text"));
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));
129 zoomOutButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/zoom-out.png")));
130 org.openide.awt.Mnemonics.setLocalizedText(zoomOutButton,
org.openide.util.NbBundle.getMessage(TextZoomPanel.class,
"TextZoomPanel.zoomOutButton.text"));
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);
144 zoomInButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/zoom-in.png")));
145 org.openide.awt.Mnemonics.setLocalizedText(zoomInButton,
org.openide.util.NbBundle.getMessage(TextZoomPanel.class,
"TextZoomPanel.zoomInButton.text"));
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);
160 jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
161 jSeparator2.setMaximumSize(
new java.awt.Dimension(6, 20));
163 org.openide.awt.Mnemonics.setLocalizedText(zoomResetButton,
org.openide.util.NbBundle.getMessage(TextZoomPanel.class,
"TextZoomPanel.zoomResetButton.text"));
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);
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)
183 .addComponent(zoomOutButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
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))
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))
202 private void zoomOutButtonActionPerformed(java.awt.event.ActionEvent evt) {
206 private void zoomInButtonActionPerformed(java.awt.event.ActionEvent evt) {
210 private void zoomResetButtonActionPerformed(java.awt.event.ActionEvent evt) {
216 private javax.swing.JButton zoomInButton;
217 private javax.swing.JButton zoomOutButton;
218 private javax.swing.JButton zoomResetButton;
219 private javax.swing.JTextField zoomTextField;