Author: rozagh
Date: 2012-03-12 12:59:36 -0700 (Mon, 12 Mar 2012)
New Revision: 28496
Added:
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/write/graphics/BitmapWriterTest.java
Modified:
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/AbstractTunableHandler.java
core3/api/trunk/work-swing-api/src/main/java/org/cytoscape/work/swing/AbstractGUITunableHandler.java
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/TunableAbstractCyWriter.java
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/quickstart/SelectMappingKeyTypeTask.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/graphics/BitmapWriter.java
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BooleanHandler.java
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BoundedHandler.java
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/DoubleHandler.java
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FloatHandler.java
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/IntegerHandler.java
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/ListMultipleHandler.java
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/LongHandler.java
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/StringHandler.java
Log:
Removed @ProvidesGUI from BitmapWriter and implemented the GUI using tunables.
Interactions between tunables implemented for BitmapWriter.
A test module developed for BitmapWriter.
work-api, work-swing-api and work-swing-impl updated. Most of the tunable
handlers have the update,getstate and event handler methods added.
Modified:
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/AbstractTunableHandler.java
===================================================================
---
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/AbstractTunableHandler.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/api/trunk/work-api/src/main/java/org/cytoscape/work/AbstractTunableHandler.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -73,11 +73,13 @@
/**
* {@inheritDoc}
*/
- final public void setValue(final Object newValue) throws
IllegalAccessException, InvocationTargetException {
+ public void setValue(final Object newValue) throws
IllegalAccessException, InvocationTargetException {
+
if (field != null)
field.set(instance, newValue);
else
setter.invoke(instance, newValue);
+
}
/**
Modified:
core3/api/trunk/work-swing-api/src/main/java/org/cytoscape/work/swing/AbstractGUITunableHandler.java
===================================================================
---
core3/api/trunk/work-swing-api/src/main/java/org/cytoscape/work/swing/AbstractGUITunableHandler.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/api/trunk/work-swing-api/src/main/java/org/cytoscape/work/swing/AbstractGUITunableHandler.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -6,6 +6,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;
@@ -29,7 +30,7 @@
* @CyAPI.Abstract.Class
*/
public abstract class AbstractGUITunableHandler
- extends AbstractTunableHandler implements GUITunableHandler,
ActionListener, ChangeListener, ListSelectionListener
+ extends AbstractTunableHandler implements GUITunableHandler
{
private static final Logger logger =
LoggerFactory.getLogger(AbstractGUITunableHandler.class);
@@ -71,7 +72,6 @@
*/
private List<GUITunableHandler> listeners;
- private Map<String,String> lastChangeState;
/** Standard base class constructor for <code>TunableHandler</code>s
that deal with
* <code>Tunable</code>s that annotate a field.
@@ -121,44 +121,18 @@
dependents = new LinkedList<GUITunableHandler>();
listeners = new LinkedList<GUITunableHandler>();
- lastChangeState = new HashMap<String,String>();
panel = new JPanel();
}
- /**
- * Action listener event handler.
- *
- * @param ae specifics of the event (ignored!)
- */
- public void actionPerformed(ActionEvent ae) {
- notifyDependents();
- notifyChangeListeners();
- }
- /**
- * Notification of a state change of a <code>GUITunableHandler</code>
- *
- * @param e the details of the state change
- */
- public void stateChanged(ChangeEvent e) {
+ public void setValue(final Object newValue) throws
IllegalAccessException, InvocationTargetException{
+ super.setValue(newValue);
notifyDependents();
notifyChangeListeners();
+
}
-
+
/**
- * Notify a change during the selection of an item in the
<code>ListSelection</code> objects
- *
- * @param le the specifics of the list selection change
- */
- public void valueChanged(ListSelectionEvent le) {
- boolean ok = le.getValueIsAdjusting();
- if (!ok) {
- notifyDependents();
- notifyChangeListeners();
- }
- }
-
- /**
* Notifies all dependents that this object has changed.
*/
public void notifyDependents() {
@@ -174,8 +148,10 @@
public void notifyChangeListeners() {
String state = getState();
String name = getName();
+
for (GUITunableHandler gh : listeners)
gh.changeOccurred(name, state);
+
}
/**
@@ -209,11 +185,7 @@
/** {@inheritDoc} */
public final void changeOccurred(final String name, final String state)
{
- String lastState = lastChangeState.get(name);
- if ( lastState == null || !lastState.equals(state) ) {
- update();
- lastChangeState.put(name,state);
- }
+ update();
}
/** {@inheritDoc} */
Modified:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/TunableAbstractCyWriter.java
===================================================================
---
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/TunableAbstractCyWriter.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/export/TunableAbstractCyWriter.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -29,7 +29,7 @@
* processing.
*/
@Tunable(description = "Select the export file format")
- public final ListSingleSelection<String> options;
+ public ListSingleSelection<String> options;
protected final String getExportFileFormat() {
return options.getSelectedValue();
Modified:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/quickstart/SelectMappingKeyTypeTask.java
===================================================================
---
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/quickstart/SelectMappingKeyTypeTask.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/quickstart/SelectMappingKeyTypeTask.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -7,7 +7,7 @@
import javax.swing.JPanel;
import org.cytoscape.task.internal.quickstart.QuickStartState.Job;
import org.cytoscape.work.AbstractTask;
-import org.cytoscape.work.ProvidesGUI;
+//import org.cytoscape.work.ProvidesGUI;
import org.cytoscape.work.TaskMonitor;
import org.cytoscape.work.Tunable;
import org.cytoscape.work.util.ListSingleSelection;
@@ -41,7 +41,7 @@
}
- @ProvidesGUI
+ //@ProvidesGUI
public JPanel getGUI() {
if (mappingKeyTypePanel == null){
this.mappingKeyTypePanel = new
MappingKeyTypePanel(values, previewKeys, previewData);
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/graphics/BitmapWriter.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/graphics/BitmapWriter.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/graphics/BitmapWriter.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -4,71 +4,186 @@
import static
org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_WIDTH;
import java.awt.Graphics2D;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
import java.awt.image.BufferedImage;
import java.io.OutputStream;
+import java.security.PublicKey;
+import java.text.ParseException;
+import java.util.ArrayList;
import java.util.Set;
import javax.imageio.ImageIO;
+import javax.swing.BoundedRangeModel;
+import javax.swing.JFormattedTextField;
import javax.swing.JPanel;
-import org.cytoscape.io.internal.ui.ExportBitmapOptionsPanel;
import org.cytoscape.io.write.CyWriter;
import org.cytoscape.view.presentation.RenderingEngine;
import org.cytoscape.work.AbstractTask;
-import org.cytoscape.work.ProvidesGUI;
import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.Tunable;
+import org.cytoscape.work.util.BoundedDouble;
+import org.cytoscape.work.util.ListSingleSelection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.cytoscape.work.AbstractTunableHandler;
+
/**
*/
public class BitmapWriter extends AbstractTask implements CyWriter {
private static final Logger logger =
LoggerFactory.getLogger(BitmapWriter.class);
- private static final int MAX_SIZE = 50000;
+ private static final double MAX_ZOOM= 500;
- private ExportBitmapOptionsPanel exportBitmapOptionsPanel = null;
+ //****
+ public BoundedDouble zoom;
+ @Tunable(description = "Zoom (%)",groups={"Image
Size"},params="alignments=vertical;slider=true",listenForChange={"WidthInPixels","HeightInPixels",
"WidthInInches", "HeightInInches"})
+ public BoundedDouble getZoom(){
+ return zoom;
+ }
+ public void setZoom(BoundedDouble zf){
+ zoom = zf;
+
+ //update height
+ heightInPixels = (int) ((zoom.getValue()/100) * initialHPixel);
+ //update width
+ widthInPixels = (int) ((zoom.getValue()/100) * initialWPixel);
+ //update inch measures
+ final double dpi = resolution.getSelectedValue().doubleValue();
+ widthInInches = new Double( widthInPixels/dpi);
+ heightInInches = new Double( heightInPixels/dpi);
+ }
- //@Tunable(description = "Image scale")
- //public BoundedDouble scaleFactor;
+ //****
- //@Tunable(description = "Original Width (px)")
- //public BoundedInteger width;
+ public int widthInPixels;
+ @Tunable(description = "Width (px)",groups={"Image
Size"},params="alignments=vertical",listenForChange={"Zoom","HeightInPixels",
"WidthInInches", "HeightInInches"})
+ public int getWidthInPixels(){
+ return widthInPixels;
+ }
+ public void setWidthInPixels(int wpf){
+ widthInPixels = wpf;
+ // udate zoom
+ zoom.setValue(( ((double)widthInPixels) / initialWPixel) *
100.0);
+ //update height
+ heightInPixels = (int) ((zoom.getValue() / 100) *
initialHPixel);
+
+ final double dpi = resolution.getSelectedValue().doubleValue();
+ widthInInches = widthInPixels/dpi;
+ heightInInches = heightInPixels/dpi;
+ }
- //@Tunable(description = "Original Height (px)")
- //public BoundedInteger height;
+ //****
+ public int heightInPixels;
+ @Tunable(description = "Height (px)",groups={"Image
Size"},params="alignments=vertical",listenForChange={"Zoom","WidthInPixels",
"WidthInInches", "HeightInInches"})
+ public int getHeightInPixels(){
+ return heightInPixels;
+ }
+ public void setHeightInPixels(int hpf){
+ heightInPixels = hpf;
+ // udate zoom
+ zoom.setValue (( ((double)heightInPixels) / initialHPixel) *
100.0);
+ //update width
+ widthInPixels = (int) ((zoom.getValue()/100) * initialWPixel);
+
+ final double dpi = resolution.getSelectedValue().doubleValue();
+ widthInInches = widthInPixels/dpi;
+ heightInInches = heightInPixels/dpi;
+ }
+
+ //****
+ public double widthInInches;
+ @Tunable(description = "Width (inches)",groups={"Image
Size"},params="alignments=vertical",listenForChange={"Resolution", "Zoom",
"HeightInPixels", "WidthInPixels" , "HeightInInches"})
+ public double getWidthInInches(){
+ return widthInInches;
+ }
+ public void setWidthInInches(double wif){
+ widthInInches = wif;
+
+ final double dpi = resolution.getSelectedValue().doubleValue();
+ widthInPixels = (int) (widthInInches * dpi);
+
+ zoom.setValue(( ((double)widthInPixels) / initialWPixel) *
100.0);
+ heightInPixels = (int) ((zoom.getValue()/100) * initialHPixel);
+
+ heightInInches = heightInPixels/dpi;
+ }
+
+ //****
+ public double heightInInches;
+ @Tunable(description = "Height (inches)",groups={"Image
Size"},params="alignments=vertical",listenForChange={"Resolution", "Zoom",
"HeightInPixels", "WidthInPixels", "WidthInInches"})
+ public double getHeightInInches(){
+ return heightInInches;
+ }
+ public void setHeightInInches(double hif){
+ heightInInches = hif;
+
+ final double dpi = resolution.getSelectedValue().doubleValue();
+ heightInPixels = (int) (heightInInches * dpi);
+
+ zoom.setValue(( ((double)heightInPixels) / initialHPixel) *
100.0);
+ widthInPixels = (int) ((zoom.getValue()/100) * initialWPixel);
+
+ widthInInches = widthInPixels/dpi;
+ }
+
+ //****
+ public ListSingleSelection<Integer> resolution;
+ @Tunable(description = "Resolution (DPI)",groups={"Image
Size"},params="alignments=vertical")
+ public ListSingleSelection<Integer> getResolution(){
+ return resolution;
+ }
+ public void setResolution(ListSingleSelection<Integer> rescb){
+ final double dpi = resolution.getSelectedValue().doubleValue();
+ widthInInches = widthInPixels/dpi;
+ heightInInches = heightInPixels/dpi;
+ }
+
+
private final OutputStream outStream;
- private final RenderingEngine<?> re;
+ private RenderingEngine<?> re;
private String extension = null;
- private int w, h;
+ private int initialWPixel, initialHPixel;
- public BitmapWriter(final RenderingEngine<?> re, OutputStream outStream,
+ public BitmapWriter( RenderingEngine<?> re, OutputStream outStream,
Set<String> extensions) {
+
+
this.re = re;
this.outStream = outStream;
setExtension(extensions);
- w = (int) (re.getViewModel()
-
.getVisualProperty(NETWORK_WIDTH).doubleValue());
- h = (int) (re.getViewModel()
-
.getVisualProperty(NETWORK_HEIGHT).doubleValue());
- }
-
-
- @ProvidesGUI
- public JPanel getGUI() {
- if (exportBitmapOptionsPanel == null) {
- try {
- this.exportBitmapOptionsPanel =
- new ExportBitmapOptionsPanel(w, h);
- } catch (Exception e) {
- throw new IllegalStateException("Could not
initialize BitmapWriterPanel.", e);
- }
- }
+ zoom = new BoundedDouble(0.0, 100.0, MAX_ZOOM,false, false);
+
+ initialWPixel = (re.getViewModel()
+ .getVisualProperty(NETWORK_WIDTH).intValue());
+
+ initialHPixel = (re.getViewModel()
+ .getVisualProperty(NETWORK_HEIGHT).intValue());
+
+
- return exportBitmapOptionsPanel;
+ widthInPixels = initialWPixel;
+ heightInPixels = initialHPixel;
+ ArrayList<Integer> values = new ArrayList<Integer>();
+ values.add(72);
+ values.add(100);
+ values.add(150);
+ values.add(300);
+ values.add(600);
+ resolution = new ListSingleSelection<Integer>(values);
+ resolution.setSelectedValue(72);
+ double dpi = 72.0 ;
+
+ widthInInches = initialWPixel / dpi;
+ heightInInches = initialHPixel / dpi;
+
}
@@ -91,17 +206,10 @@
public void run(TaskMonitor tm) throws Exception {
tm.setProgress(0.0);
logger.debug("Bitmap image rendering start.");
-
- // Extract size
- //final double scale = scaleFactor.getValue().doubleValue();
- //final int finalW =
((Number)(width.getValue()*scale)).intValue();
- //final int finalH =
((Number)(height.getValue()*scale)).intValue();
- final double scale =exportBitmapOptionsPanel.getZoom();
- final int finalW = exportBitmapOptionsPanel.getWidthPixels();
- final int finalH = exportBitmapOptionsPanel.getHeightPixels();
+ final double scale = zoom.getValue() / 100.0;
tm.setProgress(0.1);
- final BufferedImage image = new BufferedImage(finalW, finalH,
BufferedImage.TYPE_INT_RGB);
+ final BufferedImage image = new BufferedImage(widthInPixels,
heightInPixels, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) image.getGraphics();
g.scale(scale, scale);
tm.setProgress(0.2);
@@ -118,4 +226,7 @@
logger.debug("Bitmap image rendering finished.");
tm.setProgress(1.0);
}
+
+
}
+
Added:
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/write/graphics/BitmapWriterTest.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/write/graphics/BitmapWriterTest.java
(rev 0)
+++
core3/impl/trunk/io-impl/impl/src/test/java/org/cytoscape/io/internal/write/graphics/BitmapWriterTest.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -0,0 +1,175 @@
+package org.cytoscape.io.internal.write.graphics;
+
+import static
org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_HEIGHT;
+import static
org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_WIDTH;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.imageio.ImageIO;
+
+import org.cytoscape.io.CyFileFilter;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.VisualProperty;
+import org.cytoscape.view.presentation.RenderingEngine;
+import org.cytoscape.work.util.BoundedDouble;
+import org.cytoscape.work.util.ListSingleSelection;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.lowagie.text.List;
+import com.lowagie.text.pdf.codec.Base64.OutputStream;
+
+public class BitmapWriterTest {
+ private static final Logger logger =
LoggerFactory.getLogger(PDFWriterTest.class);
+
+ protected BitmapWriter bw;
+ int initHP, initWP;
+
+ @Before
+ public void init(){
+ Set<String> mySet = new HashSet<String>();
+ for( String s : ImageIO.getWriterFormatNames()){
+ mySet.add(s);
+ }
+
+ initHP = 400;
+ initWP = 550;
+
+ RenderingEngine<CyNetwork> re = ((RenderingEngine<CyNetwork>)(
mock(RenderingEngine.class)));
+ View<CyNetwork> view= (View<CyNetwork> )mock(View.class);
+ when(view.getVisualProperty(NETWORK_WIDTH)).thenReturn(550.0);
+ when(view.getVisualProperty(NETWORK_HEIGHT)).thenReturn(400.0);
+ when(re.getViewModel()).thenReturn(view);
+
+ bw = new BitmapWriter(re , mock(OutputStream.class), mySet);
+
+ }
+
+ @Test
+ public void updateZoomTest(){
+ BoundedDouble newZoom = new BoundedDouble(0.0,100.0, 500.0,
true, false);
+ newZoom.setValue(50.0);
+
+ bw.setZoom(newZoom);
+ assertTrue(50/100 == (bw.heightInPixels/initHP));
+ assertTrue(50/100 == (bw.widthInPixels/initWP));
+
+ assertTrue(bw.resolution.getSelectedValue() ==
bw.heightInPixels/bw.heightInInches);
+ assertTrue(bw.resolution.getSelectedValue() ==
bw.widthInPixels/bw.widthInInches);
+
+ }
+
+ @Test
+ public void updateZoomTest2(){
+ BoundedDouble newZoom = new BoundedDouble(0.0,100.0, 500.0,
true, false);
+ newZoom.setValue(200.0);
+
+ bw.setZoom(newZoom);
+
+ assertEquals(newZoom.getValue(), bw.zoom.getValue());
+ assertTrue(newZoom.getValue()/100 ==
(bw.heightInPixels/initHP));
+ assertTrue(newZoom.getValue()/100 == (bw.widthInPixels/initWP));
+
+ assertTrue(bw.resolution.getSelectedValue() ==
bw.heightInPixels/bw.heightInInches);
+ assertTrue(bw.resolution.getSelectedValue() ==
bw.widthInPixels/bw.widthInInches);
+
+ }
+
+ @Test
+ public void updateWP(){
+
+ int newWP = 1100;
+ bw.setWidthInPixels(newWP);
+
+ assertEquals(newWP, bw.widthInPixels);
+ assertTrue(bw.zoom.getValue() /100 == (newWP/initWP));
+ assertTrue(bw.zoom.getValue() /100 ==
(bw.heightInPixels/initHP));
+
+
+ assertTrue(bw.resolution.getSelectedValue() ==
newWP/bw.widthInInches);
+ assertTrue(bw.resolution.getSelectedValue() ==
bw.heightInPixels/bw.heightInInches);
+
+ }
+
+ @Test
+ public void updateHP(){
+
+ int newHP = 200;
+ bw.setHeightInPixels(newHP);
+
+ assertEquals(newHP, bw.heightInPixels);
+ assertEquals(((double)newHP)/initHP, bw.zoom.getValue() /100,
0.0);
+ assertEquals( ((double)bw.widthInPixels)/initWP,
bw.zoom.getValue() /100, 0.0);
+
+
+ assertTrue(bw.resolution.getSelectedValue() ==
newHP/bw.heightInInches);
+ assertTrue(bw.resolution.getSelectedValue() ==
bw.widthInPixels/bw.widthInInches);
+
+ }
+
+
+ @Test
+ public void updateWI(){
+
+ double newWI = (initWP*3)/72.0;
+ bw.setWidthInInches(newWI);
+
+ assertEquals(newWI, bw.widthInInches, 0.0);
+ assertTrue(bw.zoom.getValue() /100 ==
(bw.heightInPixels/initHP));
+ assertTrue(bw.zoom.getValue() /100 ==
(bw.widthInPixels/initWP));
+
+
+ assertTrue(bw.resolution.getSelectedValue() ==
bw.widthInPixels/newWI);
+ assertTrue(bw.resolution.getSelectedValue() ==
bw.heightInPixels/bw.heightInInches);
+
+ }
+
+ @Test
+ public void updateHI(){
+
+ double newHI = (initHP*3)/72.0;
+ bw.setHeightInInches(newHI);
+
+ assertEquals(newHI, bw.heightInInches, 0.0);
+
+ assertTrue(bw.zoom.getValue() /100 ==
(bw.heightInPixels/initHP));
+ assertTrue(bw.zoom.getValue() /100 ==
(bw.widthInPixels/initWP));
+
+
+ assertTrue(bw.resolution.getSelectedValue() ==
bw.heightInPixels/newHI);
+ assertTrue(bw.resolution.getSelectedValue() ==
bw.widthInPixels/bw.widthInInches);
+
+ }
+
+ @Test
+ public void updateResolution(){
+
+ ListSingleSelection<Integer> newResolution = bw.getResolution();
+ int newDpi = 300;
+ newResolution.setSelectedValue(newDpi);
+ bw.setResolution(newResolution);
+
+ assertEquals(newDpi,
bw.getResolution().getSelectedValue().intValue());
+
+ assertTrue(bw.zoom.getValue() /100 ==
(bw.heightInPixels/initHP));
+ assertTrue(bw.zoom.getValue() /100 ==
(bw.widthInPixels/initWP));
+
+
+ assertTrue(newDpi == bw.heightInPixels/bw.heightInInches);
+ assertTrue(newDpi == bw.widthInPixels/bw.widthInInches);
+
+ }
+
+}
Modified:
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BooleanHandler.java
===================================================================
---
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BooleanHandler.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BooleanHandler.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -3,6 +3,8 @@
import java.awt.BorderLayout;
import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -19,7 +21,7 @@
*
* @author pasteur
*/
-public class BooleanHandler extends AbstractGUITunableHandler {
+public class BooleanHandler extends AbstractGUITunableHandler implements
ActionListener {
private JCheckBox checkBox;
private boolean horizontal = false;
@@ -68,6 +70,17 @@
return false;
}
}
+
+
+ public void update(){
+ boolean b;
+ try{
+ b = (Boolean) getValue();
+ checkBox.setSelected(b);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
/**
* To set the current value represented in the <code>GUIHandler</code>
(in a <code>JCheckBox</code>)to the value of this <code>Boolean</code> object
@@ -87,4 +100,9 @@
public String getState() {
return String.valueOf(checkBox.isSelected());
}
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ handle();
+ }
}
Modified:
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BoundedHandler.java
===================================================================
---
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BoundedHandler.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/BoundedHandler.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -3,17 +3,23 @@
import java.awt.BorderLayout;
import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
import org.cytoscape.work.Tunable;
import org.cytoscape.work.swing.AbstractGUITunableHandler;
import org.cytoscape.work.internal.tunables.utils.myBoundedSwing;
import org.cytoscape.work.internal.tunables.utils.mySlider;
import org.cytoscape.work.util.AbstractBounded;
+import org.cytoscape.work.util.BoundedDouble;
/**
@@ -24,7 +30,7 @@
* @param <T> type of <code>AbstractBounded</code>
*/
@SuppressWarnings("unchecked")
-public class BoundedHandler<T extends AbstractBounded> extends
AbstractGUITunableHandler {
+public class BoundedHandler<T extends AbstractBounded> extends
AbstractGUITunableHandler implements ChangeListener, ActionListener {
/**
* Representation of the <code>Bounded</code> in a <code>JSlider</code>
*/
@@ -88,6 +94,7 @@
bounded.isUpperBoundStrict());
panel.add(label, BorderLayout.WEST);
panel.add(boundedField, BorderLayout.EAST);
+ boundedField.addActionListener(this);
}
} catch (Exception e) {
e.printStackTrace();
@@ -103,6 +110,30 @@
}
}
+ public void update(){
+
+ final String title = getDescription();
+
+ try {
+ final T bounded = getBounded();
+ if (useSlider){
+ Number n = (Number) bounded.getValue();
+ slider.setValue(n);
+ }else{
+ final JLabel label =
+ new JLabel(title + " (max: " +
bounded.getLowerBound().toString()
+ + " min: " +
bounded.getUpperBound().toString() + ")" );
+ label.setFont(new Font(null, Font.PLAIN,12));
+ boundedField = new
myBoundedSwing((Number)bounded.getValue(), (Number)bounded.getLowerBound(),
+
(Number)bounded.getUpperBound(), bounded.isLowerBoundStrict(),
+
bounded.isUpperBoundStrict());
+ }
+ } catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+
/**
* To set the value (from the JSlider or the JTextField) to the
<code>Bounded</code> object
*
@@ -112,8 +143,9 @@
try {
final T bounded = getBounded();
final Number fieldValue = useSlider ? slider.getValue()
: boundedField.getFieldValue();
- if (fieldValue instanceof Double)
+ if (fieldValue instanceof Double){
bounded.setValue((Double)fieldValue);
+ }
else if (fieldValue instanceof Float)
bounded.setValue((Float)fieldValue);
else if (fieldValue instanceof Integer)
@@ -122,6 +154,8 @@
bounded.setValue((Long)fieldValue);
else
throw new IllegalStateException("unexpected
type: " + fieldValue.getClass() + "!");
+
+ setValue(bounded);
} catch (Exception e) {
e.printStackTrace();
}
@@ -138,4 +172,15 @@
return "";
}
}
+
+
+ public void stateChanged(ChangeEvent e) {
+ System.out.println("in satatechange");
+ handle();
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ handle();
+ }
}
Modified:
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/DoubleHandler.java
===================================================================
---
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/DoubleHandler.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/DoubleHandler.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -4,9 +4,17 @@
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
import java.lang.reflect.*;
+import java.text.DecimalFormat;
+import java.text.ParseException;
import java.util.Properties;
import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ListSelectionEvent;
import org.cytoscape.work.Tunable;
import org.cytoscape.work.swing.AbstractGUITunableHandler;
@@ -17,8 +25,8 @@
*
* @author pasteur
*/
-public class DoubleHandler extends AbstractGUITunableHandler {
- private JTextField textField;
+public class DoubleHandler extends AbstractGUITunableHandler implements
ActionListener {
+ private JFormattedTextField textField;
private String newline = System.getProperty("line.separator");
/**
@@ -51,11 +59,14 @@
}
//set Gui
- textField = new JTextField(d.toString(), 10);
+
+ textField = new JFormattedTextField(new DecimalFormat());
+ textField.setValue(d);
panel = new JPanel(new BorderLayout());
JLabel label = new JLabel(getDescription());
label.setFont(new Font(null, Font.PLAIN,12));
textField.setHorizontalAlignment(JTextField.RIGHT);
+ textField.addActionListener(this);
if (horizontal) {
panel.add(label, BorderLayout.NORTH);
@@ -66,6 +77,18 @@
}
}
+ public void update(){
+ Double d;
+ try {
+ d = (Double)getValue();
+ textField.setValue(d);
+
+ } catch(final Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
/**
* Catches the value inserted in the JTextField, parses it to a
<code>Double</code> value, and tries to set it to the initial object. If it
can't, throws an exception that displays the source error to the user
*/
@@ -77,9 +100,15 @@
d = Double.parseDouble(textField.getText());
try {
setValue(d);
+
} catch (final Exception e) {
+ textField.setBackground(Color.red);
+ JOptionPane.showMessageDialog(null, "The value
entered cannot be set!", "Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
+ textField.setBackground(Color.white);
+ return;
}
+ textField.setValue(d);
} catch(NumberFormatException nfe) {
textField.setBackground(Color.red);
try {
@@ -90,11 +119,47 @@
}
JOptionPane.showMessageDialog(null,"A double was
expected. Value will be set to default: " + d, "Error",
JOptionPane.ERROR_MESSAGE);
try {
- textField.setText(getValue().toString());
+ textField.setValue(getValue().toString());
textField.setBackground(Color.white);
} catch(final Exception e){
e.printStackTrace();
}
}
}
+
+ /**
+ * To get the item that is currently selected
+ */
+ public String getState() {
+ if ( textField == null )
+ return "";
+
+ Double d = Double.parseDouble( textField.getText());
+ final String text = d.toString();
+ if ( text == null )
+ return "";
+
+ try {
+ //d = Double.parseDouble(text);
+ return text;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return "";
+ }
+
+ }
+
+ /**
+ * Action listener event handler.
+ *
+ * @param ae specifics of the event (ignored!)
+ */
+ public void actionPerformed(ActionEvent ae) {
+ handle();
+ }
+
}
+
+
+
Modified:
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
===================================================================
---
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -120,6 +120,23 @@
}
}
+ public void update(){
+
+ final int load_or_save = input ? FileUtil.LOAD : FileUtil.SAVE;
+
+ // Use the panel's parent if we have it, otherwise use the
possible
+ // parent specified in setFileTunableDirectly.
+ Component parentComponent =
SwingUtilities.getWindowAncestor(panel);
+ if ( parentComponent == null )
+ parentComponent = possibleParent;
+ final File file = fileUtil.getFile(parentComponent,
titleLabel.getText(), load_or_save, filters);
+ if (file != null) {
+ fileTextField.setText(file.getAbsolutePath());
+ }else{
+ fileTextField.setText(defaultString);
+ }
+ }
+
//construction of the GUI depending on the file type expected:
// -field to display the file's path
// -button to open the FileCHooser
@@ -253,4 +270,13 @@
}
}
+ public String getState(){
+ try{
+ return fileTextField.getText();
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ return "";
+ }
+
}
Modified:
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FloatHandler.java
===================================================================
---
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FloatHandler.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/FloatHandler.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -4,15 +4,19 @@
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.lang.reflect.*;
+import java.text.DecimalFormat;
+
import javax.swing.*;
import org.cytoscape.work.Tunable;
import org.cytoscape.work.swing.AbstractGUITunableHandler;
-public class FloatHandler extends AbstractGUITunableHandler {
- private JTextField textField;
+public class FloatHandler extends AbstractGUITunableHandler implements
ActionListener {
+ private JFormattedTextField textField;
private boolean horizontal = false;
/**
@@ -45,11 +49,13 @@
}
//setup GUI
- textField = new JTextField(f.toString(), 10);
+ textField = new JFormattedTextField(new DecimalFormat());
+ textField.setValue(f);
panel = new JPanel(new BorderLayout());
JLabel label = new JLabel(getDescription());
label.setFont(new Font(null, Font.PLAIN, 12));
textField.setHorizontalAlignment(JTextField.RIGHT);
+ textField.addActionListener(this);
if (horizontal) {
panel.add(label, BorderLayout.NORTH);
@@ -60,6 +66,16 @@
}
}
+ public void update(){
+ Float f;
+ try{
+ f= (Float) getValue();
+ textField.setValue(f);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+
/**
* Catches the value inserted in the JTextField, parses it to a
<code>Float</code> value, and tries to set it to the
* initial object. If it can't, throws an exception that displays the
source error to the user
@@ -69,7 +85,16 @@
Float f;
try {
f = Float.parseFloat(textField.getText());
- setValue(f);
+ try {
+ setValue(f);
+
+ } catch (final Exception e) {
+ textField.setBackground(Color.red);
+ JOptionPane.showMessageDialog(null, "The value
entered cannot be set!", "Error", JOptionPane.ERROR_MESSAGE);
+ e.printStackTrace();
+ textField.setBackground(Color.white);
+ return;
+ }
} catch(final Exception nfe) {
textField.setBackground(Color.red);
try{
@@ -88,4 +113,32 @@
}
}
}
+
+ /**
+ * To get the item that is currently selected
+ */
+ public String getState() {
+ if ( textField == null )
+ return "";
+ try {
+ final String text = textField.getText();
+ if ( text == null )
+ return "";
+ return text;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return "";
+ }
+
+ }
+
+ /**
+ * Action listener event handler.
+ *
+ * @param ae specifics of the event (ignored!)
+ */
+ public void actionPerformed(ActionEvent ae) {
+ handle();
+ }
}
Modified:
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/IntegerHandler.java
===================================================================
---
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/IntegerHandler.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/IntegerHandler.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -4,9 +4,12 @@
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
@@ -21,8 +24,8 @@
*
* @author pasteur
*/
-public class IntegerHandler extends AbstractGUITunableHandler {
- private JTextField textField;
+public class IntegerHandler extends AbstractGUITunableHandler implements
ActionListener {
+ private JFormattedTextField textField;
private boolean horizontal = false;
/**
@@ -58,8 +61,9 @@
panel = new JPanel(new BorderLayout());
JLabel label = new JLabel(getDescription());
label.setFont(new Font(null, Font.PLAIN,12));
- textField = new JTextField(i.toString(), 10);
+ textField = new JFormattedTextField(i.toString());
textField.setHorizontalAlignment(JTextField.RIGHT);
+ textField.addActionListener(this);
if (horizontal) {
panel.add(label, BorderLayout.NORTH);
@@ -70,6 +74,17 @@
}
}
+ public void update(){
+ Integer i = null;
+ try{
+ i = (Integer)getValue();
+ textField.setValue(i);
+ } catch(final Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
/**
* Catches the value inserted in the JTextField, parses it to a
<code>Integer</code> value, and tries to set it to the initial object. If it
can't, throws an exception that displays the source error to the user
*/
@@ -78,6 +93,7 @@
try {
textField.setBackground(Color.white);
newValue = Integer.parseInt(textField.getText());
+
} catch(final NumberFormatException nfe) {
try {
textField.setBackground(Color.red);
@@ -90,8 +106,41 @@
}
try {
setValue(newValue);
+
} catch (final Exception e) {
+ textField.setBackground(Color.red);
+ JOptionPane.showMessageDialog(null, "The value entered
cannot be set!", "Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
+ textField.setBackground(Color.white);
+ return;
}
}
+
+
+ /**
+ * To get the item that is currently selected
+ */
+ public String getState() {
+ if ( textField == null )
+ return "";
+
+ final String text = textField.getText();
+ if ( text == null )
+ return "";
+
+ try {
+ return text;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return "";
+ }
+
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+
+ handle();
+ }
}
Modified:
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
===================================================================
---
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/JPanelTunableMutator.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -333,23 +333,13 @@
private List<GUITunableHandler> findHandlers(Object objectWithTunables)
{
List<GUITunableHandler> handlers = new
ArrayList<GUITunableHandler>();
- // clear any previously set providedGUI panels
- providedGUI = null;
-
// the call to getHandlers will populate guiProviderMap
// note that map may be empty!
Map<String, GUITunableHandler> tunableHandlerMap =
getHandlers(objectWithTunables);
- if (guiProviderMap.containsKey(objectWithTunables)) {
- try {
- providedGUI =
(JPanel)guiProviderMap.get(objectWithTunables).invoke(objectWithTunables);
- } catch (final Exception e) {
- logger.error("Can't retrieve @ProvidesGUI
JPanel: ", e);
- }
- } else {
- if ( tunableHandlerMap != null &&
!tunableHandlerMap.isEmpty() )
- handlers.addAll(tunableHandlerMap.values());
- }
+
+ if ( tunableHandlerMap != null && !tunableHandlerMap.isEmpty() )
+ handlers.addAll(tunableHandlerMap.values());
return handlers;
}
Modified:
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/ListMultipleHandler.java
===================================================================
---
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/ListMultipleHandler.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/ListMultipleHandler.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -4,6 +4,7 @@
import java.awt.BorderLayout;
import java.awt.Font;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -14,6 +15,8 @@
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
import org.cytoscape.work.Tunable;
import org.cytoscape.work.swing.AbstractGUITunableHandler;
@@ -27,7 +30,7 @@
*
* @param <T> type of items the List contains
*/
-public class ListMultipleHandler<T> extends AbstractGUITunableHandler {
+public class ListMultipleHandler<T> extends AbstractGUITunableHandler
implements ListSelectionListener {
private JList itemsContainerList;
private ListMultipleSelection<T> listMultipleSelection;
@@ -85,6 +88,10 @@
panel.add(scrollpane,BorderLayout.EAST);
}
+ public void update(){
+
+ }
+
/**
* set the items that are currently selected in the
<code>itemsContainerList</code> as the selected items in
<code>listMultipleSelection</code>
*/
@@ -96,6 +103,16 @@
if (!selectedItems.isEmpty()) {
listMultipleSelection.setSelectedValues(selectedItems);
}
+
+ try {
+ setValue(listMultipleSelection);
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
/**
@@ -108,4 +125,9 @@
final List<T> selection =
listMultipleSelection.getSelectedValues();
return selection == null ? "" : selection.toString();
}
+
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ handle();
+ }
}
Modified:
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/LongHandler.java
===================================================================
---
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/LongHandler.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/LongHandler.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -4,7 +4,11 @@
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.lang.reflect.*;
+import java.text.DecimalFormat;
+
import javax.swing.*;
import org.cytoscape.work.Tunable;
@@ -16,8 +20,8 @@
*
* @author pasteur
*/
-public class LongHandler extends AbstractGUITunableHandler {
- private JTextField textField;
+public class LongHandler extends AbstractGUITunableHandler implements
ActionListener {
+ private JFormattedTextField textField;
private boolean horizontal = false;
/**
@@ -42,11 +46,13 @@
private void init() {
//setup GUI
- textField = new JTextField(getLong().toString(), 10);
+ textField = new JFormattedTextField(new DecimalFormat());
+ textField.setValue(getLong());
panel = new JPanel(new BorderLayout());
JLabel label = new JLabel(getDescription());
label.setFont(new Font(null, Font.PLAIN,12));
textField.setHorizontalAlignment(JTextField.RIGHT);
+ textField.addActionListener(this);
if (horizontal) {
panel.add(label, BorderLayout.NORTH);
@@ -66,6 +72,16 @@
}
}
+ public void update(){
+ Long l = null;
+ try{
+ l = getLong();
+ textField.setValue(l);
+ } catch(final Exception e) {
+ e.printStackTrace();
+ }
+ }
+
/**
* Catches the value inserted in the JTextField, parses it to a
<code>Long</code> value, and tries
* to set it to the initial object. If it can't, throws an exception
that displays the source error to the user
@@ -91,8 +107,41 @@
}
try {
setValue(l);
+
} catch (final Exception e) {
+ textField.setBackground(Color.red);
+ JOptionPane.showMessageDialog(null, "The value entered
cannot be set!", "Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
+ textField.setBackground(Color.white);
+ return;
}
}
+
+ /**
+ * To get the item that is currently selected
+ */
+ public String getState() {
+ if ( textField == null )
+ return "";
+
+ final String text = textField.getText();
+ if ( text == null )
+ return "";
+
+ try {
+ return text;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return "";
+ }
+
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+
+ handle();
+ }
+
}
Modified:
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/StringHandler.java
===================================================================
---
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/StringHandler.java
2012-03-12 19:08:44 UTC (rev 28495)
+++
core3/impl/trunk/work-swing-impl/impl/src/main/java/org/cytoscape/work/internal/tunables/StringHandler.java
2012-03-12 19:59:36 UTC (rev 28496)
@@ -2,6 +2,8 @@
import java.awt.BorderLayout;
import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.lang.reflect.*;
import javax.swing.*;
@@ -14,8 +16,8 @@
*
* @author pasteur
*/
-public class StringHandler extends AbstractGUITunableHandler {
- private JTextField textField;
+public class StringHandler extends AbstractGUITunableHandler implements
ActionListener {
+ private JFormattedTextField textField;
private boolean horizontal = false;
/**
@@ -48,11 +50,12 @@
}
//set Gui
- textField = new JTextField(s, 15);
+ textField = new JFormattedTextField(s);
panel = new JPanel(new BorderLayout());
JLabel label = new JLabel(getDescription());
label.setFont(new Font(null, Font.PLAIN,12));
textField.setHorizontalAlignment(JTextField.RIGHT);
+ textField.addActionListener(this);
if (horizontal) {
panel.add(label, BorderLayout.NORTH);
@@ -62,6 +65,17 @@
panel.add(textField, BorderLayout.EAST);
}
}
+
+ public void update(){
+ String s = null;
+ try {
+ s = (String)getValue();
+ textField.setValue(s);
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ }
+
/**
* Catches the value inserted in the JTextField, and tries to set it to
the initial object. If it can't, throws an
@@ -76,4 +90,31 @@
e.printStackTrace();
}
}
+
+ /**
+ * To get the item that is currently selected
+ */
+ public String getState() {
+ if ( textField == null )
+ return "";
+
+ final String text = textField.getText();
+ if ( text == null )
+ return "";
+
+ try {
+ return text;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return "";
+ }
+
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+
+ handle();
+ }
}
--
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.