/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.ui;

import java.awt.Component;
import java.awt.Font;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.plaf.FontUIResource;

/**
 * @author Sergey.Malenkov
 */
public final class RelativeFont implements PropertyChangeListener {
  private static final String PROPERTY = "font";

  public static final RelativeFont PLAIN = new RelativeFont(Font.PLAIN, 0);
  public static final RelativeFont BOLD = new RelativeFont(Font.BOLD, 0);
  public static final RelativeFont LARGE = new RelativeFont(1f);
  public static final RelativeFont SMALL = new RelativeFont(-1f);
  public static final RelativeFont HUGE = new RelativeFont(2f);
  public static final RelativeFont TINY = new RelativeFont(-2f);

  private final int myStyle;
  private final float mySize;

  public RelativeFont(float size) {
    this.myStyle = -1;
    this.mySize = size;
  }

  public RelativeFont(int style, float size) {
    this.myStyle = style & (Font.BOLD | Font.ITALIC);
    this.mySize = size;
    if (style != myStyle) {
      throw new IllegalArgumentException("style");
    }
  }

  public <T extends Component> T install(T component) {
    Font font = derive(component.getFont());
    if (font != null) {
      component.setFont(new MyFont(font));
    }
    component.addPropertyChangeListener(PROPERTY, this);
    return component;
  }

  public Font derive(Font font) {
    if (font != null) {
      if (-1 != myStyle && myStyle != font.getStyle()) {
        return mySize != 0
               ? font.deriveFont(myStyle, mySize + font.getSize2D())
               : font.deriveFont(myStyle);
      }
      if (mySize != 0) {
        return font.deriveFont(mySize + font.getSize2D());
      }
    }
    return font;
  }

  @Override
  public void propertyChange(PropertyChangeEvent event) {
    if (!(event.getNewValue() instanceof MyFont) && (event.getSource() instanceof Component) && PROPERTY.equals(event.getPropertyName())) {
      Component component = (Component)event.getSource();
      Font font = derive(event.getNewValue() instanceof Font ? (Font)event.getNewValue() : component.getFont());
      if (font != null) {
        component.setFont(new MyFont(font));
      }
    }
  }

  private static final class MyFont extends FontUIResource {
    private MyFont(Font font) {
      super(font);
    }
  }
}

@@ -833,27 +833,20 @@
 %0Apublic 
-final class
+enum
  Relativ
@@ -893,115 +893,13 @@
 %7B%0A  
-private static final String PROPERTY = %22font%22;%0A%0A  public static final RelativeFont PLAIN = new RelativeFont
+PLAIN
 (Fon
@@ -913,68 +913,16 @@
 , 0)
-;%0A  public static final RelativeFont BOLD = new RelativeFont
+,%0A  BOLD
 (Fon
@@ -935,213 +935,72 @@
 , 0)
-;%0A  public static final RelativeFont LARGE = new RelativeFont
+,%0A  LARGE
 (1f)
-;%0A  public static final RelativeFont SMALL = new RelativeFont
+,%0A  SMALL
 (-1f)
-;%0A  public static final RelativeFont HUGE = new RelativeFont(
+,%0A  HUGE(2f),%0A  TINY(-
 2f);%0A
+%0A
   p
-ublic
+rivate
  sta
@@ -1013,49 +1013,32 @@
 nal 
-RelativeFont TINY = new RelativeFont(-2f)
+String PROPERTY = %22font%22
 ;%0A%0A 
@@ -1094,31 +1094,24 @@
  mySize;%0A%0A  
-public 
 RelativeFont
@@ -1179,23 +1179,16 @@
 %0A  %7D%0A%0A  
-public 
 Relative
@@ -1299,93 +1299,8 @@
 ze;%0A
-    if (style != myStyle) %7B%0A      throw new IllegalArgumentException(%22style%22);%0A    %7D%0A
   %7D%0A

Convert the RelativeFont class to enum