| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
package org.xmlhammer.gui.util.preferences; |
| 23 |
|
|
| 24 |
|
import java.awt.BorderLayout; |
| 25 |
|
import java.awt.Component; |
| 26 |
|
import java.awt.Dimension; |
| 27 |
|
import java.awt.FlowLayout; |
| 28 |
|
import java.awt.Frame; |
| 29 |
|
import java.awt.Point; |
| 30 |
|
import java.awt.event.ActionEvent; |
| 31 |
|
import java.awt.event.ActionListener; |
| 32 |
|
import java.awt.event.KeyEvent; |
| 33 |
|
|
| 34 |
|
import javax.swing.AbstractAction; |
| 35 |
|
import javax.swing.ImageIcon; |
| 36 |
|
import javax.swing.JButton; |
| 37 |
|
import javax.swing.JComponent; |
| 38 |
|
import javax.swing.JOptionPane; |
| 39 |
|
import javax.swing.JPanel; |
| 40 |
|
import javax.swing.JSplitPane; |
| 41 |
|
import javax.swing.JTable; |
| 42 |
|
import javax.swing.KeyStroke; |
| 43 |
|
import javax.swing.UIManager; |
| 44 |
|
import javax.swing.border.CompoundBorder; |
| 45 |
|
import javax.swing.border.MatteBorder; |
| 46 |
|
import javax.swing.plaf.basic.BasicSplitPaneUI; |
| 47 |
|
|
| 48 |
|
import org.bounce.event.CardEvent; |
| 49 |
|
import org.bounce.event.CardPanelAdapter; |
| 50 |
|
import org.bounce.image.ImageLoader; |
| 51 |
|
import org.bounce.preferences.PreferencesDialog; |
| 52 |
|
import org.bounce.preferences.PreferencesPage; |
| 53 |
|
import org.xmlhammer.gui.help.HelpPanel; |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
16 |
|
| 61 |
|
|
| 62 |
160 |
public class HelpEnabledPreferencesDialog extends PreferencesDialog { |
| 63 |
|
private static final long serialVersionUID = -7403432397234000652L; |
| 64 |
|
|
| 65 |
|
public static final int OK_OPTION = JOptionPane.OK_OPTION; |
| 66 |
2 |
public static final int CANCEL_OPTION = JOptionPane.CANCEL_OPTION; |
| 67 |
|
|
| 68 |
22 |
private static final ImageIcon HELP_ICON = ImageLoader.get().getImage("/org/xmlhammer/gui/icons/etool16/help.gif"); |
| 69 |
2 |
|
| 70 |
20 |
private static Dimension size = null; |
| 71 |
28 |
private static Point position = null; |
| 72 |
8 |
|
| 73 |
80 |
private JSplitPane helpSplit = null; |
| 74 |
80 |
private HelpPanel helpPanel = null; |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
private JButton helpButton; |
| 78 |
|
private JPanel main; |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
8 |
|
| 84 |
|
public HelpEnabledPreferencesDialog(Frame parent, String title) { |
| 85 |
88 |
super(parent, title); |
| 86 |
8 |
|
| 87 |
16 |
getCards().addCardPanelListener(new CardPanelAdapter<PreferencesPage>() { |
| 88 |
96 |
public void cardChanged(CardEvent<PreferencesPage> event) { |
| 89 |
160 |
getHelpPanel().showID(((HelpEnabledPreferencesPage)event.getCard()).getHelpID()); |
| 90 |
160 |
} |
| 91 |
8 |
}); |
| 92 |
|
|
| 93 |
80 |
getRootPane().getActionMap().put("helpAction", new AbstractAction() { |
| 94 |
8 |
private static final long serialVersionUID = -6931927193561857562L; |
| 95 |
0 |
|
| 96 |
80 |
public void actionPerformed(ActionEvent e) { |
| 97 |
0 |
showHelpPanel(); |
| 98 |
0 |
} |
| 99 |
|
}); |
| 100 |
88 |
getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0, false), "helpAction"); |
| 101 |
8 |
|
| 102 |
80 |
size = new Dimension( 674, 534); |
| 103 |
80 |
} |
| 104 |
8 |
|
| 105 |
8 |
private JButton getHelpButton() { |
| 106 |
88 |
if (helpButton == null) { |
| 107 |
8 |
helpButton = new JButton("Help", HELP_ICON); |
| 108 |
0 |
helpButton.addActionListener(new ActionListener() { |
| 109 |
80 |
public void actionPerformed(ActionEvent arg0) { |
| 110 |
0 |
showHelpPanel(); |
| 111 |
0 |
} |
| 112 |
|
}); |
| 113 |
8 |
} |
| 114 |
|
|
| 115 |
80 |
return helpButton; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
8 |
@Override |
| 119 |
8 |
protected JPanel createSouthPanel() { |
| 120 |
80 |
JPanel helpButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| 121 |
88 |
helpButtonPanel.add(getHelpButton()); |
| 122 |
8 |
|
| 123 |
80 |
JPanel southPanel = super.createSouthPanel(); |
| 124 |
88 |
southPanel.add(helpButtonPanel, BorderLayout.WEST); |
| 125 |
|
|
| 126 |
80 |
return southPanel; |
| 127 |
|
} |
| 128 |
8 |
|
| 129 |
|
protected JPanel createCenterPanel() { |
| 130 |
88 |
main = super.createCenterPanel(); |
| 131 |
|
|
| 132 |
80 |
return main; |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
0 |
|
| 138 |
|
public void showHelpPanel() { |
| 139 |
0 |
HelpPanel helpPanel = getHelpPanel(); |
| 140 |
0 |
|
| 141 |
0 |
if (helpSplit == null) { |
| 142 |
0 |
this.setSize(new Dimension(getSize().width + helpPanel.getPreferredSize().width, getSize().height)); |
| 143 |
0 |
|
| 144 |
0 |
helpSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, main, helpPanel); |
| 145 |
0 |
helpSplit.setResizeWeight(1); |
| 146 |
0 |
helpSplit.setOneTouchExpandable(true); |
| 147 |
0 |
Object ui = helpSplit.getUI(); |
| 148 |
0 |
if (ui instanceof BasicSplitPaneUI) { |
| 149 |
0 |
((BasicSplitPaneUI)ui).getDivider().setBorder( |
| 150 |
|
new CompoundBorder( |
| 151 |
|
new CompoundBorder( |
| 152 |
|
new MatteBorder(0, 1, 0, 0, UIManager.getColor("controlDkShadow")), |
| 153 |
|
new MatteBorder( 0, 0, 0, 1, UIManager.getColor("controlLtHighlight"))), |
| 154 |
|
new CompoundBorder( |
| 155 |
|
new MatteBorder(0, 0, 0, 1, UIManager.getColor("controlDkShadow")), |
| 156 |
0 |
new MatteBorder( 0, 1, 0, 0, UIManager.getColor("controlLtHighlight"))))); |
| 157 |
|
} |
| 158 |
0 |
helpSplit.setBorder(null); |
| 159 |
0 |
|
| 160 |
0 |
JPanel contentPane = (JPanel)getContentPane(); |
| 161 |
0 |
contentPane.add(helpSplit, BorderLayout.CENTER); |
| 162 |
0 |
|
| 163 |
0 |
helpSplit.revalidate(); |
| 164 |
0 |
helpSplit.repaint(); |
| 165 |
0 |
|
| 166 |
0 |
contentPane.revalidate(); |
| 167 |
0 |
contentPane.repaint(); |
| 168 |
0 |
|
| 169 |
0 |
validate(); |
| 170 |
0 |
repaint(); |
| 171 |
0 |
} |
| 172 |
0 |
|
| 173 |
0 |
if (!helpPanel.isVisible() || helpPanel.getSize().width < 10) { |
| 174 |
0 |
helpSplit.setDividerLocation(helpSplit.getDividerLocation() - helpPanel.getPreferredSize().width); |
| 175 |
0 |
} |
| 176 |
0 |
|
| 177 |
0 |
helpPanel.showContext(); |
| 178 |
0 |
} |
| 179 |
0 |
|
| 180 |
0 |
public void hideHelpPanel() { |
| 181 |
0 |
helpSplit = null; |
| 182 |
0 |
this.setSize(new Dimension(getSize().width - getHelpPanel().getPreferredSize().width, getSize().height)); |
| 183 |
0 |
|
| 184 |
0 |
JPanel contentPane = (JPanel)getContentPane(); |
| 185 |
0 |
contentPane.removeAll(); |
| 186 |
0 |
contentPane.add(main, BorderLayout.CENTER); |
| 187 |
0 |
contentPane.revalidate(); |
| 188 |
0 |
contentPane.repaint(); |
| 189 |
0 |
|
| 190 |
0 |
validate(); |
| 191 |
0 |
repaint(); |
| 192 |
0 |
|
| 193 |
0 |
helpButton.requestFocusInWindow(); |
| 194 |
0 |
} |
| 195 |
16 |
|
| 196 |
8 |
private HelpPanel getHelpPanel() { |
| 197 |
168 |
if (helpPanel == null) { |
| 198 |
88 |
helpPanel = new HelpPanel(); |
| 199 |
8 |
helpPanel.setBorder(null); |
| 200 |
0 |
helpPanel.addCloseActionListener(new ActionListener() { |
| 201 |
80 |
public void actionPerformed(ActionEvent arg0) { |
| 202 |
0 |
hideHelpPanel(); |
| 203 |
0 |
} |
| 204 |
|
}); |
| 205 |
16 |
} |
| 206 |
|
|
| 207 |
160 |
return helpPanel; |
| 208 |
|
} |
| 209 |
0 |
|
| 210 |
0 |
public void close() { |
| 211 |
0 |
size = getSize(); |
| 212 |
0 |
position = getLocation(); |
| 213 |
0 |
|
| 214 |
0 |
super.close(); |
| 215 |
0 |
} |
| 216 |
0 |
|
| 217 |
0 |
public void cancel() { |
| 218 |
|
|
| 219 |
0 |
|
| 220 |
0 |
Component comp = getFocusOwner(); |
| 221 |
|
|
| 222 |
0 |
if (comp instanceof JTable && ((JTable)comp).getCellEditor() != null) { |
| 223 |
8 |
((JTable)comp).getCellEditor().stopCellEditing(); |
| 224 |
0 |
} |
| 225 |
|
|
| 226 |
0 |
size = getSize(); |
| 227 |
8 |
position = getLocation(); |
| 228 |
|
|
| 229 |
0 |
super.cancel(); |
| 230 |
0 |
} |
| 231 |
|
|
| 232 |
|
public int getSelectedOption() { |
| 233 |
80 |
if (isCancelled()) { |
| 234 |
8 |
return JOptionPane.CANCEL_OPTION; |
| 235 |
8 |
} |
| 236 |
|
|
| 237 |
88 |
return JOptionPane.OK_OPTION; |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
|
| 241 |
|
|
| 242 |
|
|
| 243 |
|
public int open() { |
| 244 |
88 |
restore(); |
| 245 |
80 |
setVisible(true); |
| 246 |
8 |
|
| 247 |
88 |
return getSelectedOption(); |
| 248 |
8 |
} |
| 249 |
0 |
|
| 250 |
|
|
| 251 |
8 |
|
| 252 |
|
|
| 253 |
|
public void restore() { |
| 254 |
80 |
this.setSize(size); |
| 255 |
|
|
| 256 |
80 |
if (position == null) { |
| 257 |
80 |
setLocationRelativeTo(getParent()); |
| 258 |
80 |
} else { |
| 259 |
0 |
setLocation(position); |
| 260 |
|
} |
| 261 |
80 |
} |
| 262 |
|
} |