📄 rampentryeditdialog.java
字号:
} else {
massCheck.doClick();
massCheck.doClick();
}
add(massCheck, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
new Insets(10, 5, 5, 5), 0, 0));
}
if (entry.hasMassSet()) {
massPanel.setValue(entry.getMass());
}
JPanel mass = new JPanel(new GridBagLayout());
mass.setBorder(createTitledBorder("PARTICLE MASS"));
mass.add(massPanel, new GridBagConstraints(0, 0, 1, 1, 1.0,
0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0), 0, 0));
add(mass, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(10, 5, 5, 5), 0, 0));
final JLabel colorLabel = createBoldLabel("Color:"), alphaLabel = new JLabel("A:");
colorHex.setFont(new Font("Arial", Font.PLAIN, 10));
colorHex.setText("#FFFFFF");
sColorPanel.setBackground(Color.white);
sColorPanel.setBorder(BorderFactory.createRaisedBevelBorder());
sColorPanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (sColorPanel.isEnabled())
colorPanel_mouseClicked(e);
}
});
alphaSpinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
entry.getColor().a = ((Number) alphaSpinner
.getValue()).intValue() / 255f;
}
});
final JPanel colorPanel = new JPanel(new GridBagLayout());
colorPanel.setBorder(createTitledBorder("PARTICLE COLOR"));
colorPanel.add(colorLabel, new GridBagConstraints(0, 0, 2, 1, 0.0,
0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(5, 10, 0, 10), 0, 0));
colorPanel.add(sColorPanel, new GridBagConstraints(0, 1, 2, 1, 0.0,
0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 25, 25));
colorPanel.add(colorHex, new GridBagConstraints(0, 2, 2, 1, 0.0,
0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 0, 4, 0), 0, 0));
colorPanel.add(alphaSpinner, new GridBagConstraints(1, 3, 1, 1,
0.25, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 20, 0));
colorPanel.add(alphaLabel, new GridBagConstraints(0, 3, 1, 1,
0.25, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
if (entry.getOffset() != -1) {
final JCheckBox colorCheck = new JCheckBox("");
colorCheck.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sColorPanel.setEnabled(colorCheck.isSelected());
alphaLabel.setEnabled(colorCheck.isSelected());
colorLabel.setEnabled(colorCheck.isSelected());
alphaSpinner.setEnabled(colorCheck.isSelected());
ColorRGBA color = makeColorRGBA(sColorPanel.getBackground());
color.a = ((Number) alphaSpinner.getValue()).intValue() / 255f;
entry.setColor(colorCheck.isSelected() ? color : RampEntry.DEFAULT_COLOR);
}
});
if (entry.hasColorSet()) {
colorCheck.setSelected(true);
} else {
colorCheck.doClick();
colorCheck.doClick();
}
add(colorCheck, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
new Insets(10, 5, 5, 5), 0, 0));
}
if (entry.hasColorSet()) {
sColorPanel.setBackground(makeColor(entry
.getColor(), false));
colorHex.setText(convColorToHex(sColorPanel.getBackground()));
alphaSpinner.setValue(new Integer(makeColor(
entry.getColor(), true).getAlpha()));
}
add(colorPanel, new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(10, 5, 5, 5), 0, 0));
setColorChooserDialogOwner(this, entry);
pack();
}
public void setColorChooserDialogOwner(JDialog owner, final RampEntry entry) {
colorChooserDialog = new JDialog(owner, "Choose a color:");
initColorChooser(entry);
}
private void initColorChooser(final RampEntry entry) {
colorChooser.setColor(sColorPanel.getBackground());
colorChooserDialog.setLayout(new BorderLayout());
colorChooserDialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
colorChooserDialog.add(colorChooser, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
buttonPanel.setOpaque(false);
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
JButton okButton = new JButton("Ok");
okButton.setOpaque(true);
okButton.setMnemonic('O');
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Color color = colorChooser.getColor();
if (color == null) {
return;
}
ColorRGBA rgba = makeColorRGBA(color);
rgba.a = (Integer.parseInt(alphaSpinner.getValue()
.toString()) / 255f);
entry.setColor(rgba);
sColorPanel.setBackground(color);
colorHex.setText(convColorToHex(sColorPanel.getBackground()));
colorChooserDialog.setVisible(false);
}
});
JButton cancelButton = new JButton("Cancel");
cancelButton.setOpaque(true);
cancelButton.setMnemonic('C');
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
colorChooserDialog.setVisible(false);
}
});
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
colorChooserDialog.add(buttonPanel, BorderLayout.SOUTH);
colorChooserDialog.setSize(colorChooserDialog.getPreferredSize());
colorChooserDialog.setLocationRelativeTo(null);
}
protected TitledBorder createTitledBorder(String title) {
TitledBorder border = new TitledBorder(" " + title + " ");
border.setTitleFont(new Font("Arial", Font.PLAIN, 10));
return border;
}
private Color makeColor(ColorRGBA rgba, boolean useAlpha) {
return new Color(rgba.r, rgba.g, rgba.b, (useAlpha ? rgba.a : 1f));
}
private ColorRGBA makeColorRGBA(Color color) {
return new ColorRGBA(color.getRed() / 255f, color.getGreen() / 255f,
color.getBlue() / 255f, color.getAlpha() / 255f);
}
private String convColorToHex(Color c) {
if (c == null)
return null;
String sRed = Integer.toHexString(c.getRed());
if (sRed.length() == 1)
sRed = "0" + sRed;
String sGreen = Integer.toHexString(c.getGreen());
if (sGreen.length() == 1)
sGreen = "0" + sGreen;
String sBlue = Integer.toHexString(c.getBlue());
if (sBlue.length() == 1)
sBlue = "0" + sBlue;
return "#" + sRed + sGreen + sBlue;
}
private void colorPanel_mouseClicked(MouseEvent e) {
colorChooser.setColor(sColorPanel.getBackground());
if (!colorChooserDialog.isVisible()) {
colorChooserDialog.setVisible(true);
}
}
protected JLabel createBoldLabel(String text) {
JLabel label = new JLabel(text);
label.setFont(new Font("Arial", Font.BOLD, 13));
return label;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -