/** * A change in the text fields. * * @param e the document event. */ private void documentChanged(DocumentEvent e) { if (e.getDocument().equals(fileCountField.getDocument())) { // set file count only if its un integer try { int newFileCount = Integer.valueOf(fileCountField.getText()); fileCountField.setForeground(Color.black); LoggingUtilsActivator.getPacketLoggingService() .getConfiguration() .setLogfileCount(newFileCount); } catch (Throwable t) { fileCountField.setForeground(Color.red); } } else if (e.getDocument().equals(fileSizeField.getDocument())) { // set file size only if its un integer try { int newFileSize = Integer.valueOf(fileSizeField.getText()); fileSizeField.setForeground(Color.black); LoggingUtilsActivator.getPacketLoggingService() .getConfiguration() .setLimit(newFileSize * 1000); } catch (Throwable t) { fileSizeField.setForeground(Color.red); } } }
@Override public JComponent createUI( DescriptionType inputOrOutput, Map<URI, Object> dataMap, Orientation orientation) { // Create the main panel JComponent component = new JPanel(new MigLayout("fill")); boolean isOptional = false; if (inputOrOutput instanceof InputDescriptionType) { isOptional = ((InputDescriptionType) inputOrOutput).getMinOccurs().equals(new BigInteger("0")); } // Display the SourceCA into a JTextField JTextField jtf = new JTextField(); jtf.setToolTipText(inputOrOutput.getAbstract().get(0).getValue()); // "Save" the CA inside the JTextField jtf.getDocument().putProperty(DATA_MAP_PROPERTY, dataMap); URI uri = URI.create(inputOrOutput.getIdentifier().getValue()); jtf.getDocument().putProperty(URI_PROPERTY, uri); // add the listener for the text changes in the JTextField jtf.getDocument() .addDocumentListener( EventHandler.create(DocumentListener.class, this, "saveDocumentText", "document")); if (isOptional) { if (dataMap.containsKey(uri)) { jtf.setText(dataMap.get(uri).toString()); } } GeometryData geometryData = null; if (inputOrOutput instanceof InputDescriptionType) { geometryData = (GeometryData) ((InputDescriptionType) inputOrOutput).getDataDescription().getValue(); } // If the DescriptionType is an output, there is nothing to show, so exit if (geometryData == null) { return null; } component.add(jtf, "growx"); if (orientation.equals(Orientation.VERTICAL)) { JPanel buttonPanel = new JPanel(new MigLayout()); // Create the button Browse JButton pasteButton = new JButton(ToolBoxIcon.getIcon(ToolBoxIcon.PASTE)); // "Save" the sourceCA and the JTextField in the button pasteButton.putClientProperty(TEXT_FIELD_PROPERTY, jtf); pasteButton.setBorderPainted(false); pasteButton.setContentAreaFilled(false); pasteButton.setMargin(new Insets(0, 0, 0, 0)); // Add the listener for the click on the button pasteButton.addActionListener(EventHandler.create(ActionListener.class, this, "onPaste", "")); buttonPanel.add(pasteButton); component.add(buttonPanel, "dock east"); } return component; }
/* Post: sets up all the options visually */ public Options() { valuesArray = new ArrayList<Integer>(); populateRandomArray(); // size of the array enterSize = new JLabel("Array size:"); arraySizeEntry = new JTextField("", 3); arraySizeEntry.addActionListener(this); arraySizeEntry.getDocument().addDocumentListener(new DocListener()); // algorithm on top topAlgo = new JLabel("Top:"); String[] topAlgos = {"Selection Sort", "Insertion Sort", "Bubble Sort", "Merge Sort"}; chooseTopAlgo = new JComboBox(topAlgos); chooseTopAlgo.addActionListener(this); // algorithm on bottom bottomAlgo = new JLabel("Bottom:"); String[] bottomAlgos = {"Selection Sort", "Insertion Sort", "Bubble Sort", "Merge Sort"}; chooseBottomAlgo = new JComboBox(bottomAlgos); chooseBottomAlgo.addActionListener(this); // average case or worst case caseLabel = new JLabel("Choose case:"); String[] cases = {"Average Case", "Worst Case"}; chooseCase = new JComboBox(cases); chooseCase.addActionListener(this); // delay of comparisons in the visualizer enterSpeed = new JLabel("Delay:"); speedEntry = new JTextField("10", 2); speedEntry.addActionListener(this); speedEntry.getDocument().addDocumentListener(this); // run button (runs the visualizer) run = new JButton("Run"); run.addActionListener(this); // adding everything to the panel add(enterSize); add(arraySizeEntry); add(topAlgo); add(chooseTopAlgo); add(bottomAlgo); add(chooseBottomAlgo); add(caseLabel); add(chooseCase); add(enterSpeed); add(speedEntry); add(run); }
private void init(final EncodeTableModel model) { setModal(true); setTitle("Encode Production Data"); table.setAutoCreateRowSorter(true); table.setModel(model); table.setRowSorter(model.getSorter()); try { rowCountLabel.setText(numberFormatter.valueToString(table.getRowCount()) + " rows"); } catch (ParseException e) { } table.setRowSelectionAllowed(false); table.setColumnSelectionAllowed(false); filterTextField .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) { updateFilter(); } public void insertUpdate(DocumentEvent e) { updateFilter(); } public void removeUpdate(DocumentEvent e) { updateFilter(); } }); }
private JTextField createColorField(boolean hex) { final NumberDocument doc = new NumberDocument(hex); int lafFix = UIUtil.isUnderWindowsLookAndFeel() || UIUtil.isUnderDarcula() ? 1 : 0; UIManager.LookAndFeelInfo info = LafManager.getInstance().getCurrentLookAndFeel(); if (info != null && (info.getName().startsWith("IDEA") || info.getName().equals("Windows Classic"))) lafFix = 1; final JTextField field; if (SystemInfo.isMac && UIUtil.isUnderIntelliJLaF()) { field = new JTextField(""); field.setDocument(doc); field.setPreferredSize(new Dimension(hex ? 60 : 40, 26)); } else { field = new JTextField(doc, "", (hex ? 5 : 2) + lafFix); field.setSize(50, -1); } doc.setSource(field); field.getDocument().addDocumentListener(this); field.addFocusListener( new FocusAdapter() { @Override public void focusGained(final FocusEvent e) { field.selectAll(); } }); return field; }
public NodeSelectionDialog(Frame owner, NodeLibrary library, NodeLibraryManager manager) { super(owner, "New Node", true); getRootPane().putClientProperty("Window.style", "small"); JPanel panel = new JPanel(new BorderLayout()); this.library = library; this.manager = manager; filteredNodeListModel = new FilteredNodeListModel(library, manager); searchField = new JTextField(); searchField.putClientProperty("JTextField.variant", "search"); EscapeListener escapeListener = new EscapeListener(); searchField.addKeyListener(escapeListener); ArrowKeysListener arrowKeysListener = new ArrowKeysListener(); searchField.addKeyListener(arrowKeysListener); SearchFieldChangeListener searchFieldChangeListener = new SearchFieldChangeListener(); searchField.getDocument().addDocumentListener(searchFieldChangeListener); nodeList = new JList(filteredNodeListModel); DoubleClickListener doubleClickListener = new DoubleClickListener(); nodeList.addMouseListener(doubleClickListener); nodeList.addKeyListener(escapeListener); nodeList.addKeyListener(arrowKeysListener); nodeList.setSelectedIndex(0); nodeList.setCellRenderer(new NodeRenderer()); JScrollPane nodeScroll = new JScrollPane( nodeList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); nodeScroll.setBorder(null); panel.add(searchField, BorderLayout.NORTH); panel.add(nodeScroll, BorderLayout.CENTER); setContentPane(panel); setSize(500, 400); SwingUtils.centerOnScreen(this); }
public BatchInputPanel(final ImagePropertyTable imageTable) { super(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1)); this.imageTable = imageTable; setupUI(); useBatchInputCheckbox.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent event) { onBatch(); } }); applyToAllButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent event) { onApply(true); } }); applyToSelectedButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent event) { onApply(false); } }); orientationComboBox.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent event) { final boolean enableLabel = (orientationComboBox.getSelectedIndex() != 2 /* [Blank] */); orientationLabel.setEnabled(enableLabel); } }); lengthField .getDocument() .addDocumentListener(LabelEnablerFactory.create(lengthField, lengthLabel)); dpiXField.getDocument().addDocumentListener(LabelEnablerFactory.create(dpiXField, dpiXLabel)); dpiYField.getDocument().addDocumentListener(LabelEnablerFactory.create(dpiYField, dpiYLabel)); startDepthField .getDocument() .addDocumentListener(LabelEnablerFactory.create(startDepthField, startDepthLabel)); depthIncField .getDocument() .addDocumentListener(LabelEnablerFactory.create(depthIncField, depthIncLabel)); }
public MavenAddArchetypeDialog(Component parent) { super(parent, false); setTitle("Add Archetype"); init(); DocumentAdapter l = new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { doValidateInput(); } }; myGroupIdField.getDocument().addDocumentListener(l); myArtifactIdField.getDocument().addDocumentListener(l); myVersionField.getDocument().addDocumentListener(l); myRepositoryField.getDocument().addDocumentListener(l); doValidateInput(); }
private void initMainPanel() { mainPanel = new JPanel(null); searchField = new JTextField(); searchField.setBounds(50, 50, 830, 20); searchField .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) {} @Override public void removeUpdate(DocumentEvent e) { listSearchTable = null; } @Override public void changedUpdate(DocumentEvent e) {} }); searchField.addActionListener(new Action()); searchButton = new JButton( new ImageIcon( "/home/mrhappyyy/Programing/Java/Project/Laboratory/Client_Laboratory/src/windows/search.png")); searchButton.setBorderPainted(false); searchButton.setBounds(900, 35, 50, 50); searchButton.addActionListener(new Action()); updateTable = new JButton( new ImageIcon( "/home/mrhappyyy/Programing/Java/Project/Laboratory/Client_Laboratory/src/windows/refresh.png")); updateTable.setBorderPainted(false); updateTable.setBounds(900, 100, 50, 50); updateTable.addActionListener(new Action()); productTableModel = new ProductTableModel(); table = new JTable(productTableModel); scroll = new JScrollPane(table); scroll.setBounds(50, 85, 830, 450); mainPanel.add(searchField); mainPanel.add(searchButton); mainPanel.add(updateTable); mainPanel.add(scroll); clarificationPanel.add(mainPanel, "mainPanel"); updateTable(); layout.show(clarificationPanel, "mainPanel"); }
/** Constructor */ public ServiceFilterPanel(String text, Vector list) { empty_border = new EmptyBorder(5, 5, 0, 5); indent_border = new EmptyBorder(5, 25, 5, 5); service_box = new JCheckBox(text); service_box.addActionListener(this); service_data = new Vector(); if (list != null) { service_box.setSelected(true); service_data = (Vector) list.clone(); } service_list = new JList(service_data); service_list.setBorder(new EtchedBorder()); service_list.setVisibleRowCount(5); service_list.addListSelectionListener(this); service_list.setEnabled(service_box.isSelected()); service_scroll = new JScrollPane(service_list); service_scroll.setBorder(new EtchedBorder()); remove_service_button = new JButton("Remove"); remove_service_button.addActionListener(this); remove_service_button.setEnabled(false); remove_service_panel = new JPanel(); remove_service_panel.setLayout(new FlowLayout()); remove_service_panel.add(remove_service_button); service_area = new JPanel(); service_area.setLayout(new BorderLayout()); service_area.add(service_scroll, BorderLayout.CENTER); service_area.add(remove_service_panel, BorderLayout.EAST); service_area.setBorder(indent_border); add_service_field = new JTextField(); add_service_field.addActionListener(this); add_service_field.getDocument().addDocumentListener(this); add_service_field.setEnabled(service_box.isSelected()); add_service_button = new JButton("Add"); add_service_button.addActionListener(this); add_service_button.setEnabled(false); add_service_panel = new JPanel(); add_service_panel.setLayout(new BorderLayout()); JPanel dummy = new JPanel(); dummy.setBorder(empty_border); add_service_panel.add(dummy, BorderLayout.WEST); add_service_panel.add(add_service_button, BorderLayout.EAST); add_service_area = new JPanel(); add_service_area.setLayout(new BorderLayout()); add_service_area.add(add_service_field, BorderLayout.CENTER); add_service_area.add(add_service_panel, BorderLayout.EAST); add_service_area.setBorder(indent_border); setLayout(new BorderLayout()); add(service_box, BorderLayout.NORTH); add(service_area, BorderLayout.CENTER); add(add_service_area, BorderLayout.SOUTH); setBorder(empty_border); }
public FenText3() { setTitle("Miroir d’un texte"); setSize(300, 110); Container contenu = getContentPane(); contenu.setLayout(new FlowLayout()); saisie = new JTextField(20); contenu.add(saisie); saisie.getDocument().addDocumentListener(this); copie = new JTextField(20); copie.setEditable(true); copie.setBackground(Color.gray); contenu.add(copie); }
public SearchDialogPanel(OWLEditorKit editorKit) { this.editorKit = editorKit; setLayout(new BorderLayout()); searchField = new AugmentedJTextField("Enter search string"); searchPanel = new SearchPanel(editorKit); add(searchField, BorderLayout.NORTH); add(searchPanel, BorderLayout.CENTER); searchField.addKeyListener( new KeyAdapter() { public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { selectEntity(); } } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_UP) { searchPanel.moveSelectionUp(); e.consume(); } if (e.getKeyCode() == KeyEvent.VK_DOWN) { searchPanel.moveSelectionDown(); e.consume(); } } }); searchField .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) {} public void insertUpdate(DocumentEvent e) { performSearch(); } public void removeUpdate(DocumentEvent e) { performSearch(); } }); searchPanel.setSearchResultClickedListener( new SearchResultClickedListener() { @Override public void handleSearchResultClicked(SearchResult searchResult, MouseEvent e) { if (e.getClickCount() == 2) { selectEntity(); } } }); }
/** * Replace the path component under the caret with the file selected from the completion list. * * @param file the selected file. * @param caretPos * @param start the start offset of the path component under the caret. * @param end the end offset of the path component under the caret. * @throws BadLocationException */ private void replacePathComponent(LookupFile file, int caretPos, int start, int end) throws BadLocationException { final Document doc = myPathTextField.getDocument(); myPathTextField.setSelectionStart(0); myPathTextField.setSelectionEnd(0); final String name = file.getName(); boolean toRemoveExistingName; String prefix = ""; if (caretPos >= start) { prefix = doc.getText(start, caretPos - start); if (prefix.length() == 0) { prefix = doc.getText(start, end - start); } if (SystemInfo.isFileSystemCaseSensitive) { toRemoveExistingName = name.startsWith(prefix) && prefix.length() > 0; } else { toRemoveExistingName = name.toUpperCase().startsWith(prefix.toUpperCase()) && prefix.length() > 0; } } else { toRemoveExistingName = true; } int newPos; if (toRemoveExistingName) { doc.remove(start, end - start); doc.insertString(start, name, doc.getDefaultRootElement().getAttributes()); newPos = start + name.length(); } else { doc.insertString(caretPos, name, doc.getDefaultRootElement().getAttributes()); newPos = caretPos + name.length(); } if (file.isDirectory()) { if (!myFinder.getSeparator().equals(doc.getText(newPos, 1))) { doc.insertString( newPos, myFinder.getSeparator(), doc.getDefaultRootElement().getAttributes()); newPos++; } } if (newPos < doc.getLength()) { if (myFinder.getSeparator().equals(doc.getText(newPos, 1))) { newPos++; } } myPathTextField.setCaretPosition(newPos); }
public void addActionListener(final ActionListener actionListener) { myProxyLoginTextField.addActionListener(actionListener); DocumentListener docListener = new DocumentListener() { public void insertUpdate(DocumentEvent e) { actionListener.actionPerformed(null); } public void removeUpdate(DocumentEvent e) { actionListener.actionPerformed(null); } public void changedUpdate(DocumentEvent e) { actionListener.actionPerformed(null); } }; myProxyPasswordTextField.getDocument().addDocumentListener(docListener); myProxyAuthCheckBox.addActionListener(actionListener); myProxyPortTextField.getDocument().addDocumentListener(docListener); myProxyHostTextField.getDocument().addDocumentListener(docListener); myUseHTTPProxyRb.addActionListener(actionListener); myRememberProxyPasswordCheckBox.addActionListener(actionListener); }
private void processChosenFromCompletion(boolean nameOnly) { final LookupFile file = getSelectedFileFromCompletionPopup(); if (file == null) return; if (nameOnly) { try { final Document doc = myPathTextField.getDocument(); int caretPos = myPathTextField.getCaretPosition(); if (myFinder.getSeparator().equals(doc.getText(caretPos, 1))) { for (; caretPos < doc.getLength(); caretPos++) { final String eachChar = doc.getText(caretPos, 1); if (!myFinder.getSeparator().equals(eachChar)) break; } } int start = caretPos > 0 ? caretPos - 1 : caretPos; while (start >= 0) { final String each = doc.getText(start, 1); if (myFinder.getSeparator().equals(each)) { start++; break; } start--; } int end = start < caretPos ? caretPos : start; while (end <= doc.getLength()) { final String each = doc.getText(end, 1); if (myFinder.getSeparator().equals(each)) { break; } end++; } if (end > doc.getLength()) { end = doc.getLength(); } if (start > end || start < 0 || end > doc.getLength()) { setTextToFile(file); } else { replacePathComponent(file, caretPos, start, end); } } catch (BadLocationException e) { LOG.error(e); } } else { setTextToFile(file); } }
public JComponent createOptionsPanel() { JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); final JTextField checkedClasses = new JTextField(CHECKED_CLASSES); checkedClasses .getDocument() .addDocumentListener( new DocumentAdapter() { public void textChanged(DocumentEvent event) { CHECKED_CLASSES = checkedClasses.getText(); } }); panel.add(checkedClasses); return panel; }
public URLField() { config = new Config(); icon = new SignIcon(config); label = new JLabel(icon); /* show at least a 16x16 icon */ label.setMinimumSize(new Dimension(18, 18)); field = new JTextField(30); buildUI(); field.addActionListener(this); field.getDocument().addDocumentListener(this); setText(null); }
public ListDemo() { super(new BorderLayout()); listModel = new DefaultListModel(); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(hireString); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(hireString); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); loadButton = new JButton(loadString); loadButton.setActionCommand(loadString); loadButton.addActionListener(new loadListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name; if (listModel.size() > 0) { name = listModel.getElementAt(list.getSelectedIndex()).toString(); } // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(loadButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
/** Adds a listener to the text field holding the abbreviation of this data set. */ private void addTextFieldListener() { textField .getDocument() .addDocumentListener( new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { updateNodeName(); } @Override public void insertUpdate(DocumentEvent e) { updateNodeName(); } @Override public void changedUpdate(DocumentEvent e) { updateNodeName(); } private void updateNodeName() { if (dataSetNode != null) { String newExternalName = textField.getText(); String internalID = CyGlobals.KPM.externalToInternalIDManager.getInternalIdentifier( dataSetNode.getExternalName()); CyGlobals.KPM.externalToInternalIDManager.updateExternalIdentifier( internalID, newExternalName); dataSetNode.setExternalName(newExternalName); dataPanel.dataSetNamesUnique(); KPMLinksTab lp = dataPanel.getKPMTabbedPane().getLinksPanel(); lp.refreshLogicalFormulaLabel(); lParameterPanel.setExternalName(newExternalName); } } }); }
/** The constructor */ private BranchNameEditor() { myDefaultForeground = myTextField.getForeground(); myTextField .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { String s = myTextField.getText(); if ((myInvalidValues == null || !myInvalidValues.contains(s)) && (s.length() == 0 || BranchNameValidator.INSTANCE.checkInput(s))) { myTextField.setForeground(myDefaultForeground); } else { myTextField.setForeground(Color.RED); } } }); myTextField.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { stopCellEditing(); } }); myPanel.add( myTextField, new GridBagConstraints( 0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); }
public GithubLoginPanel(final GithubLoginDialog dialog) { DocumentListener listener = new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { dialog.clearErrors(); } }; myLoginTextField.getDocument().addDocumentListener(listener); myPasswordField.getDocument().addDocumentListener(listener); mySignupTextField.setText( "<html>Do not have an account at github.com? <a href=\"https://github.com\">Sign up</a>.</html>"); mySignupTextField.setMargin(new Insets(5, 0, 0, 0)); mySignupTextField.addHyperlinkListener( new HyperlinkAdapter() { @Override protected void hyperlinkActivated(final HyperlinkEvent e) { BrowserUtil.browse(e.getURL()); } }); mySignupTextField.setBackground(UIUtil.TRANSPARENT_COLOR); mySignupTextField.setCursor(new Cursor(Cursor.HAND_CURSOR)); }
private void setUpChooseGenerateFilePath() { FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.getDirectoryChooserDescriptor( "directory where generated files will be stored"); fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRoots()); generatedChooseFile.addBrowseFolderListener(null, null, project, fileChooserDescriptor); final JTextField textField = generatedChooseFile.getTextField(); textField .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { onChange(); } @Override public void removeUpdate(DocumentEvent e) { onChange(); } @Override public void changedUpdate(DocumentEvent e) { onChange(); } private void onChange() { File file = new File(generatedChooseFile.getText()); if (!file.isDirectory()) { textField.setForeground(Color.RED); } else { textField.setForeground(Color.BLACK); } } }); }
public ResourceEditor( @Nullable ResourceType[] types, Set<AttributeFormat> formats, @Nullable String[] values) { myTypes = types; myIsDimension = formats.contains(AttributeFormat.Dimension); if (formats.contains(AttributeFormat.Boolean)) { myCheckBox = new JCheckBox(); myEditor = new ComponentWithBrowseButton<JCheckBox>(myCheckBox, null) { @Override public Dimension getPreferredSize() { return getComponentPreferredSize(); } }; myCheckBox.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (!myIgnoreCheckBoxValue) { myBooleanResourceValue = null; fireValueCommitted(false, true); } } }); } else if (formats.contains(AttributeFormat.Enum)) { ComboboxWithBrowseButton editor = new ComboboxWithBrowseButton(SystemInfo.isWindows ? new MyComboBox() : new JComboBox()) { @Override public Dimension getPreferredSize() { return getComponentPreferredSize(); } }; final JComboBox comboBox = editor.getComboBox(); DefaultComboBoxModel model = new DefaultComboBoxModel(values); model.insertElementAt(StringsComboEditor.UNSET, 0); comboBox.setModel(model); comboBox.setEditable(true); ComboEditor.installListeners( comboBox, new ComboEditor.ComboEditorListener(this) { @Override protected void onValueChosen() { if (comboBox.getSelectedItem() == StringsComboEditor.UNSET) { comboBox.setSelectedItem(null); } super.onValueChosen(); } }); myEditor = editor; comboBox.setSelectedIndex(0); } else { myEditor = new TextFieldWithBrowseButton() { @Override protected void installPathCompletion( FileChooserDescriptor fileChooserDescriptor, @Nullable Disposable parent) {} @Override public Dimension getPreferredSize() { return getComponentPreferredSize(); } }; myEditor.registerKeyboardAction( new ActionListener() { @Override public void actionPerformed(ActionEvent e) {} }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); JTextField textField = getComboText(); textField.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fireValueCommitted(false, true); } }); textField .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(final DocumentEvent e) { preferredSizeChanged(); } }); selectTextOnFocusGain(textField); } if (myCheckBox == null) { myEditor.registerKeyboardAction( new ActionListener() { @Override public void actionPerformed(ActionEvent e) {} }, KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); } myEditor.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showDialog(); } }); myEditor.addFocusListener( new FocusAdapter() { @Override public void focusGained(FocusEvent e) { myEditor.getChildComponent().requestFocus(); } }); }
public void show(List<Rule> rules) { if (original != null) config.restoreState(original); dialog = new JDialog(owner, true); dialog.setTitle(messages.getString("guiConfigWindowTitle")); Collections.sort(rules, new CategoryComparator()); // close dialog when user presses Escape key: final KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); final ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(@SuppressWarnings("unused") ActionEvent actionEvent) { dialog.setVisible(false); } }; final JRootPane rootPane = dialog.getRootPane(); rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); // JPanel final JPanel checkBoxPanel = new JPanel(); checkBoxPanel.setLayout(new GridBagLayout()); GridBagConstraints cons = new GridBagConstraints(); cons.anchor = GridBagConstraints.NORTHWEST; cons.gridx = 0; cons.weightx = 1.0; cons.weighty = 1.0; cons.fill = GridBagConstraints.BOTH; DefaultMutableTreeNode rootNode = createTree(rules); DefaultTreeModel treeModel = new DefaultTreeModel(rootNode); treeModel.addTreeModelListener( new TreeModelListener() { @Override public void treeNodesChanged(TreeModelEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getTreePath().getLastPathComponent(); int index = e.getChildIndices()[0]; node = (DefaultMutableTreeNode) (node.getChildAt(index)); if (node instanceof RuleNode) { RuleNode o = (RuleNode) node; if (o.getRule().isDefaultOff()) { if (o.isEnabled()) { config.getEnabledRuleIds().add(o.getRule().getId()); } else { config.getEnabledRuleIds().remove(o.getRule().getId()); } } else { if (o.isEnabled()) { config.getDisabledRuleIds().remove(o.getRule().getId()); } else { config.getDisabledRuleIds().add(o.getRule().getId()); } } } if (node instanceof CategoryNode) { CategoryNode o = (CategoryNode) node; if (o.isEnabled()) { config.getDisabledCategoryNames().remove(o.getCategory().getName()); } else { config.getDisabledCategoryNames().add(o.getCategory().getName()); } } } @Override public void treeNodesInserted(TreeModelEvent e) {} @Override public void treeNodesRemoved(TreeModelEvent e) {} @Override public void treeStructureChanged(TreeModelEvent e) {} }); configTree = new JTree(treeModel); configTree.setRootVisible(false); configTree.setEditable(false); configTree.setCellRenderer(new CheckBoxTreeCellRenderer()); TreeListener.install(configTree); checkBoxPanel.add(configTree, cons); MouseAdapter ma = new MouseAdapter() { private void handlePopupEvent(MouseEvent e) { final JTree tree = (JTree) e.getSource(); TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); TreePath[] paths = tree.getSelectionPaths(); boolean isSelected = false; if (paths != null) { for (TreePath selectionPath : paths) { if (selectionPath.equals(path)) { isSelected = true; } } } if (!isSelected) { tree.setSelectionPath(path); } if (node.isLeaf()) { JPopupMenu popup = new JPopupMenu(); final JMenuItem aboutRuleMenuItem = new JMenuItem(messages.getString("guiAboutRuleMenu")); aboutRuleMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { RuleNode node = (RuleNode) tree.getSelectionPath().getLastPathComponent(); Rule rule = node.getRule(); Language lang = config.getLanguage(); if (lang == null) { lang = Language.getLanguageForLocale(Locale.getDefault()); } Tools.showRuleInfoDialog( tree, messages.getString("guiAboutRuleTitle"), rule.getDescription(), rule, messages, lang.getShortNameWithCountryAndVariant()); } }); popup.add(aboutRuleMenuItem); popup.show(tree, e.getX(), e.getY()); } } @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { handlePopupEvent(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { handlePopupEvent(e); } } }; configTree.addMouseListener(ma); final JPanel treeButtonPanel = new JPanel(); cons = new GridBagConstraints(); cons.gridx = 0; cons.gridy = 0; final JButton expandAllButton = new JButton(messages.getString("guiExpandAll")); treeButtonPanel.add(expandAllButton, cons); expandAllButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { TreeNode root = (TreeNode) configTree.getModel().getRoot(); TreePath parent = new TreePath(root); for (Enumeration categ = root.children(); categ.hasMoreElements(); ) { TreeNode n = (TreeNode) categ.nextElement(); TreePath child = parent.pathByAddingChild(n); configTree.expandPath(child); } } }); cons.gridx = 1; cons.gridy = 0; final JButton collapseAllbutton = new JButton(messages.getString("guiCollapseAll")); treeButtonPanel.add(collapseAllbutton, cons); collapseAllbutton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { TreeNode root = (TreeNode) configTree.getModel().getRoot(); TreePath parent = new TreePath(root); for (Enumeration categ = root.children(); categ.hasMoreElements(); ) { TreeNode n = (TreeNode) categ.nextElement(); TreePath child = parent.pathByAddingChild(n); configTree.collapsePath(child); } } }); final JPanel motherTonguePanel = new JPanel(); motherTonguePanel.add(new JLabel(messages.getString("guiMotherTongue")), cons); motherTongueBox = new JComboBox(getPossibleMotherTongues()); if (config.getMotherTongue() != null) { motherTongueBox.setSelectedItem(config.getMotherTongue().getTranslatedName(messages)); } motherTongueBox.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { Language motherTongue; if (motherTongueBox.getSelectedItem() instanceof String) { motherTongue = getLanguageForLocalizedName(motherTongueBox.getSelectedItem().toString()); } else { motherTongue = (Language) motherTongueBox.getSelectedItem(); } config.setMotherTongue(motherTongue); } } }); motherTonguePanel.add(motherTongueBox, cons); final JPanel portPanel = new JPanel(); portPanel.setLayout(new GridBagLayout()); // TODO: why is this now left-aligned?!?! cons = new GridBagConstraints(); cons.insets = new Insets(0, 4, 0, 0); cons.gridx = 0; cons.gridy = 0; cons.anchor = GridBagConstraints.WEST; cons.fill = GridBagConstraints.NONE; cons.weightx = 0.0f; if (!insideOOo) { serverCheckbox = new JCheckBox(Tools.getLabel(messages.getString("guiRunOnPort"))); serverCheckbox.setMnemonic(Tools.getMnemonic(messages.getString("guiRunOnPort"))); serverCheckbox.setSelected(config.getRunServer()); portPanel.add(serverCheckbox, cons); serverCheckbox.addActionListener( new ActionListener() { @Override public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) { serverPortField.setEnabled(serverCheckbox.isSelected()); serverSettingsCheckbox.setEnabled(serverCheckbox.isSelected()); } }); serverCheckbox.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { config.setRunServer(serverCheckbox.isSelected()); } }); serverPortField = new JTextField(Integer.toString(config.getServerPort())); serverPortField.setEnabled(serverCheckbox.isSelected()); serverSettingsCheckbox = new JCheckBox(Tools.getLabel(messages.getString("useGUIConfig"))); // TODO: without this the box is just a few pixels small, but why??: serverPortField.setMinimumSize(new Dimension(100, 25)); cons.gridx = 1; portPanel.add(serverPortField, cons); serverPortField .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { changedUpdate(e); } @Override public void removeUpdate(DocumentEvent e) { changedUpdate(e); } @Override public void changedUpdate(DocumentEvent e) { try { int serverPort = Integer.parseInt(serverPortField.getText()); if (serverPort > -1 && serverPort < 65536) { serverPortField.setForeground(null); config.setServerPort(serverPort); } else { serverPortField.setForeground(Color.RED); } } catch (NumberFormatException ex) { serverPortField.setForeground(Color.RED); } } }); cons.gridx = 0; cons.gridy = 10; serverSettingsCheckbox.setMnemonic(Tools.getMnemonic(messages.getString("useGUIConfig"))); serverSettingsCheckbox.setSelected(config.getUseGUIConfig()); serverSettingsCheckbox.setEnabled(config.getRunServer()); serverSettingsCheckbox.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { config.setUseGUIConfig(serverSettingsCheckbox.isSelected()); } }); portPanel.add(serverSettingsCheckbox, cons); } final JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridBagLayout()); okButton = new JButton(Tools.getLabel(messages.getString("guiOKButton"))); okButton.setMnemonic(Tools.getMnemonic(messages.getString("guiOKButton"))); okButton.addActionListener(this); cancelButton = new JButton(Tools.getLabel(messages.getString("guiCancelButton"))); cancelButton.setMnemonic(Tools.getMnemonic(messages.getString("guiCancelButton"))); cancelButton.addActionListener(this); cons = new GridBagConstraints(); cons.insets = new Insets(0, 4, 0, 0); buttonPanel.add(okButton, cons); buttonPanel.add(cancelButton, cons); final Container contentPane = dialog.getContentPane(); contentPane.setLayout(new GridBagLayout()); cons = new GridBagConstraints(); cons.insets = new Insets(4, 4, 4, 4); cons.gridx = 0; cons.gridy = 0; cons.weightx = 10.0f; cons.weighty = 10.0f; cons.fill = GridBagConstraints.BOTH; contentPane.add(new JScrollPane(checkBoxPanel), cons); cons.gridx = 0; cons.gridy = 1; cons.weightx = 0.0f; cons.weighty = 0.0f; cons.fill = GridBagConstraints.NONE; cons.anchor = GridBagConstraints.LINE_END; contentPane.add(treeButtonPanel, cons); cons.gridx = 0; cons.gridy = 2; cons.weightx = 0.0f; cons.weighty = 0.0f; cons.fill = GridBagConstraints.NONE; cons.anchor = GridBagConstraints.WEST; contentPane.add(motherTonguePanel, cons); cons.gridx = 0; cons.gridy = 3; cons.weightx = 0.0f; cons.weighty = 0.0f; cons.fill = GridBagConstraints.NONE; cons.anchor = GridBagConstraints.WEST; contentPane.add(portPanel, cons); cons.gridx = 0; cons.gridy = 4; cons.weightx = 0.0f; cons.weighty = 0.0f; cons.fill = GridBagConstraints.NONE; cons.anchor = GridBagConstraints.EAST; contentPane.add(buttonPanel, cons); dialog.pack(); dialog.setSize(500, 500); // center on screen: final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final Dimension frameSize = dialog.getSize(); dialog.setLocation( screenSize.width / 2 - frameSize.width / 2, screenSize.height / 2 - frameSize.height / 2); dialog.setLocationByPlatform(true); dialog.setVisible(true); }
private void initComponents() { final TitledBorder border = BorderFactory.createTitledBorder(label); final Font titleFont = border.getTitleFont(); if (titleFont != null) { border.setTitleFont(titleFont.deriveFont(Font.BOLD)); } setBorder(border); jtext = new JTextField(); // jtext.setText(defalt.getFile().getPath()); jRelativneKProgramu = new JCheckBox("Relativně k umístění programu"); jRelativneKProgramu.setEnabled(FConst.JAR_DIR_EXISTUJE); jActive = new JCheckBox("Aktivní"); jActive.setEnabled(lzeDeaktivovat); jCurrVal = new JTextField(); jCurrVal.setForeground(Color.BLUE); jCurrVal.setEditable(false); jCurrVal.setBorder(null); final JButton jbut = new JButton("..."); // jtext.setText(defalt.getFile().getPath()); jtext.setColumns(50); if (editovatelne) { final Box box2 = Box.createHorizontalBox(); box2.setAlignmentX(LEFT_ALIGNMENT); box2.add(jtext); box2.add(jbut); final Box panel3 = Box.createHorizontalBox(); if (FConst.JAR_DIR_EXISTUJE) { panel3.add(jRelativneKProgramu); } if (jActive.isEnabled()) { panel3.add(jActive); } if (panel3.getComponentCount() > 0) { add(panel3); } panel3.setAlignmentX(LEFT_ALIGNMENT); add(box2); } // panel.add(Box.createVerticalStrut(20)); jCurrVal.setAlignmentX(LEFT_ALIGNMENT); add(jCurrVal); // add(panel); // add(Box.createVerticalStrut(20)); jbut.addActionListener( new ActionListener() { private JFileChooser fc; @Override public void actionPerformed(final ActionEvent ae) { if (fc == null) { // dlouho to trvá, tak vytvoříme vždy nový fc = new JFileChooser(); } fc.setCurrentDirectory(new File(jtext.getText())); if (jenAdresare) { fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } final int result = fc.showDialog(JJedenSouborPanel.this, "Vybrat"); if (result == JFileChooser.APPROVE_OPTION) { jtext.setText(fc.getSelectedFile().getPath()); } } }); prepocitej(); jtext.getDocument().addDocumentListener(this); jRelativneKProgramu.addActionListener(e -> prepocitej()); jActive.addActionListener(e -> prepocitej()); }
/** Creates all of the UI components used by this application. */ private void createComponents() { // the data entry fields need their focus watched... final FocusWatcher focusWatcher = new FocusWatcher(); // create the label and field for the mortgage principal amount fieldPrincipal = new JTextField(); fieldPrincipal.addFocusListener(focusWatcher); fieldPrincipal.setColumns(FIELD_COLUMNS); labelPrincipal = new JLabel(LABEL_PRINCIPAL); labelPrincipal.setLabelFor(fieldPrincipal); // create the label and field for the mortgage terms combo-box/list fieldMortgageChoices = new JComboBox(); fieldMortgageChoices.addActionListener(new FieldActionListener()); labelMortgageChoices = new JLabel(LABEL_MORTGAGE_CHOICES); labelMortgageChoices.setLabelFor(fieldMortgageChoices); // create the label and field for the mortgage term period fieldTerm = new JTextField(); fieldTerm.addFocusListener(focusWatcher); fieldTerm.setColumns(FIELD_COLUMNS); labelTerm = new JLabel(LABEL_TERM); labelTerm.setLabelFor(fieldTerm); // create the label and field for the mortgage annual interest rate fieldRate = new JTextField(); fieldRate.addFocusListener(focusWatcher); fieldRate.setColumns(FIELD_COLUMNS); labelRate = new JLabel(LABEL_RATE); labelRate.setLabelFor(fieldRate); // create the label that will provide the header text for the panel labelHeader = new JLabel(MSG_HEADER); // create the label that will provide any mesages to the user, // including the newly calculated mortgage payment amounts labelMessage = new JLabel(""); // create a chart used to display the mortgage payment detail; a small // pixel size is used so our primary window isn't sized too large paymentsChart = new Chart(320, 240); paymentsChart.setBorder(BorderFactory.createLineBorder(Color.BLACK)); // TODO paymentsModel = new MortgagePaymentsTableModel(); paymentsTable = new JTableHelper(paymentsModel); paymentsTable.setColumnSelectionAllowed(false); paymentsTable.setRowSelectionAllowed(true); paymentsTable.setDefaultRenderer(Double.class, new CurrencyRenderer()); // create the button that will allow the user to calculate a mortgage // payment schedule from the current input final Action calcAction = new CalcAction(); calcButton = new JButton(calcAction); getRootPane().setDefaultButton(calcButton); // set default values for all of the fields to make the user feel cozy fieldPrincipal.setText(FMT_PRINCIPAL.format(DEFAULT_PRINCIPAL)); fieldRate.setText(FMT_RATE.format(DEFAULT_RATE)); fieldTerm.setText(FMT_TERM.format(DEFAULT_TERM)); // watch the documents of our input fields so that we can reset our // current mortgage calculate whenever the user changes anything final DocumentListener docWatcher = new DocumentWatcher(); fieldPrincipal.getDocument().addDocumentListener(docWatcher); fieldRate.getDocument().addDocumentListener(docWatcher); fieldTerm.getDocument().addDocumentListener(docWatcher); }
public ScrapeView() { this.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); GridBagLayout layout = new GridBagLayout(); this.setLayout(layout); GridBagConstraints constraint = new GridBagConstraints(); constraint.insets = new Insets(3, 3, 3, 3); constraint.weightx = 1; constraint.weighty = 0; constraint.gridwidth = 1; constraint.anchor = GridBagConstraints.CENTER; { websiteDataUrlLabel = new JLabel("Website data URL:"); constraint.weightx = 0; constraint.weighty = 0; constraint.gridx = 0; constraint.gridy = 0; constraint.gridwidth = 1; constraint.gridheight = 1; constraint.fill = GridBagConstraints.BOTH; this.add(websiteDataUrlLabel, constraint); } { websiteDataUrlTextField = new JTextField(""); websiteDataUrlTextField .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { try { String str = e.getDocument().getText(0, e.getDocument().getLength()); if (str.contains("motel6.com")) { parserComboBox.setSelectedIndex(0); } else if (str.contains("redroof.com")) { parserComboBox.setSelectedIndex(1); } else if (str.contains("redlion.com")) { parserComboBox.setSelectedIndex(2); } } catch (BadLocationException exception) { logger.error(exception); } } @Override public void removeUpdate(DocumentEvent e) {} @Override public void changedUpdate(DocumentEvent e) {} }); constraint.weightx = 1; constraint.weighty = 0; constraint.gridx = 1; constraint.gridy = 0; constraint.gridwidth = 1; constraint.gridheight = 1; constraint.fill = GridBagConstraints.BOTH; this.add(websiteDataUrlTextField, constraint); } { browserEngineLabel = new JLabel("Browser engine:"); constraint.weightx = 0; constraint.weighty = 0; constraint.gridx = 0; constraint.gridy = 1; constraint.gridwidth = 1; constraint.gridheight = 1; constraint.fill = GridBagConstraints.BOTH; this.add(browserEngineLabel, constraint); } { String[] values = new String[] {"HtmlUnit", "Ui4j", "JxBrowser"}; browserEngineComboBox = new JComboBox<>(values); browserEngineComboBox.setSelectedIndex(2); constraint.weightx = 1; constraint.weighty = 0; constraint.gridx = 1; constraint.gridy = 1; constraint.gridwidth = 1; constraint.gridheight = 1; constraint.fill = GridBagConstraints.BOTH; this.add(browserEngineComboBox, constraint); } { parserLabel = new JLabel("Website parser:"); constraint.weightx = 0; constraint.weighty = 0; constraint.gridx = 0; constraint.gridy = 2; constraint.gridwidth = 1; constraint.gridheight = 1; constraint.fill = GridBagConstraints.BOTH; this.add(parserLabel, constraint); } { String[] values = new String[] {"Motel6", "RedRoof", "RedLion"}; parserComboBox = new JComboBox<>(values); parserComboBox.setSelectedIndex(0); constraint.weightx = 1; constraint.weighty = 0; constraint.gridx = 1; constraint.gridy = 2; constraint.gridwidth = 1; constraint.gridheight = 1; constraint.fill = GridBagConstraints.BOTH; this.add(parserComboBox, constraint); } { scrapeButton = new JButton("Scrape website"); constraint.weightx = 1; constraint.weighty = 0; constraint.gridx = 0; constraint.gridy = 3; constraint.gridwidth = 2; constraint.gridheight = 1; constraint.fill = GridBagConstraints.BOTH; this.add(scrapeButton, constraint); } { outputTextArea = new JTextArea(); outputTextArea.setEditable(false); outputTextArea.setWrapStyleWord(false); outputTextArea.setAutoscrolls(true); JScrollPane scrollPane = new JScrollPane(outputTextArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); constraint.weightx = 1; constraint.weighty = 1; constraint.gridx = 0; constraint.gridy = 4; constraint.gridwidth = 2; constraint.gridheight = 1; constraint.fill = GridBagConstraints.BOTH; this.add(scrollPane, constraint); } { progressBar = new JProgressBar(); progressBar.setString(progressBarTextPrefix); progressBar.setStringPainted(true); progressBar.setIndeterminate(true); progressBar.setVisible(false); constraint.weightx = 1; constraint.weighty = 0; constraint.gridx = 0; constraint.gridy = 5; constraint.gridwidth = 2; constraint.gridheight = 1; constraint.fill = GridBagConstraints.BOTH; this.add(progressBar, constraint); } }
/** * The constructor * * @param project the project * @param target the target configuration * @param allChanges the all changes * @param roots the collection of roots * @param remoteBranch the remote branch * @param config the configuration * @param isModify the modify flag * @throws VcsException if there is a problem with detecting the current state */ protected SwitchBranchesDialog( Project project, final BranchConfiguration target, final List<Change> allChanges, List<VirtualFile> roots, String remoteBranch, final BranchConfigurations config, boolean isModify) throws VcsException { super(project, true); setTitle(isModify ? "Modify Branch Configuration" : "Checkout Branch Configuration"); assert (remoteBranch == null) || (target == null) : "There should be no target for remote branch"; myTarget = target; myConfig = config; myModify = isModify; myProject = project; VirtualFile baseDir = project.getBaseDir(); myBaseFile = baseDir == null ? null : new File(baseDir.getPath()); myExistingConfigNames = myConfig.getConfigurationNames(); myChangesTree = new ChangesTreeList<Change>( myProject, Collections.<Change>emptyList(), !myModify, true, null, RemoteRevisionsCache.getInstance(project).getChangesNodeDecorator()) { protected DefaultTreeModel buildTreeModel( final List<Change> changes, ChangeNodeDecorator changeNodeDecorator) { TreeModelBuilder builder = new TreeModelBuilder(myProject, false); return builder.buildModel(changes, changeNodeDecorator); } protected List<Change> getSelectedObjects(final ChangesBrowserNode<Change> node) { return node.getAllChangesUnder(); } @Nullable protected Change getLeadSelectedObject(final ChangesBrowserNode node) { final Object o = node.getUserObject(); if (o instanceof Change) { return (Change) o; } return null; } }; if (remoteBranch != null) { myBranches = prepareBranchesForRemote(remoteBranch, roots); } else { myBranches = prepareBranchDescriptors(target, roots); } Collections.sort( myBranches, new Comparator<BranchDescriptor>() { @Override public int compare(BranchDescriptor o1, BranchDescriptor o2) { return o1.getRoot().compareTo(o2.getRoot()); } }); if (target == null) { myNameTextField.setText(generateNewConfigurationName()); } else { myNameTextField.setText(target.getName()); } myChangesTree.setChangesToDisplay(allChanges); myChangesTree.setIncludedChanges(Collections.<Change>emptyList()); myChangesPanel.add(myChangesTree, BorderLayout.CENTER); myChangesLabel.setLabelFor(myChangesTree); if (myModify) { myChangesLabel.setText("Changes in the current configuration"); } RootTableModel tableModel = new RootTableModel(); myBranchesTable.setModel(tableModel); myBranchesTable.setDefaultRenderer(Pair.class, new PairTableRenderer()); final TableColumnModel columns = myBranchesTable.getColumnModel(); final PairTableRenderer renderer = new PairTableRenderer(); for (Enumeration<TableColumn> cs = columns.getColumns(); cs.hasMoreElements(); ) { cs.nextElement().setCellRenderer(renderer); } TableColumn revisionColumn = columns.getColumn(RootTableModel.REVISION_COLUMN); revisionColumn.setCellEditor(new ReferenceEditor()); TableColumn branchColumn = columns.getColumn(RootTableModel.NEW_BRANCH_COLUMN); branchColumn.setCellEditor(new BranchNameEditor()); myNameTextField .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { verify(); } }); tableModel.addTableModelListener( new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { verify(); } }); verify(); init(); }
// {{{ InstallPanel constructor InstallPanel(PluginManager window, boolean updates) { super(new BorderLayout(12, 12)); this.window = window; this.updates = updates; setBorder(new EmptyBorder(12, 12, 12, 12)); final JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); split.setResizeWeight(0.75); /* Setup the table */ table = new JTable(pluginModel = new PluginTableModel()); table.setShowGrid(false); table.setIntercellSpacing(new Dimension(0, 0)); table.setRowHeight(table.getRowHeight() + 2); table.setPreferredScrollableViewportSize(new Dimension(500, 200)); table.setDefaultRenderer( Object.class, new TextRenderer((DefaultTableCellRenderer) table.getDefaultRenderer(Object.class))); table.addFocusListener(new TableFocusHandler()); InputMap tableInputMap = table.getInputMap(JComponent.WHEN_FOCUSED); ActionMap tableActionMap = table.getActionMap(); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "tabOutForward"); tableActionMap.put("tabOutForward", new KeyboardAction(KeyboardCommand.TAB_OUT_FORWARD)); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK), "tabOutBack"); tableActionMap.put("tabOutBack", new KeyboardAction(KeyboardCommand.TAB_OUT_BACK)); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "editPlugin"); tableActionMap.put("editPlugin", new KeyboardAction(KeyboardCommand.EDIT_PLUGIN)); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "closePluginManager"); tableActionMap.put( "closePluginManager", new KeyboardAction(KeyboardCommand.CLOSE_PLUGIN_MANAGER)); TableColumn col1 = table.getColumnModel().getColumn(0); TableColumn col2 = table.getColumnModel().getColumn(1); TableColumn col3 = table.getColumnModel().getColumn(2); TableColumn col4 = table.getColumnModel().getColumn(3); TableColumn col5 = table.getColumnModel().getColumn(4); col1.setPreferredWidth(30); col1.setMinWidth(30); col1.setMaxWidth(30); col1.setResizable(false); col2.setPreferredWidth(180); col3.setPreferredWidth(130); col4.setPreferredWidth(70); col5.setPreferredWidth(70); JTableHeader header = table.getTableHeader(); header.setReorderingAllowed(false); header.addMouseListener(new HeaderMouseHandler()); header.setDefaultRenderer( new HeaderRenderer((DefaultTableCellRenderer) header.getDefaultRenderer())); scrollpane = new JScrollPane(table); scrollpane.getViewport().setBackground(table.getBackground()); split.setTopComponent(scrollpane); /* Create description */ JScrollPane infoPane = new JScrollPane(infoBox = new PluginInfoBox()); infoPane.setPreferredSize(new Dimension(500, 100)); split.setBottomComponent(infoPane); EventQueue.invokeLater( new Runnable() { @Override public void run() { split.setDividerLocation(0.75); } }); final JTextField searchField = new JTextField(); searchField.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) { table.dispatchEvent(e); table.requestFocus(); } } }); searchField .getDocument() .addDocumentListener( new DocumentListener() { void update() { pluginModel.setFilterString(searchField.getText()); } @Override public void changedUpdate(DocumentEvent e) { update(); } @Override public void insertUpdate(DocumentEvent e) { update(); } @Override public void removeUpdate(DocumentEvent e) { update(); } }); table.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { int i = table.getSelectedRow(), n = table.getModel().getRowCount(); if (e.getKeyCode() == KeyEvent.VK_DOWN && i == (n - 1) || e.getKeyCode() == KeyEvent.VK_UP && i == 0) { searchField.requestFocus(); searchField.selectAll(); } } }); Box filterBox = Box.createHorizontalBox(); filterBox.add(new JLabel("Filter : ")); filterBox.add(searchField); add(BorderLayout.NORTH, filterBox); add(BorderLayout.CENTER, split); /* Create buttons */ Box buttons = new Box(BoxLayout.X_AXIS); buttons.add(new InstallButton()); buttons.add(Box.createHorizontalStrut(12)); buttons.add(new SelectallButton()); buttons.add(chooseButton = new ChoosePluginSet()); buttons.add(new ClearPluginSet()); buttons.add(Box.createGlue()); buttons.add(new SizeLabel()); add(BorderLayout.SOUTH, buttons); String path = jEdit.getProperty(PluginManager.PROPERTY_PLUGINSET, ""); if (!path.isEmpty()) { loadPluginSet(path); } } // }}}
private int documentListenerCount() { return ((AbstractDocument) textField.getDocument()).getDocumentListeners().length; }