提交 ebf5be44 编写于 作者: R rupashka

6554743: JFileChooser dn't close after pressing escape key after changing the views

Summary: Restore focus after changing the views in JFileChooser
Reviewed-by: loneid
上级 cc745e0b
......@@ -308,44 +308,80 @@ public class FilePane extends JPanel implements PropertyChangeListener {
}
public void setViewType(int viewType) {
int oldValue = this.viewType;
if (viewType == oldValue) {
if (viewType == this.viewType) {
return;
}
int oldValue = this.viewType;
this.viewType = viewType;
JPanel createdViewPanel = null;
Component newFocusOwner = null;
switch (viewType) {
case VIEWTYPE_LIST:
if (viewPanels[viewType] == null) {
JPanel p = fileChooserUIAccessor.createList();
if (p == null) {
p = createList();
createdViewPanel = fileChooserUIAccessor.createList();
if (createdViewPanel == null) {
createdViewPanel = createList();
}
list = (JList) findChildComponent(createdViewPanel, JList.class);
if (listSelectionModel == null) {
listSelectionModel = list.getSelectionModel();
if (detailsTable != null) {
detailsTable.setSelectionModel(listSelectionModel);
}
} else {
list.setSelectionModel(listSelectionModel);
}
setViewPanel(viewType, p);
}
list.setLayoutOrientation(JList.VERTICAL_WRAP);
newFocusOwner = list;
break;
case VIEWTYPE_DETAILS:
if (viewPanels[viewType] == null) {
JPanel p = fileChooserUIAccessor.createDetailsView();
if (p == null) {
p = createDetailsView();
createdViewPanel = fileChooserUIAccessor.createDetailsView();
if (createdViewPanel == null) {
createdViewPanel = createDetailsView();
}
detailsTable = (JTable) findChildComponent(createdViewPanel, JTable.class);
detailsTable.setRowHeight(Math.max(detailsTable.getFont().getSize() + 4, 16 + 1));
if (listSelectionModel != null) {
detailsTable.setSelectionModel(listSelectionModel);
}
setViewPanel(viewType, p);
}
newFocusOwner = detailsTable;
break;
}
JPanel oldViewPanel = currentViewPanel;
if (createdViewPanel != null) {
viewPanels[viewType] = createdViewPanel;
recursivelySetInheritsPopupMenu(createdViewPanel, true);
}
boolean isFocusOwner = false;
if (currentViewPanel != null) {
Component owner = DefaultKeyboardFocusManager.
getCurrentKeyboardFocusManager().getPermanentFocusOwner();
isFocusOwner = owner == detailsTable || owner == list;
remove(currentViewPanel);
}
currentViewPanel = viewPanels[viewType];
if (currentViewPanel != oldViewPanel) {
if (oldViewPanel != null) {
remove(oldViewPanel);
}
add(currentViewPanel, BorderLayout.CENTER);
revalidate();
repaint();
add(currentViewPanel, BorderLayout.CENTER);
if (isFocusOwner && newFocusOwner != null) {
newFocusOwner.requestFocusInWindow();
}
revalidate();
repaint();
updateViewMenu();
firePropertyChange("viewType", oldValue, viewType);
}
......@@ -385,42 +421,6 @@ public class FilePane extends JPanel implements PropertyChangeListener {
}
}
public void setViewPanel(int viewType, JPanel viewPanel) {
viewPanels[viewType] = viewPanel;
recursivelySetInheritsPopupMenu(viewPanel, true);
switch (viewType) {
case VIEWTYPE_LIST:
list = (JList)findChildComponent(viewPanels[viewType], JList.class);
if (listSelectionModel == null) {
listSelectionModel = list.getSelectionModel();
if (detailsTable != null) {
detailsTable.setSelectionModel(listSelectionModel);
}
} else {
list.setSelectionModel(listSelectionModel);
}
break;
case VIEWTYPE_DETAILS:
detailsTable = (JTable)findChildComponent(viewPanels[viewType], JTable.class);
detailsTable.setRowHeight(Math.max(detailsTable.getFont().getSize() + 4, 16+1));
if (listSelectionModel != null) {
detailsTable.setSelectionModel(listSelectionModel);
}
break;
}
if (this.viewType == viewType) {
if (currentViewPanel != null) {
remove(currentViewPanel);
}
currentViewPanel = viewPanel;
add(currentViewPanel, BorderLayout.CENTER);
revalidate();
repaint();
}
}
protected void installDefaults() {
Locale l = getFileChooser().getLocale();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册