1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
265 //
266 public static ComponentUI createUI(JComponent c) {
267 return new MotifFileChooserUI((JFileChooser)c);
268 }
269
270 public void installUI(JComponent c) {
271 super.installUI(c);
272 }
273
274 public void uninstallUI(JComponent c) {
275 c.removePropertyChangeListener(filterComboBoxModel);
276 approveButton.removeActionListener(getApproveSelectionAction());
277 filenameTextField.removeActionListener(getApproveSelectionAction());
278 super.uninstallUI(c);
279 }
280
281 public void installComponents(JFileChooser fc) {
282 fc.setLayout(new BorderLayout(10, 10));
283 fc.setAlignmentX(JComponent.CENTER_ALIGNMENT);
284
285 JPanel interior = new JPanel() {
286 public Insets getInsets() {
287 return insets;
288 }
289 };
290 interior.setInheritsPopupMenu(true);
291 align(interior);
292 interior.setLayout(new BoxLayout(interior, BoxLayout.PAGE_AXIS));
293
294 fc.add(interior, BorderLayout.CENTER);
295
296 // PENDING(jeff) - I18N
297 JLabel l = new JLabel(pathLabelText);
298 l.setDisplayedMnemonic(pathLabelMnemonic);
299 align(l);
300 interior.add(l);
301
302 File currentDirectory = fc.getCurrentDirectory();
303 String curDirName = null;
304 if(currentDirectory != null) {
305 curDirName = currentDirectory.getPath();
306 }
307 pathField = new JTextField(curDirName) {
308 public Dimension getMaximumSize() {
309 Dimension d = super.getMaximumSize();
310 d.height = getPreferredSize().height;
311 return d;
312 }
313 };
314 pathField.setInheritsPopupMenu(true);
315 l.setLabelFor(pathField);
316 align(pathField);
317
318 // Change to folder on return
319 pathField.addActionListener(getUpdateAction());
320 interior.add(pathField);
321
322 interior.add(Box.createRigidArea(vstrut10));
323
324
325 // CENTER: left, right accessory
326 JPanel centerPanel = new JPanel();
327 centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.LINE_AXIS));
328 align(centerPanel);
329
330 // left panel - Filter & folderList
331 JPanel leftPanel = new JPanel();
332 leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
333 align(leftPanel);
334
335 // add the filter PENDING(jeff) - I18N
336 l = new JLabel(filterLabelText);
337 l.setDisplayedMnemonic(filterLabelMnemonic);
338 align(l);
339 leftPanel.add(l);
340
341 filterComboBox = new JComboBox<FileFilter>() {
342 public Dimension getMaximumSize() {
343 Dimension d = super.getMaximumSize();
344 d.height = getPreferredSize().height;
345 return d;
346 }
347 };
348 filterComboBox.setInheritsPopupMenu(true);
349 l.setLabelFor(filterComboBox);
350 filterComboBoxModel = createFilterComboBoxModel();
351 filterComboBox.setModel(filterComboBoxModel);
352 filterComboBox.setRenderer(createFilterComboBoxRenderer());
353 fc.addPropertyChangeListener(filterComboBoxModel);
354 align(filterComboBox);
355 leftPanel.add(filterComboBox);
356
357 // leftPanel.add(Box.createRigidArea(vstrut10));
358
359 // Add the Folder List PENDING(jeff) - I18N
360 l = new JLabel(foldersLabelText);
361 l.setDisplayedMnemonic(foldersLabelMnemonic);
362 align(l);
363 leftPanel.add(l);
364 JScrollPane sp = createDirectoryList();
365 sp.getVerticalScrollBar().setFocusable(false);
366 sp.getHorizontalScrollBar().setFocusable(false);
367 sp.setInheritsPopupMenu(true);
397 accessoryPanel.setPreferredSize(ZERO_ACC_SIZE);
398 accessoryPanel.setMaximumSize(ZERO_ACC_SIZE);
399 } else {
400 getAccessoryPanel().add(accessory, BorderLayout.CENTER);
401 accessoryPanel.setPreferredSize(PREF_ACC_SIZE);
402 accessoryPanel.setMaximumSize(MAX_SIZE);
403 }
404 align(accessoryPanel);
405 centerPanel.add(accessoryPanel);
406 accessoryPanel.setInheritsPopupMenu(true);
407 }
408 interior.add(centerPanel);
409 interior.add(Box.createRigidArea(vstrut10));
410
411 // add the filename field PENDING(jeff) - I18N
412 fileNameLabel = new JLabel();
413 populateFileNameLabel();
414 align(fileNameLabel);
415 interior.add(fileNameLabel);
416
417 filenameTextField = new JTextField() {
418 public Dimension getMaximumSize() {
419 Dimension d = super.getMaximumSize();
420 d.height = getPreferredSize().height;
421 return d;
422 }
423 };
424 filenameTextField.setInheritsPopupMenu(true);
425 fileNameLabel.setLabelFor(filenameTextField);
426 filenameTextField.addActionListener(getApproveSelectionAction());
427 align(filenameTextField);
428 filenameTextField.setAlignmentX(JComponent.LEFT_ALIGNMENT);
429 interior.add(filenameTextField);
430
431 bottomPanel = getBottomPanel();
432 bottomPanel.add(new JSeparator(), BorderLayout.NORTH);
433
434 // Add buttons
435 JPanel buttonPanel = new JPanel();
436 align(buttonPanel);
437 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
438 buttonPanel.add(Box.createGlue());
439
440 approveButton = new JButton(getApproveButtonText(fc)) {
441 public Dimension getMaximumSize() {
442 return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
443 }
444 };
445 approveButton.setMnemonic(getApproveButtonMnemonic(fc));
446 approveButton.setToolTipText(getApproveButtonToolTipText(fc));
447 approveButton.setInheritsPopupMenu(true);
448 align(approveButton);
449 approveButton.setMargin(buttonMargin);
450 approveButton.addActionListener(getApproveSelectionAction());
451 buttonPanel.add(approveButton);
452 buttonPanel.add(Box.createGlue());
453
454 JButton updateButton = new JButton(updateButtonText) {
455 public Dimension getMaximumSize() {
456 return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
457 }
458 };
459 updateButton.setMnemonic(updateButtonMnemonic);
460 updateButton.setToolTipText(updateButtonToolTipText);
461 updateButton.setInheritsPopupMenu(true);
462 align(updateButton);
463 updateButton.setMargin(buttonMargin);
464 updateButton.addActionListener(getUpdateAction());
465 buttonPanel.add(updateButton);
466 buttonPanel.add(Box.createGlue());
467
468 JButton cancelButton = new JButton(cancelButtonText) {
469 public Dimension getMaximumSize() {
470 return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
471 }
472 };
473 cancelButton.setMnemonic(cancelButtonMnemonic);
474 cancelButton.setToolTipText(cancelButtonToolTipText);
475 cancelButton.setInheritsPopupMenu(true);
476 align(cancelButton);
477 cancelButton.setMargin(buttonMargin);
478 cancelButton.addActionListener(getCancelSelectionAction());
479 buttonPanel.add(cancelButton);
480 buttonPanel.add(Box.createGlue());
481
482 JButton helpButton = new JButton(helpButtonText) {
483 public Dimension getMaximumSize() {
484 return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
485 }
486 };
487 helpButton.setMnemonic(helpButtonMnemonic);
488 helpButton.setToolTipText(helpButtonToolTipText);
489 align(helpButton);
490 helpButton.setMargin(buttonMargin);
491 helpButton.setEnabled(false);
492 helpButton.setInheritsPopupMenu(true);
493 buttonPanel.add(helpButton);
494 buttonPanel.add(Box.createGlue());
495 buttonPanel.setInheritsPopupMenu(true);
496
497 bottomPanel.add(buttonPanel, BorderLayout.SOUTH);
498 bottomPanel.setInheritsPopupMenu(true);
499 if (fc.getControlButtonsAreShown()) {
500 fc.add(bottomPanel, BorderLayout.SOUTH);
501 }
624 return new Dimension(d.width < prefSize.width ? prefSize.width : d.width,
625 d.height < prefSize.height ? prefSize.height : d.height);
626 } else {
627 return prefSize;
628 }
629 }
630
631 public Dimension getMinimumSize(JComponent x) {
632 return MIN_SIZE;
633 }
634
635 public Dimension getMaximumSize(JComponent x) {
636 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
637 }
638
639 protected void align(JComponent c) {
640 c.setAlignmentX(JComponent.LEFT_ALIGNMENT);
641 c.setAlignmentY(JComponent.TOP_ALIGNMENT);
642 }
643
644 protected class FileCellRenderer extends DefaultListCellRenderer {
645 public Component getListCellRendererComponent(JList list, Object value, int index,
646 boolean isSelected, boolean cellHasFocus) {
647
648 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
649 setText(getFileChooser().getName((File) value));
650 setInheritsPopupMenu(true);
651 return this;
652 }
653 }
654
655 protected class DirectoryCellRenderer extends DefaultListCellRenderer {
656 public Component getListCellRendererComponent(JList list, Object value, int index,
657 boolean isSelected, boolean cellHasFocus) {
658
659 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
660 setText(getFileChooser().getName((File) value));
661 setInheritsPopupMenu(true);
662 return this;
663 }
664 }
665
666 protected class MotifDirectoryListModel extends AbstractListModel<File> implements ListDataListener {
667 public MotifDirectoryListModel() {
668 getModel().addListDataListener(this);
669 }
670
671 public int getSize() {
672 return getModel().getDirectories().size();
673 }
674
675 public File getElementAt(int index) {
676 return getModel().getDirectories().elementAt(index);
677 }
678
679 public void intervalAdded(ListDataEvent e) {
680 fireIntervalAdded(this, e.getIndex0(), e.getIndex1());
681 }
682
683 public void intervalRemoved(ListDataEvent e) {
684 fireIntervalRemoved(this, e.getIndex0(), e.getIndex1());
685 }
686
687 // PENDING(jeff) - this is inefficient - should sent out
688 // incremental adjustment values instead of saying that the
689 // whole list has changed.
690 public void fireContentsChanged() {
691 fireContentsChanged(this, 0, getModel().getDirectories().size()-1);
692 }
693
694 // PENDING(jeff) - fire the correct interval changed - currently sending
695 // out that everything has changed
696 public void contentsChanged(ListDataEvent e) {
697 fireContentsChanged();
698 }
699
700 }
701
702 protected class MotifFileListModel extends AbstractListModel<File> implements ListDataListener {
703 public MotifFileListModel() {
704 getModel().addListDataListener(this);
705 }
706
707 public int getSize() {
708 return getModel().getFiles().size();
709 }
710
711 public boolean contains(Object o) {
712 return getModel().getFiles().contains(o);
713 }
714
715 public int indexOf(Object o) {
716 return getModel().getFiles().indexOf(o);
717 }
718
719 public File getElementAt(int index) {
720 return getModel().getFiles().elementAt(index);
721 }
743 }
744
745 //
746 // DataModel for Types Comboxbox
747 //
748 protected FilterComboBoxModel createFilterComboBoxModel() {
749 return new FilterComboBoxModel();
750 }
751
752 //
753 // Renderer for Types ComboBox
754 //
755 protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
756 return new FilterComboBoxRenderer();
757 }
758
759
760 /**
761 * Render different type sizes and styles.
762 */
763 public class FilterComboBoxRenderer extends DefaultListCellRenderer {
764 public Component getListCellRendererComponent(JList list,
765 Object value, int index, boolean isSelected,
766 boolean cellHasFocus) {
767
768 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
769
770 if (value != null && value instanceof FileFilter) {
771 setText(((FileFilter)value).getDescription());
772 }
773
774 return this;
775 }
776 }
777
778 /**
779 * Data model for a type-face selection combo-box.
780 */
781 protected class FilterComboBoxModel extends AbstractFilterComboBoxModel {
782 protected JFileChooser getFileChooser() {
783 return MotifFileChooserUI.this.getFileChooser();
784 }
785 }
786
787 protected JButton getApproveButton(JFileChooser fc) {
788 return approveButton;
789 }
790
791 }
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
265 //
266 public static ComponentUI createUI(JComponent c) {
267 return new MotifFileChooserUI((JFileChooser)c);
268 }
269
270 public void installUI(JComponent c) {
271 super.installUI(c);
272 }
273
274 public void uninstallUI(JComponent c) {
275 c.removePropertyChangeListener(filterComboBoxModel);
276 approveButton.removeActionListener(getApproveSelectionAction());
277 filenameTextField.removeActionListener(getApproveSelectionAction());
278 super.uninstallUI(c);
279 }
280
281 public void installComponents(JFileChooser fc) {
282 fc.setLayout(new BorderLayout(10, 10));
283 fc.setAlignmentX(JComponent.CENTER_ALIGNMENT);
284
285 @SuppressWarnings("serial") // anonymous class
286 JPanel interior = new JPanel() {
287 public Insets getInsets() {
288 return insets;
289 }
290 };
291 interior.setInheritsPopupMenu(true);
292 align(interior);
293 interior.setLayout(new BoxLayout(interior, BoxLayout.PAGE_AXIS));
294
295 fc.add(interior, BorderLayout.CENTER);
296
297 // PENDING(jeff) - I18N
298 JLabel l = new JLabel(pathLabelText);
299 l.setDisplayedMnemonic(pathLabelMnemonic);
300 align(l);
301 interior.add(l);
302
303 File currentDirectory = fc.getCurrentDirectory();
304 String curDirName = null;
305 if(currentDirectory != null) {
306 curDirName = currentDirectory.getPath();
307 }
308
309 @SuppressWarnings("serial") // anonymous class
310 JTextField tmp1 = new JTextField(curDirName) {
311 public Dimension getMaximumSize() {
312 Dimension d = super.getMaximumSize();
313 d.height = getPreferredSize().height;
314 return d;
315 }
316 };
317 pathField = tmp1;
318 pathField.setInheritsPopupMenu(true);
319 l.setLabelFor(pathField);
320 align(pathField);
321
322 // Change to folder on return
323 pathField.addActionListener(getUpdateAction());
324 interior.add(pathField);
325
326 interior.add(Box.createRigidArea(vstrut10));
327
328
329 // CENTER: left, right accessory
330 JPanel centerPanel = new JPanel();
331 centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.LINE_AXIS));
332 align(centerPanel);
333
334 // left panel - Filter & folderList
335 JPanel leftPanel = new JPanel();
336 leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
337 align(leftPanel);
338
339 // add the filter PENDING(jeff) - I18N
340 l = new JLabel(filterLabelText);
341 l.setDisplayedMnemonic(filterLabelMnemonic);
342 align(l);
343 leftPanel.add(l);
344
345 @SuppressWarnings("serial") // anonymous class
346 JComboBox tmp2 = new JComboBox<FileFilter>() {
347 public Dimension getMaximumSize() {
348 Dimension d = super.getMaximumSize();
349 d.height = getPreferredSize().height;
350 return d;
351 }
352 };
353 filterComboBox = tmp2;
354 filterComboBox.setInheritsPopupMenu(true);
355 l.setLabelFor(filterComboBox);
356 filterComboBoxModel = createFilterComboBoxModel();
357 filterComboBox.setModel(filterComboBoxModel);
358 filterComboBox.setRenderer(createFilterComboBoxRenderer());
359 fc.addPropertyChangeListener(filterComboBoxModel);
360 align(filterComboBox);
361 leftPanel.add(filterComboBox);
362
363 // leftPanel.add(Box.createRigidArea(vstrut10));
364
365 // Add the Folder List PENDING(jeff) - I18N
366 l = new JLabel(foldersLabelText);
367 l.setDisplayedMnemonic(foldersLabelMnemonic);
368 align(l);
369 leftPanel.add(l);
370 JScrollPane sp = createDirectoryList();
371 sp.getVerticalScrollBar().setFocusable(false);
372 sp.getHorizontalScrollBar().setFocusable(false);
373 sp.setInheritsPopupMenu(true);
403 accessoryPanel.setPreferredSize(ZERO_ACC_SIZE);
404 accessoryPanel.setMaximumSize(ZERO_ACC_SIZE);
405 } else {
406 getAccessoryPanel().add(accessory, BorderLayout.CENTER);
407 accessoryPanel.setPreferredSize(PREF_ACC_SIZE);
408 accessoryPanel.setMaximumSize(MAX_SIZE);
409 }
410 align(accessoryPanel);
411 centerPanel.add(accessoryPanel);
412 accessoryPanel.setInheritsPopupMenu(true);
413 }
414 interior.add(centerPanel);
415 interior.add(Box.createRigidArea(vstrut10));
416
417 // add the filename field PENDING(jeff) - I18N
418 fileNameLabel = new JLabel();
419 populateFileNameLabel();
420 align(fileNameLabel);
421 interior.add(fileNameLabel);
422
423 @SuppressWarnings("serial") // anonymous class
424 JTextField tmp3 = new JTextField() {
425 public Dimension getMaximumSize() {
426 Dimension d = super.getMaximumSize();
427 d.height = getPreferredSize().height;
428 return d;
429 }
430 };
431 filenameTextField = tmp3;
432 filenameTextField.setInheritsPopupMenu(true);
433 fileNameLabel.setLabelFor(filenameTextField);
434 filenameTextField.addActionListener(getApproveSelectionAction());
435 align(filenameTextField);
436 filenameTextField.setAlignmentX(JComponent.LEFT_ALIGNMENT);
437 interior.add(filenameTextField);
438
439 bottomPanel = getBottomPanel();
440 bottomPanel.add(new JSeparator(), BorderLayout.NORTH);
441
442 // Add buttons
443 JPanel buttonPanel = new JPanel();
444 align(buttonPanel);
445 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
446 buttonPanel.add(Box.createGlue());
447
448 @SuppressWarnings("serial") // anonymous class
449 JButton tmp4 = new JButton(getApproveButtonText(fc)) {
450 public Dimension getMaximumSize() {
451 return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
452 }
453 };
454 approveButton = tmp4;
455 approveButton.setMnemonic(getApproveButtonMnemonic(fc));
456 approveButton.setToolTipText(getApproveButtonToolTipText(fc));
457 approveButton.setInheritsPopupMenu(true);
458 align(approveButton);
459 approveButton.setMargin(buttonMargin);
460 approveButton.addActionListener(getApproveSelectionAction());
461 buttonPanel.add(approveButton);
462 buttonPanel.add(Box.createGlue());
463
464 @SuppressWarnings("serial") // anonymous class
465 JButton updateButton = new JButton(updateButtonText) {
466 public Dimension getMaximumSize() {
467 return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
468 }
469 };
470 updateButton.setMnemonic(updateButtonMnemonic);
471 updateButton.setToolTipText(updateButtonToolTipText);
472 updateButton.setInheritsPopupMenu(true);
473 align(updateButton);
474 updateButton.setMargin(buttonMargin);
475 updateButton.addActionListener(getUpdateAction());
476 buttonPanel.add(updateButton);
477 buttonPanel.add(Box.createGlue());
478
479 @SuppressWarnings("serial") // anonymous class
480 JButton cancelButton = new JButton(cancelButtonText) {
481 public Dimension getMaximumSize() {
482 return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
483 }
484 };
485 cancelButton.setMnemonic(cancelButtonMnemonic);
486 cancelButton.setToolTipText(cancelButtonToolTipText);
487 cancelButton.setInheritsPopupMenu(true);
488 align(cancelButton);
489 cancelButton.setMargin(buttonMargin);
490 cancelButton.addActionListener(getCancelSelectionAction());
491 buttonPanel.add(cancelButton);
492 buttonPanel.add(Box.createGlue());
493
494 @SuppressWarnings("serial") // anonymous class
495 JButton helpButton = new JButton(helpButtonText) {
496 public Dimension getMaximumSize() {
497 return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
498 }
499 };
500 helpButton.setMnemonic(helpButtonMnemonic);
501 helpButton.setToolTipText(helpButtonToolTipText);
502 align(helpButton);
503 helpButton.setMargin(buttonMargin);
504 helpButton.setEnabled(false);
505 helpButton.setInheritsPopupMenu(true);
506 buttonPanel.add(helpButton);
507 buttonPanel.add(Box.createGlue());
508 buttonPanel.setInheritsPopupMenu(true);
509
510 bottomPanel.add(buttonPanel, BorderLayout.SOUTH);
511 bottomPanel.setInheritsPopupMenu(true);
512 if (fc.getControlButtonsAreShown()) {
513 fc.add(bottomPanel, BorderLayout.SOUTH);
514 }
637 return new Dimension(d.width < prefSize.width ? prefSize.width : d.width,
638 d.height < prefSize.height ? prefSize.height : d.height);
639 } else {
640 return prefSize;
641 }
642 }
643
644 public Dimension getMinimumSize(JComponent x) {
645 return MIN_SIZE;
646 }
647
648 public Dimension getMaximumSize(JComponent x) {
649 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
650 }
651
652 protected void align(JComponent c) {
653 c.setAlignmentX(JComponent.LEFT_ALIGNMENT);
654 c.setAlignmentY(JComponent.TOP_ALIGNMENT);
655 }
656
657 @SuppressWarnings("serial") // Superclass is not serializable across versions
658 protected class FileCellRenderer extends DefaultListCellRenderer {
659 public Component getListCellRendererComponent(JList list, Object value, int index,
660 boolean isSelected, boolean cellHasFocus) {
661
662 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
663 setText(getFileChooser().getName((File) value));
664 setInheritsPopupMenu(true);
665 return this;
666 }
667 }
668
669 @SuppressWarnings("serial") // Superclass is not serializable across versions
670 protected class DirectoryCellRenderer extends DefaultListCellRenderer {
671 public Component getListCellRendererComponent(JList list, Object value, int index,
672 boolean isSelected, boolean cellHasFocus) {
673
674 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
675 setText(getFileChooser().getName((File) value));
676 setInheritsPopupMenu(true);
677 return this;
678 }
679 }
680
681 @SuppressWarnings("serial") // Superclass is not serializable across versions
682 protected class MotifDirectoryListModel extends AbstractListModel<File> implements ListDataListener {
683 public MotifDirectoryListModel() {
684 getModel().addListDataListener(this);
685 }
686
687 public int getSize() {
688 return getModel().getDirectories().size();
689 }
690
691 public File getElementAt(int index) {
692 return getModel().getDirectories().elementAt(index);
693 }
694
695 public void intervalAdded(ListDataEvent e) {
696 fireIntervalAdded(this, e.getIndex0(), e.getIndex1());
697 }
698
699 public void intervalRemoved(ListDataEvent e) {
700 fireIntervalRemoved(this, e.getIndex0(), e.getIndex1());
701 }
702
703 // PENDING(jeff) - this is inefficient - should sent out
704 // incremental adjustment values instead of saying that the
705 // whole list has changed.
706 public void fireContentsChanged() {
707 fireContentsChanged(this, 0, getModel().getDirectories().size()-1);
708 }
709
710 // PENDING(jeff) - fire the correct interval changed - currently sending
711 // out that everything has changed
712 public void contentsChanged(ListDataEvent e) {
713 fireContentsChanged();
714 }
715
716 }
717
718 @SuppressWarnings("serial") // Superclass is not serializable across versions
719 protected class MotifFileListModel extends AbstractListModel<File> implements ListDataListener {
720 public MotifFileListModel() {
721 getModel().addListDataListener(this);
722 }
723
724 public int getSize() {
725 return getModel().getFiles().size();
726 }
727
728 public boolean contains(Object o) {
729 return getModel().getFiles().contains(o);
730 }
731
732 public int indexOf(Object o) {
733 return getModel().getFiles().indexOf(o);
734 }
735
736 public File getElementAt(int index) {
737 return getModel().getFiles().elementAt(index);
738 }
760 }
761
762 //
763 // DataModel for Types Comboxbox
764 //
765 protected FilterComboBoxModel createFilterComboBoxModel() {
766 return new FilterComboBoxModel();
767 }
768
769 //
770 // Renderer for Types ComboBox
771 //
772 protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
773 return new FilterComboBoxRenderer();
774 }
775
776
777 /**
778 * Render different type sizes and styles.
779 */
780 @SuppressWarnings("serial") // Superclass is not serializable across versions
781 public class FilterComboBoxRenderer extends DefaultListCellRenderer {
782 public Component getListCellRendererComponent(JList list,
783 Object value, int index, boolean isSelected,
784 boolean cellHasFocus) {
785
786 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
787
788 if (value != null && value instanceof FileFilter) {
789 setText(((FileFilter)value).getDescription());
790 }
791
792 return this;
793 }
794 }
795
796 /**
797 * Data model for a type-face selection combo-box.
798 */
799 @SuppressWarnings("serial") // Superclass is a JDK-implementation class
800 protected class FilterComboBoxModel extends AbstractFilterComboBoxModel {
801 protected JFileChooser getFileChooser() {
802 return MotifFileChooserUI.this.getFileChooser();
803 }
804 }
805
806 protected JButton getApproveButton(JFileChooser fc) {
807 return approveButton;
808 }
809
810 }
|