| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.app.beauti.util; |
| 27 |
|
| 28 |
import javax.swing.*; |
| 29 |
import java.awt.*; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class PanelUtils { |
| 36 |
public static JPanel createAddRemoveButtonPanel(Action addAction, |
| 37 |
Icon addIcon, String addToolTip, Action removeAction, |
| 38 |
Icon removeIcon, String removeToolTip, int axis) { |
| 39 |
|
| 40 |
JPanel buttonPanel = new JPanel(); |
| 41 |
buttonPanel.setLayout(new BoxLayout(buttonPanel, axis)); |
| 42 |
buttonPanel.setOpaque(false); |
| 43 |
JButton addButton = new JButton(addAction); |
| 44 |
if (addIcon != null) { |
| 45 |
addButton.setIcon(addIcon); |
| 46 |
addButton.setText(null); |
| 47 |
} |
| 48 |
addButton.setToolTipText(addToolTip); |
| 49 |
addButton.putClientProperty("JButton.buttonType", "toolbar"); |
| 50 |
addButton.setOpaque(false); |
| 51 |
addAction.setEnabled(false); |
| 52 |
|
| 53 |
JButton removeButton = new JButton(removeAction); |
| 54 |
if (removeIcon != null) { |
| 55 |
removeButton.setIcon(removeIcon); |
| 56 |
removeButton.setText(null); |
| 57 |
} |
| 58 |
removeButton.setToolTipText(removeToolTip); |
| 59 |
removeButton.putClientProperty("JButton.buttonType", "toolbar"); |
| 60 |
removeButton.setOpaque(false); |
| 61 |
removeAction.setEnabled(false); |
| 62 |
|
| 63 |
buttonPanel.add(addButton); |
| 64 |
buttonPanel.add(new JToolBar.Separator(new Dimension(6, 6))); |
| 65 |
buttonPanel.add(removeButton); |
| 66 |
|
| 67 |
return buttonPanel; |
| 68 |
} |
| 69 |
|
| 70 |
public static void setupComponent(JComponent comp) { |
| 71 |
comp.setOpaque(false); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
if (comp instanceof JButton) { |
| 76 |
comp.putClientProperty("JButton.buttonType", "textured"); |
| 77 |
|
| 78 |
|
| 79 |
} |
| 80 |
if (comp instanceof JComboBox) { |
| 81 |
comp.putClientProperty("JComboBox.isPopDown", Boolean.TRUE); |
| 82 |
|
| 83 |
} |
| 84 |
if (comp instanceof JTextArea) { |
| 85 |
((JTextArea) comp).setEditable(false); |
| 86 |
((JTextArea) comp).setOpaque(false); |
| 87 |
((JTextArea) comp).setLineWrap(true); |
| 88 |
((JTextArea) comp).setWrapStyleWord(true); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
public static Frame getActiveFrame() { |
| 93 |
Frame result = null; |
| 94 |
Frame[] frames = Frame.getFrames(); |
| 95 |
for (int i = 0; i < frames.length; i++) { |
| 96 |
Frame frame = frames[i]; |
| 97 |
if (frame.isVisible()) { |
| 98 |
result = frame; |
| 99 |
break; |
| 100 |
} |
| 101 |
} |
| 102 |
return result; |
| 103 |
} |
| 104 |
|
| 105 |
} |