jcomponent.java
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 2,217 行 · 第 1/5 页
JAVA
2,217 行
/** * Override the default key dispatch system from Component to hook into * the swing {@link InputMap} / {@link ActionMap} system. * * See <a * href="http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html">this * report</a> for more details, it's somewhat complex. */ protected void processKeyEvent(KeyEvent e) { processComponentKeyEvent(e); // FIXME: this needs to be elaborated significantly, to do all the // focus / ancestor / window searching for the various binding modes. if (! e.isConsumed() && processKeyBinding(KeyStroke.getKeyStrokeForEvent(e), e, WHEN_FOCUSED, e.getID() == KeyEvent.KEY_PRESSED)) e.consume(); } protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { if (isEnabled()) { Action act = null; InputMap map = getInputMap(condition); if (map != null) { Object cmd = map.get(ks); if (cmd != null) { if (cmd instanceof ActionListenerProxy) act = (Action) cmd; else act = (Action) getActionMap().get(cmd); } } if (act != null && act.isEnabled()) return SwingUtilities.notifyAction(act, ks, e, this, e.getModifiers()); } return false; } /** * Remove a keyboard action registry. * * @param stroke The keystroke to unregister * * @see #registerKeyboardAction * @see #getConditionForKeystroke * @see #resetKeyboardActiond */ public void unregisterKeyboardAction(KeyStroke aKeyStroke) { } /** * Reset all keyboard action registries. * * @see #registerKeyboardAction * @see #unregisterKeyboardAction * @see #getConditionForKeystroke */ public void resetKeyboardActions() { if (inputMap_whenFocused != null) inputMap_whenFocused.clear(); if (inputMap_whenAncestorOfFocused != null) inputMap_whenAncestorOfFocused.clear(); if (inputMap_whenInFocusedWindow != null) inputMap_whenInFocusedWindow.clear(); if (actionMap != null) actionMap.clear(); } /** * Mark the described region of this component as dirty in the current * {@link RepaintManager}. This will queue an asynchronous repaint using * the system painting thread in the near future. * * @param tm ignored * @param x coordinate of the region to mark as dirty * @param y coordinate of the region to mark as dirty * @param width dimension of the region to mark as dirty * @param height dimension of the region to mark as dirty */ public void repaint(long tm, int x, int y, int width, int height) { Rectangle dirty = new Rectangle(x, y, width, height); Rectangle vis = getVisibleRect(); dirty = dirty.intersection(vis); RepaintManager.currentManager(this).addDirtyRegion(this, dirty.x, dirty.y, dirty.width, dirty.height); } /** * Mark the described region of this component as dirty in the current * {@link RepaintManager}. This will queue an asynchronous repaint using * the system painting thread in the near future. * * @param r The rectangle to mark as dirty */ public void repaint(Rectangle r) { repaint((long) 0, (int) r.getX(), (int) r.getY(), (int) r.getWidth(), (int) r.getHeight()); } /** * Request focus on the default component of this component's {@link * FocusTraversalPolicy}. * * @return The result of {@link #requestFocus} * * @deprecated Use {@link #requestFocus()} on the default component provided from * the {@link FocusTraversalPolicy} instead. */ public boolean requestDefaultFocus() { return false; } /** * Queue a an invalidation and revalidation of this component, using * {@link RepaintManager#addInvalidComponent}. */ public void revalidate() { invalidate(); RepaintManager.currentManager(this).addInvalidComponent(this); } /** * Calls <code>scrollRectToVisible</code> on the component's parent. * Components which can service this call should override. * * @param r The rectangle to make visible */ public void scrollRectToVisible(Rectangle r) { Component p = getParent(); if (p instanceof JComponent) ((JComponent) p).scrollRectToVisible(r); } /** * Set the value of the {@link #alignmentX} property. * * @param a The new value of the property */ public void setAlignmentX(float a) { alignmentX = a; } /** * Set the value of the {@link #alignmentY} property. * * @param a The new value of the property */ public void setAlignmentY(float a) { alignmentY = a; } /** * Set the value of the {@link #autoscrolls} property. * * @param a The new value of the property */ public void setAutoscrolls(boolean a) { autoscrolls = a; } /** * Set the value of the {@link #debugGraphicsOptions} property. * * @param debugOptions The new value of the property */ public void setDebugGraphicsOptions(int debugOptions) { debugGraphicsOptions = debugOptions; } /** * Set the value of the {@link #doubleBuffered} property. * * @param db The new value of the property */ public void setDoubleBuffered(boolean db) { doubleBuffered = db; } /** * Set the value of the {@link #enabled} property, revalidate * and repaint this component. * * @param enable The new value of the property */ public void setEnabled(boolean enable) { boolean oldEnabled = isEnabled(); super.setEnabled(enable); firePropertyChange("enabeld", oldEnabled, enable); revalidate(); repaint(); } /** * Set the value of the {@link #font} property, revalidate * and repaint this component. * * @param f The new value of the property */ public void setFont(Font f) { super.setFont(f); revalidate(); repaint(); } /** * Set the value of the {@link #background} property, revalidate * and repaint this component. * * @param bg The new value of the property */ public void setBackground(Color bg) { super.setBackground(bg); revalidate(); repaint(); } /** * Set the value of the {@link #foreground} property, revalidate * and repaint this component. * * @param fg The new value of the property */ public void setForeground(Color fg) { super.setForeground(fg); revalidate(); repaint(); } /** * Set the value of the {@link #maximumSize} property, revalidate * and repaint this component. * * @param max The new value of the property */ public void setMaximumSize(Dimension max) { Dimension oldMaximumSize = maximumSize; maximumSize = max; firePropertyChange("maximumSize", oldMaximumSize, maximumSize); revalidate(); repaint(); } /** * Set the value of the {@link #minimumSize} property, revalidate * and repaint this component. * * @param min The new value of the property */ public void setMinimumSize(Dimension min) { Dimension oldMinimumSize = minimumSize; minimumSize = min; firePropertyChange("minimumSize", oldMinimumSize, minimumSize); revalidate(); repaint(); } /** * Set the value of the {@link #preferredSize} property, revalidate * and repaint this component. * * @param pref The new value of the property */ public void setPreferredSize(Dimension pref) { Dimension oldPreferredSize = preferredSize; preferredSize = pref; firePropertyChange("preferredSize", oldPreferredSize, preferredSize); } /** * Set the specified component to be the next component in the * focus cycle, overriding the {@link FocusTraversalPolicy} for * this component. * * @param aComponent The component to set as the next focusable * * @deprecated Use FocusTraversalPolicy instead */ public void setNextFocusableComponent(Component aComponent) { } /** * Set the value of the {@link #requestFocusEnabled} property. * * @param e The new value of the property */ public void setRequestFocusEnabled(boolean e) { requestFocusEnabled = e; } /** * Get the value of the {@link #transferHandler} property. * * @return The current value of the property * * @see ComponentUI#setTransferHandler */ public TransferHandler getTransferHandler() { return transferHandler; } /** * Set the value of the {@link #transferHandler} property. * * @param newHandler The new value of the property * * @see ComponentUI#getTransferHandler */ public void setTransferHandler(TransferHandler newHandler) { if (transferHandler == newHandler) return; TransferHandler oldHandler = transferHandler; transferHandler = newHandler; firePropertyChange("transferHandler", oldHandler, newHandler); } /** * Set the value of the {@link #opaque} property, revalidate and repaint * this component. * * @param isOpaque The new value of the property * * @see ComponentUI#update */ public void setOpaque(boolean isOpaque) { boolean oldOpaque = opaque; opaque = isOpaque; firePropertyChange("opaque", oldOpaque, opaque); revalidate(); repaint(); } /** * Set the value of the visible property, and revalidate / repaint the * component. * * @param v The new value of the property */ public void setVisible(boolean v) { super.setVisible(v); revalidate(); repaint(); } /** * Call {@link paint}. * * @param g The graphics context to paint into */ public void update(Graphics g) { paint(g); } /** * Get the value of the UIClassID property. This property should be a key * in the {@link UIDefaults} table managed by {@link UIManager}, the * value of which is the name of a class to load for the component's * {@link ui} property. * * @return A "symbolic" name which will map to a class to use for the * component's UI, such as <code>"ComponentUI"</code> * * @see #setUI * @see #updateUI */ public String getUIClassID() { return "ComponentUI"; } /** * Install a new UI delegate as the component's {@link ui} property. In * the process, this will call {@link ComponentUI.uninstallUI} on any * existing value for the {@link ui} property, and {@link * ComponentUI.installUI} on the new UI delegate. * * @param newUI The new UI delegate to install * * @see #updateUI * @see #getUIClassID */ protected void setUI(ComponentUI newUI) { if (ui != null) ui.uninstallUI(this); ComponentUI oldUI = ui; ui = newUI; if (ui != null) ui.installUI(this); firePropertyChange("UI", oldUI, newUI); revalidate(); repaint(); } /** * This method should be overridden in subclasses. In JComponent, the * method does nothing. In subclasses, it should a UI delegate * (correspond
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?