@Nullable
  @Override
  protected JComponent createCustomPanel() {
    myHostLabel = new JBLabel("Host:", SwingConstants.RIGHT);

    JPanel myHostPanel = new JPanel(new BorderLayout(5, 0));
    myHostPanel.add(myURLText, BorderLayout.CENTER);
    myHostPanel.add(myShareUrlCheckBox, BorderLayout.EAST);

    myRepositoryLabel = new JBLabel("Repository:", SwingConstants.RIGHT);
    myRepoAuthor = new MyTextField("Repository Owner");
    myRepoName = new MyTextField("Repository Name");
    myRepoAuthor.setPreferredSize("SomelongNickname");
    myRepoName.setPreferredSize("SomelongReponame-with-suffixes");

    JPanel myRepoPanel = new JPanel(new GridBagLayout());
    GridBag bag = new GridBag().setDefaultWeightX(1).setDefaultFill(GridBagConstraints.HORIZONTAL);
    myRepoPanel.add(myRepoAuthor, bag.nextLine().next());
    myRepoPanel.add(new JLabel("/"), bag.next().fillCellNone().insets(0, 5, 0, 5).weightx(0));
    myRepoPanel.add(myRepoName, bag.next());

    myTokenLabel = new JBLabel("API Token:", SwingConstants.RIGHT);
    myToken = new MyTextField("OAuth2 token");
    myTokenButton = new JButton("Create API token");
    myTokenButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            generateToken();
            doApply();
          }
        });

    JPanel myTokenPanel = new JPanel();
    myTokenPanel.setLayout(new BorderLayout(5, 5));
    myTokenPanel.add(myToken, BorderLayout.CENTER);
    myTokenPanel.add(myTokenButton, BorderLayout.EAST);

    installListener(myRepoAuthor);
    installListener(myRepoName);
    installListener(myToken);

    return FormBuilder.createFormBuilder()
        .setAlignLabelOnRight(true)
        .addLabeledComponent(myHostLabel, myHostPanel)
        .addLabeledComponent(myRepositoryLabel, myRepoPanel)
        .addLabeledComponent(myTokenLabel, myTokenPanel)
        .getPanel();
  }
Ejemplo n.º 2
0
  int showOpenDialog(final boolean sa) {

    dialog = new JDialog(frame, JDialog.ModalityType.APPLICATION_MODAL);
    // dialog.setUndecorated(false);

    saveAs = sa;

    dialog.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            dialog.dispose();
          }
        });

    panel = new JPanel();
    panel.setLayout(new BorderLayout());

    driver.curDiag.filterOptions[0] = fCParms.title;
    cBox = new MyComboBox(driver.curDiag.filterOptions);
    cBox.setMaximumRowCount(2);
    cBox.addMouseListener(this);
    cBox.setSelectedIndex(driver.allFiles ? 1 : 0);

    order = new Vector<Component>(9);
    order.add(text);
    order.add(butParent);
    order.add(butNF);
    order.add(panel); // just a place-holder - will be filled in by
    // buildList
    order.add(text2);
    order.add(butCopy);
    order.add(butOK);
    order.add(cBox);
    order.add(butDel);
    order.add(butCancel);

    text.setEditable(true);
    text.setEnabled(true);

    // text.getDocument().addDocumentListener(this);

    text2.setEditable(true);
    text2.setEnabled(true);
    text2.setRequestFocusEnabled(true);
    // text2.addKeyListener(this);
    // text2.getDocument().addDocumentListener(this);
    text2.setPreferredSize(new Dimension(100, driver.fontHeight + 2));

    text3.setEditable(false);
    text3.setEnabled(true);
    // text3.setRequestFocusEnabled(true);
    text3.setFont(driver.fontg.deriveFont(Font.ITALIC));
    // text3.setPreferredSize(new Dimension(100, driver.fontHeight + 2));

    String s = (saveAs) ? "Save or Save As" : "Open File";
    comp = new MyFileCompare();
    renderer = new ListRenderer(driver);

    if (fCParms == driver.curDiag.fCPArr[DrawFBP.DIAGRAM]) dialog.setTitle(s);
    else {
      if (fCParms == driver.curDiag.fCPArr[DrawFBP.GENCODE])
        fCParms.prompt =
            "Specify file name for generated code - for diagram: " + driver.curDiag.title + ".drw";

      dialog.setTitle(fCParms.prompt);
      if (fCParms == driver.curDiag.fCPArr[DrawFBP.CLASS]) listShowingJarFile = listHead;
    }

    enterAction = new EnterAction();
    copyAction = new CopyAction();
    cancelAction = new CancelAction();
    deleteAction = new DeleteAction();

    parentAction = new ParentAction();
    newFolderAction = new NewFolderAction();

    butParent.setAction(parentAction);
    butParent.setText("Parent Folder");
    butParent.setMnemonic(KeyEvent.VK_P);

    butNF.setAction(newFolderAction);
    butNF.setMnemonic(KeyEvent.VK_N);
    butNF.setText("New Folder");

    // butOK.setAction(okAction);
    butOK.setAction(enterAction);
    butCopy.setAction(copyAction);
    butCancel.setAction(cancelAction);
    butDel.setAction(deleteAction);

    butParent.setRequestFocusEnabled(true);
    butNF.setRequestFocusEnabled(true);
    butCopy.setRequestFocusEnabled(true);

    text.addMouseListener(this);
    text2.addMouseListener(this);

    panel.setPreferredSize(new Dimension(600, 600));

    text.setFocusTraversalKeysEnabled(false);
    butParent.setFocusTraversalKeysEnabled(false);
    butNF.setFocusTraversalKeysEnabled(false);
    text2.setFocusTraversalKeysEnabled(false);
    butOK.setFocusTraversalKeysEnabled(false);
    butDel.setFocusTraversalKeysEnabled(false);
    butCancel.setFocusTraversalKeysEnabled(false);
    butCopy.setFocusTraversalKeysEnabled(false);

    butParent.setEnabled(true);
    butNF.setEnabled(true);
    butOK.setEnabled(true);
    // butCopy.setEnabled(saveAs);
    butCopy.setEnabled(true);
    butCancel.setEnabled(true);
    butDel.setEnabled(true);

    KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    panel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(escape, "CLOSE");

    panel.getActionMap().put("CLOSE", cancelAction);

    JLabel label = new JLabel("Current folder: ");
    label.setFont(driver.fontg);

    Box box0 = new Box(BoxLayout.Y_AXIS);
    Box box1 = new Box(BoxLayout.X_AXIS);

    box1.add(label);

    box1.add(Box.createRigidArea(new Dimension(12, 0)));
    box1.add(text);
    box1.add(Box.createRigidArea(new Dimension(6, 0)));

    box1.add(butParent);
    // butParent.addActionListener(this);
    box1.add(Box.createRigidArea(new Dimension(6, 0)));

    // butNF.addActionListener(this);
    box1.add(butNF);

    box0.add(Box.createRigidArea(new Dimension(0, 20)));
    box0.add(box1);

    box0.add(Box.createRigidArea(new Dimension(0, 20)));
    panel.add(box0, BorderLayout.NORTH);

    text.setFont(label.getFont());
    text.addActionListener(this);
    text2.addActionListener(this);

    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;

    JPanel pan2 = new JPanel();

    pan2.setLayout(gridbag);
    // c.fill = GridBagConstraints.BOTH;

    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0.0;

    JLabel lab1 = new JLabel("File name: ");
    gridbag.setConstraints(lab1, c);
    pan2.add(lab1);

    c.gridx = 1;
    c.weightx = 0.0;
    JLabel lab5 = new JLabel("  ");
    gridbag.setConstraints(lab5, c);
    pan2.add(lab5);

    c.gridx = 2;

    c.weightx = saveAs ? 0.1 : 1.0;
    c.gridwidth = saveAs ? 1 : 3;
    // c.ipadx  = saveAs ? -20: 0;
    gridbag.setConstraints(text2, c);
    pan2.add(text2);

    if (saveAs) {
      c.gridx = 3;
      c.weightx = 0.0;
      c.gridwidth = 1;
      JLabel lab6 = new JLabel("   Suggestion: ");
      gridbag.setConstraints(lab6, c);
      pan2.add(lab6);

      c.gridx = 4;
      c.weightx = 0.9;
      // c.ipadx = 20;
      gridbag.setConstraints(text3, c);
      pan2.add(text3);
      text3.setBackground(Color.WHITE);
      Dimension dim = text3.getPreferredSize();
      text3.setPreferredSize(new Dimension(driver.fontWidth * 25, dim.height));
    }

    c.gridx = 5;
    c.weightx = 0.0;
    JLabel lab7 = new JLabel("  ");
    gridbag.setConstraints(lab7, c);
    pan2.add(lab7);

    c.gridx = 6;
    c.weightx = 0.0;

    if (saveAs) {
      c.gridwidth = 1;
      gridbag.setConstraints(butCopy, c);
      pan2.add(butCopy);

      c.gridx = 7;
      c.weightx = 0.0;

      c.gridwidth = 1;
    } else c.gridwidth = 2;
    gridbag.setConstraints(butOK, c);
    pan2.add(butOK);

    c.weightx = 0.0;
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;

    JLabel lab2 = new JLabel("Files of type:");
    gridbag.setConstraints(lab2, c);
    pan2.add(lab2);

    c.gridx = 1;
    c.weightx = 0.0;
    JLabel lab8 = new JLabel("  ");
    gridbag.setConstraints(lab8, c);
    pan2.add(lab8);

    c.gridx = 2;
    c.weightx = 1.0;
    c.gridwidth = 3;
    gridbag.setConstraints(cBox, c);
    pan2.add(cBox);
    cBox.addActionListener(this);

    c.gridx = 5;
    c.weightx = 0.0;
    c.gridwidth = 1;
    JLabel lab9 = new JLabel("  ");
    gridbag.setConstraints(lab9, c);
    pan2.add(lab9);

    c.gridx = 6;
    c.weightx = 0.0;
    gridbag.setConstraints(butDel, c);
    pan2.add(butDel);

    c.gridx = 7;
    c.weightx = 0.0;
    gridbag.setConstraints(butCancel, c);
    pan2.add(butCancel);

    butOK.setText("OK");
    butOK.setFont(driver.fontg.deriveFont(Font.BOLD));
    butCancel.setText("Cancel");
    butDel.setText("Delete");
    butCopy.setText(saveAs ? "Use suggested name" : "");

    JLabel lab3 = new JLabel();
    lab3.setPreferredSize(new Dimension(500, 30));
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 4;
    c.weightx = 1.0;
    gridbag.setConstraints(lab3, c);
    pan2.add(lab3);

    cBox.addActionListener(this);

    // cBox.setUI(new BasicComboBoxUI());
    cBox.setRenderer(new ComboBoxRenderer());

    Dimension dim = new Dimension(1000, 800);
    dialog.setPreferredSize(dim);

    dialog.setFocusTraversalKeysEnabled(false);
    text.addKeyListener(this);
    text2.addKeyListener(this);
    butParent.addKeyListener(this); // needed to service tab keys
    butNF.addKeyListener(this); // needed to service tab keys
    butOK.addKeyListener(this); // needed to service tab keys
    cBox.addKeyListener(this); // needed to service tab keys
    butDel.addKeyListener(this); // needed to service tab keys
    butCancel.addKeyListener(this); // needed to service tab keys
    butCopy.addKeyListener(this); // needed to service tab keys
    cBox.setFocusTraversalKeysEnabled(false);
    mtp = new MyTraversalPolicy();
    setFocusTraversalPolicy(mtp);
    setFocusCycleRoot(false);

    showList();
    if (saveAs) {

      if (suggestedName != null && !(suggestedName.equals(""))) {
        File h = new File(suggestedName);
        listHead = h.getParent();
        text.setText(listHead);
        text2.setText(h.getName());
        text3.setText(h.getName());

        /*
        SwingUtilities.invokeLater(new Runnable() {
        	public void run() {
        		text2.requestFocusInWindow();
        		selComp = text2;
        		text2.setBackground(vLightBlue);
        	}
        });

        */

        text2.addAncestorListener(new RequestFocusListener(false));
        selComp = text2;
        // text2.setBackground(vLightBlue);
        // text2.setEditable(true);
      }

      if (driver.curDiag.title != null && driver.curDiag.diagFile != null) {
        s += " (current file: " + driver.curDiag.diagFile.getAbsolutePath() + ")";
      }
    } else {
      text.setText(listHead);
      /*
      SwingUtilities.invokeLater(new Runnable() {
      	public void run() {
      		list.requestFocusInWindow();
      		selComp = list;
      		// list.setBackground(vLightBlue);
      	}
      });
      */
      // list.addAncestorListener( new RequestFocusListener() );
      selComp = list;
    }

    panel.add(pan2, BorderLayout.SOUTH);
    dialog.add(panel);

    dialog.pack();
    dialog.setLocation(200, 100);
    frame.pack();

    dialog.setVisible(true);

    // if (!saveAs)
    // textBackground = Color.WHITE;

    frame.repaint();

    return result;
  }