List of usage examples for javax.swing JTextField getText
public String getText()
TextComponent
. From source file:PostTest.java
public PostTestFrame() { setTitle("PostTest"); northPanel = new JPanel(); add(northPanel, BorderLayout.NORTH); northPanel.setLayout(new GridLayout(0, 2)); northPanel.add(new JLabel("Host: ", SwingConstants.TRAILING)); final JTextField hostField = new JTextField(); northPanel.add(hostField);//from www. j a va2s . c o m northPanel.add(new JLabel("Action: ", SwingConstants.TRAILING)); final JTextField actionField = new JTextField(); northPanel.add(actionField); for (int i = 1; i <= 8; i++) northPanel.add(new JTextField()); final JTextArea result = new JTextArea(20, 40); add(new JScrollPane(result)); JPanel southPanel = new JPanel(); add(southPanel, BorderLayout.SOUTH); JButton addButton = new JButton("More"); southPanel.add(addButton); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { northPanel.add(new JTextField()); northPanel.add(new JTextField()); pack(); } }); JButton getButton = new JButton("Get"); southPanel.add(getButton); getButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { result.setText(""); final Map<String, String> post = new HashMap<String, String>(); for (int i = 4; i < northPanel.getComponentCount(); i += 2) { String name = ((JTextField) northPanel.getComponent(i)).getText(); if (name.length() > 0) { String value = ((JTextField) northPanel.getComponent(i + 1)).getText(); post.put(name, value); } } new SwingWorker<Void, Void>() { protected Void doInBackground() throws Exception { try { String urlString = hostField.getText() + "/" + actionField.getText(); result.setText(doPost(urlString, post)); } catch (IOException e) { result.setText("" + e); } return null; } }.execute(); } }); pack(); }
From source file:edu.ku.brc.specify.config.FeedBackDlg.java
@Override protected FeedBackSenderItem getFeedBackSenderItem(final Class<?> cls, final Exception exception) { CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g", "p,4px,p,4px,p,4px,p,4px,f:p:g")); Vector<String> taskItems = new Vector<String>(); for (Taskable task : TaskMgr.getInstance().getAllTasks()) { taskItems.add(task.getTitle());// w ww. j a v a2 s . co m } String[] OTHERS = { "WEBSITE", "CSTSUP", "INSTL", "DOC", "WHTPR", "HLP" }; for (String key : OTHERS) { taskItems.add(UIRegistry.getResourceString("FeedBackDlg." + key)); } Collections.sort(taskItems); final JComboBox taskCBX = createComboBox(taskItems); final JTextField subjectTF = createTextField(); final JTextField issueTF = createTextField(); final JTextArea commentsTA = createTextArea(15, 60); int y = 1; pb.add(createI18NLabel("FeedBackDlg.INFO"), cc.xyw(1, y, 4)); y += 2; pb.add(createI18NFormLabel("FeedBackDlg.SUB"), cc.xy(1, y)); pb.add(subjectTF, cc.xyw(3, y, 2)); y += 2; pb.add(createI18NFormLabel("FeedBackDlg.COMP"), cc.xy(1, y)); pb.add(taskCBX, cc.xy(3, y)); y += 2; //pb.add(createFormLabel("Question/Issue"), cc.xy(1, y)); //pb.add(issueTF, cc.xyw(3, y, 2)); y += 2; pb.add(createI18NFormLabel("FeedBackDlg.COMM"), cc.xy(1, y)); y += 2; pb.add(createScrollPane(commentsTA, true), cc.xyw(1, y, 4)); y += 2; Taskable currTask = SubPaneMgr.getInstance().getCurrentSubPane().getTask(); taskCBX.setSelectedItem(currTask != null ? currTask : TaskMgr.getDefaultTaskable()); pb.setDefaultDialogBorder(); CustomDialog dlg = new CustomDialog((Frame) null, UIRegistry.getResourceString("FeedBackDlg.TITLE"), true, pb.getPanel()); centerAndShow(dlg); if (!dlg.isCancelled()) { String taskTitle = (String) taskCBX.getSelectedItem(); if (taskTitle != null) { for (Taskable task : TaskMgr.getInstance().getAllTasks()) { if (task.getTitle().equals(taskTitle)) { taskTitle = task.getName(); } } } else { taskTitle = "No Task Name"; } FeedBackSenderItem item = new FeedBackSenderItem(taskTitle, subjectTF.getText(), issueTF.getText(), commentsTA.getText(), "", cls != null ? cls.getName() : ""); return item; } return null; }
From source file:edu.umich.robot.GuiApplication.java
public void connectSuperdroidRobotDialog() { final int defaultPort = 3192; FormLayout layout = new FormLayout("right:pref, 4dlu, 35dlu, 4dlu, 35dlu", "pref, 2dlu, pref, 2dlu, pref, 2dlu, pref"); final JDialog dialog = new JDialog(frame, "Connect to Superdroid", true); dialog.setLayout(layout);/* w w w.j av a 2 s. c om*/ final JTextField namefield = new JTextField("charlie"); final JTextField hostfield = new JTextField("192.168.1.165"); final JTextField portfield = new JTextField(Integer.toString(defaultPort)); final JButton cancel = new JButton("Cancel"); final JButton ok = new JButton("OK"); CellConstraints cc = new CellConstraints(); dialog.add(new JLabel("Name"), cc.xy(1, 1)); dialog.add(namefield, cc.xyw(3, 1, 3)); dialog.add(new JLabel("Host"), cc.xy(1, 3)); dialog.add(hostfield, cc.xyw(3, 3, 3)); dialog.add(new JLabel("Port"), cc.xy(1, 5)); dialog.add(portfield, cc.xyw(3, 5, 3)); dialog.add(cancel, cc.xy(3, 7)); dialog.add(ok, cc.xy(5, 7)); portfield.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { int p = defaultPort; try { p = Integer.parseInt(portfield.getText()); if (p < 1) p = 1; if (p > 65535) p = 65535; } catch (NumberFormatException ex) { } portfield.setText(Integer.toString(p)); } }); final ActionListener okListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String robotName = namefield.getText().trim(); if (robotName.isEmpty()) { logger.error("Connect Superdroid: robot name empty"); return; } for (char c : robotName.toCharArray()) { if (!Character.isDigit(c) && !Character.isLetter(c)) { logger.error("Create Superdroid: illegal robot name"); return; } } try { controller.createRealSuperdroid(robotName, hostfield.getText(), Integer.valueOf(portfield.getText())); } catch (UnknownHostException ex) { ex.printStackTrace(); logger.error("Connect Superdroid: " + ex); } catch (SocketException ex) { ex.printStackTrace(); logger.error("Connect Superdroid: " + ex); } dialog.dispose(); } }; namefield.addActionListener(okListener); hostfield.addActionListener(okListener); portfield.addActionListener(okListener); ok.addActionListener(okListener); ActionListener cancelAction = new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; cancel.addActionListener(cancelAction); dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); dialog.setLocationRelativeTo(frame); dialog.pack(); dialog.setVisible(true); }
From source file:edu.umich.robot.GuiApplication.java
public void createSuperdroidRobotDialog() { final Pose pose = new Pose(); FormLayout layout = new FormLayout("right:pref, 4dlu, 30dlu, 4dlu, right:pref, 4dlu, 30dlu", "pref, 2dlu, pref, 2dlu, pref"); layout.setRowGroups(new int[][] { { 1, 3 } }); final JDialog dialog = new JDialog(frame, "Create Superdroid Robot", true); dialog.setLayout(layout);/*from www . j a v a2 s .c om*/ final JTextField name = new JTextField(); final JTextField x = new JTextField(Double.toString((pose.getX()))); final JTextField y = new JTextField(Double.toString((pose.getY()))); final JButton cancel = new JButton("Cancel"); final JButton ok = new JButton("OK"); CellConstraints cc = new CellConstraints(); dialog.add(new JLabel("Name"), cc.xy(1, 1)); dialog.add(name, cc.xyw(3, 1, 5)); dialog.add(new JLabel("x"), cc.xy(1, 3)); dialog.add(x, cc.xy(3, 3)); dialog.add(new JLabel("y"), cc.xy(5, 3)); dialog.add(y, cc.xy(7, 3)); dialog.add(cancel, cc.xyw(1, 5, 3)); dialog.add(ok, cc.xyw(5, 5, 3)); x.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setX(Double.parseDouble(x.getText())); } catch (NumberFormatException ex) { x.setText(Double.toString(pose.getX())); } } }); y.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setY(Double.parseDouble(y.getText())); } catch (NumberFormatException ex) { y.setText(Double.toString(pose.getX())); } } }); final ActionListener okListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String robotName = name.getText().trim(); if (robotName.isEmpty()) { logger.error("Create Superdroid: robot name empty"); return; } for (char c : robotName.toCharArray()) if (!Character.isDigit(c) && !Character.isLetter(c)) { logger.error("Create Superdroid: illegal robot name"); return; } controller.createSuperdroidRobot(robotName, pose, true); controller.createSimSuperdroid(robotName); dialog.dispose(); } }; name.addActionListener(okListener); x.addActionListener(okListener); y.addActionListener(okListener); ok.addActionListener(okListener); ActionListener cancelAction = new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; cancel.addActionListener(cancelAction); dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); dialog.setLocationRelativeTo(frame); dialog.pack(); dialog.setVisible(true); }
From source file:edu.umich.robot.GuiApplication.java
/** * <p>//from w w w. ja v a 2s .c o m * Pops up a window to create a new splinter robot to add to the simulation. */ public void createSplinterRobotDialog() { final Pose pose = new Pose(); FormLayout layout = new FormLayout("right:pref, 4dlu, 30dlu, 4dlu, right:pref, 4dlu, 30dlu", "pref, 2dlu, pref, 2dlu, pref"); layout.setRowGroups(new int[][] { { 1, 3 } }); final JDialog dialog = new JDialog(frame, "Create Splinter Robot", true); dialog.setLayout(layout); final JTextField name = new JTextField(); final JTextField x = new JTextField(Double.toString((pose.getX()))); final JTextField y = new JTextField(Double.toString((pose.getY()))); final JButton cancel = new JButton("Cancel"); final JButton ok = new JButton("OK"); CellConstraints cc = new CellConstraints(); dialog.add(new JLabel("Name"), cc.xy(1, 1)); dialog.add(name, cc.xyw(3, 1, 5)); dialog.add(new JLabel("x"), cc.xy(1, 3)); dialog.add(x, cc.xy(3, 3)); dialog.add(new JLabel("y"), cc.xy(5, 3)); dialog.add(y, cc.xy(7, 3)); dialog.add(cancel, cc.xyw(1, 5, 3)); dialog.add(ok, cc.xyw(5, 5, 3)); x.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setX(Double.parseDouble(x.getText())); } catch (NumberFormatException ex) { x.setText(Double.toString(pose.getX())); } } }); y.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setY(Double.parseDouble(y.getText())); } catch (NumberFormatException ex) { y.setText(Double.toString(pose.getX())); } } }); final ActionListener okListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String robotName = name.getText().trim(); if (robotName.isEmpty()) { logger.error("Create splinter: robot name empty"); return; } for (char c : robotName.toCharArray()) if (!Character.isDigit(c) && !Character.isLetter(c)) { logger.error("Create splinter: illegal robot name"); return; } controller.createSplinterRobot(robotName, pose, true); controller.createSimSplinter(robotName); controller.createSimLaser(robotName); dialog.dispose(); } }; name.addActionListener(okListener); x.addActionListener(okListener); y.addActionListener(okListener); ok.addActionListener(okListener); ActionListener cancelAction = new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; cancel.addActionListener(cancelAction); dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); dialog.setLocationRelativeTo(frame); dialog.pack(); dialog.setVisible(true); }
From source file:edu.ku.brc.specify.tasks.subpane.images.ImagesPane.java
/** * @return/*from ww w .j a v a 2 s. c o m*/ */ private void createColObjSearch() { if (searchType != SearchType.FromRecordSet) { searchForAllAttachments(); gridPanel.setItemList(rowsVector); JScrollPane sb = new JScrollPane(gridPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); add(sb, BorderLayout.CENTER); return; } CellConstraints cc = new CellConstraints(); String rowDef = searchType != SearchType.FromRecordSet ? "f:p:g" : "p,4px,f:p:g"; PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,2px,p", rowDef)); int y = 1; coVBP = new ViewBasedDisplayPanel(null, "COImageSearch", CollectionObject.class.getName(), true, MultiView.NO_SCROLLBARS | MultiView.IS_SINGLE_OBJ | MultiView.IS_EDITTING); pb.add(coVBP, cc.xyw(1, y, 3)); y += 2; pb.add(gridPanel, cc.xyw(1, y, 3)); coVBP.setData(dataMap); FormViewObj fvo = coVBP.getMultiView().getCurrentViewAsFormViewObj(); JButton searchBtn = fvo.getCompById("2"); JTextField textField = fvo.getCompById("1"); y += 2; //fvo.setAlwaysGetDataFromUI(true); if (searchBtn != null) { final JButton searchBtnFinal = searchBtn; final JTextField textFieldFinal = textField; searchBtn.setEnabled(false); searchBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //searchForColObjImagesForTable(); gridPanel.setItemList(rowsVector); //invalidate(); //revalidate(); } }); textField.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { searchBtnFinal.setEnabled(textFieldFinal.getText().length() > 0); } }); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && textFieldFinal.getText().length() > 0) { //searchForColObjImagesForTable(); } } }); } JScrollPane sb = new JScrollPane(pb.getPanel(), JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); add(sb, BorderLayout.CENTER); }
From source file:ffx.ui.ModelingPanel.java
/** * Create a string representing the modeling command to execute. * * @return the modeling command string.//from w w w. j av a 2 s . co m */ private String createCommandInput() { StringBuilder commandLineParams = new StringBuilder(activeCommand + " "); // Now append command line input to a TextArea, one option per line. // This TextArea gets dumped to an input file. commandTextArea.setText(""); int numparams = optionsTabbedPane.getTabCount(); for (int i = 0; i < numparams; i++) { // A few cases require that a newLine not be generated between // options. boolean newLine = true; // The optionString will collect the parameters for this Option, // then append them to the CommandTextArea. StringBuilder optionString = new StringBuilder(); JPanel optionPanel = (JPanel) optionsTabbedPane.getComponentAt(i); int numOptions = optionPanel.getComponentCount(); String title = optionsTabbedPane.getTitleAt(i); if (title.equalsIgnoreCase("Sequence")) { for (int k = 0; k < acidComboBox.getItemCount(); k++) { if (k != 0) { optionString.append("\n"); } String s = (String) acidComboBox.getItemAt(k); s = s.substring(s.indexOf(" "), s.length()).trim(); optionString.append(s); } // Need an extra newline for Nucleic if (activeCommand.equalsIgnoreCase("NUCLEIC")) { optionString.append("\n"); } } else { JPanel valuePanel = (JPanel) optionPanel.getComponent(numOptions - 1); int numValues = valuePanel.getComponentCount(); for (int j = 0; j < numValues; j++) { Component value = valuePanel.getComponent(j); if (value instanceof JCheckBox) { JCheckBox jcbox = (JCheckBox) value; if (jcbox.isSelected()) { optionString.append("-"); optionString.append(jcbox.getName()); optionString.append(" "); optionString.append(jcbox.getText()); } } else if (value instanceof JTextField) { JTextField jtfield = (JTextField) value; optionString.append("-"); optionString.append(jtfield.getName()); optionString.append(" "); optionString.append(jtfield.getText()); } else if (value instanceof JComboBox) { JComboBox jcb = (JComboBox) value; Object object = jcb.getSelectedItem(); if (object instanceof FFXSystem) { FFXSystem system = (FFXSystem) object; File file = system.getFile(); if (file != null) { String absolutePath = file.getAbsolutePath(); if (absolutePath.endsWith("xyz")) { absolutePath = absolutePath + "_1"; } optionString.append(absolutePath); } } } else if (value instanceof JRadioButton) { JRadioButton jrbutton = (JRadioButton) value; if (jrbutton.isSelected()) { if (!jrbutton.getText().equalsIgnoreCase("NONE")) { optionString.append("-"); optionString.append(jrbutton.getName()); optionString.append(" "); optionString.append(jrbutton.getText()); } if (title.equalsIgnoreCase("C-CAP")) { optionString.append("\n"); } } } } // Handle Conditional Options if (optionPanel.getComponentCount() == 3) { valuePanel = (JPanel) optionPanel.getComponent(1); // JLabel conditionalLabel = (JLabel) // valuePanel.getComponent(0); JTextField jtf = (JTextField) valuePanel.getComponent(1); if (jtf.isEnabled()) { String conditionalInput = jtf.getText(); // Post-Process the Input into Atom Pairs String postProcess = jtf.getName(); if (postProcess != null && postProcess.equalsIgnoreCase("ATOMPAIRS")) { String tokens[] = conditionalInput.split(" +"); StringBuilder atomPairs = new StringBuilder(); int atomNumber = 0; for (String token : tokens) { atomPairs.append(token); if (atomNumber++ % 2 == 0) { atomPairs.append(" "); } else { atomPairs.append("\n"); } } conditionalInput = atomPairs.toString(); } // Append a newline to "enter" the option string. // Append "conditional" input. optionString.append("\n").append(conditionalInput); } } } if (optionString.length() > 0) { commandTextArea.append(optionString.toString()); if (newLine) { commandTextArea.append("\n"); } } } String commandInput = commandTextArea.getText(); if (commandInput != null && !commandInput.trim().equalsIgnoreCase("")) { commandLineParams.append(commandInput); } // The final token on the command line is the structure file name, except // for protein and nucleic. if (!activeCommand.equalsIgnoreCase("Protein") && !activeCommand.equalsIgnoreCase("Nucleic")) { File file = activeSystem.getFile(); if (file != null) { String name = file.getName(); commandLineParams.append(name); commandLineParams.append(" "); } else { return null; } } return commandLineParams.toString(); }
From source file:io.github.jeremgamer.editor.panels.components.PanelsPanel.java
public PanelsPanel(JFrame frame, final PanelSave ps) { this.ps = ps; this.frame = frame; this.setSize(new Dimension(395, frame.getHeight() - 27 - 23)); this.setLocation(300, 0); this.setBorder(BorderFactory.createTitledBorder("Edition du panneau")); JPanel content = new JPanel(); JScrollPane scroll = new JScrollPane(content); scroll.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); scroll.setBorder(null);/*from w w w .ja v a 2 s .com*/ content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS)); scroll.setPreferredSize(new Dimension(382, frame.getHeight() - 27 - 46 - 20)); JPanel namePanel = new JPanel(); name.setPreferredSize(new Dimension(this.getWidth() - 280, 30)); name.setEditable(false); namePanel.add(new JLabel("Nom :")); namePanel.add(name); namePanel.add(Box.createRigidArea(new Dimension(10, 1))); layout.addItem("Basique"); layout.addItem("Bordures"); layout.addItem("Ligne"); layout.addItem("Colonne"); layout.addItem("Grille"); layout.addItem("Empil"); layout.setPreferredSize(new Dimension(110, 30)); layout.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); cl.show(advanced, listContent[combo.getSelectedIndex()]); ps.set("layout", combo.getSelectedIndex()); ActionPanel.updateLists(); } }); namePanel.add(new JLabel("Disposition :")); namePanel.add(layout); namePanel.setPreferredSize(new Dimension(365, 50)); namePanel.setMaximumSize(new Dimension(365, 50)); content.add(namePanel); advanced.setPreferredSize(new Dimension(365, 300)); advanced.setMaximumSize(new Dimension(365, 300)); advanced.add(ble, listContent[0]); advanced.add(brdle, listContent[1]); advanced.add(lle, listContent[2]); advanced.add(rle, listContent[3]); advanced.add(gle, listContent[4]); advanced.add(cle, listContent[5]); content.add(advanced); topBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.top", combo.getSelectedItem()); } }); leftBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.left", combo.getSelectedItem()); } }); centerBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.center", combo.getSelectedItem()); } }); rightBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.right", combo.getSelectedItem()); } }); bottomBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.bottom", combo.getSelectedItem()); } }); JPanel prefSize = new JPanel(); prefSize.setPreferredSize(new Dimension(365, 110)); prefSize.setMaximumSize(new Dimension(365, 110)); prefSize.setBorder(BorderFactory.createTitledBorder("Taille prfre")); JPanel prefSizePanel = new JPanel(); prefSizePanel.setLayout(new GridLayout(2, 4)); prefSizePanel.setPreferredSize(new Dimension(300, 55)); prefSizePanel.setMaximumSize(new Dimension(300, 55)); prefSizePanel.add(prefSizeEnabled); prefSizePanel.add(new JLabel("")); prefSizePanel.add(new JLabel("")); prefSizePanel.add(new JLabel("(en pixels)")); prefSizePanel.add(new JLabel("Largeur :")); prefSizePanel.add(prefWidth); prefSizePanel.add(new JLabel("Hauteur :")); prefSizePanel.add(prefHeight); prefWidth.setEnabled(false); prefHeight.setEnabled(false); prefSizeEnabled.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JCheckBox check = (JCheckBox) event.getSource(); ps.set("preferredSize", check.isSelected()); prefWidth.setEnabled(check.isSelected()); prefHeight.setEnabled(check.isSelected()); } }); prefWidth.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("preferredWidth", spinner.getValue()); } }); prefHeight.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("preferredHeight", spinner.getValue()); } }); prefSize.add(prefSizePanel); content.add(prefSize); JPanel insetsPanel = new JPanel(); insetsPanel.setBorder(BorderFactory.createTitledBorder("carts")); insetsPanel.setPreferredSize(new Dimension(365, 100)); insetsPanel.setMaximumSize(new Dimension(365, 100)); JPanel insetsContent = new JPanel(); insetsContent.setLayout(new BoxLayout(insetsContent, BoxLayout.PAGE_AXIS)); JPanel insetInput = new JPanel(); insetInput.setLayout(new GridLayout(2, 4)); insetInput.add(insetsEnabled); insetInput.add(new JLabel("")); insetInput.add(new JLabel("")); insetInput.add(new JLabel("(en pixels)")); insetInput.add(new JLabel("Horizontaux :")); insetInput.add(insetHz); insetInput.add(new JLabel("Verticaux :")); insetInput.add(insetVt); insetsEnabled.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JCheckBox check = (JCheckBox) event.getSource(); if (check.isSelected()) { insetHz.setEnabled(true); insetVt.setEnabled(true); ps.set("insets", true); } else { insetHz.setEnabled(true); insetVt.setEnabled(true); ps.set("insets", false); } } }); insetHz.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("insets.horizontal", spinner.getValue()); } }); insetVt.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("insets.vertical", spinner.getValue()); } }); insetsContent.add(insetInput); insetsPanel.add(insetsContent); content.add(insetsPanel); JPanel web = new JPanel(); web.setPreferredSize(new Dimension(365, 100)); web.setMaximumSize(new Dimension(365, 100)); web.setBorder(BorderFactory.createTitledBorder("Page Web")); JPanel webContent = new JPanel(); webContent.setLayout(new BorderLayout()); webContent.add(webEnabled, BorderLayout.NORTH); webEnabled.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox check = (JCheckBox) e.getSource(); ps.set("web", check.isSelected()); if (check.isSelected() == true) { layout.setSelectedIndex(0); layout.setEnabled(false); ble.removeAllComponents(); ble.disableComponents(); adress.setEnabled(true); } else { ble.enableComponents(); layout.setEnabled(true); adress.setEnabled(false); } } }); JPanel webInput = new JPanel(); webInput.add(new JLabel("Adresse :")); adress.setPreferredSize(new Dimension(250, 30)); CaretListener caretUpdate = new CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { JTextField text = (JTextField) e.getSource(); ps.set("web.adress", text.getText()); } }; adress.addCaretListener(caretUpdate); webInput.add(adress); webContent.add(webInput, BorderLayout.CENTER); web.add(webContent); JPanel background = new JPanel(); BorderLayout bLayout = new BorderLayout(); bLayout.setVgap(12); background.setLayout(bLayout); background.setBorder(BorderFactory.createTitledBorder("Couleur de fond")); background.setPreferredSize(new Dimension(365, 210)); background.setMaximumSize(new Dimension(365, 210)); cp.setPreferredSize(new Dimension(347, 145)); cp.setMaximumSize(new Dimension(347, 145)); opaque.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox check = (JCheckBox) e.getSource(); ps.set("background.opaque", check.isSelected()); cp.enableComponents(check.isSelected()); } }); background.add(opaque, BorderLayout.NORTH); background.add(cp, BorderLayout.CENTER); JPanel image = new JPanel(); image.setBorder(BorderFactory.createTitledBorder("Image de fond")); image.setPreferredSize(new Dimension(365, 125)); image.setMaximumSize(new Dimension(365, 125)); image.setLayout(new BorderLayout()); try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.setEnabled(false); remove.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { File img = new File( "projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png"); if (img.exists()) { img.delete(); } browseImage.setEnabled(true); } }); JPanel top = new JPanel(); browseImage.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JButton button = (JButton) e.getSource(); String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "background.png"); nameBackground.setText(new File(path).getName()); ps.set("background.image", new File(path).getName()); button.setEnabled(false); size.setEnabled(true); size2.setEnabled(true); remove.setEnabled(true); } } }); bg.add(size); bg.add(size2); JPanel sizePanel = new JPanel(); sizePanel.setLayout(new BoxLayout(sizePanel, BoxLayout.PAGE_AXIS)); size.setEnabled(false); size2.setEnabled(false); sizePanel.add(size); sizePanel.add(size2); size.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { ps.set("background.size", 0); } }); size2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { ps.set("background.size", 1); } }); top.add(browseImage); top.add(sizePanel); remove.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JButton button = (JButton) event.getSource(); new File("projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png") .delete(); nameBackground.setText(""); ps.set("background.image", ""); button.setEnabled(false); } }); nameBackground.setFont(new Font("Sans Serif", Font.PLAIN, 15)); JPanel center = new JPanel(new BorderLayout()); center.add(nameBackground, BorderLayout.CENTER); center.add(remove, BorderLayout.EAST); image.add(top, BorderLayout.NORTH); image.add(center, BorderLayout.CENTER); content.add(web); content.add(background); content.add(image); this.add(scroll); }
From source file:edu.ku.brc.specify.plugins.ipadexporter.ManageDataSetsDlg.java
/** * /*from w w w . j a v a 2 s. c o m*/ */ private void addUserToDS() { final Vector<String> wsList = new Vector<String>(); final Vector<String> instItems = new Vector<String>(); String addStr = getResourceString("ADD"); instItems.add(addStr); wsList.add(addStr); for (String fullName : cloudHelper.getInstList()) { String[] toks = StringUtils.split(fullName, '\t'); instItems.add(toks[0]); wsList.add(toks[1]); } final JTextField userNameTF = createTextField(20); final JTextField passwordTF = createTextField(20); final JLabel pwdLbl = createI18NFormLabel("Password"); final JLabel statusLbl = createLabel(""); final JCheckBox isNewUser = UIHelper.createCheckBox("Is New User"); final JLabel instLbl = createI18NFormLabel("Insitution"); final JComboBox instCmbx = UIHelper.createComboBox(instItems.toArray()); if (instItems.size() == 2) { instCmbx.setSelectedIndex(1); } CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,4px,p,4px,p,4px,p,4px,p,8px,p")); pb.add(createI18NLabel("Add New or Existing User to DataSet"), cc.xyw(1, 1, 3)); pb.add(createI18NFormLabel("Username"), cc.xy(1, 3)); pb.add(userNameTF, cc.xy(3, 3)); pb.add(pwdLbl, cc.xy(1, 5)); pb.add(passwordTF, cc.xy(3, 5)); pb.add(instLbl, cc.xy(1, 7)); pb.add(instCmbx, cc.xy(3, 7)); pb.add(isNewUser, cc.xy(3, 9)); pb.add(statusLbl, cc.xyw(1, 11, 3)); pb.setDefaultDialogBorder(); pwdLbl.setVisible(false); passwordTF.setVisible(false); instLbl.setVisible(false); instCmbx.setVisible(false); final CustomDialog dlg = new CustomDialog(this, "Add User", true, OKCANCEL, pb.getPanel()) { @Override protected void okButtonPressed() { String usrName = userNameTF.getText(); if (cloudHelper.isUserNameOK(usrName)) { String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex()); if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) { super.okButtonPressed(); } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("Unable to add usr: %s to the DataSet guid: %s", usrName, collGuid)); } } else if (isNewUser.isSelected()) { String pwdStr = passwordTF.getText(); String guid = null; if (instCmbx.getSelectedIndex() == 0) { // InstDlg instDlg = new InstDlg(cloudHelper); // if (!instDlg.isInstOK()) // { // instDlg.createUI(); // instDlg.pack(); // centerAndShow(instDlg, 600, null); // if (instDlg.isCancelled()) // { // return; // } // //guid = instDlg.getGuid()(); // } } else { //webSite = wsList.get(instCmbx.getSelectedIndex()); } if (guid != null) { String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex()); if (cloudHelper.addNewUser(usrName, pwdStr, guid)) { if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) { ManageDataSetsDlg.this.loadUsersForDataSetsIntoJList(); super.okButtonPressed(); } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("Unable to add%s to the DataSet %s", usrName, collGuid)); } } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("Unable to add%s to the DataSet %s", usrName, collGuid)); } } else { // error } } else { iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("'%s' doesn't exist.", usrName)); } } }; KeyAdapter ka = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { statusLbl.setText(""); String usrNmStr = userNameTF.getText(); boolean hasData = StringUtils.isNotEmpty(usrNmStr) && (!isNewUser.isSelected() || StringUtils.isNotEmpty(passwordTF.getText())) && UIHelper.isValidEmailAddress(usrNmStr); dlg.getOkBtn().setEnabled(hasData); } }; userNameTF.addKeyListener(ka); passwordTF.addKeyListener(ka); final Color textColor = userNameTF.getForeground(); FocusAdapter fa = new FocusAdapter() { @Override public void focusGained(FocusEvent e) { JTextField tf = (JTextField) e.getSource(); if (!tf.getForeground().equals(textColor)) { tf.setText(""); tf.setForeground(textColor); } } @Override public void focusLost(FocusEvent e) { JTextField tf = (JTextField) e.getSource(); if (tf.getText().length() == 0) { tf.setText("Enter email address"); tf.setForeground(Color.LIGHT_GRAY); } } }; userNameTF.addFocusListener(fa); userNameTF.setText("Enter email address"); userNameTF.setForeground(Color.LIGHT_GRAY); isNewUser.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean isSel = isNewUser.isSelected(); pwdLbl.setVisible(isSel); passwordTF.setVisible(isSel); instLbl.setVisible(isSel); instCmbx.setVisible(isSel); Dimension s = dlg.getSize(); int hgt = isNewUser.getSize().height + 4 + instCmbx.getSize().height; s.height += isSel ? hgt : -hgt; dlg.setSize(s); } }); dlg.createUI(); dlg.getOkBtn().setEnabled(false); centerAndShow(dlg); if (!dlg.isCancelled()) { loadUsersForDataSetsIntoJList(); } }
From source file:lejos.pc.charting.LogChartFrame.java
private void manageAxisLabel(int AxisIndex) { JLabel tempLabel;/* ww w .jav a 2 s .c o m*/ JTextField tempTextField; switch (AxisIndex) { case 0: tempLabel = jLabel2; tempTextField = axis1LabelTextField; break; case 1: tempLabel = jLabel3; tempTextField = axis2LabelTextField; break; case 2: tempLabel = jLabel4; tempTextField = axis3LabelTextField; break; case 3: tempLabel = jLabel6; tempTextField = axis4LabelTextField; break; default: return; } boolean axisExists = loggingJFreeChart.getXYPlot().getRangeAxis(AxisIndex) != null; tempTextField.setEnabled(axisExists); tempLabel.setEnabled(axisExists); if (!axisExists) return; String chartAxisLabel = loggingJFreeChart.getXYPlot().getRangeAxis(AxisIndex).getLabel(); String customLabel = tempTextField.getText(); if (customLabel.equals("")) { tempTextField.setText(chartAxisLabel); } else { loggingJFreeChart.getXYPlot().getRangeAxis(AxisIndex).setLabel(customLabel); } }