Eclipseplugins
FontSize.java
1 package com.proalpha.java.oea.plugins.oeaextension.fontsizer;
2 
3 import org.eclipse.core.runtime.preferences.InstanceScope;
4 import org.eclipse.ui.preferences.ScopedPreferenceStore;
5 
6 public class FontSize {
7 
8  private enum Size {
9  INCEASE, DECREASE
10  }
11 
12  private ScopedPreferenceStore store;
13  private static FontSize fontSize;
14 
15  public static FontSize getInstance() {
16 
17  if (fontSize == null)
18  fontSize = new FontSize();
19 
20  return fontSize;
21  }
22 
23  private FontSize() {
24  this.store = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.ui.workbench");
25  }
26 
27  public void increaseFont() {
28  changeFontSize(Size.INCEASE);
29  }
30 
31  public void decreaseFont() {
32  changeFontSize(Size.DECREASE);
33  }
34 
35  private void changeFontSize(Size size) {
36 
37  if (this.store != null) {
38 
39  String font = this.store.getString("org.eclipse.jface.textfont");
40 
41  if (font != null && !"".equals(font)) {
42 
43  try {
44  String[] split = font.split("\\|");
45 
46  float fontSize = 1.0F;
47 
48  if (size == Size.INCEASE)
49  fontSize = Float.parseFloat(split[2]) + 1.0F;
50  else
51  fontSize = Float.parseFloat(split[2]) - 1.0F;
52 
53  // Limit font size
54  if (fontSize <= 0.0F) {
55  fontSize = 1.0F;
56  }
57 
58  split[2] = Float.toString(fontSize);
59  StringBuilder builder = new StringBuilder(split[0]);
60  for (int i = 1; i < split.length; i++) {
61  builder.append('|').append(split[i]);
62  }
63  this.store.setValue("org.eclipse.jface.textfont", builder.toString());
64 
65  } catch (Exception e) {
66  // Just catch the exception and do nothing
67  }
68  }
69  }
70  }
71 
72 }