Ejemplo n.º 1
0
  public AbstractFunction(
      String[] expr, Color3f color, String[] bounds, float[] stepSize, Plotter plotter)
      throws IllegalExpressionException {
    this.expr = expr;
    this.plotter = plotter;
    this.visible = true;
    this.selected = false;
    this.color = color;
    this.boundsString = bounds;
    this.stepSize = stepSize;
    this.bounds = new float[6];
    for (int i = 0; i < bounds.length; i++) {
      this.bounds[i] = GuiUtil.evalString(bounds[i]);
    }

    state = FILL.FILL;
  }
Ejemplo n.º 2
0
  private void init() {
    input = new JTextField[nInputs];

    double[] rowWeights =
        new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
    rowWeights[nInputs + 2] = 1.0;

    GridBagLayout gbl_functionPanel = new GridBagLayout();
    gbl_functionPanel.columnWidths = new int[] {5, 0, 50, 50, 30, 25, 5, 0};
    gbl_functionPanel.rowHeights = new int[] {10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10};
    gbl_functionPanel.columnWeights =
        new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
    gbl_functionPanel.rowWeights = rowWeights;
    this.setLayout(gbl_functionPanel);

    // Function input field.
    for (int i = 0; i < nInputs; i++) {
      // Creation.
      input[i] = new JTextField();
      GridBagConstraints gbc_stdFuncInput = new GridBagConstraints();
      gbc_stdFuncInput.gridwidth = 4;
      gbc_stdFuncInput.insets = new Insets(0, 0, 5, 5);
      gbc_stdFuncInput.fill = GridBagConstraints.HORIZONTAL;
      gbc_stdFuncInput.anchor = GridBagConstraints.NORTH;
      gbc_stdFuncInput.gridx = 2;
      gbc_stdFuncInput.gridy = i + 1;

      // Setup.
      GuiUtil.setupUndoListener(input[i]);
      setupInputListeners(input[i]);
      this.add(input[i], gbc_stdFuncInput);
    }

    // Labels for the input fields
    String[] labelNames = labelNames();
    for (int i = 0; i < labelNames.length; i++) {
      GridBagConstraints gbc_FuncLabel = new GridBagConstraints();
      gbc_FuncLabel.gridwidth = 1;
      gbc_FuncLabel.insets = new Insets(0, 0, 5, 5);
      gbc_FuncLabel.fill = GridBagConstraints.HORIZONTAL;
      gbc_FuncLabel.anchor = GridBagConstraints.CENTER;
      gbc_FuncLabel.gridx = 1;
      gbc_FuncLabel.gridy = i + 1;

      JLabel label = new JLabel(labelNames[i]);
      this.add(label, gbc_FuncLabel);
    }

    // OptionPanel.
    mainOP = new JPanel();
    mainOP.setBorder(BorderFactory.createEtchedBorder());
    GridBagConstraints gbc_mainOP = new GridBagConstraints();
    gbc_mainOP.fill = GridBagConstraints.BOTH;
    gbc_mainOP.gridwidth = 5;
    gbc_mainOP.insets = new Insets(0, 0, 5, 5);
    gbc_mainOP.gridx = 1;
    gbc_mainOP.gridy = nInputs + 1;
    this.add(mainOP, gbc_mainOP);

    gridOP = getGridOptionPanel();
    gridOP.addFunctionListener(createGridOptionPanelListener());
    apperanceOP = new AppearanceOptionPanel(colorList, map);
    mainOP.setLayout(new BoxLayout(mainOP, BoxLayout.Y_AXIS));
    mainOP.add((Component) gridOP);
    mainOP.add(apperanceOP);

    // The standard function list
    outerFuncTab = new JPanel();
    funcPanelWrapper = new JScrollPane(outerFuncTab);
    funcPanelWrapper.setBorder(BorderFactory.createEtchedBorder());
    funcPanelWrapper.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    funcPanelWrapper.setMinimumSize(new Dimension(310, 500));
    GridBagConstraints gbc_funcPanelWrapper = new GridBagConstraints();
    gbc_funcPanelWrapper.fill = GridBagConstraints.BOTH;
    gbc_funcPanelWrapper.gridwidth = 5;
    gbc_funcPanelWrapper.insets = new Insets(0, 0, 5, 5);
    gbc_funcPanelWrapper.gridx = 1;
    gbc_funcPanelWrapper.gridy = nInputs + 2;
    ;
    this.add(funcPanelWrapper, gbc_funcPanelWrapper);

    GridBagLayout gbl_stdFuncPanel = new GridBagLayout();
    gbl_stdFuncPanel.columnWidths = new int[] {0, 0};
    gbl_stdFuncPanel.rowHeights = new int[] {0, 0};
    gbl_stdFuncPanel.columnWeights = new double[] {1.0, Double.MIN_VALUE};
    gbl_stdFuncPanel.rowWeights = new double[] {1.0, Double.MIN_VALUE};
    outerFuncTab.setLayout(gbl_stdFuncPanel);

    innerFuncTab = new JPanel();
    GridBagConstraints gbc_innerFuncPanel = new GridBagConstraints();
    gbc_innerFuncPanel.anchor = GridBagConstraints.NORTH;
    gbc_innerFuncPanel.fill = GridBagConstraints.HORIZONTAL;
    gbc_innerFuncPanel.gridx = 0;
    gbc_innerFuncPanel.gridy = 0;
    outerFuncTab.add(innerFuncTab, gbc_innerFuncPanel);
    innerFuncTab.setLayout(new BoxLayout(innerFuncTab, BoxLayout.Y_AXIS));
  }
Ejemplo n.º 3
0
  public ParametricFunctionLabel(Function function) {
    super(function);

    // GUI representation
    GridBagLayout gbl_fLabel = new GridBagLayout();
    gbl_fLabel.columnWidths = new int[] {0, 0, 150, 30, 0, 0};
    gbl_fLabel.rowHeights = new int[] {5, 0, 0, 0, 0, 0, 0};
    gbl_fLabel.columnWeights = new double[] {0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
    gbl_fLabel.rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
    this.setLayout(gbl_fLabel);

    lblX = new JLabel("x =");
    GridBagConstraints gbc_lblX = new GridBagConstraints();
    gbc_lblX.insets = new Insets(0, 0, 5, 5);
    gbc_lblX.anchor = GridBagConstraints.EAST;
    gbc_lblX.gridx = 1;
    gbc_lblX.gridy = 1;
    add(lblX, gbc_lblX);

    exprFieldX = new JTextField(function.getExpression()[0]);
    GridBagConstraints gbc_list = new GridBagConstraints();
    gbc_list.insets = new Insets(0, 0, 5, 5);
    gbc_list.fill = GridBagConstraints.HORIZONTAL;
    gbc_list.gridx = 2;
    gbc_list.gridy = 1;
    this.add(exprFieldX, gbc_list);

    toggleButton =
        new ToggleButton(
            new ImageIcon("Icons/selected.png"), new ImageIcon("Icons/notSelected.png"));
    GridBagConstraints gbc_chckbxTest = new GridBagConstraints();
    gbc_chckbxTest.gridheight = 2;
    gbc_chckbxTest.insets = new Insets(0, 0, 5, 5);
    gbc_chckbxTest.gridx = 3;
    gbc_chckbxTest.gridy = 1;
    this.add(toggleButton, gbc_chckbxTest);

    lblY = new JLabel("y =");
    GridBagConstraints gbc_lblY = new GridBagConstraints();
    gbc_lblY.gridheight = 2;
    gbc_lblY.insets = new Insets(0, 0, 5, 5);
    gbc_lblY.anchor = GridBagConstraints.EAST;
    gbc_lblY.gridx = 1;
    gbc_lblY.gridy = 2;
    add(lblY, gbc_lblY);

    exprFieldY = new JTextField(function.getExpression()[1]);
    GridBagConstraints gbc_textField = new GridBagConstraints();
    gbc_textField.gridheight = 2;
    gbc_textField.insets = new Insets(0, 0, 5, 5);
    gbc_textField.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField.gridx = 2;
    gbc_textField.gridy = 2;
    add(exprFieldY, gbc_textField);
    exprFieldY.setColumns(10);

    lblZ = new JLabel("z =");
    GridBagConstraints gbc_lblZ = new GridBagConstraints();
    gbc_lblZ.insets = new Insets(0, 0, 5, 5);
    gbc_lblZ.anchor = GridBagConstraints.EAST;
    gbc_lblZ.gridx = 1;
    gbc_lblZ.gridy = 4;
    add(lblZ, gbc_lblZ);

    exprFieldZ = new JTextField(function.getExpression()[2]);
    GridBagConstraints gbc_textField_1 = new GridBagConstraints();
    gbc_textField_1.insets = new Insets(0, 0, 5, 5);
    gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField_1.gridx = 2;
    gbc_textField_1.gridy = 4;
    add(exprFieldZ, gbc_textField_1);
    exprFieldZ.setColumns(10);

    // Don't f**k up layout, when text string becomes too long.
    exprFieldX.setPreferredSize(new Dimension(100, 20));
    exprFieldY.setPreferredSize(new Dimension(100, 20));
    exprFieldZ.setPreferredSize(new Dimension(100, 20));

    btnDelete = new JButton(new ImageIcon("Icons/delete.png"));
    GridBagConstraints gbc_btnDelete = new GridBagConstraints();
    gbc_btnDelete.gridheight = 2;
    gbc_btnDelete.insets = new Insets(0, 0, 5, 5);
    gbc_btnDelete.gridx = 3;
    gbc_btnDelete.gridy = 3;
    add(btnDelete, gbc_btnDelete);

    // Add listeners;
    addTextChangeListener();
    addToggleButtonListener();
    addDeleteListener();

    this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

    GuiUtil.setupUndoListener(exprFieldX);
    GuiUtil.setupUndoListener(exprFieldY);
    GuiUtil.setupUndoListener(exprFieldZ);
  }