Author: laylaoesper
Date: 2010-09-21 17:36:08 -0700 (Tue, 21 Sep 2010)
New Revision: 21970
Added:
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/SaveCloudAction.java
Modified:
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/CreateCloudAction.java
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/SemanticSummaryInputPanel.java
Log:
Start of changes for saving a file of the image of the cloud.
Modified:
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/CreateCloudAction.java
===================================================================
---
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/CreateCloudAction.java
2010-09-22 00:05:14 UTC (rev 21969)
+++
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/CreateCloudAction.java
2010-09-22 00:36:08 UTC (rev 21970)
@@ -159,6 +159,7 @@
//inputPanel.setNetworkList(params);
inputPanel.addNewCloud(cloudParams);
inputPanel.getCreateNetworkButton().setEnabled(true);
+ inputPanel.getSaveCloudButton().setEnabled(true);
//Update the list of filter words and checkbox
inputPanel.refreshNetworkSettings();
Added:
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/SaveCloudAction.java
===================================================================
---
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/SaveCloudAction.java
(rev 0)
+++
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/SaveCloudAction.java
2010-09-22 00:36:08 UTC (rev 21970)
@@ -0,0 +1,127 @@
+/*
+ File: SaveCloudAction.java
+
+ Copyright 2010 - The Cytoscape Consortium (www.cytoscape.org)
+
+ Code written by: Layla Oesper
+ Authors: Layla Oesper, Ruth Isserlin, Daniele Merico
+
+ This library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this project. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package cytoscape.csplugins.wordcloud;
+
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.event.ActionEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+
+import javax.imageio.ImageIO;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingConstants;
+
+import cytoscape.Cytoscape;
+import cytoscape.util.CyFileFilter;
+import cytoscape.util.CytoscapeAction;
+import cytoscape.util.FileUtil;
+import cytoscape.view.cytopanels.CytoPanel;
+
+public class SaveCloudAction extends CytoscapeAction
+{
+ //VARIABLES
+
+ // Extensions for the new file
+ public static String SESSION_EXT = ".jpg";
+
+
+ //CONSTRUCTORS
+
+ /**
+ * SaveCloudAction constructor.
+ */
+ public SaveCloudAction()
+ {
+ super("Save Cloud Image");
+ }
+
+ //METHODS
+
+ /**
+ * Method called when a Create Network Cloud action occurs.
+ *
+ * @param ActionEvent - event created when choosing to save the image
+ * of a cloud.
+ */
+ public void actionPerformed(ActionEvent ae) {
+
+ //Open save dialog and get name of file
+
+ String name; // file name
+
+ // Open Dialog to ask user the file name.
+ try {
+
+ name = FileUtil.getFile("Save Current Cloud as JPEG
File", FileUtil.SAVE,
+ new CyFileFilter[] {
}).toString();
+ } catch (Exception exp) {
+ // this is because the selection was canceled
+ return;
+ }
+ if (!name.endsWith(SESSION_EXT))
+ name = name + SESSION_EXT;
+
+ saveFile(name);
+ }
+
+
+ /**
+ * Method that actually creates the file
+ * @param name
+ */
+ private void saveFile(String name)
+ {
+ //Retrieve current panel
+ CloudDisplayPanel panel =
SemanticSummaryManager.getInstance().getCloudWindow();
+ String cloudName =
SemanticSummaryManager.getInstance().getCurCloud().getCloudName();
+
+ //Testing
+
+ Dimension size = panel.getPreferredSize();
+ JFrame frame = new JFrame(cloudName);
+ //frame.setSize(size);
+ frame.getContentPane().add(panel);
+ frame.pack();
+ frame.setLocation(-100, -100);
+ frame.setVisible(true);
+
+ Dimension newSize = frame.getPreferredSize();
+
+
+ BufferedImage b = new
BufferedImage(newSize.width,newSize.height,BufferedImage.TYPE_INT_RGB); /*
change sizes of course */
+ Graphics2D g = b.createGraphics();
+ frame.printAll(g);
+ try{ImageIO.write(b,"jpg",new File(name));}catch (Exception e)
{}
+
+ frame.dispose();
+
+ new SemanticSummaryPluginAction().loadCloudPanel();
+
+ }
+
+}
Modified:
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/SemanticSummaryInputPanel.java
===================================================================
---
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/SemanticSummaryInputPanel.java
2010-09-22 00:05:14 UTC (rev 21969)
+++
csplugins/trunk/soc/layla/WordCloudPlugin/trunk/WordCloud/src/cytoscape/csplugins/wordcloud/SemanticSummaryInputPanel.java
2010-09-22 00:36:08 UTC (rev 21970)
@@ -121,6 +121,7 @@
private JButton addDelimiterButton;
private JButton removeDelimiterButton;
private JButton createNetworkButton;
+ private JButton saveCloudButton;
//Checkbox
private JCheckBox numExclusion;
@@ -810,7 +811,30 @@
gridBagConstraints.insets = new Insets(5, 10, 0, 0);
cloudLayoutPanel.add(createNetworkButton, gridBagConstraints);
+ //Save file to .jpg stuff
+ JLabel saveCloudLabel = new JLabel("Save Cloud Image:");
+ saveCloudButton = new JButton("Export Cloud to File");
+ saveCloudButton.setEnabled(false);
+ saveCloudButton.setToolTipText("Saves the current cloud as an
image file");
+ saveCloudButton.addActionListener(new SaveCloudAction());
+
+ gridBagConstraints = new GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 2;
+ gridBagConstraints.anchor = GridBagConstraints.WEST;
+ gridBagConstraints.insets = new Insets(5, 0, 0, 0);
+ cloudLayoutPanel.add(saveCloudLabel, gridBagConstraints);
+
+ gridBagConstraints = new GridBagConstraints();
+ gridBagConstraints.gridx = 1;
+ gridBagConstraints.gridy = 2;
+ gridBagConstraints.gridwidth = 2;
+ gridBagConstraints.anchor = GridBagConstraints.EAST;
+ gridBagConstraints.weightx = 1.0;
+ gridBagConstraints.insets = new Insets(5, 10, 0, 0);
+ cloudLayoutPanel.add(saveCloudButton, gridBagConstraints);
+
collapsiblePanel.getContentPane().add(panel,BorderLayout.NORTH);
return collapsiblePanel;
}
@@ -917,10 +941,12 @@
if
(params.equals(SemanticSummaryManager.getInstance().getNullCloudParameters()))
{
createNetworkButton.setEnabled(false);
+ saveCloudButton.setEnabled(false);
}
else
{
createNetworkButton.setEnabled(true);
+ saveCloudButton.setEnabled(true);
}
SemanticSummaryManager.getInstance().setCurCloud(params);
@@ -1709,11 +1735,16 @@
{
return attNames;
}
-
+
public JButton getCreateNetworkButton()
{
return createNetworkButton;
}
+
+ public JButton getSaveCloudButton()
+ {
+ return saveCloudButton;
+ }
/**
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.