Download this file

PathFileSetting.java    173 lines (135 with data), 5.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package cologne.eck.all_peas.gui;
/*
* Peafactory - Production of Password Encryption Archives
* Copyright (C) 2015 Axel von dem Bruch
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* See: http://www.gnu.org/licenses/gpl-2.0.html
* You should have received a copy of the GNU General Public License
* along with this library.
*/
/**
* Settings for the password hashing scheme Pomelo.
*/
import java.awt.Dimension;
//import java.awt.Font;
import java.awt.Point;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.accessibility.AccessibleContext;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import cologne.eck.all_peas.control.PathFileManager;
import cologne.eck.all_peas.data.PeaProperties;
import cologne.eck.tools.ReadResources;
import cologne.eck.tools.WriteResources;
@SuppressWarnings("serial")
public class PathFileSetting extends JDialog implements ActionListener {
private static PathFileSetting pathFileSetting;
private JTextArea pathArea;
private PathFileSetting(Window parent, Point loc) {
super(parent);
pathFileSetting = this;
pathFileSetting.setAlwaysOnTop(true);
this.setTitle(PeaProperties.getBundle().getString("path_file_setting"));
this.setIconImage(PswDialogView.getImage());
JPanel pane = (JPanel) pathFileSetting.getContentPane();//new JPanel();
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
pane.setBorder(PeaBorderFactory.createBorder(false));//.setBorder(new EmptyBorder(5,5,5,5));
JTextArea infoArea = new JTextArea();
infoArea.setEditable(false);
infoArea.setText(PeaProperties.getBundle().getString("path_file_info_1")
+ "\n "
// + System.getProperty("user.dir") + java.io.File.separator
+ PathFileManager.getPathFileName()
+ "\n\n" + PeaProperties.getBundle().getString("path_file_info_2") );
//infoArea.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
infoArea.setMinimumSize(new Dimension (400, 60));
//infoArea.setMaximumSize(new Dimension (400, 60));
infoArea.setBackground(pane.getBackground());
pane.add(infoArea);
pane.add(Box.createVerticalStrut(10));
pathArea = new JTextArea();
String content = " ";
if (new File(PathFileManager.getPathFileName()).exists()
&& new File(PathFileManager.getPathFileName()).length() > 0){
content = new String(
ReadResources.readExternFile(PathFileManager.getPathFileName()), PeaProperties.getCharset());
//System.out.println(content);
}
pathArea.setText(content);
JScrollPane scrollPane = new JScrollPane(pathArea);
scrollPane.setPreferredSize(new Dimension (400, 200));
pane.add(scrollPane);
JButton okButton = new JButton("ok");
okButton.setActionCommand("newSetting");
okButton.addActionListener(this);
pane.add(okButton);
pathFileSetting.pack();
// this.getParent().getLocationOnScreen();
pathFileSetting.setLocation(loc);
pathFileSetting.setVisible(true);
}
public static PathFileSetting getInstance(Window parent, Point p) {
if (pathFileSetting == null) {
return new PathFileSetting(parent, p);
} else {
return pathFileSetting;
}
}
@Override
public void actionPerformed(ActionEvent ape) {
String command = ape.getActionCommand();
if (command.equals("newSetting")) {
// leading or trailing whitespace may cause bugs
String areaText = pathArea.getText();
if ((new File(PathFileManager.getPathFileName()).exists() == false)
&& areaText.equals(" ")) {
pathFileSetting.dispose();
pathFileSetting = null;
return;
}
String newPathFiles = "";
String[] lines = areaText.split("\n");
int len = lines.length;
if (len > 0) {
for (int i = 0; i < len-1; i++){
newPathFiles += lines[i].trim() + "\n"; // delete whitespace
}
// last line without "\n":
newPathFiles += lines[len-1].trim();
}
// write String without leading and trailing whitespace:
WriteResources.writeText(newPathFiles, PathFileManager.getPathFileName());
pathFileSetting.dispose();
pathFileSetting = null;
}
}
public static void main(String[] args){
PathFileSetting p = new PathFileSetting(null, new Point(100,100));
p.setVisible(true);
}
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessiblePathFileSetting();
}
return accessibleContext;
}
protected class AccessiblePathFileSetting extends AccessibleJDialog {
//Inherit everything, override nothing.
}
}