import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
//import ij.plugin.frame.*;
import ij.*;
import ij.process.*;
//import ij.plugin.*;
//import ij.gui.*;
//import ij.measure.ResultsTable;
//import ij.ImageStack.*;
//import ij.IJ;
//import ij.io.Opener;
//import ij.io.*;
public class U_I extends JFrame implements ChangeListener {
public static void main(String[] args) {
U_I frame = new U_I();
//frame.addMouseListener(frame);
//frame.setSize(800, 600);
//frame.pack();
//frame.setVisible(true);
}
JLabel instruction;
public JSlider pickNum;
JButton RunExpt;
JLabel description;
JButton PlotResults;
//ChangeListener pickNumChangeListener;
static public int PickNumValue;
int value;
public static String s;
public U_I() {
super("Slider");
setSize(800, 600);
setLocationRelativeTo(null);
Container pane = getContentPane();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
pane.setLayout(gridbag);
////////////////////////////////////////////////////////////////////
//JPanel for slider and associated label
//Slider Label
JLabel instruction = new JLabel("<html><div style=\"text-align: "
+ "center;\"> <b>Choose a treatment </b></html>");
instruction.setFont(new Font("sansserif", Font.BOLD, 15));
//////////////////
constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 3;
constraints.gridheight = 2;
constraints.weightx = 0.42;
constraints.weighty = 0.14;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(40,100,0,0);
constraints.ipadx = 0;
constraints.ipady = 0;
//constraints.insets = new Insets(20,20,20,20);
gridbag.setConstraints(instruction, constraints);
add(instruction);
//Slider
JSlider pickNum = new JSlider(JSlider.HORIZONTAL, 0, 40, 5);
pickNum.setMajorTickSpacing(10);
pickNum.setMinorTickSpacing(5);
pickNum.setPaintTicks(true);
pickNum.setPaintLabels(true);
pickNum.setSnapToTicks(true);
pickNum.setPreferredSize(new Dimension(400,210));
pickNum.setFont(new Font("sansserif", Font.BOLD, 15));
//Register listener for slider
//pickNumChangeListenerClass pickNumChangeListener =
//new pickNumChangeListenerClass();
pickNum.addChangeListener(this);
//String myString = "";
//myString = Integer.toString(PickNumValue);
//System.out.println(myString);
// above converts the Slider int value to a string to allow print
// for testing (not required for function)!
//////////////////
constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 3;
constraints.gridheight = 2;
constraints.weightx = 0.42;
constraints.weighty = 0.14;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(35,30,0,0);
constraints.ipadx = 0;
constraints.ipady = 0;
//constraints.insets = new Insets(20,20,20,20);
gridbag.setConstraints(pickNum, constraints);
add(pickNum);
////////////////////////////////////////////////////////////////////
//Run Expt Button
ImageIcon play = new ImageIcon
("/Users/otills/Code/Symbols/Play_small.gif");
JButton RunExpt = new JButton("Run Experiment", play );
RunExpt.setPreferredSize(new Dimension(190,100));
RunExpt.setFont(new Font("sansserif", Font.BOLD, 15));
RunExptListenerClass RunExptlistener = new RunExptListenerClass();
RunExpt.addActionListener(RunExptlistener);
constraints = new GridBagConstraints();
constraints.gridx = 8;
constraints.gridy = 1;
constraints.gridwidth = 4;
constraints.gridheight = 2;
constraints.weightx = 0.33;
constraints.weighty = 0.18;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(20,0,0,0);
constraints.ipadx = 0;
constraints.ipady = 0;
//constraints.insets = new Insets(20,20,20,20);
gridbag.setConstraints(RunExpt, constraints);
add(RunExpt);
////////////////////////////////////////////////////////////////////
// Graphic
JLabel description = new JLabel();
description.setIcon(new javax.swing.ImageIcon
("/Users/otills/Desktop/demovirtualexpt.jpg"));
constraints = new GridBagConstraints();
constraints.gridx = 1;
constraints.gridy = 4;
constraints.gridwidth = 6;
constraints.gridheight = 4;
constraints.weightx = 0.42;
constraints.weighty = 0.5;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(0,50,0,0);
constraints.ipadx = 0;
constraints.ipady = 0;
//constraints.insets = new Insets(20,20,20,20);
gridbag.setConstraints(description, constraints);
add(description);
////////////////////////////////////////////////////////////////////
//Plot Results Button
ImageIcon graph = new ImageIcon
("/Users/otills/JavaTest/src/Graph_icon.gif");
JButton PlotResults = new JButton("Plot Results", graph);
PlotResults.setPreferredSize(new Dimension(190,100));
PlotResults.setFont(new Font("sansserif", Font.BOLD, 15));
//PlotResults.addActionListener(this);
constraints = new GridBagConstraints();
PlotResultsListenerClass PlotListener = new PlotResultsListenerClass();
PlotResults.addActionListener(PlotListener);
constraints.gridx = 9;
constraints.gridy = 8;
constraints.gridwidth = 3;
constraints.gridheight = 2;
constraints.weightx = 0.25;
constraints.weighty = 0.18;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(0,0,10,0);
constraints.ipadx = 0;
constraints.ipady = 0;
//constraints.insets = new Insets(20,20,20,20);
gridbag.setConstraints(PlotResults, constraints);
add(PlotResults);
//PlotResults.addActionListener(this);
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
setVisible(true);
}
//public void stateChanged(ChangeEvent e) {
//JSlider source = (JSlider)e.getSource();
//if (!source.getValueIsAdjusting()) {
//PickNumValue = (int)source.getValue();
//U_I.getvalue(pickNum)
//System.out.println(PickNumValue);
//}}
//if (PickNumValue < 20) {
//System.out.println(PickNumValue);
//} else
//{ IJ.runMacroFile("/Users/otills/Desktop/SequenceOne.txt");}
//}
//}
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider)e.getSource();
if (source.getValueIsAdjusting() !=true) {
PickNumValue = source.getValue();
String s = Integer.toString(PickNumValue);
System.out.println(s);
}
}
}
class RunExptListenerClass implements ActionListener {
public void actionPerformed(ActionEvent e) {
if ((U_I.PickNumValue >= 10) && (U_I.PickNumValue <= 20)) {
Analyse_ analysebar = new Analyse_();
analysebar.setVisible(true);
// AddPickNumColumn();
// Data.tableModel.addColumn();
// Data AddPickNumColumn = new PickNumColumn();
// AddPickNumColumn
// tableModel.addColumn(U_I.s);
// tableModel.fireTableStructureChanged();
// tableModel.AddPickNumColumn();
//IJ.run("Image Sequence...", "open=[/Users/otills/Desktop/"
// + "Two] number=5 starting=1 increment=1 "
// + "scale=100 file=[] or=[] sort use");
//String directory = IJ.getDirectory("Select a Directory");
//imp.show();
//ImageStack.create(width, height, 3, 8);
//ImageStack nf = ij.ImageStack.create(130, 133, n, n);
//ImagePlus myImPlus = WindowManager.getCurrentImage();
// int myStackLength = 200;
//Opener opener = new Opener();
//ImagePlus imp = opener.openImage("/Users/otills/Desktop/Daniotest/img_000000000_Sequence_000.tif");
//ImageProcessor currIP = imp.getProcessor();
//ImageStack myStack = new ImageStack(currIP.getWidth(), currIP.getHeight());
// for (int SliceNo = 1; SliceNo <= myStackLength; SliceNo++)
// {
// myStack.addSlice("Slice"+SliceNo, currIP);
// }
//ImagePlus myTargetImPlus = new ImagePlus("Stack of "+imp.getTitle(), currIP);
//The .getTitle() method, recuperates the title of the image.
//myTargetImPlus.show();
//myTargetImPlus.setStack(null, myStack);
}
//imp.createEmptyStack(800,600);
//imp.show();
//ImagePlus imp = IJ.openImage("/Users/otills/Desktop/Two");
//imp.show();
else if (U_I.PickNumValue < 10) {
System.out.println("less than 10");
Analyse_ analysebar = new Analyse_();
analysebar.setVisible(true);
// IJ.run("Image Sequence...", "open=[/Users/otills/Desktop/"
// + "One] number=5 starting=1 increment=1 "
// + "scale=100 file=[] or=[] sort use");
}
else if (U_I.PickNumValue > 20) {
System.out.println("greater than 20");
}
}
}
//System.out.println(s);
//if (U_I.PickNumValue <20){
//IJ.runMacroFile("/Users/otills/Desktop/SequenceOne.txt");
//}
//else if (U_I.PickNumValue > 20){
//IJ.runMacroFile("/Users/otills/Desktop/SequenceTwo.txt");
//System.out.println("PickNumValue.U_I");
//}
//PickNumValue.UI = UI.getDeclaredField("PickNumValue");
class PlotResultsListenerClass implements ActionListener {
public void actionPerformed(ActionEvent e) {
IJ.runMacroFile("/Users/otills/Desktop/SequenceTwo.txt");
IJ.run("Table...", "name=Table width=350 height=450");
//IJ.ImageWindow.setLocationRelativeTo(null);
//ImageWindow.getWindows();
// new.DataTable.Data();
//Tablemodel datamodel = new AbstractTableModel() {
};
}
//}
class DataTable{
public JTable Data;
}
//pickNum.addChangeListener(new ChangeListener() {
// public void stateChanged(ChangeEvent e) {
// JSlider source = (JSlider)e.getSource();
// if (!source.getValueIsAdjusting()) {
// PickNumValue = source.getValue();
// }
// }
// });