List of usage examples for javax.swing JTextField getText
public String getText()
TextComponent
. From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_multicastDemand.java
private static void createMulticastDemandGUI(final NetworkElementType networkElementType, final IVisualizationCallback callback) { final NetPlan netPlan = callback.getDesign(); JTextField textFieldIngressNodeId = new JTextField(20); JTextField textFieldEgressNodeIds = new JTextField(20); JPanel pane = new JPanel(); pane.add(new JLabel("Ingress node id: ")); pane.add(textFieldIngressNodeId);/*from w w w . ja v a 2 s. co m*/ pane.add(Box.createHorizontalStrut(15)); pane.add(new JLabel("Egress node ids (space separated): ")); pane.add(textFieldEgressNodeIds); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please enter multicast demand ingress node and set of egress nodes", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { if (textFieldIngressNodeId.getText().isEmpty()) throw new Exception("Please, insert the ingress node id"); if (textFieldEgressNodeIds.getText().isEmpty()) throw new Exception("Please, insert the set of egress node ids"); String ingressNodeId_st = textFieldIngressNodeId.getText(); String egressNodeId_st = textFieldEgressNodeIds.getText(); final long ingressNode = Long.parseLong(ingressNodeId_st); if (netPlan.getNodeFromId(ingressNode) == null) throw new Exception("Not a valid ingress node id: " + ingressNodeId_st); Set<Node> egressNodes = new HashSet<Node>(); for (String egressNodeIdString : StringUtils.split(egressNodeId_st)) { final long nodeId = Long.parseLong(egressNodeIdString); final Node node = netPlan.getNodeFromId(nodeId); if (node == null) throw new Exception("Not a valid egress node id: " + egressNodeIdString); egressNodes.add(node); } netPlan.addMulticastDemand(netPlan.getNodeFromId(ingressNode), egressNodes, 0, null); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Collections.singleton(NetworkElementType.MULTICAST_DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.addErrorOrException(ex, AdvancedJTable_multicastDemand.class); ErrorHandling.showErrorDialog("Error adding the multicast demand"); } } }
From source file:co.edu.unal.pos.gui.PosHadoopJFrame.java
private Integer getIntegerValue(JTextField jTextField) { String stringValue = StringUtils.trimToNull(jTextField.getText()); Integer integerValue = null;/*w ww . j ava 2 s . c o m*/ if (stringValue != null) { integerValue = Integer.valueOf(stringValue); } return integerValue; }
From source file:edu.ku.brc.specify.datamodel.busrules.LoanBusRules.java
@Override public void afterFillForm(final Object dataObj) { if (formViewObj != null && formViewObj.getDataObj() instanceof Loan) { formViewObj.setSkippingAttach(true); MultiView mvParent = formViewObj.getMVParent(); Loan loan = (Loan) formViewObj.getDataObj(); boolean isNewObj = loan.getId() == null;//MultiView.isOptionOn(mvParent.getOptions(), MultiView.IS_NEW_OBJECT); boolean isEdit = mvParent.isEditable(); Component comp = formViewObj.getControlByName("generateInvoice"); if (comp instanceof JCheckBox) { ((JCheckBox) comp).setVisible(isEdit); }/*w ww. ja v a2s . c o m*/ boolean allResolved = true; for (LoanPreparation loanPrep : loan.getLoanPreparations()) { Boolean isResolved = loanPrep.getIsResolved(); if (isResolved == null || (isResolved != null && !isResolved)) { allResolved = false; break; } } comp = formViewObj.getControlByName("ReturnLoan"); if (comp instanceof JButton) { comp.setVisible(isEdit); Boolean isClosed = loan.getIsClosed(); comp.setEnabled(!isNewObj && (isClosed != null ? !loan.getIsClosed() : false) && !allResolved); if (allResolved) { ((JButton) comp).setText(UIRegistry.getResourceString("LOAN_ALL_PREPS_RETURNED")); } } if (isNewObj) { Component shipComp = formViewObj.getControlByName("shipmentNumber"); comp = formViewObj.getControlByName("loanNumber"); if (comp instanceof JTextField && shipComp instanceof JTextField) { JTextField loanTxt = (JTextField) comp; if (shipComp instanceof GetSetValueIFace) { GetSetValueIFace gsv = (GetSetValueIFace) shipComp; gsv.setValue(loanTxt.getText(), loanTxt.getText()); } else if (shipComp instanceof JTextField) { ((JTextField) shipComp).setText(loanTxt.getText()); } if (shipComp instanceof UIValidatable) { UIValidatable uiv = (UIValidatable) shipComp; uiv.setChanged(true); } } } } }
From source file:edu.ku.brc.specify.datamodel.busrules.SpecifyUserBusRules.java
/** * NOTE: This is being called when editing an existing person. * @param id/* w w w . j a v a2 s .co m*/ * @param keyName * @param isPwd * @return */ private boolean isFieldOK(final String id, final String keyName, final boolean isPwd) { JTextField tf = null; Component comp = formViewObj.getCompById(id); if (comp instanceof EditViewCompSwitcherPanel) { tf = (JTextField) ((EditViewCompSwitcherPanel) comp).getCurrentComp(); } else { tf = (JTextField) comp; } String value = tf.getText().trim(); if (StringUtils.contains(value, ' ') || (!isPwd && StringUtils.contains(value, ','))) { UIRegistry.showLocalizedError(keyName); return false; } return true; }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.AddParallelLineDialog.java
/** * Verify that the y-value is correct./*from w w w . j a v a 2s . com*/ * * @param input * @return true if the value is valid; false otherwise */ private boolean verifyYInput(JComponent input) { JTextField textField = (JTextField) input; String inputString = textField.getText(); try { Double.parseDouble(inputString); } catch (NumberFormatException e) { textField.setForeground(Color.RED); return false; } textField.setForeground(Color.BLACK); return true; }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.AddParallelLineDialog.java
/** * Verify that the x-value is correct./*from w w w. ja v a 2s. c o m*/ * * @param input * @return true if the value is valid; false otherwise */ private boolean verifyXInput(JComponent input) { JTextField textField = (JTextField) input; String inputString = textField.getText(); try { Double.parseDouble(inputString); } catch (NumberFormatException e) { textField.setForeground(Color.RED); return false; } textField.setForeground(Color.BLACK); return true; }
From source file:edu.cmu.cs.diamond.pathfind.DjangoAnnotationStore.java
private void login(String loginuri) throws IOException { String username = prefs.get("username", ""); String password = ""; JLabel label = new JLabel("Please enter your username and password:"); JTextField jtf = new JTextField(username); JPasswordField jpf = new JPasswordField(); int dialogResult = JOptionPane.showConfirmDialog(null, new Object[] { label, jtf, jpf }, "Login to PathFind", JOptionPane.OK_CANCEL_OPTION); if (dialogResult == JOptionPane.OK_OPTION) { username = jtf.getText(); prefs.put("username", username); password = new String(jpf.getPassword()); } else {/*from ww w . jav a2s . c o m*/ throw new IOException("User refused to login"); } // get the form to get the cookies GetMethod form = new GetMethod(loginuri); try { if (httpClient.executeMethod(form) != 200) { throw new IOException("Can't GET " + loginuri); } } finally { form.releaseConnection(); } // get cookies Cookie[] cookies = httpClient.getState().getCookies(); for (Cookie c : cookies) { System.out.println(c); if (c.getName().equals("csrftoken")) { csrftoken = c.getValue(); break; } } // now, post PostMethod post = new PostMethod(loginuri); try { post.addRequestHeader("Referer", loginuri); NameValuePair params[] = { new NameValuePair("username", username), new NameValuePair("password", password), new NameValuePair("csrfmiddlewaretoken", csrftoken) }; //System.out.println(Arrays.toString(params)); post.setRequestBody(params); httpClient.executeMethod(post); System.out.println(post.getResponseBodyAsString()); } finally { post.releaseConnection(); } }
From source file:net.lldp.checksims.ui.results.ScrollViewer.java
/** * Create a scroll viewer from a sortable Matrix Viewer * @param results the sortableMatrix to view * @param toRevalidate frame to revalidate sometimes *//*from w w w . j a va 2 s . co m*/ public ScrollViewer(SimilarityMatrix exportMatrix, SortableMatrixViewer results, JFrame toRevalidate) { resultsView = new JScrollPane(results); setBackground(Color.black); resultsView.addComponentListener(new ComponentListener() { @Override public void componentHidden(ComponentEvent arg0) { } @Override public void componentMoved(ComponentEvent arg0) { } @Override public void componentResized(ComponentEvent ce) { Dimension size = ce.getComponent().getSize(); results.padToSize(size); } @Override public void componentShown(ComponentEvent arg0) { } }); resultsView.getViewport().addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Rectangle r = resultsView.getViewport().getViewRect(); results.setViewAt(r); } }); resultsView.setBackground(Color.black); sidebar = new JPanel(); setPreferredSize(new Dimension(900, 631)); setMinimumSize(new Dimension(900, 631)); sidebar.setPreferredSize(new Dimension(200, 631)); sidebar.setMaximumSize(new Dimension(200, 3000)); resultsView.setMinimumSize(new Dimension(700, 631)); resultsView.setPreferredSize(new Dimension(700, 631)); sidebar.setBackground(Color.GRAY); setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); this.add(sidebar); this.add(resultsView); resultsView.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); resultsView.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); resultsView.getVerticalScrollBar().setUnitIncrement(16); resultsView.getHorizontalScrollBar().setUnitIncrement(16); Integer[] presetThresholds = { 80, 60, 40, 20, 0 }; JComboBox<Integer> threshHold = new JComboBox<Integer>(presetThresholds); threshHold.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) { Integer item = (Integer) event.getItem(); results.updateThreshold(item / 100.0); toRevalidate.revalidate(); toRevalidate.repaint(); } } }); threshHold.setSelectedIndex(0); results.updateThreshold((Integer) threshHold.getSelectedItem() / 100.0); JTextField student1 = new JTextField(15); JTextField student2 = new JTextField(15); KeyListener search = new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { results.highlightMatching(student1.getText(), student2.getText()); toRevalidate.revalidate(); toRevalidate.repaint(); } @Override public void keyTyped(KeyEvent e) { } }; student1.addKeyListener(search); student2.addKeyListener(search); Collection<MatrixPrinter> printerNameSet = MatrixPrinterRegistry.getInstance() .getSupportedImplementations(); JComboBox<MatrixPrinter> exportAs = new JComboBox<>(new Vector<>(printerNameSet)); JButton exportAsSave = new JButton("Save"); JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle("Save results"); exportAsSave.addActionListener(ae -> { MatrixPrinter method = (MatrixPrinter) exportAs.getSelectedItem(); int err = fc.showDialog(toRevalidate, "Save"); if (err == JFileChooser.APPROVE_OPTION) { try { FileUtils.writeStringToFile(fc.getSelectedFile(), method.printMatrix(exportMatrix)); } catch (InternalAlgorithmError | IOException e1) { // TODO log / show error } } }); JPanel thresholdLabel = new JPanel(); JPanel studentSearchLabel = new JPanel(); JPanel fileOutputLabel = new JPanel(); thresholdLabel.setBorder(BorderFactory.createTitledBorder("Matching Threshold")); studentSearchLabel.setBorder(BorderFactory.createTitledBorder("Student Search")); fileOutputLabel.setBorder(BorderFactory.createTitledBorder("Save Results")); thresholdLabel.add(threshHold); studentSearchLabel.add(student1); studentSearchLabel.add(student2); fileOutputLabel.add(exportAs); fileOutputLabel.add(exportAsSave); studentSearchLabel.setPreferredSize(new Dimension(200, 100)); studentSearchLabel.setMinimumSize(new Dimension(200, 100)); thresholdLabel.setPreferredSize(new Dimension(200, 100)); thresholdLabel.setMinimumSize(new Dimension(200, 100)); fileOutputLabel.setPreferredSize(new Dimension(200, 100)); fileOutputLabel.setMinimumSize(new Dimension(200, 100)); sidebar.setMaximumSize(new Dimension(200, 4000)); sidebar.add(thresholdLabel); sidebar.add(studentSearchLabel); sidebar.add(fileOutputLabel); }
From source file:dbseer.gui.actions.ExplainChartAction.java
private void updateExplanations() { JTextField confidenceThresholdTextField = panel.getControlPanel().getConfidenceThresholdTextField(); if (!UserInputValidator.validateNumber(confidenceThresholdTextField.getText().trim(), "Confidence Threshold", true)) { return;//from ww w.j a v a2s .co m } confidenceThreshold = Double.parseDouble(confidenceThresholdTextField.getText().trim()); if (confidenceThreshold < 0 || confidenceThreshold > 100) { JOptionPane.showMessageDialog(null, "Confidence threshold must be between 1 and 100.", "Warning", JOptionPane.WARNING_MESSAGE); return; } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { DefaultListModel explanationListModel = panel.getControlPanel().getExplanationListModel(); explanationListModel.clear(); int rank = 1; for (DBSeerCausalModel explanation : explanations) { if (explanation.getConfidence() > confidenceThreshold) { String output = String.format("%d. %s\n", rank++, explanation.toString()); explanationListModel.addElement(output); } } } }); }
From source file:com.willwinder.ugs.nbp.setupwizard.panels.WizardPanelStepCalibration.java
private KeyListener createKeyListenerChangeSetting(Axis axis, JButton buttonUpdateSettings) { return new KeyListener() { @Override//from w w w .j av a 2 s . co m public void keyTyped(KeyEvent event) { } @Override public void keyPressed(KeyEvent event) { } @Override public void keyReleased(KeyEvent event) { if (getBackend().getController() != null && getBackend().getController().getFirmwareSettings() != null) { try { JTextField source = (JTextField) event.getSource(); IFirmwareSettings firmwareSettings = getBackend().getController().getFirmwareSettings(); int stepsPerMillimeter = firmwareSettings.getStepsPerMillimeter(axis); if (!StringUtils.isNumeric(source.getText()) || source.getText().trim().equalsIgnoreCase(String.valueOf(stepsPerMillimeter))) { buttonUpdateSettings.setEnabled(false); } else if (StringUtils.isNumeric(source.getText())) { buttonUpdateSettings.setEnabled(true); } } catch (FirmwareSettingsException e) { e.printStackTrace(); } } } }; }