Exemplo n.º 1
0
  public CreateObjectDialog(AppD app, SpreadsheetView view, int objectType) {

    super(app.getFrame(), false, app.getLocalization());
    this.app = app;
    this.objectType = objectType;
    this.table = (MyTableD) view.getSpreadsheetTable();
    cp = table.getCellRangeProcessor();
    selectedCellRanges = table.selectedCellRanges;

    boolean showApply = false;

    createGUI(title, "", false, 16, 1, false, false, false, showApply, DialogType.GeoGebraEditor);

    // this.btCancel.setVisible(false);

    createAdditionalGUI();

    updateGUI();

    isIniting = false;
    setLabels(null);
    // setTitle((String) model.getElementAt(objectType));

    // optionPane.add(inputPanel, BorderLayout.CENTER);
    typeList.setSelectedIndex(objectType);

    wrappedDialog.setResizable(true);
    centerOnScreen();
    btCancel.requestFocus();
    wrappedDialog.pack();
    wrappedDialog.addWindowFocusListener(this);
  }
Exemplo n.º 2
0
  /** Update localization */
  public void setLabels() {
    initGUI();

    btnUseAsText.setToolTipText(app.getPlainTooltip("stylebar.UseAsText"));
    btnTextColor.setToolTipText(app.getPlainTooltip("stylebar.TextColor"));
    btnTextSize.setToolTipText(app.getPlainTooltip("stylebar.TextSize"));
    btnBold.setToolTipText(app.getPlainTooltip("stylebar.Bold"));
    btnItalic.setToolTipText(app.getPlainTooltip("stylebar.Italic"));
  }
 /**
  * Sets the focus to this EV. TODO: use this view's id directly to set the focus (current code
  * assumes only 2 EVs)
  */
 private void requestViewFocus() {
   if (ev.equals(app.getEuclidianView1()))
     ((LayoutD) ((GuiManagerD) app.getGuiManager()).getLayout())
         .getDockManager()
         .setFocusedPanel(App.VIEW_EUCLIDIAN);
   else
     ((LayoutD) ((GuiManagerD) app.getGuiManager()).getLayout())
         .getDockManager()
         .setFocusedPanel(App.VIEW_EUCLIDIAN2);
 }
Exemplo n.º 4
0
  /** Switch panel for which we want to change the toolbar. */
  public void actionPerformed(ActionEvent e) {
    int id = ((KeyValue) ((JComboBox) e.getSource()).getSelectedItem()).getKey();

    if (id == -1) {
      confPanel.setToolbar(null, ((GuiManagerD) app.getGuiManager()).getToolbarDefinition());
    } else {
      DockPanel panel =
          ((GuiManagerD) app.getGuiManager()).getLayout().getDockManager().getPanel(id);
      confPanel.setToolbar(panel, panel.getToolbarString());
    }
  }
Exemplo n.º 5
0
  /** Initialize and update the items. */
  @Override
  public void initItems() {
    if (!initialized) {
      return;
    }

    removeAll();
    JMenuItem mit = add(newWindowAction);
    setMenuShortCutAccelerator(mit, 'N');

    ArrayList<GeoGebraFrame> ggbInstances = GeoGebraFrame.getInstances();
    int size = ggbInstances.size();
    if (size == 1) return;

    addSeparator();
    StringBuilder sb = new StringBuilder();
    ButtonGroup bg = new ButtonGroup();
    JRadioButtonMenuItem mi;

    int current = -1;

    for (int i = 0; i < size; i++) {
      GeoGebraFrame ggb = ggbInstances.get(i);
      AppD application = ggb.getApplication();
      if (app == application) current = i;
    }

    for (int i = 0; i < size; i++) {
      GeoGebraFrame ggb = ggbInstances.get(i);
      AppD application = ggb.getApplication();

      sb.setLength(0);
      sb.append(i + 1);
      if (application != null) // Michael Borcherds 2008-03-03 bugfix
      if (application.getCurrentFile() != null) {
          sb.append(" ");
          sb.append(application.getCurrentFile().getName());
        }

      mi = new JRadioButtonMenuItem(sb.toString());
      if (application == this.app) mi.setSelected(true);
      ActionListener al = new RequestFocusListener(ggb);
      mi.addActionListener(al);
      if (i == ((current + 1) % size)) setMenuShortCutShiftAccelerator(mi, 'N');
      else if (i == ((current - 1 + size) % size)) setMenuShortCutShiftAltAccelerator(mi, 'N');
      bg.add(mi);
      add(mi);
    }

    // support for right-to-left languages
    app.setComponentOrientation(this);
  }
Exemplo n.º 6
0
  public static void evalScript(App app, String script, String arg) {
    // Application.debug(app.getKernel().getLibraryJavaScript() + script);
    Context cx = Context.enter();
    // Initialize the standard objects (Object, Function, etc.)
    // This must be done before scripts can be executed. Returns
    // a scope object that we use in later calls.
    Scriptable scope = cx.initStandardObjects();

    // initialise the JavaScript variable applet so that we can call
    // GgbApi functions, eg ggbApplet.evalCommand()
    GeoGebraGlobal.initStandardObjects((AppD) app, scope, arg, false);

    // JavaScript to execute
    // String s = "ggbApplet.evalCommand('F=(2,3)')";

    // No class loader for unsigned applets so don't try and optimize.
    // http://www.mail-archive.com/[email protected]/msg00108.html
    if (!AppD.hasFullPermissions()) {
      cx.setOptimizationLevel(-1);
      Context.setCachingEnabled(false);
    }
    // Now evaluate the string we've collected.
    Object result =
        cx.evaluateString(
            scope,
            ((AppD) app).getKernel().getLibraryJavaScript() + script,
            app.getPlain("ErrorAtLine"),
            1,
            null);

    // Convert the result to a string and print it.
    // Application.debug("script result: "+(Context.toString(result)));
  }
Exemplo n.º 7
0
  /**
   * @param app application
   * @return All tools as a toolbar definition string
   */
  public static String getAllTools(AppD app) {
    StringBuilder sb = new StringBuilder();

    sb.append(ToolBar.getAllToolsNoMacros(true, false));

    // macros
    Kernel kernel = app.getKernel();
    int macroNumber = kernel.getMacroNumber();

    // check if at least one macro is shown
    // to avoid strange GUI
    boolean at_least_one_shown = false;
    for (int i = 0; i < macroNumber; i++) {
      Macro macro = kernel.getMacro(i);
      if (macro.isShowInToolBar()) {
        at_least_one_shown = true;
        break;
      }
    }

    if (macroNumber > 0 && at_least_one_shown) {
      sb.append(" || ");
      for (int i = 0; i < macroNumber; i++) {
        Macro macro = kernel.getMacro(i);
        if (macro.isShowInToolBar()) {
          sb.append(i + EuclidianConstants.MACRO_MODE_ID_OFFSET);
          sb.append(" ");
        }
      }
    }

    return sb.toString();
  }
Exemplo n.º 8
0
 @Override
 public void mousePressed(MouseEvent e) {
   rightClick = AppD.isRightClick(e);
   table.stopEditing();
   mousePressedRow = rowHeader.locationToIndex(e.getPoint());
   rowHeader.requestFocus();
 }
Exemplo n.º 9
0
  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;
  }
Exemplo n.º 10
0
  /**
   * @param e mouse event
   * @param geo geo
   * @return true if left press can select the geo
   */
  protected boolean leftPressCanSelectGeo(java.awt.event.MouseEvent e, GeoElement geo) {

    if (!AppD.isControlDown(e) && !e.isShiftDown()) {
      if (!setSelectedGeo(geo)) return true;
    }

    return false;
  }
Exemplo n.º 11
0
  /** @return The top-most panel of the window this toolbar belongs to. */
  public Component getMainComponent() {
    // if this is the general toolbar the main component is the application
    // main
    // component (not true for toolbars in EV)
    if (dockPanel == null) {
      return app.wrapGetMainComponent();
    }

    // this toolbar belongs to a dock panel
    // in frame?
    if (dockPanel.isOpenInFrame()) {
      return dockPanel;
    }

    // otherwise use the application main component
    return app.wrapGetMainComponent();
  }
Exemplo n.º 12
0
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    needUndo = false;

    ArrayList<GeoElement> targetGeos = new ArrayList<GeoElement>();
    targetGeos.addAll(ec.getJustCreatedGeos());
    if (mode != EuclidianConstants.MODE_MOVE) targetGeos.addAll(defaultGeos);
    else targetGeos.addAll(app.getSelectedGeos());

    processSource(source, targetGeos);

    if (needUndo) {
      app.storeUndoInfo();
      needUndo = false;
    }

    updateGUI();
  }
Exemplo n.º 13
0
 private String[] getToolTipArray() {
   String[] toolTipArray = new String[colorSet.length];
   for (int i = 0; i < toolTipArray.length; i++) {
     if (colorSet[i] == null) {
       toolTipArray[i] = app.getMenu("Transparent");
     } else {
       toolTipArray[i] = GeoGebraColorConstants.getGeogebraColorName(app, colorSet[i]);
     }
   }
   return toolTipArray;
 }
Exemplo n.º 14
0
  @Override
  protected boolean leftPressCanSelectGeo(java.awt.event.MouseEvent e, GeoElement geo) {

    int mode = app.getActiveEuclidianView().getMode();
    if ((mode == EuclidianConstants.MODE_MOVE || mode == EuclidianConstants.MODE_SELECTION_LISTENER)
        && !AppD.isControlDown(e)
        && !e.isShiftDown()) {
      if (!setSelectedGeo(geo)) return true;
    }
    return false;
  }
Exemplo n.º 15
0
 @Override
 public void mousePressed(java.awt.event.MouseEvent e) {
   view.cancelEditing();
   boolean rightClick = app.isRightClickEnabled() && AppD.isRightClick(e);
   if (rightClick) { // RIGHT CLICK
     geogebra.common.awt.GPoint mouseCoords =
         new geogebra.common.awt.GPoint(e.getPoint().x, e.getPoint().y);
     rightPress(e, mouseCoords);
   } else { // LEFT CLICK
     leftPress(e);
   }
 }
Exemplo n.º 16
0
  /**
   * 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());
  }
Exemplo n.º 17
0
  /**
   * @param source event source
   * @param targetGeos cells that need updating
   */
  protected void processSource(Object source, ArrayList<GeoElement> targetGeos) {

    if (source == btnTextColor) {
      if (btnTextColor.getSelectedIndex() >= 0) {
        applyTextColor(targetGeos);
        // btnTextColor.setFgColor((Color)btnTextColor.getSelectedValue());
        // btnItalic.setForeground((Color)btnTextColor.getSelectedValue());
        // btnBold.setForeground((Color)btnTextColor.getSelectedValue());
      }
    } else if (source == btnBold) {
      applyFontStyle(targetGeos);
    } else if (source == btnItalic) {
      applyFontStyle(targetGeos);
    } else if (source == btnTextSize) {
      applyTextSize(targetGeos);
    } else if (source == btnUseAsText) {
      int i = casView.getConsoleTable().getEditingRow();
      int pos =
          ((CASTableCellEditorD) casView.getConsoleTable().getCellEditor(i, CASTable.COL_CAS_CELLS))
              .getCaretPosition();
      applyUseAsText(targetGeos);
      casView.getConsoleTable().startEditingRow(i);
      ((CASTableCellEditorD) casView.getConsoleTable().getCellEditor(i, CASTable.COL_CAS_CELLS))
          .setCaretPosition(pos);
    } else if (source == btnShowKeyboard) {
      if (((GuiManagerD) app.getGuiManager()) != null) {
        if (AppD.isVirtualKeyboardActive()
            && !((GuiManagerD) app.getGuiManager()).showVirtualKeyboard()) {

          // if keyboard is active but hidden, just show it
          ((GuiManagerD) app.getGuiManager()).toggleKeyboard(true);
          ((GuiManagerD) app.getGuiManager()).getVirtualKeyboard().toggleNumeric(true);

        } else {

          AppD.setVirtualKeyboardActive(!AppD.isVirtualKeyboardActive());
          ((GuiManagerD) app.getGuiManager()).toggleKeyboard(AppD.isVirtualKeyboardActive());
          ((GuiManagerD) app.getGuiManager())
              .getVirtualKeyboard()
              .toggleNumeric(AppD.isVirtualKeyboardActive());
        }
      }
    }
    updateStyleBar();
  }
Exemplo n.º 18
0
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    needUndo = false;

    processSource(source, selectedRows);

    if (needUndo) {
      app.storeUndoInfo();
      needUndo = false;
    }

    // updateGUI();
  }
Exemplo n.º 19
0
  public void mouseDragged(MouseEvent e) {
    e.consume();

    // update selection
    int mouseDraggedRow = rowHeader.locationToIndex(e.getPoint());

    // make sure mouse pressed is initialized, this may not be the case
    // after closing the popup menu
    if (mousePressedRow < 0) {
      table.stopEditing();
      mousePressedRow = mouseDraggedRow;
    }
    if (AppD.isControlDown(e)) rowHeader.addSelectionInterval(mousePressedRow, mouseDraggedRow);
    else rowHeader.setSelectionInterval(mousePressedRow, mouseDraggedRow);
  }
Exemplo n.º 20
0
  /** Creates a toolbar using the current strToolBarDefinition. */
  public void buildGui() {
    mode = -1;

    ModeToggleButtonGroup bg = new ModeToggleButtonGroup();
    modeToggleMenus = new ArrayList<ModeToggleMenu>();

    // create toolbar
    removeAll();

    setAlignmentX(LEFT_ALIGNMENT);

    // add menus with modes to toolbar
    addCustomModesToToolbar(bg);

    setMode(app.getMode());
  }
 private void setSupportedFlavours() {
   if (supportedFlavors == null) {
     if (app.isUsingFullGui()) {
       supportedFlavors = new DataFlavor[5];
       supportedFlavors[0] = DataFlavor.imageFlavor;
       supportedFlavors[1] = DataFlavor.stringFlavor;
       supportedFlavors[2] = DataFlavor.javaFileListFlavor;
       supportedFlavors[3] = AlgebraViewTransferHandler.algebraViewFlavor;
       supportedFlavors[4] = PlotPanelEuclidianView.plotPanelFlavor;
     } else {
       supportedFlavors = new DataFlavor[3];
       supportedFlavors[0] = DataFlavor.imageFlavor;
       supportedFlavors[1] = DataFlavor.stringFlavor;
       supportedFlavors[2] = DataFlavor.javaFileListFlavor;
     }
   }
 }
Exemplo n.º 22
0
 @Override
 protected boolean checkDoubleClick(GeoElement geo, MouseEvent e) {
   // check double click
   int clicks = e.getClickCount();
   // EuclidianView ev = app.getEuclidianView();
   EuclidianViewInterfaceCommon ev = app.getActiveEuclidianView();
   if (clicks == 2) {
     selection.clearSelectedGeos(true, false);
     app.updateSelection(false);
     ev.resetMode();
     if (geo != null && !AppD.isControlDown(e)) {
       view.startEditing(geo, e.isShiftDown());
     }
     return true;
   }
   return false;
 }
Exemplo n.º 23
0
 /**
  * @param findMode mode to be found
  * @return true if given mode is present in this toolbar
  */
 public boolean containsMode(int findMode) {
   Vector<ToolbarItem> toolbarVec;
   if (dockPanel != null) {
     toolbarVec = ToolBar.parseToolbarString(dockPanel.getToolbarString());
   } else {
     toolbarVec =
         ToolBar.parseToolbarString(((GuiManagerD) app.getGuiManager()).getToolbarDefinition());
   }
   for (int i = 0; i < toolbarVec.size(); i++) {
     ToolbarItem item = toolbarVec.get(i);
     if (item.getMode() != null && item.getMode() == findMode) return true;
     if (item.getMenu() != null) {
       for (Integer m : item.getMenu()) {
         if (m == findMode) return true;
       }
     }
   }
   return false;
 }
Exemplo n.º 24
0
  public AnimationStepPanel(AppD app) {
    kernel = app.getKernel();

    // text field for animation step
    label = new JLabel();
    tfAnimStep = new AngleTextField(6, app);
    label.setLabelFor(tfAnimStep);
    tfAnimStep.addActionListener(this);
    tfAnimStep.addFocusListener(this);

    // put it all together
    JPanel animPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    animPanel.add(label);
    animPanel.add(tfAnimStep);

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    animPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    add(animPanel);

    setLabels();
  }
Exemplo n.º 25
0
  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();
  }
Exemplo n.º 26
0
  /**
   * *********************************************** Constructs a styleBar
   *
   * @param ev view
   */
  public EuclidianStyleBarD(EuclidianViewInterfaceCommon ev) {

    isIniting = true;

    this.ev = ev;
    ec = (EuclidianControllerD) ev.getEuclidianController();
    app = (AppD) ev.getApplication();
    cons = app.getKernel().getConstruction();

    // init handling of default geos
    defaultGeoMap = EuclidianStyleBarStatic.createDefaultMap();
    defaultGeos = new ArrayList<GeoElement>();

    // toolbar display settings
    setFloatable(false);
    Dimension d = getPreferredSize();
    d.height = iconHeight + 8;
    setPreferredSize(d);

    // init button-specific fields
    // TODO: put these in button classes
    EuclidianStyleBarStatic.pointStyleArray = EuclidianView.getPointStyles();
    pointStyleMap = new HashMap<Integer, Integer>();
    for (int i = 0; i < EuclidianStyleBarStatic.pointStyleArray.length; i++)
      pointStyleMap.put(EuclidianStyleBarStatic.pointStyleArray[i], i);

    EuclidianStyleBarStatic.lineStyleArray = EuclidianView.getLineTypes();
    lineStyleMap = new HashMap<Integer, Integer>();
    for (int i = 0; i < EuclidianStyleBarStatic.lineStyleArray.length; i++)
      lineStyleMap.put(EuclidianStyleBarStatic.lineStyleArray[i], i);

    setLabels(); // this will also init the GUI

    isIniting = false;

    setMode(ev.getMode()); // this will also update the stylebar
  }
Exemplo n.º 27
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);
  }
Exemplo n.º 28
0
  /** 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"));
  }
Exemplo n.º 29
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);
  }
Exemplo n.º 30
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);
  }