Skip to content

Commit 59db54e

Browse files
lgajosOgefest
authored andcommitted
changed controls in create new notepad window
1 parent 8824f91 commit 59db54e

2 files changed

Lines changed: 122 additions & 119 deletions

File tree

src/main/java/notepack/NotepadCreateController.java

Lines changed: 105 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package notepack;
22

3+
import javafx.scene.input.Clipboard;
4+
import javafx.scene.input.ClipboardContent;
35
import notepack.NotepadCreateCallback;
46
import java.io.File;
57
import java.io.IOException;
68
import java.net.URL;
9+
import java.util.Arrays;
10+
import java.util.Collections;
11+
import java.util.List;
712
import java.util.ResourceBundle;
813
import java.util.logging.Level;
914
import java.util.logging.Logger;
@@ -44,14 +49,12 @@ public class NotepadCreateController implements Initializable {
4449

4550
@FXML
4651
private TextField notepadName;
47-
private TextField directoryPath;
4852

4953
private NotepadCreateCallback clbk;
5054
@FXML
5155
private Button btnCancel;
5256

5357
private Notepad notepad;
54-
private boolean notepadEdition = false;
5558
@FXML
5659
private ToggleButton btnUserColor6;
5760
@FXML
@@ -77,20 +80,17 @@ public class NotepadCreateController implements Initializable {
7780
private AnchorPane engineForm;
7881

7982
private EngineController currentFormController;
83+
8084
@FXML
81-
private CheckBox gpgCheckbox;
82-
@FXML
83-
private TextField gpgPublicKeyPath;
84-
@FXML
85-
private Button gpgSelectPublicKey;
85+
private CheckBox encryptionCheckbox;
8686
@FXML
87-
private TextField gpgPrivateKeyPath;
87+
private PasswordField encryptionPassword;
8888
@FXML
89-
private Button gpgSelectPrivateKey;
89+
private Button generatePassword;
9090
@FXML
91-
private Label gpgPublicLabel;
91+
private Button copyPasswordBtn;
9292
@FXML
93-
private Label gpgPrivateLabel;
93+
private Label passwordLabel;
9494

9595
/**
9696
* Initializes the controller class.
@@ -119,21 +119,15 @@ public void initialize(URL url, ResourceBundle rb) {
119119
}
120120
});
121121

122-
gpgCheckbox.selectedProperty().addListener((o) -> {
123-
if (gpgCheckbox.isSelected()) {
124-
gpgPrivateLabel.setDisable(false);
125-
gpgPublicLabel.setDisable(false);
126-
gpgPrivateKeyPath.setDisable(false);
127-
gpgPublicKeyPath.setDisable(false);
128-
gpgSelectPrivateKey.setDisable(false);
129-
gpgSelectPublicKey.setDisable(false);
122+
encryptionCheckbox.selectedProperty().addListener((o) -> {
123+
if (encryptionCheckbox.isSelected()) {
124+
encryptionPassword.setDisable(false);
125+
generatePassword.setDisable(false);
126+
passwordLabel.setDisable(false);
130127
} else {
131-
gpgPrivateLabel.setDisable(true);
132-
gpgPublicLabel.setDisable(true);
133-
gpgPrivateKeyPath.setDisable(true);
134-
gpgPublicKeyPath.setDisable(true);
135-
gpgSelectPrivateKey.setDisable(true);
136-
gpgSelectPublicKey.setDisable(true);
128+
encryptionPassword.setDisable(true);
129+
generatePassword.setDisable(true);
130+
passwordLabel.setDisable(true);
137131
}
138132
});
139133

@@ -151,8 +145,7 @@ public void initialize(URL url, ResourceBundle rb) {
151145

152146
try {
153147
Parent root = fxmlLoader.load();
154-
// new Theme(new PreferencesSettings()).setCurrent(root.getScene());
155-
148+
156149
currentFormController = (EngineController) fxmlLoader.getController();
157150

158151
engineForm.getChildren().add(root);
@@ -171,7 +164,7 @@ public void setNotepadCreateCallback(NotepadCreateCallback clbk) {
171164

172165
public void setNotepadToEdit(Notepad notepad) {
173166
this.notepad = notepad;
174-
notepadEdition = true;
167+
// notepadEdition = true;
175168

176169
notepadName.setText(notepad.getName());
177170

@@ -188,17 +181,16 @@ public void setNotepadToEdit(Notepad notepad) {
188181
engineSelection.getSelectionModel().select(0);
189182
engineSelection.setDisable(true);
190183

191-
if (notepad.getParam("gpg-enabled").equals("1")) {
192-
gpgPrivateKeyPath.setText(notepad.getParam("gpg-private-key"));
193-
gpgPublicKeyPath.setText(notepad.getParam("gpg-public-key"));
194-
gpgCheckbox.setSelected(true);
184+
if (notepad.getParam("encryption-enabled").equals("1")) {
185+
encryptionPassword.setText(notepad.getParam("encryption-password"));
186+
encryptionCheckbox.setSelected(true);
187+
copyPasswordBtn.setDisable(false);
195188
}
196189

197-
gpgCheckbox.setDisable(true);
198-
gpgPrivateKeyPath.setDisable(true);
199-
gpgPublicKeyPath.setDisable(true);
200-
gpgSelectPrivateKey.setDisable(true);
201-
gpgSelectPublicKey.setDisable(true);
190+
encryptionCheckbox.setDisable(true);
191+
encryptionPassword.setDisable(true);
192+
generatePassword.setDisable(true);
193+
passwordLabel.setDisable(true);
202194

203195
currentFormController.setStorage(notepad.getStorage());
204196

@@ -248,28 +240,21 @@ private void onAdd(ActionEvent event) {
248240
return;
249241
}
250242

251-
if (gpgCheckbox.isSelected()) {
252-
notepad.setParam("gpg-enabled", "1");
243+
if (encryptionCheckbox.isSelected()) {
244+
notepad.setParam("encryption-enabled", "1");
253245

254-
File privateFile = new File(gpgPrivateKeyPath.getText());
255-
File publicFile = new File(gpgPublicKeyPath.getText());
246+
String pwd = encryptionPassword.getText();
256247

257-
if (!privateFile.exists()) {
258-
Alert a = new Alert(Alert.AlertType.ERROR, "GPG private key not exists");
259-
a.show();
260-
return;
261-
}
262-
if (!publicFile.exists()) {
263-
Alert a = new Alert(Alert.AlertType.ERROR, "GPG public key not exists");
248+
if (pwd.length() < 5) {
249+
Alert a = new Alert(Alert.AlertType.ERROR, "Password must have at least 5 characters");
264250
a.show();
265251
return;
266252
}
267253

268-
notepad.setParam("gpg-private-key", privateFile.getAbsolutePath());
269-
notepad.setParam("gpg-public-key", publicFile.getAbsolutePath());
254+
notepad.setParam("encryption-password", pwd);
270255

271256
} else {
272-
notepad.setParam("gpg-enabled", "0");
257+
notepad.setParam("encryption-enabled", "0");
273258
}
274259

275260
String color = (String) tg.getSelectedToggle().getUserData();
@@ -289,57 +274,81 @@ private void onCancel(ActionEvent event) {
289274
stage.close();
290275
}
291276

292-
private void webDavTestConnection(ActionEvent event) {
293-
294-
String url = webDavUrl.getText();
295-
String username = webDavUsername.getText();
296-
String password = webDavPassword.getText();
297-
298-
NoteStorageConfiguration nsc = new NoteStorageConfiguration();
299-
nsc.set("url", url);
300-
nsc.set("username", username);
301-
nsc.set("password", password);
302-
303-
Webdav wd = new Webdav(nsc);
304-
305-
try {
306-
NoteStorageItem noteItem = wd.getItemsInStorage();
307-
wd.refreshItemsInStorage();
308-
} catch (MessageError ex) {
309-
Alert a = new Alert(Alert.AlertType.ERROR, "WebDAV problem: " + ex.getMessage());
310-
a.showAndWait();
311-
return;
312-
}
313-
314-
Alert a = new Alert(Alert.AlertType.INFORMATION, "WebDAV configuration looks good ");
315-
a.showAndWait();
316-
317-
}
318-
319277
@FXML
320-
private void onSelectPublicKey(ActionEvent event) {
321-
Stage stage = (Stage) gpgPublicKeyPath.getScene().getWindow();
278+
public void generateRandomPassword(ActionEvent actionEvent) {
279+
String input = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+,./<>?;':[]{}";
280+
String pwd = "";
281+
for (int i = 0; i < 20; i++) {
282+
List<String> result = Arrays.asList(input.split(""));
283+
Collections.shuffle(result);
284+
pwd = pwd + result.get(0);
285+
}
286+
encryptionPassword.setText(pwd);
287+
copyPasswordBtn.setDisable(false);
322288

323-
FileChooser chooser = new FileChooser();
324-
chooser.setTitle("Select GPG public key");
289+
Alert alert = new Alert(Alert.AlertType.INFORMATION);
290+
alert.setTitle("Information Dialog");
291+
alert.setHeaderText(null);
292+
alert.setContentText("Copy and save generated password, this is possible only now!");
325293

326-
File selectedFile = chooser.showOpenDialog(stage);
327-
if (selectedFile != null) {
328-
gpgPublicKeyPath.setText(selectedFile.getAbsolutePath());
329-
}
294+
alert.showAndWait();
330295
}
331296

332297
@FXML
333-
private void onSelectPrivateKey(ActionEvent event) {
334-
Stage stage = (Stage) gpgPrivateKeyPath.getScene().getWindow();
335-
336-
FileChooser chooser = new FileChooser();
337-
chooser.setTitle("Select GPG private key");
338-
339-
File selectedFile = chooser.showOpenDialog(stage);
340-
if (selectedFile != null) {
341-
gpgPrivateKeyPath.setText(selectedFile.getAbsolutePath());
342-
}
298+
public void copyPassword(ActionEvent actionEvent) {
299+
Clipboard clipboard = Clipboard.getSystemClipboard();
300+
ClipboardContent content = new ClipboardContent();
301+
content.putString(encryptionPassword.getText());
302+
clipboard.setContent(content);
343303
}
344304

305+
// private void webDavTestConnection(ActionEvent event) {
306+
//
307+
// String url = webDavUrl.getText();
308+
// String username = webDavUsername.getText();
309+
// String password = webDavPassword.getText();
310+
//
311+
// NoteStorageConfiguration nsc = new NoteStorageConfiguration();
312+
// nsc.set("url", url);
313+
// nsc.set("username", username);
314+
// nsc.set("password", password);
315+
//
316+
// Webdav wd = new Webdav(nsc);
317+
//
318+
// try {
319+
// NoteStorageItem noteItem = wd.getItemsInStorage();
320+
// wd.refreshItemsInStorage();
321+
// } catch (MessageError ex) {
322+
// Alert a = new Alert(Alert.AlertType.ERROR, "WebDAV problem: " + ex.getMessage());
323+
// a.showAndWait();
324+
// return;
325+
// }
326+
//
327+
// Alert a = new Alert(Alert.AlertType.INFORMATION, "WebDAV configuration looks good ");
328+
// a.showAndWait();
329+
//
330+
// }
331+
332+
// private void onSelectPublicKey(ActionEvent event) {
333+
// Stage stage = (Stage) gpgPublicKeyPath.getScene().getWindow();
334+
//
335+
// FileChooser chooser = new FileChooser();
336+
// chooser.setTitle("Select GPG public key");
337+
//
338+
// File selectedFile = chooser.showOpenDialog(stage);
339+
// if (selectedFile != null) {
340+
// gpgPublicKeyPath.setText(selectedFile.getAbsolutePath());
341+
// }
342+
// }
343+
// private void onSelectPrivateKey(ActionEvent event) {
344+
// Stage stage = (Stage) gpgPrivateKeyPath.getScene().getWindow();
345+
//
346+
// FileChooser chooser = new FileChooser();
347+
// chooser.setTitle("Select GPG private key");
348+
//
349+
// File selectedFile = chooser.showOpenDialog(stage);
350+
// if (selectedFile != null) {
351+
// gpgPrivateKeyPath.setText(selectedFile.getAbsolutePath());
352+
// }
353+
// }
345354
}

src/main/resources/notepack/NotepadCreate.fxml

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
<?import javafx.scene.layout.VBox?>
1919
<?import javafx.scene.text.Font?>
2020

21-
<VBox prefHeight="825.0" prefWidth="746.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="notepack.NotepadCreateController">
21+
<VBox prefHeight="699.0" prefWidth="746.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="notepack.NotepadCreateController">
2222
<stylesheets>
23-
<!--<URL value="@color-definition.css" />-->
23+
<URL value="@color-definition.css" />
2424
<URL value="@scrollbar.css" />
2525
<URL value="@icons.css" />
2626
<URL value="@default.css" />
@@ -33,37 +33,31 @@
3333
<font>
3434
<Font size="15.0" />
3535
</font></Label>
36-
<TextField fx:id="notepadName" layoutX="280.0" layoutY="31.0" prefHeight="38.0" prefWidth="315.0" />
36+
<TextField fx:id="notepadName" layoutX="215.0" layoutY="32.0" prefHeight="38.0" prefWidth="445.0" />
3737
<Label layoutX="56.0" layoutY="84.0" text="Notepad color:" AnchorPane.leftAnchor="20.0">
3838
<font>
3939
<Font size="15.0" />
4040
</font></Label>
41-
<ToggleButton fx:id="btnUserColor6" layoutX="444.0" layoutY="79.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" style="-fx-background-color: user-color-6;" />
42-
<ToggleButton fx:id="btnUserColor5" layoutX="410.0" layoutY="79.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" style="-fx-background-color: user-color-5;" />
43-
<ToggleButton fx:id="btnUserColor4" layoutX="378.0" layoutY="79.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" style="-fx-background-color: user-color-4;" />
44-
<ToggleButton fx:id="btnUserColor3" layoutX="344.0" layoutY="79.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" style="-fx-background-color: user-color-3;" />
45-
<ToggleButton fx:id="btnUserColor2" layoutX="312.0" layoutY="79.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" style="-fx-background-color: user-color-2;" />
46-
<ToggleButton fx:id="btnUserColor1" layoutX="280.0" layoutY="79.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" selected="true" style="-fx-background-color: user-color-1;" />
47-
<Label layoutX="40.0" layoutY="126.0" text="Enable GPG encryption:">
41+
<ToggleButton fx:id="btnUserColor6" layoutX="379.0" layoutY="80.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" style="-fx-background-color: user-color-6;" />
42+
<ToggleButton fx:id="btnUserColor5" layoutX="345.0" layoutY="80.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" style="-fx-background-color: user-color-5;" />
43+
<ToggleButton fx:id="btnUserColor4" layoutX="313.0" layoutY="80.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" style="-fx-background-color: user-color-4;" />
44+
<ToggleButton fx:id="btnUserColor3" layoutX="279.0" layoutY="80.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" style="-fx-background-color: user-color-3;" />
45+
<ToggleButton fx:id="btnUserColor2" layoutX="247.0" layoutY="80.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" style="-fx-background-color: user-color-2;" />
46+
<ToggleButton fx:id="btnUserColor1" layoutX="215.0" layoutY="80.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" selected="true" style="-fx-background-color: user-color-1;" />
47+
<Label layoutX="40.0" layoutY="126.0" text="Enable encryption:">
4848
<font>
4949
<Font size="15.0" />
5050
</font>
5151
</Label>
52-
<CheckBox fx:id="gpgCheckbox" layoutX="280.0" layoutY="127.0" mnemonicParsing="false" />
53-
<Label fx:id="gpgPublicLabel" disable="true" layoutX="40.0" layoutY="175.0" text="Public key:">
52+
<CheckBox fx:id="encryptionCheckbox" layoutX="215.0" layoutY="128.0" mnemonicParsing="false" />
53+
<Label fx:id="passwordLabel" disable="true" layoutX="40.0" layoutY="175.0" text="Password:">
5454
<font>
5555
<Font size="15.0" />
5656
</font>
5757
</Label>
58-
<TextField fx:id="gpgPublicKeyPath" disable="true" layoutX="277.0" layoutY="166.0" prefHeight="38.0" prefWidth="253.0" />
59-
<Button fx:id="gpgSelectPublicKey" cancelButton="true" disable="true" layoutX="530.0" layoutY="166.0" mnemonicParsing="false" onAction="#onSelectPublicKey" text="Select" />
60-
<Label fx:id="gpgPrivateLabel" disable="true" layoutX="40.0" layoutY="228.0" text="Private key:">
61-
<font>
62-
<Font size="15.0" />
63-
</font>
64-
</Label>
65-
<TextField fx:id="gpgPrivateKeyPath" disable="true" layoutX="277.0" layoutY="218.0" prefHeight="38.0" prefWidth="253.0" />
66-
<Button fx:id="gpgSelectPrivateKey" cancelButton="true" disable="true" layoutX="530.0" layoutY="218.0" mnemonicParsing="false" onAction="#onSelectPrivateKey" text="Select" />
58+
<PasswordField fx:id="encryptionPassword" disable="true" layoutX="214.0" layoutY="167.0" prefHeight="37.0" prefWidth="223.0" />
59+
<Button fx:id="generatePassword" disable="true" layoutX="446.0" layoutY="168.0" mnemonicParsing="false" onAction="#generateRandomPassword" text="Generate" />
60+
<Button fx:id="copyPasswordBtn" disable="true" layoutX="539.0" layoutY="168.0" mnemonicParsing="false" onAction="#copyPassword" text="Copy password" />
6761
</children>
6862
<padding>
6963
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
@@ -78,10 +72,10 @@
7872
</VBox.margin>
7973
<children>
8074
<ComboBox fx:id="engineSelection" layoutX="23.0" layoutY="22.0" prefHeight="26.0" prefWidth="665.0" promptText="Select storage engine" AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="15.0" />
81-
<AnchorPane fx:id="engineForm" layoutX="15.0" layoutY="52.0" prefHeight="292.0" prefWidth="706.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
75+
<AnchorPane fx:id="engineForm" layoutX="15.0" layoutY="52.0" prefHeight="269.0" prefWidth="706.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
8276
</children>
8377
</AnchorPane>
84-
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="100.0" VBox.vgrow="ALWAYS">
78+
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="86.0" prefWidth="706.0" VBox.vgrow="ALWAYS">
8579
<children>
8680
<Button fx:id="btnSave" defaultButton="true" layoutX="333.0" layoutY="436.0" mnemonicParsing="false" onAction="#onAdd" text="Add" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="0.0" />
8781
<Button fx:id="btnCancel" cancelButton="true" layoutX="577.0" layoutY="10.0" mnemonicParsing="false" onAction="#onCancel" text="Cancel" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="60.0" />

0 commit comments

Comments
 (0)