List of usage examples for javax.swing JTextField setEnabled
@BeanProperty(expert = true, preferred = true, visualUpdate = true, description = "The enabled state of the component.") public void setEnabled(boolean enabled)
From source file:eu.apenet.dpt.standalone.gui.eag2012.EagControlPanel.java
@Override protected JComponent buildEditorPanel(List<String> errors) { if (errors == null) errors = new ArrayList<String>(0); else if (Utilities.isDev && errors.size() > 0) { LOG.info("Errors in form:"); for (String error : errors) { LOG.info(error);/*from w ww.j a va2 s . c o m*/ } } FormLayout layout = new FormLayout("right:max(50dlu;p), 4dlu, 100dlu, 7dlu, right:p, 4dlu, 100dlu", EDITOR_ROW_SPEC); layout.setColumnGroups(new int[][] { { 1, 3, 5, 7 } }); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); rowNb = 1; builder.addLabel(labels.getString("eag2012.commons.idUsedInApe") + "*", cc.xy(1, rowNb)); JTextField recordIdTf = new JTextField(eag.getControl().getRecordId().getValue()); recordIdTf.setEnabled(false); builder.add(recordIdTf, cc.xy(3, rowNb)); setNextRow(); builder.addLabel(labels.getString("eag2012.commons.personResponsible"), cc.xy(1, rowNb)); int sizeEvents = eag.getControl().getMaintenanceHistory().getMaintenanceEvent().size(); if (sizeEvents > 0) { MaintenanceEvent event = eag.getControl().getMaintenanceHistory().getMaintenanceEvent() .get(sizeEvents - 1); personInstitutionRespTf = new TextFieldWithLanguage(event.getAgent().getContent(), event.getAgent().getLang()); } else { personInstitutionRespTf = new TextFieldWithLanguage("", ""); } personInstitutionRespTf.getTextField().setEnabled(false); builder.add(personInstitutionRespTf.getTextField(), cc.xy(3, rowNb)); builder.addLabel(labels.getString("eag2012.commons.language"), cc.xy(5, rowNb)); builder.add(personInstitutionRespTf.getLanguageBox(), cc.xy(7, rowNb)); setNextRow(); builder.addSeparator(labels.getString("eag2012.control.usedLanguages"), cc.xyw(1, rowNb, 7)); setNextRow(); if (eag.getControl().getLanguageDeclarations() == null) eag.getControl().setLanguageDeclarations(new LanguageDeclarations()); if (eag.getControl().getLanguageDeclarations().getLanguageDeclaration().size() == 0) { LanguageDeclaration languageDeclaration = new LanguageDeclaration(); languageDeclaration.setLanguage(new Language()); languageDeclaration.setScript(new Script()); eag.getControl().getLanguageDeclarations().getLanguageDeclaration().add(languageDeclaration); } int i = 0; languageWithScriptTfs = new ArrayList<LanguageWithScript>( eag.getControl().getLanguageDeclarations().getLanguageDeclaration().size()); for (LanguageDeclaration languageDeclaration : eag.getControl().getLanguageDeclarations() .getLanguageDeclaration()) { builder.addLabel(labels.getString("eag2012.commons.language"), cc.xy(1, rowNb)); LanguageWithScript languageWithScript = new LanguageWithScript( languageDeclaration.getLanguage().getLanguageCode(), languageDeclaration.getScript().getScriptCode(), labels); languageWithScriptTfs.add(languageWithScript); builder.add(languageWithScript.getLanguageBox(), cc.xy(3, rowNb)); builder.addLabel(labels.getString("eag2012.control.descriptionScript"), cc.xy(5, rowNb)); builder.add(languageWithScript.getScriptBox(), cc.xy(7, rowNb)); setNextRow(); } if (errors.contains("languageWithScriptTfs")) { builder.add(createErrorLabel(labels.getString("eag2012.errors.noscript")), cc.xy(3, rowNb)); } JButton addLanguagesBtn = new ButtonTab(labels.getString("eag2012.control.addFurtherLangsAnsScripts")); builder.add(addLanguagesBtn, cc.xy(5, rowNb)); addLanguagesBtn.addActionListener(new AddLanguagesBtnAction(eag, tabbedPane, model)); setNextRow(); builder.addSeparator(labels.getString("eag2012.control.conventions"), cc.xyw(1, rowNb, 7)); setNextRow(); if (eag.getControl().getConventionDeclaration().size() == 0) eag.getControl().getConventionDeclaration().add(new ConventionDeclaration()); rulesConventionTfs = new ArrayList<TextFieldWithLanguage>( eag.getControl().getConventionDeclaration().size()); for (ConventionDeclaration conventionDeclaration : eag.getControl().getConventionDeclaration()) { builder.addLabel(labels.getString("eag2012.control.abbreviation"), cc.xy(1, rowNb)); TextFieldWithLanguage textFieldWithLanguage = new TextFieldWithLanguage( conventionDeclaration.getAbbreviation().getContent(), "", conventionDeclaration.getCitation().get(0).getContent()); rulesConventionTfs.add(textFieldWithLanguage); builder.add(textFieldWithLanguage.getTextField(), cc.xy(3, rowNb)); builder.addLabel(labels.getString("eag2012.control.fullName"), cc.xy(5, rowNb)); builder.add(textFieldWithLanguage.getExtraField(), cc.xy(7, rowNb)); setNextRow(); } JButton addConventionBtn = new ButtonTab(labels.getString("eag2012.commons.addCnventions")); builder.add(addConventionBtn, cc.xy(5, rowNb)); addConventionBtn.addActionListener(new AddConventionBtnAction(eag, tabbedPane, model)); setNextRow(); builder.addSeparator("", cc.xyw(1, rowNb, 7)); setNextRow(); JButton exitBtn = new ButtonTab(labels.getString("eag2012.commons.exit")); builder.add(exitBtn, cc.xy(1, rowNb)); exitBtn.addActionListener(new ExitBtnAction(eag, tabbedPane, model)); JButton previousTabBtn = new ButtonTab(labels.getString("eag2012.commons.previousTab")); builder.add(previousTabBtn, cc.xy(3, rowNb)); previousTabBtn.addActionListener(new ChangeTabBtnAction(eag, tabbedPane, model, false)); JButton nextTabBtn = new ButtonTab(labels.getString("eag2012.commons.nextTab")); builder.add(nextTabBtn, cc.xy(5, rowNb)); nextTabBtn.addActionListener(new ChangeTabBtnAction(eag, tabbedPane, model, true)); setNextRow(); JButton saveBtn = new ButtonTab(labels.getString("eag2012.commons.save")); builder.add(saveBtn, cc.xy(5, rowNb)); saveBtn.addActionListener(new SaveBtnAction(eag, tabbedPane, model)); setNextRow(); builder.addSeparator("", cc.xyw(1, rowNb, 7)); setNextRow(); JButton nextInstitutionTabBtn = new ButtonTab(labels.getString("eag2012.controls.nextInstitution")); nextInstitutionTabBtn.addActionListener(new NextInstitutionTabBtnAction(eag, tabbedPane, model)); builder.add(nextInstitutionTabBtn, cc.xy(5, rowNb)); // Define the change tab listener. this.removeChangeListener(); this.tabbedPane.addChangeListener(new ChangeTabListener(this.eag, this.tabbedPane, this.model, 5)); JPanel panel = builder.getPanel(); KeyboardFocusManager.getCurrentKeyboardFocusManager() .addPropertyChangeListener(new FocusManagerListener(panel)); return panel; }
From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfControlPanel.java
private PanelBuilder buildMainPanel(PanelBuilder builder, CellConstraints cc) { JLabel jLabelIdInTheApeEACCPF = new JLabel(this.labels.getString("eaccpf.control.idintheapeeaccpf")); builder.add(jLabelIdInTheApeEACCPF, cc.xy(1, rowNb)); //extracted from dashboard implementation Random random = new Random(); String value = ""; // String mainagencycode = (this.eaccpf.getControl().getMaintenanceAgency().getAgencyCode()!=null && this.eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue()!=null )?this.eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue():""; if (this.eaccpf.getControl().getRecordId().getValue() == null || this.eaccpf.getControl().getRecordId().getValue().isEmpty()) { int fakeId = random.nextInt(1000000000); value = Integer.toString(fakeId); // value = "eac_" + mainagencycode + "_" + Integer.toString(fakeId); } else {// ww w . j a v a2s. c o m value = this.eaccpf.getControl().getRecordId().getValue(); } JTextField jTextFieldIdInTheApeEACCPF = new JTextField(value); jTextFieldIdInTheApeEACCPF.setEnabled(false); //put like disabled, it's not editable builder.add(jTextFieldIdInTheApeEACCPF, cc.xy(3, rowNb)); this.idAutogeneratedControl = jTextFieldIdInTheApeEACCPF.getText(); //It's not shown because field is autogenerated and it's not editabled (eaccpf object has no access to this value by form) setNextRow(); JLabel jLabelLinkPersonResponsible = new JLabel( this.labels.getString("eaccpf.control.personinstitutionresponsiblefordescription")); builder.add(jLabelLinkPersonResponsible, cc.xy(1, rowNb)); String content = ""; if (StringUtils.isNotEmpty(responsible)) { content = responsible; } else if (this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() > 0 && this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent() .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1) .getAgent() != null && this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent() .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1) .getAgent().getContent() != null && !this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent() .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1) .getAgent().getContent().isEmpty()) { content = this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent() .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1) .getAgent().getContent(); } else { content = MAINTENANCE_AGENT_HUMAN; } JTextField jTextFieldPersonResponsible = new JTextField(content); builder.add(jTextFieldPersonResponsible, cc.xy(3, rowNb)); this.personInstitutionResponsibleTextField = jTextFieldPersonResponsible; setNextRow(); JLabel jLabelIdentifierForPersonResponsible = new JLabel( this.labels.getString("eaccpf.control.identifierofinstitutionresponsible") + "*"); builder.add(jLabelIdentifierForPersonResponsible, cc.xy(1, rowNb)); content = eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue() != null ? eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue() : ""; JTextField jTextFieldIdentifierForPersonResponsible = new JTextField(content); builder.add(jTextFieldIdentifierForPersonResponsible, cc.xy(3, rowNb)); this.idControl = jTextFieldIdentifierForPersonResponsible; setNextRow(); if (StringUtils.isEmpty(content)) { builder.add(createErrorLabel(this.labels.getString("eaccpf.control.error.emptyidentifier")), cc.xyw(1, this.rowNb, 3)); setNextRow(); } if (this.eaccpf.getControl().getOtherRecordId().isEmpty()) { OtherRecordId newOtherRecordId = new OtherRecordId(); newOtherRecordId.setLocalType(EacCpfPanel.LOCAL_TYPE_ORIGINAL); this.eaccpf.getControl().getOtherRecordId().add(newOtherRecordId); } List<OtherRecordId> otherRecordIds = this.eaccpf.getControl().getOtherRecordId(); this.localIdentifierForInstitution = new ArrayList<JTextField>(otherRecordIds.size()); this.listIdentifierType = new ArrayList<JTextField>(otherRecordIds.size()); for (OtherRecordId otherRecordId : otherRecordIds) { // Create element. JTextField jTextFieldLocalIdentifierPersonResponsible = new JTextField(otherRecordId.getContent()); JTextField jTextFieldIdentifierType = new JTextField(otherRecordId.getLocalType()); // Add elements to the list. this.localIdentifierForInstitution.add(jTextFieldLocalIdentifierPersonResponsible); this.listIdentifierType.add(jTextFieldIdentifierType); builder.addLabel(this.labels.getString("eaccpf.control.otherRecordIdentifier"), cc.xy(1, this.rowNb)); builder.add(jTextFieldLocalIdentifierPersonResponsible, cc.xy(3, this.rowNb)); this.setNextRow(); } JButton nextTabBtn = new ButtonTab(this.labels.getString("eaccpf.control.addlocalidentifier")); builder.add(nextTabBtn, cc.xy(1, this.rowNb)); nextTabBtn.addActionListener(new AddLocalIdentifier(eaccpf, tabbedPane, model)); setNextRow(); builder.addLabel(this.labels.getString("eaccpf.control.usedlanguagesandscriptsfordescription"), cc.xyw(1, this.rowNb, 7)); setNextRow(); builder.addLabel(labels.getString("eaccpf.commons.select.language") + "*" + ":", cc.xy(1, rowNb)); LanguageWithScript languageWithScript = new LanguageWithScript(firstLanguage, firstScript, labels); JComboBox<String> scriptBox = languageWithScript.getScriptBox(); //fix for script part, it's not selecting values boolean found = false; int size = scriptBox.getModel().getSize(); for (int i = 0; !found && i < size; i++) { String element = scriptBox.getModel().getElementAt(i); if (element != null && element.equalsIgnoreCase(firstScript)) { scriptBox.setSelectedIndex(i); found = true; } } //end fix for script part builder.add(languageWithScript.getLanguageBox(), cc.xy(3, rowNb)); this.languageFirst = languageWithScript.getLanguageBox(); builder.addLabel(labels.getString("eaccpf.control.selectascript") + "*" + ":", cc.xy(5, rowNb)); builder.add(languageWithScript.getScriptBox(), cc.xy(7, rowNb)); this.scriptFirst = languageWithScript.getScriptBox(); this.languageWithScript = languageWithScript; setNextRow(); return builder; }
From source file:com.smanempat.controller.ControllerClassification.java
public void chooseFile(ActionEvent evt, JTextField txtFileDirectory, JTextField txtNumberOfK, JLabel labelJumlahData, JButton buttonProses, JTable tablePreview) { try {//from ww w.j a v a2s .c o m JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter fileNameExtensionFilter = new FileNameExtensionFilter("Excel File", "xls", "xlsx"); fileChooser.setFileFilter(fileNameExtensionFilter); if (fileChooser.showOpenDialog(fileChooser) == JFileChooser.APPROVE_OPTION) { txtFileDirectory.setText(fileChooser.getSelectedFile().getAbsolutePath()); System.out.println("Good, File Chooser runing well!"); if (txtFileDirectory.getText().endsWith(".xls") || txtFileDirectory.getText().endsWith(".xlsx")) { showOnTable(evt, txtFileDirectory, tablePreview); labelJumlahData.setText(tablePreview.getRowCount() + " Data"); txtNumberOfK.setEnabled(true); txtNumberOfK.requestFocus(); buttonProses.setEnabled(true); } else { JOptionPane.showMessageDialog(null, "File dataset harus file spreadsheet dengan ekstensi *xls atau *.xlsx!", "Error", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/fail.png")); txtFileDirectory.setText(""); chooseFile(evt, txtFileDirectory, txtNumberOfK, labelJumlahData, buttonProses, tablePreview); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:configuration.Util.java
public static void buttonEventText(workflow_properties properties, javax.swing.JRadioButton b, javax.swing.JTextField t) { if (b == null) { properties.put(t.getName(), t.getText()); } else {//from w ww. j a v a 2s. c om if (b.isSelected() == true) { if (t == null) { properties.put(b.getName(), b.isSelected()); } else { t.setEnabled(true); properties.put(t.getName(), t.getText()); properties.put(b.getName(), t.getText()); } } } }
From source file:configuration.Util.java
public static void boxEventText(workflow_properties properties, javax.swing.JCheckBox b, javax.swing.JTextField t) { if (b == null) { properties.put(t.getName(), t.getText()); } else {/*www . j ava 2s . co m*/ if (b.isSelected() == true) { if (t == null) { properties.put(b.getName(), b.isSelected()); } else { t.setEnabled(true); properties.put(t.getName(), t.getText()); properties.put(b.getName(), t.getText()); } } else { properties.remove(b.getName()); if (t != null) { t.setEnabled(false); } } } }
From source file:lejos.pc.charting.LogChartFrame.java
private void manageAxisLabel(int AxisIndex) { JLabel tempLabel;/*from w ww . j a va2s . co 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); } }
From source file:ffx.ui.ModelingPanel.java
/** * This handles conditional command option input. * * @param evt ActionEvent/*from w ww .ja v a2s. co m*/ */ private void conditionalCommandEvent(ActionEvent evt) { Object source = evt.getSource(); if (source instanceof JRadioButton) { JRadioButton jrb = (JRadioButton) source; String selection = jrb.getText().toLowerCase(); for (JLabel label : conditionals) { JTextField jtf = (JTextField) label.getLabelFor(); String cupon = label.getName().toLowerCase(); if (cupon.contains(selection) && jrb.isSelected()) { label.setEnabled(true); jtf.setEnabled(true); } else { label.setEnabled(false); jtf.setEnabled(false); } } } else if (source instanceof JCheckBox) { JCheckBox jcb = (JCheckBox) source; String selection = jcb.getText().toLowerCase(); for (JLabel label : conditionals) { String cupon = label.getName().toLowerCase(); JTextField jtf = (JTextField) label.getLabelFor(); if (cupon.contains(selection) && jcb.isSelected()) { label.setEnabled(true); jtf.setEnabled(true); } else { label.setEnabled(false); jtf.setEnabled(false); } } } statusLabel.setText(" " + createCommandInput()); }
From source file:ffx.ui.ModelingPanel.java
private void loadCommand() { synchronized (this) { // Force Field X Command Element command;/*ww w . ja v a 2 s . co m*/ // Command Options NodeList options; Element option; // Option Values NodeList values; Element value; // Options may be Conditional based on previous Option values (not // always supplied) NodeList conditionalList; Element conditional; // JobPanel GUI Components that change based on command JPanel optionPanel; // Clear the previous components commandPanel.removeAll(); optionsTabbedPane.removeAll(); conditionals.clear(); String currentCommand = (String) currentCommandBox.getSelectedItem(); if (currentCommand == null) { commandPanel.validate(); commandPanel.repaint(); return; } command = null; for (int i = 0; i < commandList.getLength(); i++) { command = (Element) commandList.item(i); String name = command.getAttribute("name"); if (name.equalsIgnoreCase(currentCommand)) { break; } } int div = splitPane.getDividerLocation(); descriptTextArea.setText(currentCommand.toUpperCase() + ": " + command.getAttribute("description")); splitPane.setBottomComponent(descriptScrollPane); splitPane.setDividerLocation(div); // The "action" tells Force Field X what to do when the // command finishes commandActions = command.getAttribute("action").trim(); // The "fileType" specifies what file types this command can execute // on String string = command.getAttribute("fileType").trim(); String[] types = string.split(" +"); commandFileTypes.clear(); for (String type : types) { if (type.contains("XYZ")) { commandFileTypes.add(FileType.XYZ); } if (type.contains("INT")) { commandFileTypes.add(FileType.INT); } if (type.contains("ARC")) { commandFileTypes.add(FileType.ARC); } if (type.contains("PDB")) { commandFileTypes.add(FileType.PDB); } if (type.contains("ANY")) { commandFileTypes.add(FileType.ANY); } } // Determine what options are available for this command options = command.getElementsByTagName("Option"); int length = options.getLength(); for (int i = 0; i < length; i++) { // This Option will be enabled (isEnabled = true) unless a // Conditional disables it boolean isEnabled = true; option = (Element) options.item(i); conditionalList = option.getElementsByTagName("Conditional"); /* * Currently, there can only be 0 or 1 Conditionals per Option * There are three types of Conditionals implemented. 1.) * Conditional on a previous Option, this option may be * available 2.) Conditional on input for this option, a * sub-option may be available 3.) Conditional on the presence * of keywords, this option may be available */ if (conditionalList != null) { conditional = (Element) conditionalList.item(0); } else { conditional = null; } // Get the command line flag String flag = option.getAttribute("flag").trim(); // Get the description String optionDescript = option.getAttribute("description"); JTextArea optionTextArea = new JTextArea(" " + optionDescript.trim()); optionTextArea.setEditable(false); optionTextArea.setLineWrap(true); optionTextArea.setWrapStyleWord(true); optionTextArea.setBorder(etchedBorder); // Get the default for this Option (if one exists) String defaultOption = option.getAttribute("default"); // Option Panel optionPanel = new JPanel(new BorderLayout()); optionPanel.add(optionTextArea, BorderLayout.NORTH); String swing = option.getAttribute("gui"); JPanel optionValuesPanel = new JPanel(new FlowLayout()); optionValuesPanel.setBorder(etchedBorder); ButtonGroup bg = null; if (swing.equalsIgnoreCase("CHECKBOXES")) { // CHECKBOXES allows selection of 1 or more values from a // predefined set (Analyze, for example) values = option.getElementsByTagName("Value"); for (int j = 0; j < values.getLength(); j++) { value = (Element) values.item(j); JCheckBox jcb = new JCheckBox(value.getAttribute("name")); jcb.addMouseListener(this); jcb.setName(flag); if (defaultOption != null && jcb.getActionCommand().equalsIgnoreCase(defaultOption)) { jcb.setSelected(true); } optionValuesPanel.add(jcb); } } else if (swing.equalsIgnoreCase("TEXTFIELD")) { // TEXTFIELD takes an arbitrary String as input JTextField jtf = new JTextField(20); jtf.addMouseListener(this); jtf.setName(flag); if (defaultOption != null && defaultOption.equals("ATOMS")) { FFXSystem sys = mainPanel.getHierarchy().getActive(); if (sys != null) { jtf.setText("" + sys.getAtomList().size()); } } else if (defaultOption != null) { jtf.setText(defaultOption); } optionValuesPanel.add(jtf); } else if (swing.equalsIgnoreCase("RADIOBUTTONS")) { // RADIOBUTTONS allows one choice from a set of predifined // values bg = new ButtonGroup(); values = option.getElementsByTagName("Value"); for (int j = 0; j < values.getLength(); j++) { value = (Element) values.item(j); JRadioButton jrb = new JRadioButton(value.getAttribute("name")); jrb.addMouseListener(this); jrb.setName(flag); bg.add(jrb); if (defaultOption != null && jrb.getActionCommand().equalsIgnoreCase(defaultOption)) { jrb.setSelected(true); } optionValuesPanel.add(jrb); } } else if (swing.equalsIgnoreCase("PROTEIN")) { // Protein allows selection of amino acids for the protein // builder optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS)); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(getAminoAcidPanel()); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidComboBox.removeAllItems(); JButton add = new JButton("Edit"); add.setActionCommand("PROTEIN"); add.addActionListener(this); add.setAlignmentX(Button.CENTER_ALIGNMENT); JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidTextField); comboPanel.add(add); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton remove = new JButton("Remove"); add.setMinimumSize(remove.getPreferredSize()); add.setPreferredSize(remove.getPreferredSize()); remove.setActionCommand("PROTEIN"); remove.addActionListener(this); remove.setAlignmentX(Button.CENTER_ALIGNMENT); comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidComboBox); comboPanel.add(remove); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(acidScrollPane); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton reset = new JButton("Reset"); reset.setActionCommand("PROTEIN"); reset.addActionListener(this); reset.setAlignmentX(Button.CENTER_ALIGNMENT); optionValuesPanel.add(reset); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidTextArea.setText(""); acidTextField.setText(""); } else if (swing.equalsIgnoreCase("NUCLEIC")) { // Nucleic allows selection of nucleic acids for the nucleic // acid builder optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS)); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(getNucleicAcidPanel()); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidComboBox.removeAllItems(); JButton add = new JButton("Edit"); add.setActionCommand("NUCLEIC"); add.addActionListener(this); add.setAlignmentX(Button.CENTER_ALIGNMENT); JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidTextField); comboPanel.add(add); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton remove = new JButton("Remove"); add.setMinimumSize(remove.getPreferredSize()); add.setPreferredSize(remove.getPreferredSize()); remove.setActionCommand("NUCLEIC"); remove.addActionListener(this); remove.setAlignmentX(Button.CENTER_ALIGNMENT); comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidComboBox); comboPanel.add(remove); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(acidScrollPane); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton button = new JButton("Reset"); button.setActionCommand("NUCLEIC"); button.addActionListener(this); button.setAlignmentX(Button.CENTER_ALIGNMENT); optionValuesPanel.add(button); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidTextArea.setText(""); acidTextField.setText(""); } else if (swing.equalsIgnoreCase("SYSTEMS")) { // SYSTEMS allows selection of an open system JComboBox<FFXSystem> jcb = new JComboBox<>(mainPanel.getHierarchy().getNonActiveSystems()); jcb.setSize(jcb.getMaximumSize()); jcb.addActionListener(this); optionValuesPanel.add(jcb); } // Set up a Conditional for this Option if (conditional != null) { isEnabled = false; String conditionalName = conditional.getAttribute("name"); String conditionalValues = conditional.getAttribute("value"); String cDescription = conditional.getAttribute("description"); String cpostProcess = conditional.getAttribute("postProcess"); if (conditionalName.toUpperCase().startsWith("KEYWORD")) { optionPanel.setName(conditionalName); String keywords[] = conditionalValues.split(" +"); if (activeSystem != null) { Hashtable<String, Keyword> systemKeywords = activeSystem.getKeywords(); for (String key : keywords) { if (systemKeywords.containsKey(key.toUpperCase())) { isEnabled = true; } } } } else if (conditionalName.toUpperCase().startsWith("VALUE")) { isEnabled = true; // Add listeners to the values of this option so // the conditional options can be disabled/enabled. for (int j = 0; j < optionValuesPanel.getComponentCount(); j++) { JToggleButton jtb = (JToggleButton) optionValuesPanel.getComponent(j); jtb.addActionListener(this); jtb.setActionCommand("Conditional"); } JPanel condpanel = new JPanel(); condpanel.setBorder(etchedBorder); JLabel condlabel = new JLabel(cDescription); condlabel.setEnabled(false); condlabel.setName(conditionalValues); JTextField condtext = new JTextField(10); condlabel.setLabelFor(condtext); if (cpostProcess != null) { condtext.setName(cpostProcess); } condtext.setEnabled(false); condpanel.add(condlabel); condpanel.add(condtext); conditionals.add(condlabel); optionPanel.add(condpanel, BorderLayout.SOUTH); } else if (conditionalName.toUpperCase().startsWith("REFLECTION")) { String[] condModifiers; if (conditionalValues.equalsIgnoreCase("AltLoc")) { condModifiers = activeSystem.getAltLocations(); if (condModifiers != null && condModifiers.length > 1) { isEnabled = true; bg = new ButtonGroup(); for (int j = 0; j < condModifiers.length; j++) { JRadioButton jrbmi = new JRadioButton(condModifiers[j]); jrbmi.addMouseListener(this); bg.add(jrbmi); optionValuesPanel.add(jrbmi); if (j == 0) { jrbmi.setSelected(true); } } } } else if (conditionalValues.equalsIgnoreCase("Chains")) { condModifiers = activeSystem.getChainNames(); if (condModifiers != null && condModifiers.length > 0) { isEnabled = true; for (int j = 0; j < condModifiers.length; j++) { JRadioButton jrbmi = new JRadioButton(condModifiers[j]); jrbmi.addMouseListener(this); bg.add(jrbmi); optionValuesPanel.add(jrbmi, j); } } } } } optionPanel.add(optionValuesPanel, BorderLayout.CENTER); optionPanel.setPreferredSize(optionPanel.getPreferredSize()); optionsTabbedPane.addTab(option.getAttribute("name"), optionPanel); optionsTabbedPane.setEnabledAt(optionsTabbedPane.getTabCount() - 1, isEnabled); } } optionsTabbedPane.setPreferredSize(optionsTabbedPane.getPreferredSize()); commandPanel.setLayout(borderLayout); commandPanel.add(optionsTabbedPane, BorderLayout.CENTER); commandPanel.validate(); commandPanel.repaint(); loadLogSettings(); statusLabel.setText(" " + createCommandInput()); }
From source file:edu.ku.brc.specify.tasks.ExpressSearchTask.java
/** * Performs the express search and returns the results to the ExpressSearchResultsPaneIFace. * If the control is null then it will use the string. * * @param searchTextArg the Text Control that contains the search string (can be null) * @param searchTextStr the Text Control that contains the search string (can be null) * @param tables ExpressResultsTableInfo hash * @param esrPane the pane that the results will be set into * @return true if results were found, false if not results *///from ww w .ja v a 2 s . c om public synchronized boolean doQuery(final JTextField searchTextArg, final String searchTextStr, final ExpressSearchResultsPaneIFace esrPane) { doingDebug = AppPreferences.getLocalPrefs().getBoolean("esdebug", false); searchWarningsResults = null; String searchTerm = (searchTextArg != null ? searchTerm = searchTextArg.getText() : searchTextStr); if (!ESTermParser.getInstance().parse(searchTerm, false)) { setUserInputToNotFound("BAD_SEARCH_TERMS", false); return false; } //boolean hasResults = true; if (StringUtils.isNotEmpty(searchTerm)) { SearchTableConfig context = SearchConfigService.getInstance().getSearchContext(); if (context == null) { SearchConfig config = SearchConfigService.getInstance().getSearchConfig(); if (config.getTables().size() > 0) { sqlHasResults = false; if (searchTextArg != null) { searchTextArg.setEnabled(false); } if (searchBtn != null) { searchBtn.setEnabled(false); } queryList.clear(); // Just in case queryCount = 0; queryCountDone = 0; int cnt = 0; for (SearchTableConfig table : config.getTables()) { if (!table.getTableInfo().isHidden()) { if (AppContextMgr.isSecurityOn()) { if (table.getTableInfo().getPermissions().canView()) { if (startSearchJPA(esrPane, table, searchTerm, ESTermParser.getInstance().getFields()) != null) { cnt++; } } else { log.debug("Skipping [" + table.getTableInfo().getTitle() + "]"); } } else { if (startSearchJPA(esrPane, table, searchTerm, ESTermParser.getInstance().getFields()) != null) { cnt++; } } } } if (cnt == 0) { setUserInputToNotFound("NO_FIELDS_TO_SEARCH", true); searchText.setEnabled(true); searchBtn.setEnabled(true); return false; } // Check to see if any queries got started. if (queryList.size() == 0) { completionUIHelper(null); } else { return true; } } else { searchTextArg.getToolkit().beep(); } } else { if (startSearchJPA(esrPane, context, searchTerm, ESTermParser.getInstance().getFields()) != null) { return true; } setUserInputToNotFound("NO_FIELDS_TO_SEARCH", true); return true; // if we return false then this error gets overwritten with a different error } } else { //System.err.println("SearchTableConfig service has not been loaded or is empty."); log.error("SearchTableConfig service has been loaded or is empty."); } return false; }
From source file:com.edduarte.protbox.ui.windows.RestoreFileWindow.java
private RestoreFileWindow(final PReg registry) { super();/*from w w w .j av a 2s.co m*/ setLayout(null); final JTextField searchField = new JTextField(); searchField.setLayout(null); searchField.setBounds(2, 2, 301, 26); searchField.setBorder(new LineBorder(Color.lightGray)); searchField.setFont(Constants.FONT); add(searchField); final JLabel noBackupFilesLabel = new JLabel("<html>No backups files were found!<br><br>" + "<font color=\"gray\">If you think there is a problem with the<br>" + "backup system, please create an issue here:<br>" + "<a href=\"#\">https://github.com/com.edduarte/protbox/issues</a></font></html>"); noBackupFilesLabel.setLayout(null); noBackupFilesLabel.setBounds(20, 50, 300, 300); noBackupFilesLabel.setFont(Constants.FONT.deriveFont(14f)); noBackupFilesLabel.addMouseListener((OnMouseClick) e -> { String urlPath = "https://github.com/com.edduarte/protbox/issues"; try { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(new URI(urlPath)); } else { if (SystemUtils.IS_OS_WINDOWS) { Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + urlPath); } else { java.util.List<String> browsers = Lists.newArrayList("firefox", "opera", "safari", "mozilla", "chrome"); for (String browser : browsers) { if (Runtime.getRuntime().exec(new String[] { "which", browser }).waitFor() == 0) { Runtime.getRuntime().exec(new String[] { browser, urlPath }); break; } } } } } catch (Exception ex) { ex.printStackTrace(); } }); DefaultMutableTreeNode rootTreeNode = registry.buildEntryTree(); final JTree tree = new JTree(rootTreeNode); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); if (rootTreeNode.getChildCount() == 0) { searchField.setEnabled(false); add(noBackupFilesLabel); } expandTree(tree); tree.setLayout(null); tree.setRootVisible(false); tree.setEditable(false); tree.setCellRenderer(new SearchableTreeCellRenderer(searchField)); searchField.addKeyListener((OnKeyReleased) e -> { // update and expand tree DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); model.nodeStructureChanged((TreeNode) model.getRoot()); expandTree(tree); }); final JScrollPane scroll = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setBorder(new DropShadowBorder()); scroll.setBorder(new LineBorder(Color.lightGray)); scroll.setBounds(2, 30, 334, 360); add(scroll); JLabel close = new JLabel(new ImageIcon(Constants.getAsset("close.png"))); close.setLayout(null); close.setBounds(312, 7, 18, 18); close.setFont(Constants.FONT); close.setForeground(Color.gray); close.addMouseListener((OnMouseClick) e -> dispose()); add(close); final JLabel permanentDeleteButton = new JLabel(new ImageIcon(Constants.getAsset("permanent.png"))); permanentDeleteButton.setLayout(null); permanentDeleteButton.setBounds(91, 390, 40, 39); permanentDeleteButton.setBackground(Color.black); permanentDeleteButton.setEnabled(false); permanentDeleteButton.addMouseListener((OnMouseClick) e -> { if (permanentDeleteButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (JOptionPane.showConfirmDialog(null, "Are you sure you wish to permanently delete '" + entry.realName() + "'?\nThis file and its " + "backup copies will be deleted immediately. You cannot undo this action.", "Confirm Cancel", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) { registry.permanentDelete(entry); dispose(); RestoreFileWindow.getInstance(registry); } else { setVisible(true); } } }); add(permanentDeleteButton); final JLabel configBackupsButton = new JLabel(new ImageIcon(Constants.getAsset("config.png"))); configBackupsButton.setLayout(null); configBackupsButton.setBounds(134, 390, 40, 39); configBackupsButton.setBackground(Color.black); configBackupsButton.setEnabled(false); configBackupsButton.addMouseListener((OnMouseClick) e -> { if (configBackupsButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (entry instanceof PbxFile) { PbxFile pbxFile = (PbxFile) entry; JFrame frame = new JFrame("Choose backup policy"); Object option = JOptionPane.showInputDialog(frame, "Choose below the backup policy for this file:", "Choose backup", JOptionPane.QUESTION_MESSAGE, null, PbxFile.BackupPolicy.values(), pbxFile.getBackupPolicy()); if (option == null) { setVisible(true); return; } PbxFile.BackupPolicy pickedPolicy = PbxFile.BackupPolicy.valueOf(option.toString()); pbxFile.setBackupPolicy(pickedPolicy); } setVisible(true); } }); add(configBackupsButton); final JLabel restoreBackupButton = new JLabel(new ImageIcon(Constants.getAsset("restore.png"))); restoreBackupButton.setLayout(null); restoreBackupButton.setBounds(3, 390, 85, 39); restoreBackupButton.setBackground(Color.black); restoreBackupButton.setEnabled(false); restoreBackupButton.addMouseListener((OnMouseClick) e -> { if (restoreBackupButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (entry instanceof PbxFolder) { registry.restoreFolderFromEntry((PbxFolder) entry); } else if (entry instanceof PbxFile) { PbxFile pbxFile = (PbxFile) entry; java.util.List<String> snapshots = pbxFile.snapshotsToString(); if (snapshots.isEmpty()) { setVisible(true); return; } JFrame frame = new JFrame("Choose backup"); Object option = JOptionPane.showInputDialog(frame, "Choose below what backup snapshot would you like restore:", "Choose backup", JOptionPane.QUESTION_MESSAGE, null, snapshots.toArray(), snapshots.get(0)); if (option == null) { setVisible(true); return; } int pickedIndex = snapshots.indexOf(option.toString()); registry.restoreFileFromEntry((PbxFile) entry, pickedIndex); } dispose(); } }); add(restoreBackupButton); tree.addMouseListener((OnMouseClick) e -> { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node != null) { PbxEntry entry = (PbxEntry) node.getUserObject(); if ((entry instanceof PbxFolder && entry.areNativeFilesDeleted())) { permanentDeleteButton.setEnabled(true); restoreBackupButton.setEnabled(true); configBackupsButton.setEnabled(false); } else if (entry instanceof PbxFile) { permanentDeleteButton.setEnabled(true); restoreBackupButton.setEnabled(true); configBackupsButton.setEnabled(true); } else { permanentDeleteButton.setEnabled(false); restoreBackupButton.setEnabled(false); configBackupsButton.setEnabled(false); } } }); final JLabel cancel = new JLabel(new ImageIcon(Constants.getAsset("cancel.png"))); cancel.setLayout(null); cancel.setBounds(229, 390, 122, 39); cancel.setBackground(Color.black); cancel.addMouseListener((OnMouseClick) e -> dispose()); add(cancel); addWindowFocusListener(new WindowFocusListener() { private boolean gained = false; @Override public void windowGainedFocus(WindowEvent e) { gained = true; } @Override public void windowLostFocus(WindowEvent e) { if (gained) { dispose(); } } }); setSize(340, 432); setUndecorated(true); getContentPane().setBackground(Color.white); setResizable(false); getRootPane().setBorder(BorderFactory.createLineBorder(new Color(100, 100, 100))); Utils.setComponentLocationOnCenter(this); setVisible(true); }