List of usage examples for javax.swing JPasswordField JPasswordField
public JPasswordField(int columns)
JPasswordField
with the specified number of columns. From source file:com.bright.json.PGS.java
public static void main(String[] args) throws FileNotFoundException { String fileBasename = null;// www. j av a 2 s . co m JFileChooser chooser = new JFileChooser(); try { FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel Spreadsheets", "xls", "xlsx"); chooser.setFileFilter(filter); chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home"))); chooser.setDialogTitle("Select the Excel file"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); System.out.println("getSelectedFile() : " + chooser.getSelectedFile()); // String fileBasename = // chooser.getSelectedFile().toString().substring(chooser.getSelectedFile().toString().lastIndexOf(File.separator)+1,chooser.getSelectedFile().toString().lastIndexOf(".")); fileBasename = chooser.getSelectedFile().toString() .substring(chooser.getSelectedFile().toString().lastIndexOf(File.separator) + 1); System.out.println("Base name: " + fileBasename); } else { System.out.println("No Selection "); } } catch (Exception e) { System.out.println(e.toString()); } String fileName = chooser.getSelectedFile().toString(); InputStream inp = new FileInputStream(fileName); Workbook workbook = null; if (fileName.toLowerCase().endsWith("xlsx")) { try { workbook = new XSSFWorkbook(inp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (fileName.toLowerCase().endsWith("xls")) { try { workbook = new HSSFWorkbook(inp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Sheet nodeSheet = workbook.getSheet("Devices"); Sheet interfaceSheet = workbook.getSheet("Interfaces"); System.out.println("Read nodes sheet."); // Row nodeRow = nodeSheet.getRow(1); // System.out.println(row.getCell(0).toString()); // System.exit(0); JTextField uiHost = new JTextField("demo.brightcomputing.com"); // TextPrompt puiHost = new // TextPrompt("demo.brightcomputing.com",uiHost); JTextField uiUser = new JTextField("root"); // TextPrompt puiUser = new TextPrompt("root", uiUser); JTextField uiPass = new JPasswordField(""); // TextPrompt puiPass = new TextPrompt("x5deix5dei", uiPass); JPanel myPanel = new JPanel(new GridLayout(5, 1)); myPanel.add(new JLabel("Bright HeadNode hostname:")); myPanel.add(uiHost); // myPanel.add(Box.createHorizontalStrut(1)); // a spacer myPanel.add(new JLabel("Username:")); myPanel.add(uiUser); myPanel.add(new JLabel("Password:")); myPanel.add(uiPass); int result = JOptionPane.showConfirmDialog(null, myPanel, "Please fill in all the fields.", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { System.out.println("Input received."); } String rhost = uiHost.getText(); String ruser = uiUser.getText(); String rpass = uiPass.getText(); String cmURL = "https://" + rhost + ":8081/json"; List<Cookie> cookies = doLogin(ruser, rpass, cmURL); chkVersion(cmURL, cookies); Map<String, Long> categories = UniqueKeyMap(cmURL, "cmdevice", "getCategories", cookies); Map<String, Long> networks = UniqueKeyMap(cmURL, "cmnet", "getNetworks", cookies); Map<String, Long> partitions = UniqueKeyMap(cmURL, "cmpart", "getPartitions", cookies); Map<String, Long> racks = UniqueKeyMap(cmURL, "cmpart", "getRacks", cookies); Map<String, Long> switches = UniqueKeyMap(cmURL, "cmdevice", "getEthernetSwitches", cookies); // System.out.println(switches.get("switch01")); // System.out.println("Size of the map: "+ switches.size()); // System.exit(0); cmDevice newnode = new cmDevice(); cmDevice.deviceObject devObj = new cmDevice.deviceObject(); cmDevice.switchObject switchObj = new cmDevice.switchObject(); // cmDevice.netObject netObj = new cmDevice.netObject(); List<String> emptyslist = new ArrayList<String>(); // Row nodeRow = nodeSheet.getRow(1); // Row ifRow = interfaceSheet.getRow(1); // System.out.println(nodeRow.getCell(0).toString()); // nodeRow.getCell(3).getStringCellValue() Map<String, ArrayList<cmDevice.netObject>> ifmap = new HashMap<String, ArrayList<cmDevice.netObject>>(); // Map<String,netObject> helperMap = new HashMap<String,netObject>(); // Iterator<Row> rows = interfaceSheet.rowIterator (); // while (rows. < interfaceSheet.getPhysicalNumberOfRows()) { // List<netObject> netList = new ArrayList<netObject>(); for (int i = 0; i < interfaceSheet.getPhysicalNumberOfRows(); i++) { Row ifRow = interfaceSheet.getRow(i); if (ifRow.getRowNum() == 0) { continue; // just skip the rows if row number is 0 } System.out.println("Row nr: " + ifRow.getRowNum()); cmDevice.netObject netObj = new cmDevice.netObject(); ArrayList<cmDevice.netObject> helperList = new ArrayList<cmDevice.netObject>(); netObj.setBaseType("NetworkInterface"); netObj.setCardType(ifRow.getCell(3).getStringCellValue()); netObj.setChildType(ifRow.getCell(4).getStringCellValue()); netObj.setDhcp((ifRow.getCell(5).getNumericCellValue() > 0.1) ? true : false); netObj.setIp(ifRow.getCell(7).getStringCellValue()); // netObj.setMac(ifRow.getCell(0).toString()); //netObj.setModified(true); netObj.setName(ifRow.getCell(1).getStringCellValue()); netObj.setNetwork(networks.get(ifRow.getCell(6).getStringCellValue())); //netObj.setOldLocalUniqueKey(0L); netObj.setRevision(""); netObj.setSpeed(ifRow.getCell(8, Row.CREATE_NULL_AS_BLANK).getStringCellValue()); netObj.setStartIf("ALWAYS"); netObj.setToBeRemoved(false); netObj.setUniqueKey((long) ifRow.getCell(2).getNumericCellValue()); //netObj.setAdditionalHostnames(new ArrayList<String>(Arrays.asList(ifRow.getCell(9, Row.CREATE_NULL_AS_BLANK).getStringCellValue().split("\\s*,\\s*")))); //netObj.setMac(ifRow.getCell(10, Row.CREATE_NULL_AS_BLANK).getStringCellValue()); netObj.setMode((int) ifRow.getCell(11, Row.CREATE_NULL_AS_BLANK).getNumericCellValue()); netObj.setOptions(ifRow.getCell(12, Row.CREATE_NULL_AS_BLANK).getStringCellValue()); netObj.setMembers(new ArrayList<String>(Arrays .asList(ifRow.getCell(13, Row.CREATE_NULL_AS_BLANK).getStringCellValue().split("\\s*,\\s*")))); // ifmap.put(ifRow.getCell(0).getStringCellValue(), new // HashMap<String, cmDevice.netObject>()); // helperMap.put(ifRow.getCell(1).getStringCellValue(), netObj) ; // ifmap.get(ifRow.getCell(0).getStringCellValue()).putIfAbsent(ifRow.getCell(1).getStringCellValue(), // netObj); // ifmap.put(ifRow.getCell(0).getStringCellValue(), helperMap); if (!ifmap.containsKey(ifRow.getCell(0).getStringCellValue())) { ifmap.put(ifRow.getCell(0).getStringCellValue(), new ArrayList<cmDevice.netObject>()); } helperList = ifmap.get(ifRow.getCell(0).getStringCellValue()); helperList.add(netObj); ifmap.put(ifRow.getCell(0).getStringCellValue(), helperList); continue; } for (int i = 0; i < nodeSheet.getPhysicalNumberOfRows(); i++) { Row nodeRow = nodeSheet.getRow(i); if (nodeRow.getRowNum() == 0) { continue; // just skip the rows if row number is 0 } newnode.setService("cmdevice"); newnode.setCall("addDevice"); Map<String, Long> ifmap2 = new HashMap<String, Long>(); for (cmDevice.netObject j : ifmap.get(nodeRow.getCell(0).getStringCellValue())) ifmap2.put(j.getName(), j.getUniqueKey()); switchObj.setEthernetSwitch(switches.get(nodeRow.getCell(8).getStringCellValue())); System.out.println(nodeRow.getCell(8).getStringCellValue()); System.out.println(switches.get(nodeRow.getCell(8).getStringCellValue())); switchObj.setPrt((int) nodeRow.getCell(9).getNumericCellValue()); switchObj.setBaseType("SwitchPort"); devObj.setBaseType("Device"); // devObj.setCreationTime(0L); devObj.setCustomPingScript(""); devObj.setCustomPingScriptArgument(""); devObj.setCustomPowerScript(""); devObj.setCustomPowerScriptArgument(""); devObj.setCustomRemoteConsoleScript(""); devObj.setCustomRemoteConsoleScriptArgument(""); devObj.setDisksetup(""); devObj.setBmcPowerResetDelay(0L); devObj.setBurning(false); devObj.setEthernetSwitch(switchObj); devObj.setExcludeListFull(""); devObj.setExcludeListGrab(""); devObj.setExcludeListGrabnew(""); devObj.setExcludeListManipulateScript(""); devObj.setExcludeListSync(""); devObj.setExcludeListUpdate(""); devObj.setFinalize(""); devObj.setRack(racks.get(nodeRow.getCell(10).getStringCellValue())); devObj.setRackHeight((long) nodeRow.getCell(11).getNumericCellValue()); devObj.setRackPosition((long) nodeRow.getCell(12).getNumericCellValue()); devObj.setIndexInsideContainer(0L); devObj.setInitialize(""); devObj.setInstallBootRecord(false); devObj.setInstallMode(""); devObj.setIoScheduler(""); devObj.setLastProvisioningNode(0L); devObj.setMac(nodeRow.getCell(6).getStringCellValue()); devObj.setModified(true); devObj.setCategory(categories.get(nodeRow.getCell(1).getStringCellValue())); devObj.setChildType("PhysicalNode"); //devObj.setDatanode((nodeRow.getCell(5).getNumericCellValue() > 0.1) ? true // : false); devObj.setHostname(nodeRow.getCell(0).getStringCellValue()); devObj.setModified(true); devObj.setPartition(partitions.get(nodeRow.getCell(2).getStringCellValue())); devObj.setUseExclusivelyFor("Category"); devObj.setNextBootInstallMode(""); devObj.setNotes(""); devObj.setOldLocalUniqueKey(0L); devObj.setPowerControl(nodeRow.getCell(7).getStringCellValue()); // System.out.println(ifmap.get("excelnode001").size()); // System.out.println(ifmap.get(nodeRow.getCell(0).getStringCellValue()).get(nodeRow.getCell(3).getStringCellValue()).getUniqueKey()); devObj.setManagementNetwork(networks.get(nodeRow.getCell(3).getStringCellValue())); devObj.setProvisioningNetwork(ifmap2.get(nodeRow.getCell(4).getStringCellValue())); devObj.setProvisioningTransport("RSYNCDAEMON"); devObj.setPxelabel(""); // "rack": 90194313218, // "rackHeight": 1, // "rackPosition": 4, devObj.setRaidconf(""); devObj.setRevision(""); devObj.setSoftwareImageProxy(null); devObj.setStartNewBurn(false); devObj.setTag("00000000a000"); devObj.setToBeRemoved(false); // devObj.setUcsInfoConfigured(null); // devObj.setUniqueKey(12345L); devObj.setUserdefined1(""); devObj.setUserdefined2(""); ArrayList<Object> mylist = new ArrayList<Object>(); ArrayList<cmDevice.netObject> mylist2 = new ArrayList<cmDevice.netObject>(); ArrayList<Object> emptylist = new ArrayList<Object>(); devObj.setFsexports(emptylist); devObj.setFsmounts(emptylist); devObj.setGpuSettings(emptylist); devObj.setFspartAssociations(emptylist); devObj.setPowerDistributionUnits(emptyslist); devObj.setRoles(emptylist); devObj.setServices(emptylist); devObj.setStaticRoutes(emptylist); mylist2 = ifmap.get(nodeRow.getCell(0).getStringCellValue()); devObj.setNetworks(mylist2); mylist.add(devObj); mylist.add(1); newnode.setArgs(mylist); GsonBuilder builder = new GsonBuilder(); builder.enableComplexMapKeySerialization(); // Gson g = new Gson(); Gson g = builder.create(); String json2 = g.toJson(newnode); // To be used from a real console and not Eclipse String message = JSonRequestor.doRequest(json2, cmURL, cookies); continue; } JOptionPane optionPaneF = new JOptionPane("The nodes have been added!"); JDialog myDialogF = optionPaneF.createDialog(null, "Complete: "); myDialogF.setModal(false); myDialogF.setVisible(true); doLogout(cmURL, cookies); // System.exit(0); }
From source file:de.tbuchloh.kiskis.gui.widgets.PasswordElement.java
/** * @param pwd//from w w w . j a v a 2s .co m * the password to edit */ public PasswordElement(final char[] pwd) { _pwdField = new JPasswordField(new String(pwd)); _pwdField.setFont(createFont()); _pwdField.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(final DocumentEvent e) { notifyListeners(); } @Override public void insertUpdate(final DocumentEvent e) { notifyListeners(); } @Override public void removeUpdate(final DocumentEvent e) { notifyListeners(); } }); _pwdButton = new LinkLabel(M.createAction(this, "onShowPassword")); _pwdButton.setHorizontalAlignment(SwingConstants.RIGHT); _testButton = new LinkLabel(M.createAction(this, "onTestPassword")); _testButton.setHorizontalAlignment(SwingConstants.RIGHT); _mode = HIDDEN; _progressBar = new PasswordQualityBar(); _progressBar.setSmallFont(); init(); initCreatePopup(); }
From source file:com.googlecode.vfsjfilechooser2.accessories.connection.ConnectionDialog.java
private void initCenterPanelComponents() { // create the panel this.centerPanel = new JPanel(new GridBagLayout()); this.centerPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); // create the components this.hostnameLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.hostnameLabelText")); this.hostnameLabel.setForeground(Color.RED); this.hostnameTextField = new JTextField(25); this.portLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.portLabelText")); this.portTextField = new JFormattedTextField(NumberFormat.getInstance()); this.isPortTextFieldDirty = false; this.protocolLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.protocolLabelText")); this.protocolModel = new DefaultComboBoxModel(Protocol.values()); this.protocolList = new JComboBox(protocolModel); this.protocolList.setRenderer(new ProtocolRenderer()); this.usernameLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.usernameLabelText")); this.usernameTextField = new JTextField(20); this.passwordLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.passwordLabelText")); this.passwordTextField = new JPasswordField(12); this.defaultRemotePathLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.pathLabelText")); this.defaultRemotePathTextField = new JTextField(20); // Add the components to the panel makeGridPanel(new Component[] { hostnameLabel, hostnameTextField, portLabel, portTextField, protocolLabel, protocolList, usernameLabel, usernameTextField, passwordLabel, passwordTextField, defaultRemotePathLabel, defaultRemotePathTextField }); }
From source file:ch.admin.hermes.etl.load.HermesETLApplication.java
/** * CommandLine parse und fehlende Argumente verlangen * @param args Args/* w w w . j a va 2s.c o m*/ * @throws ParseException */ private static void parseCommandLine(String[] args) throws Exception { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // HACK um UTF-8 CharSet fuer alle Dateien zu setzen (http://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding) System.setProperty("file.encoding", "UTF-8"); Field charset = Charset.class.getDeclaredField("defaultCharset"); charset.setAccessible(true); charset.set(null, null); // commandline Options - FremdsystemSite, Username und Password Options options = new Options(); options.addOption("s", true, "Zielsystem - URL"); options.addOption("u", true, "Zielsystem - Username"); options.addOption("p", true, "Zielsystem - Password"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); site = cmd.getOptionValue("s"); user = cmd.getOptionValue("u"); passwd = cmd.getOptionValue("p"); // restliche Argumente pruefen - sonst usage ausgeben String[] others = cmd.getArgs(); if (others.length >= 1 && (others[0].endsWith(".js") || others[0].endsWith(".ftl"))) script = others[0]; if (others.length >= 2 && others[1].endsWith(".xml")) model = others[1]; // Dialog mit allen Werten zusammenstellen JComboBox<String> scenarios = new JComboBox<String>(crawler.getScenarios()); JTextField tsite = new JTextField(45); tsite.setText(site); JTextField tuser = new JTextField(16); tuser.setText(user); JPasswordField tpasswd = new JPasswordField(16); tpasswd.setText(passwd); final JTextField tscript = new JTextField(45); tscript.setText(script); final JTextField tmodel = new JTextField(45); tmodel.setText(model); JPanel myPanel = new JPanel(new GridLayout(6, 2)); myPanel.add(new JLabel("Szenario (von http://www.hermes.admin.ch):")); myPanel.add(scenarios); myPanel.add(new JLabel("XML Model:")); myPanel.add(tmodel); JPanel pmodel = new JPanel(); pmodel.add(tmodel); JButton bmodel = new JButton("..."); pmodel.add(bmodel); bmodel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model = getFile("Szenario XML Model", new String[] { "XML Model" }, new String[] { ".xml" }); if (model != null) tmodel.setText(model); } }); myPanel.add(pmodel); scenarios.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { try { Object o = e.getItem(); tmodel.setText(crawler.getModelURL(o.toString())); scenario = o.toString(); } catch (Exception e1) { } } }); // Script myPanel.add(new JLabel("Umwandlungs-Script:")); JPanel pscript = new JPanel(); pscript.add(tscript); JButton bscript = new JButton("..."); pscript.add(bscript); myPanel.add(pscript); bscript.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { script = getFile("JavaScript/Freemarker Umwandlungs-Script", new String[] { "JavaScript", "Freemarker" }, new String[] { ".js", ".ftl" }); if (script != null) tscript.setText(script); } }); // Zielsystem Angaben myPanel.add(new JLabel("Zielsystem URL:")); myPanel.add(tsite); myPanel.add(new JLabel("Zielsystem Benutzer:")); myPanel.add(tuser); myPanel.add(new JLabel("Zielsystem Password:")); myPanel.add(tpasswd); // Trick um Feld scenario und model zu setzen. if (scenarios.getItemCount() >= 8) scenarios.setSelectedIndex(8); // Dialog int result = JOptionPane.showConfirmDialog(null, myPanel, "HERMES 5 XML Model nach Fremdsystem/Format", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { site = tsite.getText(); user = tuser.getText(); passwd = new String(tpasswd.getPassword()); model = tmodel.getText(); script = tscript.getText(); } else System.exit(1); if (model == null || script == null || script.trim().length() == 0) usage(); if (script.endsWith(".js")) if (site == null || user == null || passwd == null || user.trim().length() == 0 || passwd.trim().length() == 0) usage(); }
From source file:com._17od.upm.gui.DatabaseActions.java
public void changeMasterPassword() throws IOException, ProblemReadingDatabaseFile, CryptoException, PasswordDatabaseException, TransportException { if (getLatestVersionOfDatabase()) { //The first task is to get the current master password boolean passwordCorrect = false; boolean okClicked = true; do {/*from www. j a v a2 s. c o m*/ char[] password = askUserForPassword(Translator.translate("enterDatabasePassword")); if (password == null) { okClicked = false; } else { try { dbPers.load(database.getDatabaseFile(), password); passwordCorrect = true; } catch (InvalidPasswordException e) { JOptionPane.showMessageDialog(mainWindow, Translator.translate("incorrectPassword")); } } } while (!passwordCorrect && okClicked); //If the master password was entered correctly then the next step is to get the new master password if (passwordCorrect == true) { final JPasswordField masterPassword = new JPasswordField(""); boolean passwordsMatch = false; Object buttonClicked; //Ask the user for the new master password //This loop will continue until the two passwords entered match or until the user hits the cancel button do { JPasswordField confirmedMasterPassword = new JPasswordField(""); JOptionPane pane = new JOptionPane( new Object[] { Translator.translate("enterNewMasterPassword"), masterPassword, Translator.translate("confirmation"), confirmedMasterPassword }, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dialog = pane.createDialog(mainWindow, Translator.translate("changeMasterPassword")); dialog.addWindowFocusListener(new WindowAdapter() { public void windowGainedFocus(WindowEvent e) { masterPassword.requestFocusInWindow(); } }); dialog.show(); buttonClicked = pane.getValue(); if (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION))) { if (!Arrays.equals(masterPassword.getPassword(), confirmedMasterPassword.getPassword())) { JOptionPane.showMessageDialog(mainWindow, Translator.translate("passwordsDontMatch")); } else { passwordsMatch = true; } } } while (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION)) && !passwordsMatch); //If the user clicked OK and the passwords match then change the database password if (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION)) && passwordsMatch) { this.dbPers.getEncryptionService().initCipher(masterPassword.getPassword()); saveDatabase(); } } } }
From source file:com.piusvelte.taplock.server.TapLockServer.java
private static void initialize() { (new File(APP_PATH)).mkdir(); if (OS == OS_WIN) Security.addProvider(new BouncyCastleProvider()); System.out.println("APP_PATH: " + APP_PATH); try {/*w ww. ja va 2s.co m*/ sLogFileHandler = new FileHandler(sLog); } catch (SecurityException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } catch (IOException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } File propertiesFile = new File(sProperties); if (!propertiesFile.exists()) { try { propertiesFile.createNewFile(); } catch (IOException e) { writeLog("propertiesFile.createNewFile: " + e.getMessage()); } } Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); if (prop.isEmpty()) { prop.setProperty(sPassphraseKey, sPassphrase); prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); prop.store(new FileOutputStream(sProperties), null); } else { if (prop.containsKey(sPassphraseKey)) sPassphrase = prop.getProperty(sPassphraseKey); else prop.setProperty(sPassphraseKey, sPassphrase); if (prop.containsKey(sDisplaySystemTrayKey)) sDisplaySystemTray = Boolean.parseBoolean(prop.getProperty(sDisplaySystemTrayKey)); else prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); if (prop.containsKey(sDebuggingKey)) sDebugging = Boolean.parseBoolean(prop.getProperty(sDebuggingKey)); else prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); } } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } if (sLogFileHandler != null) { sLogger = Logger.getLogger("TapLock"); sLogger.setUseParentHandlers(false); sLogger.addHandler(sLogFileHandler); SimpleFormatter sf = new SimpleFormatter(); sLogFileHandler.setFormatter(sf); writeLog("service starting"); } if (sDisplaySystemTray && SystemTray.isSupported()) { final SystemTray systemTray = SystemTray.getSystemTray(); Image trayIconImg = Toolkit.getDefaultToolkit() .getImage(TapLockServer.class.getResource("/systemtrayicon.png")); final TrayIcon trayIcon = new TrayIcon(trayIconImg, "Tap Lock"); trayIcon.setImageAutoSize(true); PopupMenu popupMenu = new PopupMenu(); MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem toggleSystemTrayIcon = new CheckboxMenuItem("Display Icon in System Tray"); toggleSystemTrayIcon.setState(sDisplaySystemTray); CheckboxMenuItem toggleDebugging = new CheckboxMenuItem("Debugging"); toggleDebugging.setState(sDebugging); MenuItem shutdownItem = new MenuItem("Shutdown Tap Lock Server"); popupMenu.add(aboutItem); popupMenu.add(toggleSystemTrayIcon); if (OS == OS_WIN) { MenuItem setPasswordItem = new MenuItem("Set password"); popupMenu.add(setPasswordItem); setPasswordItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel panel = new JPanel(); JLabel label = new JLabel("Enter your Windows account password:"); JPasswordField passField = new JPasswordField(32); panel.add(label); panel.add(passField); String[] options = new String[] { "OK", "Cancel" }; int option = JOptionPane.showOptionDialog(null, panel, "Tap Lock", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (option == 0) { String password = encryptString(new String(passField.getPassword())); if (password != null) { Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sPasswordKey, password); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e1) { writeLog("prop load: " + e1.getMessage()); } catch (IOException e1) { writeLog("prop load: " + e1.getMessage()); } } } } }); } popupMenu.add(toggleDebugging); popupMenu.add(shutdownItem); trayIcon.setPopupMenu(popupMenu); try { systemTray.add(trayIcon); } catch (AWTException e) { writeLog("systemTray.add: " + e.getMessage()); } aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String newline = System.getProperty("line.separator"); newline += newline; JOptionPane.showMessageDialog(null, "Tap Lock" + newline + "Copyright (c) 2012 Bryan Emmanuel" + newline + "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version." + newline + "This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details." + newline + "You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>." + newline + "Bryan Emmanuel piusvelte@gmail.com"); } }); toggleSystemTrayIcon.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setTrayIconDisplay(e.getStateChange() == ItemEvent.SELECTED); if (!sDisplaySystemTray) systemTray.remove(trayIcon); } }); toggleDebugging.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setDebugging(e.getStateChange() == ItemEvent.SELECTED); } }); shutdownItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { shutdown(); } }); } synchronized (sConnectionThreadLock) { (sConnectionThread = new ConnectionThread()).start(); } }
From source file:JavaMail.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try {/* w w w .ja v a 2s .c o m*/ String from = jTextField1.getText(); String to = jTextField2.getText(); String subject = jTextField3.getText(); String content = jTextArea1.getText(); Email email = new SimpleEmail(); String provi = prov.getSelectedItem().toString(); if (provi.equals("Gmail")) { email.setHostName("smtp.gmail.com"); email.setSmtpPort(465); serverlink = "smtp.gmail.com"; serverport = 465; } if (provi.equals("Outlook")) { email.setHostName("smtp-mail.outlook.com"); serverlink = "smtp-mail.outlook.com"; email.setSmtpPort(25); serverport = 25; } if (provi.equals("Yahoo")) { email.setHostName("smtp.mail.yahoo.com"); serverlink = "smtp.mail.yahoo.com"; email.setSmtpPort(465); serverport = 465; } System.out.println("Initializing email sending sequence"); System.out.println("Connecting to " + serverlink + " at port " + serverport); JPanel panel = new JPanel(); JLabel label = new JLabel( "Enter the password of your email ID to connect with your Email provider." + "\n"); JPasswordField pass = new JPasswordField(10); panel.add(label); panel.add(pass); String[] options = new String[] { "OK", "Cancel" }; int option = JOptionPane.showOptionDialog(null, panel, "Enter Email ID Password", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if (option == 0) // pressing OK button { char[] password = pass.getPassword(); emailpass = new String(password); } email.setAuthenticator(new DefaultAuthenticator(from, emailpass)); email.setSSLOnConnect(true); if (email.isSSLOnConnect() == true) { System.out.println("This server requires SSL/TLS authentication."); } email.setFrom(from); email.setSubject(subject); email.setMsg(content); email.addTo(to); email.send(); JOptionPane.showMessageDialog(null, "Message sent successfully."); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.harvard.mcz.imagecapture.LoginDialog.java
/** * This method initializes jPasswordFieldDB * // ww w .ja v a 2 s. c o m * @return javax.swing.JPasswordField */ private JPasswordField getJPasswordFieldDB() { if (jPasswordFieldDB == null) { jPasswordFieldDB = new JPasswordField(30); } return jPasswordFieldDB; }
From source file:kevin.gvmsgarch.App.java
private static String getPassword() { String retval = null;//w w w . ja v a 2 s . co m JPasswordField pwd = new JPasswordField(20); int optionSelected = JOptionPane.showConfirmDialog(null, pwd, "Enter Password", JOptionPane.OK_CANCEL_OPTION); if (optionSelected == JOptionPane.OK_OPTION) { retval = new String(pwd.getPassword()); } return retval; }
From source file:greenfoot.gui.export.ExportPublishPane.java
/** * Creates a login panel with a username and password and a create account option * @return Login panel Component/*from w w w .j a v a2s. com*/ */ private JComponent getLoginPanel() { JComponent loginPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 8, 4)); loginPanel.setBackground(background); loginPanel.setAlignmentX(LEFT_ALIGNMENT); Border border = BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(12, 12, 12, 12)); loginPanel.setBorder(border); JLabel text = new JLabel(Config.getString("export.publish.login")); text.setForeground(headingColor); text.setVerticalAlignment(SwingConstants.TOP); loginPanel.add(text); text = new JLabel(Config.getString("export.publish.username"), SwingConstants.TRAILING); text.setFont(font); loginPanel.add(text); userNameField = new JTextField(10); userNameField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { String text = userNameField.getText(); return text.length() > 0; } }); userNameField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { checkForExistingScenario(); } }); loginPanel.add(userNameField); text = new JLabel(Config.getString("export.publish.password"), SwingConstants.TRAILING); text.setFont(font); loginPanel.add(text); passwordField = new JPasswordField(10); loginPanel.add(passwordField); JLabel createAccountLabel = new JLabel(Config.getString("export.publish.createAccount")); { createAccountLabel.setBackground(background); createAccountLabel.setHorizontalAlignment(SwingConstants.RIGHT); GreenfootUtil.makeLink(createAccountLabel, createAccountUrl); } loginPanel.add(createAccountLabel); return loginPanel; }