Search in sources :

Example 11 with JTextField

use of javax.swing.JTextField in project gitblit by gitblit.

the class SearchDialog method initialize.

private void initialize() {
    prev = new JButton("<");
    prev.setToolTipText(Translation.get("gb.pagePrevious"));
    prev.setEnabled(false);
    prev.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            search(--page);
        }
    });
    next = new JButton(">");
    next.setToolTipText(Translation.get("gb.pageNext"));
    next.setEnabled(false);
    next.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            search(++page);
        }
    });
    final JButton search = new JButton(Translation.get(isSearch ? "gb.search" : "gb.refresh"));
    search.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            search(0);
        }
    });
    final JButton viewCommit = new JButton(Translation.get("gb.view"));
    viewCommit.setEnabled(false);
    viewCommit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            viewCommit();
        }
    });
    final JButton viewCommitDiff = new JButton(Translation.get("gb.commitdiff"));
    viewCommitDiff.setEnabled(false);
    viewCommitDiff.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            viewCommitDiff();
        }
    });
    final JButton viewTree = new JButton(Translation.get("gb.tree"));
    viewTree.setEnabled(false);
    viewTree.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            viewTree();
        }
    });
    JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, Utils.MARGIN, 0));
    controls.add(viewCommit);
    controls.add(viewCommitDiff);
    controls.add(viewTree);
    NameRenderer nameRenderer = new NameRenderer();
    tableModel = new FeedEntryTableModel();
    header = new HeaderPanel(Translation.get(isSearch ? "gb.search" : "gb.log"), isSearch ? "search-icon.png" : "commit_changes_16x16.png");
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    String name = table.getColumnName(FeedEntryTableModel.Columns.Author.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    name = table.getColumnName(FeedEntryTableModel.Columns.Repository.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    name = table.getColumnName(FeedEntryTableModel.Columns.Branch.ordinal());
    table.getColumn(name).setCellRenderer(new BranchRenderer());
    name = table.getColumnName(FeedEntryTableModel.Columns.Message.ordinal());
    table.getColumn(name).setCellRenderer(new MessageRenderer());
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                if (e.isControlDown()) {
                    viewCommitDiff();
                } else {
                    viewCommit();
                }
            }
        }
    });
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            boolean singleSelection = table.getSelectedRowCount() == 1;
            viewCommit.setEnabled(singleSelection);
            viewCommitDiff.setEnabled(singleSelection);
            viewTree.setEnabled(singleSelection);
        }
    });
    repositorySelector = new JComboBox(gitblit.getRepositories().toArray());
    repositorySelector.setRenderer(nameRenderer);
    repositorySelector.setForeground(nameRenderer.getForeground());
    repositorySelector.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            // repopulate the branch list based on repository selection
            // preserve branch selection, if possible
            String selectedBranch = null;
            if (branchSelector.getSelectedIndex() > -1) {
                selectedBranch = branchSelector.getSelectedItem().toString();
            }
            updateBranches();
            if (StringUtils.isEmpty(selectedBranch)) {
                // do not select branch
                branchSelector.setSelectedIndex(-1);
            } else {
                if (branchChoices.getIndexOf(selectedBranch) > -1) {
                    // select branch
                    branchChoices.setSelectedItem(selectedBranch);
                } else {
                    // branch does not exist, do not select branch
                    branchSelector.setSelectedIndex(-1);
                }
            }
        }
    });
    branchChoices = new DefaultComboBoxModel();
    branchSelector = new JComboBox(branchChoices);
    branchSelector.setRenderer(new BranchRenderer());
    searchTypeSelector = new JComboBox(Constants.SearchType.values());
    searchTypeSelector.setSelectedItem(Constants.SearchType.COMMIT);
    maxHitsSelector = new JComboBox(new Integer[] { 25, 50, 75, 100 });
    maxHitsSelector.setSelectedIndex(0);
    searchFragment = new JTextField(25);
    searchFragment.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            search(0);
        }
    });
    JPanel queryPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));
    queryPanel.add(new JLabel(Translation.get("gb.repository")));
    queryPanel.add(repositorySelector);
    queryPanel.add(new JLabel(Translation.get("gb.branch")));
    queryPanel.add(branchSelector);
    if (isSearch) {
        queryPanel.add(new JLabel(Translation.get("gb.type")));
        queryPanel.add(searchTypeSelector);
    }
    queryPanel.add(new JLabel(Translation.get("gb.maxHits")));
    queryPanel.add(maxHitsSelector);
    JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));
    actionsPanel.add(search);
    actionsPanel.add(prev);
    actionsPanel.add(next);
    JPanel northControls = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    northControls.add(queryPanel, BorderLayout.WEST);
    if (isSearch) {
        northControls.add(searchFragment, BorderLayout.CENTER);
    }
    northControls.add(actionsPanel, BorderLayout.EAST);
    JPanel northPanel = new JPanel(new BorderLayout(0, Utils.MARGIN));
    northPanel.add(header, BorderLayout.NORTH);
    northPanel.add(northControls, BorderLayout.CENTER);
    JPanel contentPanel = new JPanel() {

        private static final long serialVersionUID = 1L;

        @Override
        public Insets getInsets() {
            return Utils.INSETS;
        }
    };
    contentPanel.setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    contentPanel.add(northPanel, BorderLayout.NORTH);
    contentPanel.add(new JScrollPane(table), BorderLayout.CENTER);
    contentPanel.add(controls, BorderLayout.SOUTH);
    setLayout(new BorderLayout());
    add(contentPanel, BorderLayout.CENTER);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent event) {
            if (isSearch) {
                searchFragment.requestFocus();
            } else {
                search(0);
            }
        }

        @Override
        public void windowActivated(WindowEvent event) {
            if (isSearch) {
                searchFragment.requestFocus();
            }
        }
    });
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) WindowAdapter(java.awt.event.WindowAdapter) JTextField(javax.swing.JTextField) BorderLayout(java.awt.BorderLayout) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent)

Example 12 with JTextField

use of javax.swing.JTextField in project gitblit by gitblit.

the class UsersPanel method initialize.

private void initialize() {
    JButton refreshUsers = new JButton(Translation.get("gb.refresh"));
    refreshUsers.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshUsers();
        }
    });
    JButton createUser = new JButton(Translation.get("gb.create"));
    createUser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            createUser();
        }
    });
    final JButton editUser = new JButton(Translation.get("gb.edit"));
    editUser.setEnabled(false);
    editUser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editUser(getSelectedUsers().get(0));
        }
    });
    final JButton delUser = new JButton(Translation.get("gb.delete"));
    delUser.setEnabled(false);
    delUser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            deleteUsers(getSelectedUsers());
        }
    });
    NameRenderer nameRenderer = new NameRenderer();
    tableModel = new UsersTableModel();
    defaultSorter = new TableRowSorter<UsersTableModel>(tableModel);
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    String name = table.getColumnName(UsersTableModel.Columns.Name.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    int w = 130;
    name = table.getColumnName(UsersTableModel.Columns.Type.ordinal());
    table.getColumn(name).setMinWidth(w);
    table.getColumn(name).setMaxWidth(w);
    name = table.getColumnName(UsersTableModel.Columns.Teams.ordinal());
    table.getColumn(name).setMinWidth(w);
    table.getColumn(name).setMaxWidth(w);
    name = table.getColumnName(UsersTableModel.Columns.Repositories.ordinal());
    table.getColumn(name).setMinWidth(w);
    table.getColumn(name).setMaxWidth(w);
    table.setRowSorter(defaultSorter);
    table.getRowSorter().toggleSortOrder(UsersTableModel.Columns.Name.ordinal());
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            boolean selected = table.getSelectedRow() > -1;
            boolean singleSelection = table.getSelectedRows().length == 1;
            editUser.setEnabled(singleSelection && selected);
            delUser.setEnabled(selected);
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                editUser(getSelectedUsers().get(0));
            }
        }
    });
    filterTextfield = new JTextField();
    filterTextfield.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterUsers(filterTextfield.getText());
        }
    });
    filterTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            filterUsers(filterTextfield.getText());
        }
    });
    JPanel userFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    userFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
    userFilterPanel.add(filterTextfield, BorderLayout.CENTER);
    JPanel userTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    userTablePanel.add(userFilterPanel, BorderLayout.NORTH);
    userTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
    JPanel userControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    userControls.add(refreshUsers);
    userControls.add(createUser);
    userControls.add(editUser);
    userControls.add(delUser);
    setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    header = new HeaderPanel(Translation.get("gb.users"), "user_16x16.png");
    add(header, BorderLayout.NORTH);
    add(userTablePanel, BorderLayout.CENTER);
    add(userControls, BorderLayout.SOUTH);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) ListSelectionListener(javax.swing.event.ListSelectionListener) KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout)

Example 13 with JTextField

use of javax.swing.JTextField in project gitblit by gitblit.

the class EditRepositoryDialog method validateFields.

private boolean validateFields() {
    String rname = nameField.getText();
    if (StringUtils.isEmpty(rname)) {
        error("Please enter a repository name!");
        return false;
    }
    // automatically convert backslashes to forward slashes
    rname = rname.replace('\\', '/');
    // Automatically replace // with /
    rname = rname.replace("//", "/");
    // prohibit folder paths
    if (rname.startsWith("/")) {
        error("Leading root folder references (/) are prohibited.");
        return false;
    }
    if (rname.startsWith("../")) {
        error("Relative folder references (../) are prohibited.");
        return false;
    }
    if (rname.contains("/../")) {
        error("Relative folder references (../) are prohibited.");
        return false;
    }
    if (rname.endsWith("/")) {
        rname = rname.substring(0, rname.length() - 1);
    }
    // confirm valid characters in repository name
    Character c = StringUtils.findInvalidCharacter(rname);
    if (c != null) {
        error(MessageFormat.format("Illegal character ''{0}'' in repository name!", c));
        return false;
    }
    // verify repository name uniqueness on create
    if (isCreate) {
        // filesystem
        if (repositoryNames.contains(rname.toLowerCase())) {
            error(MessageFormat.format("Can not create repository ''{0}'' because it already exists.", rname));
            return false;
        }
    } else {
        // check rename collision
        if (!repositoryName.equalsIgnoreCase(rname)) {
            if (repositoryNames.contains(rname.toLowerCase())) {
                error(MessageFormat.format("Failed to rename ''{0}'' because ''{1}'' already exists.", repositoryName, rname));
                return false;
            }
        }
    }
    if (accessRestriction.getSelectedItem() == null) {
        error("Please select access restriction!");
        return false;
    }
    if (federationStrategy.getSelectedItem() == null) {
        error("Please select federation strategy!");
        return false;
    }
    repository.name = rname;
    repository.description = descriptionField.getText();
    repository.owners.clear();
    repository.owners.addAll(ownersPalette.getSelections());
    repository.HEAD = headRefField.getSelectedItem() == null ? null : headRefField.getSelectedItem().toString();
    repository.gcPeriod = (Integer) gcPeriod.getSelectedItem();
    repository.gcThreshold = gcThreshold.getText();
    repository.acceptNewPatchsets = acceptNewPatchsets.isSelected();
    repository.acceptNewTickets = acceptNewTickets.isSelected();
    repository.requireApproval = requireApproval.isSelected();
    repository.mergeTo = mergeToField.getSelectedItem() == null ? null : Repository.shortenRefName(mergeToField.getSelectedItem().toString());
    repository.useIncrementalPushTags = useIncrementalPushTags.isSelected();
    repository.showRemoteBranches = showRemoteBranches.isSelected();
    repository.skipSizeCalculation = skipSizeCalculation.isSelected();
    repository.skipSummaryMetrics = skipSummaryMetrics.isSelected();
    repository.maxActivityCommits = (Integer) maxActivityCommits.getSelectedItem();
    repository.isFrozen = isFrozen.isSelected();
    repository.allowForks = allowForks.isSelected();
    repository.verifyCommitter = verifyCommitter.isSelected();
    String ml = mailingListsField.getText();
    if (!StringUtils.isEmpty(ml)) {
        Set<String> list = new HashSet<String>();
        for (String address : ml.split("(,|\\s)")) {
            if (StringUtils.isEmpty(address)) {
                continue;
            }
            list.add(address.toLowerCase());
        }
        repository.mailingLists = new ArrayList<String>(list);
    }
    repository.accessRestriction = (AccessRestrictionType) accessRestriction.getSelectedItem();
    repository.authorizationControl = allowAuthenticated.isSelected() ? AuthorizationControl.AUTHENTICATED : AuthorizationControl.NAMED;
    repository.federationStrategy = (FederationStrategy) federationStrategy.getSelectedItem();
    if (repository.federationStrategy.exceeds(FederationStrategy.EXCLUDE)) {
        repository.federationSets = setsPalette.getSelections();
    }
    repository.indexedBranches = indexedBranchesPalette.getSelections();
    repository.preReceiveScripts = preReceivePalette.getSelections();
    repository.postReceiveScripts = postReceivePalette.getSelections();
    // Custom Fields
    repository.customFields = new LinkedHashMap<String, String>();
    if (customTextfields != null) {
        for (JTextField field : customTextfields) {
            String key = field.getName();
            String value = field.getText();
            repository.customFields.put(key, value);
        }
    }
    return true;
}
Also used : JTextField(javax.swing.JTextField) HashSet(java.util.HashSet)

Example 14 with JTextField

use of javax.swing.JTextField in project gitblit by gitblit.

the class X509CertificateViewer method newField.

private JPanel newField(String label, String value, int cols) {
    JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2 * Utils.MARGIN, 0));
    JLabel lbl = new JLabel(label);
    lbl.setHorizontalAlignment(SwingConstants.RIGHT);
    lbl.setPreferredSize(new Dimension(125, 20));
    panel.add(lbl);
    JTextField tf = new JTextField(value, cols);
    tf.setCaretPosition(0);
    tf.setEditable(false);
    panel.add(tf);
    return panel;
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField)

Example 15 with JTextField

use of javax.swing.JTextField in project gitblit by gitblit.

the class EditRepositoryDialog method setCustomFields.

public void setCustomFields(RepositoryModel repository, Map<String, String> customFields) {
    customFieldsPanel.removeAll();
    customTextfields = new ArrayList<JTextField>();
    final Insets insets = new Insets(5, 5, 5, 5);
    JPanel fields = new JPanel(new GridLayout(0, 1, 0, 5)) {

        private static final long serialVersionUID = 1L;

        @Override
        public Insets getInsets() {
            return insets;
        }
    };
    for (Map.Entry<String, String> entry : customFields.entrySet()) {
        String field = entry.getKey();
        String value = "";
        if (repository.customFields != null && repository.customFields.containsKey(field)) {
            value = repository.customFields.get(field);
        }
        JTextField textField = new JTextField(value);
        textField.setName(field);
        textField.setPreferredSize(new Dimension(450, 26));
        fields.add(newFieldPanel(entry.getValue(), 250, textField));
        customTextfields.add(textField);
    }
    JScrollPane jsp = new JScrollPane(fields);
    jsp.getVerticalScrollBar().setBlockIncrement(100);
    jsp.getVerticalScrollBar().setUnitIncrement(100);
    jsp.setViewportBorder(null);
    customFieldsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    customFieldsPanel.add(jsp);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

JTextField (javax.swing.JTextField)311 JLabel (javax.swing.JLabel)188 JPanel (javax.swing.JPanel)173 JButton (javax.swing.JButton)107 BorderLayout (java.awt.BorderLayout)85 JCheckBox (javax.swing.JCheckBox)58 Dimension (java.awt.Dimension)57 ActionEvent (java.awt.event.ActionEvent)56 ActionListener (java.awt.event.ActionListener)49 JScrollPane (javax.swing.JScrollPane)47 BoxLayout (javax.swing.BoxLayout)41 Insets (java.awt.Insets)37 GridBagLayout (java.awt.GridBagLayout)36 FlowLayout (java.awt.FlowLayout)35 GridBagConstraints (java.awt.GridBagConstraints)35 JComboBox (javax.swing.JComboBox)29 JTextArea (javax.swing.JTextArea)28 JRadioButton (javax.swing.JRadioButton)23 GridLayout (java.awt.GridLayout)22 JTable (javax.swing.JTable)22