public GithubRepositoryEditor( final Project project, final GithubRepository repository, Consumer<GithubRepository> changeListener) { super(project, repository, changeListener); myUrlLabel.setVisible(false); myUsernameLabel.setVisible(false); myUserNameText.setVisible(false); myPasswordLabel.setVisible(false); myPasswordText.setVisible(false); myUseHttpAuthenticationCheckBox.setVisible(false); myRepoAuthor.setText(repository.getRepoAuthor()); myRepoName.setText(repository.getRepoName()); myToken.setText(repository.getToken()); DocumentListener buttonUpdater = new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { updateTokenButton(); } }; myURLText.getDocument().addDocumentListener(buttonUpdater); myRepoAuthor.getDocument().addDocumentListener(buttonUpdater); myRepoName.getDocument().addDocumentListener(buttonUpdater); }
private void checkLogin() { // 对输入进行基本的合法非法判断 String id = idTxt.getText(); String passwd = String.valueOf(passwordTxt.getPassword()); ResultMessage idResult = Utility.checkInputValid(id, 4, 14, false); ResultMessage passwdResult = Utility.checkInputValid(passwd, 5, 14, false); if (idResult != ResultMessage.SUCCESS) { MyOptionPane.showMessageDialog(null, "输入的用户名" + idResult.toFriendlyString() + "!"); return; } else if (passwdResult != ResultMessage.SUCCESS) { MyOptionPane.showMessageDialog(null, "输入的密码" + passwdResult.toFriendlyString() + "!"); return; } // 登录验证 ResultMessage loginresult = loginController.login(usertype.getSelectedIndex(), id, passwd); if (loginresult == ResultMessage.SUCCESS) { new HomeUI(loginController); frame.dispose(); } else { if (loginresult == ResultMessage.WRONG_ID) { MyOptionPane.showMessageDialog(null, "用户名错误!"); idTxt.setText(""); passwordTxt.setText(""); } else if (loginresult == ResultMessage.WRONG_PASSWD) { MyOptionPane.showMessageDialog(null, "密码错误!"); passwordTxt.setText(""); } else { MyOptionPane.showMessageDialog(null, "服务器未开启!"); } } }
@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(); }
private void generateToken() { try { myToken.setText( GithubUtil.computeValueInModal( myProject, "Access to GitHub", new ThrowableConvertor<ProgressIndicator, String, IOException>() { @NotNull @Override public String convert(ProgressIndicator indicator) throws IOException { return GithubUtil.runTaskWithBasicAuthForHost( myProject, GithubAuthDataHolder.createFromSettings(), indicator, getHost(), new ThrowableConvertor<GithubAuthData, String, IOException>() { @NotNull @Override public String convert(@NotNull GithubAuthData auth) throws IOException { return GithubApiUtil.getReadOnlyToken( auth, getRepoAuthor(), getRepoName(), "Intellij tasks plugin"); } }); } })); } catch (GithubOperationCanceledException ignore) { } catch (IOException e) { GithubNotifications.showErrorDialog(myProject, "Can't get access token", e); } }
public void actionPerformed(ActionEvent e) { text.setBackground(Color.WHITE); // if (e.getSource() == butParent) { // ParentAction parentAction = new ParentAction(); // parentAction.actionPerformed(new ActionEvent(e, 0, "")); // return; // } // if (e.getSource() == butNF) { // NewFolderAction nfAction = new NewFolderAction(); // newFolderAction.actionPerformed(new ActionEvent(e, 0, "")); // return; // } if (e.getSource() == cBox) { int i = cBox.getSelectedIndex(); driver.allFiles = (i == 1); // fullNodeName = (new File(fullNodeName)).getParent(); // driver.properties // .put("allFiles", Boolean.toString(driver.allFiles)); // driver.propertiesChanged = true; // panel.remove(listView); showList(); // selComp = cBox; cBox.requestFocusInWindow(); cBox.setBackground(vLightBlue); // Component c = cBox.getComponent(1); // c.setBackground(vLightBlue); selComp.setFocusable(true); cBox.setEnabled(true); } // repaint(); }
@NotNull private String getToken() { return myToken.getText().trim(); }
@NotNull private String getRepoName() { return myRepoName.getText().trim(); }
@NotNull private String getRepoAuthor() { return myRepoAuthor.getText().trim(); }
public void paintList() { // selComp.setBackground(vLightBlue); if (selComp instanceof JList) { String s = list.getSelectedValue(); if (s == null || s.equals("(empty folder)")) s = ""; // String fn = listHead + File.separator + s; String fn = DrawFBP.makeAbsFileName(s, listHead); if (currentNode == null) { File h = new File(fn); if (h.isDirectory()) { // text.setText(fn); text.setText(listHead); text2.setText(""); // selComp = text2; // text2.setBackground(vLightBlue); // text2.setEditable(true); // Bob's bug! /* SwingUtilities.invokeLater(new Runnable() { public void run() { text2.requestFocusInWindow(); text2.setEnabled(true); text2.getCaret().setVisible(true); } }); */ } else { text2.setText(s); text.setText(listHead); selComp = text2; } } else { // String t = list.getSelectedValue(); DefaultMutableTreeNode ch = currentNode; // findChild(currentNode, // t); if (ch.getChildCount() > 0) { // text.setText(fn); text.setText(listHead); text2.setText(""); // selComp = text2; // text2.setBackground(vLightBlue); // text2.setEditable(true); /* SwingUtilities.invokeLater(new Runnable() { public void run() { text2.requestFocusInWindow(); text2.setEnabled(true); text2.getCaret().setVisible(true); } }); */ } else { text2.setText(list.getSelectedValue()); text.setText(listHead); selComp = text2; } } } repaint(); }
String getSelectedFile() { return DrawFBP.makeAbsFileName(text2.getText(), text.getText()); }
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; }
public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_TAB) { if (selComp == text || selComp == text2) { selComp.setBackground(Color.WHITE); ((JTextField) selComp).setEditable(false); ((JTextField) selComp).getCaret().setVisible(false); } text2.setBackground(Color.WHITE); // list.setSelectedIndex(-1); cBox.repaint(); // if (saveAs) // text2.setBackground(Color.WHITE); if (selComp == cBox) cBox.setRequestFocusEnabled(false); if (selComp instanceof MyButton) { ((MyButton) selComp).setSelected(false); } // selComp.setRequestFocusEnabled(false); selComp.setFocusable(false); // list.setSelectedIndex(-1); if (!shift) selComp = (JComponent) mtp.getComponentAfter(dialog, selComp); else selComp = (JComponent) mtp.getComponentBefore(dialog, selComp); if (selComp == butCopy && !saveAs) if (!shift) selComp = (JComponent) mtp.getComponentAfter(dialog, selComp); else selComp = (JComponent) mtp.getComponentBefore(dialog, selComp); if (selComp == text || selComp == text2) { selComp.setBackground(vLightBlue); ((JTextField) selComp).getCaret().setVisible(true); ((JTextField) selComp).setEditable(true); } if (selComp == null) { selComp = list; } else if (selComp instanceof MyButton) ((MyButton) selComp).setSelected(true); if (selComp instanceof MyComboBox) { cBox.setBackground(vLightBlue); } selComp.setFocusable(true); selComp.requestFocusInWindow(); } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) { shift = true; } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { // if (selComp instanceof JList || selComp == text || selComp == // text2) { enterAction.actionPerformed(new ActionEvent(e, 0, "")); // } } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { // if (selComp instanceof JList) { cancelAction.actionPerformed(new ActionEvent(e, 0, "")); // } } else if (e.getKeyCode() == KeyEvent.VK_DELETE) { if (selComp instanceof JList) { deleteAction.actionPerformed(new ActionEvent(e, 0, "")); } } else if (selComp == cBox && ((e.getKeyCode() == KeyEvent.VK_UP) && driver.allFiles || (e.getKeyCode() == KeyEvent.VK_DOWN) && !driver.allFiles)) { driver.allFiles = !driver.allFiles; cBox.setSelectedIndex(driver.allFiles ? 1 : 0); return; } // else if (selComp == text || selComp == text2) { // selComp = (Component) e.getSource(); // } // repaint(); // String u = list.getSelectedValue(); // force selection // list.setSelectedValue(u, false); paintList(); list.repaint(); repaint(); }
public void mouseClicked(MouseEvent e) { list.setSelectedIndex(-1); list.setRequestFocusEnabled(false); // changedField = null; if (selComp == text || selComp == text2) { selComp.setBackground(Color.WHITE); ((JTextField) selComp).setEditable(false); ((JTextField) selComp).getCaret().setVisible(false); } text2.setBackground(Color.WHITE); // cBox.repaint(); if (selComp instanceof MyButton) { ((MyButton) selComp).setSelected(false); ((MyButton) selComp).setFocusable(false); } selComp = (Component) e.getSource(); if (selComp == text || selComp == text2) { ((JTextField) selComp).setRequestFocusEnabled(true); selComp.setBackground(vLightBlue); ((JTextField) selComp).getCaret().setVisible(true); ((JTextField) selComp).setEditable(true); // ((JTextField) selComp).requestFocusInWindow(); } if (e.getSource() instanceof JList) { selComp = list; int rowNo = list.locationToIndex(e.getPoint()); if (rowNo == -1) return; list.setRequestFocusEnabled(true); list.setSelectedIndex(rowNo); text.setBackground(Color.WHITE); // text2.setBackground(textBackground); // http://stackoverflow.com/questions/16392212/unable-to-type-or-delete-text-in-jtextfield // http://stackoverflow.com/questions/13415150/java-swing-form-and-cannot-type-text-in-newly-added-jtextfield // (this says don't use keylistener!) // http://stackoverflow.com/questions/22642401/jtextfield-and-keylistener-java-swing?rq=1 // textField.getDocument().addDocumentListener(...); // new code // text2.requestFocusInWindow(); // text2.setBackground(vLightBlue); // text2.getCaret().setVisible(true); // String fn = listHead + File.separator + nodeNames[rowNo]; if (e.getClickCount() == 1) { mLoc = e.getLocationOnScreen(); if (nodeNames[rowNo].equals("(empty folder")) return; } else if (e.getClickCount() == 2) { Point p = e.getLocationOnScreen(); if (mLoc != null && Math.abs(p.x - mLoc.x) < 6 && Math.abs(p.y - mLoc.y) < 6) { enterAction.actionPerformed(new ActionEvent(e, 0, "")); } } } if (selComp == cBox) { selComp.setFocusable(true); cBox.requestFocusInWindow(); cBox.setEnabled(true); cBox.setBackground(vLightBlue); } if (selComp instanceof MyButton) { ((MyButton) selComp).setSelected(false); } paintList(); list.repaint(); }