Example usage for javax.swing ListModel getSize

List of usage examples for javax.swing ListModel getSize

Introduction

In this page you can find the example usage for javax.swing ListModel getSize.

Prototype

int getSize();

Source Link

Document

Returns the length of the list.

Usage

From source file:com.sshtools.common.ui.SshToolsConnectionHostTab.java

/**
 *
 *
 * @param profile/* ww w  .j  a v  a  2 s.com*/
 */
public void setConnectionProfile(SshToolsConnectionProfile profile) {
    this.profile = profile;
    jTextHostname.setText(profile == null ? "" : profile.getHost());
    jTextUsername.setText(profile == null ? "" : profile.getUsername());
    jTextPort.setValue(new Integer(profile == null ? DEFAULT_PORT : profile.getPort()));

    if (System.getProperty("sshtools.agent") == null) {
        allowAgentForwarding.setSelected(false);
        allowAgentForwarding.setEnabled(false);
    } else {
        allowAgentForwarding.setEnabled(true);
        allowAgentForwarding.setSelected(profile != null && profile.getAllowAgentForwarding());
    }

    String cur = PreferencesStore.get(SshTerminalPanel.PREF_PROXY_TYPE,
            Integer.toString(GSIConstants.GSI_3_IMPERSONATION_PROXY));
    profile.getApplicationProperty(SshTerminalPanel.PREF_PROXY_TYPE, cur);
    if (cur.equals(Integer.toString(GSIConstants.GSI_3_IMPERSONATION_PROXY)) || cur.equals("prerfc")) {
        proxyOption.setSelectedIndex(0);
    } else if (cur.equals(Integer.toString(GSIConstants.GSI_4_IMPERSONATION_PROXY)) || cur.equals("rfc")) {
        proxyOption.setSelectedIndex(1);
    }
    if (cur.equals(Integer.toString(GSIConstants.GSI_2_PROXY)) || cur.equals("legacy")) {
        proxyOption.setSelectedIndex(2);
    }

    cur = PreferencesStore.get(SshTerminalPanel.PREF_DELEGATION_TYPE, "full");
    cur = profile.getApplicationProperty(SshTerminalPanel.PREF_DELEGATION_TYPE, cur);
    if (cur.equals("full")) {
        delegationOption.setSelectedIndex(0);
    } else if (cur.equals("limited")) {
        delegationOption.setSelectedIndex(1);
    } else if (cur.equals("none")) {
        delegationOption.setSelectedIndex(2);
    }
    cur = PreferencesStore.get(SshTerminalPanel.PREF_PROXY_LENGTH, "12");
    cur = profile.getApplicationProperty(SshTerminalPanel.PREF_PROXY_LENGTH, cur);
    Integer t = new Integer(12);
    try {
        Integer tt = Integer.parseInt(cur);
        if (tt <= 240 && tt >= 1) {
            t = tt;
        }
    } catch (NumberFormatException e) {
    }
    proxyLength.setValue(t);

    boolean saveProxy = PreferencesStore.getBoolean(SshTerminalPanel.PREF_SAVE_PROXY, false);
    saveProxy = profile.getApplicationPropertyBoolean(SshTerminalPanel.PREF_SAVE_PROXY, saveProxy);
    proxySave.setSelected(saveProxy);

    // Match the authentication methods
    Map auths = profile == null ? new HashMap() : profile.getAuthenticationMethods();
    Iterator it = auths.entrySet().iterator();
    Map.Entry entry;
    String authmethod;
    int[] selectionarray = new int[auths.values().size()];
    int count = 0;

    ListModel model = jListAuths.getModel();

    while (it.hasNext()) {
        entry = (Map.Entry) it.next();
        authmethod = (String) entry.getKey();

        for (int i = 0; i < model.getSize(); i++) {
            if (model.getElementAt(i).equals(authmethod)) {
                selectionarray[count++] = i;
                break;
            }
        }
        /*if (jListAuths.getNextMatch(authmethod, 0, Position.Bias.Forward) > -1) {
             selectionarray[count] = jListAuths.getNextMatch(authmethod, 0,
        Position.Bias.Forward);
             count++;
        }*/

        jListAuths.clearSelection();
        jListAuths.setSelectedIndices(selectionarray);
    }
}

From source file:com.kstenschke.copypastestack.ToolWindow.java

/**
 * Copy selected items back into clipboard
 *//* w  w  w . j av a2s .  co m*/
public void copySelectedItems() {
    boolean hasSelection = !this.form.listClipItems.isSelectionEmpty();
    if (hasSelection) {
        ListModel<String> listModel = this.form.listClipItems.getModel();
        ListSelectionModel selectionModel = this.form.listClipItems.getSelectionModel();

        int amountItems = listModel.getSize();

        for (int i = 0; i < amountItems; i++) {
            if (selectionModel.isSelectedIndex(i)) {
                String currentItemText = listModel.getElementAt(i);
                UtilsEnvironment.copyToClipboard(currentItemText);
            }
        }
    }
}

From source file:com.kstenschke.copypastestack.ToolWindow.java

/**
 * Paste all / selected items into editor
 *///from  w ww. jav  a2s . c o  m
public void pasteItems() {
    boolean hasSelection = !this.form.listClipItems.isSelectionEmpty();
    int amountSelected = !hasSelection ? 0 : this.form.listClipItems.getSelectedIndices().length;
    boolean focusEditor = this.form.checkboxFocusOnPaste.isSelected();

    String wrapBefore = "";
    String wrapAfter = "";
    String wrapDelimiter = "";

    if (this.form.checkBoxWrap.isSelected()) {
        wrapBefore = this.form.textFieldWrapBefore.getText();
        wrapAfter = this.form.textFieldWrapAfter.getText();
        wrapDelimiter = this.form.textFieldWrapDelimiter.getText();

        if (this.form.checkboxWrapExtended.isSelected()) {
            wrapBefore = UtilsString.convertWhitespace(wrapBefore);
            wrapAfter = UtilsString.convertWhitespace(wrapAfter);
            wrapDelimiter = UtilsString.convertWhitespace(wrapDelimiter);
        }
    }

    if (!hasSelection || amountSelected > 1) {
        // Insert multiple items
        ListModel<String> listModel = this.form.listClipItems.getModel();
        ListSelectionModel selectionModel = this.form.listClipItems.getSelectionModel();

        int amountItems = listModel.getSize();
        int amountInserted = 0;
        for (int i = 0; i < amountItems; i++) {
            if (selectionModel.isSelectedIndex(i)) {
                String currentItemText = listModel.getElementAt(i);
                UtilsEnvironment.insertInEditor(wrapBefore + currentItemText + wrapAfter
                        + (amountInserted + 1 < amountSelected ? wrapDelimiter : ""), focusEditor);
                amountInserted++;
            }
        }
    } else {
        // Insert selected item
        Object itemValue = this.form.listClipItems.getSelectedValue();
        if (itemValue != null) {
            String itemText = itemValue.toString();
            if (this.form.checkBoxWrap.isSelected()) {
                itemText = wrapBefore + itemText + wrapAfter;
            }
            UtilsEnvironment.insertInEditor(itemText, focusEditor);
        }
    }
}

From source file:com.gnadenheimer.mg.utils.Utils.java

public Integer getIndexOfModel(ListModel model, Object value) {
    if (value == null) {
        return -1;
    }//from ww  w.j a  v a2s . co  m
    if (model instanceof DefaultListModel) {
        return ((DefaultListModel) model).indexOf(value);
    }
    for (Integer i = 0; i < model.getSize(); i++) {
        if (value.equals(model.getElementAt(i))) {
            return i;
        }
    }
    return -1;
}

From source file:com.kstenschke.copypastestack.ToolWindow.java

/**
 * @return  String[]//w  ww . j  a  va 2s  . co  m
 */
private String[] getUnselectedItems() {
    ListModel<String> listModel = this.form.listClipItems.getModel();
    ListSelectionModel selectionModel = this.form.listClipItems.getSelectionModel();
    int[] selectedIndices = this.form.listClipItems.getSelectedIndices();

    int amountItems = listModel.getSize();
    String[] unselectedItems = new String[amountItems - selectedIndices.length];

    int index = 0;
    for (int i = 0; i < amountItems; i++) {
        if (!selectionModel.isSelectedIndex(i)) {
            String item = listModel.getElementAt(i);
            if (!item.trim().isEmpty()) {
                unselectedItems[index] = item;
                index++;
            }
        }
    }

    return unselectedItems;
}

From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java

public Set<Document> getDocSet() {
    TreeSet<Document> docSet = new TreeSet<Document>();
    ListModel listModel = inputDocList.getModel();
    for (int i = 0; i < listModel.getSize(); i++) {
        Document doc = (Document) listModel.getElementAt(i);
        docSet.add(doc);/*from   ww  w. j av a  2  s . co m*/
    }
    return docSet;
}

From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java

public String getTargetTextLines(String word) {
    StringWriter writer = new StringWriter();
    ListModel listModel = inputDocList.getModel();
    for (int i = 0; i < listModel.getSize(); i++) {
        Document doc = (Document) listModel.getElementAt(i);
        String text = doc.getText();
        if (text != null) {
            writer.write("[ " + doc.getFile().getAbsolutePath() + " ]\n");
            String[] lines = text.split("\n");
            for (int j = 0; j < lines.length; j++) {
                String line = lines[j];
                if (line.indexOf(word) != -1) {
                    writer.write((j + 1) + ": " + line + "\n");
                }//from   w  w  w  . ja v a  2 s.  com
            }
            writer.write("\n");
        }
    }
    return writer.toString();
}

From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java

public String getTargetHtmlLines(String word) {
    StringWriter writer = new StringWriter();
    writer.write("<html><body>");
    ListModel listModel = inputDocList.getModel();
    for (int i = 0; i < listModel.getSize(); i++) {
        Document doc = (Document) listModel.getElementAt(i);
        String text = doc.getText();
        StringBuilder buf = new StringBuilder();
        if (text != null) {
            String[] lines = text.split("\n");
            for (int j = 0; j < lines.length; j++) {
                String line = lines[j];
                if (line.matches(".*" + word + ".*")) {
                    line = line.replaceAll(word, "<b><font size=3 color=red>" + word + "</font></b>");
                    buf.append("<b><font size=3 color=navy>");
                    if (DODDLEConstants.LANG.equals("en")) {
                        buf.append(Translator.getTerm("LineMessage"));
                        buf.append(" ");
                        buf.append((j + 1));
                    } else {
                        buf.append((j + 1));
                        buf.append(Translator.getTerm("LineMessage"));
                    }/*from   ww w  .  j  a  va 2 s  .c o m*/
                    buf.append(": </font></b>");
                    buf.append("<font size=3>");
                    buf.append(line);
                    buf.append("</font>");
                    buf.append("<br>");
                }
            }
        }
        if (0 < buf.toString().length()) {
            writer.write("<font size=3><b>" + doc.getFile().getAbsolutePath() + "</b></font><br>");
            writer.write(buf.toString());
        }
    }
    writer.write("</body></html>");
    return writer.toString();
}

From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == termExtractionButton) {
        destroyProcesses(); // ??????
        TermExtractionWorker worker = new TermExtractionWorker(4);
        DODDLE_OWL.STATUS_BAR.setSwingWorker(worker);
        worker.execute();/*from w ww  .  j a va  2  s .  c om*/
    } else if (e.getSource() == docLangBox) {
        if (docList.getSelectedValues().length == 1) {
            String lang = (String) docLangBox.getSelectedItem();
            Document doc = (Document) docList.getSelectedValue();
            doc.setLang(lang);
            updateUI();
        }
    } else if (e.getSource() == inputDocLangBox) {
        if (inputDocList.getSelectedValues().length == 1) {
            String lang = (String) inputDocLangBox.getSelectedItem();
            Document doc = (Document) inputDocList.getSelectedValue();
            doc.setLang(lang);
            updateUI();
        }
    } else if (e.getSource() == setPunctuationButton) {
        PUNCTUATION_CHARS = punctuationField.getText();
        ListModel inputDocModel = inputDocList.getModel();
        for (int i = 0; i < inputDocModel.getSize(); i++) {
            Document doc = (Document) inputDocModel.getElementAt(i);
            doc.resetText();
        }
        Document doc = (Document) inputDocList.getSelectedValue();
        if (doc != null) {
            inputDocArea.setText(doc.getText());
            inputDocArea.setCaretPosition(0);
            docLangBox.setSelectedItem(doc.getLang());
        }
        updateUI();
    }
}

From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java

private Map<File, String> getFileTextStringMap(ListModel listModel) {
    Map<File, String> fileTextStringMap = new HashMap<File, String>();
    for (int i = 0; i < listModel.getSize(); i++) {
        Document doc = (Document) listModel.getElementAt(i);
        fileTextStringMap.put(doc.getFile(), doc.getText());
    }/*  w  w  w . jav a2 s. c o  m*/
    return fileTextStringMap;
}