Class TextEditor

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
com.vividsolutions.jump.workbench.ui.TextEditor
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class TextEditor extends JComponent
Modified from http://jfontchooser.osdn.jp/site/jfontchooser/project-summary.html MIT/X common Licence, Copyright (c) 2004 Masahiko SAWAI - The panel gets Font and Text preview from a selected Text component - Preview panel works as text editor. Preview is saved as text - How it works
  TextEditor editor = new JFontChooser();
  editor.showDialog(Component.getParent(), "Title of this font/editor panel");
  
  // Optional, set font, font size, font style and preview text in the TextEditor from a JTextComponent
  //                                                                                    
  //   editor.setSelectedFont(JTextComponent.getFont());                            
  //   editor.setSelectedFontSize(JTextComponent.getFont().getSize());                   
  //   editor.setSelectedFontStyle(JTextComponent.getFont().getStyle());                   
  //   editor.setSelectedFontFamily(JTextComponent.getFont().getFamily());                  
  //   editor.setSampleTextField(JTextComponent.getText());                                

   if (editor.wasOKPressed()) {
       Font font = editor.getSelectedFont(); 
      System.out.println("Selected Font : " + font);
     
    // Optional, get modified text String from preview panel
    //                                    
    //  String string = editor.getSampleTextField().getText() 
    //  System.out.println("Selected modified text: "string);
      
   } else {
   reportNothingToUndoYet(null);
}

Author:
Giuseppe Aruta
See Also:
  • Field Details

  • Constructor Details

    • TextEditor

      public TextEditor()
      Constructs a JFontChooser object.
    • TextEditor

      public TextEditor(String[] fontSizeStrings)
      Constructs a JFontChooser object using the given font size array.
      Parameters:
      fontSizeStrings - the array of font size string.
  • Method Details

    • getFontFamilyTextField

      public JTextField getFontFamilyTextField()
    • getFontStyleTextField

      public JTextField getFontStyleTextField()
    • getFontSizeTextField

      public JTextField getFontSizeTextField()
    • getFontFamilyList

      public JList<String> getFontFamilyList()
    • getFontStyleList

      public JList<String> getFontStyleList()
    • getFontSizeList

      public JList<String> getFontSizeList()
    • getSelectedFontFamily

      public String getSelectedFontFamily()
      Get the family name of the selected font.
      Returns:
      the font family of the selected font.
      See Also:
    • getSelectedFontStyle

      public int getSelectedFontStyle()
      Get the style of the selected font.
      Returns:
      the style of the selected font. Font.PLAIN, Font.BOLD, Font.ITALIC, Font.BOLD|Font.ITALIC
      See Also:
    • getSelectedFontSize

      public int getSelectedFontSize()
      Get the size of the selected font.
      Returns:
      the size of the selected font
      See Also:
    • getSelectedFont

      public Font getSelectedFont()
      Get the selected font.
      Returns:
      the selected font
      See Also:
    • setSelectedFontFamily

      public void setSelectedFontFamily(String name)
      Set the family name of the selected font.
      Parameters:
      name - the family name of the selected font.
      See Also:
    • setSelectedFontStyle

      public void setSelectedFontStyle(int style)
      Set the style of the selected font.
      Parameters:
      style - the size of the selected font. Font.PLAIN, Font.BOLD, Font.ITALIC, or Font.BOLD|Font.ITALIC.
      See Also:
    • setSampleTextField

      public void setSampleTextField(String a)
    • setSelectedSampleTextField

      public void setSelectedSampleTextField(int size)
      Set the size of the selected font.
      Parameters:
      size - the size of the selected font
      See Also:
    • setSelectedFontSize

      public void setSelectedFontSize(int size)
      Set the size of the selected font.
      Parameters:
      size - the size of the selected font
      See Also:
    • setSelectedFont

      public void setSelectedFont(Font font)
      Set the selected font.
      Parameters:
      font - the selected font
      See Also:
    • getVersionString

      public String getVersionString()
    • showDialog

      public int showDialog(Component parent, String title)
      Show font selection dialog.
      Parameters:
      parent - Dialog's Parent component.
      Returns:
      OK_OPTION, CANCEL_OPTION or ERROR_OPTION
      See Also:
    • addOKCancelApplyPanelActionListener

      public void addOKCancelApplyPanelActionListener(ActionListener actionListener)
    • setApplyVisible

      public void setApplyVisible(boolean applyVisible)
    • setCancelVisible

      public void setCancelVisible(boolean cancelVisible)
    • setOKVisible

      public void setOKVisible(boolean okVisible)
    • setApplyEnabled

      public void setApplyEnabled(boolean applyEnabled)
    • setCancelEnabled

      public void setCancelEnabled(boolean cancelEnabled)
    • setOKEnabled

      public void setOKEnabled(boolean okEnabled)
    • wasApplyPressed

      public boolean wasApplyPressed()
    • wasOKPressed

      public boolean wasOKPressed()
    • createDialog

      protected JDialog createDialog(Component parent, String title)
    • updateSampleFont

      protected void updateSampleFont()
    • getFontFamilyPanel

      protected JPanel getFontFamilyPanel()
    • getFontStylePanel

      protected JPanel getFontStylePanel()
    • getFontSizePanel

      protected JPanel getFontSizePanel()
    • getSamplePanel

      protected JPanel getSamplePanel()
    • getSampleTextField

      public JTextArea getSampleTextField()
    • getFontFamilies

      protected String[] getFontFamilies()
    • getFontStyleNames

      protected String[] getFontStyleNames()