comparison SMART/Java/Program.java @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
children
comparison
equal deleted inserted replaced
5:ea3082881bf8 6:769e306b7933
1 /**
2 *
3 * Copyright INRA-URGI 2009-2010
4 *
5 * This software is governed by the CeCILL license under French law and
6 * abiding by the rules of distribution of free software. You can use,
7 * modify and/ or redistribute the software under the terms of the CeCILL
8 * license as circulated by CEA, CNRS and INRIA at the following URL
9 * "http://www.cecill.info".
10 *
11 * As a counterpart to the access to the source code and rights to copy,
12 * modify and redistribute granted by the license, users are provided only
13 * with a limited warranty and the software's author, the holder of the
14 * economic rights, and the successive licensors have only limited
15 * liability.
16 *
17 * In this respect, the user's attention is drawn to the risks associated
18 * with loading, using, modifying and/or developing or reproducing the
19 * software by the user in light of its specific status of free software,
20 * that may mean that it is complicated to manipulate, and that also
21 * therefore means that it is reserved for developers and experienced
22 * professionals having in-depth computer knowledge. Users are therefore
23 * encouraged to load and test the software's suitability as regards their
24 * requirements in conditions enabling the security of their systems and/or
25 * data to be ensured and, more generally, to use and operate it in the
26 * same conditions as regards security.
27 *
28 * The fact that you are presently reading this means that you have had
29 * knowledge of the CeCILL license and that you accept its terms.
30 *
31 */
32 import java.util.*;
33 import java.awt.*;
34 import javax.swing.*;
35
36
37 public class Program {
38 String shortName;
39 String name;
40 String section;
41 String description;
42 Vector <ProgramOption> options;
43 JPanel panel;
44 JButton button;
45
46
47 public Program() {
48 this.shortName = null;
49 this.name = null;
50 this.options = new Vector <ProgramOption> ();
51 }
52
53
54 public void setShortName(String shortName) {
55 this.shortName = shortName;
56 }
57
58
59 public void setName(String name) {
60 this.name = name;
61 }
62
63
64 public void setSection(String section) {
65 this.section = section;
66 }
67
68 public void setDescription(String description) {
69 this.description = description;
70 }
71
72
73 public void addOption(ProgramOption option) {
74 options.add(option);
75 }
76
77
78 public String getShortName() {
79 return this.shortName;
80 }
81
82
83 public String getName() {
84 return this.name;
85 }
86
87
88 public String getSection() {
89 return this.section;
90 }
91
92 public String getDescription() {
93 return this.description;
94 }
95
96
97 public String checkValues() {
98 for (int i = 0; i < options.size(); i++) {
99 String comment = options.get(i).checkValue();
100 if (comment != null) {
101 return comment;
102 }
103 }
104 return null;
105 }
106
107
108 public LinkedList<String> getCommand() {
109 LinkedList<String> parameterList = new LinkedList<String>();
110 parameterList.add(Global.pythonCommand);
111 parameterList.add("Python" + java.io.File.separator + this.shortName);
112 for (int i = 0; i < options.size(); i++) {
113 ProgramOption option = options.get(i);
114 parameterList.addAll(option.getCommand());
115 }
116 return parameterList;
117 }
118
119
120 public JPanel getPanel() {
121 if (this.panel != null) {
122 return this.panel;
123 }
124
125 this.panel = new JPanel(false);
126 this.panel.setLayout(new FlowLayout());
127 Box box = Box.createVerticalBox();
128
129 JPanel descriptionPanel = new JPanel(false);
130 JLabel descriptionLabel = new JLabel(this.description);
131 descriptionPanel.add(descriptionLabel);
132 box.add(descriptionPanel);
133
134 for (int i = 0; i < options.size(); i++) {
135 ProgramOption option = options.get(i);
136 JPanel panel = option.getPanel();
137 if (panel == null) {
138 System.out.println("Problem with Python program '" + this.shortName + "'.");
139 return null;
140 }
141 box.add(option.getPanel());
142 }
143
144 JPanel buttonPanel = new JPanel(false);
145 this.button = new JButton("GO!");
146
147 buttonPanel.add(button);
148
149 box.add(buttonPanel);
150
151 this.panel.add(box);
152
153 return this.panel;
154 }
155
156
157 public JButton getButton() {
158 if (this.button == null) {
159 this.getPanel();
160 }
161 return this.button;
162 }
163
164
165 public Vector < File > getOutputFiles() {
166 Vector < File > files = new Vector < File > ();
167 for (int i = 0; i < options.size(); i++) {
168 ProgramOption option = options.get(i);
169 if (! option.isInput()) {
170 files.add(option.getOutputFile());
171 }
172 }
173 return files;
174 }
175 }