1 /********************************************************************
2 *
3 *  This library is free software; you can redistribute it and/or
4 *  modify it under the terms of the GNU Library General Public
5 *  License as published by the Free Software Foundation; either
6 *  version 2 of the License, or (at your option) any later version.
7 *
8 *  This library is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 *  Library General Public License for more details.
12 *
13 *  You should have received a copy of the GNU Library General Public
14 *  License along with this library; if not, write to the
15 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 *  Boston, MA  02111-1307, USA.
17 *
18 *  @author: Copyright (C) Tim Carver
19 *
20 ********************************************************************/
21 
22 
23 package org.emboss.jemboss.draw;
24 
25 import javax.swing.*;
26 import java.awt.BorderLayout;
27 import java.awt.Dimension;
28 import java.util.Vector;
29 import java.util.Hashtable;
30 import org.emboss.jemboss.gui.ScrollPanel;
31 
32 
33 /**
34 *
35 * DNA draw wizard
36 *
37 */
38 public class Wizard
39 {
40 
41   private DNADraw dna = null;
42 
Wizard(DNADraw dna_current)43   public Wizard(DNADraw dna_current)
44   {
45     int n = getOption(dna_current);  // option 0 - read data file
46                                      // option 1 - create dna display
47                                      // option 2 - edit existing dna
48     if(n == 0)
49     {
50       //Vector restrictionEnzyme = new Vector();
51       EmbossCirdnaReader dnaRead = new EmbossCirdnaReader();
52 
53       Hashtable lineAttr = new Hashtable();
54       lineAttr.put("lsize",new Integer(5));
55       lineAttr.put("circular",new Boolean(true));
56       lineAttr.put("start",new Integer(dnaRead.getStart()));
57       lineAttr.put("end",new Integer(dnaRead.getEnd()));
58 
59       dna = new DNADraw(dnaRead.getBlock(),
60                         dnaRead.getRestrictionEnzyme(),
61                         lineAttr,0,100,100);
62     }
63     else if(n == 1 || n == 2)
64     {
65       JFrame f = new JFrame("Genetic Feature");
66 
67       Vector block = new Vector();
68       Vector restrictionEnzyme = new Vector();
69       if(dna_current == null)
70         dna = new DNADraw();
71       else
72       {
73         dna = dna_current;
74         block = dna_current.getGeneticMarker();
75         restrictionEnzyme = dna_current.getRestrictionEnzyme();
76       }
77 
78       LineAttribute la = new LineAttribute(dna);
79 
80       GeneticMarker gm;
81       if(dna_current != null)
82         gm = new GeneticMarker(dna_current,block);
83       else
84         gm = new GeneticMarker(dna,block);
85 
86       RestrictionEnzyme re;
87       if(dna_current != null)
88         re = new RestrictionEnzyme(dna_current,restrictionEnzyme);
89       else
90         re = new RestrictionEnzyme(dna,restrictionEnzyme);
91 
92       Ticks tk = new Ticks(dna_current,false);
93 
94       la.setMinimumSize(la.getPreferredSize());
95       la.setMaximumSize(la.getPreferredSize());
96 
97       re.setMinimumSize(re.getPreferredSize());
98       re.setMaximumSize(re.getPreferredSize());
99 
100       ScrollPanel pane = new ScrollPanel(new BorderLayout());
101       Box bdown = Box.createVerticalBox();
102       bdown.add(new JLabel("DNA Attributes"));
103       Box bacross = Box.createHorizontalBox();
104       bacross.add(la);
105       bacross.add(tk);
106       bacross.add(Box.createHorizontalGlue());
107       bdown.add(bacross);
108 
109       bdown.add(Box.createHorizontalStrut(10));
110       bdown.add(new JLabel("Genetic Feature"));
111       bacross = Box.createHorizontalBox();
112       bacross.add(gm);
113       bacross.add(Box.createHorizontalGlue());
114       bdown.add(bacross);
115 
116       bdown.add(Box.createHorizontalStrut(10));
117       bdown.add(new JLabel("Restriction Enzymes"));
118       bacross = Box.createHorizontalBox();
119       bacross.add(re);
120       bacross.add(Box.createHorizontalGlue());
121       bdown.add(bacross);
122       pane.add(bdown,BorderLayout.CENTER);
123 
124       JScrollPane createWizScroll = new JScrollPane(pane);
125 
126       Dimension dscreen = f.getToolkit().getScreenSize();
127       int wid = (int)dscreen.getWidth();
128       if(wid > 700)
129         wid = 700;
130 
131       int hgt = (int)dscreen.getHeight();
132       if(hgt > 750)
133         hgt = 700;
134       hgt-=50;
135 
136       Dimension d = new Dimension(wid,hgt);
137       createWizScroll.setPreferredSize(d);
138 
139       JOptionPane.showMessageDialog(null,
140                       createWizScroll, "DNA Wizard",
141                       JOptionPane.PLAIN_MESSAGE);
142 
143       dna.setGeneticMarker(block);
144       dna.setRestrictionEnzyme(restrictionEnzyme);
145       dna.setLineAttributes(la.getLineAttr());
146       dna.setStartTick(tk.getStartTick());
147       dna.setMinorTickInterval(tk.getMinorTickInterval());
148       dna.setTickInterval(tk.getTickInterval());
149 
150       int s = la.getStart();
151       dna.setStart(s);
152 
153       s = la.getEnd();
154       dna.setEnd(s);
155 
156     }
157   }
158 
159 
getDNADraw()160   public DNADraw getDNADraw()
161   {
162     return dna;
163   }
164 
165 
getOption(DNADraw dna_current)166   private int getOption(DNADraw dna_current)
167   {
168     Box bdown = Box.createVerticalBox();
169 
170     JRadioButton[] radioButtons;
171 
172     if(dna_current !=  null)
173       radioButtons = new JRadioButton[3];
174     else
175       radioButtons = new JRadioButton[2];
176     final ButtonGroup group = new ButtonGroup();
177     radioButtons[0] = new JRadioButton("Read in data file");
178     group.add(radioButtons[0]);
179     radioButtons[1] = new JRadioButton("Create new dna display");
180     group.add(radioButtons[1]);
181     radioButtons[1].setSelected(true);
182     bdown.add(radioButtons[0]);
183     bdown.add(radioButtons[1]);
184 
185     if(dna_current !=  null)
186     {
187       radioButtons[2] = new JRadioButton("Edit current dna display");
188       group.add(radioButtons[2]);
189       radioButtons[2].setSelected(true);
190       bdown.add(radioButtons[2]);
191     }
192 
193     JPanel pane = new JPanel(new BorderLayout());
194     pane.add(bdown);
195     JOptionPane.showMessageDialog(null,
196                       pane, "Jemboss DNA Viewer Wizard",
197                       JOptionPane.QUESTION_MESSAGE);
198 
199     if(radioButtons[0].isSelected())
200       return 0;
201     else if(radioButtons[1].isSelected())
202       return 1;
203     else if(radioButtons[2].isSelected())
204       return 2;
205 
206     return 1;
207   }
208 
209 }
210 
211