Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/memoire/bu/BuFontChooser.java


1   /**
2    * @modification $Date: 2002/11/14 19:25:32 $
3    * @statut       unstable
4    * @file         BuFontChooser.java
5    * @version      0.36
6    * @author       Guillaume Desnoix
7    * @email        guillaume@desnoix.com
8    * @license      GNU General Public License 2 (GPL2)
9    * @copyright    1998-2001 Guillaume Desnoix
10   */
11  
12  package com.memoire.bu;
13  
14  import com.memoire.bu.*;
15  
16  import java.awt.*;
17  import java.awt.event.*;
18  import java.awt.image.*;
19  import javax.swing.*;
20  import javax.swing.border.*;
21  import javax.swing.event.*;
22  
23  /**
24   * A simple font chooser.
25   */
26  
27  public class BuFontChooser
28         extends BuDialog
29         implements ActionListener, ListSelectionListener
30  {
31    protected BuButton    btValider_;
32    protected BuButton    btAnnuler_;
33    protected BuEmptyList ltFamille_;
34    protected BuEmptyList ltTaille_;
35    protected BuCheckBox  cbGras_;
36    protected BuCheckBox  cbItalique_;
37    protected BuCheckBox  cbSouligne_;
38    protected BuTextField tfExemple_;
39  
40    public BuFontChooser(BuCommonInterface      _parent,
41             BuInformationsSoftware _isoft,
42             String                 _title,
43             Font                   _value)
44    {
45      super(_parent,_isoft,_title);
46  
47      tfExemple_.setText("ABC abc 123");
48  
49      if(_value==null) _value=new Font("SansSerif",Font.PLAIN,12);
50      valeur_=_value;
51  
52      String f=valeur_.getName();
53      String s=""+valeur_.getSize();
54      if(f==null) { f="SansSerif"; s="12"; }
55      ltFamille_.setSelectedValue(f,true);
56      ltTaille_ .setSelectedValue(s,true);
57      
58      BuPanel pnb=new BuPanel();
59      pnb.setLayout(new BuButtonLayout());
60      //new FlowLayout(FlowLayout.RIGHT));
61  
62      btValider_=new BuButton(BuLib.loadToolCommandIcon("VALIDER"),
63             BuResource.BU.getString("Valider"));
64      btValider_.addActionListener(this);
65      getRootPane().setDefaultButton(btValider_);
66      pnb.add(btValider_);
67  
68      btAnnuler_=new BuButton(BuLib.loadToolCommandIcon("ANNULER"),
69             BuResource.BU.getString("Annuler"));
70      btAnnuler_.addActionListener(this);
71      pnb.add(btAnnuler_);
72  
73      content_.add(pnb,BuBorderLayout.SOUTH);
74    }
75  
76    public JComponent getComponent()
77    {
78      String[] FAMILLES=new String[]
79      {"SansSerif","Serif","Monospaced" }; //,"Dialog", "Input" };
80  
81      String[] TAILLES =new String[]
82      { "6","8","10","12","14","16","18","20","24","28","32","36","48","72" };
83  
84      ltFamille_=new BuEmptyList();
85      ltTaille_ =new BuEmptyList();
86      ltFamille_.setListData(FAMILLES);
87      ltTaille_ .setListData(TAILLES );
88      ltFamille_.addListSelectionListener(this);
89      ltTaille_ .addListSelectionListener(this);
90  
91      cbGras_    =new BuCheckBox("Bold");
92      cbItalique_=new BuCheckBox("Italic");
93      cbSouligne_=new BuCheckBox("Underlined");
94      cbGras_    .addActionListener(this);
95      cbItalique_.addActionListener(this);
96      cbSouligne_.addActionListener(this);
97      cbSouligne_.setEnabled(false);
98  
99      BuPanel s=new BuPanel();
100     s.setLayout(new BuVerticalLayout(5,true,false));
101     s.add(cbGras_);
102     s.add(cbItalique_);
103     s.add(cbSouligne_);
104 
105     BuPanel q=new BuPanel();
106     q.setLayout(new BuGridLayout(3,5,5,true,true));
107     q.add(new BuScrollPane(ltFamille_));
108     q.add(s);
109     q.add(new BuScrollPane(ltTaille_));
110 
111     tfExemple_=new BuTextField();
112     tfExemple_.setPreferredSize(new Dimension(200,100));
113 
114     BuPanel p=new BuPanel();
115     p.setLayout(new BuVerticalLayout(5,true,true));
116     p.setBorder(new EmptyBorder(5,5,5,5));
117     p.add(q);
118     p.add(tfExemple_);
119     p.add(new BuPanel());
120     return p;
121   }
122 
123   private final Font value()
124   {
125     Font r=null;
126 
127     try
128     {
129       r=new Font(""+ltFamille_.getSelectedValue(),
130      Font.PLAIN
131      | (cbGras_    .isSelected() ? Font.BOLD : 0)
132      | (cbItalique_.isSelected() ? Font.ITALIC : 0),
133      Integer.parseInt(""+ltTaille_.getSelectedValue()));
134     }
135     catch(Exception ex) { }
136 
137     return r;
138   }
139 
140   public void valueChanged(ListSelectionEvent _evt)
141   {
142     JComponent source=(JComponent)_evt.getSource();
143 
144     if((source==ltFamille_)||(source==ltTaille_))
145     {
146       valeur_=value();
147       tfExemple_.setFont(valeur_);
148     }
149   }
150 
151   public void actionPerformed(ActionEvent _evt)
152   {
153     JComponent source=(JComponent)_evt.getSource();
154 
155     if((source==cbGras_)||(source==cbItalique_))
156     {
157       valeur_=value();
158       tfExemple_.setFont(valeur_);
159     }
160 
161     if(source==btValider_)
162     {
163       reponse_=JOptionPane.OK_OPTION;
164       //valeur_ =tfValeur_.getText();
165       setVisible(false);
166     }
167 
168     if(source==btAnnuler_)
169     {
170       reponse_=JOptionPane.CANCEL_OPTION;
171       valeur_ =null;
172       setVisible(false);
173     }
174   }
175 
176   private Font valeur_;
177 
178   public Font getValue()
179     { return valeur_; }
180 
181   public void setValue(Font _value)
182   {
183     tfExemple_.setFont(_value);
184     valeur_=_value;
185   }
186 
187   public static void main(String[] _args)
188   {
189     new BuFontChooser(null,null,"test BuFontChooser",null)
190       .activate();
191   }
192 }