cloud search work

This commit is contained in:
bancika
2016-10-24 11:55:40 +02:00
parent a197bbc21a
commit a9df82cbab
7 changed files with 395 additions and 279 deletions
@@ -209,6 +209,7 @@ public class CloudPresenter {
public List<ProjectEntity> search(String criteria, String category, String sortOrder, int pageNumber, int itemsPerPage) public List<ProjectEntity> search(String criteria, String category, String sortOrder, int pageNumber, int itemsPerPage)
throws CloudException { throws CloudException {
LOG.info(String.format("search(%1$s,%2$s,%3$s,%4$d,%5$d)", criteria, category, sortOrder, pageNumber, itemsPerPage));
try { try {
Object res = service.search(criteria, category, "json", pageNumber, itemsPerPage, sortOrder); Object res = service.search(criteria, category, "json", pageNumber, itemsPerPage, sortOrder);
if (res == null) if (res == null)
@@ -32,7 +32,8 @@ public enum IconLoader {
"briefcase_into.png"), RotateCW("rotate_cw.png"), RotateCCW("rotate_ccw.png"), ElementInto("element_into.png"), Arrow( "briefcase_into.png"), RotateCW("rotate_cw.png"), RotateCCW("rotate_ccw.png"), ElementInto("element_into.png"), Arrow(
"arrow.png"), Cloud("cloud.png"), CloudUp("cloud_up.png"), CloudGear("cloud_gear.png"), IdCardEdit( "arrow.png"), Cloud("cloud.png"), CloudUp("cloud_up.png"), CloudGear("cloud_gear.png"), IdCardEdit(
"id_card_edit.png"), KeyEdit("key_edit.png"), Find("find.png"), Dashboard("dashboard.png"), DataFind( "id_card_edit.png"), KeyEdit("key_edit.png"), Find("find.png"), Dashboard("dashboard.png"), DataFind(
"data_find.png"), CloudDownload("cloud-download.png"); "data_find.png"), CloudDownload("cloud-download.png"), NavLeftBlue("nav_left_blue.png"), NavRightBlue(
"nav_right_blue.png");
protected String name; protected String name;
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

@@ -323,14 +323,16 @@ public class MainFrame extends JFrame implements ISwingUI {
try { try {
T result = get(); T result = get();
task.complete(result); task.complete(result);
getGlassPane().setVisible(false);
} catch (ExecutionException e) { } catch (ExecutionException e) {
getGlassPane().setVisible(false);
LOG.error("Background task execution failed", e); LOG.error("Background task execution failed", e);
task.failed(e); task.failed(e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
getGlassPane().setVisible(false);
LOG.error("Background task execution interrupted", e); LOG.error("Background task execution interrupted", e);
task.failed(e); task.failed(e);
} }
getGlassPane().setVisible(false);
} }
}; };
worker.execute(); worker.execute();
@@ -32,6 +32,7 @@ import javax.swing.JScrollPane;
import javax.swing.JSeparator; import javax.swing.JSeparator;
import javax.swing.JTabbedPane; import javax.swing.JTabbedPane;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
@@ -72,6 +73,10 @@ public class CloudBrowserFrame extends JFrame {
private IPlugInPort plugInPort; private IPlugInPort plugInPort;
private CloudPresenter cloudPresenter; private CloudPresenter cloudPresenter;
// search criteria
private String searchFor;
private String category;
private String sort;
private int pageNumber; private int pageNumber;
private int itemsPerPage = 10; private int itemsPerPage = 10;
@@ -177,7 +182,7 @@ public class CloudBrowserFrame extends JFrame {
searchPanel.add(new JLabel("Filter By Category:"), gbc); searchPanel.add(new JLabel("Filter By Category:"), gbc);
gbc.gridx = 3; gbc.gridx = 3;
gbc.weightx = 1; gbc.weightx = 0.3;
searchPanel.add(getCategoryBox(), gbc); searchPanel.add(getCategoryBox(), gbc);
gbc.gridx = 4; gbc.gridx = 4;
@@ -195,7 +200,7 @@ public class CloudBrowserFrame extends JFrame {
private JTextField getSearchField() { private JTextField getSearchField() {
if (searchField == null) { if (searchField == null) {
searchField = new JTextField(); searchField = new JTextField(60);
} }
return searchField; return searchField;
} }
@@ -249,73 +254,71 @@ public class CloudBrowserFrame extends JFrame {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
CloudBrowserFrame.this.pageNumber = 1; CloudBrowserFrame.this.pageNumber = 1;
CloudBrowserFrame.this.searchFor = getSearchField().getText();
CloudBrowserFrame.this.category =
getCategoryBox().getSelectedItem() == null ? "" : getCategoryBox().getSelectedItem().toString();
CloudBrowserFrame.this.sort =
getSortBox().getSelectedItem() == null ? "" : getSortBox().getSelectedItem().toString();
executeBackgroundTask(new ITask<List<ProjectEntity>>() { search();
@Override
public List<ProjectEntity> doInBackground() throws Exception {
return cloudPresenter.search(getSearchField().getText(), getCategoryBox().getSelectedItem() == null ? ""
: getCategoryBox().getSelectedItem().toString(), getSortBox().getSelectedItem() == null ? ""
: getSortBox().getSelectedItem().toString(), CloudBrowserFrame.this.pageNumber,
CloudBrowserFrame.this.itemsPerPage);
}
@Override
public void failed(Exception e) {
showMessage("Search failed. Error: " + e.getMessage(), "Search Failed", IView.ERROR_MESSAGE);
}
@Override
public void complete(List<ProjectEntity> result) {
getResultsPanel().removeAll();
int count = 0;
for (Iterator<ProjectEntity> i = result.iterator(); i.hasNext();) {
ProjectEntity project = i.next();
addProjectToDisplay(project, count++, i.hasNext());
}
}
});
} }
}); });
} }
return goButton; return goButton;
} }
public <T extends Object> void executeBackgroundTask(final ITask<T> task) { private void search() {
getGlassPane().setVisible(true); executeBackgroundTask(new ITask<List<ProjectEntity>>() {
SwingWorker<T, Void> worker = new SwingWorker<T, Void>() {
@Override @Override
protected T doInBackground() throws Exception { public List<ProjectEntity> doInBackground() throws Exception {
return task.doInBackground(); return cloudPresenter.search(searchFor, category, sort, pageNumber, itemsPerPage);
} }
@Override @Override
protected void done() { public void failed(Exception e) {
try { showMessage("Search failed! Detailed message is in the logs. Please report to the author.", "Search Failed",
T result = get(); IView.ERROR_MESSAGE);
task.complete(result); }
} catch (ExecutionException e) {
LOG.error("Background task execution failed", e); @Override
task.failed(e); public void complete(List<ProjectEntity> result) {
} catch (InterruptedException e) { getResultsPanel().removeAll();
LOG.error("Background task execution interrupted", e); int count = 0;
task.failed(e); for (Iterator<ProjectEntity> i = result.iterator(); i.hasNext();) {
ProjectEntity project = i.next();
addProjectToDisplay(project, count++);
} }
getGlassPane().setVisible(false); if (count == 0) {
showNoMatches();
count++;
}
addNavigationPanel(count);
} }
}; });
worker.execute();
} }
private void addProjectToDisplay(final ProjectEntity project, int location, boolean hasNext) { private void showNoMatches() {
JLabel label = new JLabel("<html><font size='5' color='red'>No projects match the search criteria.</font></html>");
label.setHorizontalAlignment(SwingConstants.CENTER);
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(2, 2, 2, 2);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1;
gbc.weighty = Integer.MAX_VALUE;
getResultsPanel().add(label, gbc);
}
private void addProjectToDisplay(final ProjectEntity project, int location) {
JLabel thumbnailLabel = new JLabel(downloadImage(project.getThumbnailUrl())); JLabel thumbnailLabel = new JLabel(downloadImage(project.getThumbnailUrl()));
JLabel nameLabel = new JLabel("<html><b>" + project.getName() + "</b></html>"); JLabel nameLabel = new JLabel("<html><b>" + project.getName() + "</b></html>");
nameLabel.setFont(nameLabel.getFont().deriveFont(12f)); nameLabel.setFont(nameLabel.getFont().deriveFont(12f));
JLabel descriptionLabel = new JLabel("<html>" + project.getDescription() + "</html>"); JLabel descriptionLabel = new JLabel("<html>" + project.getDescription() + "</html>");
JLabel categoryLabel = new JLabel("Category: " + project.getCategory()); JLabel categoryLabel = new JLabel("<html>Category: <b>" + project.getCategory() + "</b></html>");
JLabel authorLabel = new JLabel("<html>by: <b>" + project.getOwner() + "</b></html>"); JLabel authorLabel = new JLabel("<html>Author: <b>" + project.getOwner() + "</b></html>");
JLabel updatedLabel = new JLabel("Last updated: " + project.getUpdated()); JLabel updatedLabel = new JLabel("<html>Last updated: <b>" + project.getUpdated() + "</b></html>");
JButton downloadButton = new JButton(IconLoader.CloudDownload.getIcon()); JButton downloadButton = new JButton(IconLoader.CloudDownload.getIcon());
downloadButton.setBorderPainted(false); downloadButton.setBorderPainted(false);
@@ -365,7 +368,7 @@ public class CloudBrowserFrame extends JFrame {
@Override @Override
public void failed(Exception e) { public void failed(Exception e) {
CloudBrowserFrame.this.showMessage("Could not open file. " + e.getMessage(), "Error", CloudBrowserFrame.this.showMessage("Could not open file. Detailed message is in the logs", "Error",
ISwingUI.ERROR_MESSAGE); ISwingUI.ERROR_MESSAGE);
} }
}); });
@@ -374,7 +377,7 @@ public class CloudBrowserFrame extends JFrame {
@Override @Override
public void failed(Exception e) { public void failed(Exception e) {
CloudBrowserFrame.this.showMessage("Could not save to file. " + e.getMessage(), "Error", CloudBrowserFrame.this.showMessage("Could not save to file. Detailed message is in the logs", "Error",
ISwingUI.ERROR_MESSAGE); ISwingUI.ERROR_MESSAGE);
} }
}); });
@@ -386,9 +389,9 @@ public class CloudBrowserFrame extends JFrame {
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.insets = new Insets(2, 2, 2, 2); gbc.insets = new Insets(2, 2, 2, 2);
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = location * 5; gbc.gridy = location * 6;
gbc.fill = GridBagConstraints.NONE; gbc.fill = GridBagConstraints.NONE;
gbc.gridheight = 4; gbc.gridheight = 5;
gbc.weightx = 0; gbc.weightx = 0;
getResultsPanel().add(thumbnailLabel, gbc); getResultsPanel().add(thumbnailLabel, gbc);
@@ -397,11 +400,11 @@ public class CloudBrowserFrame extends JFrame {
gbc.weightx = 1; gbc.weightx = 1;
gbc.insets = new Insets(2, 6, 2, 2); gbc.insets = new Insets(2, 6, 2, 2);
getResultsPanel().add(nameLabel, gbc); getResultsPanel().add(nameLabel, gbc);
//
gbc.gridx = 2; // gbc.gridx = 2;
gbc.anchor = GridBagConstraints.NORTHEAST; // gbc.anchor = GridBagConstraints.NORTHEAST;
gbc.insets = new Insets(2, 2, 2, 8); // gbc.insets = new Insets(2, 2, 2, 8);
getResultsPanel().add(authorLabel, gbc); // getResultsPanel().add(authorLabel, gbc);
gbc.gridy++; gbc.gridy++;
gbc.gridx = 1; gbc.gridx = 1;
@@ -416,7 +419,7 @@ public class CloudBrowserFrame extends JFrame {
getResultsPanel().add(categoryLabel, gbc); getResultsPanel().add(categoryLabel, gbc);
gbc.gridx = 2; gbc.gridx = 2;
gbc.gridheight = 2; gbc.gridheight = 3;
gbc.insets = new Insets(2, 2, 2, 2); gbc.insets = new Insets(2, 2, 2, 2);
gbc.anchor = GridBagConstraints.SOUTHEAST; gbc.anchor = GridBagConstraints.SOUTHEAST;
getResultsPanel().add(downloadButton, gbc); getResultsPanel().add(downloadButton, gbc);
@@ -426,17 +429,106 @@ public class CloudBrowserFrame extends JFrame {
gbc.gridheight = 1; gbc.gridheight = 1;
gbc.insets = new Insets(2, 6, 2, 2); gbc.insets = new Insets(2, 6, 2, 2);
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.anchor = GridBagConstraints.NORTHWEST;
getResultsPanel().add(authorLabel, gbc);
gbc.gridy++;
getResultsPanel().add(updatedLabel, gbc); getResultsPanel().add(updatedLabel, gbc);
if (hasNext) { gbc.gridx = 0;
gbc.gridx = 0; gbc.gridy++;
gbc.gridy++; gbc.gridwidth = 3;
gbc.gridwidth = 3; gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1;
gbc.weightx = 1; gbc.insets = new Insets(2, 2, 2, 2);
gbc.insets = new Insets(2, 2, 2, 2); getResultsPanel().add(new JSeparator(), gbc);
getResultsPanel().add(new JSeparator(), gbc); }
}
private void addNavigationPanel(int location) {
JPanel navigationPanel = new JPanel(new GridBagLayout());
navigationPanel.setBackground(Color.white);
JButton prevPageButton = new JButton(IconLoader.NavLeftBlue.getIcon());
prevPageButton.setBorderPainted(false);
prevPageButton.setContentAreaFilled(false);
prevPageButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
prevPageButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (CloudBrowserFrame.this.pageNumber > 1) {
CloudBrowserFrame.this.pageNumber--;
CloudBrowserFrame.this.search();
}
}
});
JButton nextPageButton = new JButton(IconLoader.NavRightBlue.getIcon());
nextPageButton.setBorderPainted(false);
nextPageButton.setContentAreaFilled(false);
nextPageButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
nextPageButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CloudBrowserFrame.this.pageNumber++;
CloudBrowserFrame.this.search();
}
});
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.SOUTHWEST;
gbc.insets = new Insets(2, 2, 2, 2);
gbc.gridx = 0;
gbc.weightx = 0;
gbc.fill = GridBagConstraints.NONE;
navigationPanel.add(prevPageButton, gbc);
gbc.gridx++;
gbc.weightx = 1;
navigationPanel.add(new JLabel(), gbc);
gbc.gridx++;
gbc.weightx = 0;
navigationPanel.add(nextPageButton, gbc);
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.insets = new Insets(2, 2, 2, 2);
gbc.gridx = 0;
gbc.gridy = location * 6;
gbc.fill = GridBagConstraints.BOTH;
gbc.weighty = 100;
gbc.gridwidth = 3;
getResultsPanel().add(navigationPanel, gbc);
}
public <T extends Object> void executeBackgroundTask(final ITask<T> task) {
getGlassPane().setVisible(true);
SwingWorker<T, Void> worker = new SwingWorker<T, Void>() {
@Override
protected T doInBackground() throws Exception {
return task.doInBackground();
}
@Override
protected void done() {
try {
T result = get();
task.complete(result);
getGlassPane().setVisible(false);
} catch (ExecutionException e) {
LOG.error("Background task execution failed", e);
getGlassPane().setVisible(false);
task.failed(e);
} catch (InterruptedException e) {
getGlassPane().setVisible(false);
LOG.error("Background task execution interrupted", e);
task.failed(e);
}
}
};
worker.execute();
} }
public void showMessage(String message, String title, int messageType) { public void showMessage(String message, String title, int messageType) {
@@ -32,254 +32,274 @@ import org.diylc.swingframework.ButtonDialog;
public class UploadDialog extends ButtonDialog { public class UploadDialog extends ButtonDialog {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final String BULLET = "&nbsp;&nbsp;&nbsp;&#8226;&nbsp;"; private static final String BULLET = "&nbsp;&nbsp;&nbsp;&#8226;&nbsp;";
private static final String TERMS_HTML = "<html>" + BULLET private static final String TERMS_HTML = "<html>"
+ "All content uploaded to DIY Cloud is shared under Creative Commons 3.0 Licence.<br>" + BULLET + BULLET
+ "Only finished and resonably verified projects may be uploaded to the DIY Cloud.<br>" + BULLET + "All content uploaded to DIY Cloud is shared under Creative Commons 3.0 Licence.<br>"
+ "Please provide a meaningful project description to make it possible for others to find the project.<br>" + BULLET
+ BULLET + "If you are building on top of someone else's work, please leave credits in the description.<br>" + "Only finished and resonably verified projects may be uploaded to the DIY Cloud.<br>"
+ BULLET + BULLET
+ "Uploaded content may be reviewed, edited and removed by the administrators if it is not up to standards.<br>" + "Please provide a meaningful project description to make it possible for others to find the project.<br>"
+ "</html>"; + BULLET
+ "If you are building on top of someone else's work, please leave credits in the description.<br>"
+ BULLET
+ "Uploaded content may be reviewed, edited and removed by the administrators if it is not up to standards.<br>"
+ "</html>";
private JPanel mainPanel; private JPanel mainPanel;
private JLabel termsLabel; private JLabel termsLabel;
private JCheckBox agreeBox; private JCheckBox agreeBox;
private JPanel thumbnailPanel; private JPanel thumbnailPanel;
private JTextField nameField; private JTextField nameField;
private JComboBox categoryBox; private JComboBox categoryBox;
private JTextArea descriptionArea; private JTextArea descriptionArea;
private JTextField keywordsField; private JTextField keywordsField;
private IPlugInPort plugInPort; private IPlugInPort plugInPort;
private CloudPresenter cloudPresenter; private CloudPresenter cloudPresenter;
public UploadDialog(JFrame owner, IPlugInPort plugInPort, CloudPresenter cloudPresenter) { public UploadDialog(JFrame owner, IPlugInPort plugInPort,
super(owner, "Upload A Project", new String[] {OK, CANCEL}); CloudPresenter cloudPresenter) {
this.plugInPort = plugInPort; super(owner, "Upload A Project", new String[] { OK, CANCEL });
this.cloudPresenter = cloudPresenter; this.plugInPort = plugInPort;
layoutGui(); this.cloudPresenter = cloudPresenter;
getButton(OK).setEnabled(false); layoutGui();
} getButton(OK).setEnabled(false);
}
@Override @Override
protected JComponent getMainComponent() { protected JComponent getMainComponent() {
if (mainPanel == null) { if (mainPanel == null) {
mainPanel = new JPanel(new GridBagLayout()); mainPanel = new JPanel(new GridBagLayout());
mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.insets = new Insets(2, 2, 2, 2); gbc.insets = new Insets(2, 2, 2, 2);
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = 0; gbc.gridy = 0;
gbc.gridheight = 4; gbc.gridheight = 4;
mainPanel.add(getThumbnailPanel(), gbc); mainPanel.add(getThumbnailPanel(), gbc);
gbc.gridheight = 1; gbc.gridheight = 1;
gbc.gridx = 1; gbc.gridx = 1;
gbc.weightx = 0; gbc.weightx = 0;
gbc.insets = new Insets(4, 2, 2, 2); gbc.insets = new Insets(4, 2, 2, 2);
gbc.fill = GridBagConstraints.HORIZONTAL; gbc.fill = GridBagConstraints.HORIZONTAL;
mainPanel.add(new JLabel("Project Name: "), gbc); mainPanel.add(new JLabel("Project Name: "), gbc);
gbc.gridy = 1; gbc.gridy = 1;
mainPanel.add(new JLabel("Category:"), gbc); mainPanel.add(new JLabel("Category:"), gbc);
gbc.gridy = 2; gbc.gridy = 2;
mainPanel.add(new JLabel("Description: "), gbc); mainPanel.add(new JLabel("Description: "), gbc);
gbc.gridy = 3; gbc.gridy = 3;
mainPanel.add(new JLabel("Keywords: "), gbc); mainPanel.add(new JLabel("Keywords: "), gbc);
gbc.gridx = 2; gbc.gridx = 2;
gbc.gridy = 0; gbc.gridy = 0;
gbc.weightx = 1; gbc.weightx = 1;
gbc.insets = new Insets(2, 2, 2, 2); gbc.insets = new Insets(2, 2, 2, 2);
mainPanel.add(getNameField(), gbc); mainPanel.add(getNameField(), gbc);
gbc.gridy = 1; gbc.gridy = 1;
mainPanel.add(getCategoryBox(), gbc); mainPanel.add(getCategoryBox(), gbc);
gbc.gridy = 2; gbc.gridy = 2;
gbc.weightx = 1; gbc.weightx = 1;
gbc.weighty = 1; gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
mainPanel.add(getDescriptionArea(), gbc); mainPanel.add(getDescriptionArea(), gbc);
gbc.gridy = 3; gbc.gridy = 3;
gbc.weighty = 0; gbc.weighty = 0;
gbc.weightx = 1; gbc.weightx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL; gbc.fill = GridBagConstraints.HORIZONTAL;
mainPanel.add(getKeywordsField(), gbc); mainPanel.add(getKeywordsField(), gbc);
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = 4; gbc.gridy = 4;
gbc.weightx = 1; gbc.weightx = 1;
gbc.weighty = 1; gbc.weighty = 1;
gbc.gridwidth = 3; gbc.gridwidth = 3;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
mainPanel.add(getTermsLabel(), gbc); mainPanel.add(getTermsLabel(), gbc);
gbc.gridy = 5; gbc.gridy = 5;
gbc.anchor = GridBagConstraints.CENTER; gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.NONE; gbc.fill = GridBagConstraints.NONE;
gbc.weightx = 0; gbc.weightx = 0;
gbc.weighty = 0; gbc.weighty = 0;
mainPanel.add(getAgreeBox(), gbc); mainPanel.add(getAgreeBox(), gbc);
} }
return mainPanel; return mainPanel;
} }
private JCheckBox getAgreeBox() { private JCheckBox getAgreeBox() {
if (agreeBox == null) { if (agreeBox == null) {
agreeBox = new JCheckBox("I agree to these terms"); agreeBox = new JCheckBox("I agree to these terms");
agreeBox.addChangeListener(new ChangeListener() { agreeBox.addChangeListener(new ChangeListener() {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
getButton(OK).setEnabled(getAgreeBox().isSelected()); getButton(OK).setEnabled(getAgreeBox().isSelected());
} }
}); });
} }
return agreeBox; return agreeBox;
} }
private JLabel getTermsLabel() { private JLabel getTermsLabel() {
if (termsLabel == null) { if (termsLabel == null) {
termsLabel = new JLabel(); termsLabel = new JLabel();
termsLabel.setOpaque(true); termsLabel.setOpaque(true);
termsLabel.setBackground(UIManager.getColor("ToolTip.background")); termsLabel.setBackground(UIManager.getColor("ToolTip.background"));
termsLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), termsLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(2, 2, 2, 2))); BorderFactory.createEtchedBorder(),
termsLabel.setText(TERMS_HTML); BorderFactory.createEmptyBorder(2, 2, 2, 2)));
} termsLabel.setText(TERMS_HTML);
return termsLabel; }
} return termsLabel;
}
private JPanel getThumbnailPanel() { private JPanel getThumbnailPanel() {
if (thumbnailPanel == null) { if (thumbnailPanel == null) {
thumbnailPanel = new JPanel(new GridBagLayout()); thumbnailPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.LINE_START; gbc.anchor = GridBagConstraints.LINE_START;
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = 0; gbc.gridy = 0;
gbc.weightx = 1; gbc.weightx = 1;
gbc.weighty = 1; gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
thumbnailPanel.add(new JComponent() { thumbnailPanel.add(new JComponent() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
public void paint(Graphics g) { public void paint(Graphics g) {
super.paint(g); super.paint(g);
paintThumbnail(g, getBounds()); paintThumbnail(g, getBounds());
} }
}, gbc); }, gbc);
Dimension d = UploadDialog.this.plugInPort.getCanvasDimensions(false); Dimension d = UploadDialog.this.plugInPort
if (d.height > d.width) .getCanvasDimensions(false);
thumbnailPanel.setPreferredSize(new Dimension(192 * d.width / d.height, 192)); if (d.height > d.width)
else thumbnailPanel.setPreferredSize(new Dimension(192 * d.width
thumbnailPanel.setPreferredSize(new Dimension(192, 192 * d.height / d.width)); / d.height, 192));
thumbnailPanel.setBorder(BorderFactory.createEtchedBorder()); else
} thumbnailPanel.setPreferredSize(new Dimension(192, 192
return thumbnailPanel; * d.height / d.width));
} thumbnailPanel.setBorder(BorderFactory.createEtchedBorder());
}
return thumbnailPanel;
}
private JTextField getNameField() { private JTextField getNameField() {
if (nameField == null) { if (nameField == null) {
nameField = new JTextField(); nameField = new JTextField();
// set default from the project // set default from the project
for (int i = 0; i < plugInPort.getProjectProperties().size(); i++) for (int i = 0; i < plugInPort.getProjectProperties().size(); i++)
if (plugInPort.getProjectProperties().get(i).getName().equals("Title")) if (plugInPort.getProjectProperties().get(i).getName()
nameField.setText(plugInPort.getProjectProperties().get(i).getValue().toString()); .equals("Title"))
} nameField.setText(plugInPort.getProjectProperties().get(i)
return nameField; .getValue().toString());
} }
return nameField;
}
private JComboBox getCategoryBox() { private JComboBox getCategoryBox() {
if (categoryBox == null) { if (categoryBox == null) {
try { try {
categoryBox = new JComboBox(cloudPresenter.getCategories()); categoryBox = new JComboBox(cloudPresenter.getCategories());
} catch (CloudException e) { } catch (CloudException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
return categoryBox; return categoryBox;
} }
private JTextArea getDescriptionArea() { private JTextArea getDescriptionArea() {
if (descriptionArea == null) { if (descriptionArea == null) {
descriptionArea = new JTextArea(); descriptionArea = new JTextArea();
// set default from the project // set default from the project
for (int i = 0; i < plugInPort.getProjectProperties().size(); i++) for (int i = 0; i < plugInPort.getProjectProperties().size(); i++)
if (plugInPort.getProjectProperties().get(i).getName().equals("Description")) if (plugInPort.getProjectProperties().get(i).getName()
descriptionArea.setText(plugInPort.getProjectProperties().get(i).getValue().toString()); .equals("Description"))
descriptionArea.setBorder(getNameField().getBorder()); try {
descriptionArea.setFont(getNameField().getFont()); descriptionArea.setText(plugInPort
} .getProjectProperties().get(i).getValue()
return descriptionArea; .toString());
} } catch (Exception e) {
}
descriptionArea.setBorder(getNameField().getBorder());
descriptionArea.setFont(getNameField().getFont());
}
return descriptionArea;
}
private JTextField getKeywordsField() { private JTextField getKeywordsField() {
if (keywordsField == null) { if (keywordsField == null) {
keywordsField = new JTextField(); keywordsField = new JTextField();
} }
return keywordsField; return keywordsField;
} }
public String getName() { public String getName() {
return getNameField().getText(); return getNameField().getText();
} }
public String getDescription() { public String getDescription() {
return getDescriptionArea().getText(); return getDescriptionArea().getText().replace("\n", "<br>");
} }
public String getCategory() { public String getCategory() {
return getCategoryBox().getSelectedItem().toString(); return getCategoryBox().getSelectedItem().toString();
} }
public BufferedImage getThumbnail() { public BufferedImage getThumbnail() {
BufferedImage thumbnailImage = BufferedImage thumbnailImage = new BufferedImage(getThumbnailPanel()
new BufferedImage(getThumbnailPanel().getWidth(), getThumbnailPanel().getHeight(), BufferedImage.TYPE_INT_RGB); .getWidth(), getThumbnailPanel().getHeight(),
Graphics2D cg = thumbnailImage.createGraphics(); BufferedImage.TYPE_INT_RGB);
Graphics2D cg = thumbnailImage.createGraphics();
paintThumbnail(cg, new Rectangle(thumbnailImage.getWidth(), thumbnailImage.getHeight())); paintThumbnail(cg, new Rectangle(thumbnailImage.getWidth(),
return thumbnailImage; thumbnailImage.getHeight()));
} return thumbnailImage;
}
private void paintThumbnail(Graphics g, Rectangle rect) { private void paintThumbnail(Graphics g, Rectangle rect) {
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
Dimension d = UploadDialog.this.plugInPort.getCanvasDimensions(false); Dimension d = UploadDialog.this.plugInPort.getCanvasDimensions(false);
g2d.setColor(Color.white); g2d.setColor(Color.white);
g2d.fill(rect); g2d.fill(rect);
double projectRatio = d.getWidth() / d.getHeight(); double projectRatio = d.getWidth() / d.getHeight();
double actualRatio = rect.getWidth() / rect.getHeight(); double actualRatio = rect.getWidth() / rect.getHeight();
double zoomRatio; double zoomRatio;
if (projectRatio > actualRatio) { if (projectRatio > actualRatio) {
zoomRatio = rect.getWidth() / d.getWidth(); zoomRatio = rect.getWidth() / d.getWidth();
} else { } else {
zoomRatio = rect.getHeight() / d.getHeight(); zoomRatio = rect.getHeight() / d.getHeight();
} }
g2d.scale(zoomRatio, zoomRatio); g2d.scale(zoomRatio, zoomRatio);
UploadDialog.this.plugInPort.draw(g2d, EnumSet.of(DrawOption.ANTIALIASING), null); UploadDialog.this.plugInPort.draw(g2d,
} EnumSet.of(DrawOption.ANTIALIASING), null);
}
public String getKeywords() { public String getKeywords() {
return getKeywordsField().getText(); return getKeywordsField().getText();
} }
} }