Esempio n. 1
0
  private void createTableTextButtons() {
    Dimension iconDimension = new Dimension(16, iconHeight);

    // ==============================
    // justification popup
    ImageIcon[] justifyIcons =
        new ImageIcon[] {
          app.getImageIcon("format-justify-left.png"),
          app.getImageIcon("format-justify-center.png"),
          app.getImageIcon("format-justify-right.png")
        };
    btnTableTextJustify =
        new PopupMenuButton(
            (AppD) ev.getApplication(),
            justifyIcons,
            1,
            -1,
            new Dimension(20, iconHeight),
            geogebra.common.gui.util.SelectionTable.MODE_ICON) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            if (tableText != null) {
              this.setVisible(true);
              String justification = tableText.getJustification();
              if (justification.equals("c")) btnTableTextJustify.setSelectedIndex(1);
              else if (justification.equals("r")) btnTableTextJustify.setSelectedIndex(2);
              else btnTableTextJustify.setSelectedIndex(0); // left align

            } else {
              this.setVisible(false);
            }
          }
        };

    btnTableTextJustify.addActionListener(this);
    btnTableTextJustify.setKeepVisible(false);

    // ==============================
    // bracket style popup

    ImageIcon[] bracketIcons = new ImageIcon[EuclidianStyleBarStatic.bracketArray.length];
    for (int i = 0; i < bracketIcons.length; i++) {
      bracketIcons[i] =
          GeoGebraIcon.createStringIcon(
              EuclidianStyleBarStatic.bracketArray[i],
              app.getPlainFont(),
              true,
              false,
              true,
              new Dimension(30, iconHeight),
              Color.BLACK,
              null);
    }

    btnTableTextBracket =
        new PopupMenuButton(
            (AppD) ev.getApplication(),
            bracketIcons,
            2,
            -1,
            new Dimension(30, iconHeight),
            geogebra.common.gui.util.SelectionTable.MODE_ICON) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            if (tableText != null) {
              this.setVisible(true);
              String s = tableText.getOpenSymbol() + " " + tableText.getCloseSymbol();
              int index = 0;
              for (int i = 0; i < EuclidianStyleBarStatic.bracketArray.length; i++) {
                if (s.equals(EuclidianStyleBarStatic.bracketArray[i])) {
                  index = i;
                  break;
                }
              }
              // System.out.println("index" + index);
              btnTableTextBracket.setSelectedIndex(index);

            } else {
              this.setVisible(false);
            }
          }
        };

    btnTableTextBracket.addActionListener(this);
    btnTableTextBracket.setKeepVisible(false);

    // ====================================
    // vertical grid lines toggle button
    btnTableTextLinesV =
        new MyToggleButton(GeoGebraIcon.createVGridIcon(iconDimension), iconHeight) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            if (tableText != null) {
              setVisible(true);
              setSelected(tableText.isVerticalLines());
            } else {
              setVisible(false);
            }
          }
        };
    btnTableTextLinesV.addActionListener(this);

    // ====================================
    // horizontal grid lines toggle button
    btnTableTextLinesH =
        new MyToggleButton(GeoGebraIcon.createHGridIcon(iconDimension), iconHeight) {

          private static final long serialVersionUID = 1L;

          @Override
          public void update(Object[] geos) {
            if (tableText != null) {
              setVisible(true);
              setSelected(tableText.isHorizontalLines());
            } else {
              setVisible(false);
            }
          }
        };
    btnTableTextLinesH.addActionListener(this);
  }
Esempio n. 2
0
  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);
  }