List of usage examples for javax.swing.event DocumentListener DocumentListener
DocumentListener
From source file:edu.ku.brc.specify.conversion.CustomDBConverterPanel.java
/** * Creates a Document dbConverterListener so the UI is updated when the doc changes * @param textField the text field to be changed *///from ww w . ja v a2s . c om protected void addDocListenerForTextComp(final JTextComponent textField) { textField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { updateUIControls(); } public void insertUpdate(DocumentEvent e) { updateUIControls(); } public void removeUpdate(DocumentEvent e) { updateUIControls(); } }); }
From source file:de.codesourcery.eve.skills.ui.components.impl.AssetListComponent.java
@Override protected JPanel createPanel() { // Merge controls. final JPanel mergeControlsPanel = new JPanel(); mergeControlsPanel.setLayout(new GridBagLayout()); mergeControlsPanel.setBorder(BorderFactory.createTitledBorder("Merging")); int y = 0;/*w w w. j a v a 2s. c o m*/ // merge by type mergeAssetsByType.setSelected(true); mergeAssetsByType.addActionListener(actionListener); mergeControlsPanel.add(mergeAssetsByType, constraints(0, y).anchorWest().end()); mergeControlsPanel.add(new JLabel("Merge assets by type", SwingConstants.LEFT), constraints(1, y++).width(2).end()); // "ignore different packaging" ignorePackaging.setSelected(true); ignorePackaging.addActionListener(actionListener); mergeControlsPanel.add(new JLabel(""), constraints(0, y).anchorWest().end()); mergeControlsPanel.add(ignorePackaging, constraints(1, y).anchorWest().end()); final JLabel label1 = new JLabel("Merge different packaging", SwingConstants.RIGHT); mergeControlsPanel.add(label1, constraints(2, y++).end()); // "ignore different locations" ignoreLocations.setSelected(true); ignoreLocations.addActionListener(actionListener); mergeControlsPanel.add(new JLabel(""), constraints(0, y).anchorWest().end()); mergeControlsPanel.add(ignoreLocations, constraints(1, y).anchorWest().end()); final JLabel label2 = new JLabel("Merge different locations", SwingConstants.RIGHT); mergeControlsPanel.add(label2, constraints(2, y++).end()); linkComponentEnabledStates(mergeAssetsByType, ignoreLocations, ignorePackaging, label1, label2); /* * Filter controls. */ final JPanel filterControlsPanel = new JPanel(); filterControlsPanel.setLayout(new GridBagLayout()); filterControlsPanel.setBorder(BorderFactory.createTitledBorder("Filters")); y = 0; // filter by location combo box filterByLocation.addActionListener(actionListener); locationComboBox.addActionListener(actionListener); filterByLocation.setSelected(false); linkComponentEnabledStates(filterByLocation, locationComboBox); locationComboBox.setRenderer(new LocationRenderer()); locationComboBox.setPreferredSize(new Dimension(150, 20)); locationComboBox.setModel(locationModel); filterControlsPanel.add(filterByLocation, constraints(0, y).end()); filterControlsPanel.add(locationComboBox, constraints(1, y++).end()); // filter by type combo box filterByType.addActionListener(actionListener); typeComboBox.addActionListener(actionListener); filterByType.setSelected(false); linkComponentEnabledStates(filterByType, typeComboBox); typeComboBox.setPreferredSize(new Dimension(150, 20)); typeComboBox.setModel(typeModel); filterControlsPanel.add(filterByType, constraints(0, y).end()); filterControlsPanel.add(typeComboBox, constraints(1, y++).end()); // filter by item category combobox filterByCategory.addActionListener(actionListener); categoryComboBox.addActionListener(actionListener); categoryComboBox.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); setText(getDisplayName((InventoryCategory) value)); setEnabled(categoryComboBox.isEnabled()); return this; } }); filterByCategory.setSelected(false); linkComponentEnabledStates(filterByCategory, categoryComboBox); categoryComboBox.setPreferredSize(new Dimension(150, 20)); categoryComboBox.setModel(categoryModel); filterControlsPanel.add(filterByCategory, constraints(0, y).end()); filterControlsPanel.add(categoryComboBox, constraints(1, y++).end()); // filter by item group combobox filterByGroup.addActionListener(actionListener); groupComboBox.addActionListener(actionListener); filterByGroup.setSelected(false); linkComponentEnabledStates(filterByGroup, groupComboBox); groupComboBox.setPreferredSize(new Dimension(150, 20)); groupComboBox.setModel(groupModel); filterControlsPanel.add(filterByGroup, constraints(0, y).end()); filterControlsPanel.add(groupComboBox, constraints(1, y++).end()); /* * Table panel. */ table = new JTable() { @Override public TableCellRenderer getCellRenderer(int row, int column) { // subclassing hack is needed because table // returns different renderes depending on column type final TableCellRenderer result = super.getCellRenderer(row, column); return new TableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component comp = result.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); final int modelRow = table.convertRowIndexToModel(row); final Asset asset = model.getRow(modelRow); final StringBuilder label = new StringBuilder("<HTML><BODY>"); label.append(asset.getItemId() + " - flags: " + asset.getFlags() + "<BR>"); if (asset.hasMultipleLocations()) { label.append("<BR>"); for (ILocation loc : asset.getLocations()) { label.append(loc.getDisplayName()).append("<BR>"); } } label.append("</BODY></HTML>"); ((JComponent) comp).setToolTipText(label.toString()); return comp; } }; } }; model.setViewFilter(this.viewFilter); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateSelectedVolume(); } }); FixedBooleanTableCellRenderer.attach(table); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setModel(model); table.setBorder(BorderFactory.createLineBorder(Color.BLACK)); table.setRowSorter(model.getRowSorter()); popupMenuBuilder.addItem("Refine...", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final List<Asset> assets = getSelectedAssets(); if (assets == null || assets.isEmpty()) { return; } final ICharacter c = selectionProvider.getSelectedItem(); final RefiningComponent comp = new RefiningComponent(c); comp.setItemsToRefine(assets); ComponentWrapper.wrapComponent("Refining", comp).setVisible(true); } @Override public boolean isEnabled() { return table.getSelectedRow() != -1; } }); popupMenuBuilder.addItem("Copy selection to clipboard (text)", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final List<Asset> assets = getSelectedAssets(); if (assets == null || assets.isEmpty()) { return; } new PlainTextTransferable(toPlainText(assets)).putOnClipboard(); } @Override public boolean isEnabled() { return table.getSelectedRow() != -1; } }); popupMenuBuilder.addItem("Copy selection to clipboard (CSV)", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final List<Asset> assets = getSelectedAssets(); if (assets == null || assets.isEmpty()) { return; } final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new PlainTextTransferable(toCsv(assets)), null); } @Override public boolean isEnabled() { return table.getSelectedRow() != -1; } }); table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.popupMenuBuilder.attach(table); final JScrollPane scrollPane = new JScrollPane(table); /* * Name filter */ final JPanel nameFilterPanel = new JPanel(); nameFilterPanel.setLayout(new GridBagLayout()); nameFilterPanel.setBorder(BorderFactory.createTitledBorder("Filter by name")); nameFilterPanel.setPreferredSize(new Dimension(150, 70)); nameFilter.setColumns(10); nameFilter.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { model.viewFilterChanged(); } @Override public void insertUpdate(DocumentEvent e) { model.viewFilterChanged(); } @Override public void removeUpdate(DocumentEvent e) { model.viewFilterChanged(); } }); nameFilterPanel.add(nameFilter, constraints(0, 0).resizeHorizontally().end()); final JButton clearButton = new JButton("Clear"); clearButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { nameFilter.setText(null); } }); nameFilterPanel.add(clearButton, constraints(1, 0).noResizing().end()); // Selected volume final JPanel selectedVolumePanel = this.selectedVolume.getPanel(); // add control panels to result panel final JPanel topPanel = new JPanel(); topPanel.setLayout(new GridBagLayout()); topPanel.add(mergeControlsPanel, constraints(0, 0).height(2).weightX(0).anchorWest().end()); topPanel.add(filterControlsPanel, constraints(1, 0).height(2).anchorWest().weightX(0).end()); topPanel.add(nameFilterPanel, constraints(2, 0).height(1).anchorWest().useRemainingWidth().end()); topPanel.add(selectedVolumePanel, constraints(2, 1).height(1).anchorWest().useRemainingWidth().end()); final JSplitPane splitPane = new ImprovedSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, scrollPane); splitPane.setDividerLocation(0.3d); final JPanel content = new JPanel(); content.setLayout(new GridBagLayout()); content.add(splitPane, constraints().resizeBoth().useRemainingSpace().end()); return content; }
From source file:ca.uhn.hl7v2.testpanel.ui.editor.Hl7V2MessageEditorPanel.java
private void initLocal() { myDocumentListener = new DocumentListener() { public void changedUpdate(DocumentEvent theE) { ourLog.info("Document change: " + theE); handleChange(theE);/*from w w w .j av a2s . c o m*/ } private void handleChange(DocumentEvent theE) { myDontRespondToSourceMessageChanges = true; try { long start = System.currentTimeMillis(); String newSource = myMessageEditor.getText(); int changeStart = theE.getOffset(); int changeEnd = changeStart + theE.getLength(); myMessage.updateSourceMessage(newSource, changeStart, changeEnd); ourLog.info("Handled document update in {} ms", System.currentTimeMillis() - start); } finally { myDontRespondToSourceMessageChanges = false; } } public void insertUpdate(DocumentEvent theE) { ourLog.info("Document insert: " + theE); handleChange(theE); } public void removeUpdate(DocumentEvent theE) { ourLog.info("Document removed: " + theE); handleChange(theE); } }; myMessageEditor.getDocument().addDocumentListener(myDocumentListener); myMessageEditor.addCaretListener(new CaretListener() { public void caretUpdate(final CaretEvent theE) { removeMostHighlights(); if (!myDisableCaretUpdateHandling) { myController.invokeInBackground(new Runnable() { @Override public void run() { myMessage.setHighlitedPathBasedOnRange(new Range(theE.getDot(), theE.getMark())); myTreePanel.repaint(); } }); } } }); updateOutboundConnectionsBox(); myOutboundConnectionsListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent theEvt) { updateOutboundConnectionsBox(); } }; myController.getOutboundConnectionList().addPropertyChangeListener(OutboundConnectionList.PROP_LIST, myOutboundConnectionsListener); myOutboundInterfaceCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent theE) { if (!myOutboundInterfaceComboModelIsUpdating) { updateSendButton(); } } }); JMenuItem copyMenuItem = new JMenuItem("Copy to Clipboard"); copyMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent theE) { String selection = myTerserPathTextField.getText(); StringSelection data = new StringSelection(selection); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(data, data); } }); myTerserPathPopupMenu.add(copyMenuItem); myProfilesListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent theEvt) { myProfileComboboxModel.update(); registerProfileNamesListeners(); } }; myController.getProfileFileList().addPropertyChangeListener(ProfileFileList.PROP_FILES, myProfilesListener); registerProfileNamesListeners(); myProfilesNamesListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent theEvt) { myProfileComboboxModel.update(); } }; }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
public static JPasswordField createPasswordField(DocumentListener... docListeners) { final JPasswordField field = new JPasswordField(); final Border oldBorder = field.getBorder(); if (docListeners != null) { for (DocumentListener docListener : docListeners) { field.getDocument().addDocumentListener(docListener); field.getDocument().putProperty("owner", field); }/*from ww w . j ava2 s . c om*/ } final InputVerifier verifier = new InputVerifier() { @Override public boolean verify(final JComponent input) { final JPasswordField field = (JPasswordField) input; char[] txt = field.getPassword(); if (txt.length == 0) { // Run in EDT to avoid deadlock in case this gets called // from not swing thread Util.runInEDT(new Runnable() { @Override public void run() { field.setToolTipText(UILabels.STL50084_CANT_BE_BLANK.getDescription()); input.setBackground(UIConstants.INTEL_LIGHT_RED); input.setBorder(BorderFactory.createLineBorder(UIConstants.INTEL_RED, 2)); // show tooltip immediately ToolTipManager.sharedInstance() .mouseMoved(new MouseEvent(field, 0, 0, 0, 0, 0, 0, false)); } }); return false; } else { Util.runInEDT(new Runnable() { @Override public void run() { input.setBackground(UIConstants.INTEL_WHITE); input.setBorder(oldBorder); } }); return true; } } }; DocumentListener dynamicChecker = new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { verifier.verify(field); } @Override public void removeUpdate(DocumentEvent e) { verifier.verify(field); } @Override public void changedUpdate(DocumentEvent e) { verifier.verify(field); } }; field.getDocument().addDocumentListener(dynamicChecker); // Add the input verifier field.setInputVerifier(verifier); return field; }
From source file:ca.phon.ipamap.IpaMap.java
private IpaMapSearchField createSearchField() { final IpaMapSearchField searchField = new IpaMapSearchField(); searchField.setPrompt("Search Glyphs"); searchField.setFont(getFont().deriveFont(12.0f)); searchField.getDocument().addDocumentListener(new DocumentListener() { @Override/*from www . j av a 2 s . c o m*/ public void removeUpdate(DocumentEvent arg0) { if (searchField.getState() == FieldState.INPUT) updateSearchPanel(searchField.getSearchType(), searchField.getText()); else updateSearchPanel(searchField.getSearchType(), ""); } @Override public void insertUpdate(DocumentEvent arg0) { if (searchField.getState() == FieldState.INPUT) updateSearchPanel(searchField.getSearchType(), searchField.getText()); else updateSearchPanel(searchField.getSearchType(), ""); } @Override public void changedUpdate(DocumentEvent arg0) { } }); searchField.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent arg0) { if (arg0.getPropertyName().equals(IpaMapSearchField.SEARCH_TYPE_PROP)) { if (searchField.getText().length() > 0) { updateSearchPanel(searchField.getSearchType(), searchField.getText()); } } } }); return searchField; }
From source file:com.mirth.connect.connectors.http.HttpListener.java
private void initComponentsManual() { staticResourcesTable.setModel(new RefreshTableModel(StaticResourcesColumn.getNames(), 0) { @Override//from w w w .j a va 2 s. c o m public boolean isCellEditable(int rowIndex, int columnIndex) { return true; } }); staticResourcesTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); staticResourcesTable.setRowHeight(UIConstants.ROW_HEIGHT); staticResourcesTable.setFocusable(true); staticResourcesTable.setSortable(false); staticResourcesTable.setOpaque(true); staticResourcesTable.setDragEnabled(false); staticResourcesTable.getTableHeader().setReorderingAllowed(false); staticResourcesTable.setShowGrid(true, true); staticResourcesTable.setAutoCreateColumnsFromModel(false); staticResourcesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); staticResourcesTable.setRowSelectionAllowed(true); staticResourcesTable.setCustomEditorControls(true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { staticResourcesTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } class ContextPathCellEditor extends TextFieldCellEditor { public ContextPathCellEditor() { getTextField().setDocument(new MirthFieldConstraints("^\\S*$")); } @Override protected boolean valueChanged(String value) { if (StringUtils.isEmpty(value) || value.equals("/")) { return false; } if (value.equals(getOriginalValue())) { return false; } for (int i = 0; i < staticResourcesTable.getRowCount(); i++) { if (value.equals(fixContentPath((String) staticResourcesTable.getValueAt(i, StaticResourcesColumn.CONTEXT_PATH.getIndex())))) { return false; } } parent.setSaveEnabled(true); return true; } @Override public Object getCellEditorValue() { String value = fixContentPath((String) super.getCellEditorValue()); String baseContextPath = getBaseContextPath(); if (value.equals(baseContextPath)) { return null; } else { return fixContentPath(StringUtils.removeStartIgnoreCase(value, baseContextPath + "/")); } } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { String resourceContextPath = fixContentPath((String) value); setOriginalValue(resourceContextPath); getTextField().setText(getBaseContextPath() + resourceContextPath); return getTextField(); } } ; staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTEXT_PATH.getIndex()) .setCellEditor(new ContextPathCellEditor()); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTEXT_PATH.getIndex()) .setCellRenderer(new DefaultTableCellRenderer() { @Override protected void setValue(Object value) { super.setValue(getBaseContextPath() + fixContentPath((String) value)); } }); class ResourceTypeCellEditor extends MirthComboBoxTableCellEditor implements ActionListener { private Object originalValue; public ResourceTypeCellEditor(JTable table, Object[] items, int clickCount, boolean focusable) { super(table, items, clickCount, focusable, null); for (ActionListener actionListener : comboBox.getActionListeners()) { comboBox.removeActionListener(actionListener); } comboBox.addActionListener(this); } @Override public boolean stopCellEditing() { if (ObjectUtils.equals(getCellEditorValue(), originalValue)) { cancelCellEditing(); } else { parent.setSaveEnabled(true); } return super.stopCellEditing(); } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { originalValue = value; return super.getTableCellEditorComponent(table, value, isSelected, row, column); } @Override public void actionPerformed(ActionEvent evt) { ((AbstractTableModel) staticResourcesTable.getModel()).fireTableCellUpdated( staticResourcesTable.getSelectedRow(), StaticResourcesColumn.VALUE.getIndex()); stopCellEditing(); fireEditingStopped(); } } String[] resourceTypes = ResourceType.stringValues(); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()).setMinWidth(100); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()).setMaxWidth(100); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()) .setCellEditor(new ResourceTypeCellEditor(staticResourcesTable, resourceTypes, 1, false)); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()) .setCellRenderer(new MirthComboBoxTableCellRenderer(resourceTypes)); class ValueCellEditor extends AbstractCellEditor implements TableCellEditor { private JPanel panel; private JLabel label; private JTextField textField; private String text; private String originalValue; public ValueCellEditor() { panel = new JPanel(new MigLayout("insets 0 1 0 0, novisualpadding, hidemode 3")); panel.setBackground(UIConstants.BACKGROUND_COLOR); label = new JLabel(); label.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent evt) { new ValueDialog(); stopCellEditing(); } }); panel.add(label, "grow, pushx, h 19!"); textField = new JTextField(); panel.add(textField, "grow, pushx, h 19!"); } @Override public boolean isCellEditable(EventObject evt) { if (evt == null) { return false; } if (evt instanceof MouseEvent) { return ((MouseEvent) evt).getClickCount() >= 2; } return true; } @Override public Object getCellEditorValue() { if (label.isVisible()) { return text; } else { return textField.getText(); } } @Override public boolean stopCellEditing() { if (ObjectUtils.equals(getCellEditorValue(), originalValue)) { cancelCellEditing(); } else { parent.setSaveEnabled(true); } return super.stopCellEditing(); } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { boolean custom = table.getValueAt(row, StaticResourcesColumn.RESOURCE_TYPE.getIndex()) .equals(ResourceType.CUSTOM.toString()); label.setVisible(custom); textField.setVisible(!custom); panel.setBackground(table.getSelectionBackground()); label.setBackground(panel.getBackground()); label.setMaximumSize(new Dimension(table.getColumnModel().getColumn(column).getWidth(), 19)); String text = (String) value; this.text = text; originalValue = text; label.setText(text); textField.setText(text); return panel; } class ValueDialog extends MirthDialog { public ValueDialog() { super(parent, true); setTitle("Custom Value"); setPreferredSize(new Dimension(600, 500)); setLayout(new MigLayout("insets 12, novisualpadding, hidemode 3, fill", "", "[grow]7[]")); setBackground(UIConstants.BACKGROUND_COLOR); getContentPane().setBackground(getBackground()); final MirthSyntaxTextArea textArea = new MirthSyntaxTextArea(); textArea.setSaveEnabled(false); textArea.setText(text); textArea.setBorder(BorderFactory.createEtchedBorder()); add(textArea, "grow"); add(new JSeparator(), "newline, grow"); JPanel buttonPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3")); buttonPanel.setBackground(getBackground()); JButton openFileButton = new JButton("Open File..."); openFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { String content = parent.browseForFileString(null); if (content != null) { textArea.setText(content); } } }); buttonPanel.add(openFileButton); JButton okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { text = textArea.getText(); label.setText(text); textField.setText(text); staticResourcesTable.getModel().setValueAt(text, staticResourcesTable.getSelectedRow(), StaticResourcesColumn.VALUE.getIndex()); parent.setSaveEnabled(true); dispose(); } }); buttonPanel.add(okButton); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { dispose(); } }); buttonPanel.add(cancelButton); add(buttonPanel, "newline, right"); pack(); setLocationRelativeTo(parent); setVisible(true); } } } ; staticResourcesTable.getColumnExt(StaticResourcesColumn.VALUE.getIndex()) .setCellEditor(new ValueCellEditor()); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex()).setMinWidth(100); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex()).setMaxWidth(150); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex()) .setCellEditor(new TextFieldCellEditor() { @Override protected boolean valueChanged(String value) { if (value.equals(getOriginalValue())) { return false; } parent.setSaveEnabled(true); return true; } }); staticResourcesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (getSelectedRow(staticResourcesTable) != -1) { staticResourcesLastIndex = getSelectedRow(staticResourcesTable); staticResourcesDeleteButton.setEnabled(true); } else { staticResourcesDeleteButton.setEnabled(false); } } }); contextPathField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent evt) { changedUpdate(evt); } @Override public void removeUpdate(DocumentEvent evt) { changedUpdate(evt); } @Override public void changedUpdate(DocumentEvent evt) { ((AbstractTableModel) staticResourcesTable.getModel()).fireTableDataChanged(); } }); staticResourcesDeleteButton.setEnabled(false); }
From source file:de.rub.nds.burp.espresso.gui.attacker.saml.UIDTDAttack.java
private void initEditorsAndListener() { firstEditor = new JTextArea(); firstEditor.setEditable(false);/*from www. j a v a2 s. c o m*/ firstEditor.getDocument().addDocumentListener(new DocumentListener() { private void notify(DocumentEvent de) { if (autoModifyCheckbox.isSelected()) { notifyAllTabs(new SamlCodeEvent(this, firstEditor.getText())); Logging.getInstance().log(getClass(), "Notify all tabs.", Logging.DEBUG); } } @Override public void insertUpdate(DocumentEvent de) { notify(de); } @Override public void removeUpdate(DocumentEvent de) { notify(de); } @Override public void changedUpdate(DocumentEvent de) { notify(de); } }); secondEditor = new JTextArea(); secondEditor.setEditable(false); firstScrollPane = new JScrollPane(firstEditor, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); firstScrollPane.setPreferredSize(new Dimension(100, 280)); secondScrollPane = new JScrollPane(secondEditor, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); secondScrollPane.setPreferredSize(new Dimension(100, 280)); // Set listener TextfieldListener textfieldListener = new TextfieldListener(); attackeListenerTextField.getDocument().addDocumentListener(textfieldListener); helperURLTextField.getDocument().addDocumentListener(textfieldListener); targetFileTextField.getDocument().addDocumentListener(textfieldListener); SysPubRadioButtonGroupListener radioButtonGroupListener = new SysPubRadioButtonGroupListener(); publicRadioButton.addActionListener(radioButtonGroupListener); systemRadioButton.addActionListener(radioButtonGroupListener); EncodingRadioButtonGroupListener encodingRadioButtonGroupListener = new EncodingRadioButtonGroupListener(); utf7RadioButton.addActionListener(encodingRadioButtonGroupListener); utf7RadioButton.setActionCommand(EncodingType.UTF_7.getEncoding()); utf8RadioButton.addActionListener(encodingRadioButtonGroupListener); utf8RadioButton.setActionCommand(EncodingType.UTF_8.getEncoding()); utf16RadioButton.addActionListener(encodingRadioButtonGroupListener); utf16RadioButton.setActionCommand(EncodingType.UTF_16.getEncoding()); // Set dtd vectors sorted by name dtdComboBox.setModel(new DefaultComboBoxModel(dtdNames.toArray())); dtdComboBox.setRenderer(new BasicComboBoxRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JComponent comp = (JComponent) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (-1 < index && null != value && null != dtdDescriptions) { descriptionTextArea.setText(dtdDescriptions.get(index)); } return comp; } }); dtdComboBox.setSelectedIndex(0); }
From source file:src.gui.ItTabbedPane.java
public void openPDDLTab(Element diagram, String id, String title, Element project, Element projectHeader, File file) {//from ww w . j av a2 s . c om String nodeType = diagram.getName(); // Checks whether the diagram is already open String xpath = "openTab[@language='PDDL' and @projectID='" + projectHeader.getAttributeValue("id") + "' and @diagramID='" + id + "' and type='" + nodeType + "']"; //Checks if it is already opened Element openingDiagram = null; try { XPath path = new JDOMXPath(xpath); openingDiagram = (Element) path.selectSingleNode(openTabs); } catch (JaxenException e2) { e2.printStackTrace(); } if (openingDiagram != null) { // select the tab if it is already open setSelectedIndex(openingDiagram.getParent().indexOf(openingDiagram)); } else { //New Tab Document newDoc = null; try { newDoc = XMLUtilities.readFromFile("resources/settings/commonData.xml"); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Element openTab = ((Element) newDoc.getRootElement().getChild("internalUse").getChild("openTab") .clone()); Icon icon = null; JRootPane panel = null; ItToolBar toolBar = new ItToolBar(diagram.getName(), "PDDL"); toolBar.setName(title); ItHilightedDocument pddlDocument = new ItHilightedDocument(); pddlDocument.setHighlightStyle(ItHilightedDocument.PDDL_STYLE); JTextPane pddlTextPane = new JTextPane(pddlDocument); pddlTextPane.setFont(new Font("Courier", 0, 12)); pddlDocument.setTextPane(pddlTextPane); pddlDocument.setData(diagram); pddlDocument.addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent de) { //throw new UnsupportedOperationException("Not supported yet."); //System.out.println("insert"); storechange(de); } public void removeUpdate(DocumentEvent de) { //throw new UnsupportedOperationException("Not supported yet."); //System.out.println("remove"); storechange(de); } public void changedUpdate(DocumentEvent de) { //throw new UnsupportedOperationException("Not supported yet."); //System.out.println("changed"); } public void storechange(DocumentEvent de) { //When a document is open it is also calling this method ItHilightedDocument document = (ItHilightedDocument) de.getDocument(); String text = document.getTextPane().getText(); Element diagram = document.getData(); Element content = diagram.getChild("content"); if (content != null) { content.setText(text); } else { content = new Element("content"); content.setText(text); diagram.addContent(content); } } }); //ROSI pddlDocument UndoManager undo = new UndoManager(); toolBar.setUndoManager(undo); pddlDocument.addUndoableEditListener(new MyUndoableEditListener(undo)); toolBar.setTextPane(pddlTextPane); JScrollPane pddlScrollPane = new JScrollPane(pddlTextPane); panel = new JRootPane(); panel.setLayout(new BorderLayout()); panel.add(toolBar, BorderLayout.NORTH); panel.add(pddlScrollPane, BorderLayout.CENTER); icon = new ImageIcon("resources/images/" + diagram.getName() + ".png"); String fileContentText = ""; fileContentText = getContentsAsString(file); pddlTextPane.setText(fileContentText); //Set Tab properties openTab.setAttribute("language", "PDDL"); openTab.setAttribute("diagramID", id); openTab.setAttribute("projectID", projectHeader.getAttributeValue("id")); openTab.getChild("type").setText(diagram.getName()); //if (diagram.getName().equals("pddlproblem")){ // // planningProblems domains // openTab.getChild("domain").setText(diagram.getParentElement().getParentElement().getAttributeValue("id")); //} if (icon != null && panel != null) { // add the tab openTabs.addContent(openTab); addTab(title, icon, panel); if (getTabCount() > 1) { setSelectedIndex(getTabCount() - 1); } } } }
From source file:SuitaDetails.java
public DefPanel(String descriptions, String button, String id, int width, final int index, SuitaDetails container) {/*from w ww . ja va 2 s . co m*/ this.descriptions = descriptions; this.id = id; reference = this; this.container = container; this.index = index; setBackground(new Color(255, 255, 255)); setBorder(BorderFactory.createEmptyBorder(2, 20, 2, 20)); setMaximumSize(new Dimension(32767, 30)); setMinimumSize(new Dimension(100, 30)); setPreferredSize(new Dimension(300, 30)); setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); description = new JLabel(descriptions); description.setPreferredSize(new Dimension(width, 20)); description.setMinimumSize(new Dimension(width, 20)); description.setMaximumSize(new Dimension(width, 20)); add(description); filedsGap = new JPanel(); filedsGap.setBackground(new Color(255, 255, 255)); filedsGap.setMaximumSize(new Dimension(20, 20)); filedsGap.setMinimumSize(new Dimension(20, 20)); filedsGap.setPreferredSize(new Dimension(20, 20)); GroupLayout filedsGapLayout = new GroupLayout(filedsGap); filedsGap.setLayout(filedsGapLayout); filedsGapLayout.setHorizontalGroup( filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE)); filedsGapLayout.setVerticalGroup( filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE)); add(filedsGap); userDefinition = new JTextField(); doclistener = new DocumentListener() { public void changedUpdate(DocumentEvent e) { setParentField(userDefinition.getText(), false); } public void removeUpdate(DocumentEvent e) { setParentField(userDefinition.getText(), false); } public void insertUpdate(DocumentEvent e) { setParentField(userDefinition.getText(), false); } }; userDefinition.getDocument().addDocumentListener(doclistener); userDefinition.setText(""); userDefinition.setMaximumSize(new Dimension(300, 100)); userDefinition.setMinimumSize(new Dimension(50, 20)); userDefinition.setPreferredSize(new Dimension(100, 20)); add(userDefinition); filedsGap = new JPanel(); filedsGap.setBackground(new Color(255, 255, 255)); filedsGap.setMaximumSize(new Dimension(20, 20)); filedsGap.setMinimumSize(new Dimension(20, 20)); filedsGap.setPreferredSize(new Dimension(20, 20)); filedsGapLayout = new GroupLayout(filedsGap); filedsGap.setLayout(filedsGapLayout); filedsGapLayout.setHorizontalGroup( filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE)); filedsGapLayout.setVerticalGroup( filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE)); add(filedsGap); if (button.equals("UserSelect")) { final JButton database = new JButton("Database"); database.setMaximumSize(new Dimension(100, 20)); database.setMinimumSize(new Dimension(50, 20)); database.setPreferredSize(new Dimension(80, 20)); add(database); database.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { DatabaseFrame frame = new DatabaseFrame(reference); frame.executeQuery(); frame.setLocation((int) database.getLocationOnScreen().getX() - 100, (int) database.getLocationOnScreen().getY()); frame.setVisible(true); } }); } else if (button.equals("UserScript")) { JButton script = new JButton("Script"); script.setMaximumSize(new Dimension(100, 20)); script.setMinimumSize(new Dimension(50, 20)); script.setPreferredSize(new Dimension(80, 20)); add(script); script.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { Container c; if (RunnerRepository.container != null) c = RunnerRepository.container.getParent(); else c = RunnerRepository.window; try { // String passwd = RunnerRepository.getRPCClient().execute("sendFile", new Object[]{"/etc/passwd"}).toString(); // new MySftpBrowser(RunnerRepository.host,RunnerRepository.user,RunnerRepository.password,userDefinition,c,passwd); new MySftpBrowser(RunnerRepository.host, RunnerRepository.user, RunnerRepository.password, userDefinition, c, false); } catch (Exception e) { System.out.println("There was a problem in opening sftp browser!"); e.printStackTrace(); } } }); filedsGap = new JPanel(); filedsGap.setBackground(new Color(255, 255, 255)); filedsGap.setMaximumSize(new Dimension(10, 10)); filedsGap.setMinimumSize(new Dimension(10, 10)); filedsGap.setPreferredSize(new Dimension(10, 10)); filedsGapLayout = new GroupLayout(filedsGap); filedsGap.setLayout(filedsGapLayout); filedsGapLayout.setHorizontalGroup(filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGap(0, 20, Short.MAX_VALUE)); filedsGapLayout.setVerticalGroup(filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGap(0, 20, Short.MAX_VALUE)); filedsGap.setLayout(filedsGapLayout); add(filedsGap); final JButton value = new JButton("Value"); value.setMaximumSize(new Dimension(100, 20)); value.setMinimumSize(new Dimension(50, 20)); value.setPreferredSize(new Dimension(80, 20)); add(value); value.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String script = userDefinition.getText(); if (script != null && !script.equals("")) { try { String result = RunnerRepository.getRPCClient().execute("runUserScript", new Object[] { script }) + ""; JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setLocation(value.getLocationOnScreen()); JLabel l = new JLabel("Script result: " + result); f.getContentPane().add(l, BorderLayout.CENTER); f.pack(); f.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } } }); } else if (button.equals("UserText")) { JPanel database = new JPanel(); database.setBackground(Color.WHITE); database.setMaximumSize(new Dimension(100, 20)); database.setMinimumSize(new Dimension(50, 20)); database.setPreferredSize(new Dimension(80, 20)); add(database); } }
From source file:it.txt.access.capability.revocation.wizard.panel.PanelRevocationData.java
private void checkEditableTextBox(final javax.swing.JTextField textBox) { textBox.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { sorroundIssuerDocumentChange(e); }/* w w w .j a v a 2 s .c om*/ public void removeUpdate(DocumentEvent e) { sorroundIssuerDocumentChange(e); } public void changedUpdate(DocumentEvent e) { sorroundIssuerDocumentChange(e); } private void sorroundIssuerDocumentChange(DocumentEvent e) { if (textBox.getText().equals("")) { textBox.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); } else { textBox.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0))); } } }); }