List of usage examples for javax.swing DefaultListModel addElement
public void addElement(E element)
From source file:ome.formats.importer.gui.HistoryTableStore.java
public DefaultListModel getBaseTableDataByDate(Date start, Date end) { try {// w w w. j a v a 2s.co m // Format the current time. String dayString, hourString, status; long uid = 0L, importTime = 0L; String icon; DefaultListModel list = new DefaultListModel(); String searchString = "(DateTime>=" + start.getTime() + ") & (DateTime<=" + end.getTime() + ")"; long[] ids = baseTable.getWhereList(searchString, null, 0, baseTable.getNumberOfRows(), 1); int returnedRows = ids.length; if (DEBUG) log.debug("getBaseTableDataByDate returned rows: " + returnedRows); Data d = getBaseTableData(); if (d == null) { log.error("Error retrieving base table data."); return new DefaultListModel(); } LongColumn uids = (LongColumn) d.columns[BASE_UID_COLUMN]; LongColumn importTimes = (LongColumn) d.columns[BASE_DATETIME_COLUMN]; StringColumn statuses = (StringColumn) d.columns[BASE_STATUS_COLUMN]; for (int h = 0; h < returnedRows; h++) { int i = (int) ids[h]; try { uid = uids.values[i]; importTime = importTimes.values[i]; status = statuses.values[i].trim(); } catch (ArrayIndexOutOfBoundsException e) { System.err.println("ids[" + h + "] not found in dataset."); continue; } if (status.equals("complete")) icon = "gfx/import_done_16.png"; else icon = "gfx/warning_msg16.png"; dayString = day.format(new Date(importTime)); hourString = hour.format(new Date(importTime)); if (day.format(new Date()).equals(dayString)) dayString = "Today"; if (day.format(getYesterday()).equals(dayString)) { dayString = "Yesterday"; } ImportEntry entry = new ImportEntry(dayString + " " + hourString, icon, (int) uid); list.addElement(entry); } return list; } catch (Exception e) { String s = String.format("Error retrieving base list from %s to %s.", start.toString(), end.toString()); log.error(s, e); } return new DefaultListModel(); // return empty defaultlist }
From source file:op.tools.SYSTools.java
public static DefaultListModel list2dlm(List list) { DefaultListModel dlm = new DefaultListModel(); if (list != null) { for (Object o : list) { dlm.addElement(o); }//from ww w . j a v a2 s . c o m } return dlm; }
From source file:op.tools.SYSTools.java
public static DefaultListModel cmb2lst(DefaultComboBoxModel dcbm) { DefaultListModel dlm = new DefaultListModel(); for (int i = 0; i < dcbm.getSize(); i++) { dlm.addElement(dcbm.getElementAt(i)); }/*from w w w . ja v a 2 s.c o m*/ return dlm; }
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java
@Override public void refreshView(final ViewState state) { this.removeAll(); tableMenu = new JPopupMenu("TableMenu"); this.add(tableMenu); override = new JMenuItem(OVERRIDE); override.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition()); String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state); Metadata staticMet = state.getSelected().getModel().getStaticMetadata(); if (staticMet == null) { staticMet = new Metadata(); }//from w w w . j av a2s . c o m if (e.getActionCommand().equals(OVERRIDE)) { if (!staticMet.containsKey(key)) { staticMet.addMetadata(key, (String) DefaultPropView.this.table.getValueAt(row, 2)); String envReplace = (String) DefaultPropView.this.table.getValueAt(row, 3); if (Boolean.valueOf(envReplace)) { staticMet.addMetadata(key + "/envReplace", envReplace); } state.getSelected().getModel().setStaticMetadata(staticMet); DefaultPropView.this.notifyListeners(); } } } }); delete = new JMenuItem(DELETE); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition()); String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state); Metadata staticMet = state.getSelected().getModel().getStaticMetadata(); if (staticMet == null) { staticMet = new Metadata(); } staticMet.removeMetadata(key); staticMet.removeMetadata(key + "/envReplace"); state.getSelected().getModel().setStaticMetadata(staticMet); DefaultPropView.this.notifyListeners(); } }); tableMenu.add(override); tableMenu.add(delete); if (state.getSelected() != null) { JPanel masterPanel = new JPanel(); masterPanel.setLayout(new BoxLayout(masterPanel, BoxLayout.Y_AXIS)); masterPanel.add(this.getModelIdPanel(state.getSelected(), state)); masterPanel.add(this.getModelNamePanel(state.getSelected(), state)); if (!state.getSelected().getModel().isParentType()) { masterPanel.add(this.getInstanceClassPanel(state.getSelected(), state)); } masterPanel.add(this.getExecutionTypePanel(state.getSelected(), state)); masterPanel.add(this.getPriorityPanel(state)); masterPanel.add(this.getExecusedIds(state.getSelected())); if (state.getSelected().getModel().getExecutionType().equals("condition")) { masterPanel.add(this.getTimeout(state.getSelected(), state)); masterPanel.add(this.getOptional(state.getSelected(), state)); } JScrollPane scrollPane = new JScrollPane(table = this.createTable(state), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.getHorizontalScrollBar().setUnitIncrement(10); scrollPane.getVerticalScrollBar().setUnitIncrement(10); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBorder(new EtchedBorder()); final JLabel metLabel = new JLabel("Static Metadata"); metLabel.setAlignmentX(Component.CENTER_ALIGNMENT); final JLabel extendsLabel = new JLabel("<extends>"); extendsLabel.setFont(new Font("Serif", Font.PLAIN, 10)); extendsLabel.setAlignmentX(Component.CENTER_ALIGNMENT); extendsLabel.addMouseListener(new MouseListener() { private JScrollPane availableScroller; private JScrollPane mineScroller; private JList mineList; private JList availableList; private DefaultListModel mineModel; private DefaultListModel availableModel; public void mouseClicked(MouseEvent e) { final JPopupMenu popup = new JPopupMenu(); popup.setLayout(new BorderLayout()); JPanel main = new JPanel(); main.setLayout(new BoxLayout(main, BoxLayout.X_AXIS)); JPanel mine = new JPanel(); mine.setBorder(new EtchedBorder()); mine.setLayout(new BorderLayout()); JLabel mineLabel = new JLabel("Mine"); mineScroller = new JScrollPane(mineList = createJList(mineModel = new DefaultListModel(), state.getSelected().getModel().getExtendsConfig())); mineScroller.setPreferredSize(new Dimension(250, 80)); mine.add(mineLabel, BorderLayout.NORTH); mine.add(mineScroller, BorderLayout.CENTER); JPanel available = new JPanel(); available.setBorder(new EtchedBorder()); available.setLayout(new BorderLayout()); JLabel availableLabel = new JLabel("Available"); Vector<String> availableGroups = new Vector<String>(state.getGlobalConfigGroups().keySet()); availableGroups.removeAll(state.getSelected().getModel().getExtendsConfig()); availableScroller = new JScrollPane(availableList = this .createJList(availableModel = new DefaultListModel(), availableGroups)); availableScroller.setPreferredSize(new Dimension(250, 80)); available.add(availableLabel, BorderLayout.NORTH); available.add(availableScroller, BorderLayout.CENTER); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.Y_AXIS)); JButton addButton = new JButton("<---"); addButton.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { String selected = availableList.getSelectedValue().toString(); Vector<String> extendsConfig = new Vector<String>( state.getSelected().getModel().getExtendsConfig()); extendsConfig.add(selected); state.getSelected().getModel().setExtendsConfig(extendsConfig); availableModel.remove(availableList.getSelectedIndex()); mineModel.addElement(selected); popup.revalidate(); DefaultPropView.this.notifyListeners(); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); JButton removeButton = new JButton("--->"); removeButton.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { String selected = mineList.getSelectedValue().toString(); Vector<String> extendsConfig = new Vector<String>( state.getSelected().getModel().getExtendsConfig()); extendsConfig.remove(selected); state.getSelected().getModel().setExtendsConfig(extendsConfig); mineModel.remove(mineList.getSelectedIndex()); availableModel.addElement(selected); popup.revalidate(); DefaultPropView.this.notifyListeners(); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); buttons.add(addButton); buttons.add(removeButton); main.add(mine); main.add(buttons); main.add(available); popup.add(main, BorderLayout.CENTER); popup.show(extendsLabel, e.getX(), e.getY()); } public void mouseEntered(MouseEvent e) { extendsLabel.setForeground(Color.blue); } public void mouseExited(MouseEvent e) { extendsLabel.setForeground(Color.black); } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } private JList createJList(DefaultListModel model, final List<String> list) { for (String value : list) { model.addElement(value); } JList jList = new JList(model); jList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); jList.setLayoutOrientation(JList.VERTICAL); return jList; } }); JLabel metGroupLabel = new JLabel("(Sub-Group: " + (state.getCurrentMetGroup() != null ? state.getCurrentMetGroup() : "<base>") + ")"); metGroupLabel.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel labelPanel = new JPanel(); labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS)); JPanel top = new JPanel(); top.setLayout(new BoxLayout(top, BoxLayout.Y_AXIS)); top.add(extendsLabel); top.add(metLabel); labelPanel.add(top); labelPanel.add(metGroupLabel); panel.add(labelPanel, BorderLayout.NORTH); panel.add(scrollPane, BorderLayout.CENTER); masterPanel.add(panel); this.add(masterPanel); } else { this.add(new JPanel()); } this.revalidate(); }
From source file:org.cloudml.ui.graph.Visu.java
public DefaultListModel fillList() { DefaultListModel lm = new DefaultListModel(); for (ExternalComponent n : dmodel.getComponents().onlyExternals()) { lm.addElement(n.getName()); }/* w ww. j a v a 2 s . c om*/ for (Component n : dmodel.getComponents()) { lm.addElement(n.getName()); } for (Relationship b : dmodel.getRelationships()) { lm.addElement(b.getName()); } return lm; }
From source file:org.executequery.gui.editor.ManageShortcutsPanel.java
public void addShortcut() { EditorSQLShortcut shortcut = new EditorSQLShortcut(); shortcut.setShortcut(bundleString("newShortcutName")); shortcut.setQuery(Constants.EMPTY);/*from ww w .ja va 2 s .c o m*/ DefaultListModel model = modelFromList(); model.addElement(shortcut); int index = model.indexOf(shortcut); list.setSelectedIndex(index); list.scrollRectToVisible(list.getCellBounds(index, index)); listEditingAction().actionPerformed(actionEventForEdit()); }
From source file:org.feistymeow.dragdrop.dragdrop_list_test.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public dragdrop_list_test(String startPath) { super("dragdrop_test"); // Create the list and put it in a scroll pane list = new DraggableDroppableList(); DefaultListModel listModel = (DefaultListModel) list.getModel(); list.setCellRenderer(new CustomCellRenderer()); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);/*from w ww .j a v a 2 s.c o m*/ list.addListSelectionListener(this); JScrollPane listScrollPane = new JScrollPane(list); String dirName = startPath + "/"; // make sure we think of it as a directory. String filelist[] = new File(dirName).list(); for (int i = 0; i < filelist.length; i++) { String thisFileSt = dirName + filelist[i]; File thisFile = new File(thisFileSt); // skip directories for now. if (thisFile.isDirectory()) continue; // skip dot files. if (filelist[i].startsWith(".")) continue; try { listModel.addElement(makeNode(thisFile.getName(), thisFile.toURI().toURL().toString(), thisFile.getAbsolutePath())); } catch (java.net.MalformedURLException e) { } } fileName = new JTextField(50); list.setSelectedIndex(0); int sel_index = list.getSelectedIndex(); Object obj_at_index = listModel.getElementAt(sel_index); String name = obj_at_index.toString(); fileName.setText(name); // Create a panel that uses FlowLayout (the default). JPanel buttonPane = new JPanel(); buttonPane.add(fileName); Container contentPane = getContentPane(); contentPane.add(listScrollPane, BorderLayout.CENTER); contentPane.add(buttonPane, BorderLayout.NORTH); }
From source file:org.kuali.test.ui.components.dialogs.ImportPlatformTestsDlg.java
private void loadTestList(String platformName) { Platform p = Utils.findPlatform(getMainframe().getConfiguration(), platformName); availableTests.removeAll();/*from ww w . j a va 2 s .co m*/ DefaultListModel lm = new DefaultListModel(); availableTests.setModel(lm); List<String> l = new ArrayList<String>(); for (TestHeader th : p.getPlatformTests().getTestHeaderArray()) { if (!existingTargetPlatformTestNames.contains(th.getTestName())) { l.add(th.getTestName()); } } if (!l.isEmpty()) { Collections.sort(l); for (String s : l) { lm.addElement(s); } } }
From source file:org.n52.ifgicopter.spf.output.GpxOutputPlugin.java
/** * /*from www . j av a 2s. c o m*/ * @return */ private JPanel makeGUI() { if (this.panel == null) { this.panel = new JPanel(new BorderLayout()); JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); JButton selectFileButton = new JButton(SELECT_GPX_FILE_TEXT); selectFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectGpxFileAction(); } }); controlPanel.add(selectFileButton); this.outputFileLabel = new JLabel(); controlPanel.add(this.outputFileLabel); JButton saveFileButton = new JButton(SAVE_CURRENT_FILE_TEXT); saveFileButton.setToolTipText("Does also save manual changes undless model changes were made."); saveFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveCurrentFile(); } }); controlPanel.add(saveFileButton); // JCheckBox scrollLockCheckBox = new JCheckBox("scroll lock"); // scrollLockCheckBox.setSelected(true); // scrollLockCheckBox.addActionListener(new ActionListener() { // @Override // public void actionPerformed(final ActionEvent e) { // EventQueue.invokeLater(new Runnable() { // // @Override // public void run() { // JCheckBox source = (JCheckBox) e.getSource(); // // GpxOutputPlugin.this.textPane.setAutoscrolls(source.isSelected()); // } // }); // } // }); // controlPanel.add(scrollLockCheckBox); this.panel.add(controlPanel, BorderLayout.NORTH); JPanel valuesPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT)); DefaultListModel listModel = new DefaultListModel(); listModel.addElement(NO_DATA_LIST_ELEMENT); this.valuesToSaveList = new JList(listModel); this.valuesToSaveList.setVisibleRowCount(2); this.valuesToSaveList .setToolTipText("Select (multiple) values to include in the GPX file [Multiple using <Ctrl>]."); this.valuesToSaveList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { JList list = (JList) e.getSource(); // DefaultListModel listModel = (DefaultListModel) list.getModel(); Object[] selectedValues = list.getSelectedValues(); log.debug("New selection in value list:" + Arrays.toString(selectedValues)); GpxOutputPlugin.this.valuesToSave.clear(); for (Object o : selectedValues) { if (o instanceof String) { String s = (String) o; if (!GpxOutputPlugin.this.valuesToSave.contains(s)) GpxOutputPlugin.this.valuesToSave.add(s); } } } }); } }); this.valuesToSaveList.setSize(200, 22); this.valuesToSaveList.setAlignmentY(Component.CENTER_ALIGNMENT); valuesPanel.add(new JLabel("Saved attributes:")); valuesPanel.add(this.valuesToSaveList); valuesPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); this.panel.add(valuesPanel, BorderLayout.EAST); this.textPane = new XmlTextPane(); this.textPane.setEditable(true); this.textPane.setFont(Font.getFont(Font.MONOSPACED)); JScrollPane scrollPane = new JScrollPane(this.textPane); this.panel.add(scrollPane, BorderLayout.CENTER); JButton refreshTextFieldButton = new JButton("Update"); refreshTextFieldButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { updateGUI(); } }); } }); this.panel.add(refreshTextFieldButton, BorderLayout.SOUTH); updateGUI(); } return this.panel; }
From source file:org.n52.ifgicopter.spf.output.GpxOutputPlugin.java
/** * /*from w ww . j av a 2s.com*/ */ protected void updateGUI() { if (this.gpx == null) return; final String t = this.gpx.xmlText(GPX_OPTIONS); EventQueue.invokeLater(new Runnable() { @Override public void run() { GpxOutputPlugin.this.textPane.setText(t); GpxOutputPlugin.this.outputFileLabel .setText("<html><b>Output file: </b>" + getGpxFilePath() + "</html>"); DefaultListModel model = (DefaultListModel) GpxOutputPlugin.this.valuesToSaveList.getModel(); // update list if (model.getSize() < GpxOutputPlugin.this.availableDataKeys.size()) { if (model.contains(NO_DATA_LIST_ELEMENT)) model.remove(model.indexOf(NO_DATA_LIST_ELEMENT)); for (String s : GpxOutputPlugin.this.availableDataKeys) { if (!model.contains(s)) { model.addElement(s); } } } } }); }