AMADEUS html plain
This sketchy text is generated by AMADEUS
import
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.colorchooser.*;
Javadoc
* See klass realiseerib fonti varvi ja suuruse valimise dialog.
* Kirjutatud SWINGi kasutades AMADEUS projekti jaoks.
*@author Aleksandr Jatsuk
*@version 1.0
public class JColorChooserDialog extends JDialog implements ActionListener
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
JComboBox combo1 = new JComboBox();
JComboBox combo2 = new JComboBox();
JTextField textField = new JTextField();
String[] fonts_names;
int fontStyle = 0;
String text ="The quick brown fox jump over the lazy dog.";
Color int_color, ext_color;
boolean cancel_pressed;
Font int_font, ext_font;
*
Javadoc
*Class JColorChooserDialog Costructor
*Creates a modal dialog with title "Font&Color Choose Dialog"
*with the specifed Frame as its owner.
*@param frame1 the Frame from which the dialog is displayed
public JColorChooserDialog(Frame frame1)
super(frame1, "Font&Color Choose Dialog",true);
final JButton bbutton = new JButton(new String("Bold"));
bbutton.addActionListener
bbutton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
switch (fontStyle){
case 0: fontStyle = 1;
break;
case 1: fontStyle = 0;
break;
case 2: fontStyle = 3;
break;
case 3: fontStyle = 2;
break;
}
refreshTextField();
}
}
);
final JButton ibutton = new JButton(new String("Italic"));
ibutton.addActionListener
ibutton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
switch (fontStyle){
case 0: fontStyle = 2;
break;
case 2: fontStyle = 0;
break;
case 1: fontStyle = 3;
break;
case 3: fontStyle = 1;
break;
}
refreshTextField();
}
}
);
final JButton okbutton = new JButton("Ok");
okbutton.addActionListener
okbutton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
ext_font = int_font;
ext_color = int_color;
setVisible(false);
cancel_pressed = false;
}
}
);
final JButton cancelbutton = new JButton("Cancel");
cancelbutton.addActionListener
cancelbutton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
cancel_pressed = true;
}
}
);
Set up color chooser for setting text color
final JColorChooser tcc = new JColorChooser(Default.foregroundColor);
tcc.getSelectionModel().addChangeListener
tcc.getSelectionModel().addChangeListener(
new ChangeListener() {
public void stateChanged(ChangeEvent e) {
Color newColor = tcc.getColor();
int_color = newColor;
textField.setForeground(newColor);
//System.out.println(textField.getFont().toString());
}
}
);
remove preview pannel from ColorChooser
tcc.setPreviewPanel(new JPanel());
Get aviable Font names
fonts_names = ge.getAvailableFontFamilyNames();
fill ComboBox with font names
* int i=0; i
combo1.addItem (fonts_names[i]);
Set Default font as defoult
combo1.setSelectedItem((String)"Default");
fill Combobox with font sizes
* int i=8;i<=72;i+=2
combo2.addItem (new Integer(i).toString());
Set 12 as default size
combo2.setSelectedItem((String)"12");
fill TextFiel with text
textField.setText(text);
Set as BackGround Color White
textField.setBackground(Color.white);
Set Text Field Non-Editable
textField.setEditable(false);
Get Content Pane
Container contentPane = getContentPane();
Set NULL layuot (w/o any layout manager)
contentPane.setLayout(null);
layout*
Add the components to the Dialog panel
contentPane.add(tcc);
contentPane.add(textField);
contentPane.add(combo2);
contentPane.add(combo1);
contentPane.add(bbutton);
contentPane.add(ibutton);
contentPane.add(okbutton);
contentPane.add(cancelbutton);
Add Actionlisteners to the ComboBoxes
combo1.addActionListener(this);
combo2.addActionListener(this);
Manual component layout (Layout Managers not used)
combo2.setBounds(0,0,50,20);
combo1.setBounds(55,0,200,20);
bbutton.setBounds(260,0,80,20);
ibutton.setBounds(345,0,80,20);
okbutton.setBounds(100,430,80,20);
cancelbutton.setBounds(250,430,80,20);
tcc.setBounds(0,25,430,300);
textField.setBounds(0,335,430,90);
Javadoc
*Shows Dialog
*@param ft curient font
*@param cl curient color
public void showDialog(Font ft,Color cl)
ext_font = ft;
ext_color = cl;
setSize(435,500);
setVisible(true);
Javadoc
public void actionPerformed(ActionEvent e)
Javadoc
public void setTextFieldValue(String r)
text = r;
refreshTextField();
public void refreshTextField()
int_font = new Font(fonts_names[combo1.getSelectedIndex()],fontStyle,new Integer((String) combo2.getSelectedItem()).intValue());
textField.setFont(int_font);
textField.setText(text);
//System.out.println(textField.getFont().toString());
Javadoc
* Returns choosed font
*@return choosed font
public Font getMyFont()
<======ext_font
Javadoc
* Returns choosed color
*@return choosed color
public Color getMyColor()
<======ext_color