if(mIsVersionChange) {
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
JPanel contentPane = (JPanel) getContentPane();
contentPane.setLayout(new BorderLayout(0, 10));
contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 11, 11));
mCloseBtn = new JButton(Localizer.getLocalization(Localizer.I18N_CLOSE));
mCloseBtn.addActionListener(this);
mCloseBtn.setEnabled(!mIsVersionChange);
mDownloadBtn = new JButton(mLocalizer.msg("download", "Download selected items"));
mDownloadBtn.addActionListener(this);
mHelpBtn = new JButton(mLocalizer.msg("openWebsite","Open website"), TVBrowserIcons.webBrowser(TVBrowserIcons.SIZE_SMALL));
mHelpBtn.addActionListener(this);
mHelpBtn.setEnabled(false);
ButtonBarBuilder2 builder = new ButtonBarBuilder2();
if(onlyUpdate && !mIsVersionChange) {
mAutoUpdates = new JCheckBox(mLocalizer.msg("autoUpdates","Find plugin updates automatically"), Settings.propAutoUpdatePlugins.getBoolean());
mAutoUpdates.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
Settings.propAutoUpdatePlugins.setBoolean(e.getStateChange() == ItemEvent.SELECTED);
}
});
builder.addFixed(mAutoUpdates);
builder.addRelatedGap();
}
builder.addFixed(mHelpBtn);
builder.addGlue();
builder.addFixed(mDownloadBtn);
builder.addRelatedGap();
builder.addFixed(mCloseBtn);
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());