下面列出了javax.swing.JButton#setRequestFocusEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void addCopyButton(JToolBar buttonBar, Insets margin) {
copyButton = new JButton(new ImageIcon(GUIFrame.class.getResource("/resources/images/Copy-16.png")));
copyButton.setToolTipText(formatToolTip("Copy (Ctrl+C)",
"Copies the selected entity to the clipboard."));
copyButton.setMargin(margin);
copyButton.setFocusPainted(false);
copyButton.setRequestFocusEnabled(false);
copyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed( ActionEvent event ) {
if (selectedEntity != null)
copyToClipboard(selectedEntity);
controlStartResume.requestFocusInWindow();
}
});
buttonBar.add( copyButton );
}
private void addPasteButton(JToolBar buttonBar, Insets margin) {
pasteButton = new JButton(new ImageIcon(GUIFrame.class.getResource("/resources/images/Paste-16.png")));
pasteButton.setToolTipText(formatToolTip("Paste (Ctrl+V)",
"Pastes a copy of an entity from the clipboard to the location of the most recent "
+ "mouse click."));
pasteButton.setMargin(margin);
pasteButton.setFocusPainted(false);
pasteButton.setRequestFocusEnabled(false);
pasteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed( ActionEvent event ) {
pasteEntityFromClipboard();
controlStartResume.requestFocusInWindow();
}
});
buttonBar.add( pasteButton );
}
public void readValues(DataRead dr) throws BasicException {
m_sId = dr.getString(1);
m_sName = dr.getString(2);
m_ix = dr.getInt(3).intValue();
m_iy = dr.getInt(4).intValue();
m_sfloor = dr.getString(5);
m_bPeople = false;
m_btn = new JButton();
m_btn.setFocusPainted(false);
m_btn.setFocusable(false);
m_btn.setRequestFocusEnabled(false);
m_btn.setHorizontalTextPosition(SwingConstants.CENTER);
m_btn.setVerticalTextPosition(SwingConstants.BOTTOM);
m_btn.setIcon(ICO_FRE);
m_btn.setText(m_sName);
}
public void addComponent(JPanelMenu menu) {
JButton btn = new JButton(act);
btn.setFocusPainted(false);
btn.setFocusable(false);
btn.setRequestFocusEnabled(false);
btn.setHorizontalAlignment(SwingConstants.LEADING);
btn.setPreferredSize(new Dimension(220, 50));
// btn.setSize(220, 50);
// btn.setLocation(p);
// if (p.x >= 470) {
// p.x = 20;
// p.y += 55;
// } else {
// p.x += 225;
// }
// comp.add(btn);
menu.addEntry(btn);
}
public void addProduct(Image img, String name, ActionListener al) {
JButton btn = new JButton();
btn.applyComponentOrientation(getComponentOrientation());
btn.setText(name);
btn.setFont(btn.getFont().deriveFont((float)24));
btn.setIcon(new ImageIcon(img));
btn.setFocusPainted(false);
btn.setFocusable(false);
btn.setRequestFocusEnabled(false);
btn.setHorizontalTextPosition(SwingConstants.CENTER);
btn.setVerticalTextPosition(SwingConstants.BOTTOM);
btn.setMargin(new Insets(2, 2, 2, 2));
btn.setMaximumSize(new Dimension(80, 70));
btn.setPreferredSize(new Dimension(80, 70));
btn.setMinimumSize(new Dimension(80, 70));
btn.addActionListener(al);
flowpanel.add(btn);
}
protected JButton createToolBarButton(String toolTip, Icon icon, ActionListener act) {
JButton button = new RolloverButton(icon);
button.setMargin(new Insets(0, 0, 0, 0));
button.setRequestFocusEnabled(false);
button.setToolTipText(toolTip);
button.setRequestFocusEnabled(false);
button.addActionListener(act);
return button;
}
@Override
protected Component createNextButton() {
AbstractButton ab = (AbstractButton) super.createNextButton();
JButton b = new SpinnerButton("up");
b.setRequestFocusEnabled(false);
b.addActionListener((ActionListener) getUIResource(ab.getActionListeners()));
b.addMouseListener((MouseListener) getUIResource(ab.getMouseListeners()));
return b;
}
protected Component createPreviousButton() {
// if (NLXPStyle.getXP() != null)
{
JButton xpButton = new GlyphButton(spinner, Type.down);
Dimension size = UIManager.getDimension("Spinner.arrowButtonSize");
xpButton.setPreferredSize(size);
xpButton.setRequestFocusEnabled(false);
installPreviousButtonListeners(xpButton);
return xpButton;
}
// return super.createPreviousButton();
}
protected Component createNextButton() {
// if (NLXPStyle.getXP() != null)
{
JButton xpButton = new GlyphButton(spinner, Type.up);
Dimension size = UIManager.getDimension("Spinner.arrowButtonSize");
xpButton.setPreferredSize(size);
xpButton.setRequestFocusEnabled(false);
installNextButtonListeners(xpButton);
return xpButton;
}
// return super.createNextButton();
}
public void addButton(String image, double amount) {
JButton btn = new JButton();
btn.setIcon(new ImageIcon(tnbbutton.getThumbNailText(dlSystem.getResourceAsImage(image), Formats.CURRENCY.formatValue(amount))));
btn.setFocusPainted(false);
btn.setFocusable(false);
btn.setRequestFocusEnabled(false);
btn.setHorizontalTextPosition(SwingConstants.CENTER);
btn.setVerticalTextPosition(SwingConstants.BOTTOM);
btn.setMargin(new Insets(2, 2, 2, 2));
btn.addActionListener(new AddAmount(amount));
jPanel6.add(btn);
}
private void addClearFormattingButton(JToolBar buttonBar, Insets margin) {
clearButton = new JButton(new ImageIcon(
GUIFrame.class.getResource("/resources/images/Clear-16.png")));
clearButton.setToolTipText(formatToolTip("Clear Formatting",
"Resets the format inputs for the selected Entity or DisplayModel to their default "
+ "values."));
clearButton.setMargin(margin);
clearButton.setFocusPainted(false);
clearButton.setRequestFocusEnabled(false);
clearButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed( ActionEvent event ) {
if (selectedEntity == null)
return;
ArrayList<KeywordIndex> kwList = new ArrayList<>();
for (Input<?> in : selectedEntity.getEditableInputs()) {
String cat = in.getCategory();
if (in.isDefault() || !cat.equals(Entity.FORMAT) && !cat.equals(Entity.FONT))
continue;
KeywordIndex kw = InputAgent.formatArgs(in.getKeyword());
kwList.add(kw);
}
if (kwList.isEmpty())
return;
KeywordIndex[] kws = new KeywordIndex[kwList.size()];
kwList.toArray(kws);
InputAgent.storeAndExecute(new KeywordCommand(selectedEntity, kws));
controlStartResume.requestFocusInWindow();
}
});
buttonBar.add( clearButton );
}
private void addFontColourButton(JToolBar buttonBar, Insets margin) {
colourIcon = new ColorIcon(16, 16);
colourIcon.setFillColor(Color.LIGHT_GRAY);
colourIcon.setOutlineColor(Color.LIGHT_GRAY);
fontColour = new JButton(colourIcon);
fontColour.setMargin(margin);
fontColour.setFocusPainted(false);
fontColour.setRequestFocusEnabled(false);
fontColour.setToolTipText(formatToolTip("Font Colour", "Sets the colour of the text."));
fontColour.addActionListener(new ActionListener() {
@Override
public void actionPerformed( ActionEvent event ) {
if (!(selectedEntity instanceof TextEntity))
return;
final TextEntity textEnt = (TextEntity) selectedEntity;
final Color4d presentColour = textEnt.getFontColor();
ArrayList<Color4d> coloursInUse = GUIFrame.getFontColoursInUse(sim);
ColourMenu fontMenu = new ColourMenu(presentColour, coloursInUse, true) {
@Override
public void setColour(String colStr) {
KeywordIndex kw = InputAgent.formatInput("FontColour", colStr);
InputAgent.storeAndExecute(new KeywordCommand(selectedEntity, kw));
}
};
fontMenu.show(fontColour, 0, fontColour.getPreferredSize().height);
controlStartResume.requestFocusInWindow();
}
});
buttonBar.add( fontColour );
}
private void addLineColourButton(JToolBar buttonBar, Insets margin) {
lineColourIcon = new ColorIcon(16, 16);
lineColourIcon.setFillColor(Color.LIGHT_GRAY);
lineColourIcon.setOutlineColor(Color.LIGHT_GRAY);
lineColour = new JButton(lineColourIcon);
lineColour.setMargin(margin);
lineColour.setFocusPainted(false);
lineColour.setRequestFocusEnabled(false);
lineColour.setToolTipText(formatToolTip("Line Colour",
"Sets the colour of the line."));
lineColour.addActionListener(new ActionListener() {
@Override
public void actionPerformed( ActionEvent event ) {
if (!(selectedEntity instanceof LineEntity))
return;
final LineEntity lineEnt = (LineEntity) selectedEntity;
final Color4d presentColour = lineEnt.getLineColour();
ArrayList<Color4d> coloursInUse = GUIFrame.getLineColoursInUse(sim);
ColourMenu menu = new ColourMenu(presentColour, coloursInUse, true) {
@Override
public void setColour(String colStr) {
KeywordIndex kw = InputAgent.formatInput("LineColour", colStr);
InputAgent.storeAndExecute(new KeywordCommand(selectedEntity, kw));
}
};
menu.show(lineColour, 0, lineColour.getPreferredSize().height);
controlStartResume.requestFocusInWindow();
}
});
buttonBar.add( lineColour );
}
private void addFillColourButton(JToolBar buttonBar, Insets margin) {
fillColourIcon = new ColorIcon(16, 16);
fillColourIcon.setFillColor(Color.LIGHT_GRAY);
fillColourIcon.setOutlineColor(Color.LIGHT_GRAY);
fillColour = new JButton(fillColourIcon);
fillColour.setMargin(margin);
fillColour.setFocusPainted(false);
fillColour.setRequestFocusEnabled(false);
fillColour.setToolTipText(formatToolTip("Fill Colour",
"Sets the colour of the fill."));
fillColour.addActionListener(new ActionListener() {
@Override
public void actionPerformed( ActionEvent event ) {
if (!(selectedEntity instanceof FillEntity))
return;
final FillEntity fillEnt = (FillEntity) selectedEntity;
final Color4d presentColour = fillEnt.getFillColour();
ArrayList<Color4d> coloursInUse = GUIFrame.getFillColoursInUse(sim);
ColourMenu menu = new ColourMenu(presentColour, coloursInUse, true) {
@Override
public void setColour(String colStr) {
KeywordIndex kw = InputAgent.formatInput("FillColour", colStr);
InputAgent.storeAndExecute(new KeywordCommand(selectedEntity, kw));
}
};
menu.show(fillColour, 0, fillColour.getPreferredSize().height);
controlStartResume.requestFocusInWindow();
}
});
buttonBar.add( fillColour );
}
/**
* Creates and return an instance of JButton that can be used to
* collapse the right component in the split pane.
*/
@Override
protected JButton createRightOneTouchButton() {
JButton b = new JButton() {
private static final long serialVersionUID = 1L;
public void setBorder(Border border) {
}
@Override
public void paint(Graphics g) {
if (splitPane != null) {
int[] xs = new int[3];
int[] ys = new int[3];
int blockSize;
// Fill the background first ...
g.setColor(new Color(255,0,255));
g.fillRect(0, 0, this.getWidth(),
this.getHeight());
// ... then draw the arrow.
if (orientation == JSplitPane.VERTICAL_SPLIT) {
blockSize = Math.min(getHeight(), oneTouchSize);
xs[0] = blockSize;
xs[1] = blockSize << 1;
xs[2] = 0;
ys[0] = blockSize;
ys[1] = ys[2] = 0;
} else {
blockSize = Math.min(getWidth(), oneTouchSize);
xs[0] = xs[2] = 0;
xs[1] = blockSize;
ys[0] = 0;
ys[1] = blockSize;
ys[2] = blockSize << 1;
}
g.setColor(new Color(255,0,255));
g.fillPolygon(xs, ys, 3);
}
}
// Don't want the button to participate in focus traversable.
public boolean isFocusTraversable() {
return false;
}
};
b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
b.setFocusPainted(false);
b.setBorderPainted(false);
b.setRequestFocusEnabled(false);
return b;
}
/**
* Creates and return an instance of JButton that can be used to
* collapse the right component in the split pane.
*
* @return the j button
*/
protected JButton createRightOneTouchButton() {
JButton b = new JButton() {
public void setBorder(Border border) {
}
public void paint(Graphics g) {
if (splitPane != null) {
int[] xs = new int[3];
int[] ys = new int[3];
int blockSize;
// Fill the background first ...
g.setColor(this.getBackground());
g.fillRect(0, 0, this.getWidth(),
this.getHeight());
//* 开启反走样
BEUtils.setAntiAliasing((Graphics2D)g, true);
// ... then draw the arrow.
if (orientation == JSplitPane.VERTICAL_SPLIT) {
blockSize = Math.min(getHeight(), oneTouchSize);
xs[0] = blockSize;
xs[1] = blockSize << 1;
xs[2] = 0;
ys[0] = blockSize;
ys[1] = ys[2] = 0;
}
else {
blockSize = Math.min(getWidth(), oneTouchSize);
xs[0] = xs[2] = 0;
xs[1] = blockSize;
ys[0] = 0;
ys[1] = blockSize;
ys[2] = blockSize << 1;
}
//modified by jb2011
g.setColor(TOUCH_BUTTON_COLOR);//Color.black);
g.fillPolygon(xs, ys, 3);
//* 关闭反走样
BEUtils.setAntiAliasing((Graphics2D)g, false);
}
}
// Don't want the button to participate in focus traversable.
public boolean isFocusTraversable() {
return false;
}
};
b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
b.setFocusPainted(false);
b.setBorderPainted(false);
b.setRequestFocusEnabled(false);
return b;
}
private void addDisplayModelSelector(JToolBar buttonBar, Insets margin) {
dispModel = new JTextField("");
dispModel.setEditable(false);
dispModel.setHorizontalAlignment(JTextField.CENTER);
dispModel.setPreferredSize(new Dimension(120, fileSave.getPreferredSize().height));
dispModel.setToolTipText(formatToolTip("DisplayModel", "Sets the default appearance of the entity. "
+ "A DisplayModel is analogous to a text style in a word processor."));
buttonBar.add(dispModel);
modelSelector = new JButton(new ImageIcon(
GUIFrame.class.getResource("/resources/images/dropdown.png")));
modelSelector.setMargin(margin);
modelSelector.setFocusPainted(false);
modelSelector.setRequestFocusEnabled(false);
modelSelector.addActionListener(new ActionListener() {
@Override
public void actionPerformed( ActionEvent event ) {
if (!(selectedEntity instanceof DisplayEntity))
return;
DisplayEntity dispEnt = (DisplayEntity) selectedEntity;
if (!dispEnt.isGraphicsNominal() || dispEnt.getDisplayModelList().size() != 1)
return;
final String presentModelName = dispEnt.getDisplayModelList().get(0).getName();
Input<?> in = dispEnt.getInput("DisplayModel");
ArrayList<String> choices = in.getValidOptions(selectedEntity);
PreviewablePopupMenu menu = new PreviewablePopupMenu(presentModelName, choices, true) {
@Override
public void setValue(String str) {
dispModel.setText(str);
KeywordIndex kw = InputAgent.formatArgs("DisplayModel", str);
InputAgent.storeAndExecute(new KeywordCommand(dispEnt, kw));
}
};
menu.show(dispModel, 0, dispModel.getPreferredSize().height);
controlStartResume.requestFocusInWindow();
}
});
buttonBar.add(modelSelector);
}
@Override
protected JButton createRightOneTouchButton() {
JButton b = new JButton() {
public void setBorder(Border border) {
}
public void paint(Graphics g) {
if (splitPane != null) {
int[] xs = new int[3];
int[] ys = new int[3];
int blockSize;
// Fill the background first ...
g.setColor(this.getBackground());
g.fillRect(0, 0, this.getWidth(),
this.getHeight());
// ... then draw the arrow.
if (orientation == JSplitPane.VERTICAL_SPLIT) {
blockSize = Math.min(getHeight(), ONE_TOUCH_SIZE);
xs[0] = blockSize;
xs[1] = blockSize << 1;
xs[2] = 0;
ys[0] = blockSize;
ys[1] = ys[2] = 0;
}
else {
blockSize = Math.min(getWidth(), ONE_TOUCH_SIZE);
xs[0] = xs[2] = 0;
xs[1] = blockSize;
ys[0] = 0;
ys[1] = blockSize;
ys[2] = blockSize << 1;
}
g.setColor(new DoubleColor(Gray._255, UIUtil.getLabelForeground()));
g.fillPolygon(xs, ys, 3);
}
}
// Don't want the button to participate in focus traversable.
public boolean isFocusTraversable() {
return false;
}
};
b.setMinimumSize(new Dimension(ONE_TOUCH_SIZE, ONE_TOUCH_SIZE));
b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
b.setFocusPainted(false);
b.setBorderPainted(false);
b.setRequestFocusEnabled(false);
return b;
}
private void addTextHeightButtons(JToolBar buttonBar, Insets margin) {
ActionListener textHeightListener = new ActionListener() {
@Override
public void actionPerformed( ActionEvent event ) {
if (!(selectedEntity instanceof TextEntity))
return;
TextEntity textEnt = (TextEntity) selectedEntity;
double height = textEnt.getTextHeight();
double spacing = sim.getSimulation().getSnapGridSpacing();
if (textEnt instanceof OverlayText || textEnt instanceof BillboardText)
spacing = 1.0d;
height = Math.round(height/spacing) * spacing;
if (event.getActionCommand().equals("LargerText")) {
height += spacing;
}
else if (event.getActionCommand().equals("SmallerText")) {
height -= spacing;
height = Math.max(spacing, height);
}
String format = "%.1f m";
if (textEnt instanceof OverlayText || textEnt instanceof BillboardText)
format = "%.0f";
String str = String.format(format, height);
textHeight.setText(str);
KeywordIndex kw = InputAgent.formatInput("TextHeight", str);
InputAgent.storeAndExecute(new KeywordCommand((Entity)textEnt, kw));
controlStartResume.requestFocusInWindow();
}
};
largerText = new JButton(new ImageIcon(
GUIFrame.class.getResource("/resources/images/LargerText-16.png")));
largerText.setMargin(margin);
largerText.setFocusPainted(false);
largerText.setRequestFocusEnabled(false);
largerText.setToolTipText(formatToolTip("Larger Text",
"Increases the text height to the next higher multiple of the snap grid spacing."));
largerText.setActionCommand("LargerText");
largerText.addActionListener( textHeightListener );
smallerText = new JButton(new ImageIcon(
GUIFrame.class.getResource("/resources/images/SmallerText-16.png")));
smallerText.setMargin(margin);
smallerText.setFocusPainted(false);
smallerText.setRequestFocusEnabled(false);
smallerText.setToolTipText(formatToolTip("Smaller Text",
"Decreases the text height to the next lower multiple of the snap grid spacing."));
smallerText.setActionCommand("SmallerText");
smallerText.addActionListener( textHeightListener );
buttonBar.add( largerText );
buttonBar.add( smallerText );
}
private void addZButtons(JToolBar buttonBar, Insets margin) {
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed( ActionEvent event ) {
if (!(selectedEntity instanceof DisplayEntity)
|| selectedEntity instanceof OverlayEntity)
return;
DisplayEntity dispEnt = (DisplayEntity) selectedEntity;
double delta = sim.getSimulation().getSnapGridSpacing()/100.0d;
Vec3d pos = dispEnt.getPosition();
ArrayList<Vec3d> points = dispEnt.getPoints();
Vec3d offset = new Vec3d();
if (event.getActionCommand().equals("Up")) {
pos.z += delta;
offset.z += delta;
}
else if (event.getActionCommand().equals("Down")) {
pos.z -= delta;
offset.z -= delta;
}
// Normal object
KeywordIndex posKw = InputAgent.formatVec3dInput("Position", pos, DistanceUnit.class);
if (!dispEnt.usePointsInput()) {
InputAgent.storeAndExecute(new KeywordCommand(dispEnt, posKw));
controlStartResume.requestFocusInWindow();
return;
}
// Polyline object
KeywordIndex ptsKw = InputAgent.formatPointsInputs("Points", points, offset);
InputAgent.storeAndExecute(new KeywordCommand(dispEnt, posKw, ptsKw));
controlStartResume.requestFocusInWindow();
}
};
increaseZ = new JButton(new ImageIcon(
GUIFrame.class.getResource("/resources/images/PlusZ-16.png")));
increaseZ.setMargin(margin);
increaseZ.setFocusPainted(false);
increaseZ.setRequestFocusEnabled(false);
increaseZ.setToolTipText(formatToolTip("Move Up",
"Increases the selected object's z-coordinate by one hundredth of the snap-grid "
+ "spacing. By moving the object closer to the camera, it will appear on top of "
+ "other objects with smaller z-coordinates."));
increaseZ.setActionCommand("Up");
increaseZ.addActionListener( actionListener );
decreaseZ = new JButton(new ImageIcon(
GUIFrame.class.getResource("/resources/images/MinusZ-16.png")));
decreaseZ.setMargin(margin);
decreaseZ.setFocusPainted(false);
decreaseZ.setRequestFocusEnabled(false);
decreaseZ.setToolTipText(formatToolTip("Move Down",
"Decreases the selected object's z-coordinate by one hundredth of the snap-grid "
+ "spacing. By moving the object farther from the camera, it will appear below "
+ "other objects with larger z-coordinates."));
decreaseZ.setActionCommand("Down");
decreaseZ.addActionListener( actionListener );
buttonBar.add( increaseZ );
buttonBar.add( decreaseZ );
}