下面列出了javax.swing.plaf.synth.SynthUI#sun.swing.DefaultLookup 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void focusLost(FocusEvent e) {
AbstractButton b = (AbstractButton) e.getSource();
JRootPane root = b.getRootPane();
if (root != null) {
JButton initialDefault = (JButton)root.getClientProperty("initialDefaultButton");
if (b != initialDefault) {
BasicButtonUI ui = (BasicButtonUI)BasicLookAndFeel.getUIOfType(
b.getUI(), BasicButtonUI.class);
if (ui != null && DefaultLookup.getBoolean(b, ui,
ui.getPropertyPrefix() +
"defaultButtonFollowsFocus", true)) {
root.setDefaultButton(initialDefault);
}
}
}
ButtonModel model = b.getModel();
model.setPressed(false);
model.setArmed(false);
b.repaint();
}
/**
* Invoked when the default button property has changed. This reloads
* the bindings from the defaults table with name
* <code>RootPane.defaultButtonWindowKeyBindings</code>.
*/
void updateDefaultButtonBindings(JRootPane root) {
InputMap km = SwingUtilities.getUIInputMap(root, JComponent.
WHEN_IN_FOCUSED_WINDOW);
while (km != null && !(km instanceof RootPaneInputMap)) {
km = km.getParent();
}
if (km != null) {
km.clear();
if (root.getDefaultButton() != null) {
Object[] bindings = (Object[])DefaultLookup.get(root, this,
"RootPane.defaultButtonWindowKeyBindings");
if (bindings != null) {
LookAndFeel.loadKeyBindings(km, bindings);
}
}
}
}
InputMap getInputMap(int condition) {
if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
return (InputMap)DefaultLookup.get(tree, this,
"Tree.ancestorInputMap");
}
else if (condition == JComponent.WHEN_FOCUSED) {
InputMap keyMap = (InputMap)DefaultLookup.get(tree, this,
"Tree.focusInputMap");
InputMap rtlKeyMap;
if (tree.getComponentOrientation().isLeftToRight() ||
((rtlKeyMap = (InputMap)DefaultLookup.get(tree, this,
"Tree.focusInputMap.RightToLeft")) == null)) {
return keyMap;
} else {
rtlKeyMap.setParent(keyMap);
return rtlKeyMap;
}
}
return null;
}
/**
* Creates an instance of BasicSplitPaneDivider. Registers this
* instance for mouse events and mouse dragged events.
*/
public BasicSplitPaneDivider(BasicSplitPaneUI ui) {
oneTouchSize = DefaultLookup.getInt(ui.getSplitPane(), ui,
"SplitPane.oneTouchButtonSize", ONE_TOUCH_SIZE);
oneTouchOffset = DefaultLookup.getInt(ui.getSplitPane(), ui,
"SplitPane.oneTouchButtonOffset", ONE_TOUCH_OFFSET);
centerOneTouchButtons = DefaultLookup.getBoolean(ui.getSplitPane(),
ui, "SplitPane.centerOneTouchButtons", true);
setLayout(new DividerLayout());
setBasicSplitPaneUI(ui);
orientation = splitPane.getOrientation();
setCursor((orientation == JSplitPane.HORIZONTAL_SPLIT) ?
Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR) :
Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
setBackground(UIManager.getColor("SplitPane.background"));
}
private void installDefaults2() {
editor.addMouseListener(dragListener);
editor.addMouseMotionListener(dragListener);
String prefix = getPropertyPrefix();
Caret caret = editor.getCaret();
if (caret == null || caret instanceof UIResource) {
caret = createCaret();
editor.setCaret(caret);
int rate = DefaultLookup.getInt(getComponent(), this, prefix + ".caretBlinkRate", 500);
caret.setBlinkRate(rate);
}
Highlighter highlighter = editor.getHighlighter();
if (highlighter == null || highlighter instanceof UIResource) {
editor.setHighlighter(createHighlighter());
}
TransferHandler th = editor.getTransferHandler();
if (th == null || th instanceof UIResource) {
editor.setTransferHandler(getTransferHandler());
}
}
InputMap getInputMap(int condition) {
if (condition == JComponent.WHEN_FOCUSED) {
InputMap keyMap = (InputMap)DefaultLookup.get(
list, this, "List.focusInputMap");
InputMap rtlKeyMap;
if (isLeftToRight ||
((rtlKeyMap = (InputMap)DefaultLookup.get(list, this,
"List.focusInputMap.RightToLeft")) == null)) {
return keyMap;
} else {
rtlKeyMap.setParent(keyMap);
return rtlKeyMap;
}
}
return null;
}
/**
* Returns the icon to use for the passed in type.
*/
protected Icon getIconForType(int messageType) {
if(messageType < 0 || messageType > 3)
return null;
String propertyName = null;
switch(messageType) {
case 0:
propertyName = "OptionPane.errorIcon";
break;
case 1:
propertyName = "OptionPane.informationIcon";
break;
case 2:
propertyName = "OptionPane.warningIcon";
break;
case 3:
propertyName = "OptionPane.questionIcon";
break;
}
if (propertyName != null) {
return (Icon)DefaultLookup.get(optionPane, this, propertyName);
}
return null;
}
InputMap getInputMap(int condition, JSlider slider) {
if (condition == JComponent.WHEN_FOCUSED) {
InputMap keyMap = (InputMap)DefaultLookup.get(slider, this,
"Slider.focusInputMap");
InputMap rtlKeyMap;
if (slider.getComponentOrientation().isLeftToRight() ||
((rtlKeyMap = (InputMap)DefaultLookup.get(slider, this,
"Slider.focusInputMap.RightToLeft")) == null)) {
return keyMap;
} else {
rtlKeyMap.setParent(keyMap);
return rtlKeyMap;
}
}
return null;
}
InputMap getInputMap(int condition) {
if (condition == JComponent.WHEN_FOCUSED) {
InputMap keyMap = (InputMap)DefaultLookup.get(
list, this, "List.focusInputMap");
InputMap rtlKeyMap;
if (isLeftToRight ||
((rtlKeyMap = (InputMap)DefaultLookup.get(list, this,
"List.focusInputMap.RightToLeft")) == null)) {
return keyMap;
} else {
rtlKeyMap.setParent(keyMap);
return rtlKeyMap;
}
}
return null;
}
InputMap getInputMap(int condition, JSlider slider) {
if (condition == JComponent.WHEN_FOCUSED) {
InputMap keyMap = (InputMap)DefaultLookup.get(slider, this,
"Slider.focusInputMap");
InputMap rtlKeyMap;
if (slider.getComponentOrientation().isLeftToRight() ||
((rtlKeyMap = (InputMap)DefaultLookup.get(slider, this,
"Slider.focusInputMap.RightToLeft")) == null)) {
return keyMap;
} else {
rtlKeyMap.setParent(keyMap);
return rtlKeyMap;
}
}
return null;
}
/**
* Creates an instance of BasicSplitPaneDivider. Registers this
* instance for mouse events and mouse dragged events.
*/
public BasicSplitPaneDivider(BasicSplitPaneUI ui) {
oneTouchSize = DefaultLookup.getInt(ui.getSplitPane(), ui,
"SplitPane.oneTouchButtonSize", ONE_TOUCH_SIZE);
oneTouchOffset = DefaultLookup.getInt(ui.getSplitPane(), ui,
"SplitPane.oneTouchButtonOffset", ONE_TOUCH_OFFSET);
centerOneTouchButtons = DefaultLookup.getBoolean(ui.getSplitPane(),
ui, "SplitPane.centerOneTouchButtons", true);
setLayout(new DividerLayout());
setBasicSplitPaneUI(ui);
orientation = splitPane.getOrientation();
setCursor((orientation == JSplitPane.HORIZONTAL_SPLIT) ?
Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR) :
Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
setBackground(UIManager.getColor("SplitPane.background"));
}
public void focusLost(FocusEvent e) {
AbstractButton b = (AbstractButton) e.getSource();
JRootPane root = b.getRootPane();
if (root != null) {
JButton initialDefault = (JButton)root.getClientProperty("initialDefaultButton");
if (b != initialDefault) {
BasicButtonUI ui = (BasicButtonUI)BasicLookAndFeel.getUIOfType(
b.getUI(), BasicButtonUI.class);
if (ui != null && DefaultLookup.getBoolean(b, ui,
ui.getPropertyPrefix() +
"defaultButtonFollowsFocus", true)) {
root.setDefaultButton(initialDefault);
}
}
}
ButtonModel model = b.getModel();
model.setPressed(false);
model.setArmed(false);
b.repaint();
}
/**
* Creates and returns a {@code Container} containing the buttons.
* The buttons are created by calling {@code getButtons}.
*
* @return a {@code Container} containing the buttons
*/
protected Container createButtonArea() {
JPanel bottom = new JPanel();
Border border = (Border)DefaultLookup.get(optionPane, this,
"OptionPane.buttonAreaBorder");
bottom.setName("OptionPane.buttonArea");
if (border != null) {
bottom.setBorder(border);
}
bottom.setLayout(new ButtonAreaLayout(
DefaultLookup.getBoolean(optionPane, this,
"OptionPane.sameSizeButtons", true),
DefaultLookup.getInt(optionPane, this, "OptionPane.buttonPadding",
6),
DefaultLookup.getInt(optionPane, this,
"OptionPane.buttonOrientation", SwingConstants.CENTER),
DefaultLookup.getBoolean(optionPane, this, "OptionPane.isYesLast",
false)));
addButtonComponents(bottom, getButtons(), getInitialValueIndex());
return bottom;
}
protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) {
Rectangle tabRect = rects[tabIndex];
String propKey = (isSelected ? "selectedLabelShift" : "labelShift");
int nudge = DefaultLookup.getInt(
tabPane, this, "TabbedPane." + propKey, 1);
switch (tabPlacement) {
case LEFT:
return nudge;
case RIGHT:
return -nudge;
case BOTTOM:
case TOP:
default:
return tabRect.width % 2;
}
}
/**
* Invoked when the default button property has changed. This reloads
* the bindings from the defaults table with name
* <code>RootPane.defaultButtonWindowKeyBindings</code>.
*/
void updateDefaultButtonBindings(JRootPane root) {
InputMap km = SwingUtilities.getUIInputMap(root, JComponent.
WHEN_IN_FOCUSED_WINDOW);
while (km != null && !(km instanceof RootPaneInputMap)) {
km = km.getParent();
}
if (km != null) {
km.clear();
if (root.getDefaultButton() != null) {
Object[] bindings = (Object[])DefaultLookup.get(root, this,
"RootPane.defaultButtonWindowKeyBindings");
if (bindings != null) {
LookAndFeel.loadKeyBindings(km, bindings);
}
}
}
}
InputMap getInputMap(int condition) {
if (condition == JComponent.WHEN_FOCUSED) {
InputMap keyMap = (InputMap)DefaultLookup.get(
list, this, "List.focusInputMap");
InputMap rtlKeyMap;
if (isLeftToRight ||
((rtlKeyMap = (InputMap)DefaultLookup.get(list, this,
"List.focusInputMap.RightToLeft")) == null)) {
return keyMap;
} else {
rtlKeyMap.setParent(keyMap);
return rtlKeyMap;
}
}
return null;
}
public void stateChanged(ChangeEvent e) {
if (e.getSource() instanceof JSpinner) {
JSpinner spinner = (JSpinner)e.getSource();
SpinnerUI spinnerUI = spinner.getUI();
if (DefaultLookup.getBoolean(spinner, spinnerUI,
"Spinner.disableOnBoundaryValues", false) &&
spinnerUI instanceof BasicSpinnerUI) {
BasicSpinnerUI ui = (BasicSpinnerUI)spinnerUI;
ui.updateEnabledState();
}
}
}
/**
* Configures any necessary colors/fonts for the specified button
* used representing the button portion of the optionpane.
*/
private void configureButton(JButton button) {
Font buttonFont = (Font)DefaultLookup.get(optionPane, this,
"OptionPane.buttonFont");
if (buttonFont != null) {
button.setFont(buttonFont);
}
}
/**
* Configures any necessary colors/fonts for the specified button
* used representing the button portion of the optionpane.
*/
private void configureButton(JButton button) {
Font buttonFont = (Font)DefaultLookup.get(optionPane, this,
"OptionPane.buttonFont");
if (buttonFont != null) {
button.setFont(buttonFont);
}
}
private void paintDropLine(Graphics g) {
JList.DropLocation loc = list.getDropLocation();
if (loc == null || !loc.isInsert()) {
return;
}
Color c = DefaultLookup.getColor(list, this, "List.dropLineColor", null);
if (c != null) {
g.setColor(c);
Rectangle rect = getDropLineRect(loc);
g.fillRect(rect.x, rect.y, rect.width, rect.height);
}
}
public void paint(Graphics g) {
Icon icon = frame.getFrameIcon();
if (icon == null) {
icon = (Icon)DefaultLookup.get(frame, frame.getUI(),
"InternalFrame.icon");
}
if (icon != null) {
// Resize to 16x16 if necessary.
if (icon instanceof ImageIcon && (icon.getIconWidth() > 16 || icon.getIconHeight() > 16)) {
Image img = ((ImageIcon)icon).getImage();
((ImageIcon)icon).setImage(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
}
icon.paintIcon(this, g, 0, 0);
}
}
/**
* Configures any necessary colors/fonts for the specified button
* used representing the button portion of the optionpane.
*/
private void configureButton(JButton button) {
Font buttonFont = (Font)DefaultLookup.get(optionPane, this,
"OptionPane.buttonFont");
if (buttonFont != null) {
button.setFont(buttonFont);
}
}
/**
* Messaged from installComponents to create a Container containing the
* body of the message. The icon is the created by calling
* <code>addIcon</code>.
*/
protected Container createMessageArea() {
JPanel top = new JPanel();
Border topBorder = (Border)DefaultLookup.get(optionPane, this,
"OptionPane.messageAreaBorder");
if (topBorder != null) {
top.setBorder(topBorder);
}
top.setLayout(new BorderLayout());
/* Fill the body. */
Container body = new JPanel(new GridBagLayout());
Container realBody = new JPanel(new BorderLayout());
body.setName("OptionPane.body");
realBody.setName("OptionPane.realBody");
if (getIcon() != null) {
JPanel sep = new JPanel();
sep.setName("OptionPane.separator");
sep.setPreferredSize(new Dimension(15, 1));
realBody.add(sep, BorderLayout.BEFORE_LINE_BEGINS);
}
realBody.add(body, BorderLayout.CENTER);
GridBagConstraints cons = new GridBagConstraints();
cons.gridx = cons.gridy = 0;
cons.gridwidth = GridBagConstraints.REMAINDER;
cons.gridheight = 1;
cons.anchor = DefaultLookup.getInt(optionPane, this,
"OptionPane.messageAnchor", GridBagConstraints.CENTER);
cons.insets = new Insets(0,0,3,0);
addMessageComponents(body, cons, getMessage(),
getMaxCharactersPerLineCount(), false);
top.add(realBody, BorderLayout.CENTER);
addIcon(top);
return top;
}
private Border getNoFocusBorder() {
Border border = DefaultLookup.getBorder(this, ui, "Table.cellNoFocusBorder");
if (System.getSecurityManager() != null) {
if (border != null) return border;
return SAFE_NO_FOCUS_BORDER;
} else if (border != null) {
if (noFocusBorder == null || noFocusBorder == DEFAULT_NO_FOCUS_BORDER) {
return border;
}
}
return noFocusBorder;
}
/**
* Get the InputMap to use for the UI.
*/
InputMap getInputMap() {
InputMap map = new InputMapUIResource();
InputMap shared =
(InputMap)DefaultLookup.get(editor, this,
getPropertyPrefix() + ".focusInputMap");
if (shared != null) {
map.setParent(shared);
}
return map;
}
/**
* Paints the background of the currently selected item.
*
* @param g an instance of {@code Graphics}
* @param bounds a bounding rectangle to render to
* @param hasFocus is focused
*/
public void paintCurrentValueBackground(Graphics g,Rectangle bounds,boolean hasFocus) {
Color t = g.getColor();
if ( comboBox.isEnabled() )
g.setColor(DefaultLookup.getColor(comboBox, this,
"ComboBox.background", null));
else
g.setColor(DefaultLookup.getColor(comboBox, this,
"ComboBox.disabledBackground", null));
g.fillRect(bounds.x,bounds.y,bounds.width,bounds.height);
g.setColor(t);
}
InputMap getInputMap(int condition) {
if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
return (InputMap)DefaultLookup.get(splitPane, this,
"SplitPane.ancestorInputMap");
}
return null;
}
protected Dimension getPreferredInnerVertical() {
Dimension vertDim = (Dimension)DefaultLookup.get(progressBar, this,
"ProgressBar.verticalSize");
if (vertDim == null) {
vertDim = new Dimension(12, 146);
}
return vertDim;
}
public Dimension getMinimumVerticalSize() {
Dimension minVertDim = (Dimension)DefaultLookup.get(slider,
this, "Slider.minimumVerticalSize");
if (minVertDim == null) {
minVertDim = new Dimension(21, 36);
}
return minVertDim;
}
InputMap createInputMap(int condition) {
if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {
Object[] bindings = (Object[])DefaultLookup.get(
frame, this, "InternalFrame.windowBindings");
if (bindings != null) {
return LookAndFeel.makeComponentInputMap(frame, bindings);
}
}
return null;
}