Package com.coswald.jtalker.gui
Class JTalkerMenuBar
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JMenuBar
-
- com.coswald.jtalker.gui.JTalkerMenuBar
-
- All Implemented Interfaces:
Initializable
,ImageObserver
,MenuContainer
,Serializable
,Accessible
,MenuElement
public class JTalkerMenuBar extends JMenuBar implements Initializable
A menu bar for the JTalker application. This menu bar has five menus: file, edit, view, settings, and help. Each menu is separated by the functions of the software (file managment, editing of content, viewing of content, specific settings of content, and help with use of content). This is fairly standard, and as such standard keyboard shortcuts are used for each action. When you display the menu bar, it will look like this:
- Since:
- JTalker 0.1.5
- Version:
- 0.0.1
- Author:
- C. William Oswald
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JMenuBar
JMenuBar.AccessibleJMenuBar
-
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 protected static Map<String,KeyStroke>
SHORTCUTS
A map between the name of a menu item and the keystroke that activates it.-
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 JTalkerMenuBar(JFrame frame, ColoredTextPane coloredTextPane, TextEntryPanel textEntryPanel, CanvasPanel canvasPanel)
Initializes the menu bar.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeConnection()
Closes the connection to the remove server.protected static JRadioButtonMenuItem
createButtonMenuItem(String name, boolean enabled, int accelerator, int mask, int mnemonic, ActionListener action)
Creates aJRadioButtonMenuItem
to be added to theJTalkerMenuBar
.protected static JMenuItem
createMenuItem(String name, int accelerator, int mask, int mnemonic, ActionListener action)
Creates aJMenuItem
to be added to theJTalkerMenuBar
.void
init()
Initializes each menu within the menu bar (file, edit, view, settings, and help).void
openConnection()
Opens a connection to a remote server.void
openKeyboardShortcuts()
Opens aJOptionPane
that displays the current keyboard shortcuts.void
printChat()
Sends the chat to the printer service.void
saveCanvas()
Saves the canvas as a PNG.void
saveChat()
Saves the chat to a file specified by the user.void
selectColoredTextPane()
Select all of the colored text pane's text.void
systemCopy()
A Java wrapper method for the system's "Copy" action.void
systemCut()
A Java wrapper method for the system's "Cut" action.void
systemPaste()
A Java wrapper method for the system's "Paste" action.-
Methods inherited from class javax.swing.JMenuBar
add, addNotify, getAccessibleContext, getComponent, getComponentAtIndex, getComponentIndex, getHelpMenu, getMargin, getMenu, getMenuCount, getSelectionModel, getSubElements, getUI, getUIClassID, isBorderPainted, isSelected, menuSelectionChanged, paintBorder, paramString, processKeyBinding, processKeyEvent, processMouseEvent, removeNotify, setBorderPainted, setHelpMenu, setMargin, setSelected, setSelectionModel, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, 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
-
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, 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
-
-
-
-
Constructor Detail
-
JTalkerMenuBar
public JTalkerMenuBar(JFrame frame, ColoredTextPane coloredTextPane, TextEntryPanel textEntryPanel, CanvasPanel canvasPanel)
Initializes the menu bar. The four components that are needed for the menu bar to work effectively are theJFrame
,ColoredTextPane
,TextEntryPanel
, and theCanvasPanel
. These things work in tandom to make sure each action described by this class is able to work.- Parameters:
frame
- The frame of the application.coloredTextPane
- The colored text pane of the application.textEntryPanel
- The text entry panel of the application.canvasPanel
- The canvas panel of the application.
-
-
Method Detail
-
createMenuItem
protected static JMenuItem createMenuItem(String name, int accelerator, int mask, int mnemonic, ActionListener action)
Creates aJMenuItem
to be added to theJTalkerMenuBar
. This will create a menu item using the given name, the keystroke, mnemonic, and action associated with it. When it creates the menu item, it will add the keystroke to amap
which can be used for later. If you wish to not add a keystroke, just make sure that the accelerator and/or mask variable is set to a number smaller than zero. However, the mnemonic is not optional.- Parameters:
name
- The title of the menu item.accelerator
- The accelerator of the menu item.mask
- The mask of the menu item.mnemonic
- The mnemonic of the menu item.action
- The action to do when the menu item is pressed.- Returns:
- The new menu item.
-
createButtonMenuItem
protected static JRadioButtonMenuItem createButtonMenuItem(String name, boolean enabled, int accelerator, int mask, int mnemonic, ActionListener action)
Creates aJRadioButtonMenuItem
to be added to theJTalkerMenuBar
. This will create a menu item using the given name, whether it is enabled, the keystroke, mnemonic, and action associated with it. When it creates the menu item, it will add the keystroke to amap
which can be used for later. If you wish to not add a keystroke, just make sure that the accelerator and/or mask variable is set to a number smaller than zero. However, the mnemonic is not optional.- Parameters:
name
- The title of the menu item.enabled
- Whether the radio button is on.accelerator
- The accelerator of the menu item.mask
- The mask of the menu item.mnemonic
- The mnemonic of the menu item.action
- The action to do when the menu item is pressed.- Returns:
- The new menu item.
-
init
public void init()
Initializes each menu within the menu bar (file, edit, view, settings, and help).- Specified by:
init
in interfaceInitializable
-
saveChat
public void saveChat()
Saves the chat to a file specified by the user. This will open up a file chooser, in which the user will select and confirm the saving of the file. This will save the escape codes found in the chat, even if the color mode for the chat is disabled.
-
saveCanvas
public void saveCanvas()
Saves the canvas as a PNG. This will open a file chooser in which the user can navigate to and save a png file that is described by the canvas object. It does so by creating aBufferedImage
, painting the graphics to that image, and then writing that image usingImageIO
.- See Also:
ImageIO
-
printChat
public void printChat()
Sends the chat to the printer service. This will print the colored text pane on a physical peice of paper (or to a file), exactly how the colored text pane determines it.
-
systemCopy
public void systemCopy()
A Java wrapper method for the system's "Copy" action.
-
systemCut
public void systemCut()
A Java wrapper method for the system's "Cut" action. This will not cut anything except for the text entry panel'sJTextField
.
-
systemPaste
public void systemPaste()
A Java wrapper method for the system's "Paste" action. This will automatically (and only) paste to the text entry panel'sJTextField
. This will not disable the normal paste; this will only work when this method is called (via a menu item for example).
-
selectColoredTextPane
public void selectColoredTextPane()
Select all of the colored text pane's text. This is a wrapper method forthis
method; however, it will also ensure that the selection can be seen after by requesting focus to the window manager.
-
openKeyboardShortcuts
public void openKeyboardShortcuts()
Opens aJOptionPane
that displays the current keyboard shortcuts.- See Also:
SHORTCUTS
-
openConnection
public void openConnection()
Opens a connection to a remote server.
-
closeConnection
public void closeConnection()
Closes the connection to the remove server.
-
-