List of usage examples for javax.swing JList JList
public JList(final Vector<? extends E> listData)
JList
that displays the elements in the specified Vector
. From source file:net.sf.jabref.openoffice.AutoDetectPaths.java
private boolean autoDetectPaths() { if (OS.WINDOWS) { List<File> progFiles = findProgramFilesDir(); File sOffice = null;/*from w w w. j a v a2 s.com*/ List<File> sofficeFiles = new ArrayList<>(); for (File dir : progFiles) { if (fileSearchCancelled) { return false; } sOffice = findFileDir(dir, "soffice.exe"); if (sOffice != null) { sofficeFiles.add(sOffice); } } if (sOffice == null) { JOptionPane.showMessageDialog(parent, Localization.lang( "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."), Localization.lang("Could not find OpenOffice/LibreOffice installation"), JOptionPane.INFORMATION_MESSAGE); JFileChooser jfc = new JFileChooser(new File("C:\\")); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileFilter(new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File file) { return file.isDirectory(); } @Override public String getDescription() { return Localization.lang("Directories"); } }); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.showOpenDialog(parent); if (jfc.getSelectedFile() != null) { sOffice = jfc.getSelectedFile(); } } if (sOffice == null) { return false; } if (sofficeFiles.size() > 1) { // More than one file found DefaultListModel<File> mod = new DefaultListModel<>(); for (File tmpfile : sofficeFiles) { mod.addElement(tmpfile); } JList<File> fileList = new JList<>(mod); fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fileList.setSelectedIndex(0); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref")); b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1); b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3); b.add(fileList).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } else { sOffice = fileList.getSelectedValue(); } } else { sOffice = sofficeFiles.get(0); } return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe"); } else if (OS.OS_X) { File rootDir = new File("/Applications"); File[] files = rootDir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName()) || "LibreOffice.app".equals(file.getName()))) { rootDir = file; break; } } } File sOffice = findFileDir(rootDir, SOFFICE_BIN); if (fileSearchCancelled) { return false; } if (sOffice == null) { return false; } else { return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN); } } else { // Linux: String usrRoot = "/usr/lib"; File inUsr = findFileDir(new File(usrRoot), SOFFICE); if (fileSearchCancelled) { return false; } if (inUsr == null) { inUsr = findFileDir(new File("/usr/lib64"), SOFFICE); if (inUsr != null) { usrRoot = "/usr/lib64"; } } if (fileSearchCancelled) { return false; } File inOpt = findFileDir(new File("/opt"), SOFFICE); if (fileSearchCancelled) { return false; } if ((inUsr != null) && (inOpt == null)) { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } else if (inOpt != null) { if (inUsr == null) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { // Found both JRadioButton optRB = new JRadioButton(inOpt.getPath(), true); JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false); ButtonGroup bg = new ButtonGroup(); bg.add(optRB); bg.add(usrRB); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref ")); b.add(Localization.lang( "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:")) .xy(1, 1); b.add(optRB).xy(1, 3); b.add(usrRB).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } if (optRB.isSelected()) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } } } } return false; }
From source file:BasicDnD.java
public BasicDnD() { super(new BorderLayout()); JPanel leftPanel = createVerticalBoxPanel(); JPanel rightPanel = createVerticalBoxPanel(); // Create a table model. DefaultTableModel tm = new DefaultTableModel(); tm.addColumn("Column 0"); tm.addColumn("Column 1"); tm.addColumn("Column 2"); tm.addColumn("Column 3"); tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" }); tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" }); tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" }); tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" }); // LEFT COLUMN // Use the table model to create a table. table = new JTable(tm); leftPanel.add(createPanelForComponent(table, "JTable")); // Create a color chooser. colorChooser = new JColorChooser(); leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser")); // RIGHT COLUMN // Create a textfield. textField = new JTextField(30); textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast"); rightPanel.add(createPanelForComponent(textField, "JTextField")); // Create a scrolled text area. textArea = new JTextArea(5, 30); textArea.setText("Favorite shows:\nBuffy, Alias, Angel"); JScrollPane scrollPane = new JScrollPane(textArea); rightPanel.add(createPanelForComponent(scrollPane, "JTextArea")); // Create a list model and a list. DefaultListModel listModel = new DefaultListModel(); listModel.addElement("Martha Washington"); listModel.addElement("Abigail Adams"); listModel.addElement("Martha Randolph"); listModel.addElement("Dolley Madison"); listModel.addElement("Elizabeth Monroe"); listModel.addElement("Louisa Adams"); listModel.addElement("Emily Donelson"); list = new JList(listModel); list.setVisibleRowCount(-1);/*from www . j a va 2 s . c o m*/ list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport info) { // we only import Strings if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); if (dl.getIndex() == -1) { return false; } return true; } public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } // Check for String flavor if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { displayDropLocation("List doesn't accept a drop of this type."); return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); DefaultListModel listModel = (DefaultListModel) list.getModel(); int index = dl.getIndex(); boolean insert = dl.isInsert(); // Get the current string under the drop. String value = (String) listModel.getElementAt(index); // Get the string that is being dropped. Transferable t = info.getTransferable(); String data; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } // Display a dialog with the drop information. String dropValue = "\"" + data + "\" dropped "; if (dl.isInsert()) { if (dl.getIndex() == 0) { displayDropLocation(dropValue + "at beginning of list"); } else if (dl.getIndex() >= list.getModel().getSize()) { displayDropLocation(dropValue + "at end of list"); } else { String value1 = (String) list.getModel().getElementAt(dl.getIndex() - 1); String value2 = (String) list.getModel().getElementAt(dl.getIndex()); displayDropLocation(dropValue + "between \"" + value1 + "\" and \"" + value2 + "\""); } } else { displayDropLocation(dropValue + "on top of " + "\"" + value + "\""); } /** * This is commented out for the basicdemo.html tutorial page. * If you * add this code snippet back and delete the * "return false;" line, the * list will accept drops * of type string. // Perform the actual * import. if (insert) { listModel.add(index, data); } else { * listModel.set(index, data); } return true; */ return false; } public int getSourceActions(JComponent c) { return COPY; } protected Transferable createTransferable(JComponent c) { JList list = (JList) c; Object[] values = list.getSelectedValues(); StringBuffer buff = new StringBuffer(); for (int i = 0; i < values.length; i++) { Object val = values[i]; buff.append(val == null ? "" : val.toString()); if (i != values.length - 1) { buff.append("\n"); } } return new StringSelection(buff.toString()); } }); list.setDropMode(DropMode.ON_OR_INSERT); JScrollPane listView = new JScrollPane(list); listView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(listView, "JList")); // Create a tree. DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia"); DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon"); rootNode.add(sharon); DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya"); sharon.add(maya); DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya"); sharon.add(anya); sharon.add(new DefaultMutableTreeNode("Bongo")); maya.add(new DefaultMutableTreeNode("Muffin")); anya.add(new DefaultMutableTreeNode("Winky")); DefaultTreeModel model = new DefaultTreeModel(rootNode); tree = new JTree(model); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JScrollPane treeView = new JScrollPane(tree); treeView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(treeView, "JTree")); // Create the toggle button. toggleDnD = new JCheckBox("Turn on Drag and Drop"); toggleDnD.setActionCommand("toggleDnD"); toggleDnD.addActionListener(this); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); splitPane.setOneTouchExpandable(true); add(splitPane, BorderLayout.CENTER); add(toggleDnD, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:Main.java
private void initScreen() { setBorder(BorderFactory.createEtchedBorder()); setLayout(new GridBagLayout()); sourceLabel = new JLabel(DEFAULT_SOURCE_CHOICE_LABEL); sourceListModel = new SortedListModel(); sourceList = new JList(sourceListModel); add(sourceLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, EMPTY_INSETS, 0, 0)); add(new JScrollPane(sourceList), new GridBagConstraints(0, 1, 1, 5, .5, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, EMPTY_INSETS, 0, 0)); addButton = new JButton(ADD_BUTTON_LABEL); add(addButton, new GridBagConstraints(1, 2, 1, 2, 0, .25, GridBagConstraints.CENTER, GridBagConstraints.NONE, EMPTY_INSETS, 0, 0)); addButton.addActionListener(new AddListener()); removeButton = new JButton(REMOVE_BUTTON_LABEL); add(removeButton, new GridBagConstraints(1, 4, 1, 2, 0, .25, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0)); removeButton.addActionListener(new RemoveListener()); destLabel = new JLabel(DEFAULT_DEST_CHOICE_LABEL); destListModel = new SortedListModel(); destList = new JList(destListModel); add(destLabel, new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, EMPTY_INSETS, 0, 0));//www . j ava 2 s . co m add(new JScrollPane(destList), new GridBagConstraints(2, 1, 1, 5, .5, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, EMPTY_INSETS, 0, 0)); }
From source file:com.emental.mindraider.ui.dialogs.OpenConceptByTagJDialog.java
public OpenConceptByTagJDialog(String dialogTitle, String selectionLabel, String buttonLabel, boolean showCancel) { super(dialogTitle); JPanel framePanel = new JPanel(); framePanel.setBorder(new EmptyBorder(5, 10, 0, 10)); framePanel.setLayout(new BorderLayout()); // NORTH panel JPanel northPanel = new JPanel(); northPanel.setLayout(new BorderLayout()); northPanel.add(new JLabel(selectionLabel), BorderLayout.NORTH); final JTextField tagLabel = new JTextField(TEXTFIELD_WIDTH); // data// w w w. j av a2 s .c om tags = MindRaider.tagCustodian.getAllTags(); ; if (tags == null) { tagLabel.setEnabled(false); } tagLabel.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent keyEvent) { if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) { logger.debug("Openning selected tag..."); openTagSearchDialog(); } } public void keyReleased(KeyEvent keyEvent) { getListModel().clear(); shownTags.clear(); if (tagLabel.getText().length() > 0) { for (TagEntry tag : tags) { if (tag.getTagLabel().toLowerCase().startsWith(tagLabel.getText().toLowerCase())) { getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")"); shownTags.add(tag); } } } else { // show all tags for (TagEntry tag : tags) { getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")"); shownTags.add(tag); } } } public void keyTyped(KeyEvent keyEvent) { } }); northPanel.add(tagLabel, BorderLayout.SOUTH); framePanel.add(northPanel, BorderLayout.NORTH); // CENTER panel JPanel centerPanel = new JPanel(); centerPanel.setLayout(new BorderLayout()); centerPanel.add(new JLabel(Messages.getString("OpenConceptByTagJDialog.matchingTags")), BorderLayout.NORTH); defaultListModel = new DefaultListModel(); list = new JList(defaultListModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); // list.addListSelectionListener(this); list.setVisibleRowCount(15); JScrollPane listScrollPane = new JScrollPane(list); centerPanel.add(listScrollPane, BorderLayout.SOUTH); framePanel.add(centerPanel, BorderLayout.CENTER); JPanel southPanel = new JPanel(); southPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); JButton openButton = new JButton(buttonLabel); southPanel.add(openButton); openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openTagSearchDialog(); } }); if (showCancel) { JButton cancelButton = new JButton(Messages.getString("OpenNotebookJDialog.cancel")); southPanel.add(cancelButton); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OpenConceptByTagJDialog.this.dispose(); } }); } framePanel.add(southPanel, BorderLayout.SOUTH); getContentPane().add(framePanel, BorderLayout.CENTER); // show pack(); Gfx.centerAndShowWindow(this); }
From source file:hr.fer.zemris.vhdllab.platform.ui.command.DevFloodWithCompliationRequestsCommand.java
private void showResults(List<String> results) { logger.info(results);/*from ww w . j a v a2 s . co m*/ JList list = new JList(results.toArray()); JOptionPane.showOptionDialog(null, new JScrollPane(list), "Results", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); }
From source file:edu.ku.brc.specify.config.init.secwiz.UserPanel.java
/** * /*w w w .jav a 2 s. co m*/ */ protected void createUI() { dbList = new JList(new DefaultListModel()); otherDBList = new JList(new DefaultListModel()); userModel = new UserTableModel(null); userTable = new JTable(userModel); CellConstraints cc = new CellConstraints(); saveBtn = UIHelper.createButton("Save"); mkKeysBtn = UIHelper.createButton("Make Keys"); copyKeyBtn = UIHelper.createButton("Copy Master Key"); sendKeysBtn = UIHelper.createButton("Send Keys"); showKeysBtn = UIHelper.createButton("Show Summary"); printKeysBtn = UIHelper.createButton("Print"); btns = new JButton[] { saveBtn, sendKeysBtn, copyKeyBtn, showKeysBtn, printKeysBtn }; String colDef = UIHelper.createDuplicateJGoodiesDef("p", "8px", btns.length); PanelBuilder btnPB = new PanelBuilder(new FormLayout("f:p:g," + colDef, "p")); int x = 2; for (JButton b : btns) { btnPB.add(b, cc.xy(x, 1)); x += 2; } saveBtn.setEnabled(false); copyKeyBtn.setEnabled(false); label = UIHelper.createLabel("", SwingConstants.CENTER); gainAccessBtn = UIHelper.createIconBtn("Unmap", "", null); loseAccessBtn = UIHelper.createIconBtn("Map", "", null); PanelBuilder bpb = new PanelBuilder(new FormLayout("p", "f:p:g,p,8px,p,f:p:g")); bpb.add(gainAccessBtn, cc.xy(1, 2)); bpb.add(loseAccessBtn, cc.xy(1, 4)); PanelBuilder tpb = new PanelBuilder(new FormLayout("f:p:g,10px,p,10px,f:p:g", "p,4px,f:p:g")); tpb.add(UIHelper.createI18NLabel("MSTR_HAS_PERM", SwingConstants.CENTER), cc.xy(1, 1)); tpb.add(otherDBLbl = UIHelper.createI18NLabel("MSTR_HAS_NOPERM", SwingConstants.CENTER), cc.xy(5, 1)); tpb.add(dbScrollPane = UIHelper.createScrollPane(dbList), cc.xy(1, 3)); tpb.add(bpb.getPanel(), cc.xy(3, 3)); tpb.add(odbScrollPane = UIHelper.createScrollPane(otherDBList), cc.xy(5, 3)); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p", "f:p:g,20px,p,8px,p,4px,f:p:g,4px,p,20px,p"), this); sendKeysBtn.setVisible(false); int y = 1; pb.add(tpb.getPanel(), cc.xyw(1, y, 2)); y += 2; y += 2; pb.add(label, cc.xyw(1, y, 2)); y += 2; pb.add(userScrollPane = UIHelper.createScrollPane(userTable), cc.xyw(1, y, 2)); y += 2; pb.add(btnPB.getPanel(), cc.xy(2, y)); y += 2; pb.addSeparator("", cc.xyw(1, y, 2)); y += 2; dbList.setVisibleRowCount(8); otherDBList.setVisibleRowCount(8); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Dimension size = userTable.getPreferredScrollableViewportSize(); size.height = 10 * userTable.getRowHeight(); userTable.setPreferredScrollableViewportSize(size); } }); updateBtnUI(false); dbList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { loadData(false); gainAccessBtn.setEnabled(otherDBList.getSelectedIndex() > -1); loseAccessBtn.setEnabled(dbList.getSelectedIndex() > -1); } } }); userTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { doUserSelected(); } } }); saveBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveUserData(); } }); sendKeysBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sendKeys(); } }); mkKeysBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { makeKeys(); } }); copyKeyBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int inx = userTable.getSelectedRow(); if (inx > -1) { String masterKey = userModel.getUserData().get(inx).getMasterKey(); UIHelper.setTextToClipboard(masterKey); } } }); showKeysBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { displayData(); } }); printKeysBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { printUserData(); } }); gainAccessBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changeMasterAccess(true); } }); loseAccessBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changeMasterAccess(false); } }); otherDBList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { otherDBName = (String) otherDBList.getSelectedValue(); gainAccessBtn.setEnabled(otherDBList.getSelectedIndex() > -1); loseAccessBtn.setEnabled(dbList.getSelectedIndex() > -1); } } }); }
From source file:edu.ku.brc.specify.plugins.TaxonLabelFormatting.java
@Override public void initialize(Properties propertiesArg, boolean isViewModeArg) { super.initialize(propertiesArg, isViewModeArg); String plName = "TaxonLabelFormatter"; PickListDBAdapterIFace adapter = PickListDBAdapterFactory.getInstance().create(plName, false); if (adapter == null || adapter.getPickList() == null) { throw new RuntimeException("PickList Adapter [" + plName + "] cannot be null!"); }/* w w w .j a va2 s. c om*/ formatCBX = new ValComboBox(adapter); formatCBX.getComboBox().addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doFormatting(); } }); formatCBX.getComboBox().addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { doFormatting(); } }); newAgentBtn = createButton(""); // Label set when new Resource Bundle is installed (below) searchPanel = new DBObjSearchPanel("Search", "AgentNameSearch", "AgentNameSearch", "edu.ku.brc.specify.datamodel.Agent", "agentId", SwingConstants.BOTTOM); searchPanel.getScrollPane().setMinimumSize(new Dimension(100, 200)); searchPanel.getScrollPane().setPreferredSize(new Dimension(100, 150)); ((FormViewObj) searchPanel.getForm()).getPanel().setBorder(null); try { UIRegistry.loadAndPushResourceBundle("specify_plugins"); newAgentBtn.setText(getResourceString("NewAgent")); authorsList = new JList(new DefaultListModel()); authorsList.setVisibleRowCount(10); authorsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Object selObj = authorsList.getSelectedValue(); if (selObj != null) { } updateEnabledState(); } } }); JScrollPane scrollPane = new JScrollPane(authorsList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); mapToBtn = createIconBtn("Map", "ADD_AUTHOR_NAME_TT", new ActionListener() { public void actionPerformed(ActionEvent ae) { Object agent = searchPanel.getSelectedObject(); ((DefaultListModel) authorsList.getModel()).addElement(agent); doFormatting(); } }); unmapBtn = createIconBtn("Unmap", "REMOVE_AUTHOR_NAME_TT", new ActionListener() { public void actionPerformed(ActionEvent ae) { int index = authorsList.getSelectedIndex(); if (index > -1) { DefaultListModel model = (DefaultListModel) authorsList.getModel(); model.remove(index); updateEnabledState(); doFormatting(); } } }); upBtn = createIconBtn("ReorderUp", "MOVE_AUTHOR_NAME_UP", new ActionListener() { public void actionPerformed(ActionEvent ae) { DefaultListModel model = (DefaultListModel) authorsList.getModel(); int index = authorsList.getSelectedIndex(); Object item = authorsList.getSelectedValue(); model.remove(index); model.insertElementAt(item, index - 1); authorsList.setSelectedIndex(index - 1); updateEnabledState(); } }); downBtn = createIconBtn("ReorderDown", "MOVE_AUTHOR_NAME_DOWN", new ActionListener() { public void actionPerformed(ActionEvent ae) { DefaultListModel model = (DefaultListModel) authorsList.getModel(); int index = authorsList.getSelectedIndex(); Object item = authorsList.getSelectedValue(); model.remove(index); model.insertElementAt(item, index + 1); authorsList.setSelectedIndex(index + 1); updateEnabledState(); } }); PanelBuilder bldr = new PanelBuilder(new FormLayout("p, 5px, p, 5px, f:p:g, 2px, p", "p, 4px, p, 2px, f:p:g, 4px, p, 4px, p, 2px, p, 2px, p, 2px, p"), this); CellConstraints cc = new CellConstraints(); PanelBuilder upDownPanel = new PanelBuilder(new FormLayout("p", "p, 2px, p, f:p:g")); upDownPanel.add(upBtn, cc.xy(1, 1)); upDownPanel.add(downBtn, cc.xy(1, 3)); PanelBuilder middlePanel = new PanelBuilder(new FormLayout("c:p:g", "f:p:g, p, 2px, p, f:p:g")); middlePanel.add(mapToBtn, cc.xy(1, 2)); middlePanel.add(unmapBtn, cc.xy(1, 4)); PanelBuilder rwPanel = new PanelBuilder(new FormLayout("p, 2px, f:p:g", "p")); refWorkLabel = createLabel(getResourceString("NONE")); rwPanel.add(createI18NFormLabel("REFERENCEWORK"), cc.xy(1, 1)); rwPanel.add(refWorkLabel, cc.xy(3, 1)); int y = 1; bldr.add(rwPanel.getPanel(), cc.xywh(1, y, 7, 1)); y += 2; bldr.add(searchPanel, cc.xywh(1, y, 1, 3)); bldr.addSeparator(getResourceString("Authors"), cc.xy(5, y)); y += 2; bldr.add(middlePanel.getPanel(), cc.xy(3, y)); bldr.add(scrollPane, cc.xywh(5, y, 1, 3)); bldr.add(upDownPanel.getPanel(), cc.xy(7, y)); y += 2; PanelBuilder newAgentPanel = new PanelBuilder(new FormLayout("f:p:g,p", "p")); newAgentPanel.add(newAgentBtn, cc.xy(2, 1)); bldr.add(newAgentPanel.getPanel(), cc.xy(1, y)); y += 2; JLabel fmtLabel = createLabel(getResourceString("LABELFORMAT")); bldr.add(fmtLabel, cc.xy(1, y)); y += 2; bldr.add(formatCBX, cc.xywh(1, y, 7, 1)); y += 2; Font plain = fmtLabel.getFont(); specialLabel = new SpecialLabel(plain, new Font(plain.getName(), Font.ITALIC, plain.getSize())); specialLabel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY)); bldr.add(createLabel(getResourceString("SAMPLEOUTPUT") + ":"), cc.xywh(1, y, 7, 1)); y += 2; bldr.add(specialLabel, cc.xywh(1, y, 7, 1)); searchPanel.setOKBtn(mapToBtn); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TaxonLabelFormatting.class, ex); log.error(ex); ex.printStackTrace(); } UIRegistry.popResourceBundle(); }
From source file:FillViewportHeightDemo.java
public FillViewportHeightDemo() { super("Empty Table DnD Demo"); tableModel = getDefaultTableModel(); table = new JTable(tableModel); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setDropMode(DropMode.INSERT_ROWS); table.setTransferHandler(new TransferHandler() { public boolean canImport(TransferSupport support) { // for the demo, we'll only support drops (not clipboard paste) if (!support.isDrop()) { return false; }/*w w w .ja v a 2s . com*/ // we only import Strings if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } return true; } public boolean importData(TransferSupport support) { // if we can't handle the import, say so if (!canImport(support)) { return false; } // fetch the drop location JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation(); int row = dl.getRow(); // fetch the data and bail if this fails String data; try { data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException e) { return false; } catch (IOException e) { return false; } String[] rowData = data.split(","); tableModel.insertRow(row, rowData); Rectangle rect = table.getCellRect(row, 0, false); if (rect != null) { table.scrollRectToVisible(rect); } // demo stuff - remove for blog model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); // end demo stuff return true; } }); JList dragFrom = new JList(model); dragFrom.setFocusable(false); dragFrom.setPrototypeCellValue(getNextString(100)); model.insertElementAt(getNextString(count++), 0); dragFrom.setDragEnabled(true); dragFrom.setBorder(BorderFactory.createLoweredBevelBorder()); dragFrom.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() % 2 == 0) { String text = (String) model.getElementAt(0); String[] rowData = text.split(","); tableModel.insertRow(table.getRowCount(), rowData); model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); } } }); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); JPanel wrap = new JPanel(); wrap.add(new JLabel("Drag from here:")); wrap.add(dragFrom); p.add(Box.createHorizontalStrut(4)); p.add(Box.createGlue()); p.add(wrap); p.add(Box.createGlue()); p.add(Box.createHorizontalStrut(4)); getContentPane().add(p, BorderLayout.NORTH); JScrollPane sp = new JScrollPane(table); getContentPane().add(sp, BorderLayout.CENTER); fillBox = new JCheckBoxMenuItem("Fill Viewport Height"); fillBox.addActionListener(this); JMenuBar mb = new JMenuBar(); JMenu options = new JMenu("Options"); mb.add(options); setJMenuBar(mb); JMenuItem clear = new JMenuItem("Reset"); clear.addActionListener(this); options.add(clear); options.add(fillBox); getContentPane().setPreferredSize(new Dimension(260, 180)); }
From source file:captureplugin.drivers.defaultdriver.AdditionalParams.java
/** * Create List-Panel/* ww w . j av a 2s .c om*/ * @return List-Panel */ private Component createListPanel() { JPanel panel = new JPanel(new BorderLayout(0, 2)); panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); panel.add(new JLabel(mLocalizer.msg("command", "Command")), BorderLayout.NORTH); mList = new JList(mListModel); panel.add(new JScrollPane(mList), BorderLayout.CENTER); JPanel buttons = new JPanel(new FlowLayout(FlowLayout.LEFT)); JButton add = new JButton(TVBrowserIcons.newIcon(TVBrowserIcons.SIZE_SMALL)); add.setToolTipText(Localizer.getLocalization(Localizer.I18N_ADD)); add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addPressed(); } }); buttons.add(add); JButton remove = new JButton(TVBrowserIcons.delete(TVBrowserIcons.SIZE_SMALL)); remove.setToolTipText(Localizer.getLocalization(Localizer.I18N_DELETE)); remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removePressed(); } }); buttons.add(remove); final JButton up = new JButton(TVBrowserIcons.up(TVBrowserIcons.SIZE_SMALL)); up.setToolTipText(Localizer.getLocalization(Localizer.I18N_UP)); buttons.add(up); up.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { upPressed(); } }); final JButton down = new JButton(TVBrowserIcons.down(TVBrowserIcons.SIZE_SMALL)); down.setToolTipText(Localizer.getLocalization(Localizer.I18N_DOWN)); buttons.add(down); down.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { downPressed(); } }); mStartStop = new JButton(mStartIcon); mStartStop.setToolTipText(mLocalizer.msg("startstop", "Activate or Deactivate Parameter")); mStartStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { startStopPressed(); } }); buttons.add(mStartStop); panel.add(buttons, BorderLayout.SOUTH); mList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { selectionChanged(); if (mList.getSelectedIndex() == 0) { up.setEnabled(false); down.setEnabled(true); } else if (mList.getSelectedIndex() == mListModel.getSize() - 1) { up.setEnabled(true); down.setEnabled(false); } else { up.setEnabled(true); down.setEnabled(true); } } }); selectionChanged(); return panel; }
From source file:SplitPaneDemo2.java
public SplitPaneDemo() { //Read image names from a properties file. ResourceBundle imageResource; try {// www . ja va 2s .c o m imageResource = ResourceBundle.getBundle("imagenames"); String imageNamesString = imageResource.getString("images"); imageNames = parseList(imageNamesString); } catch (MissingResourceException e) { handleMissingResource(e); } //Create the list of images and put it in a scroll pane. list = new JList(imageNames); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); list.addListSelectionListener(this); JScrollPane listScrollPane = new JScrollPane(list); //Set up the picture label and put it in a scroll pane. ImageIcon firstImage = createImageIcon("images/" + (String) imageNames.firstElement()); if (firstImage != null) { picture = new JLabel(firstImage); } else { picture = new JLabel((String) imageNames.firstElement()); } JScrollPane pictureScrollPane = new JScrollPane(picture); //Create a split pane with the two scroll panes in it. splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listScrollPane, pictureScrollPane); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(150); //Provide minimum sizes for the two components in the split pane. Dimension minimumSize = new Dimension(100, 50); listScrollPane.setMinimumSize(minimumSize); pictureScrollPane.setMinimumSize(minimumSize); //Provide a preferred size for the split pane. splitPane.setPreferredSize(new Dimension(400, 200)); }