79 | *
80 | * Subclasses of OutputStream
must provide an
81 | *
82 | * implementation for this method.
83 | *
84 | *
85 | *
86 | * @param b
87 | * the byte
.
88 | *
89 | * @exception IOException
90 | * if an I/O error occurs.
91 | *
92 | * @since JDK1.0
93 | */
94 |
95 | public void write(int b) throws IOException {
96 | one[0] = (byte) b;
97 | write(one, 0, 1);
98 | }
99 |
100 | /**
101 | *
102 | * Writes len
bytes from the specified byte array
103 | *
104 | * starting at offset off
to this output stream.
105 | *
106 | *
107 | *
108 | * The write
method of OutputStream
calls
109 | *
110 | * the write method of one argument on each of the bytes to be
111 | *
112 | * written out. Subclasses are encouraged to override this method and
113 | *
114 | * provide a more efficient implementation.
115 | *
116 | *
117 | *
118 | * @param b
119 | * the data.
120 | *
121 | * @param off
122 | * the start offset in the data.
123 | *
124 | * @param len
125 | * the number of bytes to write.
126 | *
127 | * @exception IOException
128 | * if an I/O error occurs.
129 | *
130 | * @since JDK1.0
131 | */
132 |
133 | public void write(final byte b[], final int off, final int len)
134 | throws IOException {
135 | try {
136 | SwingUtilities.invokeAndWait(new Runnable() {
137 |
138 | @Override
139 | public void run() {
140 | try {
141 | doc.insertString(doc.getLength(), new String(b, off, len),
142 | a);
143 | } catch (BadLocationException ble) {
144 | throw new RuntimeException(ble);
145 | }
146 | }
147 | });
148 | } catch (InterruptedException e) {
149 | throw new IOException(e);
150 | } catch (InvocationTargetException e) {
151 | throw new IOException(e);
152 | }
153 |
154 | }
155 |
156 | protected byte[] one = new byte[1];
157 |
158 | protected Document doc;
159 |
160 | protected AttributeSet a;
161 |
162 | }
163 |
--------------------------------------------------------------------------------
/command-ui/src/main/java/xy/command/ui/util/FileUtils.java:
--------------------------------------------------------------------------------
1 | package xy.command.ui.util;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileOutputStream;
6 | import java.io.FilenameFilter;
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 |
10 | /**
11 | * Various utilities for dealing with files.
12 | *
13 | * @author olitank
14 | *
15 | */
16 | public class FileUtils {
17 |
18 | public static String read(File file) throws Exception {
19 | return new String(readBinary(file));
20 | }
21 |
22 | public static byte[] readBinary(File file) throws Exception {
23 | InputStream in = null;
24 | try {
25 | in = new FileInputStream(file);
26 | long length = file.length();
27 | byte[] bytes = new byte[(int) length];
28 | int offset = 0;
29 | int numRead = 0;
30 | while (offset < bytes.length && (numRead = in.read(bytes, offset, bytes.length - offset)) >= 0) {
31 | offset += numRead;
32 | }
33 | if (offset < bytes.length) {
34 | throw new IOException("Could not completely read file");
35 | }
36 | in.close();
37 | return bytes;
38 | } catch (IOException e) {
39 | throw new Exception("Unable to read file : '" + file.getAbsolutePath() + "': " + e.getMessage(), e);
40 | } finally {
41 | if (in != null) {
42 | try {
43 | in.close();
44 | } catch (IOException e) {
45 | }
46 | }
47 | }
48 | }
49 |
50 | public static void write(File file, String text, boolean append) throws Exception {
51 | writeBinary(file, text.getBytes(), append);
52 | }
53 |
54 | public static void writeBinary(File file, byte[] bytes, boolean append) throws Exception {
55 | FileOutputStream out = null;
56 | try {
57 | out = new FileOutputStream(file);
58 | out.write(bytes);
59 | out.flush();
60 | out.close();
61 | } catch (IOException e) {
62 | throw new Exception("Unable to write file : '" + file.getAbsolutePath() + "': " + e.getMessage(), e);
63 | } finally {
64 | if (out != null) {
65 | try {
66 | out.close();
67 | } catch (IOException e) {
68 | }
69 | }
70 | }
71 |
72 | }
73 |
74 | public static String removeFileNameExtension(String fileName) {
75 | String extension = getFileNameExtension(fileName);
76 | if (extension.length() > 0) {
77 | return fileName.substring(0, fileName.length() - ("." + extension).length());
78 | } else {
79 | return fileName;
80 | }
81 | }
82 |
83 | public static String getFileNameExtension(String fileName) {
84 | int lastDotIndex = fileName.lastIndexOf(".");
85 | if (lastDotIndex == -1) {
86 | return "";
87 | } else {
88 | return fileName.substring(lastDotIndex + 1);
89 | }
90 | }
91 |
92 | public static void copy(File src, File dst) throws Exception {
93 | copy(src, dst, true);
94 | }
95 |
96 | public static void copy(File src, File dst, boolean recusrsively) throws Exception {
97 | copy(src, dst, recusrsively, null);
98 | }
99 |
100 | public static void copy(File src, File dst, boolean recusrsively, FilenameFilter filenameFilter) throws Exception {
101 | try {
102 | if (src.isDirectory()) {
103 | mkDir(dst);
104 | if (recusrsively) {
105 | for (File srcChild : src.listFiles(filenameFilter)) {
106 | copy(srcChild, new File(dst, srcChild.getName()), recusrsively, filenameFilter);
107 | }
108 | }
109 | } else if (src.isFile()) {
110 | writeBinary(dst, readBinary(src), false);
111 | } else {
112 | throw new Exception("File not found: '" + src + "'", null);
113 | }
114 | } catch (Exception e) {
115 | throw new Exception("Unable to copy resource: '" + src.getAbsolutePath() + "' > '" + dst.getAbsolutePath()
116 | + "': " + e.getMessage(), e);
117 | }
118 | }
119 |
120 | public static void mkDir(File dir) throws Exception {
121 | if (dir.isDirectory()) {
122 | return;
123 | }
124 | final boolean success;
125 | try {
126 | success = dir.mkdir();
127 | } catch (Exception e) {
128 | throw new Exception("Failed to create directory: '" + dir.getAbsolutePath() + "': " + e.getMessage(), e);
129 | }
130 | if (!success) {
131 | throw new Exception("Unable to create directory: '" + dir.getAbsolutePath() + "'", null);
132 | }
133 | }
134 |
135 | public static String getRelativePath(File child, File ancestor) {
136 | if (!FileUtils.isAncestor(ancestor, child)) {
137 | return null;
138 | }
139 | try {
140 | return child.getCanonicalPath().substring(ancestor.getCanonicalPath().length() + 1);
141 | } catch (IOException e) {
142 | throw new RuntimeException(e);
143 | }
144 | }
145 |
146 | public static boolean canonicallyEquals(File file1, File file2) {
147 | try {
148 | return file1.getCanonicalFile().equals(file2.getCanonicalFile());
149 | } catch (IOException e) {
150 | throw new RuntimeException(e.toString(), e);
151 | }
152 | }
153 |
154 | public static File getCanonicalParent(File file) {
155 | try {
156 | return file.getCanonicalFile().getParentFile();
157 | } catch (IOException e) {
158 | throw new RuntimeException(e);
159 | }
160 | }
161 |
162 | public static void delete(File file) throws Exception {
163 | delete(file, null);
164 | }
165 |
166 | public static void delete(File file, final FilenameFilter filter) throws Exception {
167 | if (file.isDirectory()) {
168 | CountingFilenameFilter countingFilter = (filter != null) ? new CountingFilenameFilter(filter) : null;
169 | for (File childFile : file.listFiles(countingFilter)) {
170 | delete(childFile, countingFilter);
171 | }
172 | if ((countingFilter != null) && countingFilter.getFilteredCount() > 0) {
173 | return;
174 | }
175 | }
176 | boolean success;
177 | try {
178 | success = file.delete();
179 | } catch (Exception e) {
180 | throw new Exception("Failed to delete resource: '" + file.getAbsolutePath() + "'" + e.getMessage(), e);
181 | }
182 | if (!success) {
183 | throw new Exception("Unable to delete resource: '" + file.getAbsolutePath() + "'", null);
184 | }
185 | }
186 |
187 | public static void rename(File file, String destFileName) throws Exception {
188 | try {
189 | if (new File(destFileName).getParent() != null) {
190 | throw new Exception("Destination file name is not is not a local name: '" + destFileName + "'");
191 | }
192 | File destFile = new File(file.getParent(), destFileName);
193 | boolean success = file.renameTo(destFile);
194 | if (!success) {
195 | throw new Exception("System error");
196 | }
197 | } catch (Exception e) {
198 | throw new Exception("Failed to rename resource: '" + file.getAbsolutePath() + "' to '" + destFileName
199 | + "': " + e.getMessage(), e);
200 | }
201 | }
202 |
203 | public static boolean hasFileNameExtension(String fileName, String[] extensions) {
204 | for (String ext : extensions) {
205 | if (ext.toLowerCase().equals(getFileNameExtension(fileName).toLowerCase())) {
206 | return true;
207 | }
208 | }
209 | return false;
210 | }
211 |
212 | public static boolean isAncestor(File ancestor, File file) {
213 | File mayBeAncestor = getCanonicalParent(file);
214 | while (true) {
215 | if (mayBeAncestor == null) {
216 | return false;
217 | }
218 | if (canonicallyEquals(mayBeAncestor, ancestor)) {
219 | return true;
220 | }
221 | mayBeAncestor = getCanonicalParent(mayBeAncestor);
222 | }
223 | }
224 |
225 | }
226 |
--------------------------------------------------------------------------------
/command-ui/src/main/java/xy/command/ui/util/ValidationError.java:
--------------------------------------------------------------------------------
1 | package xy.command.ui.util;
2 |
3 | /**
4 | * Error thrown when a command line model is not valid.
5 | *
6 | * @author olitank
7 | *
8 | */
9 | public class ValidationError extends Exception {
10 |
11 | protected static final long serialVersionUID = 1L;
12 |
13 | public ValidationError() {
14 | super();
15 | }
16 |
17 | public ValidationError(String message, Throwable cause) {
18 | super(message, cause);
19 | }
20 |
21 | public ValidationError(String message) {
22 | super(message);
23 | }
24 |
25 | public ValidationError(Throwable cause) {
26 | super(cause);
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return super.getMessage();
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/ArgumentGroup.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/ArgumentGroup.gif
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/ArgumentPage.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/ArgumentPage.gif
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/Choice.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/Choice.gif
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/CommandLine.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/CommandLine.gif
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/DirectoryArgument.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/DirectoryArgument.gif
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/FileArgument.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/FileArgument.gif
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/FixedArgument.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/FixedArgument.gif
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/InputArgument.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/InputArgument.gif
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/MultiplePart.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/MultiplePart.gif
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/OptionalPart.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/OptionalPart.gif
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/banner.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/banner.jpg
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/baseFont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/baseFont.ttf
--------------------------------------------------------------------------------
/command-ui/src/main/resources/xy/command/ui/resource/buttonBackground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotxyteam/CommandUI/18861730d94d150cb61ed16e371576c0a71d6bf2/command-ui/src/main/resources/xy/command/ui/resource/buttonBackground.png
--------------------------------------------------------------------------------
/command-ui/src/test/java/xy/command/ui/TestWithAutomation.java:
--------------------------------------------------------------------------------
1 | package xy.command.ui;
2 |
3 | import java.io.File;
4 | import java.nio.file.Files;
5 |
6 | import org.junit.BeforeClass;
7 | import org.junit.Test;
8 |
9 | import xy.reflect.ui.undo.ModificationStack;
10 | import xy.reflect.ui.util.MiscUtils;
11 | import xy.reflect.ui.util.MoreSystemProperties;
12 | import xy.ui.testing.Tester;
13 | import xy.ui.testing.util.TestingUtils;
14 |
15 | public class TestWithAutomation {
16 |
17 | Tester tester = new Tester();
18 |
19 | protected static void checkSystemProperty(String key, String expectedValue) {
20 | String value = System.getProperty(key);
21 | if (!MiscUtils.equalsOrBothNull(expectedValue, value)) {
22 | String errorMsg = "System property invalid value:\n" + "-D" + key + "=" + value + "\nExpected:\n" + "-D"
23 | + key + "=" + expectedValue;
24 | System.err.println(errorMsg);
25 | throw new AssertionError(errorMsg);
26 |
27 | }
28 | }
29 |
30 | public static void setupTestEnvironment() {
31 | checkSystemProperty(MoreSystemProperties.DEBUG, "true");
32 | }
33 |
34 | @BeforeClass
35 | public static void beforeAllTests() {
36 | setupTestEnvironment();
37 | TestingUtils.purgeAllReportsDirectory();
38 | }
39 |
40 | @Test
41 | public void test() throws Exception {
42 | File comanndLineSpecFile = new File("test.cml");
43 | if (comanndLineSpecFile.exists()) {
44 | Files.delete(comanndLineSpecFile.toPath());
45 | }
46 | System.setProperty(ModificationStack.DEFAULT_CAPACITY_PROPERTY_KEY, "100");
47 | try {
48 | TestingUtils.assertSuccessfulReplay(tester, new File(
49 | System.getProperty("command-ui.project.directory", "./") + "test-specifications/test.stt"));
50 | } finally {
51 | Files.delete(comanndLineSpecFile.toPath());
52 | }
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/command-ui/todo.txt:
--------------------------------------------------------------------------------
1 | - get new exe icon
2 | - set part types icons
3 | - Allow to parse command syntax???
4 | . Into clipboard??? In a new argument group??? Allow to choose
5 | - �fixed args only� optionalArg must be represented by a simple checkbox
6 | - Save/load settings option for instances
7 | - Display successful validation
8 | - Validation error for
9 | . Empty optionalArg, MultipleArg, choice, argument group
10 |
11 | For reflectionUI
12 | - List copy problem: modification of original modifies the copy and vice-versa
13 | - Undo tooltip empty
14 | - ListControl �Paste� must be before �Paste Before/After�
15 |
16 |
17 | - check parameter values not empty
18 | - allow to save player state
19 | - Context menu needed
20 | - command icon arg
21 | - add group layout???
22 | - remove group label and add labelPart
23 | - use env path
24 | - change theme
25 | - make player themable
26 |
--------------------------------------------------------------------------------