public class SwingLightPanel extends SimpleComponent implements InteractiveLightPanel
LightPanel pro prostředí Swing. Tato základní
implementace vykresluje pouze jednobarevné pozadí pro celý panel a, je-li
nastavené, pozadí v jednotlivých buňkách. Odvozené typy vykreslují na pozadí
buňky vlastní tvary, např. SwingCircleLightPanel vykreslí vepsaný
ovál.
Změnit vykreslovaný tvar v třídě Matrix lze změnou továrny na panely
voláním
Matrix.setLightPanelFactory.
javax.swing.JComponent.AccessibleJComponentjava.awt.Container.AccessibleAWTContainerjava.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategyInteractiveLightPanel.UserSelectionModelistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW| Constructor and Description |
|---|
SwingLightPanel(BasicLightMatrix matrix)
Vytvoří Swingový panel pro zadanou matici.
|
SwingLightPanel(BasicLightMatrix matrix,
java.lang.String title)
Vytvoří Swingový panel pro zadanou matici a nastaví titulek.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addChangeListener(EventListener<LightChangeEvent> listener)
Přidá posluchače změny.
|
void |
addKeyListener(EventListener<KeyEvent> listener)
Přidá posluchače klávesnice.
|
void |
addSelectListener(EventListener<LightSelectEvent> listener)
Přidá posluchače výběru.
|
protected int |
getCellCol(int x)
Převede souřadnici
x na sloupec. |
protected java.awt.Dimension |
getCellDimension()
Zjistí rozměr buňky.
|
protected java.awt.Point |
getCellLocation(int col,
int row)
Zjistí pozici levého horního rohu buňky.
|
protected java.awt.Rectangle |
getCellRectangle(int col,
int row)
Pro určenou buňku zjistí obalující obdélník.
|
protected int |
getCellRow(int y)
Převede souřadnici
y na řádek. |
protected int |
getCellX(int col)
Převede sloupec na levou souřadnici
x. |
protected int |
getCellY(int row)
Převede řádek na horní souřadnici
x. |
int |
getSelectedCol()
Zjistí vybraný sloupec.
|
int |
getSelectedRow()
Zjistí vybraný řádek.
|
protected void |
paintComponent(java.awt.Graphics g)
Vykreslí panel na zadanou grafiku.
|
protected void |
paintLight(java.awt.Graphics g,
java.awt.Rectangle rect,
int col,
int row,
LightColor color,
LightColor background)
Vykreslí jedno světlo na uvedené pozici.
|
void |
removeChangeListener(EventListener<LightChangeEvent> listener)
Odebere posluchače změny.
|
void |
removeKeyListener(EventListener<KeyEvent> listener)
Odebere posluchače klávesnice.
|
void |
removeSelectListener(EventListener<LightSelectEvent> listener)
Odebere posluchače výběru.
|
void |
select(int col,
int row)
Vybere buňku.
|
void |
setBackground(LightColor background)
Nastaví barvu pozadí celého panelu.
|
void |
setSelectionVisible(boolean visible)
Zapne nebo vypne zobrazování označení vybrané buňky.
|
void |
setUserSelectionMode(InteractiveLightPanel.UserSelectionMode mode)
Nastaví uživatelský režim výběru myší.
|
void |
unselect()
Zruší předchozí výběr.
|
getDefaultCloseOperation, getTitle, isAntialiasing, runInEDT, setAntialiasing, setDefaultCloseOperation, setTitle, showWindowaddAncestorListener, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printComponent, printChildren, 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, updateUIadd, 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, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, checkImage, checkImage, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetTitle, setTitle, showWindowpublic SwingLightPanel(BasicLightMatrix matrix, java.lang.String title)
matrix - matice, pro který se panel vytvářítitle - počáteční titulekpublic SwingLightPanel(BasicLightMatrix matrix)
nullový.matrix - matice, pro který se panel vytvářípublic void setBackground(LightColor background)
LightPanelsetBackground in interface LightPanelbackground - barva pozadíprotected final void paintComponent(java.awt.Graphics g)
paintLight(java.awt.Graphics, java.awt.Rectangle, int, int, cz.gyarab.util.light.LightColor, cz.gyarab.util.light.LightColor), pro kterou vždy spočítá obdélník, do
které se má konkrétní buňka vykreslit. Souřadnice obdélníku jsou již
přepočítány do souřadného systému Swingu.
Po vykreslení buňky se okolo vybrané zobrazí tečkovaný obdélník světle šedé barvy, pokud je vykreslování povoleno.
Tato metoda je volána, kdykoliv je potřeba překreslit panel nebo jeho část. Nikdy není volána přímo, pouze v důsledku změny barvy světla, výběru světla nebo když to vyžaduje grafické rozhraní (např. po odkrytí plochy dříve zakryté jiným oknem).
Rozšiřující třídy by měly překrýt metodu paintLight(java.awt.Graphics, java.awt.Rectangle, int, int, cz.gyarab.util.light.LightColor, cz.gyarab.util.light.LightColor).
paintComponent in class SimpleComponentg - grafika, na kterou se komponenta kreslíprotected void paintLight(java.awt.Graphics g,
java.awt.Rectangle rect,
int col,
int row,
LightColor color,
LightColor background)
SwingLightPanel pouze vykresluje pozadí, v překrytých metodách by
tedy nejprve měl být zavolán super.paintLight() a pak vykresleno
v popředí příslušné světlo.
Kromě aktuální barvy je třeba všechny změny v grafice před návratem z metody uvést do původního stavu.
g - grafika, na kterou se kreslírect - obdélník odpovídající buňce světlacol - číslo sloupcerow - číslo řádkucolor - barva popředíbackground - barva pozadíprotected int getCellCol(int x)
x na sloupec.x - souřadniceprotected int getCellRow(int y)
y na řádek.y - souřadniceprotected int getCellX(int col)
x.col - sloupecxprotected int getCellY(int row)
x.row - řádekxprotected java.awt.Point getCellLocation(int col,
int row)
col - sloupecrow - řádekprotected java.awt.Dimension getCellDimension()
protected java.awt.Rectangle getCellRectangle(int col,
int row)
col - sloupecrow - řádekpublic int getSelectedCol()
InteractiveLightPanelgetSelectedCol in interface InteractiveLightPanelpublic int getSelectedRow()
InteractiveLightPanelgetSelectedRow in interface InteractiveLightPanelpublic void select(int col,
int row)
InteractiveLightPanelselect in interface InteractiveLightPanelcol - sloupecrow - řádekpublic void unselect()
InteractiveLightPanelunselect in interface InteractiveLightPanelpublic void setUserSelectionMode(InteractiveLightPanel.UserSelectionMode mode)
InteractiveLightPanelsetUserSelectionMode in interface InteractiveLightPanelmode - režimpublic void setSelectionVisible(boolean visible)
InteractiveLightPanelsetSelectionVisible in interface InteractiveLightPanelvisible - true při zobrazenípublic void addSelectListener(EventListener<LightSelectEvent> listener)
InteractiveLightPaneladdSelectListener in interface InteractiveLightPanellistener - posluchačInteractiveLightPanel.setUserSelectionMode(cz.gyarab.util.light.InteractiveLightPanel.UserSelectionMode),
InteractiveLightPanel.select(int, int),
LightSelectEventpublic void removeSelectListener(EventListener<LightSelectEvent> listener)
InteractiveLightPanelremoveSelectListener in interface InteractiveLightPanellistener - posluchačpublic void addChangeListener(EventListener<LightChangeEvent> listener)
InteractiveLightPaneladdChangeListener in interface InteractiveLightPanellistener - posluchačLightChangeEventpublic void removeChangeListener(EventListener<LightChangeEvent> listener)
InteractiveLightPanelremoveChangeListener in interface InteractiveLightPanellistener - posluchačpublic void addKeyListener(EventListener<KeyEvent> listener)
InteractiveLightPaneladdKeyListener in interface InteractiveLightPanellistener - posluchačKeyEventpublic void removeKeyListener(EventListener<KeyEvent> listener)
InteractiveLightPanelremoveKeyListener in interface InteractiveLightPanellistener - posluchač