Simple single-color 8x8x8 LED Cube with AVRs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. /*
  5. * cube.c
  6. *
  7. * Copyright 2011 Thomas Buck <xythobuz@me.com>
  8. * Copyright 2011 Max Nuding <max.nuding@gmail.com>
  9. * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
  10. *
  11. * This file is part of LED-Cube.
  12. *
  13. * LED-Cube is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * LED-Cube is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  25. */
  26. public class frame extends JFrame {
  27. // Anfang Variablen
  28. private Canvas cubeCanvas = new Canvas();
  29. private JButton editA = new JButton();
  30. private JButton editB = new JButton();
  31. private JButton editC = new JButton();
  32. private JButton editD = new JButton();
  33. private JButton editE = new JButton();
  34. private JButton editF = new JButton();
  35. private JButton editG = new JButton();
  36. private JButton editH = new JButton();
  37. private DefaultListModel frameListModel = new DefaultListModel();
  38. private JList frameList = new JList(frameListModel);
  39. private JButton frameUp = new JButton();
  40. private JButton frameDown = new JButton();
  41. private JButton frameAdd = new JButton();
  42. private JButton frameRemove = new JButton();
  43. private DefaultListModel animationListModel = new DefaultListModel();
  44. private JList jList2 = new JList(animationListModel);
  45. private JButton animUp = new JButton();
  46. private JButton animDown = new JButton();
  47. private JButton animAdd = new JButton();
  48. private JButton animRemove = new JButton();
  49. private JTextField animPath = new JTextField();
  50. private JButton load = new JButton();
  51. private JButton save = new JButton();
  52. private String[] jComboBox1Daten = {"Select serial port..."};
  53. private JComboBox jComboBox1 = new JComboBox(jComboBox1Daten);
  54. private JButton upload = new JButton();
  55. private JButton download = new JButton();
  56. private JLabel jLabel4 = new JLabel();
  57. private JTextField frameRemaining = new JTextField();
  58. private cubeWorker worker = new cubeWorker();
  59. // Ende Variablen
  60. private int saveExitDialog() {
  61. String[] Optionen = {"Yes", "No"};
  62. int Auswahl = JOptionPane.showOptionDialog(this, "Save?", "Yes/No", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Optionen, Optionen[0]);
  63. if (Auswahl == JOptionPane.YES_OPTION) {
  64. worker.saveState(animPath.getText());
  65. return 1;
  66. } else {
  67. return 0;
  68. }
  69. }
  70. public frame(String title) {
  71. // Frame-Initialisierung
  72. super(title);
  73. frameListModel.add(0, "Frame 1");
  74. frameListModel.add(1, "Frame 2");
  75. frameListModel.add(2, "Frame 3");
  76. animationListModel.add(0, "Animation 1");
  77. animationListModel.add(1, "Animation 2");
  78. animationListModel.add(2, "Animation 3");
  79. addWindowListener(new WindowAdapter() {
  80. public void windowClosing(WindowEvent evt) {
  81. if (worker.changedStateSinceSave()) {
  82. saveExitDialog();
  83. }
  84. System.exit(0);
  85. }
  86. });
  87. int frameWidth = 662;
  88. int frameHeight = 416;
  89. setSize(frameWidth, frameHeight);
  90. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  91. int x = (d.width - getSize().width) / 2;
  92. int y = (d.height - getSize().height) / 2 ;
  93. setLocation(x, y);
  94. Container cp = getContentPane();
  95. cp.setLayout(null);
  96. // Anfang Komponenten
  97. cubeCanvas.setBounds(8, 8, 250, 250);
  98. cubeCanvas.setBackground(Color.GRAY);
  99. cp.add(cubeCanvas);
  100. editA.setBounds(264, 8, 107, 25);
  101. editA.setText("Layer A");
  102. cp.add(editA);
  103. editA.addActionListener(new ActionListener() {
  104. public void actionPerformed(ActionEvent evt) {
  105. editAActionPerformed(evt);
  106. }
  107. });
  108. editB.setBounds(264, 40, 107, 25);
  109. editB.setText("Layer B");
  110. cp.add(editB);
  111. editB.addActionListener(new ActionListener() {
  112. public void actionPerformed(ActionEvent evt) {
  113. editBActionPerformed(evt);
  114. }
  115. });
  116. editC.setBounds(264, 72, 107, 25);
  117. editC.setText("Layer C");
  118. cp.add(editC);
  119. editC.addActionListener(new ActionListener() {
  120. public void actionPerformed(ActionEvent evt) {
  121. editCActionPerformed(evt);
  122. }
  123. });
  124. editD.setBounds(264, 104, 107, 25);
  125. editD.setText("Layer D");
  126. cp.add(editD);
  127. editD.addActionListener(new ActionListener() {
  128. public void actionPerformed(ActionEvent evt) {
  129. editDActionPerformed(evt);
  130. }
  131. });
  132. editE.setBounds(264, 136, 107, 25);
  133. editE.setText("Layer E");
  134. cp.add(editE);
  135. editE.addActionListener(new ActionListener() {
  136. public void actionPerformed(ActionEvent evt) {
  137. editEActionPerformed(evt);
  138. }
  139. });
  140. editF.setBounds(264, 168, 107, 25);
  141. editF.setText("Layer F");
  142. cp.add(editF);
  143. editF.addActionListener(new ActionListener() {
  144. public void actionPerformed(ActionEvent evt) {
  145. editFActionPerformed(evt);
  146. }
  147. });
  148. editG.setBounds(264, 200, 107, 25);
  149. editG.setText("Layer G");
  150. cp.add(editG);
  151. editG.addActionListener(new ActionListener() {
  152. public void actionPerformed(ActionEvent evt) {
  153. editGActionPerformed(evt);
  154. }
  155. });
  156. editH.setBounds(264, 232, 107, 25);
  157. editH.setText("Layer H");
  158. cp.add(editH);
  159. editH.addActionListener(new ActionListener() {
  160. public void actionPerformed(ActionEvent evt) {
  161. editHActionPerformed(evt);
  162. }
  163. });
  164. frameList.setBounds(384, 8, 145, 249);
  165. cp.add(frameList);
  166. frameUp.setBounds(544, 8, 107, 33);
  167. frameUp.setText("Move up");
  168. cp.add(frameUp);
  169. frameUp.addActionListener(new ActionListener() {
  170. public void actionPerformed(ActionEvent evt) {
  171. frameUpActionPerformed(evt);
  172. }
  173. });
  174. frameDown.setBounds(544, 152, 107, 33);
  175. frameDown.setText("Move down");
  176. cp.add(frameDown);
  177. frameDown.addActionListener(new ActionListener() {
  178. public void actionPerformed(ActionEvent evt) {
  179. frameDownActionPerformed(evt);
  180. }
  181. });
  182. frameAdd.setBounds(544, 56, 107, 33);
  183. frameAdd.setText("Add");
  184. cp.add(frameAdd);
  185. frameAdd.addActionListener(new ActionListener() {
  186. public void actionPerformed(ActionEvent evt) {
  187. frameAddActionPerformed(evt);
  188. }
  189. });
  190. frameRemove.setBounds(544, 104, 107, 33);
  191. frameRemove.setText("Remove");
  192. cp.add(frameRemove);
  193. frameRemove.addActionListener(new ActionListener() {
  194. public void actionPerformed(ActionEvent evt) {
  195. frameRemoveActionPerformed(evt);
  196. }
  197. });
  198. jList2.setBounds(8, 264, 209, 121);
  199. cp.add(jList2);
  200. animUp.setBounds(224, 264, 99, 25);
  201. animUp.setText("Move up");
  202. cp.add(animUp);
  203. animUp.addActionListener(new ActionListener() {
  204. public void actionPerformed(ActionEvent evt) {
  205. animUpActionPerformed(evt);
  206. }
  207. });
  208. animDown.setBounds(224, 360, 99, 25);
  209. animDown.setText("Move down");
  210. cp.add(animDown);
  211. animDown.addActionListener(new ActionListener() {
  212. public void actionPerformed(ActionEvent evt) {
  213. animDownActionPerformed(evt);
  214. }
  215. });
  216. animAdd.setBounds(224, 296, 99, 25);
  217. animAdd.setText("Add");
  218. cp.add(animAdd);
  219. animAdd.addActionListener(new ActionListener() {
  220. public void actionPerformed(ActionEvent evt) {
  221. animAddActionPerformed(evt);
  222. }
  223. });
  224. animRemove.setBounds(224, 328, 99, 25);
  225. animRemove.setText("Remove");
  226. cp.add(animRemove);
  227. animRemove.addActionListener(new ActionListener() {
  228. public void actionPerformed(ActionEvent evt) {
  229. animRemoveActionPerformed(evt);
  230. }
  231. });
  232. animPath.setBounds(344, 264, 305, 24);
  233. animPath.setEditable(false);
  234. animPath.setText("Load/Save an animation file...");
  235. cp.add(animPath);
  236. load.setBounds(344, 296, 147, 25);
  237. load.setText("Load");
  238. cp.add(load);
  239. load.addActionListener(new ActionListener() {
  240. public void actionPerformed(ActionEvent evt) {
  241. loadActionPerformed(evt);
  242. }
  243. });
  244. save.setBounds(504, 296, 147, 25);
  245. save.setText("Save");
  246. cp.add(save);
  247. save.addActionListener(new ActionListener() {
  248. public void actionPerformed(ActionEvent evt) {
  249. saveActionPerformed(evt);
  250. }
  251. });
  252. jComboBox1.setBounds(344, 328, 305, 24);
  253. cp.add(jComboBox1);
  254. upload.setBounds(344, 360, 147, 25);
  255. upload.setText("Upload");
  256. cp.add(upload);
  257. upload.addActionListener(new ActionListener() {
  258. public void actionPerformed(ActionEvent evt) {
  259. uploadActionPerformed(evt);
  260. }
  261. });
  262. download.setBounds(504, 360, 147, 25);
  263. download.setText("Download");
  264. cp.add(download);
  265. download.addActionListener(new ActionListener() {
  266. public void actionPerformed(ActionEvent evt) {
  267. downloadActionPerformed(evt);
  268. }
  269. });
  270. jLabel4.setBounds(536, 208, 111, 16);
  271. jLabel4.setText("Frames remaining:");
  272. jLabel4.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
  273. cp.add(jLabel4);
  274. frameRemaining.setBounds(536, 232, 113, 24);
  275. frameRemaining.setEditable(false);
  276. frameRemaining.setText("2048");
  277. cp.add(frameRemaining);
  278. // Ende Komponenten
  279. setResizable(false);
  280. setVisible(true);
  281. }
  282. // Anfang Ereignisprozeduren
  283. public void editAActionPerformed(ActionEvent evt) {
  284. }
  285. public void editBActionPerformed(ActionEvent evt) {
  286. }
  287. public void editCActionPerformed(ActionEvent evt) {
  288. }
  289. public void editDActionPerformed(ActionEvent evt) {
  290. }
  291. public void editEActionPerformed(ActionEvent evt) {
  292. }
  293. public void editFActionPerformed(ActionEvent evt) {
  294. }
  295. public void editGActionPerformed(ActionEvent evt) {
  296. }
  297. public void editHActionPerformed(ActionEvent evt) {
  298. }
  299. public void frameUpActionPerformed(ActionEvent evt) {
  300. int i = frameList.getSelectedIndex();
  301. if ((i > 0) && (frameListModel.getSize() >= 2)) {
  302. Object tmp = frameListModel.get(i);
  303. frameListModel.set(i, frameListModel.get(i - 1));
  304. frameListModel.set(i - 1, tmp);
  305. frameList.setSelectedIndex(i - 1);
  306. }
  307. }
  308. public void frameDownActionPerformed(ActionEvent evt) {
  309. int i = frameList.getSelectedIndex();
  310. if ((i >= 0) && (frameListModel.getSize() >= 2) && (i < (frameListModel.getSize() - 1))) {
  311. Object tmp = frameListModel.get(i);
  312. frameListModel.set(i, frameListModel.get(i + 1));
  313. frameListModel.set(i + 1, tmp);
  314. frameList.setSelectedIndex(i + 1);
  315. }
  316. }
  317. public void frameAddActionPerformed(ActionEvent evt) {
  318. }
  319. public void frameRemoveActionPerformed(ActionEvent evt) {
  320. }
  321. public void animUpActionPerformed(ActionEvent evt) {
  322. int i = jList2.getSelectedIndex();
  323. if ((i > 0) && (animationListModel.getSize() >= 2)) {
  324. Object tmp = animationListModel.get(i);
  325. animationListModel.set(i, animationListModel.get(i - 1));
  326. animationListModel.set(i - 1, tmp);
  327. jList2.setSelectedIndex(i - 1);
  328. }
  329. }
  330. public void animDownActionPerformed(ActionEvent evt) {
  331. int i = jList2.getSelectedIndex();
  332. if ((i >= 0) && (animationListModel.getSize() >= 2) && (i < (animationListModel.getSize() - 1))) {
  333. Object tmp = animationListModel.get(i);
  334. animationListModel.set(i, animationListModel.get(i + 1));
  335. animationListModel.set(i + 1, tmp);
  336. jList2.setSelectedIndex(i + 1);
  337. }
  338. }
  339. public void animAddActionPerformed(ActionEvent evt) {
  340. }
  341. public void animRemoveActionPerformed(ActionEvent evt) {
  342. }
  343. public void loadActionPerformed(ActionEvent evt) {
  344. }
  345. public void saveActionPerformed(ActionEvent evt) {
  346. }
  347. public void uploadActionPerformed(ActionEvent evt) {
  348. if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
  349. JOptionPane.showMessageDialog(this, "No serial port selected...");
  350. } else {
  351. worker.uploadState((String)jComboBox1.getSelectedItem());
  352. }
  353. }
  354. public void downloadActionPerformed(ActionEvent evt) {
  355. if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
  356. JOptionPane.showMessageDialog(this, "No serial port selected...");
  357. } else {
  358. worker.downloadState((String)jComboBox1.getSelectedItem());
  359. }
  360. }
  361. // Ende Ereignisprozeduren
  362. public static void main(String[] args) {
  363. new frame("Cube Control");
  364. }
  365. }