package net.sf.jpluck.apps.jpluckx.ui;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import net.sf.jpluck.ClientConfiguration;
import net.sf.jpluck.swing.LinkLabel;
import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.FormLayout;
class ShowcasePanel extends JPanel {
private PreviewLabel previewLabel = new PreviewLabel(PreviewLabel.WEB_ROOT);
private JCheckBox downloadPreviewCheck = new JCheckBox(new DisablePreviewAction());
ShowcasePanel(Action[] actions) {
initComponents(actions);
}
private void initComponents(Action[] actions) {
downloadPreviewCheck.setFocusable(false);
downloadPreviewCheck.setSelected(ClientConfiguration.getDefault().isShowcasePreview());
String rows = "162px, 2dlu, pref, 4dlu";
for (int i = 0; i < actions.length; i++) {
rows += ", pref";
if (i < (actions.length - 1)) {
rows += ", 2dlu";
}
}
FormLayout formLayout = new FormLayout("pref", rows);
PanelBuilder panelBuilder = new PanelBuilder(this, formLayout);
panelBuilder.setDefaultDialogBorder();
panelBuilder.add(previewLabel, "1,1");
panelBuilder.add(downloadPreviewCheck, "1,3");
for (int i = 0; i < actions.length; i++) {
panelBuilder.add(new LinkLabel(actions[i]), "1," + (5+(i*2)));
}
}
void showPreview(String name) {
previewLabel.showPreview(name);
}
private class DisablePreviewAction extends AbstractAction {
DisablePreviewAction() {
super("Download preview");
}
public void actionPerformed(ActionEvent ev) {
ClientConfiguration.getDefault().setShowcasePreview(downloadPreviewCheck.isSelected());
if (downloadPreviewCheck.isSelected()) {
showPreview(null);
}
}
}
}