final CellConstraints cc = new CellConstraints();
FormLayout layout = new FormLayout("default,5dlu,0dlu:grow","default");
JPanel northPn = new JPanel(layout);
northPn.add(new JLabel(onlyUpdate ?mLocalizer.msg("updateHeader","Updates for installed plugins were found.") :
mLocalizer.msg("header","Here you can download new plugins and updates for it.")), cc.xyw(1,1,3));
JPanel southPn = new JPanel(new BorderLayout());
southPn.add(builder.getPanel(), BorderLayout.SOUTH);
ArrayList<SoftwareUpdateItem> selectedItems = new ArrayList<SoftwareUpdateItem>();
for (SoftwareUpdateItem item : itemArr) {
if (item.isAlreadyInstalled() && item.getInstalledVersion().compareTo(item.getVersion()) < 0) {
selectedItems.add(item);
}
}
mDownloadBtn.setEnabled(!selectedItems.isEmpty());
mSoftwareUpdateItemList = new SelectableItemList(selectedItems.toArray(new SoftwareUpdateItem[selectedItems.size()]),itemArr);
mSoftwareUpdateItemList.addListSelectionListener(this);
mSoftwareUpdateItemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
mSoftwareUpdateItemList.setListUI(new MyListUI());
mSoftwareUpdateItemList.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
mSoftwareUpdateItemList.addCenterRendererComponent(PluginsSoftwareUpdateItem.class,new SelectableItemRendererCenterComponentIf() {
private final ImageIcon NEW_VERSION_ICON = IconLoader.getInstance().getIconFromTheme("status", "software-update-available", 16);
public JPanel createCenterPanel(JList list, Object value, int index, boolean isSelected, boolean isEnabled, JScrollPane parentScrollPane, int leftColumnWidth) {
FormLayout lay = new FormLayout("5dlu,default,5dlu,default:grow","2dlu,default,2dlu,fill:pref:grow,2dlu");
EnhancedPanelBuilder pb = new EnhancedPanelBuilder(lay);
pb.getPanel().setOpaque(false);
SoftwareUpdateItem item = (SoftwareUpdateItem)value;
JLabel label = pb.addLabel(HTMLTextHelper.convertHtmlToText(item.getName()) + " " + item.getVersion(), cc.xy(2,2));
label.setFont(label.getFont().deriveFont(Font.BOLD, label.getFont().getSize2D()+2));
int width = parentScrollPane.getSize().width - parentScrollPane.getVerticalScrollBar().getWidth() - leftColumnWidth - Sizes.dialogUnitXAsPixel(5,pb.getPanel()) * 4 - parentScrollPane.getInsets().left - parentScrollPane.getInsets().right;
if (width <= 0) {
width = Settings.propColumnWidth.getInt();
}
TextAreaIcon icon = new TextAreaIcon(HTMLTextHelper.convertHtmlToText(item.getDescription()), new JLabel().getFont(), width, 2);
JLabel iconLabel = new JLabel("");
iconLabel.setIcon(icon);
pb.add(iconLabel, cc.xyw(2,4,3));
JLabel label3 = new JLabel();
if (item.isAlreadyInstalled()) {
Version installedVersion = item.getInstalledVersion();
if ((installedVersion != null) && (installedVersion.compareTo(item.getVersion()) < 0)) {
label.setIcon(NEW_VERSION_ICON);
label3.setText("(" + mLocalizer.msg("installed","Installed version: ") + installedVersion.toString()+")");
label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize2D()+2));
pb.add(label3, cc.xy(4,2));
}
}
if (isSelected && isEnabled) {
label.setForeground(list.getSelectionForeground());
String author = item.getProperty("author");
String website = item.getWebsite();
FormLayout authorAndWebsiteLayout = new FormLayout("default,5dlu,default","default");
JPanel authorAndWebsite = new JPanel(authorAndWebsiteLayout);
authorAndWebsite.setOpaque(false);
if (author != null) {
lay.appendRow(RowSpec.decode("2dlu"));
lay.appendRow(RowSpec.decode("default"));
lay.appendRow(RowSpec.decode("2dlu"));
pb.add(authorAndWebsite, cc.xyw(2,7,3));
JLabel authorLabel = new JLabel(mLocalizer.msg("author", "Author"));
authorLabel.setFont(authorLabel.getFont().deriveFont(Font.BOLD));
authorLabel.setForeground(list.getSelectionForeground());
authorLabel.setHorizontalAlignment(SwingConstants.RIGHT);
JLabel authorName = new JLabel(HTMLTextHelper.convertHtmlToText(author));
authorName.setForeground(list.getSelectionForeground());
authorAndWebsite.add(authorLabel, cc.xy(1,1));
authorAndWebsite.add(authorName, cc.xy(3,1));
}
if (website != null) {
if(author == null) {
lay.appendRow(RowSpec.decode("2dlu"));
lay.appendRow(RowSpec.decode("default"));
lay.appendRow(RowSpec.decode("2dlu"));
pb.add(authorAndWebsite, cc.xyw(2,7,3));
}
else {
authorAndWebsiteLayout.appendRow(RowSpec.decode("1dlu"));
authorAndWebsiteLayout.appendRow(RowSpec.decode("default"));
}
JLabel webLabel = new JLabel(mLocalizer.msg("website", "Website"));
webLabel.setFont(webLabel.getFont().deriveFont(Font.BOLD));
webLabel.setForeground(list.getSelectionForeground());
webLabel.setHorizontalAlignment(SwingConstants.RIGHT);
LinkButton webLink = new LinkButton(HTMLTextHelper.convertHtmlToText(website));
webLink.setForeground(list.getSelectionForeground());
authorAndWebsite.add(webLabel, cc.xy(1,author == null ? 1 : 3));
authorAndWebsite.add(webLink, cc.xy(3,author == null ? 1 : 3));
}
icon.setMaximumLineCount(-1);
iconLabel.setForeground(list.getSelectionForeground());
label3.setForeground(list.getSelectionForeground());
} else {
if(!item.isStable()) {
label.setForeground(new Color(200, 0, 0));
}
else {
label.setForeground(list.getForeground());
}
icon.setMaximumLineCount(1);
iconLabel.setForeground(list.getSelectionForeground());
iconLabel.setForeground(list.getForeground());
label3.setForeground(Color.gray);
}
return pb.getPanel();
}
public void calculateSize(JList list, int index, JPanel contPane) {
if(list.getUI() instanceof MyListUI) {
((MyListUI)list.getUI()).setCellHeight(index, contPane.getPreferredSize().height);
}
}
});
mSoftwareUpdateItemList.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if(SwingUtilities.isRightMouseButton(e) && e.isPopupTrigger()) {
showPopupMenu(e);
}
}
@Override
public void mouseReleased(MouseEvent e) {
if(SwingUtilities.isRightMouseButton(e) && e.isPopupTrigger()) {
showPopupMenu(e);
}
}
});
if(!onlyUpdate) {
layout.appendRow(RowSpec.decode("5dlu"));
layout.appendRow(RowSpec.decode("default"));
JLabel filterLabel = new JLabel(mLocalizer.msg("filterLabel","Show only Plugins with the following category:"));
northPn.add(filterLabel, cc.xy(1,3));
ArrayList<FilterItem> filterList = new ArrayList<FilterItem>(0);