Example usage for javax.swing DefaultComboBoxModel addElement

List of usage examples for javax.swing DefaultComboBoxModel addElement

Introduction

In this page you can find the example usage for javax.swing DefaultComboBoxModel addElement.

Prototype

public void addElement(E anObject) 

Source Link

Usage

From source file:view.AppearanceSettingsDialog.java

/**
 * Creates new form NewJDialog/*  w  w  w.  j a v a2s . co m*/
 *
 * @param parent
 * @param modal
 * @param signatureSettings
 */
public AppearanceSettingsDialog(java.awt.Frame parent, boolean modal, CCSignatureSettings signatureSettings) {
    super(parent, modal);
    initComponents();
    this.signatureSettings = signatureSettings;

    updateText();

    // Pastas conforme o SO
    ArrayList<String> dirs = new ArrayList<>();
    if (SystemUtils.IS_OS_WINDOWS) {
        dirs.add(System.getenv("windir") + File.separator + "fonts");
    } else if (SystemUtils.IS_OS_LINUX) {
        dirs.add("/usr/share/fonts/truetype/");
        dirs.add("/usr/X11R6/lib/X11/fonts/");
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        dirs.add("/Library/Fonts");
        dirs.add("/System/Library/Fonts");
    }
    dirs.add("extrafonts");

    // Hashmap com fonts
    hmFonts = getAllFonts(dirs);
    ArrayList<com.itextpdf.text.Font> alFonts = new ArrayList<>(hmFonts.keySet());

    Collections.sort(alFonts, new Comparator<com.itextpdf.text.Font>() {
        @Override
        public int compare(com.itextpdf.text.Font f1, com.itextpdf.text.Font f2) {
            return f1.getFamilyname().compareToIgnoreCase(f2.getFamilyname());
        }
    });

    DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
    for (com.itextpdf.text.Font font : alFonts) {
        dcbm.addElement(font.getFamilyname());
    }
    cbFontType.setModel(dcbm);

    String fontLocation = signatureSettings.getAppearance().getFontLocation();
    boolean italic = signatureSettings.getAppearance().isItalic();
    boolean bold = signatureSettings.getAppearance().isBold();
    boolean showName = signatureSettings.getAppearance().isShowName();
    boolean showLocation = signatureSettings.getAppearance().isShowLocation();
    boolean showReason = signatureSettings.getAppearance().isShowReason();
    boolean showDate = signatureSettings.getAppearance().isShowDate();
    int align = signatureSettings.getAppearance().getAlign();

    switch (align) {
    case 0:
        cbAlign.setSelectedIndex(0);
        break;
    case 1:
        cbAlign.setSelectedIndex(1);
        break;
    case 2:
        cbAlign.setSelectedIndex(2);
        break;
    default:
        cbAlign.setSelectedIndex(0);
    }

    previewPanel1.setReason(signatureSettings.getReason());
    previewPanel1.setShowDate(showDate);

    if (signatureSettings.getCcAlias() != null) {
        previewPanel1.setAliasName(signatureSettings.getCcAlias().getName());
    } else {
        previewPanel1.setAliasName(Bundle.getBundle().getString("name"));
    }

    if (!signatureSettings.getLocation().isEmpty()) {
        previewPanel1.setLocation(signatureSettings.getLocation());
        cbShowLocation.setSelected(showLocation);
        previewPanel1.setShowLocation(showLocation);
    } else {
        cbShowLocation.setEnabled(false);
        cbShowLocation.setSelected(false);
    }

    cbShowName.setSelected(showName);
    previewPanel1.setShowName(showName);

    if (!signatureSettings.getReason().isEmpty()) {
        previewPanel1.setReason(signatureSettings.getReason());
        cbShowReason.setSelected(showReason);
        previewPanel1.setShowReason(showReason);
    } else {
        cbShowReason.setEnabled(false);
        cbShowReason.setSelected(false);
    }
    previewPanel1.setText(signatureSettings.getText());
    previewPanel1.setAlign(align);
    colorChooser.setPreviewPanel(new JPanel());
    Color color = signatureSettings.getAppearance().getFontColor();
    colorChooser.setColor(color);
    lblSampleText.setForeground(color);
    cbShowReason.setSelected(showReason);
    cbShowLocation.setSelected(showLocation);
    cbShowDateTime.setSelected(showDate);

    ColorSelectionModel model = colorChooser.getSelectionModel();
    ChangeListener changeListener = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent changeEvent) {
            Color newForegroundColor = colorChooser.getColor();
            lblSampleText.setForeground(newForegroundColor);
        }
    };
    model.addChangeListener(changeListener);

    if (fontLocation.contains("aCCinaPDF" + File.separator + "extrafonts")) {
        try {
            Font newFont = Font.createFont(Font.TRUETYPE_FONT, new File(fontLocation));
            Font font = null;
            if (italic && bold) {
                font = newFont.deriveFont(Font.ITALIC + Font.BOLD, 36);
            } else if (italic && !bold) {
                font = newFont.deriveFont(Font.ITALIC, 36);
            } else if (!italic && bold) {
                font = newFont.deriveFont(Font.BOLD, 36);
            } else {
                font = newFont.deriveFont(Font.PLAIN, 36);
            }
            lblSampleText.setFont(font);
        } catch (FontFormatException | IOException ex) {
        }
    } else {
        if (italic && bold) {
            lblSampleText.setFont(new Font(fontLocation, Font.ITALIC + Font.BOLD, 36));
        } else if (italic && !bold) {
            lblSampleText.setFont(new Font(fontLocation, Font.ITALIC, 36));
        } else if (!italic && bold) {
            lblSampleText.setFont(new Font(fontLocation, Font.BOLD, 36));
        } else {
            lblSampleText.setFont(new Font(fontLocation, Font.PLAIN, 36));
        }
    }

    cbBold.setSelected(bold);
    cbItalic.setSelected(italic);

    updateSettings(fontLocation, bold, italic);

    previewPanel1.repaint();
}

From source file:view.AppearanceSettingsDialog.java

private void updateText() {
    panelSignatureSettings.setBorder(javax.swing.BorderFactory
            .createTitledBorder(Bundle.getBundle().getString("panel.signatureSettings")));
    panelFontSettings.setBorder(/* ww  w.  j  a va 2s .com*/
            javax.swing.BorderFactory.createTitledBorder(Bundle.getBundle().getString("panel.fontSettings")));
    lblShow.setText(Bundle.getBundle().getString("label.show"));
    cbShowName.setText(Bundle.getBundle().getString("name"));
    cbShowReason.setText(Bundle.getBundle().getString("reason"));
    cbShowLocation.setText(Bundle.getBundle().getString("location"));
    cbShowDateTime.setText(Bundle.getBundle().getString("dateAndTime"));
    lblAlign.setText(Bundle.getBundle().getString("label.align"));
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
    dcbm.addElement(WordUtils.capitalize(Bundle.getBundle().getString("left")));
    dcbm.addElement(WordUtils.capitalize(Bundle.getBundle().getString("center")));
    dcbm.addElement(WordUtils.capitalize(Bundle.getBundle().getString("right")));
    cbAlign.setModel(dcbm);
    lblSampleText.setText(Bundle.getBundle().getString("label.sampleText"));
    lblFontType.setText(Bundle.getBundle().getString("label.fontType"));
    cbBold.setText(Bundle.getBundle().getString("label.bold"));
    cbItalic.setText(Bundle.getBundle().getString("label.italic"));
    cbSetAsDefault.setText(Bundle.getBundle().getString("label.setAsDefault"));
    btnAccept.setText(Bundle.getBundle().getString("btn.accept"));
    btnCancel.setText(Bundle.getBundle().getString("btn.cancel"));
}

From source file:view.MainWindow.java

private void populateDriveComboBox() {
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel();

    if (SystemUtils.IS_OS_WINDOWS) {
        File[] roots;/*from w  w  w  . ja  v  a  2 s  . c o  m*/
        roots = File.listRoots();
        if (roots.length > 1) {
            for (File root : roots) {
                dcbm.addElement(root.getAbsolutePath());
            }
            dcbm.addElement(System.getProperty("user.name"));
            dcbm.addElement(Bundle.getBundle().getString("desktop"));
            jtExplorer.setModel(new FileSystemModel(new File(roots[0].getAbsolutePath()), null));
        }
    } else {
        String userDir = System.getProperty("user.home");
        dcbm.addElement("/");
        dcbm.addElement(userDir);
        jtExplorer.setModel(new FileSystemModel(new File(userDir), null));
    }
    cbVolume.setModel(dcbm);
    cbVolume.adjustDropDownMenuWidth();
}

From source file:view.SettingsDialog.java

/**
 * Creates new form SettingsDialog/*from  w  w  w.jav  a  2  s .  c o m*/
 *
 * @param parent
 * @param modal
 */
public SettingsDialog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    updateText();
    loadSettings();
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
    for (Bundle.Locales locale : Bundle.Locales.values()) {
        dcbm.addElement(locale.toString());
    }
    cbLanguages.setModel(dcbm);
    Locale locale = Bundle.getBundle().getCurrentLocale();
    if (locale.equals(Bundle.getBundle().getLocale(Bundle.Locales.English))) {
        cbLanguages.setSelectedIndex(0);
    } else if (locale.equals(Bundle.getBundle().getLocale(Bundle.Locales.Portugues))) {
        cbLanguages.setSelectedIndex(1);
    }
}

From source file:view.SettingsDialog.java

private void loadSettings() {
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
    dcbm.addElement(PdfWriter.PDF_VERSION_1_2);
    dcbm.addElement(PdfWriter.PDF_VERSION_1_3);
    dcbm.addElement(PdfWriter.PDF_VERSION_1_4);
    dcbm.addElement(PdfWriter.PDF_VERSION_1_5);
    dcbm.addElement(PdfWriter.PDF_VERSION_1_6);
    dcbm.addElement(PdfWriter.PDF_VERSION_1_7);
    jComboBox1.setModel(dcbm);// ww  w  .  j  av a2s .  c o  m

    String language = null;
    String renderQuality = null;
    String pdfVersion = null;
    String prefix = null;
    String signatureWidthString = null;
    String signatureHeightString = null;
    try {
        language = getConfigParameter("language");
        renderQuality = getConfigParameter("renderQuality");
        pdfVersion = getConfigParameter("pdfversion");
        prefix = getConfigParameter("prefix");
        signatureWidthString = getConfigParameter("signatureWidth");
        signatureHeightString = getConfigParameter("signatureHeight");
    } catch (IOException ex) {
        loadSettings();
        return;
    }

    if (pdfVersion == null || prefix == null || signatureWidthString == null || signatureHeightString == null) {
        loadSettings();
        return;
    }

    switch (language) {
    case "en-US":
        Bundle.getBundle().setCurrentLocale(Bundle.Locales.English);
        break;
    case "pt-PT":
        Bundle.getBundle().setCurrentLocale(Bundle.Locales.Portugues);
        break;
    default:
        Bundle.getBundle().setCurrentLocale(Bundle.Locales.English);
    }

    switch (Integer.valueOf(renderQuality)) {
    case 3:
        jComboBox2.setSelectedIndex(0);
        break;
    case 2:
        jComboBox2.setSelectedIndex(1);
        break;
    case 1:
        jComboBox2.setSelectedIndex(2);
        break;
    default:
        jComboBox2.setSelectedIndex(1);
    }

    switch (pdfVersion) {
    case "/1.2":
        jComboBox1.setSelectedIndex(0);
        break;
    case "/1.3":
        jComboBox1.setSelectedIndex(1);
        break;
    case "/1.4":
        jComboBox1.setSelectedIndex(2);
        break;
    case "/1.5":
        jComboBox1.setSelectedIndex(3);
        break;
    case "/1.6":
        jComboBox1.setSelectedIndex(4);
        break;
    case "/1.7":
        jComboBox1.setSelectedIndex(5);
        break;
    default:
        jComboBox1.setSelectedIndex(5);
    }
    int signatureWidth = Integer.parseInt(signatureWidthString);
    int signatureHeight = Integer.parseInt(signatureHeightString);
    tfPrefix.setText(prefix);
    tfHeight.setText(String.valueOf(signatureHeight));
    tfWidth.setText(String.valueOf(signatureWidth));
}

From source file:vn.hieptn.interesttopic.InterestTopicMain.java

private void tabTwitterCollectionStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabTwitterCollectionStateChanged
    // TODO add your handling code here:
    System.out.println("Mo:" + tabTwitterCollection.getSelectedIndex());
    DefaultComboBoxModel modelTopic = (DefaultComboBoxModel) cmboxTopic.getModel();
    modelTopic.removeAllElements();/*from  w w w .  j  a  va 2 s .c o  m*/

    if (tabTwitterCollection.getSelectedIndex() == 2) {
        List<ClassifiedTopicEnt> lstTopic = DataBaseService.GetListDataClassifiedTopic();
        if (lstTopic != null && lstTopic.size() > 0) {
            for (ClassifiedTopicEnt tmpTopic : lstTopic) {
                if (tmpTopic != null) {
                    modelTopic.addElement(tmpTopic.TopicName);
                    ConfigInfo.MAP_TOPIC_REPORT.put(tmpTopic.TopicName, tmpTopic);
                }
            }

            cmboxTopic.setModel(modelTopic);
        }
    }
}

From source file:vn.hieptn.interesttopic.InterestTopicMain.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    List<MainTopicEnt> listMainTopic = DataBaseService.GetListMainTopicEnt();
    DefaultComboBoxModel modelMainTopic = (DefaultComboBoxModel) cmbMainTopicResult.getModel();
    modelMainTopic.removeAllElements();//from w w w .  ja va 2s .c  om

    if (listMainTopic != null && listMainTopic.size() > 0) {
        for (MainTopicEnt tmpMainTopicEnt : listMainTopic) {
            tmpMainTopicEnt.Keyword = "";
            String fileWordmap = ConfigInfo.DIR_DATA_TRAIN + File.separator + tmpMainTopicEnt.TopicName
                    + File.separator + "WordTopic.txt";
            List<String> listWordmap = FunctionUtils.ReadTextFileToList(fileWordmap);
            if (listWordmap != null && listWordmap.size() > 1) {
                tmpMainTopicEnt.NumKeywordNoDuplicate = ConvertUtils.toInt(listWordmap.get(0));
                for (int i = 1; i < listWordmap.size(); i++) {
                    String tmpKeyword = listWordmap.get(i);
                    String[] listWord = StringUtils.split(tmpKeyword, " ");
                    if (!FunctionUtils.IsNullOrEmpty(listWord[0])) {
                        tmpMainTopicEnt.Keyword += listWord[0] + "|";
                    }
                }
            }

            modelMainTopic.addElement(
                    tmpMainTopicEnt.TopicName + ": " + tmpMainTopicEnt.NumKeywordNoDuplicate + " Tu.");
            //Update MainTopicEnt
            DataBaseService.Update(tmpMainTopicEnt);

            List<TrainTopicEnt> lstTopic = DataBaseService.GetListTrainTopic(tmpMainTopicEnt.Id);
            if (lstTopic != null && lstTopic.size() > 0) {
                for (TrainTopicEnt tmpTopic : lstTopic) {
                    if (tmpTopic != null) {
                        ConfigInfo.MAP_TRAIN_TOPIC.put(tmpTopic.TopicName + "|" + tmpMainTopicEnt.Id, tmpTopic);
                    }
                }
            }
        }
    }
    cmbMainTopicResult.setModel(modelMainTopic);
    //Thong Bao Thanh Cong
    JOptionPane.showMessageDialog(null, "Cp Nht File WordTopic Thnh Cng!", "Read File WordTopic",
            JOptionPane.INFORMATION_MESSAGE);
}

From source file:vn.hieptn.interesttopic.InterestTopicMain.java

private void cmbMainTopicResultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbMainTopicResultActionPerformed
    // TODO add your handling code here:
    if (cmbMainTopicResult != null && cmbMainTopicResult.getSelectedItem() != null) {
        String selectedName = StringUtils.split(cmbMainTopicResult.getSelectedItem().toString(), ":")[0];
        MainTopicEnt tmpMainTopicEnt = DataBaseService.GetMainTopicByName(selectedName);
        if (tmpMainTopicEnt != null && tmpMainTopicEnt.Keyword != null) {
            txtWordTopic.setText(tmpMainTopicEnt.Keyword.replaceAll("\\|", " \n"));
        }//from  w  ww.  ja  v  a 2  s.  com

        //Show Cc Topic ca Ch ? ny
        ConfigInfo.cmbMainTopicResult_ID = tmpMainTopicEnt.Id;
        DefaultComboBoxModel modelTopic = (DefaultComboBoxModel) cmbTrainTopic.getModel();
        modelTopic.removeAllElements();
        List<TrainTopicEnt> lstTopic = DataBaseService.GetListTrainTopic(tmpMainTopicEnt.Id);
        if (lstTopic != null && lstTopic.size() > 0) {
            for (TrainTopicEnt tmpTopic : lstTopic) {
                if (tmpTopic != null) {
                    modelTopic.addElement(tmpTopic.TopicName);
                    ConfigInfo.MAP_TRAIN_TOPIC.put(tmpTopic.TopicName + "|" + tmpMainTopicEnt.Id, tmpTopic);
                }
            }

            cmbTrainTopic.setModel(modelTopic);
        }

    }
}