Ejemplo n.º 1
0
  private void createGUI() {
    setTitle(textField ? app.getPlain("TextField") : app.getPlain("Button"));
    setResizable(false);

    // create caption panel
    JLabel captionLabel = new JLabel(app.getMenu("Button.Caption") + ":");
    String initString = button == null ? "" : button.getCaption();
    InputPanel ip = new InputPanel(initString, app, 1, 15, true);
    tfCaption = ip.getTextComponent();
    if (tfCaption instanceof AutoCompleteTextField) {
      AutoCompleteTextField atf = (AutoCompleteTextField) tfCaption;
      atf.setAutoComplete(false);
    }

    captionLabel.setLabelFor(tfCaption);
    JPanel captionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    captionPanel.add(captionLabel);
    captionPanel.add(ip);

    // combo box to link GeoElement to TextField
    comboModel = new DefaultComboBoxModel();
    TreeSet sortedSet = app.getKernel().getConstruction().getGeoSetNameDescriptionOrder();

    final JComboBox cbAdd = new JComboBox(comboModel);

    if (textField) {
      // lists for combo boxes to select input and output objects
      // fill combobox models
      Iterator it = sortedSet.iterator();
      comboModel.addElement(null);
      FontMetrics fm = getFontMetrics(getFont());
      int width = (int) cbAdd.getPreferredSize().getWidth();
      while (it.hasNext()) {
        GeoElement geo = (GeoElement) it.next();
        if (!geo.isGeoImage() && !(geo.isGeoButton()) && !(geo.isGeoBoolean())) {
          comboModel.addElement(geo);
          String str = geo.toString();
          if (width < fm.stringWidth(str)) width = fm.stringWidth(str);
        }
      }

      // make sure it's not too wide (eg long GeoList)
      Dimension size =
          new Dimension(
              Math.min(app.getScreenSize().width / 2, width), cbAdd.getPreferredSize().height);
      cbAdd.setMaximumSize(size);
      cbAdd.setPreferredSize(size);

      if (comboModel.getSize() > 1) {

        // listener for the combobox
        MyComboBoxListener ac =
            new MyComboBoxListener() {
              public void doActionPerformed(Object source) {
                GeoElement geo = (GeoElement) cbAdd.getSelectedItem();
                // if (geo == null)
                // {
                //
                //	return;
                // }

                linkedGeo = geo;
                // ((GeoTextField)button).setLinkedGeo(geo);

                cbAdd.removeActionListener(this);

                // cbAdd.setSelectedItem(null);
                cbAdd.addActionListener(this);
              }
            };
        cbAdd.addActionListener(ac);
        cbAdd.addMouseListener(ac);

        captionPanel.add(cbAdd);
      }
    }

    // create script panel
    JLabel scriptLabel = new JLabel(app.getPlain("Script") + ":");
    initString = (button == null) ? "" : button.getClickScript();
    InputPanel ip2 = new InputPanel(initString, app, 10, 40, false);
    tfScript = ip2.getTextComponent();
    if (tfScript instanceof AutoCompleteTextField) {
      AutoCompleteTextField atf = (AutoCompleteTextField) tfScript;
      atf.setAutoComplete(false);
    }

    scriptLabel.setLabelFor(tfScript);
    JPanel scriptPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    scriptPanel.add(scriptLabel);
    scriptPanel.add(ip2);

    JPanel linkedPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JLabel linkedLabel = new JLabel(app.getPlain("LinkedObject") + ":");
    linkedPanel.add(linkedLabel);
    linkedPanel.add(cbAdd);

    // buttons
    btApply = new JButton(app.getPlain("Apply"));
    btApply.setActionCommand("Apply");
    btApply.addActionListener(this);
    btCancel = new JButton(app.getPlain("Cancel"));
    btCancel.setActionCommand("Cancel");
    btCancel.addActionListener(this);
    btPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    btPanel.add(btApply);
    btPanel.add(btCancel);

    // Create the JOptionPane.
    optionPane = new JPanel(new BorderLayout(5, 5));

    // create object list
    optionPane.add(captionPanel, BorderLayout.NORTH);
    if (textField) optionPane.add(linkedPanel, BorderLayout.CENTER);
    else optionPane.add(scriptPanel, BorderLayout.CENTER);
    optionPane.add(btPanel, BorderLayout.SOUTH);
    optionPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    // Make this dialog display it.
    setContentPane(optionPane);

    /*

    inputPanel = new InputPanel("ggbApplet.evalCommand('A=(3,4)');", app, 10, 50, false, true, false );
    inputPanel2 = new InputPanel("function func() {\n}", app, 10, 50, false, true, false );

    JPanel centerPanel = new JPanel(new BorderLayout());

    centerPanel.add(inputPanel, BorderLayout.CENTER);
    centerPanel.add(inputPanel2, BorderLayout.SOUTH);
    getContentPane().add(centerPanel, BorderLayout.CENTER);
    //centerOnScreen();

    setContentPane(centerPanel);
    pack();
    setLocationRelativeTo(app.getFrame());	*/
  }
Ejemplo n.º 2
0
 private void setLabelFieldFocus() {
   tfLabel.getTextComponent().requestFocus();
   tfLabel.selectText();
 }