This repository was archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisabledNote.java
More file actions
282 lines (217 loc) · 7.08 KB
/
DisabledNote.java
File metadata and controls
282 lines (217 loc) · 7.08 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.StyledEditorKit;
class DisabledNote implements ActionListener{
//Attributes
SimpleAttributeSet atrSet = new SimpleAttributeSet();
SimpleAttributeSet DBSet = new SimpleAttributeSet();
StyledDocument Doc;
Font taFont = new Font("Sans", 0, 16);
// Variables
Color dColor = Color.getHSBColor(255, 239, 175); // 80, 50, 20
Color sColor = Color.getHSBColor(80, 40, 30);
Color tColor = Color.getHSBColor(100, 0, 100);
// Buttons for edit panel
JButton deleteBtn;
JButton restoreBtn;
StringBuilder DBTEXT = new StringBuilder();
int DBTextIndex = 0;
int LIndex = 0;
// Frame
JFrame disabledLeafFrame;
// Test Area
JTextPane tArea;
// Panels
JPanel updatePanel;
String DBText;
// Testing Style doc
StyledDocument styledDocument;
private int currID;
private String title;
DisabledNote(int ID, String titleValue, String textValue) {
currID = ID;
DBTEXT.append(textValue);
title = titleValue;
disabledLeafFrame = new JFrame(titleValue);
disabledLeafFrame.setSize(250, 250);
disabledLeafFrame.setLayout(new BorderLayout());
disabledLeafFrame.setBackground(dColor);
disabledLeafFrame.setLocation(450, 50);
tArea =new JTextPane();
tArea.setEditorKit(new StyledEditorKit());
Doc = tArea.getStyledDocument();
tArea.setFont(taFont);
tArea.setBackground(new Color (254, 217, 183));
tArea.setBorder(new EmptyBorder(10, 10, 10, 10));
tArea.setSize(disabledLeafFrame.getWidth(), disabledLeafFrame.getHeight());
//update panel
updatePanel = new JPanel();
updatePanel.setLayout(new GridLayout(1,3));
updatePanel.setBackground(Notes.blu);
ImageIcon Delicon = new ImageIcon(getClass().getResource("\\img\\delIcon.png"));
deleteBtn = new JButton(Delicon);
deleteBtn.setBackground(Notes.blu);
deleteBtn.setFocusable(false);
deleteBtn.addActionListener(this);
ImageIcon saveicon = new ImageIcon(getClass().getResource("\\img\\saveimg.png"));
restoreBtn = new JButton(saveicon);
restoreBtn.setBackground(Notes.blu);
restoreBtn.setFocusable(false);
restoreBtn.addActionListener(this);
updatePanel.add(restoreBtn);
updatePanel.add(deleteBtn);
//removing the decorations from the db text
removeDecorations(DBTEXT.toString());
disabledLeafFrame.add(tArea, BorderLayout.CENTER);
disabledLeafFrame.add(updatePanel, BorderLayout.SOUTH);
disabledLeafFrame.setResizable(true);
disabledLeafFrame.setDefaultCloseOperation(closeOperation());
disabledLeafFrame.setVisible(true);
}
int closeOperation(){
disabledLeafFrame.setVisible(false);
disabledLeafFrame.dispose();
return 0;
}
@Override
public void actionPerformed(ActionEvent e) {
if( e.getSource()== restoreBtn)
{
new DB().updateRestore( currID,1, title, DBTEXT.toString());
closeOperation();
}else {
new DB().updateRestore( currID,2,title, DBTEXT.toString());
closeOperation();
}
// is restore
//2 is delete
}
void removeDecorations(String input){
System.out.println("TEXT FROM to DB -- "+input);
MutableAttributeSet normal = new SimpleAttributeSet();
StyleConstants.setForeground(normal, Color.black);
MutableAttributeSet bold = new SimpleAttributeSet();
StyleConstants.setBold(bold, true);
MutableAttributeSet italic = new SimpleAttributeSet();
StyleConstants.setItalic(italic, true);
MutableAttributeSet sThroug = new SimpleAttributeSet();
StyleConstants.setStrikeThrough(sThroug, true);
MutableAttributeSet uLine = new SimpleAttributeSet();
StyleConstants.setUnderline(uLine, true);
StringBuilder result = new StringBuilder(); // string builder
boolean attrP = false;
boolean isB = false;
boolean isI = false;
boolean isU = false;
boolean isS = false;
for(int cIndex = 0; cIndex < input.length()-1; cIndex++)
{
String key = String.valueOf( input.charAt(cIndex))+String.valueOf( input.charAt(cIndex+1));
char cChar = input.charAt(cIndex);
if(key.equals("**"))
{
if(attrP)
{
attrP = false;
isB = false;
}else {
isB = true;
attrP = true;
}
++cIndex;
}else if(key.equals("$$"))
{
if(attrP)
{
attrP = false;
isS = false;
}else {
isS = true;
attrP = true;
}
++cIndex;
}else if(key.equals("__"))
{
if(attrP)
{
attrP = false;
}else {
isI = true;
attrP = true;
}
++cIndex;
}else if(key.equals("~~"))
{
if(attrP)
{
attrP = false;
isU = false;
}else {
isU = true;
attrP = true;
}
++cIndex;
}
//checking the style and appending
if(true)
{
if( cChar != 36 && cChar != 42 && cChar != 95 && cChar != 126 )//(input.charAt(cIndex) >= 65 || input.charAt(cIndex) <= 90 || input.charAt(cIndex) >=97 || input.charAt(cIndex) <= 122)
{
if (isB)
{
append(Doc, bold, String.valueOf(input.charAt(cIndex)));
result.append(cChar);
}
else if(isI)
{
append(Doc, italic, String.valueOf(input.charAt(cIndex)));
result.append(cChar);
}
else if(isU)
{
append(Doc, uLine, String.valueOf(input.charAt(cIndex)));
result.append(cChar);
}
else if(isS)
{
append(Doc, sThroug, String.valueOf(input.charAt(cIndex)));
result.append(cChar);
}
else{
result.append(cChar);
System.out.println(input.charAt(cIndex) +" ---indexed");
append(Doc, normal, String.valueOf(input.charAt(cIndex)));
}
}
}
}
System.out.println("TEXT to Screen -- "+ result.toString());
//tArea.setText(result.toString());
tArea.setDocument(Doc);
tArea.setEditable(false);
tArea.repaint();
}
private void append(StyledDocument doc, AttributeSet style, String text) {
try {
Doc.insertString(doc.getLength(), text, style);
} catch (BadLocationException ex) {
ex.printStackTrace();
}
}
}