⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 motiffilechooserui.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    public Dimension getMaximumSize() {		return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);	    }	};	approveButton.setMnemonic(getApproveButtonMnemonic(fc));	approveButton.setToolTipText(getApproveButtonToolTipText(fc));        approveButton.setInheritsPopupMenu(true);	align(approveButton);	approveButton.setMargin(buttonMargin);	approveButton.addActionListener(getApproveSelectionAction());	buttonPanel.add(approveButton);	buttonPanel.add(Box.createGlue());	JButton updateButton = new JButton(updateButtonText) {	    public Dimension getMaximumSize() {		return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);	    }	};	updateButton.setMnemonic(updateButtonMnemonic);	updateButton.setToolTipText(updateButtonToolTipText);        updateButton.setInheritsPopupMenu(true);	align(updateButton);	updateButton.setMargin(buttonMargin);	updateButton.addActionListener(getUpdateAction());	buttonPanel.add(updateButton);	buttonPanel.add(Box.createGlue());	JButton cancelButton = new JButton(cancelButtonText) {	    public Dimension getMaximumSize() {		return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);	    }	};	cancelButton.setMnemonic(cancelButtonMnemonic);	cancelButton.setToolTipText(cancelButtonToolTipText);        cancelButton.setInheritsPopupMenu(true);	align(cancelButton);	cancelButton.setMargin(buttonMargin);	cancelButton.addActionListener(getCancelSelectionAction());	buttonPanel.add(cancelButton);	buttonPanel.add(Box.createGlue());	JButton helpButton = new JButton(helpButtonText) {	    public Dimension getMaximumSize() {		return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);	    }	};	helpButton.setMnemonic(helpButtonMnemonic);	helpButton.setToolTipText(helpButtonToolTipText);	align(helpButton);	helpButton.setMargin(buttonMargin);	helpButton.setEnabled(false);        helpButton.setInheritsPopupMenu(true);	buttonPanel.add(helpButton);	buttonPanel.add(Box.createGlue());        buttonPanel.setInheritsPopupMenu(true);	bottomPanel.add(buttonPanel, BorderLayout.SOUTH);        bottomPanel.setInheritsPopupMenu(true);	if (fc.getControlButtonsAreShown()) {           fc.add(bottomPanel, BorderLayout.SOUTH);        }    }    protected JPanel getBottomPanel() {        if (bottomPanel == null) {            bottomPanel = new JPanel(new BorderLayout(0, 4));        }        return bottomPanel;    }    private void doControlButtonsChanged(PropertyChangeEvent e) {        if (getFileChooser().getControlButtonsAreShown()) {            getFileChooser().add(bottomPanel,BorderLayout.SOUTH);        } else {            getFileChooser().remove(getBottomPanel());        }    }    public void uninstallComponents(JFileChooser fc) {	fc.removeAll();	bottomPanel = null;	directoryPanel = null;    }    protected void installStrings(JFileChooser fc) {        super.installStrings(fc);        Locale l = fc.getLocale();	enterFileNameLabelText = UIManager.getString("FileChooser.enterFileNameLabelText",l);	enterFileNameLabelMnemonic = UIManager.getInt("FileChooser.enterFileNameLabelMnemonic"); 		filesLabelText = UIManager.getString("FileChooser.filesLabelText",l);	filesLabelMnemonic = UIManager.getInt("FileChooser.filesLabelMnemonic"); 		foldersLabelText = UIManager.getString("FileChooser.foldersLabelText",l);	foldersLabelMnemonic = UIManager.getInt("FileChooser.foldersLabelMnemonic"); 		pathLabelText = UIManager.getString("FileChooser.pathLabelText",l);	pathLabelMnemonic = UIManager.getInt("FileChooser.pathLabelMnemonic"); 		filterLabelText = UIManager.getString("FileChooser.filterLabelText",l);	filterLabelMnemonic = UIManager.getInt("FileChooser.filterLabelMnemonic");      }    protected void installIcons(JFileChooser fc) {	// Since motif doesn't have button icons, leave this empty	// which overrides the supertype icon loading    }    protected void uninstallIcons(JFileChooser fc) {	// Since motif doesn't have button icons, leave this empty	// which overrides the supertype icon loading    }    protected JScrollPane createFilesList() {	fileList = new JList();	if(getFileChooser().isMultiSelectionEnabled()) {	    fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);	} else {	    fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);	}		fileList.setModel(new MotifFileListModel());        fileList.getSelectionModel().removeSelectionInterval(0, 0);	fileList.setCellRenderer(new FileCellRenderer());	fileList.addListSelectionListener(createListSelectionListener(getFileChooser()));	fileList.addMouseListener(createDoubleClickListener(getFileChooser(), fileList));        fileList.addMouseListener(new MouseAdapter() {            public void mouseClicked(MouseEvent e) {                JFileChooser chooser = getFileChooser();                if (SwingUtilities.isLeftMouseButton(e) && !chooser.isMultiSelectionEnabled()) {                    int index = SwingUtilities2.loc2IndexFileList(fileList, e.getPoint());                    if (index >= 0) {                        File file = (File) fileList.getModel().getElementAt(index);                        setFileName(chooser.getName(file));                    }                }            }        });	align(fileList);	JScrollPane scrollpane = new JScrollPane(fileList);	scrollpane.setPreferredSize(prefListSize);	scrollpane.setMaximumSize(MAX_SIZE);	align(scrollpane);        fileList.setInheritsPopupMenu(true);        scrollpane.setInheritsPopupMenu(true);	return scrollpane;    }    protected JScrollPane createDirectoryList() {	directoryList = new JList();	align(directoryList);	directoryList.setCellRenderer(new DirectoryCellRenderer());	directoryList.setModel(new MotifDirectoryListModel());        directoryList.getSelectionModel().removeSelectionInterval(0, 0);	directoryList.addMouseListener(createDoubleClickListener(getFileChooser(), directoryList));	directoryList.addListSelectionListener(createListSelectionListener(getFileChooser()));        directoryList.setInheritsPopupMenu(true);	JScrollPane scrollpane = new JScrollPane(directoryList);	scrollpane.setMaximumSize(MAX_SIZE);	scrollpane.setPreferredSize(prefListSize);        scrollpane.setInheritsPopupMenu(true);	align(scrollpane);	return scrollpane;    }    public Dimension getPreferredSize(JComponent c) {	Dimension prefSize =	    (getFileChooser().getAccessory() != null) ? WITH_ACCELERATOR_PREF_SIZE : PREF_SIZE;	Dimension d = c.getLayout().preferredLayoutSize(c);	if (d != null) {	    return new Dimension(d.width < prefSize.width ? prefSize.width : d.width,				 d.height < prefSize.height ? prefSize.height : d.height);	} else {	    return prefSize;	}    }    public Dimension getMinimumSize(JComponent x)  {	return MIN_SIZE;    }    public Dimension getMaximumSize(JComponent x) {	return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);    }    protected void align(JComponent c) {	c.setAlignmentX(JComponent.LEFT_ALIGNMENT);	c.setAlignmentY(JComponent.TOP_ALIGNMENT);    }    protected class FileCellRenderer extends DefaultListCellRenderer  {	public Component getListCellRendererComponent(JList list, Object value, int index,						      boolean isSelected, boolean cellHasFocus) {	    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);	    setText(getFileChooser().getName((File) value));            setInheritsPopupMenu(true);	    return this;	}    }    protected class DirectoryCellRenderer extends DefaultListCellRenderer  {	public Component getListCellRendererComponent(JList list, Object value, int index,						      boolean isSelected, boolean cellHasFocus) {	    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);	    setText(getFileChooser().getName((File) value));            setInheritsPopupMenu(true);	    return this;	}    }    protected class MotifDirectoryListModel extends AbstractListModel implements ListDataListener {	public MotifDirectoryListModel() {	    getModel().addListDataListener(this);	}	public int getSize() {	    return getModel().getDirectories().size();	}	public Object getElementAt(int index) {	    return getModel().getDirectories().elementAt(index);	}	public void intervalAdded(ListDataEvent e) {            fireIntervalAdded(this, e.getIndex0(), e.getIndex1());	}	public void intervalRemoved(ListDataEvent e) {            fireIntervalRemoved(this, e.getIndex0(), e.getIndex1());	}	// PENDING(jeff) - this is inefficient - should sent out	// incremental adjustment values instead of saying that the	// whole list has changed.	public void fireContentsChanged() {	    fireContentsChanged(this, 0, getModel().getDirectories().size()-1);	}	// PENDING(jeff) - fire the correct interval changed - currently sending	// out that everything has changed	public void contentsChanged(ListDataEvent e) {	    fireContentsChanged();	}    }    protected class MotifFileListModel extends AbstractListModel implements ListDataListener {	public MotifFileListModel() {	    getModel().addListDataListener(this);	}	public int getSize() {	    return getModel().getFiles().size();	}	public boolean contains(Object o) {	    return getModel().getFiles().contains(o);	}	public int indexOf(Object o) {	    return getModel().getFiles().indexOf(o);	}	public Object getElementAt(int index) {	    return getModel().getFiles().elementAt(index);	}	public void intervalAdded(ListDataEvent e) {            fireIntervalAdded(this, e.getIndex0(), e.getIndex1());	}	public void intervalRemoved(ListDataEvent e) {            fireIntervalRemoved(this, e.getIndex0(), e.getIndex1());	}	// PENDING(jeff) - this is inefficient - should sent out	// incremental adjustment values instead of saying that the	// whole list has changed.	public void fireContentsChanged() {	    fireContentsChanged(this, 0, getModel().getFiles().size()-1);	}	// PENDING(jeff) - fire the interval changed	public void contentsChanged(ListDataEvent e) {	    fireContentsChanged();	}    }    //    // DataModel for Types Comboxbox    //    protected FilterComboBoxModel createFilterComboBoxModel() {	return new FilterComboBoxModel();    }    //    // Renderer for Types ComboBox    //    protected FilterComboBoxRenderer createFilterComboBoxRenderer() {	return new FilterComboBoxRenderer();    }    /**     * Render different type sizes and styles.     */    public class FilterComboBoxRenderer extends DefaultListCellRenderer {	public Component getListCellRendererComponent(JList list,	    Object value, int index, boolean isSelected,	    boolean cellHasFocus) {	    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);	    if (value != null && value instanceof FileFilter) {		setText(((FileFilter)value).getDescription());	    }	    return this;	}    }    /**     * Data model for a type-face selection combo-box.     */    protected class FilterComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener {	protected FileFilter[] filters;	protected FilterComboBoxModel() {	    super();	    filters = getFileChooser().getChoosableFileFilters();	}	public void propertyChange(PropertyChangeEvent e) {	    String prop = e.getPropertyName();	    if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {		filters = (FileFilter[]) e.getNewValue();		fireContentsChanged(this, -1, -1);	    } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {		fireContentsChanged(this, -1, -1);	    }	}	public void setSelectedItem(Object filter) {	    if(filter != null) {		getFileChooser().setFileFilter((FileFilter) filter);		fireContentsChanged(this, -1, -1);	    }	}	public Object getSelectedItem() {	    // Ensure that the current filter is in the list.	    // NOTE: we shouldnt' have to do this, since JFileChooser adds	    // the filter to the choosable filters list when the filter	    // is set. Lets be paranoid just in case someone overrides	    // setFileFilter in JFileChooser.	    FileFilter currentFilter = getFileChooser().getFileFilter();	    boolean found = false;	    if(currentFilter != null) {		for(int i=0; i < filters.length; i++) {		    if(filters[i] == currentFilter) {			found = true;		    }		}		if(found == false) {		    getFileChooser().addChoosableFileFilter(currentFilter);		}	    }	    return getFileChooser().getFileFilter();	}	public int getSize() {	    if(filters != null) {		return filters.length;	    } else {		return 0;	    }	}	public Object getElementAt(int index) {	    if(index > getSize() - 1) {		// This shouldn't happen. Try to recover gracefully.		return getFileChooser().getFileFilter();	    }	    if(filters != null) {		return filters[index];	    } else {		return null;	    }	}    }    protected JButton getApproveButton(JFileChooser fc) {	return approveButton;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -