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 worksTextEditor 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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classTextEditor.ListSearchTextFieldDocumentHandlerprotected classTextEditor.ListSelectionHandlerprotected classTextEditor.TextFieldFocusHandlerForTextSelectionprotected classTextEditor.TextFieldKeyHandlerForListSelectionUpDown-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description static intCANCEL_OPTIONReturn value fromshowDialog().protected intdialogResultValuestatic intERROR_OPTIONReturn value fromshowDialog().static intOK_OPTIONReturn value fromshowDialog().protected OKCancelApplyPanelokCancelApplyPanel-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
Constructor Summary
Constructors Constructor Description TextEditor()Constructs aJFontChooserobject.TextEditor(String[] fontSizeStrings)Constructs aJFontChooserobject using the given font size array.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddOKCancelApplyPanelActionListener(ActionListener actionListener)protected JDialogcreateDialog(Component parent, String title)protected String[]getFontFamilies()JList<String>getFontFamilyList()protected JPanelgetFontFamilyPanel()JTextFieldgetFontFamilyTextField()JList<String>getFontSizeList()protected JPanelgetFontSizePanel()JTextFieldgetFontSizeTextField()JList<String>getFontStyleList()protected String[]getFontStyleNames()protected JPanelgetFontStylePanel()JTextFieldgetFontStyleTextField()protected JPanelgetSamplePanel()JTextAreagetSampleTextField()FontgetSelectedFont()Get the selected font.StringgetSelectedFontFamily()Get the family name of the selected font.intgetSelectedFontSize()Get the size of the selected font.intgetSelectedFontStyle()Get the style of the selected font.StringgetVersionString()voidsetApplyEnabled(boolean applyEnabled)voidsetApplyVisible(boolean applyVisible)voidsetCancelEnabled(boolean cancelEnabled)voidsetCancelVisible(boolean cancelVisible)voidsetOKEnabled(boolean okEnabled)voidsetOKVisible(boolean okVisible)voidsetSampleTextField(String a)voidsetSelectedFont(Font font)Set the selected font.voidsetSelectedFontFamily(String name)Set the family name of the selected font.voidsetSelectedFontSize(int size)Set the size of the selected font.voidsetSelectedFontStyle(int style)Set the style of the selected font.voidsetSelectedSampleTextField(int size)Set the size of the selected font.intshowDialog(Component parent, String title)Show font selection dialog.protected voidupdateSampleFont()booleanwasApplyPressed()booleanwasOKPressed()-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
OK_OPTION
public static final int OK_OPTION
Return value fromshowDialog().
-
CANCEL_OPTION
public static final int CANCEL_OPTION
Return value fromshowDialog().
-
ERROR_OPTION
public static final int ERROR_OPTION
Return value fromshowDialog().
-
dialogResultValue
protected int dialogResultValue
-
okCancelApplyPanel
protected final OKCancelApplyPanel okCancelApplyPanel
-
-
Constructor Detail
-
TextEditor
public TextEditor()
Constructs aJFontChooserobject.
-
TextEditor
public TextEditor(String[] fontSizeStrings)
Constructs aJFontChooserobject using the given font size array.- Parameters:
fontSizeStrings- the array of font size string.
-
-
Method Detail
-
getFontFamilyTextField
public JTextField getFontFamilyTextField()
-
getFontStyleTextField
public JTextField getFontStyleTextField()
-
getFontSizeTextField
public JTextField getFontSizeTextField()
-
getSelectedFontFamily
public String getSelectedFontFamily()
Get the family name of the selected font.- Returns:
- the font family of the selected font.
- See Also:
setSelectedFontFamily(java.lang.String)
-
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:
Font.PLAIN,Font.BOLD,Font.ITALIC,setSelectedFontStyle(int)
-
getSelectedFontSize
public int getSelectedFontSize()
Get the size of the selected font.- Returns:
- the size of the selected font
- See Also:
setSelectedFontSize(int)
-
getSelectedFont
public Font getSelectedFont()
Get the selected font.- Returns:
- the selected font
- See Also:
setSelectedFont(java.awt.Font),Font
-
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:
getSelectedFontFamily()
-
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, orFont.BOLD|Font.ITALIC.- See Also:
Font.PLAIN,Font.BOLD,Font.ITALIC,getSelectedFontStyle()
-
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:
getSelectedFontSize()
-
setSelectedFontSize
public void setSelectedFontSize(int size)
Set the size of the selected font.- Parameters:
size- the size of the selected font- See Also:
getSelectedFontSize()
-
setSelectedFont
public void setSelectedFont(Font font)
Set the selected font.- Parameters:
font- the selected font- See Also:
getSelectedFont(),Font
-
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:
OK_OPTION,CANCEL_OPTION,ERROR_OPTION
-
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()
-
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()
-
-