List of usage examples for javax.swing JPasswordField JPasswordField
public JPasswordField()
JPasswordField
, with a default document, null
starting text string, and 0 column width. From source file:de.wusel.partyplayer.gui.LockingStatusbar.java
public LockingStatusbar(Application application, final JFrame mainFrame, final Settings settings) { this.application = application; this.settings = settings; this.application.getContext().getTaskMonitor().addPropertyChangeListener(listener); statusLabel = new JLabel("Ready"); fileReaderProgressBar = new JProgressBar(0, 100); pinCodeInputField = new JPasswordField(); PromptSupport.setPrompt("pin-code", pinCodeInputField); PromptSupport.setForeground(Color.GRAY, pinCodeInputField); pinCodeInputField.addMouseListener(new MouseAdapter() { @Override// w w w. j a v a 2s .com public void mouseClicked(MouseEvent e) { if (!pinCodeInputField.isEnabled()) { ChangePasswordDialog dialog = new ChangePasswordDialog(mainFrame, settings); dialog.setVisible(true); if (dialog.getStatus() == DialogStatus.CONFIRMED) { settings.setNewPassword(dialog.getPassDigest()); settings.backup(PathUtil.getSettingsFile()); } } } }); pinCodeInputField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean unlocked = settings .isPasswordValid(DigestUtils.md5Hex(new String(pinCodeInputField.getPassword()))); if (unlocked) { pinCodeInputField.transferFocus(); unlock(); } pinCodeInputField.setText(null); } }); lockButton = new JToggleButton(); lockButton.setIcon(getIcon("lock")); lockButton.setSelectedIcon(getIcon("lock_open")); lockButton.setEnabled(false); lockButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { lock(); } }); this.settingsButton = new JButton(getIcon("cog_edit")); this.settingsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showSettings(); } }); add(statusLabel, new JXStatusBar.Constraint(JXStatusBar.Constraint.ResizeBehavior.FILL)); add(fileReaderProgressBar, new JXStatusBar.Constraint(200)); add(pinCodeInputField, new JXStatusBar.Constraint(100)); add(lockButton, new JXStatusBar.Constraint()); add(settingsButton, new JXStatusBar.Constraint()); this.mainFrame = mainFrame; }
From source file:com.floreantpos.ui.dialog.PasswordEntryDialog.java
private JPanel createInputPanel() { JPanel inputPanel = new JPanel(new BorderLayout(5, 5)); tfPassword = new JPasswordField(); tfPassword.setFont(tfPassword.getFont().deriveFont(Font.BOLD, PosUIManager.getNumberFieldFontSize())); tfPassword.setFocusable(true);// w ww .j av a 2 s .c o m tfPassword.requestFocus(); tfPassword.setBackground(Color.WHITE); tfPassword.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { String secretKey = getPasswordAsString(); if (secretKey != null && secretKey.length() == TerminalConfig.getDefaultPassLen()) { statusLabel.setText(""); //$NON-NLS-1$ if (checkLogin(secretKey)) { setCanceled(false); dispose(); } } } @Override public void keyPressed(KeyEvent e) { } }); inputPanel.add(tfPassword, BorderLayout.NORTH); statusLabel = new JLabel(); statusLabel.setHorizontalAlignment(JLabel.CENTER); inputPanel.add(statusLabel); return inputPanel; }
From source file:gdt.jgui.tool.JTextEncrypter.java
/** * The default constructor./*from ww w. j av a 2 s. com*/ */ public JTextEncrypter() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JPanel panel = new JPanel(); panel.setBorder( new TitledBorder(null, "Master password", TitledBorder.LEADING, TitledBorder.TOP, null, null)); add(panel); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); JCheckBox chckbxNewCheckBox = new JCheckBox("Show"); chckbxNewCheckBox.setHorizontalTextPosition(SwingConstants.LEFT); chckbxNewCheckBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() != ItemEvent.SELECTED) { passwordField.setEchoChar('*'); } else { passwordField.setEchoChar((char) 0); } } }); panel.add(chckbxNewCheckBox); panel.setFocusTraversalPolicy( new FocusTraversalOnArray(new Component[] { chckbxNewCheckBox, passwordField })); passwordField = new JPasswordField(); passwordField.setMaximumSize(new Dimension(Integer.MAX_VALUE, passwordField.getPreferredSize().height)); panel.add(passwordField); JPanel panel_1 = new JPanel(); panel_1.setBorder(new TitledBorder(null, "Text", TitledBorder.LEADING, TitledBorder.TOP, null, null)); add(panel_1); panel_1.setLayout(new BorderLayout(0, 0)); textArea = new JTextArea(); textArea.setColumns(1); panel_1.add(textArea); }
From source file:BRHInit.java
public void showLoginPrompt() { if (login_window == null) { login_window = new JFrame("BRH Console"); login_window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel top_panel = new JPanel(); login_window.getContentPane().add(top_panel); top_panel.setLayout(new BoxLayout(top_panel, BoxLayout.Y_AXIS)); top_panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JPanel p = new JPanel(); top_panel.add(p);/*from w w w. j a v a 2 s . c o m*/ p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); JPanel col_panel = new JPanel(); p.add(col_panel); col_panel.setLayout(new BoxLayout(col_panel, BoxLayout.Y_AXIS)); col_panel.add(new JLabel("email")); col_panel.add(Box.createRigidArea(new Dimension(0, 5))); col_panel.add(new JLabel("password")); p.add(Box.createRigidArea(new Dimension(5, 0))); col_panel = new JPanel(); p.add(col_panel); col_panel.setLayout(new BoxLayout(col_panel, BoxLayout.Y_AXIS)); col_panel.add(email = new JTextField(20)); col_panel.add(Box.createRigidArea(new Dimension(0, 5))); col_panel.add(password = new JPasswordField()); if (email_arg != null) email.setText(email_arg); if (password_arg != null) password.setText(password_arg); top_panel.add(Box.createRigidArea(new Dimension(0, 10))); p = new JPanel(); top_panel.add(p); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.add(Box.createHorizontalGlue()); p.add(login_ok = new JButton("OK")); p.add(Box.createRigidArea(new Dimension(5, 0))); p.add(login_cancel = new JButton("Cancel")); p.add(Box.createHorizontalGlue()); login_ok.addActionListener(this); login_cancel.addActionListener(this); login_window.pack(); } cookie = null; login_window.setVisible(true); }
From source file:autoGui.RegisterPagePanel.java
RegisterPagePanel(JFrame parent, MouseAdapter backHandler) { parent.getContentPane().add(RegisterPage, "name_22846752421143"); RegisterPage.setLayout(null);/*from ww w . ja v a2 s . c om*/ //System.out.println(parent.getContentPane()); RegisterPage.setBounds(100, 100, 1036, 608); email = new JTextField(); email.setBounds(642, 87, 116, 22); RegisterPage.add(email); email.setColumns(10); JLabel lblEmail = new JLabel("Email*"); lblEmail.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblEmail.setBounds(506, 89, 56, 16); RegisterPage.add(lblEmail); JLabel lblNewLabel = new JLabel("Password*"); lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblNewLabel.setBounds(506, 132, 71, 16); RegisterPage.add(lblNewLabel); JLabel lblFirstName = new JLabel("First Name*"); lblFirstName.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblFirstName.setBounds(141, 87, 88, 16); RegisterPage.add(lblFirstName); firstName = new JTextField(); firstName.setBounds(241, 85, 142, 22); RegisterPage.add(firstName); firstName.setColumns(10); JLabel lblNewLabel_1 = new JLabel("Middle Name"); lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblNewLabel_1.setBounds(141, 132, 88, 16); RegisterPage.add(lblNewLabel_1); middleName = new JTextField(); middleName.setBounds(241, 129, 142, 22); RegisterPage.add(middleName); middleName.setColumns(10); JLabel lblNewLabel_2 = new JLabel("Last Name*"); lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblNewLabel_2.setBounds(141, 174, 88, 16); RegisterPage.add(lblNewLabel_2); lastName = new JTextField(); lastName.setBounds(241, 172, 142, 22); RegisterPage.add(lastName); lastName.setColumns(10); JLabel lblPersonalInformation = new JLabel("Personal Information"); lblPersonalInformation.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblPersonalInformation.setBounds(86, 33, 159, 27); RegisterPage.add(lblPersonalInformation); JLabel lblContactInformation = new JLabel("Contact Information"); lblContactInformation.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblContactInformation.setBounds(459, 33, 175, 27); RegisterPage.add(lblContactInformation); JLabel lblPhoneNumber = new JLabel("Phone*"); lblPhoneNumber.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblPhoneNumber.setBounds(506, 217, 71, 16); RegisterPage.add(lblPhoneNumber); phone = new JTextField(); phone.setBounds(642, 215, 116, 22); RegisterPage.add(phone); phone.setColumns(10); password = new JPasswordField(); password.setBounds(642, 130, 116, 22); RegisterPage.add(password); JButton btnBack_5 = new JButton("Back"); btnBack_5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); btnBack_5.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (lastPage == 6) { lastPage = 4; } RegisterPage.setVisible(false); parent.getContentPane().getComponent(lastPage).setVisible(true); backHandler.mouseClicked(e); } }); btnBack_5.setBounds(12, 525, 97, 25); RegisterPage.add(btnBack_5); JButton btnExit_6 = new JButton("Exit"); btnExit_6.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { parent.setVisible(false); parent.dispose(); } }); btnExit_6.setBounds(909, 525, 97, 25); RegisterPage.add(btnExit_6); JLabel lblAddress = new JLabel("Address*"); lblAddress.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblAddress.setBounds(141, 217, 56, 16); RegisterPage.add(lblAddress); address = new JTextField(); address.setBounds(241, 215, 142, 22); RegisterPage.add(address); address.setColumns(10); address2 = new JTextField(); address2.setBounds(241, 260, 142, 22); RegisterPage.add(address2); address2.setColumns(10); JLabel lblCity = new JLabel("City*"); lblCity.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblCity.setBounds(141, 308, 56, 16); RegisterPage.add(lblCity); city = new JTextField(); city.setBounds(241, 306, 142, 22); RegisterPage.add(city); city.setColumns(10); JLabel lblAddress_1 = new JLabel("Address 2"); lblAddress_1.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblAddress_1.setBounds(141, 263, 77, 16); RegisterPage.add(lblAddress_1); JLabel lblZip = new JLabel("Zip*"); lblZip.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblZip.setBounds(141, 402, 56, 16); RegisterPage.add(lblZip); zip = new JTextField(); zip.setBounds(241, 400, 142, 22); RegisterPage.add(zip); zip.setColumns(10); JLabel lblState = new JLabel("State*"); lblState.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblState.setBounds(141, 355, 56, 16); RegisterPage.add(lblState); state = new JTextField(); state.setBounds(241, 353, 142, 22); RegisterPage.add(state); state.setColumns(10); JLabel lblRequired = new JLabel("* = required"); lblRequired.setBounds(301, 39, 88, 16); RegisterPage.add(lblRequired); JLabel lblLicenseInfo = new JLabel("License Information"); lblLicenseInfo.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblLicenseInfo.setBounds(459, 257, 148, 27); RegisterPage.add(lblLicenseInfo); JLabel lblNumber = new JLabel("Number*"); lblNumber.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblNumber.setBounds(506, 310, 71, 16); RegisterPage.add(lblNumber); license = new JTextField(); license.setBounds(642, 306, 116, 22); RegisterPage.add(license); license.setColumns(10); JLabel lblDateOfBirth = new JLabel("Date of Birth*"); lblDateOfBirth.setBounds(506, 372, 88, 16); RegisterPage.add(lblDateOfBirth); birthMonth = new JComboBox(); birthMonth.setModel(new DefaultComboBoxModel(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" })); birthMonth.setBounds(642, 370, 71, 22); RegisterPage.add(birthMonth); birthDay = new JComboBox(); birthDay.setModel(new DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" })); birthDay.setBounds(708, 370, 62, 22); RegisterPage.add(birthDay); List<Integer> years = new ArrayList<Integer>(); for (int i = 1915; i <= 2015; ++i) { years.add(i); } birthYear = new JComboBox(years.toArray()); birthYear.setBounds(769, 370, 97, 22); RegisterPage.add(birthYear); JButton btnContinue = new JButton("Continue ->"); btnContinue.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { register(parent); } }); btnContinue.setBounds(674, 428, 133, 34); RegisterPage.add(btnContinue); JLabel lblConfirmPassword = new JLabel("Confirm Password*"); lblConfirmPassword.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblConfirmPassword.setBounds(506, 174, 121, 16); RegisterPage.add(lblConfirmPassword); repassword = new JPasswordField(); repassword.setBounds(642, 172, 116, 22); RegisterPage.add(repassword); JLabel lblNewLabel_3 = new JLabel("Credit card #*"); lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblNewLabel_3.setBounds(141, 448, 93, 16); RegisterPage.add(lblNewLabel_3); cardNumber = new JTextField(); cardNumber.setBounds(241, 443, 142, 28); RegisterPage.add(cardNumber); cardNumber.setColumns(10); JLabel lblCardExp = new JLabel("Card exp*"); lblCardExp.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblCardExp.setBounds(141, 496, 82, 16); RegisterPage.add(lblCardExp); cardExpMonth = new JComboBox(); cardExpMonth.setModel(new DefaultComboBoxModel(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" })); cardExpMonth.setBounds(238, 493, 77, 27); RegisterPage.add(cardExpMonth); cardExpDay = new JComboBox(); cardExpDay.setModel(new DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" })); cardExpDay.setBounds(312, 493, 71, 27); RegisterPage.add(cardExpDay); JLabel lblLicenseState = new JLabel("License state*"); lblLicenseState.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblLicenseState.setBounds(506, 338, 88, 16); RegisterPage.add(lblLicenseState); licenseState = new JTextField(); licenseState.setBounds(642, 333, 116, 28); RegisterPage.add(licenseState); licenseState.setColumns(10); RegisterPage.setVisible(false); }
From source file:ca.sqlpower.wabit.swingui.enterprise.UserPanel.java
public UserPanel(User baseUser) { final MessageDigest digester; try {/*from w w w . j ava2 s .c om*/ digester = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e1) { throw new RuntimeException(e1); } this.user = baseUser; this.workspace = (WabitWorkspace) this.user.getParent(); this.loginTextField = new JTextField(); this.loginTextField.setText(user.getName()); this.loginLabel = new JLabel("User name"); this.loginTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { user.setName(loginTextField.getText()); } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.passwordTextField = new JPasswordField(); this.passwordLabel = new JLabel("Password"); this.passwordTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { try { String pass = new String(passwordTextField.getPassword()); String encoded = new String(Hex.encodeHex(digester.digest(pass.getBytes("UTF-8")))); user.setPassword(encoded); } catch (UnsupportedEncodingException e1) { throw new RuntimeException(e1); } } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.fullNameTextField = new JTextField(); this.fullNameTextField.setText(user.getFullName()); this.fullNameLabel = new JLabel("Full name"); this.fullNameTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { user.setFullName(fullNameTextField.getText()); } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.emailTextField = new JTextField(); this.emailTextField.setText(user.getEmail()); this.emailLabel = new JLabel("Email"); this.emailTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { user.setEmail(emailTextField.getText()); } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.availableGroupsLabel = new JLabel("Available Groups"); this.availableGroupsListModel = new GroupsListModel(user, workspace, false); this.availableGroupsList = new JList(this.availableGroupsListModel); this.availableGroupsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.availableGroupsList.setCellRenderer(new DefaultListCellRenderer() { final JTree dummyTree = new JTree(); final WorkspaceTreeCellRenderer delegate = new WorkspaceTreeCellRenderer(); @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return delegate.getTreeCellRendererComponent(dummyTree, value, isSelected, false, true, 0, cellHasFocus); } }); this.availableGroupsScrollPane = new JScrollPane(this.availableGroupsList); this.currentGroupsLabel = new JLabel("Current Memberships"); this.currentGroupsListModel = new GroupsListModel(user, workspace, true); this.currentGroupsList = new JList(this.currentGroupsListModel); this.currentGroupsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.currentGroupsList.setCellRenderer(new DefaultListCellRenderer() { final JTree dummyTree = new JTree(); final WorkspaceTreeCellRenderer delegate = new WorkspaceTreeCellRenderer(); @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return delegate.getTreeCellRendererComponent(dummyTree, value, isSelected, false, true, 0, cellHasFocus); } }); this.groupsLabel = new JLabel("Edit user memberships"); this.currentGroupsScrollPane = new JScrollPane(this.currentGroupsList); this.addButton = new JButton(">"); this.addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] selection = availableGroupsList.getSelectedValues(); if (selection.length == 0) { return; } try { workspace.begin("Add user to groups"); for (Object object : selection) { ((Group) object).addMember(new GroupMember(user)); } } finally { workspace.commit(); } } }); this.removeButton = new JButton("<"); this.removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] selection = currentGroupsList.getSelectedValues(); if (selection.length == 0) { return; } try { workspace.begin("Remove user from groups"); Map<Group, GroupMember> toRemove = new ArrayMap<Group, GroupMember>(); for (Object object : selection) { for (GroupMember membership : ((Group) object).getChildren(GroupMember.class)) { if (membership.getUser().getUUID().equals(user.getUUID())) { toRemove.put((Group) object, membership); } } } for (Entry<Group, GroupMember> entry : toRemove.entrySet()) { entry.getKey().removeMember(entry.getValue()); } } finally { workspace.commit(); } } }); Action deleteAction = new DeleteFromTreeAction(this.workspace, this.user, this.panel, this.workspace.getSession().getContext()); this.toolbarBuilder.add(deleteAction, "Delete this user", WabitIcons.DELETE_ICON_32); // Panel building time JPanel namePassPanel = new JPanel(new MigLayout()); namePassPanel.add(this.loginLabel, "align right, gaptop 20"); namePassPanel.add(this.loginTextField, "span, wrap, wmin 600"); namePassPanel.add(this.passwordLabel, "align right"); namePassPanel.add(this.passwordTextField, "span, wrap, wmin 600"); namePassPanel.add(this.fullNameLabel, "align right, gaptop 20"); namePassPanel.add(this.fullNameTextField, "span, wrap, wmin 600"); namePassPanel.add(this.emailLabel, "align right"); namePassPanel.add(this.emailTextField, "span, wrap, wmin 600"); this.panel.add(namePassPanel, "north"); this.panel.add(this.groupsLabel, "span, wrap, gaptop 20, align center"); JPanel buttonsPanel = new JPanel(new MigLayout()); buttonsPanel.add(this.addButton, "wrap"); buttonsPanel.add(this.removeButton); JPanel availablePanel = new JPanel(new MigLayout()); availablePanel.add(this.availableGroupsLabel, "wrap, align center"); availablePanel.add(this.availableGroupsScrollPane, "wmin 300"); JPanel currentPanel = new JPanel(new MigLayout()); currentPanel.add(this.currentGroupsLabel, "wrap, align center"); currentPanel.add(this.currentGroupsScrollPane, "wmin 300"); this.panel.add(availablePanel); this.panel.add(buttonsPanel, "shrink, span 1 2"); this.panel.add(currentPanel); }
From source file:com.googlecode.gmail4j.util.LoginDialog.java
/** * Creates the dialog//from ww w . java 2s . c o m * * @param prompt Dialog prompt */ private void createDialog(final String prompt) { dialog = new JFrame(prompt); dialog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); latch = new CountDownLatch(1); labelUser = new JLabel("Username"); labelPass = new JLabel("Password"); user = new JTextField(); pass = new JPasswordField(); ok = new JButton("OK"); }
From source file:com.microsoftopentechnologies.intellij.helpers.AndroidStudioHelper.java
public static void newActivityTemplateManager() throws IOException, InterruptedException { String[] cmd = null;//from w w w.ja v a2 s . com String templatePath = URLDecoder .decode(ApplicationComponent.class.getResource("").getPath().replace("file:/", ""), "UTF-8"); templatePath = templatePath.replace("/", File.separator); templatePath = templatePath.substring(0, templatePath.indexOf(File.separator + "lib")); templatePath = templatePath + File.separator + "plugins" + File.separator + "android" + File.separator; templatePath = templatePath + "lib" + File.separator + "templates" + File.separator + "activities" + File.separator; String[] env = null; if (!new File(templatePath + mobileServicesTemplateName).exists()) { String tmpdir = getTempLocation(); BufferedInputStream bufferedInputStream = new BufferedInputStream( ServiceCodeReferenceHelper.getTemplateResource("ActivityTemplate.zip")); unZip(bufferedInputStream, tmpdir); if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { try { copyFolder(new File(tmpdir + mobileServicesTemplateName), new File(templatePath + mobileServicesTemplateName)); copyFolder(new File(tmpdir + officeTemplateName), new File(templatePath + officeTemplateName)); } catch (IOException ex) { PrintWriter printWriter = new PrintWriter(tmpdir + "\\script.bat"); printWriter.println("@echo off"); printWriter.println("md \"" + templatePath + mobileServicesTemplateName + "\""); printWriter.println("md \"" + templatePath + officeTemplateName + "\""); printWriter.println("xcopy \"" + tmpdir + mobileServicesTemplateName + "\" \"" + templatePath + mobileServicesTemplateName + "\" /s /i /Y"); printWriter.println("xcopy \"" + tmpdir + officeTemplateName + "\" \"" + templatePath + officeTemplateName + "\" /s /i /Y"); printWriter.flush(); printWriter.close(); String[] tmpcmd = { tmpdir + "\\elevate.exe", "script.bat", "1" }; cmd = tmpcmd; ArrayList<String> tempenvlist = new ArrayList<String>(); for (String envval : System.getenv().keySet()) tempenvlist.add(String.format("%s=%s", envval, System.getenv().get(envval))); tempenvlist.add("PRECOMPILE_STREAMLINE_FILES=1"); env = new String[tempenvlist.size()]; tempenvlist.toArray(env); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(cmd, env, new File(tmpdir)); proc.waitFor(); //wait for elevate command to finish Thread.sleep(3000); if (!new File(templatePath + mobileServicesTemplateName).exists()) UIHelper.showException( "Error copying template files. Please refer to documentation to copy manually.", new Exception()); } } else { if (System.getProperty("os.name").toLowerCase().startsWith("mac")) { String[] strings = { "osascript", // "-e", // "do shell script \"mkdir -p \\\"/" + templatePath + mobileServicesTemplateName + "\\\"\"", // "-e", // "do shell script \"mkdir -p \\\"/" + templatePath + officeTemplateName + "\\\"\"", "-e", "do shell script \"cp -Rp \\\"" + tmpdir + mobileServicesTemplateName + "\\\" \\\"/" + templatePath + "\\\"\"", "-e", "do shell script \"cp -Rp \\\"" + tmpdir + officeTemplateName + "\\\" \\\"/" + templatePath + "\\\"\"" }; exec(strings, tmpdir); } else { try { copyFolder(new File(tmpdir + mobileServicesTemplateName), new File(templatePath + mobileServicesTemplateName)); copyFolder(new File(tmpdir + officeTemplateName), new File(templatePath + officeTemplateName)); } catch (IOException ex) { JPasswordField pf = new JPasswordField(); int okCxl = JOptionPane.showConfirmDialog(null, pf, "To copy Microsoft Services templates, the plugin needs your password:", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (okCxl == JOptionPane.OK_OPTION) { String password = new String(pf.getPassword()); exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp", tmpdir + mobileServicesTemplateName, templatePath + mobileServicesTemplateName }, tmpdir); exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp", tmpdir + officeTemplateName, templatePath + officeTemplateName }, tmpdir); } } } } } }
From source file:DownloadDialog.java
/******************************************************************** * Constructor: DownloadDialog/*from w w w. j a va2 s . co m*/ * Purpose: constructor for download, with necessary references /*******************************************************************/ public DownloadDialog(final MainApplication context, Scheduler scheduler_Ref, JList courseListSelected_Ref, JList courseListAll_Ref) { // Basic setup for dialog setModalityType(Dialog.ModalityType.APPLICATION_MODAL); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); setTitle(TITLE); // Setup proper references this.scheduler = scheduler_Ref; this.courseListSelected = courseListSelected_Ref; this.courseListAll = courseListAll_Ref; // Store available terms storeTerms(); // Constraints GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(10, 10, 10, 10); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.gridwidth = 2; // Main panel panel = new JPanel(new GridBagLayout()); // Add term select box termCB = new JComboBox(termsName.toArray()); panel.add(termCB, c); // Setup username and password labels JLabel userL = new JLabel("Username:"); JLabel passL = new JLabel("Password:"); c.gridwidth = 1; c.gridx = 0; c.weightx = 0; // Add user label c.gridy = 1; c.insets = new Insets(5, 10, 0, 10); panel.add(userL, c); // Add password label c.gridy = 2; c.insets = new Insets(0, 10, 5, 10); panel.add(passL, c); // Setup user and pass text fields user = new JTextField(); pass = new JPasswordField(); c.weightx = 1; c.gridx = 1; // Add user field c.gridy = 1; c.insets = new Insets(5, 10, 2, 10); panel.add(user, c); // Add pass field c.gridy = 2; c.insets = new Insets(2, 10, 5, 10); panel.add(pass, c); // Setup login button JButton login = new JButton("Login"); login.addActionListener(this); c.insets = new Insets(10, 10, 10, 10); c.gridx = 0; c.gridy = 3; c.gridwidth = 2; c.weightx = 1; panel.add(login, c); // Add panel to main box add(panel); // Pack the components and give userbox focus pack(); user.requestFocus(); // Create worker to download courses worker = new SwingWorker<Void, Void>() { protected Void doInBackground() throws Exception { // Reset courses scheduler.resetCourses(); // Constraints GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(10, 10, 10, 10); c.gridx = 0; c.weightx = 1; c.weighty = 0; // Remove all elements panel.removeAll(); // Add status JLabel status = new JLabel("Connecting..."); c.gridy = 0; panel.add(status, c); // Add progress bar JProgressBar progressBar = new JProgressBar(0, SUBJECTS.length); c.gridy = 1; panel.add(progressBar, c); progressBar.setPreferredSize(new Dimension(275, 12)); // Revalidate, repaint, and pack //revalidate(); repaint(); pack(); try { // Create client DefaultHttpClient client = new DefaultHttpClient(); // Setup and execute initial login HttpGet initialLogin = new HttpGet("http://jweb.kettering.edu/cku1/twbkwbis.P_ValLogin"); HttpResponse response = client.execute(initialLogin); HTMLParser.parse(response); // Get current term String term = termsValue.get(termCB.getSelectedIndex()); // Consume entity (cookies) HttpEntity entity = response.getEntity(); if (entity != null) entity.consumeContent(); // Create post for login HttpPost login = new HttpPost("http://jweb.kettering.edu/cku1/twbkwbis.P_ValLogin"); // Parameters List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("sid", user.getText())); parameters.add(new BasicNameValuePair("PIN", pass.getText())); login.setEntity(new UrlEncodedFormEntity(parameters)); login.setHeader("Referer", "http://jweb.kettering.edu/cku1/twbkwbis.P_ValLogin"); // Login ! response = client.execute(login); // Store proper cookies List<Cookie> cookies = client.getCookieStore().getCookies(); // Start off assuming logging in failed boolean loggedIn = false; // Check cookies for successful login for (int i = 0; i < cookies.size(); i++) if (cookies.get(i).getName().equals("SESSID")) loggedIn = true; // Success? if (loggedIn) { // Consumption of feed HTMLParser.parse(response); // Execute GET class list page HttpGet classList = new HttpGet( "http://jweb.kettering.edu/cku1/bwskfcls.p_sel_crse_search"); classList.setHeader("Referer", "https://jweb.kettering.edu/cku1/twbkwbis.P_GenMenu"); response = client.execute(classList); HTMLParser.parse(response); // Execute GET for course page HttpGet coursePage = new HttpGet( "http://jweb.kettering.edu/cku1/bwckgens.p_proc_term_date?p_calling_proc=P_CrseSearch&p_term=" + term); coursePage.setHeader("Referer", "http://jweb.kettering.edu/cku1/bwskfcls.p_sel_crse_search"); response = client.execute(coursePage); HTMLParser.parse(response); // Download every subject's data for (int index = 0; index < SUBJECTS.length; index++) { // Don't download if cancel was pressed if (isCancelled()) break; // Update status, progress bar, then store course String subject = SUBJECTS[index]; status.setText("Downloading " + subject); progressBar.setValue(index); scheduler.storeDynamicCourse(subject, client, term); } // Update course list data courseListAll.setListData(scheduler.getCourseIDs().toArray()); // Clear course list data String[] empty = {}; courseListSelected.setListData(empty); context.updatePermutations(); context.updateSchedule(); // Dispose of dialog if cancelled if (!isCancelled()) { dispose(); } } // Invalid login? else { // Update status status.setText("Invalid login."); } } // Failed to download? catch (Exception exc) { // Show stack trace, and update status exc.printStackTrace(); status.setText("Failed downloading."); } return null; } }; // Setup window close event to be same as cancel this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // Cancel all downloads then dispose worker.cancel(true); dispose(); } }); // Make sure dialog is visible setLocationRelativeTo(context); setVisible(true); }
From source file:ca.phon.app.session.editor.TranscriberSelectionDialog.java
/** Init display and listeners */ private void initDialog() { // setup layout // layout will be seperated into two sections, existing // and new transcripts FormLayout outerLayout = new FormLayout("3dlu, pref, right:pref:grow, 3dlu", "pref, 3dlu, top:pref:noGrow, 3dlu, pref, 3dlu, fill:pref:grow, 3dlu, pref"); this.getContentPane().setLayout(outerLayout); // create the 'new' panel first FormLayout newLayout = new FormLayout("left:pref:noGrow, 3dlu, fill:pref:grow", "bottom:pref:noGrow, 3dlu, bottom:pref:noGrow, 3dlu, bottom:pref:noGrow, 3dlu, bottom:pref:noGrow, 3dlu, bottom:pref:noGrow, fill:pref:grow"); JPanel newPanel = new JPanel(newLayout); this.newTranscriptButton = new JRadioButton(); this.newTranscriptButton.setText("New Transcriber"); this.newTranscriptButton.setSelected(true); this.newTranscriptButton.addActionListener(new ActionListener() { @Override/* w w w. j a v a 2 s .c o m*/ public void actionPerformed(ActionEvent arg0) { realNameField.setEnabled(true); usernameField.setEnabled(true); passwordRequiredBox.setEnabled(true); if (passwordRequiredBox.isSelected()) { passwordField.setEnabled(true); checkField.setEnabled(true); } existingUserList.setEnabled(false); } }); this.existingTranscriptButton = new JRadioButton(); this.existingTranscriptButton.setText("Existing Transcriber"); this.existingTranscriptButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { realNameField.setEnabled(false); usernameField.setEnabled(false); passwordRequiredBox.setEnabled(false); passwordField.setEnabled(false); checkField.setEnabled(false); existingUserList.setEnabled(true); } }); ButtonGroup bg = new ButtonGroup(); bg.add(this.newTranscriptButton); bg.add(this.existingTranscriptButton); this.realNameField = new JTextField(); this.usernameField = new JTextField(); this.passwordRequiredBox = new JCheckBox(); this.passwordRequiredBox.setText("Use password"); this.passwordRequiredBox.setSelected(false); this.passwordRequiredBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { passwordField.setEnabled(passwordRequiredBox.isSelected()); checkField.setEnabled(passwordRequiredBox.isSelected()); } }); this.passwordField = new JPasswordField(); this.passwordField.setEnabled(false); this.checkField = new JPasswordField(); this.checkField.setEnabled(false); CellConstraints cc = new CellConstraints(); newPanel.add(new JLabel("Full Name:"), cc.xy(1, 1)); newPanel.add(this.realNameField, cc.xy(3, 1)); newPanel.add(new JLabel("Username:"), cc.xy(1, 3)); newPanel.add(this.usernameField, cc.xy(3, 3)); newPanel.add(this.passwordRequiredBox, cc.xyw(1, 5, 3)); newPanel.add(new JLabel("Password:"), cc.xy(1, 7)); newPanel.add(this.passwordField, cc.xy(3, 7)); newPanel.add(this.checkField, cc.xy(3, 9)); // create the 'existing' panel FormLayout existingLayout = new FormLayout( // just a list "fill:pref:grow", "fill:pref:grow"); JPanel existingPanel = new JPanel(existingLayout); List<String> existingUserData = new ArrayList<String>(); for (Transcriber t : session.getTranscribers()) existingUserData.add(t.getRealName() + " - " + t.getUsername()); this.existingUserList = new JList(existingUserData.toArray()); this.existingUserList.setEnabled(false); existingPanel.add(this.existingUserList, cc.xy(1, 1)); // create the button panel this.okButton = new JButton("OK"); this.okButton.setDefaultCapable(true); this.okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (checkDialog()) { okHandler(); } } }); getRootPane().setDefaultButton(okButton); this.cancelButton = new JButton("Cancel"); this.cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { cancelHandler(); } }); final JComponent bar = ButtonBarBuilder.buildOkCancelBar(okButton, cancelButton); this.getContentPane().add(bar, cc.xy(3, 9)); this.getContentPane().add(this.newTranscriptButton, cc.xy(2, 1)); this.getContentPane().add(newPanel, cc.xyw(2, 3, 2)); this.getContentPane().add(this.existingTranscriptButton, cc.xy(2, 5)); this.getContentPane().add(new JScrollPane(existingPanel), cc.xyw(2, 7, 2)); }