Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.update.edit;
- import java.awt.Toolkit;
- import java.awt.datatransfer.Clipboard;
- import java.awt.datatransfer.StringSelection;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.ResourceBundle;
- import javax.swing.Icon;
- import javax.swing.JLabel;
- import javax.swing.event.CaretEvent;
- import javax.swing.event.CaretListener;
- import org.omg.CORBA.INITIALIZE;
- import javafx.scene.shape.Rectangle;
- import javafx.beans.value.ChangeListener;
- import javafx.beans.value.ObservableValue;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TabPane;
- import javafx.scene.control.TextArea;
- import javafx.scene.paint.Color;
- public class Controller implements Initializable {
- private Color rectRed = new Color(0.80784, 0.26274, 0.19215, 1);
- private Color rectBlue = new Color(0.18039, 0.56078, 0.81568, 1);
- @FXML
- private Rectangle rectText;
- @FXML
- private Rectangle rectCode;
- @FXML
- private TextArea textAreaInput;
- @FXML
- private TextArea textAreaOutput;
- @FXML
- private Button buttonSwap;
- @FXML
- private Button buttonCopyToClipboard;
- @FXML
- private Button buttonExecute;
- @FXML
- private Button buttonClean;
- @FXML
- private Button buttonClose;
- @FXML
- private Label labelText;
- @FXML
- private Label labelCode;
- @FXML
- private Icon iconTrash;
- @FXML
- private Label tabPaneHistoryLabel;
- private int confirmSwapButtonHasBeenToggled = 0;
- @SuppressWarnings("unused")
- private int confirmCopyToClipboardButtonIsReadyAgain = 0;
- // private List<String> oldOutput = new ArrayList<String>();
- private String[] oldOutput = new String[1];
- private int oldOutputCount = 0;
- @FXML
- void ButtonHandler(ActionEvent event) {
- /** Button Copy */
- if (event.getSource() == buttonCopyToClipboard) {
- String str = textAreaOutput.getText();
- StringSelection stringSelection = new StringSelection(str);
- Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
- clpbrd.setContents(stringSelection, null);
- buttonCopyToClipboard.setText("Copied to Clipboard");
- buttonCopyToClipboard.setDisable(true);
- buttonCopyToClipboard.setStyle("-fx-background-color: rgb(150, 255, 0)");
- }
- /** Button Execute */
- else if (event.getSource() == buttonExecute) {
- String converted = "";
- if (confirmSwapButtonHasBeenToggled == 0) {
- converted = Coder.code(textAreaInput.getText());
- textAreaOutput.setText(converted);
- tabPaneHistoryLabel.setText("TEXT\n");
- } else {
- converted = Decoder.decode(textAreaInput.getText());
- textAreaOutput.setText(converted);
- if (converted == null) {
- // DialogErrorNullException dialog = new DialogErrorNullException(Client.this);
- // dialog.setLocationRelativeTo(Client.this);
- // dialog.setVisible(true);
- //DEV TOOL
- System.out.println("INVALID INPUT");
- }
- tabPaneHistoryLabel.setText("CODE\n");
- }
- //Initialize newOutput with textAreaOutput
- String newOutput = textAreaOutput.getText();
- //Check newOutput with oldOutput
- if (!(newOutput.equals(oldOutput[0]))) {
- buttonCopyToClipboard.setText("Copy to Clipboard");
- buttonCopyToClipboard.setDisable(false);
- oldOutputCount++;
- //DEV TOOL
- System.out.println("TRUE: " + oldOutputCount + ". Count");
- } else {
- //DEV TOOL
- System.out.println("FALSE");
- }
- //New Output added as Old Output
- // oldOutput.add(textAreaOutput.getText());
- oldOutput[0] = textAreaOutput.getText();
- }
- /** Button Clean */
- else if (event.getSource() == buttonClean) {
- // imgTrash.setVisible(false);
- textAreaInput.setText("");
- textAreaOutput.setText("");
- buttonCopyToClipboard.setText("Copy to Clipboard");
- // buttonCopyToClipboard.setStyle("-fx-background-color: rgb(225, 225, 255)");
- // buttonCopyToClipboard.setStyle("-fx-background-color: default");f
- buttonCopyToClipboard.setDisable(true);
- confirmCopyToClipboardButtonIsReadyAgain = 1;
- }
- /** Button Close */
- else if (event.getSource() == buttonClose) {
- System.exit(0);
- }
- /** Button Swap */
- else if (event.getSource() == buttonSwap) {
- String savedContent = textAreaOutput.getText();
- textAreaOutput.setText(textAreaInput.getText());
- textAreaInput.setText(savedContent);
- String savedContentInfo = labelCode.getText();
- labelCode.setText(labelText.getText());
- labelText.setText(savedContentInfo);
- /** int confirmSwapButtonHasBeenToggled toggles */
- if ( confirmSwapButtonHasBeenToggled == 0) {
- rectText.setFill(rectBlue);
- rectCode.setFill(rectRed);
- confirmSwapButtonHasBeenToggled = 1;
- } else {
- rectText.setFill(rectRed);
- rectCode.setFill(rectBlue);
- confirmSwapButtonHasBeenToggled = 0;
- }
- }
- }
- @Override
- public void initialize(URL location, ResourceBundle resources) {
- textAreaInput.caretPositionProperty().addListener(new ChangeListener<Number>() {
- public void changed(ObservableValue<? extends Number> valueObject, Number oldValue, Number newValue) {
- // System.out.println("Current caret position: " + newValue);
- String str = textAreaInput.getText();
- str = str.trim();
- if (str.isEmpty()) {
- buttonExecute.setDisable(true);
- } else {
- buttonExecute.setDisable(false);
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement