/** Set labels with localized strings. */
  public void setLabels() {

    initGUI();
    updateStyleBar();

    btnShowGrid.setToolTipText(app.getPlainTooltip("stylebar.Grid"));
    btnShowAxes.setToolTipText(app.getPlainTooltip("stylebar.Axes"));
    btnPointCapture.setToolTipText(app.getPlainTooltip("stylebar.Capture"));

    btnLabelStyle.setToolTipText(app.getPlainTooltip("stylebar.Label"));

    btnColor.setToolTipText(app.getPlainTooltip("stylebar.Color"));
    btnBgColor.setToolTipText(app.getPlainTooltip("stylebar.BgColor"));

    btnLineStyle.setToolTipText(app.getPlainTooltip("stylebar.LineStyle"));
    btnPointStyle.setToolTipText(app.getPlainTooltip("stylebar.PointStyle"));

    btnTextColor.setToolTipText(app.getPlainTooltip("stylebar.TextColor"));
    btnTextSize.setToolTipText(app.getPlainTooltip("stylebar.TextSize"));
    btnBold.setToolTipText(app.getPlainTooltip("stylebar.Bold"));
    btnItalic.setToolTipText(app.getPlainTooltip("stylebar.Italic"));
    btnTableTextJustify.setToolTipText(app.getPlainTooltip("stylebar.Align"));
    btnTableTextBracket.setToolTipText(app.getPlainTooltip("stylebar.Bracket"));
    btnTableTextLinesV.setToolTipText(app.getPlainTooltip("stylebar.HorizontalLine"));
    btnTableTextLinesH.setToolTipText(app.getPlainTooltip("stylebar.VerticalLine"));

    btnPen.setToolTipText(app.getPlainTooltip("stylebar.Pen"));
    btnFixPosition.setToolTipText(app.getPlain("AbsoluteScreenLocation"));

    btnDeleteSize.setToolTipText(app.getPlain("Size"));
  }
  /**
   * Creates new dialog
   *
   * @param app application
   */
  public ToolbarConfigDialog(AppD app) {
    super(app.getFrame(), false);
    this.app = app;

    setTitle(app.getMenu("Toolbar.Customize"));

    // list with panels
    JComboBox switcher = new JComboBox();
    switcher.addItem(new KeyValue(-1, app.getPlain("General")));

    DockPanel[] panels =
        ((LayoutD) ((GuiManagerD) app.getGuiManager()).getLayout()).getDockManager().getPanels();

    for (DockPanel panel : panels) {
      if (panel.hasToolbar()) {
        switcher.addItem(new KeyValue(panel.getViewId(), app.getPlain(panel.getViewTitle())));
      }
    }

    switcher.addActionListener(this); // add at the end to not be notified about items being added

    JPanel switcherPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    switcherPanel.add(switcher);

    getContentPane().setLayout(new BorderLayout(5, 5));
    getContentPane().add(switcherPanel, BorderLayout.NORTH);
    confPanel = new ToolbarConfigPanel(app);
    getContentPane().add(confPanel, BorderLayout.CENTER);
    getContentPane().add(createButtonPanel(), BorderLayout.SOUTH);

    pack();
    setLocationRelativeTo(app.getFrame());
  }
  private JPanel createButtonPanel() {
    JPanel btPanel = new JPanel();
    btPanel.setLayout(new BoxLayout(btPanel, BoxLayout.X_AXIS));
    btPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));

    /*
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    model.addElement(app.getMenu("Toolbar.Default"));
    //model.addElement(app.getMenu("Basic"));
    model.addElement(app.getMenu("Toolbar.UserDefined"));
    JComboBox cbToolbar = new JComboBox(model);
    */

    final JButton btDefaultToolbar = new JButton();
    btPanel.add(btDefaultToolbar);
    btDefaultToolbar.setText(app.getMenu("Toolbar.ResetDefault"));

    btPanel.add(Box.createHorizontalGlue());
    final JButton btApply = new JButton();
    btPanel.add(btApply);
    btApply.setText(app.getPlain("Apply"));

    final JButton btCancel = new JButton();
    btPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    btPanel.add(btCancel);
    btCancel.setText(app.getPlain("Cancel"));

    ActionListener ac =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Object src = e.getSource();
            if (src == btApply) {
              apply();
            } else if (src == btCancel) {
              setVisible(false);
              dispose();
            } else if (src == btDefaultToolbar) {
              confPanel.resetDefaultToolbar();
            }
          }
        };
    btCancel.addActionListener(ac);
    btApply.addActionListener(ac);
    btDefaultToolbar.addActionListener(ac);

    return btPanel;
  }
  protected void createButtons() {

    // ========================================
    // mode button

    ImageIcon[] modeArray =
        new ImageIcon[] {
          app.getImageIcon("cursor_arrow.png"),
          app.getImageIcon("applications-graphics.png"),
          app.getImageIcon("delete_small.gif"),
          app.getImageIcon("mode_point_16.gif"),
          app.getImageIcon("mode_copyvisualstyle_16.png")
        };

    // ========================================
    // pen button
    btnPen =
        new MyToggleButton(
            ((AppD) ev.getApplication()).getImageIcon("applications-graphics.png"), iconHeight) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            this.setVisible(
                (geos.length == 0 && mode == EuclidianConstants.MODE_MOVE)
                    || EuclidianView.isPenMode(mode));
          }
        };
    btnPen.addActionListener(this);
    // add(btnPen);

    // ========================================
    // delete button
    btnDelete =
        new MyToggleButton(
            ((AppD) ev.getApplication()).getImageIcon("delete_small.gif"), iconHeight) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            this.setVisible(
                (geos.length == 0 && mode == EuclidianConstants.MODE_MOVE)
                    || mode == EuclidianConstants.MODE_DELETE);
          }
        };
    btnDelete.addActionListener(this);
    add(btnDelete);

    // ========================================
    // delete-drag square size
    btnDeleteSize =
        new PopupMenuButton(app, null, 0, 0, iconDimension, 0, false, true) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            this.setVisible(mode == EuclidianConstants.MODE_DELETE);
          }
        };
    btnDeleteSize.getMySlider().setMinimum(10);
    btnDeleteSize.getMySlider().setMaximum(100);
    btnDeleteSize.getMySlider().setMajorTickSpacing(20);
    btnDeleteSize.getMySlider().setMinorTickSpacing(5);
    btnDeleteSize.getMySlider().setPaintTicks(true);
    btnDeleteSize.addActionListener(this);
    btnDeleteSize.setIcon(app.getImageIcon("delete_small.gif"));

    // ========================================
    // show axes button
    btnShowAxes =
        new MyToggleButton(app.getImageIcon("axes.gif"), iconHeight) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            // always show this button unless in pen mode
            this.setVisible(!EuclidianView.isPenMode(mode));
          }
        };

    // btnShowAxes.setPreferredSize(new Dimension(16,16));
    btnShowAxes.addActionListener(this);

    // ========================================
    // show grid button
    btnShowGrid =
        new MyToggleButton(app.getImageIcon("grid.gif"), iconHeight) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            // always show this button unless in pen mode
            this.setVisible(!EuclidianView.isPenMode(mode));
          }
        };
    // btnShowGrid.setPreferredSize(new Dimension(16,16));
    btnShowGrid.addActionListener(this);

    // ========================================
    // line style button

    // create line style icon array
    final Dimension lineStyleIconSize = new Dimension(80, iconHeight);
    ImageIcon[] lineStyleIcons = new ImageIcon[EuclidianStyleBarStatic.lineStyleArray.length];
    for (int i = 0; i < EuclidianStyleBarStatic.lineStyleArray.length; i++)
      lineStyleIcons[i] =
          GeoGebraIcon.createLineStyleIcon(
              EuclidianStyleBarStatic.lineStyleArray[i], 2, lineStyleIconSize, Color.BLACK, null);

    // create button
    btnLineStyle =
        new PopupMenuButton(
            app,
            lineStyleIcons,
            -1,
            1,
            lineStyleIconSize,
            geogebra.common.gui.util.SelectionTable.MODE_ICON) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {

            if (EuclidianView.isPenMode(mode)) {
              this.setVisible(true);
              setFgColor(geogebra.awt.GColorD.getAwtColor(ec.getPen().getPenColor()));
              setSliderValue(ec.getPen().getPenSize());
              setSelectedIndex(lineStyleMap.get(ec.getPen().getPenLineStyle()));
            } else {
              boolean geosOK = (geos.length > 0);
              for (int i = 0; i < geos.length; i++) {
                GeoElement geo = ((GeoElement) geos[i]).getGeoElementForPropertiesDialog();
                if (!(geo.isPath()
                    || (geo.isGeoList() ? ((GeoList) geo).showLineProperties() : false)
                    || (geo.isGeoNumeric()
                        ? (((GeoNumeric) geo).isDrawable() || ((GeoNumeric) geo).isSliderFixed())
                        : false)
                    || geo.isGeoAngle())) {
                  geosOK = false;
                  break;
                }
              }

              this.setVisible(geosOK);

              if (geosOK) {
                // setFgColor(((GeoElement)geos[0]).getObjectColor());

                setFgColor(Color.black);
                setSliderValue(((GeoElement) geos[0]).getLineThickness());

                setSelectedIndex(lineStyleMap.get(((GeoElement) geos[0]).getLineType()));

                this.setKeepVisible(mode == EuclidianConstants.MODE_MOVE);
              }
            }
          }

          @Override
          public ImageIcon getButtonIcon() {
            if (getSelectedIndex() > -1) {
              return GeoGebraIcon.createLineStyleIcon(
                  EuclidianStyleBarStatic.lineStyleArray[this.getSelectedIndex()],
                  this.getSliderValue(),
                  lineStyleIconSize,
                  Color.BLACK,
                  null);
            }
            return GeoGebraIcon.createEmptyIcon(lineStyleIconSize.width, lineStyleIconSize.height);
          }
        };

    btnLineStyle.getMySlider().setMinimum(1);
    btnLineStyle.getMySlider().setMaximum(13);
    btnLineStyle.getMySlider().setMajorTickSpacing(2);
    btnLineStyle.getMySlider().setMinorTickSpacing(1);
    btnLineStyle.getMySlider().setPaintTicks(true);
    btnLineStyle.setStandardButton(true); // popup on the whole button
    btnLineStyle.addActionListener(this);

    // ========================================
    // point style button

    // create line style icon array
    final Dimension pointStyleIconSize = new Dimension(20, iconHeight);
    ImageIcon[] pointStyleIcons = new ImageIcon[EuclidianStyleBarStatic.pointStyleArray.length];
    for (int i = 0; i < EuclidianStyleBarStatic.pointStyleArray.length; i++)
      pointStyleIcons[i] =
          GeoGebraIcon.createPointStyleIcon(
              EuclidianStyleBarStatic.pointStyleArray[i], 4, pointStyleIconSize, Color.BLACK, null);

    // create button
    btnPointStyle =
        new PopupMenuButton(
            app,
            pointStyleIcons,
            2,
            -1,
            pointStyleIconSize,
            geogebra.common.gui.util.SelectionTable.MODE_ICON) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            GeoElement geo;
            boolean geosOK = (geos.length > 0);
            for (int i = 0; i < geos.length; i++) {
              geo = (GeoElement) geos[i];
              if (!(geo.getGeoElementForPropertiesDialog().isGeoPoint())
                  && (!(geo.isGeoList() && ((GeoList) geo).showPointProperties()))) {
                geosOK = false;
                break;
              }
            }
            this.setVisible(geosOK);

            if (geosOK) {
              // setFgColor(((GeoElement)geos[0]).getObjectColor());
              setFgColor(Color.black);

              // if geo is a matrix, this will return a GeoNumeric...
              geo = ((GeoElement) geos[0]).getGeoElementForPropertiesDialog();

              // ... so need to check
              if (geo instanceof PointProperties) {
                setSliderValue(((PointProperties) geo).getPointSize());
                int pointStyle = ((PointProperties) geo).getPointStyle();
                if (pointStyle == -1) // global default point style
                pointStyle = EuclidianStyleConstants.POINT_STYLE_DOT;
                setSelectedIndex(pointStyleMap.get(pointStyle));
                this.setKeepVisible(mode == EuclidianConstants.MODE_MOVE);
              }
            }
          }

          @Override
          public ImageIcon getButtonIcon() {
            if (getSelectedIndex() > -1) {
              return GeoGebraIcon.createPointStyleIcon(
                  EuclidianStyleBarStatic.pointStyleArray[this.getSelectedIndex()],
                  this.getSliderValue(),
                  pointStyleIconSize,
                  Color.BLACK,
                  null);
            }
            return GeoGebraIcon.createEmptyIcon(
                pointStyleIconSize.width, pointStyleIconSize.height);
          }
        };
    btnPointStyle.getMySlider().setMinimum(1);
    btnPointStyle.getMySlider().setMaximum(9);
    btnPointStyle.getMySlider().setMajorTickSpacing(2);
    btnPointStyle.getMySlider().setMinorTickSpacing(1);
    btnPointStyle.getMySlider().setPaintTicks(true);
    btnPointStyle.setStandardButton(true); // popup on the whole button
    btnPointStyle.addActionListener(this);

    // ========================================
    // caption style button

    String[] captionArray =
        new String[] {
          app.getPlain("stylebar.Hidden"), // index
          // 4
          app.getPlain("Name"), // index 0
          app.getPlain("NameAndValue"), // index 1
          app.getPlain("Value"), // index 2
          app.getPlain("Caption") // index 3
        };

    btnLabelStyle =
        new PopupMenuButton(
            app,
            captionArray,
            -1,
            1,
            new Dimension(0, iconHeight),
            geogebra.common.gui.util.SelectionTable.MODE_TEXT) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            boolean geosOK = false;
            GeoElement geo = null;
            if (mode == EuclidianConstants.MODE_MOVE) {
              for (int i = 0; i < geos.length; i++) {
                if (((GeoElement) geos[i]).isLabelShowable()
                    || ((GeoElement) geos[i]).isGeoAngle()
                    || (((GeoElement) geos[i]).isGeoNumeric()
                        ? ((GeoNumeric) geos[i]).isSliderFixed()
                        : false)) {
                  geo = (GeoElement) geos[i];
                  geosOK = true;
                  break;
                }
              }
            } else if (app.getLabelingStyle() == ConstructionDefaults.LABEL_VISIBLE_ALWAYS_OFF) {
              this.setVisible(false);
              return;
            } else if (app.getLabelingStyle() == ConstructionDefaults.LABEL_VISIBLE_POINTS_ONLY) {
              for (int i = 0; i < geos.length; i++) {
                if (((GeoElement) geos[i]).isLabelShowable()
                    && ((GeoElement) geos[i]).isGeoPoint()) {
                  geo = (GeoElement) geos[i];
                  geosOK = true;
                  break;
                }
              }
            } else {
              for (int i = 0; i < geos.length; i++) {
                if (((GeoElement) geos[i]).isLabelShowable()
                    || ((GeoElement) geos[i]).isGeoAngle()
                    || (((GeoElement) geos[i]).isGeoNumeric()
                        ? ((GeoNumeric) geos[i]).isSliderFixed()
                        : false)) {
                  geo = (GeoElement) geos[i];
                  geosOK = true;
                  break;
                }
              }
            }
            this.setVisible(geosOK);

            if (geosOK) {
              if (!geo.isLabelVisible()) setSelectedIndex(0);
              else setSelectedIndex(geo.getLabelMode() + 1);
            }
          }

          @Override
          public ImageIcon getButtonIcon() {
            return (ImageIcon) this.getIcon();
          }
        };
    ImageIcon ic = app.getImageIcon("mode_showhidelabel_16.gif");
    btnLabelStyle.setIconSize(new Dimension(ic.getIconWidth(), iconHeight));
    btnLabelStyle.setIcon(ic);
    btnLabelStyle.setStandardButton(true);
    btnLabelStyle.addActionListener(this);
    btnLabelStyle.setKeepVisible(false);

    // ========================================
    // point capture button

    String[] strPointCapturing = {
      app.getMenu("Labeling.automatic"),
      app.getMenu("SnapToGrid"),
      app.getMenu("FixedToGrid"),
      app.getMenu("off")
    };

    btnPointCapture =
        new PopupMenuButton(
            app,
            strPointCapturing,
            -1,
            1,
            new Dimension(0, iconHeight),
            geogebra.common.gui.util.SelectionTable.MODE_TEXT) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            // always show this button unless in pen mode
            this.setVisible(!EuclidianView.isPenMode(mode));
          }

          @Override
          public ImageIcon getButtonIcon() {
            return (ImageIcon) this.getIcon();
          }
        };
    ImageIcon ptCaptureIcon = app.getImageIcon("magnet2.gif");
    btnPointCapture.setIconSize(new Dimension(ptCaptureIcon.getIconWidth(), iconHeight));
    btnPointCapture.setIcon(ptCaptureIcon);
    btnPointCapture.setStandardButton(true); // popup on the whole button
    btnPointCapture.addActionListener(this);
    btnPointCapture.setKeepVisible(false);

    // ========================================
    // fixed position button
    btnFixPosition =
        new MyToggleButton(app.getImageIcon("pin.png"), iconHeight) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {

            boolean geosOK = checkGeos(geos);

            setVisible(geosOK);
            if (geosOK) {
              if (geos[0] instanceof AbsoluteScreenLocateable
                  && !((GeoElement) geos[0]).isGeoList()) {
                AbsoluteScreenLocateable geo =
                    (AbsoluteScreenLocateable)
                        ((GeoElement) geos[0]).getGeoElementForPropertiesDialog();
                btnFixPosition.setSelected(geo.isAbsoluteScreenLocActive());
              } else if (((GeoElement) geos[0]).getParentAlgorithm()
                  instanceof AlgoAttachCopyToView) {
                btnFixPosition.setSelected(true);
              } else {
                btnFixPosition.setSelected(false);
              }
            }
          }

          private boolean checkGeos(Object[] geos) {
            if (geos.length <= 0) {
              return false;
            }

            for (int i = 0; i < geos.length; i++) {
              GeoElement geo = (GeoElement) geos[i];

              if (!geo.isPinnable()) {
                return false;
              }

              if (geo.isGeoSegment()) {
                if (geo.getParentAlgorithm() != null
                    && geo.getParentAlgorithm().getInput().length == 3) {
                  // segment is output from a Polygon
                  return false;
                }
              }
            }
            return true;
          }
        };
    btnFixPosition.addActionListener(this);
  }
  private void createTextButtons() {

    // ========================
    // text color button
    final Dimension textColorIconSize = new Dimension(20, iconHeight);

    btnTextColor =
        new ColorPopupMenuButton(
            app, textColorIconSize, ColorPopupMenuButton.COLORSET_DEFAULT, false) {

          private static final long serialVersionUID = 1L;

          private Color geoColor;

          @Override
          public void update(Object[] geos) {

            boolean geosOK = checkGeoText(geos);
            setVisible(geosOK);

            if (geosOK) {
              GeoElement geo = ((GeoElement) geos[0]).getGeoElementForPropertiesDialog();
              geoColor = geogebra.awt.GColorD.getAwtColor(geo.getObjectColor());
              updateColorTable();

              // find the geoColor in the table and select it
              int index = this.getColorIndex(geoColor);
              setSelectedIndex(index);

              // if nothing was selected, set the icon to show the
              // non-standard color
              if (index == -1) {
                this.setIcon(getButtonIcon());
              }

              setFgColor(geoColor);
              setFontStyle(((TextProperties) geo).getFontStyle());
            }
          }

          @Override
          public ImageIcon getButtonIcon() {
            return GeoGebraIcon.createTextSymbolIcon(
                "A",
                app.getPlainFont(),
                textColorIconSize,
                geogebra.awt.GColorD.getAwtColor(getSelectedColor()),
                null);
          }
        };

    btnTextColor.setStandardButton(true); // popup on the whole button
    btnTextColor.addActionListener(this);

    // ========================================
    // bold text button
    ImageIcon boldIcon =
        GeoGebraIcon.createStringIcon(
            app.getPlain("Bold").substring(0, 1),
            app.getPlainFont(),
            true,
            false,
            true,
            iconDimension,
            Color.black,
            null);
    btnBold =
        new MyToggleButton(boldIcon, iconHeight) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {

            boolean geosOK = checkGeoText(geos);
            setVisible(geosOK);
            if (geosOK) {
              GeoElement geo = ((GeoElement) geos[0]).getGeoElementForPropertiesDialog();
              int style = ((TextProperties) geo).getFontStyle();
              btnBold.setSelected(style == Font.BOLD || style == (Font.BOLD + Font.ITALIC));
            }
          }
        };
    btnBold.addActionListener(this);

    // ========================================
    // italic text button
    ImageIcon italicIcon =
        GeoGebraIcon.createStringIcon(
            app.getPlain("Italic").substring(0, 1),
            app.getPlainFont(),
            false,
            true,
            true,
            iconDimension,
            Color.black,
            null);
    btnItalic =
        new MyToggleButton(italicIcon, iconHeight) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {

            boolean geosOK = checkGeoText(geos);
            setVisible(geosOK);
            this.setVisible(geosOK);
            if (geosOK) {
              GeoElement geo = ((GeoElement) geos[0]).getGeoElementForPropertiesDialog();
              int style = ((TextProperties) geo).getFontStyle();
              btnItalic.setSelected(style == Font.ITALIC || style == (Font.BOLD + Font.ITALIC));
            }
          }
        };
    btnItalic.addActionListener(this);

    // ========================================
    // text size button

    String[] textSizeArray = app.getFontSizeStrings();

    btnTextSize =
        new PopupMenuButton(
            app,
            textSizeArray,
            -1,
            1,
            new Dimension(-1, iconHeight),
            geogebra.common.gui.util.SelectionTable.MODE_TEXT) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {

            boolean geosOK = checkGeoText(geos);
            setVisible(geosOK);

            if (geosOK) {
              GeoElement geo = ((GeoElement) geos[0]).getGeoElementForPropertiesDialog();
              setSelectedIndex(
                  GeoText.getFontSizeIndex(
                      ((TextProperties) geo).getFontSizeMultiplier())); // font size ranges from
              // -4 to 4, transform
              // this to 0,1,..,4
            }
          }
        };
    btnTextSize.addActionListener(this);
    btnTextSize.setStandardButton(true); // popup on the whole button
    btnTextSize.setKeepVisible(false);
  }
 public void setLabels() {
   if (btPlay != null) btPlay.setText(app.getPlain("Play"));
   if (btOpenWindow != null)
     btOpenWindow.setToolTipText(app.getPlainTooltip("ConstructionProtocol"));
 }