545 * @param fc a {@code JFileChooser} 546 * @return the list 547 */ 548 protected JPanel createList(JFileChooser fc) { 549 return filePane.createList(); 550 } 551 552 /** 553 * Constructs a details view. 554 * 555 * @param fc a {@code JFileChooser} 556 * @return the details view 557 */ 558 protected JPanel createDetailsView(JFileChooser fc) { 559 return filePane.createDetailsView(); 560 } 561 562 /** 563 * Creates a selection listener for the list of files and directories. 564 * 565 * @param fc a <code>JFileChooser</code> 566 * @return a <code>ListSelectionListener</code> 567 */ 568 public ListSelectionListener createListSelectionListener(JFileChooser fc) { 569 return super.createListSelectionListener(fc); 570 } 571 572 /** 573 * Obsolete class, not used in this version. 574 */ 575 protected class SingleClickListener extends MouseAdapter { 576 /** 577 * Constructs an instance of {@code SingleClickListener}. 578 * 579 * @param list an instance of {@code JList} 580 */ 581 public SingleClickListener(JList<?> list) { 582 } 583 } 584 585 /** 586 * Obsolete class, not used in this version. 590 } 591 592 public void uninstallUI(JComponent c) { 593 // Remove listeners 594 c.removePropertyChangeListener(filterComboBoxModel); 595 c.removePropertyChangeListener(filePane); 596 cancelButton.removeActionListener(getCancelSelectionAction()); 597 approveButton.removeActionListener(getApproveSelectionAction()); 598 fileNameTextField.removeActionListener(getApproveSelectionAction()); 599 600 if (filePane != null) { 601 filePane.uninstallUI(); 602 filePane = null; 603 } 604 605 super.uninstallUI(c); 606 } 607 608 /** 609 * Returns the preferred size of the specified 610 * <code>JFileChooser</code>. 611 * The preferred size is at least as large, 612 * in both height and width, 613 * as the preferred size recommended 614 * by the file chooser's layout manager. 615 * 616 * @param c a <code>JFileChooser</code> 617 * @return a <code>Dimension</code> specifying the preferred 618 * width and height of the file chooser 619 */ 620 @Override 621 public Dimension getPreferredSize(JComponent c) { 622 int prefWidth = PREF_SIZE.width; 623 Dimension d = c.getLayout().preferredLayoutSize(c); 624 if (d != null) { 625 return new Dimension(d.width < prefWidth ? prefWidth : d.width, 626 d.height < PREF_SIZE.height ? PREF_SIZE.height : d.height); 627 } else { 628 return new Dimension(prefWidth, PREF_SIZE.height); 629 } 630 } 631 632 /** 633 * Returns the minimum size of the <code>JFileChooser</code>. 634 * 635 * @param c a <code>JFileChooser</code> 636 * @return a <code>Dimension</code> specifying the minimum 637 * width and height of the file chooser 638 */ 639 @Override 640 public Dimension getMinimumSize(JComponent c) { 641 return new Dimension(MIN_WIDTH, MIN_HEIGHT); 642 } 643 644 /** 645 * Returns the maximum size of the <code>JFileChooser</code>. 646 * 647 * @param c a <code>JFileChooser</code> 648 * @return a <code>Dimension</code> specifying the maximum 649 * width and height of the file chooser 650 */ 651 @Override 652 public Dimension getMaximumSize(JComponent c) { 653 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); 654 } 655 656 private String fileNameString(File file) { 657 if (file == null) { 658 return null; 659 } else { 660 JFileChooser fc = getFileChooser(); 661 if ((fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) || 662 (fc.isDirectorySelectionEnabled() && fc.isFileSelectionEnabled() 663 && fc.getFileSystemView().isFileSystemRoot(file))) { 664 return file.getPath(); 665 } else { 666 return file.getName(); 667 } 668 } 1255 */ 1256 protected DirectoryComboBoxAction() { 1257 super("DirectoryComboBoxAction"); 1258 } 1259 1260 public void actionPerformed(ActionEvent e) { 1261 directoryComboBox.hidePopup(); 1262 File f = (File)directoryComboBox.getSelectedItem(); 1263 if (!getFileChooser().getCurrentDirectory().equals(f)) { 1264 getFileChooser().setCurrentDirectory(f); 1265 } 1266 } 1267 } 1268 1269 protected JButton getApproveButton(JFileChooser fc) { 1270 return approveButton; 1271 } 1272 1273 1274 /** 1275 * <code>ButtonAreaLayout</code> behaves in a similar manner to 1276 * <code>FlowLayout</code>. It lays out all components from left to 1277 * right, flushed right. The widths of all components will be set 1278 * to the largest preferred size width. 1279 */ 1280 private static class ButtonAreaLayout implements LayoutManager { 1281 private int hGap = 5; 1282 private int topMargin = 17; 1283 1284 public void addLayoutComponent(String string, Component comp) { 1285 } 1286 1287 public void layoutContainer(Container container) { 1288 Component[] children = container.getComponents(); 1289 1290 if (children != null && children.length > 0) { 1291 int numChildren = children.length; 1292 Dimension[] sizes = new Dimension[numChildren]; 1293 Insets insets = container.getInsets(); 1294 int yLocation = insets.top + topMargin; 1295 int maxWidth = 0; 1296 | 545 * @param fc a {@code JFileChooser} 546 * @return the list 547 */ 548 protected JPanel createList(JFileChooser fc) { 549 return filePane.createList(); 550 } 551 552 /** 553 * Constructs a details view. 554 * 555 * @param fc a {@code JFileChooser} 556 * @return the details view 557 */ 558 protected JPanel createDetailsView(JFileChooser fc) { 559 return filePane.createDetailsView(); 560 } 561 562 /** 563 * Creates a selection listener for the list of files and directories. 564 * 565 * @param fc a {@code JFileChooser} 566 * @return a {@code ListSelectionListener} 567 */ 568 public ListSelectionListener createListSelectionListener(JFileChooser fc) { 569 return super.createListSelectionListener(fc); 570 } 571 572 /** 573 * Obsolete class, not used in this version. 574 */ 575 protected class SingleClickListener extends MouseAdapter { 576 /** 577 * Constructs an instance of {@code SingleClickListener}. 578 * 579 * @param list an instance of {@code JList} 580 */ 581 public SingleClickListener(JList<?> list) { 582 } 583 } 584 585 /** 586 * Obsolete class, not used in this version. 590 } 591 592 public void uninstallUI(JComponent c) { 593 // Remove listeners 594 c.removePropertyChangeListener(filterComboBoxModel); 595 c.removePropertyChangeListener(filePane); 596 cancelButton.removeActionListener(getCancelSelectionAction()); 597 approveButton.removeActionListener(getApproveSelectionAction()); 598 fileNameTextField.removeActionListener(getApproveSelectionAction()); 599 600 if (filePane != null) { 601 filePane.uninstallUI(); 602 filePane = null; 603 } 604 605 super.uninstallUI(c); 606 } 607 608 /** 609 * Returns the preferred size of the specified 610 * {@code JFileChooser}. 611 * The preferred size is at least as large, 612 * in both height and width, 613 * as the preferred size recommended 614 * by the file chooser's layout manager. 615 * 616 * @param c a {@code JFileChooser} 617 * @return a {@code Dimension} specifying the preferred 618 * width and height of the file chooser 619 */ 620 @Override 621 public Dimension getPreferredSize(JComponent c) { 622 int prefWidth = PREF_SIZE.width; 623 Dimension d = c.getLayout().preferredLayoutSize(c); 624 if (d != null) { 625 return new Dimension(d.width < prefWidth ? prefWidth : d.width, 626 d.height < PREF_SIZE.height ? PREF_SIZE.height : d.height); 627 } else { 628 return new Dimension(prefWidth, PREF_SIZE.height); 629 } 630 } 631 632 /** 633 * Returns the minimum size of the {@code JFileChooser}. 634 * 635 * @param c a {@code JFileChooser} 636 * @return a {@code Dimension} specifying the minimum 637 * width and height of the file chooser 638 */ 639 @Override 640 public Dimension getMinimumSize(JComponent c) { 641 return new Dimension(MIN_WIDTH, MIN_HEIGHT); 642 } 643 644 /** 645 * Returns the maximum size of the {@code JFileChooser}. 646 * 647 * @param c a {@code JFileChooser} 648 * @return a {@code Dimension} specifying the maximum 649 * width and height of the file chooser 650 */ 651 @Override 652 public Dimension getMaximumSize(JComponent c) { 653 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); 654 } 655 656 private String fileNameString(File file) { 657 if (file == null) { 658 return null; 659 } else { 660 JFileChooser fc = getFileChooser(); 661 if ((fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) || 662 (fc.isDirectorySelectionEnabled() && fc.isFileSelectionEnabled() 663 && fc.getFileSystemView().isFileSystemRoot(file))) { 664 return file.getPath(); 665 } else { 666 return file.getName(); 667 } 668 } 1255 */ 1256 protected DirectoryComboBoxAction() { 1257 super("DirectoryComboBoxAction"); 1258 } 1259 1260 public void actionPerformed(ActionEvent e) { 1261 directoryComboBox.hidePopup(); 1262 File f = (File)directoryComboBox.getSelectedItem(); 1263 if (!getFileChooser().getCurrentDirectory().equals(f)) { 1264 getFileChooser().setCurrentDirectory(f); 1265 } 1266 } 1267 } 1268 1269 protected JButton getApproveButton(JFileChooser fc) { 1270 return approveButton; 1271 } 1272 1273 1274 /** 1275 * {@code ButtonAreaLayout} behaves in a similar manner to 1276 * {@code FlowLayout}. It lays out all components from left to 1277 * right, flushed right. The widths of all components will be set 1278 * to the largest preferred size width. 1279 */ 1280 private static class ButtonAreaLayout implements LayoutManager { 1281 private int hGap = 5; 1282 private int topMargin = 17; 1283 1284 public void addLayoutComponent(String string, Component comp) { 1285 } 1286 1287 public void layoutContainer(Container container) { 1288 Component[] children = container.getComponents(); 1289 1290 if (children != null && children.length > 0) { 1291 int numChildren = children.length; 1292 Dimension[] sizes = new Dimension[numChildren]; 1293 Insets insets = container.getInsets(); 1294 int yLocation = insets.top + topMargin; 1295 int maxWidth = 0; 1296 |