2929import javax .swing .JSpinner ;
3030import javax .swing .JTextField ;
3131import javax .swing .SpinnerNumberModel ;
32+ import javax .swing .UIManager ;
3233import javax .swing .colorchooser .AbstractColorChooserPanel ;
3334import javax .swing .event .ChangeEvent ;
3435import javax .swing .event .ChangeListener ;
@@ -53,9 +54,11 @@ public class AddText extends BuildingBlock {
5354
5455 public AddText (Main Main ){
5556 super ("Text" , Main );
57+ setTextFont (Main .sig .newFont (UIManager .getDefaults ().getFont ("TabbedPane.font" ).getFamily (), "plain" , 12 , "#000000" ));
5658 }
5759 public AddText (String name ,Main Main ){
5860 super (name , Main );
61+ setTextFont (Main .sig .newFont (UIManager .getDefaults ().getFont ("TabbedPane.font" ).getFamily (), "plain" , 12 , "#000000" ));
5962 }
6063
6164 /**
@@ -175,6 +178,58 @@ protected JDialog settingsTextFont(JDialog owner){
175178 final JComboBox <String > fontBox = new JComboBox <String >(GraphicsEnvironment .getLocalGraphicsEnvironment ().getAvailableFontFamilyNames ());fontBox .setEditable (false );if (getTextFont () != null ){fontBox .addItem (getTextFont ().getFontname ());fontBox .setSelectedItem (getTextFont ().getFontname ());}
176179
177180 final JButton fontBut = new JButton ("..." );
181+
182+
183+ JPanel fontPane = new JPanel ();
184+ fontPane .setLayout (new BoxLayout (fontPane , BoxLayout .LINE_AXIS ));
185+ fontPane .setBorder (BorderFactory .createEmptyBorder (15 , 25 , 3 , 25 ));
186+ fontPane .add (Box .createHorizontalGlue ());
187+ //fontPane.add(fontLab);
188+ //fontPane.add(Box.createRigidArea(new Dimension(10, 0)));
189+ fontPane .add (fontBox );
190+ fontPane .add (Box .createRigidArea (new Dimension (10 , 0 )));
191+ fontPane .add (fontBut );
192+ fontPane .add (Box .createHorizontalGlue ());
193+
194+ //Size Style
195+ JLabel sizeLab = new JLabel ("Size:" );JLabel styleLab = new JLabel ("Style:" );
196+ final JSpinner sizeSpinner = new JSpinner ();
197+ sizeSpinner .setModel (new SpinnerNumberModel (12 ,1 ,999 ,1 ));if (getTextFont () != null ){sizeSpinner .setValue (getTextFont ().getSize ());}
198+ String [] styleStrings = { "Plain" , "Bold" , "Italic" };
199+ final JComboBox <String > styleBox = new JComboBox <String >(styleStrings );
200+ styleBox .setSelectedIndex (0 );
201+ if (getTextFont () != null ){
202+ switch (getTextFont ().getStyle ().toLowerCase ()){
203+ case "bold" :styleBox .setSelectedIndex (1 );break ;
204+ case "italic" :styleBox .setSelectedIndex (2 );break ;
205+ default :styleBox .setSelectedIndex (0 );break ;
206+ }
207+ }
208+
209+ JPanel sizePane = new JPanel ();
210+ sizePane .setLayout (new BoxLayout (sizePane , BoxLayout .LINE_AXIS ));
211+ sizePane .setBorder (BorderFactory .createEmptyBorder (15 , 25 , 3 , 25 ));
212+ sizePane .add (Box .createHorizontalGlue ());
213+ sizePane .add (sizeLab );
214+ sizePane .add (Box .createRigidArea (new Dimension (10 , 0 )));
215+ sizePane .add (sizeSpinner );
216+ sizePane .add (Box .createRigidArea (new Dimension (10 , 0 )));
217+ sizePane .add (styleLab );
218+ sizePane .add (Box .createRigidArea (new Dimension (10 , 0 )));
219+ sizePane .add (styleBox );
220+ sizePane .add (Box .createHorizontalGlue ());
221+
222+ //Color
223+ final JTextField colorField = new JTextField ();colorField .setText ("#000000" );if (getTextFont () != null ){colorField .setText (getTextFont ().getHexColor ());}
224+ JButton colorBut = new JButton ("Color:" );
225+
226+ fontBox .addItemListener (new ItemListener (){
227+ public void itemStateChanged (ItemEvent e ){
228+ setTextFont (Main .sig .newFont ((String )fontBox .getSelectedItem (), ((String )styleBox .getSelectedItem ()).toLowerCase (), (int )sizeSpinner .getValue (), colorField .getText ()));
229+ saveObject ();
230+ Main .ImageWindow .update ();
231+ }
232+ });
178233 fontBut .addActionListener (new ActionListener (){
179234 public void actionPerformed (ActionEvent e ){
180235 File dir = new File (System .getProperty ("user.dir" ) + "/fonts" );
@@ -210,6 +265,9 @@ public void actionPerformed(ActionEvent e){
210265 catch (IOException e1 ) {
211266 System .out .println ("!!COPY FAILED!!" );
212267 }
268+ setTextFont (Main .sig .newFont ((String )fontBox .getSelectedItem (), ((String )styleBox .getSelectedItem ()).toLowerCase (), (int )sizeSpinner .getValue (), colorField .getText ()));
269+ saveObject ();
270+ Main .ImageWindow .update ();
213271 }
214272 }
215273 }
@@ -220,49 +278,13 @@ public void actionPerformed(ActionEvent e){
220278 }
221279 }
222280 });
223-
224- JPanel fontPane = new JPanel ();
225- fontPane .setLayout (new BoxLayout (fontPane , BoxLayout .LINE_AXIS ));
226- fontPane .setBorder (BorderFactory .createEmptyBorder (15 , 25 , 3 , 25 ));
227- fontPane .add (Box .createHorizontalGlue ());
228- //fontPane.add(fontLab);
229- //fontPane.add(Box.createRigidArea(new Dimension(10, 0)));
230- fontPane .add (fontBox );
231- fontPane .add (Box .createRigidArea (new Dimension (10 , 0 )));
232- fontPane .add (fontBut );
233- fontPane .add (Box .createHorizontalGlue ());
234-
235- //Size Style
236- JLabel sizeLab = new JLabel ("Size:" );JLabel styleLab = new JLabel ("Style:" );
237- final JSpinner sizeSpinner = new JSpinner ();
238- sizeSpinner .setModel (new SpinnerNumberModel (12 ,1 ,999 ,1 ));if (getTextFont () != null ){sizeSpinner .setValue (getTextFont ().getSize ());}
239- String [] styleStrings = { "Plain" , "Bold" , "Italic" };
240- final JComboBox <String > styleBox = new JComboBox <String >(styleStrings );
241- styleBox .setSelectedIndex (0 );
242- if (getTextFont () != null ){
243- switch (getTextFont ().getStyle ().toLowerCase ()){
244- case "bold" :styleBox .setSelectedIndex (1 );break ;
245- case "italic" :styleBox .setSelectedIndex (2 );break ;
246- default :styleBox .setSelectedIndex (0 );break ;
247- }
248- }
249-
250- JPanel sizePane = new JPanel ();
251- sizePane .setLayout (new BoxLayout (sizePane , BoxLayout .LINE_AXIS ));
252- sizePane .setBorder (BorderFactory .createEmptyBorder (15 , 25 , 3 , 25 ));
253- sizePane .add (Box .createHorizontalGlue ());
254- sizePane .add (sizeLab );
255- sizePane .add (Box .createRigidArea (new Dimension (10 , 0 )));
256- sizePane .add (sizeSpinner );
257- sizePane .add (Box .createRigidArea (new Dimension (10 , 0 )));
258- sizePane .add (styleLab );
259- sizePane .add (Box .createRigidArea (new Dimension (10 , 0 )));
260- sizePane .add (styleBox );
261- sizePane .add (Box .createHorizontalGlue ());
262-
263- //Color
264- final JTextField colorField = new JTextField ();colorField .setText ("#000000" );if (getTextFont () != null ){colorField .setText (getTextFont ().getHexColor ());}
265- JButton colorBut = new JButton ("Color:" );
281+ styleBox .addItemListener (new ItemListener (){
282+ public void itemStateChanged (ItemEvent e ){
283+ setTextFont (Main .sig .newFont ((String )fontBox .getSelectedItem (), ((String )styleBox .getSelectedItem ()).toLowerCase (), (int )sizeSpinner .getValue (), colorField .getText ()));
284+ saveObject ();
285+ Main .ImageWindow .update ();
286+ }
287+ });
266288 colorBut .addActionListener (new ActionListener (){
267289 public void actionPerformed (ActionEvent e ){
268290 final JDialog colorD = new JDialog (d , "Font Color" , true );
@@ -284,6 +306,14 @@ public void actionPerformed(ActionEvent e){
284306 }
285307 cc .setChooserPanels (newcolorPanel );
286308 cc .setPreviewPanel (new JPanel ());
309+ cc .getSelectionModel ().addChangeListener (new ChangeListener (){
310+ public void stateChanged (ChangeEvent e ){
311+ colorField .setText (Main .toHexString (cc .getColor ()));
312+ setTextFont (Main .sig .newFont ((String )fontBox .getSelectedItem (), ((String )styleBox .getSelectedItem ()).toLowerCase (), (int )sizeSpinner .getValue (), Main .toHexString (cc .getColor ())));
313+ saveObject ();
314+ Main .ImageWindow .update ();
315+ }
316+ });
287317
288318 JPanel colorPane = new JPanel ();
289319 colorPane .setLayout (new BoxLayout (colorPane , BoxLayout .PAGE_AXIS ));
@@ -296,6 +326,7 @@ public void actionPerformed(ActionEvent e){
296326 public void actionPerformed (ActionEvent e ){
297327 //save and close
298328 colorField .setText (Main .toHexString (cc .getColor ()));
329+ setTextFont (Main .sig .newFont ((String )fontBox .getSelectedItem (), ((String )styleBox .getSelectedItem ()).toLowerCase (), (int )sizeSpinner .getValue (), Main .toHexString (cc .getColor ())));
299330 colorD .dispose ();
300331 }
301332 });
@@ -324,6 +355,13 @@ public void actionPerformed(ActionEvent e){
324355 colorD .setVisible (true );
325356 }
326357 });
358+ sizeSpinner .addChangeListener (new ChangeListener (){
359+ public void stateChanged (ChangeEvent e ){
360+ setTextFont (Main .sig .newFont ((String )fontBox .getSelectedItem (), ((String )styleBox .getSelectedItem ()).toLowerCase (), (int )sizeSpinner .getValue (), colorField .getText ()));
361+ saveObject ();
362+ Main .ImageWindow .update ();
363+ }
364+ });
327365
328366 JPanel colorPane = new JPanel ();
329367 colorPane .setLayout (new BoxLayout (colorPane , BoxLayout .LINE_AXIS ));
@@ -380,6 +418,7 @@ public void actionPerformed(ActionEvent e){
380418 contentPane .add (buttonPane , BorderLayout .PAGE_END );
381419
382420 //d.setPreferredSize(new Dimension(400,130));
421+
383422 d .setLocationRelativeTo (owner );
384423 d .pack ();
385424 d .setVisible (true );
@@ -396,6 +435,7 @@ public JDialog settingsDialog(final Frame owner){
396435 final int oldangdeg = getAngdeg ();
397436
398437 final JDialog d = new JDialog (owner , getClass ().getSimpleName ()+" Settings" , true );
438+ Main .ImageWindow .update ();
399439
400440 //Name
401441 JLabel text = new JLabel ("Name:" );
0 commit comments