[569] | 1 | /* |
---|
| 2 | * $Id: PanelHolderPropertyPanel.java,v 1.4 2003/08/27 23:29:40 dwd Exp $ |
---|
| 3 | * |
---|
| 4 | * This software is provided by NOAA for full, free and open release. It is |
---|
| 5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
| 6 | * errors contained in the code. Although this software is released without |
---|
| 7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
| 8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
| 9 | * Administration should the software be included by the recipient as an |
---|
| 10 | * element in other product development. |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | package gov.noaa.pmel.sgt.beans; |
---|
| 14 | |
---|
| 15 | import java.awt.*; |
---|
| 16 | import javax.swing.*; |
---|
| 17 | import javax.swing.border.*; |
---|
| 18 | import java.awt.event.ActionEvent; |
---|
| 19 | import java.awt.event.ActionListener; |
---|
| 20 | import javax.swing.event.ChangeEvent; |
---|
| 21 | import javax.swing.event.ChangeListener; |
---|
| 22 | import java.awt.event.FocusEvent; |
---|
| 23 | import java.awt.event.FocusListener; |
---|
| 24 | |
---|
| 25 | import gov.noaa.pmel.sgt.swing.prop.ColorDialog; |
---|
| 26 | /** |
---|
| 27 | * @author Donald Denbo |
---|
| 28 | * @version $Revision: 1.4 $, $Date: 2003/08/27 23:29:40 $ |
---|
| 29 | * @since 3.0 |
---|
| 30 | **/ |
---|
| 31 | class PanelHolderPropertyPanel extends PropertyPanel implements ActionListener, ChangeListener, FocusListener { |
---|
| 32 | private boolean expert_ = false; |
---|
| 33 | private PanelHolder pHolder_ = null; |
---|
| 34 | private String[] pNames_ = {"Background", "Border", "Bounds", "Data Groups", |
---|
| 35 | "Id", "Labels", "Legends", "Page Background", "Visible"}; |
---|
| 36 | private JComponent[] comps_ = new JComponent[pNames_.length]; |
---|
| 37 | |
---|
| 38 | public PanelHolderPropertyPanel(PanelHolder ph, boolean expert) { |
---|
| 39 | super(); |
---|
| 40 | pHolder_ = ph; |
---|
| 41 | pHolder_.addChangeListener(this); |
---|
| 42 | expert_ = expert; |
---|
| 43 | create(); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | public void setPanelHolder(PanelHolder ph, boolean expert) { |
---|
| 47 | if(pHolder_ != null) pHolder_.removeChangeListener(this); |
---|
| 48 | pHolder_ = ph; |
---|
| 49 | pHolder_.addChangeListener(this); |
---|
| 50 | expert_ = expert; |
---|
| 51 | reset(); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | void create() { |
---|
| 55 | int i = -1; |
---|
| 56 | comps_[++i] = createColor(pHolder_.getBackground(), pNames_[i], this); |
---|
| 57 | comps_[++i] = createBorder(pHolder_.getBorder(), pNames_[i], this); |
---|
| 58 | Rectangle b = pHolder_.getBounds(); |
---|
| 59 | comps_[++i] = createLabel(b.x + ", " + b.y + ", " + b.width + ", " + b.height); |
---|
| 60 | comps_[++i] = createLabel(pHolder_.getDataGroupSize()); |
---|
| 61 | comps_[++i] = createTextField(pHolder_.getId(), pNames_[i], this, !pHolder_.isInstantiated()); |
---|
| 62 | comps_[++i] = createLabel(pHolder_.getLabelSize()); |
---|
| 63 | comps_[++i] = createLabel(pHolder_.getLegendSize()); |
---|
| 64 | comps_[++i] = createCheckBox(pHolder_.isUsePageBackground(), pNames_[i], this); |
---|
| 65 | comps_[++i] = createCheckBox(pHolder_.isVisible(), pNames_[i], this); |
---|
| 66 | for(i=0; i < comps_.length; i++) { |
---|
| 67 | addProperty(i+1, pNames_[i], comps_[i], false); |
---|
| 68 | } |
---|
| 69 | addProperty(comps_.length + 1, " ", new JLabel(" "), true); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | void resetFields() { |
---|
| 73 | for(int i=0; i < comps_.length; i++) { |
---|
| 74 | if(comps_[i] instanceof JTextField) { |
---|
| 75 | ((JTextField)comps_[i]).removeActionListener(this); |
---|
| 76 | ((JTextField)comps_[i]).removeFocusListener(this); |
---|
| 77 | } else if(comps_[i] instanceof JCheckBox) { |
---|
| 78 | ((JCheckBox)comps_[i]).removeActionListener(this); |
---|
| 79 | ((JCheckBox)comps_[i]).removeFocusListener(this); |
---|
| 80 | } else if(comps_[i] instanceof JComboBox) { |
---|
| 81 | ((JComboBox)comps_[i]).removeActionListener(this); |
---|
| 82 | ((JComboBox)comps_[i]).removeFocusListener(this); |
---|
| 83 | } else if(comps_[i] instanceof JButton) { |
---|
| 84 | ((JButton)comps_[i]).removeActionListener(this); |
---|
| 85 | ((JButton)comps_[i]).removeFocusListener(this); |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | void update() { |
---|
| 91 | int i = -1; |
---|
| 92 | updateColor((JButton)comps_[++i], pHolder_.getBackground()); |
---|
| 93 | updateBorder((JButton)comps_[++i], pHolder_.getBorder()); |
---|
| 94 | Rectangle b = pHolder_.getBounds(); |
---|
| 95 | ((JLabel)comps_[++i]).setText(b.x + ", " + b.y + ", " + b.width + ", " + b.height); |
---|
| 96 | ((JLabel)comps_[++i]).setText(Integer.toString(pHolder_.getDataGroupSize())); |
---|
| 97 | ((JTextField)comps_[++i]).setText(pHolder_.getId()); |
---|
| 98 | ((JLabel)comps_[++i]).setText(Integer.toString(pHolder_.getLabelSize())); |
---|
| 99 | ((JLabel)comps_[++i]).setText(Integer.toString(pHolder_.getLegendSize())); |
---|
| 100 | ((JCheckBox)comps_[++i]).setSelected(pHolder_.isUsePageBackground()); |
---|
| 101 | ((JCheckBox)comps_[++i]).setSelected(pHolder_.isVisible()); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | private void processEvent(Object obj, String command) { |
---|
| 105 | if(command.equals("Border")) { |
---|
| 106 | BorderDialog bd = new BorderDialog(null, "Select Border", true); |
---|
| 107 | bd.setBorder(pHolder_.getBorder()); |
---|
| 108 | bd.setVisible(true); |
---|
| 109 | pHolder_.setBorder(bd.getBorder()); |
---|
| 110 | } else if(command.equals("Id")) { |
---|
| 111 | String oldId = pHolder_.getId(); |
---|
| 112 | pHolder_.getPanelModel().getPanelList().remove(oldId); |
---|
| 113 | pHolder_.setId(((JTextField)obj).getText()); |
---|
| 114 | pHolder_.getPanelModel().getPanelList().put(pHolder_.getId(), pHolder_); |
---|
| 115 | } else if(command.equals("Visible")) { |
---|
| 116 | pHolder_.setVisible(((JCheckBox)obj).isSelected()); |
---|
| 117 | } else if(command.equals("Background")) { |
---|
| 118 | ColorDialog cd = new ColorDialog(getFrame(), "Select Axis Color", true); |
---|
| 119 | cd.setColor(pHolder_.getBackground()); |
---|
| 120 | cd.setVisible(true); |
---|
| 121 | Color newcolor = cd.getColor(); |
---|
| 122 | if(newcolor != null) { |
---|
| 123 | pHolder_.setBackground(newcolor); |
---|
| 124 | updateColor((JButton)obj, newcolor); |
---|
| 125 | } |
---|
| 126 | } else if(command.equals("Page Background")) { |
---|
| 127 | pHolder_.setUsePageBackground(((JCheckBox)obj).isSelected()); |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | public void actionPerformed(ActionEvent e) { |
---|
| 132 | Object obj = e.getSource(); |
---|
| 133 | String command = e.getActionCommand(); |
---|
| 134 | processEvent(obj, command); |
---|
| 135 | } |
---|
| 136 | public void stateChanged(ChangeEvent e) { |
---|
| 137 | update(); |
---|
| 138 | } |
---|
| 139 | public void focusGained(FocusEvent e) { |
---|
| 140 | } |
---|
| 141 | public void focusLost(FocusEvent e) { |
---|
| 142 | Object obj = e.getSource(); |
---|
| 143 | if(obj instanceof JTextField) { |
---|
| 144 | JTextField tf = (JTextField)obj; |
---|
| 145 | String name = tf.getName(); |
---|
| 146 | processEvent(obj, name); |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | private JButton createBorder (Border value, |
---|
| 151 | String action, ActionListener listen) { |
---|
| 152 | JButton jb = new JButton(getBorderDescription(value)); |
---|
| 153 | jb.setActionCommand(action); |
---|
| 154 | if(listen != null) jb.addActionListener(listen); |
---|
| 155 | return jb; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | private void updateBorder(JButton comp, Border value) { |
---|
| 159 | comp.setText(getBorderDescription(value)); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | private String getBorderDescription(Border border) { |
---|
| 163 | String description = "None"; |
---|
| 164 | if(border != null) { |
---|
| 165 | if(border instanceof BevelBorder) { |
---|
| 166 | description = "Beveled"; |
---|
| 167 | } else if(border instanceof EtchedBorder) { |
---|
| 168 | description = "Etched"; |
---|
| 169 | } else if(border instanceof LineBorder) { |
---|
| 170 | description = "Line"; |
---|
| 171 | } else if(border instanceof TitledBorder) { |
---|
| 172 | description = "Titled"; |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | return description; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | public void setExpert(boolean expert) { |
---|
| 179 | expert_ = expert; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | public boolean isExpert() { |
---|
| 183 | return expert_; |
---|
| 184 | } |
---|
| 185 | } |
---|