package info.limpet.stackedcharts.ui.editor.figures;

import org.eclipse.draw2d.ActionListener;
import org.eclipse.draw2d.Button;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Display;

import info.limpet.stackedcharts.ui.editor.Activator;
import info.limpet.stackedcharts.ui.editor.StackedchartsImages;

public class ChartsetFigure extends DirectionalShape
{
  private static volatile Font boldFont;
  private DirectionalLabel chartsetHeader;

  public ChartsetFigure(ActionListener addChartHandler)
  {
    add(new Label(StackedchartsImages.getImage(
        StackedchartsImages.DESC_CHARTSET)));
    chartsetHeader = new DirectionalLabel(Activator.FONT_12);
    chartsetHeader.setText("Chart Set");
    chartsetHeader.setTextAlignment(PositionConstants.TOP);
    if (boldFont == null)
    {
      FontData fontData = Display.getDefault().getActiveShell().getFont()
          .getFontData()[0];
      boldFont = new Font(Display.getDefault(), new FontData(fontData.getName(),
          fontData.getHeight(), SWT.BOLD));
    }
    chartsetHeader.setFont(boldFont);
    add(chartsetHeader);

    Button button = new Button(StackedchartsImages.getImage(
        StackedchartsImages.DESC_ADD));
    button.setToolTip(new Label("Add new chart"));
    button.addActionListener(addChartHandler);
    add(button);

  }

  public void setVertical(boolean vertical)
  {
    super.setVertical(vertical);
    chartsetHeader.setVertical(vertical);
  }

}

@@ -123,16 +123,52 @@
 Button;%0A
+import org.eclipse.draw2d.Graphics;%0A
 import o
@@ -966,312 +966,8 @@
 P);%0A
-    if (boldFont == null)%0A    %7B%0A      FontData fontData = Display.getDefault().getActiveShell().getFont()%0A          .getFontData()%5B0%5D;%0A      boldFont = new Font(Display.getDefault(), new FontData(fontData.getName(),%0A          fontData.getHeight(), SWT.BOLD));%0A    %7D%0A    chartsetHeader.setFont(boldFont);%0A
     
@@ -1340,8 +1340,404 @@
 %0A  %7D
+%0A  %0A  @Override%0A  public void paint(Graphics graphics)%0A  %7B%0A%0A    if (boldFont == null)%0A    %7B%0A      FontData fontData = Display.getDefault().getActiveShell().getFont()%0A          .getFontData()%5B0%5D;%0A      boldFont = new Font(Display.getDefault(), new FontData(fontData.getName(),%0A          fontData.getHeight(), SWT.BOLD));%0A      chartsetHeader.setFont(boldFont);%0A    %7D%0A%0A    super.paint(graphics);%0A  %7D
 %0A%0A%7D
-%0A

fix font initialization when restoring empty stacked chart, issue #355