Line 17
Link Here
|
|
|
17 |
import java.util.Iterator; |
Line 28
Link Here
|
|
|
29 |
import java.awt.event.InputEvent; |
30 |
import java.awt.event.MouseWheelEvent; |
31 |
import java.lang.ref.Reference; |
32 |
import java.lang.ref.WeakReference; |
33 |
import java.util.HashSet; |
34 |
import java.util.Set; |
35 |
import javax.swing.text.View; |
Line 31
Link Here
|
|
|
39 |
|
40 |
OutputPane() { |
41 |
registry.add (new WeakReference(this)); |
42 |
} |
43 |
|
Line 172
Link Here
|
|
|
185 |
setupFont(true); |
Line 174
Link Here
|
|
|
188 |
} |
189 |
|
190 |
private static Set registry = new HashSet(); |
191 |
|
192 |
static void changeFontSize (boolean positive) { |
193 |
int currFontSize = outputFontSize; |
194 |
int newFontSize = -1; |
195 |
for (Iterator i = registry.iterator(); i.hasNext();) { |
196 |
Reference ref = (Reference) i.next(); |
197 |
OutputPane pane = (OutputPane) ref.get(); |
198 |
if (pane != null) { |
199 |
if (currFontSize == -1) { |
200 |
currFontSize = pane.getFontSize(); |
201 |
} |
202 |
if (newFontSize == -1) { |
203 |
newFontSize = positive? currFontSize + 1 : currFontSize - 1; |
204 |
outputFontSize = Math.min (72, Math.max (6, newFontSize)); |
205 |
} |
206 |
pane.setupFont (false); |
207 |
} else { |
208 |
i.remove(); |
209 |
} |
210 |
} |
211 |
} |
212 |
|
213 |
int getFontSize() { |
214 |
return textView.getFont().getSize(); |
215 |
} |
216 |
|
217 |
public void mouseWheelMoved(MouseWheelEvent e) { |
218 |
if ((e.getModifiersEx() | InputEvent.SHIFT_DOWN_MASK) != 0) { |
219 |
boolean positive = e.getWheelRotation() > 0; |
220 |
changeFontSize (positive); |
221 |
} else { |
222 |
super.mouseWheelMoved(e); |
223 |
} |
224 |
} |
225 |
|
226 |
private static int outputFontSize = -1; |
227 |
private void setupFont (boolean initializing) { |
228 |
if (outputFontSize != -1) { |
229 |
Font f = textView.getFont(); |
230 |
if (f.getSize() != outputFontSize) { |
231 |
float sz = outputFontSize; |
232 |
String fontStr = System.getProperty ("nb.output.font"); |
233 |
if (fontStr != null) { |
234 |
f = new Font (fontStr, Font.PLAIN, textView.getFont().getSize()); |
235 |
} |
236 |
f = f.deriveFont(sz); |
237 |
textView.setFont (f); |
238 |
if (!initializing && textView.getEditorKit() instanceof OutputEditorKit) { |
239 |
OutputEditorKit kit = (OutputEditorKit)textView.getEditorKit(); |
240 |
View v = textView.getUI().getRootView(textView); |
241 |
if (v instanceof WrappedTextView) { |
242 |
((WrappedTextView) v).setChanged(); |
243 |
} |
244 |
if (textView.isShowing()) { |
245 |
textView.repaint(); |
246 |
} |
247 |
} |
248 |
} |
249 |
} |