This repository was archived by the owner on Nov 16, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathneedSave.java
More file actions
192 lines (166 loc) · 5.49 KB
/
needSave.java
File metadata and controls
192 lines (166 loc) · 5.49 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
* By attaching this document to the given files (the �work�), you, the licensee,
* are hereby granted free usage in both personal and commerical environments,
* without any obligation of attribution or payment (monetary or otherwise).
*
* The licensee is free to use, copy, modify, publish, distribute, sublicence,
* and/or merchandise the work, subject to the licensee inflecting a positive
* message unto someone. This includes (but is not limited to): smiling,
* being nice, saying �thank you�, assisting other persons, or any
* similar actions percolating the given concept.
*
* The above copyright notice serves as a permissions notice also,
* and may optionally be included in copies or portions of the work.
*
* The work is provided �as is�, without warranty or support, express or implied.
* The author(s) are not liable for any damages, misuse, or other claim, whether
* from or as a consequence of usage of the given work.
*/
package Proiect;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
/**
* This class displays a dialog box if the file needs to be saved
*
* @author Stefan Cosma
*
*/
public class needSave extends JFrame {
private static final long serialVersionUID = 1L;
public static ImageIcon getImageIcon(String name) {
return new ImageIcon(ClassLoader.getSystemResource(name));
}
public needSave() {
final JFrame needSave = new JFrame("Save file");
JPanel pan1 = new JPanel();
JPanel pan2 = new JPanel();
JPanel inpan1 = new JPanel();
JPanel inpan2 = new JPanel();
JPanel pan3 = new JPanel();
JPanel pan4 = new JPanel();
ComponentMover cm = new ComponentMover();
cm.registerComponent(needSave);
JLabel title = new JLabel("");
JButton exit = new JButton("");
JButton okB = new JButton("Ok");
JButton cancelB = new JButton("Exit");
JLabel text = new JLabel("Do you want to save the file before exit?");
needSave.setLayout(new BorderLayout());
pan1.setLayout(new FlowLayout());
pan2.setLayout(new BorderLayout());
inpan1.setLayout(new GridBagLayout());
inpan2.setLayout(new FlowLayout());
pan3.setLayout(new FlowLayout());
pan4.setLayout(new FlowLayout());
needSave.add(pan3, BorderLayout.EAST);
needSave.add(pan1, BorderLayout.NORTH);
pan1.add(title);
pan1.add(Box.createHorizontalStrut(230));
pan1.add(exit);
needSave.add(pan2, BorderLayout.CENTER);
pan2.add(inpan1, BorderLayout.NORTH);
inpan1.add(text);
pan2.add(inpan2, BorderLayout.SOUTH);
inpan2.add(okB);
inpan2.add(Box.createHorizontalStrut(30));
inpan2.add(cancelB);
needSave.add(pan4, BorderLayout.WEST);
needSave.setSize(320, 120);
needSave.setLocationRelativeTo(Encrypter.Center);
needSave.setResizable(false);
needSave.setIconImage(Toolkit.getDefaultToolkit().getImage(
getClass().getClassLoader().getResource("assets/ico.png")));
needSave.setUndecorated(true);
needSave.getRootPane().setBorder(
BorderFactory.createLineBorder(Encrypter.color_black, 2));
needSave.setVisible(true);
Color color = Encrypter.color_light;
needSave.setBackground(color);
pan1.setBackground(color);
pan2.setBackground(color);
inpan1.setBackground(color);
inpan2.setBackground(color);
pan3.setBackground(color);
pan4.setBackground(color);
pan2.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
okB.setBackground(color);
okB.setBorder(BorderFactory.createEmptyBorder());
okB.setForeground(Encrypter.color_black);
okB.setFont(Encrypter.font16);
cancelB.setBackground(color);
cancelB.setBorder(BorderFactory.createEmptyBorder());
cancelB.setForeground(Encrypter.color_black);
cancelB.setFont(Encrypter.font16);
ImageIcon title_Icon = getImageIcon("assets/icons/save.png");
title.setIcon(title_Icon);
title.setForeground(Encrypter.color_black);
title.setFont(Encrypter.font16);
ImageIcon exit_icon = getImageIcon("assets/icons/exit.png");
exit.setBackground(Encrypter.color_light);
exit.setBorder(BorderFactory.createLineBorder(Encrypter.color_dark, 0));
exit.setForeground(Encrypter.color_black);
exit.setFont(Encrypter.font16);
exit.setIcon(exit_icon);
exit.setToolTipText("Exit");
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
needSave.dispose();
}
});
okB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
needSave.dispose();
save();
}
});
cancelB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
/**
* Save the source code
*/
public void save() {
try {
String s = Encrypter.TA.getText();
if (s.length() > 0) {
FileDialog fd = new FileDialog(this, "Save File",
FileDialog.SAVE);
if (Encrypter.inFile != null) {
fd.setFile(Encrypter.inFile
.getName()
.substring(0, Encrypter.inFile.getName().length() - 5)
.toString()
+ "_en.html");
} else {
fd.setFile("file_en.html");
}
fd.setDirectory(".");
fd.setVisible(true);
fd.setLocationRelativeTo(null);
String path = fd.getDirectory() + fd.getFile();
if (Encrypter.miOpenURL.isSelected()) {
if (fd.getFile() == null) {
System.exit(0);
} else {
BrowserLaunch.openURL(path);
}
}
if (fd.getFile() == null) {
return;
} else {
FileOutputStream fos = new FileOutputStream(path);
byte[] b = s.getBytes();
fos.write(b);
fos.close();
System.exit(0);
}
}
} catch (Exception e) {
}
}
}