Simple single-color 8x8x8 LED Cube with AVRs
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

layerEditFrame.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * layerEditFrame.java
  3. *
  4. *
  5. * Copyright 2011 Thomas Buck <xythobuz@me.com>
  6. * Copyright 2011 Max Nuding <max.nuding@gmail.com>
  7. * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
  8. *
  9. * This file is part of LED-Cube.
  10. *
  11. * LED-Cube is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * LED-Cube is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. import java.awt.*;
  25. import java.awt.event.*;
  26. import javax.swing.*;
  27. import javax.swing.event.*;
  28. public class layerEditFrame extends JFrame {
  29. // Anfang Attribute
  30. private JPanel panelLED1 = new JPanel(null, true);
  31. JButton[][] ledPanels = new JButton[8][8];
  32. ImageIcon on = new ImageIcon(getClass().getResource("LEDon.png"));
  33. ImageIcon off = new ImageIcon(getClass().getResource("LEDoff.png"));
  34. byte[][] ledStatus = new byte[8][8];
  35. boolean changedStateSinceSave = false;
  36. short[] frame;
  37. int li;
  38. boolean finish = false;
  39. cubeWorker worker = null;
  40. int animI;
  41. int frameI;
  42. Frame LedFrame;
  43. // Ende Attribute
  44. public layerEditFrame(int animIndex, int frameIndex, int layerIndex, cubeWorker work, Frame LEDframe) {
  45. // Frame-Initialisierung
  46. super("Layer Edit");
  47. worker = work;
  48. LedFrame = LEDframe;
  49. animI = animIndex;
  50. frameI = frameIndex;
  51. //frame = byteToShortArray(worker.getFrame(animIndex, frameIndex));
  52. frame = worker.getFrame(animIndex, frameIndex);
  53. li = layerIndex;
  54. setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  55. int frameWidth = 180;
  56. int frameHeight = 230;
  57. setSize(frameWidth, frameHeight);
  58. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  59. int x = (d.width - getSize().width) / 2;
  60. int y = (d.height - getSize().height) / 2;
  61. setLocation(x, y);
  62. setResizable(false);
  63. Container cp = getContentPane();
  64. cp.setLayout(null);
  65. for(int i = 0; i < 8; i++){
  66. for(int j = 0; j < 8; j++){
  67. final int finalI = i;
  68. final int finalJ = j;
  69. ledPanels[i][j] = new JButton(on);
  70. ledPanels[i][j].setBounds((i*20)+5, (j*20)+5, 15, 15);
  71. ledPanels[i][j].addActionListener(new ActionListener() {
  72. public void actionPerformed(ActionEvent evt) {
  73. btnClicked(finalI, finalJ);
  74. }
  75. });
  76. ledPanels[i][j].setVisible(true);
  77. cp.add(ledPanels[i][j]);
  78. }
  79. }
  80. loadData();
  81. JButton saveBtn = new JButton("Save");
  82. JButton cancelBtn = new JButton("Cancel");
  83. saveBtn.setBounds(5, 170, 70, 25);
  84. saveBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
  85. cp.add(saveBtn);
  86. cancelBtn.setBounds(80, 170, 80, 25);
  87. cancelBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
  88. cp.add(cancelBtn);
  89. setVisible(true);
  90. saveBtn.addActionListener(new ActionListener() {
  91. public void actionPerformed(ActionEvent evt) {
  92. save();
  93. }
  94. });
  95. cancelBtn.addActionListener(new ActionListener() {
  96. public void actionPerformed(ActionEvent evt) {
  97. cancel();
  98. }
  99. });
  100. addWindowListener(new WindowAdapter() {
  101. public void windowClosing(WindowEvent evt) {
  102. if(changedStateSinceSave){
  103. saveExitDialog();
  104. }
  105. dispose();
  106. }
  107. });
  108. }
  109. // Anfang Komponenten
  110. // Ende Komponenten
  111. private void loadData(){
  112. for(int i = 0; i < 8; i++){
  113. int div = frame[(8*(li+1)+i)-8];
  114. int[] rest = new int[8];
  115. int ctr = 0;
  116. while(div != 0){
  117. rest[ctr] = div%2;
  118. div = div/2;
  119. ctr++;
  120. }
  121. for(int j = 0; j < 8; j++){
  122. if(rest[j] == 0){
  123. ledPanels[j][i].setIcon(off);
  124. } else {
  125. ledPanels[j][i].setIcon(on);
  126. }
  127. ledStatus[j][i] = (byte) rest[j];
  128. }
  129. }
  130. }
  131. public short[] getFinalFrame(){
  132. if (finish == false) {
  133. return null;
  134. }
  135. //return shortToByteArray(frame);
  136. return frame;
  137. }
  138. public void btnClicked(int i, int j){
  139. changedStateSinceSave = true;
  140. if (ledPanels[i][j].getIcon() == on){
  141. ledPanels[i][j].setIcon(off);
  142. ledStatus[i][j] = 0;
  143. } else {
  144. ledPanels[i][j].setIcon(on);
  145. ledStatus[i][j] = 1;
  146. }
  147. }
  148. public void cancel(){
  149. dispose();
  150. }
  151. public void save(){
  152. int ctr = 0;
  153. short[] tmpFrame = frame;
  154. changedStateSinceSave = false;
  155. short reihe = 0;
  156. for(int j = 0; j < 8; j++){
  157. for(int i = 0; i < 8; i++){
  158. reihe += ((short) Math.pow(2, i)) * ledStatus[i][j];
  159. ctr++;
  160. }
  161. tmpFrame[(8*(li+1)+j)-8] = reihe;
  162. reihe = 0;
  163. }
  164. frame = tmpFrame;
  165. worker.setFrame(frame, animI, frameI);
  166. ListSelectionEvent layerChanged = new ListSelectionEvent(LedFrame.frameList, LedFrame.frameList.getSelectedIndex(), LedFrame.frameList.getSelectedIndex(), false);
  167. LedFrame.valueChanged(layerChanged);
  168. dispose();
  169. }
  170. private int saveExitDialog() {
  171. String[] Optionen = {"Yes", "No"};
  172. int Auswahl = JOptionPane.showOptionDialog(this, "Do you want to save your changes?", "Save?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Optionen, Optionen[0]);
  173. if (Auswahl == JOptionPane.YES_OPTION) {
  174. save();
  175. return 1;
  176. } else {
  177. return 0;
  178. }
  179. }
  180. }