List of usage examples for javax.swing DefaultListModel addElement
public void addElement(E element)
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
/** * create the query builder UI.//from w w w . j ava 2 s . com */ protected void createUI() { removeAll(); JMenuItem saveItem = new JMenuItem(UIRegistry.getResourceString("QB_SAVE")); Action saveActionListener = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (saveQuery(false)) { try { String selId = null; if (selectedQFP != null && selectedQFP.getQueryField() != null) { selId = selectedQFP.getQueryField().getStringId(); } final String selectedFldId = selId; setupUI(true); SwingUtilities.invokeLater(new Runnable() { /* (non-Javadoc) * @see java.lang.Runnable#run() */ @Override public void run() { if (selectedFldId != null) { for (QueryFieldPanel qfp : queryFieldItems) { if (qfp.getQueryField() != null && selectedFldId.equals(qfp.getQueryField().getStringId())) { selectQFP(qfp); return; } } selectQFP(queryFieldItems.get(0)); } } }); } catch (Exception ex) { } setSaveBtnEnabled(false); } } }; saveItem.addActionListener(saveActionListener); JMenuItem saveAsItem = new JMenuItem(UIRegistry.getResourceString("QB_SAVE_AS")); Action saveAsActionListener = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (saveQuery(true)) { setSaveBtnEnabled(false); } } }; saveAsItem.addActionListener(saveAsActionListener); JComponent[] itemSample = { saveItem, saveAsItem }; saveBtn = new DropDownButton(UIRegistry.getResourceString("QB_SAVE"), null, 1, java.util.Arrays.asList(itemSample)); saveBtn.addActionListener(saveActionListener); String ACTION_KEY = "SAVE"; KeyStroke ctrlS = KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); InputMap inputMap = saveBtn.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(ctrlS, ACTION_KEY); ActionMap actionMap = saveBtn.getActionMap(); actionMap.put(ACTION_KEY, saveActionListener); ACTION_KEY = "SAVE_AS"; KeyStroke ctrlA = KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); inputMap.put(ctrlA, ACTION_KEY); actionMap.put(ACTION_KEY, saveAsActionListener); saveBtn.setActionMap(actionMap); UIHelper.setControlSize(saveBtn); //saveBtn.setOverrideBorder(true, BasicBorders.getButtonBorder()); listBoxPanel = new JPanel(new HorzLayoutManager(2, 2)); Vector<TableQRI> list = new Vector<TableQRI>(); for (int k = 0; k < tableTree.getKids(); k++) { list.add(tableTree.getKid(k).getTableQRI()); } Collections.sort(list); DefaultListModel model = new DefaultListModel(); for (TableQRI qri : list) { model.addElement(qri); } tableList = new JList(model); QryListRenderer qr = new QryListRenderer(IconManager.IconSize.Std16); qr.setDisplayKidIndicator(false); tableList.setCellRenderer(qr); JScrollPane spt = new JScrollPane(tableList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); Dimension pSize = spt.getPreferredSize(); pSize.height = 200; spt.setPreferredSize(pSize); JPanel topPanel = new JPanel(new BorderLayout()); scrollPane = new JScrollPane(listBoxPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); tableList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int inx = tableList.getSelectedIndex(); if (inx > -1) { fillNextList(tableList); } else { listBoxPanel.removeAll(); } } } }); addBtn = new JButton(IconManager.getImage("PlusSign", IconManager.IconSize.Std16)); addBtn.setEnabled(false); addBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { BaseQRI qri = (BaseQRI) listBoxList.get(currentInx).getSelectedValue(); if (qri.isInUse) { return; } try { FieldQRI fieldQRI = buildFieldQRI(qri); if (fieldQRI == null) { throw new Exception("null FieldQRI"); } SpQueryField qf = new SpQueryField(); qf.initialize(); qf.setFieldName(fieldQRI.getFieldName()); qf.setStringId(fieldQRI.getStringId()); query.addReference(qf, "fields"); if (!isExportMapping) { addQueryFieldItem(fieldQRI, qf, false); } else { addNewMapping(fieldQRI, qf, null, false); } } catch (Exception ex) { log.error(ex); UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(QueryBldrPane.class, ex); return; } } }); contextPanel = new JPanel(new BorderLayout()); contextPanel.add(createLabel("Search Context", SwingConstants.CENTER), BorderLayout.NORTH); // I18N contextPanel.add(spt, BorderLayout.CENTER); contextPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); JPanel schemaPanel = new JPanel(new BorderLayout()); schemaPanel.add(scrollPane, BorderLayout.CENTER); topPanel.add(contextPanel, BorderLayout.WEST); topPanel.add(schemaPanel, BorderLayout.CENTER); add(topPanel, BorderLayout.NORTH); queryFieldsPanel = new JPanel(); queryFieldsPanel.setLayout(new NavBoxLayoutManager(0, 2)); queryFieldsScroll = new JScrollPane(queryFieldsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); queryFieldsScroll.setBorder(null); add(queryFieldsScroll); //if (!isExportMapping) //{ final JPanel mover = buildMoverPanel(false); add(mover, BorderLayout.EAST); // } String searchLbl = schemaMapping == null ? getResourceString("QB_SEARCH") : getResourceString("QB_EXPORT_PREVIEW"); searchBtn = createButton(searchLbl); searchBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { // int m = ae.getModifiers(); // boolean ors = (m & ActionEvent.ALT_MASK) > 0 && (m & ActionEvent.CTRL_MASK) > 0 && (m & ActionEvent.SHIFT_MASK) > 0; // if (ors) // { // System.out.println("Disjunctional conjoinment desire gesture detected"); // } // doSearch(ors); doSearch(false); } }); distinctChk = createCheckBox(UIRegistry.getResourceString("QB_DISTINCT")); distinctChk.setVisible(schemaMapping == null); if (schemaMapping == null) { distinctChk.setSelected(false); distinctChk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { new SwingWorker() { /* (non-Javadoc) * @see edu.ku.brc.helpers.SwingWorker#construct() */ @Override public Object construct() { if (distinctChk.isSelected()) { UsageTracker.incrUsageCount("QB.DistinctOn"); } else { UsageTracker.incrUsageCount("QB.DistinctOff"); } if ((isTreeLevelSelected() || isAggFieldSelected()) && countOnly && distinctChk.isSelected()) { countOnlyChk.setSelected(false); countOnly = false; } query.setCountOnly(countOnly); query.setSelectDistinct(distinctChk.isSelected()); setSaveBtnEnabled(thereAreItems()); return null; } }.start(); } }); } countOnlyChk = createCheckBox(UIRegistry.getResourceString("QB_COUNT_ONLY")); countOnlyChk.setSelected(false); countOnlyChk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { new SwingWorker() { /* (non-Javadoc) * @see edu.ku.brc.helpers.SwingWorker#construct() */ @Override public Object construct() { //Don't allow change while query is running. if (runningResults.get() == null) { countOnly = !countOnly; if (countOnly) { UsageTracker.incrUsageCount("QB.CountOnlyOn"); } else { UsageTracker.incrUsageCount("QB.CountOnlyOff"); } if ((isTreeLevelSelected() || isAggFieldSelected()) && countOnly && (distinctChk.isSelected() || searchSynonymyChk.isSelected())) { distinctChk.setSelected(false); searchSynonymyChk.setSelected(false); } } else { //This might be awkward and/or klunky... countOnlyChk.setSelected(countOnly); } query.setCountOnly(countOnly); query.setSelectDistinct(distinctChk.isSelected()); setSaveBtnEnabled(thereAreItems()); return null; } }.start(); } }); searchSynonymyChk = createCheckBox(UIRegistry.getResourceString("QB_SRCH_SYNONYMS")); searchSynonymyChk.setSelected(searchSynonymy); searchSynonymyChk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { new SwingWorker() { /* (non-Javadoc) * @see edu.ku.brc.helpers.SwingWorker#construct() */ @Override public Object construct() { searchSynonymy = !searchSynonymy; if (!searchSynonymy) { UsageTracker.incrUsageCount("QB.SearchSynonymyOff"); } else { UsageTracker.incrUsageCount("QB.SearchSynonymyOn"); } if (isTreeLevelSelected() && countOnly && searchSynonymyChk.isSelected()) { countOnlyChk.setSelected(false); countOnly = false; } query.setSearchSynonymy(searchSynonymy); setSaveBtnEnabled(thereAreItems()); return null; } }.start(); } }); smushedChk = createCheckBox(UIRegistry.getResourceString("QB_SMUSH_RESULTS")); smushedChk.setVisible(isSmushableContext()); if (isSmushableContext()) { smushedChk.setSelected(smushed); smushedChk.setToolTipText( String.format(UIRegistry.getResourceString("QB_SMUSH_RESULTS_HINT"), getCatalogNumberTitle())); smushedChk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { new SwingWorker() { /* * (non-Javadoc) * * @see edu.ku.brc.helpers.SwingWorker#construct() */ @Override public Object construct() { smushed = !smushed; if (!smushed) { UsageTracker.incrUsageCount("QB.SmushedOff"); } else { UsageTracker.incrUsageCount("QB.SmushedOn"); } query.setSmushed(smushed); setSaveBtnEnabled(thereAreItems()); return null; } }.start(); } }); } PanelBuilder outer = new PanelBuilder( new FormLayout("p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 6dlu, p", "p")); CellConstraints cc = new CellConstraints(); outer.add(smushedChk, cc.xy(1, 1)); outer.add(searchSynonymyChk, cc.xy(3, 1)); outer.add(distinctChk, cc.xy(5, 1)); outer.add(countOnlyChk, cc.xy(7, 1)); outer.add(searchBtn, cc.xy(9, 1)); outer.add(saveBtn, cc.xy(11, 1)); JPanel bottom = new JPanel(new BorderLayout()); bottom.add(outer.getPanel(), BorderLayout.EAST); JButton helpBtn = UIHelper.createHelpIconButton(getHelpBtnContext()); bottom.add(helpBtn, BorderLayout.WEST); add(bottom, BorderLayout.SOUTH); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
/** * @param parentQRI//from ww w .j av a 2 s. c o m * @param tableTree * @param model */ protected void createNewList(final TableQRI tblQRI, final DefaultListModel model) { model.clear(); if (tblQRI != null) { Vector<BaseQRI> sortList = new Vector<BaseQRI>(); for (int f = 0; f < tblQRI.getFields(); f++) { if (!tblQRI.getField(f).isFieldHidden()) { sortList.add(tblQRI.getField(f)); } } for (int k = 0; k < tblQRI.getTableTree().getKids(); k++) { boolean addIt; TableTree kidK = tblQRI.getTableTree().getKid(k); if (kidK.isAlias()) { // if (!fixAliases(kidK, tableTreeHash)) // { // addIt = false; // } // else // { // addIt = tblIsDisplayable(kidK, tableTreeHash.get(kidK.getName()) // .getTableInfo()); // } addIt = tblIsDisplayable(kidK, tableTreeHash.get(kidK.getName()).getTableInfo()) && fixAliases(kidK, tableTreeHash); } else { addIt = !kidK.getTableInfo().isHidden() && tblIsDisplayable(kidK, kidK.getTableInfo()); } if (addIt) { if (kidK.getTableQRI().getRelationship() == null || !kidK.getTableQRI().getRelationship().isHidden()) { sortList.add(tblQRI.getTableTree().getKid(k).getTableQRI()); } } } Collections.sort(sortList); checkFldUsage(tblQRI.getTableTree(), sortList); for (QryListRendererIFace qri : sortList) { model.addElement(qri); } } }
From source file:com.peterbochs.PeterBochsDebugger.java
private void updateStack() { try {/* ww w .j a v a 2 s .c o m*/ jStatusLabel.setText("Updating stack"); // commandReceiver.setCommandNoOfLine(512); commandReceiver.clearBuffer(); commandReceiver.shouldShow = false; sendCommand("print-stack 40"); String result = commandReceiver.getCommandResultUntilHaveLines(40); String[] lines = result.split("\n"); registerPanel.jStackList.removeAll(); jStatusProgressBar.setMaximum(lines.length - 1); DefaultListModel model = new DefaultListModel(); for (int y = 1; y < lines.length; y++) { try { jStatusProgressBar.setValue(y); String[] b = lines[y].split("[\\[\\]]"); model.addElement(b[1]); jStatusLabel.setText("Updating stack " + y + "/" + (lines.length - 1)); } catch (Exception ex2) { } } registerPanel.jStackList.setModel(model); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:src.gui.ItSIMPLE.java
public void setStateMachineList(Element project) { if (project != null) { stateMachinesList.clear();// w ww . ja v a 2s .co m DefaultListModel model = (DefaultListModel) stateMachineJList.getModel(); model.removeAllElements(); List<?> stateMachines = project.getChild("diagrams").getChild("stateMachineDiagrams") .getChildren("stateMachineDiagram"); Iterator<?> stateMachinesIter = stateMachines.iterator(); while (stateMachinesIter.hasNext()) { Element stateMachine = (Element) stateMachinesIter.next(); model.addElement(stateMachine.getChildText("name")); stateMachinesList.add((Element) stateMachine.clone()); } } }
From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ApplicationProperties.java
private void setupForm(final String settingsPath) { this.setTitle("System Properties"); try {/*from ww w. ja v a 2 s . c o m*/ theFormControl = new FormControl(this, settingsPath); } catch (Exception ex) { LOG.error("Error loading form parameters", ex); } // Set fonts isSystemChange = true; final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); final Font[] fonts = env.getAllFonts(); DefaultListModel model = new DefaultListModel(); for (int i = 0; i < fonts.length; i++) { final Font font = fonts[i]; model.add(i, font.getName()); } lstFont.setModel(model); // Set styles model = new DefaultListModel(); model.addElement("Plain"); model.addElement("Bold"); model.addElement("Italic"); model.addElement("Bold Italic"); lstStyle.setModel(model); // Set sizes model = new DefaultListModel(); model.addElement("8"); model.addElement("10"); model.addElement("12"); model.addElement("14"); model.addElement("18"); model.addElement("20"); model.addElement("22"); model.addElement("24"); lstSize.setModel(model); txtFontSize.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(final DocumentEvent e) { updateFontSize(); } public void removeUpdate(final DocumentEvent e) { updateFontSize(); } public void insertUpdate(final DocumentEvent e) { updateFontSize(); } }); model = new DefaultListModel(); for (String favourite : personalSettings.getFavourites()) { model.addElement(favourite); } lstFavourites.setModel(model); model = new DefaultListModel(); for (PersonalSettings.FileDescriptions descriptions : personalSettings.getFilesToIgnore()) { model.addElement(descriptions); } lstFilesToIgnore.setModel(model); final DefaultComboBoxModel cmbModel = new DefaultComboBoxModel(); for (PersonalSettings.TextPosition position : PersonalSettings.TextPosition.values()) { cmbModel.addElement(position); } cmbTextPosition.setModel(cmbModel); chkSortRunning.setSelected(personalSettings.isSortRunningAscending()); chkSortPending.setSelected(personalSettings.isSortPendingAscending()); chkSortFailed.setSelected(personalSettings.isSortFailedAscending()); chkSortDeposited.setSelected(personalSettings.isSortDepositedAscending()); chkSortComplete.setSelected(personalSettings.isSortCompleteAscending()); txtNoOfRetries.setText(String.format("%d", personalSettings.getNoOfRetries())); isSystemChange = false; }
From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ApplicationProperties.java
private void addFavourite() { final JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Select favourite directory"); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); final int result = fc.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { final DefaultListModel model = (DefaultListModel) lstFavourites.getModel(); model.addElement(fc.getSelectedFile().getAbsolutePath()); }/* w w w. j av a2 s . c o m*/ checkButtons(); }
From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ApplicationProperties.java
private void addFileToIgnore() { final PersonalSettings.TextPosition textPosition = (PersonalSettings.TextPosition) cmbTextPosition .getSelectedItem();/*from www . j a v a 2 s.co m*/ final PersonalSettings.FileDescriptions description = PersonalSettings.FileDescriptions.create(textPosition, txtTextToLookFor.getText()); final DefaultListModel model = (DefaultListModel) lstFilesToIgnore.getModel(); model.addElement(description); txtTextToLookFor.setText(""); cmbTextPosition.setSelectedIndex(0); checkButtons(); }
From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.DuplicateFiles.java
private void showMissingFiles() { final DefaultListModel model = new DefaultListModel(); lstDuplicateFiles.setModel(model);//from w w w . j a va 2 s. c o m for (String fileName : theDuplicateFiles) { model.addElement(fileName); } }
From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.MissingFiles.java
private void showMissingFiles() { final DefaultListModel model = new DefaultListModel(); lstMissingFiles.setModel(model);/* ww w . j av a 2s . c o m*/ for (FileSystemObject fso : theMissingFiles) { model.addElement(fso.getFullPath()); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
private void loadProducersList() { try {/*from w w w .j av a2 s .c om*/ LOG.debug("loadProducersList, start"); DefaultListModel model; if (theProducerList.getModel() instanceof DefaultListModel) { model = (DefaultListModel) theProducerList.getModel(); model.clear(); } else { model = new DefaultListModel(); } LOG.debug("loadProducersList, Before create deposit"); IDeposit deposit = applicationProperties.getApplicationData().getDeposit(); producers = deposit.getProducers(applicationProperties.getLoggedOnUser()); LOG.debug("loadProducersList, After get list"); for (Producer data : producers) { model.addElement(data); } theProducerList.setModel(model); theProducerList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { lstProducersValueChanged(evt); } }); theProducerList.repaint(); LOG.debug("loadProducersList, end"); } catch (Exception ex) { manualDepositFrame.showError("Error loading producers", "Unable to load producer list", ex); reportException(ex); } }