List of usage examples for javax.swing JList getModel
public ListModel<E> getModel()
JList
component. From source file:edu.ku.brc.specify.tasks.DataEntryConfigDlg.java
@Override protected void addItem(final JList list, final Vector<TaskConfigItemIFace> itemList) { // Hash all the names so we can figure out which forms are not used Hashtable<String, Object> hash = new Hashtable<String, Object>(); ListModel model = stdPanel.getOrderModel(); for (int i = 0; i < model.getSize(); i++) { DataEntryView dev = (DataEntryView) model.getElementAt(i); hash.put(dev.getView(), dev);/*from w w w. j a v a 2 s.co m*/ } model = miscPanel.getOrderModel(); for (int i = 0; i < model.getSize(); i++) { DataEntryView dev = (DataEntryView) model.getElementAt(i); hash.put(dev.getView(), dev); } // Add only the unused forms (does NOT return internal views). List<String> uniqueList = new Vector<String>(); List<ViewIFace> views = ((SpecifyAppContextMgr) AppContextMgr.getInstance()).getAllViews(); Hashtable<String, ViewIFace> newAvailViews = new Hashtable<String, ViewIFace>(); for (ViewIFace view : views) { //System.out.println("["+view.getName()+"]["+view.getTitle()+"]"); if (hash.get(view.getName()) == null) { DBTableInfo ti = DBTableIdMgr.getInstance().getByClassName(view.getClassName()); if (ti != null) { if (!ti.isHidden() && !InteractionsTask.isInteractionTable(ti.getTableId())) { hash.put(view.getName(), view); String title = StringUtils.isNotEmpty(view.getObjTitle()) ? view.getObjTitle() : ti != null ? ti.getTitle() : view.getName(); if (newAvailViews.get(title) != null) { title = view.getName(); } uniqueList.add(title); newAvailViews.put(title, view); } } else { System.err.println("DBTableInfo was null for class[" + view.getClassName() + "]"); } } } if (uniqueList.size() == 0) { JOptionPane.showMessageDialog(this, getResourceString("DET_DEV_NONE_AVAIL"), getResourceString("DET_DEV_NONE_AVAIL_TITLE"), JOptionPane.INFORMATION_MESSAGE); return; } Collections.sort(uniqueList); ToggleButtonChooserDlg<String> dlg = new ToggleButtonChooserDlg<String>((Frame) UIRegistry.getTopWindow(), "DET_AVAIL_VIEWS", uniqueList); dlg.setUseScrollPane(true); UIHelper.centerAndShow(dlg); if (!dlg.isCancelled()) { model = list.getModel(); for (String title : dlg.getSelectedObjects()) { ViewIFace view = newAvailViews.get(title); DBTableInfo ti = DBTableIdMgr.getInstance().getByClassName(view.getClassName()); String frmTitle = StringUtils.isNotEmpty(view.getObjTitle()) ? view.getObjTitle() : ti != null ? ti.getTitle() : view.getName(); DataEntryView dev = new DataEntryView(frmTitle, // Title view.getName(), // Name ti != null ? ti.getName() : null, // Icon Name view.getObjTitle(), // ToolTip model.getSize(), // Order true); dev.setTableInfo(ti); ((DefaultListModel) model).addElement(dev); itemList.add(dev); } //pack(); } setHasChanged(true); }
From source file:GUI.MainWindow.java
public void deleteReferences(JTree tree, JList list) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) { return;//from w w w .j a v a 2 s .com } Object obj = node.getUserObject(); if (!(obj instanceof Vulnerability)) { return; } // Get currently selected vulnerability Vulnerability vuln = (Vulnerability) obj; DefaultListModel dlm = (DefaultListModel) list.getModel(); List selected = list.getSelectedValuesList(); for (Object ref_obj : selected) { if (ref_obj instanceof Reference) { Reference ref = (Reference) ref_obj; vuln.deleteReference(ref); dlm.removeElement(ref_obj); System.out.println("Deleted Reference: " + ref); } else { System.out.println("Somehow the references list contained a non-Regerence object"); } } }
From source file:GUI.MainWindow.java
public void addReference(JTree tree, JList list, Reference current) { DefaultMutableTreeNode node = ((DefaultMutableTreeNode) tree.getLastSelectedPathComponent()); if (node == null) { return;/*from w ww . j a v a2s. com*/ } Object obj = node.getUserObject(); if (!(obj instanceof Vulnerability)) { return; // here be monsters, most likely in the merge tree } Vulnerability vuln = (Vulnerability) obj; DefaultListModel dlm = (DefaultListModel) list.getModel(); // Build Input Field and display it JTextField description = new JTextField(); JTextField url = new JTextField(); // If current is not null then pre-set the description and risk if (current != null) { description.setText(current.getDescription()); url.setText(current.getUrl()); } JLabel error = new JLabel( "A valid URL needs to be supplied including the protocol i.e. http://www.github.com"); error.setForeground(Color.red); Object[] message = { "Description:", description, "URL:", url }; String url_string = null; Reference newref = null; while (url_string == null) { int option = JOptionPane.showConfirmDialog(null, message, "Add Reference", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION) { System.out.println("User clicked ok, validating data"); String ref_desc = description.getText(); String ref_url = url.getText(); if (!ref_desc.equals("") || !ref_url.equals("")) { // Both have values // Try to validate URL try { URL u = new URL(url.getText()); u.toURI(); url_string = url.getText(); // Causes loop to end with a valid url } catch (MalformedURLException ex) { url_string = null; //ex.printStackTrace(); } catch (URISyntaxException ex) { url_string = null; //ex.printStackTrace(); } } } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) { System.out.println("User clicked cancel/close"); return; // ends the loop without making any chages } if (url_string == null) { // We need to show an error saying that the url failed to parse Object[] message2 = { error, "Description:", description, "URL:", url }; message = message2; } } // If you get here there is a valid reference URL and description Reference ref = new Reference(description.getText(), url.getText()); if (current == null) { // Add it to the vuln vuln.addReference(ref); // Add it to the GUI dlm.addElement(ref); System.out.println("Valid reference added: " + ref); } else { // Modify it in the vuln vuln.modifyReference(current, ref); // Update the GUI dlm.removeElement(current); dlm.addElement(ref); System.out.println("Valid reference modified: " + ref); } }
From source file:de.main.sessioncreator.DesktopApplication1View.java
public void getAreasBacgroundW(File f) { fileHelper.getAreas(f);//from w ww . j a v a 2 s . c o m Iterator<Map.Entry<String, List>> it = fileHelper.areaMap.entrySet().iterator(); while (it.hasNext()) { DefaultListModel dlm = new DefaultListModel(); JList list = new JList(dlm); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); JScrollPane scrollPane = new JScrollPane(list); scrollPane.getViewport().setView(list); Map.Entry en = it.next(); wizardtabpAreas.addTab(en.getKey().toString().substring(3), scrollPane); for (Object o : fileHelper.areaMap.get(en.getKey().toString())) { dlm.addElement(o); } MouseListener mouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseEvent) { JList tabList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = tabList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = tabList.getModel().getElementAt(index); wizardtaChoosenAreas.append(o.toString() + "\n"); } } } }; list.addMouseListener(mouseListener); ListSelectionListener listListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { JList list = (JList) e.getSource(); if (e.getValueIsAdjusting() == false) { if (list.getSelectedIndex() == -1) { //No selection, disable add button. wizardbtnAddAreas.setEnabled(false); } else { //Selection, enable the add button. wizardbtnAddAreas.setEnabled(true); } } } }; list.addListSelectionListener(listListener); } }
From source file:fr.free.hd.servers.gui.FaceView.java
@Override protected JComponent createControl() { final GridBagLayout layout = new GridBagLayout(); final JPanel view = new JPanel(layout); //Face list// w w w.j a v a 2s .com GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.gridheight = 3; c.weighty = 0.75; c.weightx = 0.15; c.fill = GridBagConstraints.BOTH; final JList facesList = CreateList(); facesList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { if (facesList.getSelectedIndex() != -1) { face = (Face) facesList.getSelectedValue(); updateLabel(); } else { } } } }); view.add(facesList, c); // New button c = new GridBagConstraints(); c.gridx = 0; c.gridy = 3; c.fill = GridBagConstraints.BOTH; JButton btnNew = new JButton("Nouveau"); btnNew.setEnabled(false); view.add(btnNew, c); // Save button c = new GridBagConstraints(); c.gridx = 0; c.gridy = 4; c.fill = GridBagConstraints.BOTH; JButton btnModified = new JButton("Modifier"); btnModified.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { facesDAO.storeFace(face); } }); view.add(btnModified, c); //Draw Face c = new GridBagConstraints(); c.gridx = 1; c.gridy = 0; c.gridheight = 5; c.gridwidth = 1; c.fill = GridBagConstraints.BOTH; c.weightx = 0.60; lblFace = new JLabel(); view.add(lblFace, c); //Hand Panel c = new GridBagConstraints(); c.gridx = 2; c.gridy = 0; c.weightx = 0.15; c.fill = GridBagConstraints.BOTH; JPanel pnlHand = createPosition(); view.add(pnlHand, c); //Mouth Panel c = new GridBagConstraints(); c.gridx = 2; c.gridy = 1; c.weightx = 0.15; c.fill = GridBagConstraints.BOTH; JPanel pnlKind = createKind(); view.add(pnlKind, c); //Mouth Panel c = new GridBagConstraints(); c.gridx = 2; c.gridy = 2; c.weightx = 0.15; c.fill = GridBagConstraints.BOTH; JPanel pnlMouth = createMouth(); view.add(pnlMouth, c); // Picture filename c = new GridBagConstraints(); c.gridx = 0; c.gridy = 5; c.gridwidth = 2; c.fill = GridBagConstraints.BOTH; JTextField txtPath = new JTextField(); view.add(txtPath, c); //Browse Button c = new GridBagConstraints(); c.gridx = 2; c.gridy = 5; c.fill = GridBagConstraints.BOTH; JButton btnBrownse = new JButton("Browse"); view.add(btnBrownse, c); //Select default face if (facesList.getModel().getSize() > 0) { facesList.setSelectedIndex(0); position = HandPositionEnum.HAND_POSITION_MENTON; kind = HandKeyEnum.HAND_KEY_2V; } return view; }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
/** * Updates lists in list panel to display field as the current selection. * /*from ww w. ja v a2 s .c o m*/ * @param field */ protected void displayField(final FieldQRI field) { List<TableTreePathPoint> displayedPath = getCurrentDisplayPath(); List<TableTreePathPoint> fieldPath = field.getTableTree().getPathFromRoot(); if (tableTreeList.size() != listBoxPanel.getComponentCount() - 1) { log.error("tableTreeList and listBoxPanel are out of sync"); } int p = 0; while (p < displayedPath.size() && p < fieldPath.size()) { if (!displayedPath.get(p).equals(fieldPath.get(p))) { break; } p++; } if (!(p == fieldPath.size() && fieldPath.size() == displayedPath.size())) { if (p == fieldPath.size()) { if (p == 1) { fillNextList(tableList); } else { fillNextList(listBoxList.get(p - 2)); } } else { p--; while (p < fieldPath.size() - 1) { JList currList = p < 0 ? tableList : listBoxList.get(p); ListModel model = currList.getModel(); // find and select item in path int i = 0; boolean foundPathItem = false; while (i < model.getSize() && !foundPathItem) { QryListRendererIFace item = (BaseQRI) model.getElementAt(i); if (item.hasChildren()) { TableTree tt = ((BaseQRI) item).getTableTree(); if (fieldPath.get(p + 1).equals(new TableTreePathPoint(tt))) { currList.setSelectedIndex(i); foundPathItem = true; } } i++; } if (foundPathItem) { //fillNextList(currList); p++; } else { log.error("unable to locate field: " + field.getFieldName()); return; } } } } ListModel model = listBoxList.get(fieldPath.size() - 1).getModel(); for (int f = 0; f < model.getSize(); f++) { BaseQRI item = (BaseQRI) model.getElementAt(f); if (item.getTitle().equals(field.getTitle())) { processingLists = true; listBoxList.get(fieldPath.size() - 1).setSelectedIndex(f); listBoxList.get(fieldPath.size() - 1).ensureIndexIsVisible(f); processingLists = false; break; } } }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
protected void updateUIAfterAddOrMap(final FieldQRI fieldQRI, final QueryFieldPanel qfp, final boolean loading, final boolean isAdd, final boolean isSchemaMapping) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (currentInx > -1) { if (isAdd) { queryFieldsPanel.add(qfp); queryFieldsPanel.validate(); }//from w w w . ja v a 2s . c o m if (fieldQRI instanceof RelQRI) { BaseQRI qri = fieldQRI.getTable(); for (JList lb : listBoxList) { if (lb.isVisible()) { if (((DefaultListModel) lb.getModel()).contains(qri)) { lb.repaint(); } } } } else { listBoxList.get(currentInx).repaint(); } updateAddBtnState(); selectQFP(qfp); updateSmushBtn(); queryFieldsPanel.repaint(); if (!loading) { setSaveBtnEnabled(canSave(isSchemaMapping)); updateSearchBtn(); } //Sorry, but a new context can't be selected if any fields are selected from the current context. tableList.setEnabled(queryFieldItems.size() == 0); if (fieldQRI instanceof TreeLevelQRI && distinctChk.isSelected() && countOnly) { countOnly = false; countOnlyChk.setSelected(false); UIRegistry.displayLocalizedStatusBarText("QB_NO_COUNT_WITH_DISTINCT_WITH_TREELEVEL"); } else { UIRegistry.displayStatusBarText(null); } } } }); }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
/** * Removes it from the List.//w w w . j a va 2s.co m * * @param qfp QueryFieldPanel to be removed */ public void removeQueryFieldItem(final QueryFieldPanel qfp) { //refreshQuery(); if (query.getReports().size() > 0) { CustomDialog cd = new CustomDialog((Frame) UIRegistry.getTopWindow(), UIRegistry.getResourceString("REP_CONFIRM_DELETE_TITLE"), true, CustomDialog.OKCANCELHELP, new QBReportInfoPanel(query, UIRegistry.getResourceString("QB_USED_BY_REP_FLD_DELETE_CONFIRM"))); cd.setHelpContext("QBFieldRemovedAndReports"); UIHelper.centerAndShow(cd); cd.dispose(); if (cd.isCancelled()) { return; } } if (qfp.getFieldQRI() != null) { qfp.getFieldQRI().setIsInUse(false); } if (qfp.getQueryField() != null) { //query.removeReference(qfp.getQueryField(), "fields"); removeFieldFromQuery(qfp.getQueryField()); if (qfp.getItemMapping() != null) { removeSchemaItemMapping(qfp.getItemMapping()); } } final FieldQRI qfpqri = qfp.getFieldQRI(); queryFieldItems.remove(qfp); //XXX field label qualification issues for schema maps?? qualifyFieldLabels(); SwingUtilities.invokeLater(new Runnable() { public void run() { if (selectedQFP == qfp) { selectQFP(null); } queryFieldsPanel.getLayout().removeLayoutComponent(qfp); queryFieldsPanel.remove(qfp); queryFieldsPanel.validate(); updateAddBtnState(); // Sorry, but a new context can't be selected if any fields // are selected from the current context. tableList.setEnabled(queryFieldItems.size() == 0); try { BaseQRI qri = qfpqri instanceof RelQRI ? qfpqri.getTable() : qfpqri; //BaseQRI qri = qfp.getFieldQRI(); boolean done = false; for (JList lb : listBoxList) { if (lb.isVisible()) { for (int i = 0; i < ((DefaultListModel) lb.getModel()).getSize(); i++) { BaseQRI qriI = (BaseQRI) ((DefaultListModel) lb.getModel()).getElementAt(i); if (qriI != null) { boolean match = qriI == qri; if (!match) { match = buildFieldQRI(qri).getStringId() .equals(buildFieldQRI(qriI).getStringId()); } if (match) { qriI.setIsInUse(false); lb.repaint(); done = true; break; } } } } if (done) { break; } } } catch (Exception ex) { UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(QueryBldrPane.class, ex); log.error(ex); } queryFieldsPanel.repaint(); setSaveBtnEnabled(thereAreItems() && canSave()); updateSearchBtn(); updateSmushBtn(); UIRegistry.displayStatusBarText(null); } }); }
From source file:edu.ku.brc.af.ui.forms.FormViewObj.java
/** * Sets the appropriate index in the list box * @param list the list box//from www. j av a 2s. c om * @param data the data value */ protected static void setListValue(final JList list, final Object data) { Iterator<?> iter = null; if (data instanceof Set<?>) { iter = ((Set<?>) data).iterator(); } else if (data instanceof org.hibernate.collection.PersistentSet) { iter = ((org.hibernate.collection.PersistentSet) data).iterator(); } if (iter != null) { DefaultListModel defModel = new DefaultListModel(); while (iter.hasNext()) { defModel.addElement(iter.next()); } list.setModel(defModel); } else { ListModel model = list.getModel(); for (int i = 0; i < model.getSize(); i++) { Object item = model.getElementAt(i); if (item instanceof String) { if (((String) item).equals(data)) { list.setSelectedIndex(i); return; } } else if (item.equals(data)) { list.setSelectedIndex(i); return; } } } }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
/** * @param parentList/*from w w w .j av a 2s. c o m*/ */ protected void fillNextList(final JList parentList) { if (processingLists) { return; } processingLists = true; final int curInx = listBoxList.indexOf(parentList); if (curInx > -1) { int startSize = listBoxPanel.getComponentCount(); for (int i = curInx + 1; i < listBoxList.size(); i++) { listBoxPanel.remove(spList.get(i)); } int removed = startSize - listBoxPanel.getComponentCount(); for (int i = 0; i < removed; i++) { tableTreeList.remove(tableTreeList.size() - 1); } } else { listBoxPanel.removeAll(); tableTreeList.clear(); } QryListRendererIFace item = (QryListRendererIFace) parentList.getSelectedValue(); if (item instanceof ExpandableQRI) { JList newList; DefaultListModel model; JScrollPane sp; if (curInx == listBoxList.size() - 1) { newList = new JList(model = new DefaultListModel()); newList.addMouseListener(new MouseAdapter() { /* (non-Javadoc) * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) */ @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { if (currentInx != -1) { JList list = (JList) e.getSource(); QryListRendererIFace qriFace = (QryListRendererIFace) list.getSelectedValue(); if (BaseQRI.class.isAssignableFrom(qriFace.getClass())) { BaseQRI qri = (BaseQRI) qriFace; if (qri.isInUse()) { //remove the field for (QueryFieldPanel qfp : QueryBldrPane.this.queryFieldItems) { FieldQRI fqri = qfp.getFieldQRI(); if (fqri == qri || (fqri instanceof RelQRI && fqri.getTable() == qri)) { boolean clearIt = qfp.getSchemaItem() != null; QueryBldrPane.this.removeQueryFieldItem(qfp); if (clearIt) { qfp.setField(null, null); } break; } } } else { // add the field 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; } } } } } } }); newList.setCellRenderer(qryRenderer); listBoxList.add(newList); sp = new JScrollPane(newList, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); JLabel colHeader = UIHelper.createLabel(item.getTitle()); colHeader.setHorizontalAlignment(SwingConstants.CENTER); colHeader.setBackground(listBoxPanel.getBackground()); colHeader.setOpaque(true); sp.setColumnHeaderView(colHeader); spList.add(sp); newList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { fillNextList(listBoxList.get(curInx + 1)); } } }); } else { newList = listBoxList.get(curInx + 1); model = (DefaultListModel) newList.getModel(); sp = spList.get(curInx + 1); JLabel colHeaderLbl = (JLabel) sp.getColumnHeader().getComponent(0); if (item instanceof TableQRI) { colHeaderLbl.setText(((TableQRI) item).getTitle()); } else { colHeaderLbl.setText(getResourceString("QueryBldrPane.QueryFields")); } } createNewList((TableQRI) item, model); listBoxPanel.remove(addBtn); listBoxPanel.add(sp); tableTreeList.add(((ExpandableQRI) item).getTableTree()); listBoxPanel.add(addBtn); currentInx = -1; } else { listBoxPanel.add(addBtn); } SwingUtilities.invokeLater(new Runnable() { public void run() { updateAddBtnState(); // Is all this really necessary listBoxPanel.validate(); listBoxPanel.repaint(); scrollPane.validate(); scrollPane.invalidate(); scrollPane.doLayout(); scrollPane.repaint(); validate(); invalidate(); doLayout(); repaint(); UIRegistry.forceTopFrameRepaint(); } }); processingLists = false; currentInx = curInx; }