Skip to content

Commit a7ffa40

Browse files
committed
uploaded v1
1 parent 8d77ffd commit a7ffa40

21 files changed

+2390
-0
lines changed

src/dialogs/JFontDialog$1.class

847 Bytes
Binary file not shown.

src/dialogs/JFontDialog.class

6.09 KB
Binary file not shown.

src/dialogs/JFontDialog.java

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
/* Copyright (C) 2018 Barış Meral
2+
3+
This program is free software: you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation, either version 3 of the License, or
6+
(at your option) any later version.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program. If not, see <https://www.gnu.org/licenses/>.
15+
*/
16+
17+
package dialogs;
18+
19+
import javax.swing.*;
20+
import javax.swing.border.LineBorder;
21+
import javax.swing.border.TitledBorder;
22+
import javax.swing.event.ListSelectionEvent;
23+
import javax.swing.event.ListSelectionListener;
24+
import java.awt.*;
25+
import java.awt.event.*;
26+
import dialogs.*;
27+
28+
/**
29+
* @author Baris Meral
30+
* @version 1.1
31+
* @see java.awt.event.ActionListener
32+
* @see java.util.EventListener
33+
* @see javax.swing.event.ListSelectionListener
34+
* <b>its usage is as follows</b>
35+
* <pre>
36+
* {@code
37+
*
38+
* JTexarea textarea = new JTextarea(); // or JTextField or JLabel
39+
*
40+
* JFontDialog fontDialog = new JfontDialog(textarea);
41+
*
42+
* }
43+
* </pre>
44+
*
45+
*
46+
*/
47+
public class JFontDialog implements ListSelectionListener,ActionListener {
48+
49+
private static JFrame dialogFrame;
50+
private static JPanel fontNamePanel,fontTypePanel,fontSizePanel,buttonPanel,samplePanel;
51+
private static JList<String> fontNameList,fontTypeList,fontSizeList;
52+
private static JScrollPane fontPane,sizePane;
53+
private static JLabel sampleLabel = new JLabel("Sample..."),fontLabel,typeLabel,sizeLabel;
54+
private static JButton okButton,cancelButton;
55+
private static JSeparator separator;
56+
private static String[] graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
57+
String[] fontTypeArray,fontSizeArray;
58+
private static Font oldFont = null;
59+
private static boolean cancel=false;
60+
61+
/**
62+
* @param textArea
63+
*
64+
*/
65+
public JFontDialog(JTextArea textArea){
66+
67+
createDialog(textArea);
68+
69+
oldFont = textArea.getFont();
70+
}
71+
72+
/**
73+
* <b>Created Dialog Window</b>
74+
* @param textArea
75+
*/
76+
private void createDialog(JTextArea textArea){
77+
78+
dialogFrame = new JFrame("Font Dialog");
79+
dialogFrame.setLocationRelativeTo(null);
80+
dialogFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
81+
dialogFrame.setSize(430,440);
82+
dialogFrame.setResizable(false);
83+
dialogFrame.setLayout(null);
84+
85+
setLists();
86+
createButton();
87+
setPanels();
88+
89+
dialogFrame.add(fontNamePanel);
90+
dialogFrame.add(fontTypePanel);
91+
dialogFrame.add(fontSizePanel);
92+
dialogFrame.add(samplePanel);
93+
dialogFrame.add(separator);
94+
dialogFrame.add(buttonPanel);
95+
dialogFrame.setVisible(true);
96+
97+
dialogFrame.addWindowListener(new WindowAdapter() {
98+
@Override
99+
public void windowClosed(WindowEvent e) {
100+
101+
if (cancel==true){
102+
textArea.setFont(oldFont);
103+
}
104+
else if (cancel==false){
105+
textArea.setFont(getFont());
106+
}
107+
}
108+
});
109+
}
110+
111+
/**
112+
* <b>Created and Set JList Components</b>
113+
*/
114+
private void setLists(){
115+
116+
fontSizeArray = new String[29];
117+
for (int i = 6,j=0; i<=62;i+=2,j++)
118+
fontSizeArray[j]=String.valueOf(i);
119+
120+
fontSizeList = new JList<>(fontSizeArray);
121+
fontSizeList.setSelectionMode(0);
122+
fontSizeList.setSelectedIndex(16);
123+
fontSizeList.addListSelectionListener(this);
124+
fontSizeList.setFont(new Font("Arial",Font.CENTER_BASELINE,16));
125+
126+
127+
graphicsEnvironment[0] = "Adobe";
128+
fontNameList = new JList<>(graphicsEnvironment);
129+
fontNameList.setSelectionMode(0);
130+
fontNameList.setSelectedIndex(3);
131+
fontNameList.addListSelectionListener(this);
132+
fontNameList.setFont(new Font("Arial",Font.CENTER_BASELINE,16));
133+
134+
fontTypeArray = new String[]{"Plain", "Bold", "Italic"};
135+
fontTypeList = new JList<>(fontTypeArray);
136+
fontTypeList.setBorder(new LineBorder(Color.BLACK,1));
137+
fontTypeList.setSelectionMode(0);
138+
fontTypeList.setSelectedIndex(1);
139+
fontTypeList.addListSelectionListener(this);
140+
fontTypeList.setFont(new Font("Arial",Font.CENTER_BASELINE,16));
141+
142+
}
143+
144+
/**
145+
* <b>Created and sey Panels for Components</b>
146+
*
147+
*/
148+
private void setPanels(){
149+
150+
fontLabel = new JLabel("Fonts: ");
151+
fontLabel.setFont(new Font("Arial",Font.CENTER_BASELINE,14));
152+
fontNamePanel = new JPanel(new BorderLayout());
153+
fontPane = new JScrollPane(fontNameList);
154+
fontNamePanel.add(fontLabel,BorderLayout.NORTH);
155+
fontNamePanel.add(fontPane,BorderLayout.CENTER);
156+
fontNamePanel.setBounds(30,20,220,200);
157+
158+
typeLabel = new JLabel("Type: ");
159+
typeLabel.setFont(new Font("Arial",Font.CENTER_BASELINE,14));
160+
fontTypePanel = new JPanel(new BorderLayout());
161+
fontTypePanel.add(fontTypeList,BorderLayout.CENTER);
162+
fontTypePanel.add(typeLabel,BorderLayout.NORTH);
163+
fontTypePanel.setBounds(270,20,50,100);
164+
165+
sizeLabel = new JLabel("Sizes: ");
166+
sizeLabel.setFont(new Font("Arial",Font.CENTER_BASELINE,14));
167+
fontSizePanel = new JPanel(new BorderLayout());
168+
sizePane = new JScrollPane(fontSizeList);
169+
fontSizePanel.add(sizePane,BorderLayout.CENTER);
170+
fontSizePanel.add(sizeLabel,BorderLayout.NORTH);
171+
fontSizePanel.setBounds(340,20,50,200);
172+
173+
samplePanel = new JPanel();
174+
samplePanel.setBorder(new TitledBorder(new LineBorder(Color.BLACK,1),"Sample"));
175+
samplePanel.add(sampleLabel);
176+
samplePanel.setBounds(20,240,375,100);
177+
178+
separator = new JSeparator(JSeparator.HORIZONTAL);
179+
separator.setForeground(Color.gray);
180+
separator.setBounds(0,350,430,2);
181+
182+
buttonPanel = new JPanel(new BorderLayout());
183+
buttonPanel.add(okButton,BorderLayout.EAST);
184+
buttonPanel.add(cancelButton,BorderLayout.WEST);
185+
buttonPanel.setBounds(200,360,200,25);
186+
187+
188+
}
189+
190+
/**
191+
* <b>Created Buttons </b>
192+
*/
193+
private void createButton(){
194+
195+
okButton = new JButton("ok");
196+
okButton.setFont(new Font("Arial",Font.CENTER_BASELINE,18));
197+
okButton.addActionListener(this::actionPerformed);
198+
199+
cancelButton = new JButton("cancel");
200+
cancelButton.setFont(new Font("Arial",Font.CENTER_BASELINE,18));
201+
cancelButton.addActionListener(this::actionPerformed);
202+
203+
}
204+
205+
/**
206+
*
207+
* @return selected Font
208+
*/
209+
public static Font getFont(){
210+
return sampleLabel.getFont();
211+
}
212+
213+
@Override
214+
public void valueChanged(ListSelectionEvent e) {
215+
216+
sampleLabel.setFont(new Font(fontNameList.getSelectedValue(),fontTypeList.getSelectedIndex(),Integer.valueOf(fontSizeList.getSelectedValue())));
217+
}
218+
219+
@Override
220+
public void actionPerformed(ActionEvent e) {
221+
222+
223+
if (e.getSource()==okButton) {
224+
cancel=false;
225+
dialogFrame.dispose();
226+
}
227+
228+
else if (e.getSource()==cancelButton){
229+
cancel=true;
230+
dialogFrame.dispose();
231+
}
232+
233+
234+
}
235+
236+
237+
}

src/dialogs/Main$1.class

683 Bytes
Binary file not shown.

src/dialogs/Main.class

2.3 KB
Binary file not shown.

src/dialogs/Main.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package dialogs;
2+
import javax.swing.*;
3+
import javax.swing.border.LineBorder;
4+
import javax.swing.event.MenuEvent;
5+
import javax.swing.event.MenuListener;
6+
import java.awt.*;
7+
import dialogs.*;
8+
9+
10+
11+
12+
public class Main {
13+
14+
public static void main(String[] args) {
15+
16+
/*------------- JFrame Create and Set -------------*/
17+
JFrame frame = new JFrame();
18+
frame.setSize(960,640);
19+
frame.setDefaultCloseOperation(3);
20+
frame.setLocationRelativeTo(null);
21+
frame.setTitle("Demo");
22+
23+
24+
/*------------- JMenuBar Create and Set -------------*/
25+
JMenuBar menuBar = new JMenuBar();
26+
JMenu fontEditMenu = new JMenu("Font Select");
27+
menuBar.add(fontEditMenu);
28+
frame.setJMenuBar(menuBar);
29+
30+
/*------------- JTextArea Create and Set -------------*/
31+
JTextArea area = new JTextArea();
32+
area.setLineWrap(true);
33+
area.setBorder(new LineBorder(Color.BLACK,5));
34+
area.setCursor(Cursor.getDefaultCursor());
35+
Font defFont = new Font("Arial",Font.BOLD,30);
36+
area.setFont(defFont);
37+
38+
39+
frame.getContentPane().add(area,BorderLayout.CENTER);
40+
41+
java.awt.EventQueue.invokeLater(() -> frame.setVisible(true));
42+
43+
44+
45+
46+
47+
fontEditMenu.addMenuListener(new MenuListener() {
48+
@Override
49+
public void menuSelected(MenuEvent e) {
50+
51+
JFontDialog dialog = new JFontDialog(area);
52+
53+
}
54+
@Override
55+
public void menuDeselected (MenuEvent e){
56+
57+
}
58+
59+
@Override
60+
public void menuCanceled (MenuEvent e){
61+
62+
}
63+
64+
});
65+
66+
67+
68+
69+
70+
71+
72+
}
73+
}

src/dialogs/doc/allclasses-frame.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<!-- NewPage -->
3+
<html lang="tr">
4+
<head>
5+
<!-- Generated by javadoc (1.8.0_181) on Wed Aug 29 19:12:51 EET 2018 -->
6+
<title>All Classes</title>
7+
<meta name="date" content="2018-08-29">
8+
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
9+
<script type="text/javascript" src="script.js"></script>
10+
</head>
11+
<body>
12+
<h1 class="bar">All&nbsp;Classes</h1>
13+
<div class="indexContainer">
14+
<ul>
15+
<li><a href="dialogs/JFontDialog.html" title="class in dialogs" target="classFrame">JFontDialog</a></li>
16+
</ul>
17+
</div>
18+
</body>
19+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<!-- NewPage -->
3+
<html lang="tr">
4+
<head>
5+
<!-- Generated by javadoc (1.8.0_181) on Wed Aug 29 19:12:51 EET 2018 -->
6+
<title>All Classes</title>
7+
<meta name="date" content="2018-08-29">
8+
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
9+
<script type="text/javascript" src="script.js"></script>
10+
</head>
11+
<body>
12+
<h1 class="bar">All&nbsp;Classes</h1>
13+
<div class="indexContainer">
14+
<ul>
15+
<li><a href="dialogs/JFontDialog.html" title="class in dialogs">JFontDialog</a></li>
16+
</ul>
17+
</div>
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)