Author: mmichaud
Date: 2009-05-29 07:19:49 -0700 (Fri, 29 May 2009)
New Revision: 16849
Added:
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/BoundedHandler.java
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/FlexiblyBoundedHandler.java
Log:
[]
Added:
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/BoundedHandler.java
===================================================================
---
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/BoundedHandler.java
2009-05-29 14:18:36 UTC (rev 16848)
+++
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/BoundedHandler.java
2009-05-29 14:19:49 UTC (rev 16849)
@@ -0,0 +1,76 @@
+package org.cytoscape.work.internal.tunables;
+
+import java.awt.BorderLayout;
+import java.awt.Font;
+import java.lang.reflect.*;
+import javax.swing.*;
+
+import org.cytoscape.work.Tunable;
+import org.cytoscape.work.Tunable.Param;
+import org.cytoscape.work.internal.tunables.utils.myBoundedSwing;
+import org.cytoscape.work.internal.tunables.utils.mySlider;
+import org.cytoscape.work.util.AbstractBounded;
+
+public class BoundedHandler<T extends AbstractBounded> extends
AbstractGuiHandler {
+
+
+ T bounded;
+ private String title;
+ private boolean useslider = false;
+ private mySlider slider;
+ private myBoundedSwing boundedField;
+
+ public BoundedHandler(Field f, Object o, Tunable t) {
+ super(f,o,t);
+ try {
+ this.bounded = (T)f.get(o);
+ } catch (IllegalAccessException iae) {
+ iae.printStackTrace();
+ }
+
+ this.title = t.description();
+ for ( Param s :
t.flag())if(s.equals(Param.slider))useslider=true;
+ panel = new JPanel(new BorderLayout());
+
+ try{
+ if(useslider){
+ JLabel label = new JLabel(title);
+ label.setFont(new Font(null, Font.PLAIN,12));
+ panel.add(label,BorderLayout.WEST);
+ slider = new mySlider(title,(Number)
bounded.getLowerBound(),(Number)bounded.getUpperBound(),(Number)bounded.getValue(),bounded.isLowerBoundStrict(),bounded.isUpperBoundStrict());
+ // Add ChangeListener????????
+ slider.addChangeListener(this);
+ panel.add(slider,BorderLayout.EAST);
+ }
+
+ else{
+ 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());
+ panel.add(label,BorderLayout.WEST);
+ panel.add(boundedField,BorderLayout.EAST);
+ }
+ }catch (Exception e) { e.printStackTrace(); }
+ }
+
+ public void handle() {
+ try{
+ if(useslider==true){
+
bounded.setValue(slider.getValue().doubleValue());
+ }
+ else{
+
bounded.setValue(boundedField.getFieldValue().doubleValue());
+ }
+ }catch (Exception e){e.printStackTrace();}
+ }
+
+ public String getState() {
+ return bounded.getValue().toString();
+ }
+
+ @Override
+ public void resetValue() {
+ // TODO Auto-generated method stub
+
+ }
+}
Added:
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/FlexiblyBoundedHandler.java
===================================================================
---
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/FlexiblyBoundedHandler.java
2009-05-29 14:18:36 UTC (rev 16848)
+++
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/FlexiblyBoundedHandler.java
2009-05-29 14:19:49 UTC (rev 16849)
@@ -0,0 +1,90 @@
+package org.cytoscape.work.internal.tunables;
+
+import java.lang.reflect.*;
+import javax.swing.*;
+
+import org.cytoscape.work.Tunable;
+import org.cytoscape.work.util.AbstractFlexiblyBounded;
+
+import java.awt.event.*;
+
+
+
+public class FlexiblyBoundedHandler<T extends AbstractFlexiblyBounded> extends
AbstractGuiHandler {
+
+ JTextField tf;
+ final T b;
+ final JLabel label;
+
+
+ public FlexiblyBoundedHandler(Field f, Object o, Tunable t) {
+ super(f,o,t);
+ T bb;
+ try {
+ bb = (T)f.get(o);
+ } catch (IllegalAccessException iae) {
+ iae.printStackTrace();
+ bb = null;
+ }
+
+ b = bb;
+
+ panel = new JPanel();
+
+ JButton up = new JButton( new SetAction("Set Upper
Bound",panel,false));
+ JButton low = new JButton( new SetAction("Set Lower
Bound",panel,true));
+
+ label = new JLabel();
+ setLabelText();
+ try {
+ panel.add( label );
+ tf = new JTextField( b.getValue().toString(), 6);
+ tf.addActionListener( this );
+ panel.add( tf );
+ panel.add(low);
+ panel.add(up);
+ } catch (Exception e) { e.printStackTrace(); }
+
+ }
+
+ private void setLabelText() {
+ label.setText( t.description() + " (min: " +
b.getLowerBound().toString() + " max: " + b.getUpperBound().toString() + ")" );
+ }
+
+ public void handle() {
+ String s = tf.getText();
+ try {
+ b.setValue(s);
+ } catch (Exception e) { e.printStackTrace(); }
+ }
+
+ public String getState() {
+ return b.getValue().toString();
+ }
+
+ private class SetAction extends AbstractAction {
+ JPanel par;
+ boolean low;
+ SetAction(String name,JPanel par,boolean low) {
+ super(name);
+ this.par = par;
+ this.low = low;
+ }
+ public void actionPerformed(ActionEvent ae) {
+ String value = JOptionPane.showInputDialog(par,"Enter
the new bound value:");
+ if ( value != null ) {
+ if ( low )
+ b.setLowerBound(value);
+ else
+ b.setUpperBound(value);
+
+ setLabelText();
+ }
+ }
+ }
+
+ public void resetValue() {
+ //need to be set
+ }
+
+}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---