Skip to content

Commit 20698cc

Browse files
authored
Merge pull request #24 from gpasents/master
Added Bold and Italic buttons
2 parents 180f1b6 + afc41ba commit 20698cc

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

icons/bold.png

946 Bytes
Loading

icons/italic.png

514 Bytes
Loading

src/simplejavatexteditor/UI.java

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* @modemail [email protected]
3232
* Removed unuse objects like container, Border emptyBorder
3333
* Removed unsused imports
34+
*
35+
* @Modifiedby Giorgos Pasentsis
36+
* @modemail [email protected]
3437
*/
3538
package simplejavatexteditor;
3639

@@ -55,9 +58,14 @@ public class UI extends JFrame implements ActionListener {
5558
private final JMenuItem newFile, openFile, saveFile, close, cut, copy, paste, clearFile, selectAll, quickFind,
5659
aboutMe, aboutSoftware, wordWrap;
5760
private final JToolBar mainToolbar;
58-
JButton newButton, openButton, saveButton, clearButton, quickButton, aboutMeButton, aboutButton, closeButton;
61+
JButton newButton, openButton, saveButton, clearButton, quickButton, aboutMeButton, aboutButton, closeButton, boldButton, italicButton;
5962
private final Action selectAllAction;
6063

64+
65+
//setup icons - Bold and Italic
66+
private final ImageIcon boldIcon = new ImageIcon("icons/bold.png");
67+
private final ImageIcon italicIcon = new ImageIcon("icons/italic.png");
68+
6169
// setup icons - File Menu
6270
private final ImageIcon newIcon = new ImageIcon("icons/new.png");
6371
private final ImageIcon openIcon = new ImageIcon("icons/open.png");
@@ -88,7 +96,7 @@ public class UI extends JFrame implements ActionListener {
8896
public UI() {
8997

9098
// Set the initial size of the window
91-
setSize(700, 500);
99+
setSize(800, 500);
92100

93101
// Set the title of the window
94102
setTitle("Untitled | " + SimpleJavaTextEditor.NAME);
@@ -101,9 +109,9 @@ public UI() {
101109

102110
// Set a default font for the TextArea
103111
textArea = new JTextArea("", 0, 0);
104-
textArea.setFont(new Font("Century Gothic", Font.BOLD, 12));
112+
textArea.setFont(new Font("Century Gothic", Font.PLAIN, 12));
105113
textArea.setTabSize(2);
106-
textArea.setFont(new Font("Century Gothic", Font.BOLD, 12));
114+
textArea.setFont(new Font("Century Gothic", Font.PLAIN, 12));
107115
textArea.setTabSize(2);
108116

109117
/* SETTING BY DEFAULT WORD WRAP ENABLED OR TRUE */
@@ -311,7 +319,18 @@ public void actionPerformed(ActionEvent ev) {
311319
closeButton.addActionListener(this);
312320
mainToolbar.add(closeButton);
313321
mainToolbar.addSeparator();
314-
322+
323+
boldButton = new JButton(boldIcon);
324+
boldButton.setToolTipText("Bold");
325+
boldButton.addActionListener(this);
326+
mainToolbar.add(boldButton);
327+
mainToolbar.addSeparator();
328+
329+
italicButton = new JButton(italicIcon);
330+
italicButton.setToolTipText("Italic");
331+
italicButton.addActionListener(this);
332+
mainToolbar.add(italicButton);
333+
mainToolbar.addSeparator();
315334
/**
316335
* **************** FONT SETTINGS SECTION **********************
317336
*/
@@ -485,8 +504,25 @@ else if (e.getSource() == openFile || e.getSource() == openButton) {
485504
} // If the source of the event was the "save" option
486505
else if (e.getSource() == saveFile || e.getSource() == saveButton) {
487506
saveFile();
507+
}// If the source of the event was the "Bold" button
508+
else if (e.getSource() == boldButton) {
509+
if (textArea.getFont().getStyle() == Font.BOLD){
510+
textArea.setFont(textArea.getFont().deriveFont(Font.PLAIN));
511+
512+
}
513+
else{
514+
textArea.setFont(textArea.getFont().deriveFont(Font.BOLD));
515+
}
516+
}// If the source of the event was the "Italic" button
517+
else if (e.getSource() == italicButton) {
518+
if (textArea.getFont().getStyle() == Font.ITALIC){
519+
textArea.setFont(textArea.getFont().deriveFont(Font.PLAIN));
520+
521+
}
522+
else{
523+
textArea.setFont(textArea.getFont().deriveFont(Font.ITALIC));
524+
}
488525
}
489-
490526
// Clear File (Code)
491527
if (e.getSource() == clearFile || e.getSource() == clearButton) {
492528

0 commit comments

Comments
 (0)