Advertisement
Guest User

Controller

a guest
Dec 5th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.79 KB | None | 0 0
  1. package de.update.edit;
  2.  
  3. import java.awt.Toolkit;
  4. import java.awt.datatransfer.Clipboard;
  5. import java.awt.datatransfer.StringSelection;
  6. import java.net.URL;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. import java.util.ResourceBundle;
  10.  
  11. import javax.swing.Icon;
  12. import javax.swing.JLabel;
  13. import javax.swing.event.CaretEvent;
  14. import javax.swing.event.CaretListener;
  15.  
  16. import org.omg.CORBA.INITIALIZE;
  17.  
  18. import javafx.scene.shape.Rectangle;
  19. import javafx.beans.value.ChangeListener;
  20. import javafx.beans.value.ObservableValue;
  21. import javafx.event.ActionEvent;
  22. import javafx.fxml.FXML;
  23. import javafx.fxml.Initializable;
  24. import javafx.scene.control.Button;
  25. import javafx.scene.control.Label;
  26. import javafx.scene.control.TabPane;
  27. import javafx.scene.control.TextArea;
  28. import javafx.scene.paint.Color;
  29.  
  30. public class Controller implements Initializable {
  31.    
  32.     private Color rectRed = new Color(0.80784, 0.26274, 0.19215, 1);
  33.     private Color rectBlue = new Color(0.18039, 0.56078, 0.81568, 1);
  34.  
  35.     @FXML
  36.     private Rectangle rectText;
  37.     @FXML
  38.     private Rectangle rectCode;
  39.  
  40.     @FXML
  41.     private TextArea textAreaInput;
  42.     @FXML
  43.     private TextArea textAreaOutput;
  44.  
  45.     @FXML
  46.     private Button buttonSwap;
  47.     @FXML
  48.     private Button buttonCopyToClipboard;
  49.     @FXML
  50.     private Button buttonExecute;
  51.     @FXML
  52.     private Button buttonClean;
  53.     @FXML
  54.     private Button buttonClose;
  55.  
  56.     @FXML
  57.     private Label labelText;
  58.     @FXML
  59.     private Label labelCode;
  60.  
  61.     @FXML
  62.     private Icon iconTrash;
  63.    
  64.     @FXML
  65.     private Label tabPaneHistoryLabel;
  66.    
  67.    
  68.     private int confirmSwapButtonHasBeenToggled = 0;
  69.     @SuppressWarnings("unused")
  70.     private int confirmCopyToClipboardButtonIsReadyAgain = 0;
  71.    
  72.  
  73. //  private List<String> oldOutput = new ArrayList<String>();
  74.     private String[] oldOutput = new String[1];
  75.     private int oldOutputCount =  0;
  76.    
  77.    
  78.     @FXML
  79.     void ButtonHandler(ActionEvent event) {
  80.        
  81.         /** Button Copy */
  82.         if (event.getSource() == buttonCopyToClipboard) {
  83.             String str = textAreaOutput.getText();
  84.            
  85.             StringSelection stringSelection = new StringSelection(str);
  86.             Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
  87.             clpbrd.setContents(stringSelection, null);
  88.            
  89.             buttonCopyToClipboard.setText("Copied to Clipboard");
  90.             buttonCopyToClipboard.setDisable(true);
  91.             buttonCopyToClipboard.setStyle("-fx-background-color: rgb(150, 255, 0)");
  92.         }
  93.        
  94.  
  95.         /** Button Execute */
  96.         else if (event.getSource() == buttonExecute) {
  97.             String converted = "";
  98.            
  99.             if (confirmSwapButtonHasBeenToggled == 0) {
  100.                 converted = Coder.code(textAreaInput.getText());
  101.                 textAreaOutput.setText(converted);
  102.                
  103.                 tabPaneHistoryLabel.setText("TEXT\n");
  104.             } else {
  105.                 converted = Decoder.decode(textAreaInput.getText());
  106.                 textAreaOutput.setText(converted);
  107.                
  108.                 if (converted == null) {
  109. //                  DialogErrorNullException dialog = new DialogErrorNullException(Client.this);
  110. //                  dialog.setLocationRelativeTo(Client.this);
  111. //                  dialog.setVisible(true);
  112.                    
  113.                     //DEV TOOL
  114.                     System.out.println("INVALID INPUT");
  115.                 }
  116.                
  117.                 tabPaneHistoryLabel.setText("CODE\n");
  118.             }
  119.            
  120.            
  121.             //Initialize newOutput with textAreaOutput
  122.             String newOutput = textAreaOutput.getText();
  123.            
  124.             //Check newOutput with oldOutput
  125.             if (!(newOutput.equals(oldOutput[0]))) {
  126.                 buttonCopyToClipboard.setText("Copy to Clipboard");
  127.                 buttonCopyToClipboard.setDisable(false);
  128.                
  129.                 oldOutputCount++;
  130.                
  131.                 //DEV TOOL
  132.                 System.out.println("TRUE: " + oldOutputCount + ". Count");
  133.             } else {
  134.                 //DEV TOOL
  135.                 System.out.println("FALSE");
  136.             }
  137.            
  138.             //New Output added as Old Output
  139. //          oldOutput.add(textAreaOutput.getText());
  140.             oldOutput[0] = textAreaOutput.getText();
  141.         }
  142.        
  143.        
  144.         /** Button Clean */
  145.         else if (event.getSource() == buttonClean) {
  146. //          imgTrash.setVisible(false);
  147.             textAreaInput.setText("");
  148.             textAreaOutput.setText("");
  149.            
  150.             buttonCopyToClipboard.setText("Copy to Clipboard");
  151. //          buttonCopyToClipboard.setStyle("-fx-background-color: rgb(225, 225, 255)");
  152. //          buttonCopyToClipboard.setStyle("-fx-background-color: default");f
  153.             buttonCopyToClipboard.setDisable(true);
  154.            
  155.             confirmCopyToClipboardButtonIsReadyAgain = 1;
  156.         }
  157.        
  158.        
  159.         /** Button Close */
  160.         else if (event.getSource() == buttonClose) {
  161.             System.exit(0);
  162.         }
  163.        
  164.        
  165.         /** Button Swap */
  166.         else if (event.getSource() == buttonSwap) {
  167.             String savedContent = textAreaOutput.getText();
  168.             textAreaOutput.setText(textAreaInput.getText());
  169.             textAreaInput.setText(savedContent);
  170.            
  171.            
  172.             String savedContentInfo = labelCode.getText();
  173.             labelCode.setText(labelText.getText());
  174.             labelText.setText(savedContentInfo);
  175.            
  176.             /** int confirmSwapButtonHasBeenToggled toggles */
  177.             if ( confirmSwapButtonHasBeenToggled == 0) {
  178.                 rectText.setFill(rectBlue);
  179.                 rectCode.setFill(rectRed);
  180.                
  181.                 confirmSwapButtonHasBeenToggled = 1;
  182.             } else {
  183.                 rectText.setFill(rectRed);
  184.                 rectCode.setFill(rectBlue);
  185.  
  186.                 confirmSwapButtonHasBeenToggled = 0;
  187.             }
  188.         }
  189.     }
  190.  
  191.  
  192.  
  193.     @Override
  194.     public void initialize(URL location, ResourceBundle resources) {
  195.         textAreaInput.caretPositionProperty().addListener(new ChangeListener<Number>() {
  196.  
  197.             public void changed(ObservableValue<? extends Number> valueObject, Number oldValue, Number newValue) {
  198. //                System.out.println("Current caret position: " + newValue);
  199.                 String str = textAreaInput.getText();
  200.                 str = str.trim();
  201.                
  202.                 if (str.isEmpty()) {
  203.                     buttonExecute.setDisable(true);
  204.                 } else {
  205.                     buttonExecute.setDisable(false);
  206.                 }
  207.             }
  208.            
  209.         });
  210.     }
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement