コード例 #1
0
ファイル: CASStyleBar.java プロジェクト: Miguelos/geogebra
  private void initGUI() {

    removeAll();

    createTextButtons();

    add(btnUseAsText);
    add(btnTextColor);
    add(btnBold);
    add(btnItalic);

    btnShowKeyboard = new MyToggleButton(app.getImageIcon("cas-keyboard.png"), iconHeight);
    btnShowKeyboard.addActionListener(this);
    add(btnShowKeyboard);
    // add(btnTextSize); //TODO: Fix text size

    popupBtnList = newPopupBtnList();
    toggleBtnList = newToggleBtnList();

    updateStyleBar();
  }
コード例 #2
0
  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);
  }
コード例 #3
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);
  }
コード例 #4
0
  /** Initializes all components, sets labels */
  public void initGUI() {
    removeAll();

    btFirst = new JButton(app.getImageIcon("nav_skipback.png"));
    btLast = new JButton(app.getImageIcon("nav_skipforward.png"));
    btPrev = new JButton(app.getImageIcon("nav_rewind.png"));
    btNext = new JButton(app.getImageIcon("nav_fastforward.png"));

    btFirst.addActionListener(this);
    btLast.addActionListener(this);
    btPrev.addActionListener(this);
    btNext.addActionListener(this);

    JPanel leftPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    leftPanel.add(btFirst);
    leftPanel.add(btPrev);
    leftPanel.add(lbSteps);
    leftPanel.add(btNext);
    leftPanel.add(btLast);

    playPanel = new JPanel();
    playPanel.setVisible(showPlayButton);
    playPanel.add(Box.createRigidArea(new Dimension(20, 10)));
    btPlay = new JButton();
    btPlay.setIcon(new ImageIcon(app.getPlayImage()));
    btPlay.addActionListener(this);

    spDelay.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            try {
              playDelay = Double.parseDouble(spDelay.getValue().toString());
            } catch (Exception ex) {
              playDelay = 2;
            }
          }
        });

    playPanel.add(btPlay);
    playPanel.add(spDelay);
    playPanel.add(new JLabel("s"));

    btOpenWindow = new JButton();
    btOpenWindow.setIcon(app.getImageIcon("table.gif"));
    btOpenWindow.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // app.getGuiManager().showConstructionProtocol();
            if (!app.getGuiManager().showView(App.VIEW_CONSTRUCTION_PROTOCOL))
              app.getGuiManager().setShowView(true, App.VIEW_CONSTRUCTION_PROTOCOL);
          }
        });

    // add panels together to center
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
    add(leftPanel);
    add(playPanel);
    add(btOpenWindow);
    add(Box.createRigidArea(new Dimension(20, 10)));

    setLabels();
    setPlayDelay(playDelay);
    update();
  }