void profileList_mouseClicked(MouseEvent e) { JList theList = (JList) e.getSource(); ListModel aModel = theList.getModel(); int index = theList.locationToIndex(e.getPoint()); if (index < 0) return; UniProfile aProfile = (UniProfile) aModel.getElementAt(index); nameTextField.setText(aProfile.toString()); }
public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { JFileChooser chooser = getFileChooser(); FileSystemView fsv = chooser.getFileSystemView(); JList list = (JList) evt.getSource(); int fsm = chooser.getFileSelectionMode(); boolean useSetDirectory = usesSingleFilePane && (fsm == JFileChooser.FILES_ONLY); if (chooser.isMultiSelectionEnabled()) { File[] files = null; Object[] objects = list.getSelectedValues(); if (objects != null) { if (objects.length == 1 && ((File) objects[0]).isDirectory() && chooser.isTraversable(((File) objects[0])) && (useSetDirectory || !fsv.isFileSystem(((File) objects[0])))) { setDirectorySelected(true); setDirectory(((File) objects[0])); } else { ArrayList<File> fList = new ArrayList<File>(objects.length); for (Object object : objects) { File f = (File) object; boolean isDir = f.isDirectory(); if ((chooser.isFileSelectionEnabled() && !isDir) || (chooser.isDirectorySelectionEnabled() && fsv.isFileSystem(f) && isDir)) { fList.add(f); } } if (fList.size() > 0) { files = fList.toArray(new File[fList.size()]); } setDirectorySelected(false); } } chooser.setSelectedFiles(files); } else { File file = (File) list.getSelectedValue(); if (file != null && file.isDirectory() && chooser.isTraversable(file) && (useSetDirectory || !fsv.isFileSystem(file))) { setDirectorySelected(true); setDirectory(file); if (usesSingleFilePane) { chooser.setSelectedFile(null); } } else { setDirectorySelected(false); if (file != null) { chooser.setSelectedFile(file); } } } } }
public void mouseEntered(MouseEvent evt) { if (list != null) { TransferHandler th1 = getFileChooser().getTransferHandler(); TransferHandler th2 = list.getTransferHandler(); if (th1 != th2) { list.setTransferHandler(th1); } if (getFileChooser().getDragEnabled() != list.getDragEnabled()) { list.setDragEnabled(getFileChooser().getDragEnabled()); } } }
public void mouseClicked(MouseEvent evt) { // Note: we can't depend on evt.getSource() because of backward // compatability if (list != null && SwingUtilities.isLeftMouseButton(evt) && (evt.getClickCount() % 2 == 0)) { int index = SwingUtilities2.loc2IndexFileList(list, evt.getPoint()); if (index >= 0) { File f = (File) list.getModel().getElementAt(index); try { // Strip trailing ".." f = ShellFolder.getNormalizedFile(f); } catch (IOException ex) { // That's ok, we'll use f as is } if (getFileChooser().isTraversable(f)) { list.clearSelection(); changeDirectory(f); } else { getFileChooser().approveSelection(); } } } }
void jbInit() throws Exception { border1 = BorderFactory.createEmptyBorder(10, 10, 5, 5); panel1.setLayout(borderLayout1); jPanel1.setLayout(borderLayout2); jScrollPane1.getViewport().setBackground(Color.white); jPanel2.setLayout(gridBagLayout1); jLabel1.setText("Profile Name : "); nameTextField.setMinimumSize(new Dimension(4, 18)); nameTextField.setPreferredSize(new Dimension(63, 18)); jLabel2.setText("Profile Type : "); openButton.setMaximumSize(new Dimension(73, 24)); openButton.setMinimumSize(new Dimension(73, 24)); openButton.setPreferredSize(new Dimension(73, 24)); openButton.setText("Open"); openButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { openButton_actionPerformed(e); } }); cancelButton.setMaximumSize(new Dimension(73, 24)); cancelButton.setMinimumSize(new Dimension(73, 24)); cancelButton.setPreferredSize(new Dimension(73, 24)); cancelButton.setMargin(new Insets(0, 5, 0, 5)); cancelButton.setText("Cancel"); cancelButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton_actionPerformed(e); } }); profileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); profileList.addMouseListener( new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { profileList_mouseClicked(e); } }); jPanel2.setBorder(border1); typeComboBox.setMaximumSize(new Dimension(32767, 18)); typeComboBox.setMinimumSize(new Dimension(122, 18)); typeComboBox.setPreferredSize(new Dimension(176, 18)); getContentPane().add(panel1); panel1.add(jPanel1, BorderLayout.CENTER); jPanel1.add(jScrollPane1, BorderLayout.CENTER); panel1.add(jPanel2, BorderLayout.SOUTH); jPanel2.add( jLabel1, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 7, 0), 0, 0)); jPanel2.add( nameTextField, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 11, 7, 0), 0, 0)); jPanel2.add( jLabel2, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 17, 0), 0, 0)); jScrollPane1.getViewport().add(profileList, null); jPanel2.add( openButton, new GridBagConstraints( 3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 11, 2, 10), 0, 0)); jPanel2.add( cancelButton, new GridBagConstraints( 3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 11, 9, 10), 0, 0)); jPanel2.add( typeComboBox, new GridBagConstraints( 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 11, 17, 0), 0, 0)); }