/**
  * Creates all controls and adds them to the frame.
  *
  * @param modeController
  */
 private void init() {
   if (mControls != null) return;
   final String form = "right:max(20dlu;p), 2dlu, p, 1dlu,right:max(20dlu;p), 4dlu, 80dlu, 7dlu";
   final FormLayout rightLayout = new FormLayout(form, "");
   final DefaultFormBuilder rightBuilder = new DefaultFormBuilder(rightLayout);
   rightBuilder.setBorder(Borders.DLU2_BORDER);
   rightBuilder.appendSeparator(TextUtils.getText("OptionPanel.separator.NodeStyle"));
   if (addStyleBox) {
     addAutomaticLayout(rightBuilder);
     addStyleBox(rightBuilder);
   }
   mNodeStyleButton =
       addStyleButton(
           rightBuilder,
           "actual_node_styles",
           modeController.getAction(ManageNodeConditionalStylesAction.NAME));
   if (addStyleBox) {
     mMapStyleButton =
         addStyleButton(
             rightBuilder,
             "actual_map_styles",
             modeController.getAction(ManageMapConditionalStylesAction.NAME));
   }
   mControls = getControls();
   for (final IPropertyControl control : mControls) {
     control.layout(rightBuilder);
   }
   add(rightBuilder.getPanel(), BorderLayout.CENTER);
   addListeners();
   setFont(this, 10);
 }
  private void buildLayout(String hostProgramTitle) {
    DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("fill:p:grow"));

    b.append(
        "<html>The following programs are needed for full functionality of "
            + hostProgramTitle
            + ".<br>"
            + "Install the external program first, then click 'relocate'.<br>"
            + "If the program is installed but cannot be found, double-click on the program to assign its location manually.</html>");

    model = new DefaultListModel();
    for (Binary bin : binaries) model.addElement(bin);
    list = new JList(model);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setFont(list.getFont().deriveFont(Font.PLAIN));
    list.setVisibleRowCount(4);
    list.setCellRenderer(
        new DefaultListCellRenderer() {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            JLabel l =
                (JLabel)
                    super.getListCellRendererComponent(
                        list, value, index, isSelected, cellHasFocus);
            Binary b = (Binary) value;
            String found = "";
            if (b.isFound()) {
              l.setIcon(ImageLoader.getImage(ImageLoader.Image.ok));
              found = b.getLocation();
            } else {
              l.setIcon(ImageLoader.getImage(ImageLoader.Image.error));
              found = "<b>Not found</b>";
            }
            l.setText(
                "<html><b>"
                    + b.getDescription()
                    + "</b><br><table><tr><td>Program:</td><td>"
                    + b.getCommand()
                    + "</td></tr><tr><td>Location:</td><td>"
                    + found
                    + "</td></tr></html>");

            l.setBorder(new EmptyBorder(5, 0, 5, 0));

            return l;
          }
        });
    b.append(new JScrollPane(list));

    close = new JButton("Close");
    relocate = new JButton("Relocate program automatically.");
    JPanel buttons = ButtonBarFactory.buildRightAlignedBar(relocate, close);
    b.append(buttons);

    b.setBorder(new EmptyBorder(10, 10, 10, 10));

    setLayout(new BorderLayout());
    add(b.getPanel());
  }
  public void init(BarFormat format) {
    if (format == null) return;
    FormFormat form = format.getForm();
    if (form == null) return;
    List boxes = form.getBoxes();
    if (boxes == null || boxes.size() == 0) {
      return;
    }
    FormBoxLayout formBoxLayout = form.getLayout(zoom);
    FormLayout layout = new FormLayout(formBoxLayout.getColumnGrid(), formBoxLayout.getRowGrid());
    /// DefaultFormBuilder builder = new DefaultFormBuilder(this,layout);
    DefaultFormBuilder builder = new DefaultFormBuilder(layout, this);
    if (formBoxLayout.getBorder() == null) builder.setDefaultDialogBorder();
    else builder.setBorder(Borders.createEmptyBorder(formBoxLayout.getBorder()));
    CellConstraints cc = new CellConstraints();
    for (Iterator i = boxes.iterator(); i.hasNext(); ) {
      FormBox box = (FormBox) i.next();
      if (zoom < box.getMinZoom()) return;
      JComponent component;
      if (box.getFieldId() == null) component = new JLabel(Messages.getString(box.getTextId()));
      else {
        if (editor && !box.getField().isReadOnly()) {
          component = new ChangeAwareTextField();
          component.setBorder(null);
          // component.setOpaque(false);
        } else component = new JLabel();

        // if (box.getRow()==1&&!editor)
        // ((JLabel)component).setHorizontalAlignment(SwingConstants.CENTER);
        // bug workaround, not possible to center with classic method when rowSpan>1

        fieldComponents.put(box.getFieldId(), component);
      }
      Font font = formBoxLayout.getFont(box.getFont());
      if (font != null) component.setFont(font);
      String ba = box.getAlignment();
      int bc = box.getColumn();
      int br = box.getRow();
      int bcs = box.getColumnSpan();
      int brs = box.getRowSpan();
      try {
        builder.add(
            component, (ba == null) ? cc.xywh(bc, br, bcs, brs) : cc.xywh(bc, br, bcs, brs, ba));
      } catch (IndexOutOfBoundsException e) {
        log.fatal("box.Column(): " + bc);
        log.fatal("box.Row(): " + br);
        log.fatal("box.ColumnSpan(): " + bcs);
        log.fatal("box.RowSpan(): " + brs);
        log.fatal("box.Alignment(): " + ba);
        log.fatal("Occur Error: ", e);
      }
    }
  }
  public static JPanel getPanel() {
    FormLayout lm =
        new FormLayout(
            "fill:pref, 2dlu, fill:pref, 0dlu, fill:min:grow, 0dlu, fill:pref, 2dlu, fill:pref",
            "");
    DefaultFormBuilder builder = new DefaultFormBuilder(lm);
    builder.setBorder(new EmptyBorder(0, 0, 0, 0));

    final JLabel fontSizeLabel = new JLabel();
    fontSizeLabel.setText(
        SubstanceLookAndFeel.getFontPolicy()
                .getFontSet("Substance", null)
                .getControlFont()
                .getSize()
            + " pt.");
    builder.append(fontSizeLabel);
    // fontSizeLabel.add(Box.createHorizontalStrut(5));

    Icon zoomOutIcon = Check.configure(new View_zoom_out(), 16);
    JLabel zoomOutLabel = new JLabel(zoomOutIcon);
    builder.append(zoomOutLabel);

    final JSlider fontSizeSlider = new JSlider(0, 10, 0);
    fontSizeSlider.setFocusable(false);
    // fontSizeSlider.setOpaque(false);
    fontSizeSlider.setToolTipText(
        "Controls the global font set size. Resets Substance as the current LAF.");
    fontSizeSlider.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            // if the value is adjusting - ignore. This is done
            // to make CPU usage better.
            if (!fontSizeSlider.getModel().getValueIsAdjusting()) {
              final int newValue = fontSizeSlider.getValue();
              SwingUtilities.invokeLater(
                  new Runnable() {
                    public void run() {
                      SubstanceLookAndFeel.setFontPolicy(null);
                      final FontSet substanceCoreFontSet =
                          SubstanceLookAndFeel.getFontPolicy().getFontSet("Substance", null);
                      FontPolicy newFontPolicy =
                          new FontPolicy() {
                            public FontSet getFontSet(String lafName, UIDefaults table) {
                              return new WrapperFontSet(substanceCoreFontSet, newValue);
                            }
                          };

                      SubstanceLookAndFeel.setFontPolicy(newFontPolicy);

                      fontSizeLabel.setText(
                          SubstanceLookAndFeel.getFontPolicy()
                                  .getFontSet("Substance", null)
                                  .getControlFont()
                                  .getSize()
                              + " pt.");
                    }
                  });
            }
          }
        });
    builder.append(fontSizeSlider);

    Icon zoomInIcon = Check.configure(new View_zoom_in(), 16);
    JLabel zoomInLabel = new JLabel(zoomInIcon);
    builder.append(zoomInLabel);

    JButton tahoma = new JButton("Tahoma 11");
    tahoma.putClientProperty(SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE);
    tahoma.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    SubstanceLookAndFeel.setFontPolicy(null);
                    FontPolicy newFontPolicy =
                        new FontPolicy() {
                          public FontSet getFontSet(String lafName, UIDefaults table) {
                            return new Tahoma11FontSet();
                          }
                        };

                    SubstanceLookAndFeel.setFontPolicy(newFontPolicy);

                    fontSizeLabel.setText(
                        SubstanceLookAndFeel.getFontPolicy()
                                .getFontSet("Substance", null)
                                .getControlFont()
                                .getSize()
                            + " pt.");
                  }
                });
          }
        });
    builder.append(tahoma);

    JPanel result = builder.getPanel();
    // result.setOpaque(false);
    return result;
  }