mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[platform] list models generified to match Swing interfaces
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.openapi.ui;
|
||||
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
@@ -21,37 +20,26 @@ import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Vector;
|
||||
|
||||
public class ComboBoxWithWidePopup<E> extends JComboBox<E> {
|
||||
|
||||
private boolean myLayingOut = false;
|
||||
private int myMinLength = 20;
|
||||
|
||||
public ComboBoxWithWidePopup() { }
|
||||
|
||||
public ComboBoxWithWidePopup(final ComboBoxModel<E> aModel) {
|
||||
super(aModel);
|
||||
|
||||
if (SystemInfo.isMac && UIUtil.isUnderAquaLookAndFeel()) setMaximumRowCount(25);
|
||||
}
|
||||
|
||||
public ComboBoxWithWidePopup(final E[] items) {
|
||||
super(items);
|
||||
|
||||
if (SystemInfo.isMac && UIUtil.isUnderAquaLookAndFeel()) setMaximumRowCount(25);
|
||||
}
|
||||
|
||||
public ComboBoxWithWidePopup(@SuppressWarnings("UseOfObsoleteCollectionType") final Vector<E> items) {
|
||||
super(items);
|
||||
|
||||
if (SystemInfo.isMac && UIUtil.isUnderAquaLookAndFeel()) setMaximumRowCount(25);
|
||||
}
|
||||
|
||||
public ComboBoxWithWidePopup() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("GtkPreferredJComboBoxRenderer")
|
||||
@Override
|
||||
public void setRenderer(ListCellRenderer renderer) {
|
||||
public void setRenderer(ListCellRenderer<? super E> renderer) {
|
||||
super.setRenderer(new AdjustingListCellRenderer(this, renderer));
|
||||
}
|
||||
|
||||
@@ -112,8 +100,8 @@ public class ComboBoxWithWidePopup<E> extends JComboBox<E> {
|
||||
|
||||
if (size.width == 0) {
|
||||
if (stringValue.length() > minLength) {
|
||||
//noinspection unchecked
|
||||
_value = (E)stringValue.substring(0, minLength);
|
||||
@SuppressWarnings("unchecked") E e = (E)stringValue.substring(0, minLength);
|
||||
_value = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,4 +109,4 @@ public class ComboBoxWithWidePopup<E> extends JComboBox<E> {
|
||||
return myOldRenderer.getListCellRendererComponent(list, _value, index, isSelected, cellHasFocus);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,12 +25,11 @@ import java.util.List;
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public class CollectionComboBoxModel<T> extends CollectionListModel<T> implements ComboBoxModel {
|
||||
public class CollectionComboBoxModel<T> extends CollectionListModel<T> implements ComboBoxModel<T> {
|
||||
protected T mySelection;
|
||||
|
||||
public CollectionComboBoxModel() {
|
||||
super();
|
||||
|
||||
mySelection = null;
|
||||
}
|
||||
|
||||
@@ -40,15 +39,14 @@ public class CollectionComboBoxModel<T> extends CollectionListModel<T> implement
|
||||
|
||||
public CollectionComboBoxModel(@NotNull List<T> items, @Nullable T selection) {
|
||||
super(items, true);
|
||||
|
||||
mySelection = selection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedItem(@Nullable Object item) {
|
||||
if (mySelection != item) {
|
||||
//noinspection unchecked
|
||||
mySelection = (T)item;
|
||||
@SuppressWarnings("unchecked") T t = (T)item;
|
||||
mySelection = t;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,7 @@ import java.util.*;
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class CollectionListModel<T> extends AbstractListModel implements EditableModel {
|
||||
public class CollectionListModel<T> extends AbstractListModel<T> implements EditableModel {
|
||||
private final List<T> myItems;
|
||||
|
||||
public CollectionListModel(@NotNull final Collection<? extends T> items) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,7 @@ import static com.intellij.openapi.util.Pair.pair;
|
||||
* @author oleg
|
||||
* @since 30.09.2010
|
||||
*/
|
||||
public abstract class ListCellRendererWrapper<T> implements ListCellRenderer {
|
||||
public abstract class ListCellRendererWrapper<T> implements ListCellRenderer<T> {
|
||||
private final ListCellRenderer myDefaultRenderer;
|
||||
|
||||
private boolean mySeparator;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,13 +40,12 @@ import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class FileTypeChooser extends DialogWrapper {
|
||||
private JList myList;
|
||||
private JList<FileType> myList;
|
||||
private JLabel myTitleLabel;
|
||||
private ComboBox myPattern;
|
||||
private ComboBox<String> myPattern;
|
||||
private JPanel myPanel;
|
||||
private JRadioButton myOpenInIdea;
|
||||
private JRadioButton myOpenAsNative;
|
||||
@@ -54,32 +53,21 @@ public class FileTypeChooser extends DialogWrapper {
|
||||
|
||||
private FileTypeChooser(@NotNull List<String> patterns, @NotNull String fileName) {
|
||||
super(true);
|
||||
myFileName = fileName;
|
||||
|
||||
myFileName = fileName;
|
||||
myOpenInIdea.setText("Open matching files in " + ApplicationNamesInfo.getInstance().getFullProductName() + ":");
|
||||
|
||||
FileType[] fileTypes = FileTypeManager.getInstance().getRegisteredFileTypes();
|
||||
Arrays.sort(fileTypes, new Comparator<FileType>() {
|
||||
@Override
|
||||
public int compare(final FileType fileType1, final FileType fileType2) {
|
||||
if (fileType1 == null) {
|
||||
return 1;
|
||||
}
|
||||
if (fileType2 == null) {
|
||||
return -1;
|
||||
}
|
||||
return fileType1.getDescription().compareToIgnoreCase(fileType2.getDescription());
|
||||
}
|
||||
});
|
||||
Arrays.sort(fileTypes, (ft1, ft2) -> ft1 == null ? 1 : ft2 == null ? -1 : ft1.getDescription().compareToIgnoreCase(ft2.getDescription()));
|
||||
|
||||
final DefaultListModel model = new DefaultListModel();
|
||||
final DefaultListModel<FileType> model = new DefaultListModel<>();
|
||||
for (FileType type : fileTypes) {
|
||||
if (!type.isReadOnly() && type != FileTypes.UNKNOWN && !(type instanceof NativeFileType)) {
|
||||
model.addElement(type);
|
||||
}
|
||||
}
|
||||
myList.setModel(model);
|
||||
myPattern.setModel(new CollectionComboBoxModel(ContainerUtil.map(patterns, FunctionUtil.<String>id()), patterns.get(0)));
|
||||
myPattern.setModel(new CollectionComboBoxModel<>(ContainerUtil.map(patterns, FunctionUtil.id()), patterns.get(0)));
|
||||
|
||||
setTitle(FileTypesBundle.message("filetype.chooser.title"));
|
||||
init();
|
||||
@@ -129,13 +117,13 @@ public class FileTypeChooser extends DialogWrapper {
|
||||
}
|
||||
|
||||
public FileType getSelectedType() {
|
||||
return myOpenAsNative.isSelected() ? NativeFileType.INSTANCE : (FileType) myList.getSelectedValue();
|
||||
return myOpenAsNative.isSelected() ? NativeFileType.INSTANCE : myList.getSelectedValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* If fileName is already associated any known file type returns it.
|
||||
* Otherwise asks user to select file type and associates it with fileName extension if any selected.
|
||||
* @return Known file type or null. Never returns {@link com.intellij.openapi.fileTypes.FileTypes#UNKNOWN}.
|
||||
* @return Known file type or null. Never returns {@link FileTypes#UNKNOWN}.
|
||||
*/
|
||||
@Nullable
|
||||
public static FileType getKnownFileTypeOrAssociate(@NotNull VirtualFile file, @Nullable Project project) {
|
||||
@@ -205,4 +193,4 @@ public class FileTypeChooser extends DialogWrapper {
|
||||
protected String getHelpId() {
|
||||
return "reference.dialogs.register.association";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user