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