| 1 |
// Copyright 2001 freehep |
| 2 |
package org.freehep.graphicsio.exportchooser; |
| 3 |
|
| 4 |
import java.awt.BorderLayout; |
| 5 |
import java.awt.FlowLayout; |
| 6 |
import java.awt.Font; |
| 7 |
import java.awt.GridLayout; |
| 8 |
import java.awt.event.ActionEvent; |
| 9 |
import java.awt.event.ActionListener; |
| 10 |
import java.awt.event.ItemEvent; |
| 11 |
import java.awt.event.ItemListener; |
| 12 |
|
| 13 |
import javax.swing.JButton; |
| 14 |
import javax.swing.JCheckBox; |
| 15 |
import javax.swing.JDialog; |
| 16 |
import javax.swing.JLabel; |
| 17 |
import javax.swing.JPanel; |
| 18 |
import javax.swing.JTextField; |
| 19 |
|
| 20 |
import org.freehep.graphics2d.TagString; |
| 21 |
import org.freehep.graphicsio.MultiPageDocument; |
| 22 |
|
| 23 |
/** |
| 24 |
* @author Simon Fischer |
| 25 |
* @version $Id: freehep-graphicsio/src/main/java/org/freehep/graphicsio/exportchooser/HeadFootDialog.java 5641ca92a537 2005/11/26 00:15:35 duns $ |
| 26 |
*/ |
| 27 |
public class HeadFootDialog extends JDialog implements ActionListener, |
| 28 |
ItemListener { |
| 29 |
|
| 30 |
private static final String[] HF_LABELS = { "Headline", "Footline" }; |
| 31 |
|
| 32 |
private JTextField textField[][]; |
| 33 |
|
| 34 |
private JCheckBox useCheckBox[]; |
| 35 |
|
| 36 |
private TagString text[][]; |
| 37 |
|
| 38 |
public HeadFootDialog() { |
| 39 |
super(); |
| 40 |
setTitle("Head- and footlines"); |
| 41 |
setModal(true); |
| 42 |
getContentPane().setLayout(new BorderLayout()); |
| 43 |
|
| 44 |
textField = new JTextField[HF_LABELS.length][]; |
| 45 |
useCheckBox = new JCheckBox[HF_LABELS.length]; |
| 46 |
JPanel textPanel = new JPanel(new GridLayout(HF_LABELS.length * 2, 1)); |
| 47 |
for (int i = 0; i < HF_LABELS.length; i++) { |
| 48 |
JPanel title = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| 49 |
useCheckBox[i] = new JCheckBox(); |
| 50 |
useCheckBox[i].setSelected(false); |
| 51 |
useCheckBox[i].addItemListener(this); |
| 52 |
title.add(useCheckBox[i]); |
| 53 |
title.add(new JLabel(HF_LABELS[i])); |
| 54 |
textPanel.add(title); |
| 55 |
JPanel textFieldPanel = new JPanel(new FlowLayout()); |
| 56 |
textField[i] = new JTextField[3]; |
| 57 |
for (int j = 0; j < textField[i].length; j++) { |
| 58 |
textField[i][j] = new JTextField(10); |
| 59 |
textField[i][j].setEnabled(false); |
| 60 |
textFieldPanel.add(textField[i][j]); |
| 61 |
} |
| 62 |
textPanel.add(textFieldPanel); |
| 63 |
} |
| 64 |
getContentPane().add(textPanel, BorderLayout.CENTER); |
| 65 |
|
| 66 |
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
| 67 |
JButton cancel = new JButton("Cancel"); |
| 68 |
cancel.setActionCommand("cancel"); |
| 69 |
cancel.addActionListener(this); |
| 70 |
buttonPanel.add(cancel); |
| 71 |
JButton ok = new JButton("Ok"); |
| 72 |
ok.setActionCommand("ok"); |
| 73 |
ok.addActionListener(this); |
| 74 |
buttonPanel.add(ok); |
| 75 |
getContentPane().add(buttonPanel, BorderLayout.SOUTH); |
| 76 |
|
| 77 |
pack(); |
| 78 |
|
| 79 |
text = new TagString[useCheckBox.length][]; |
| 80 |
} |
| 81 |
|
| 82 |
public void actionPerformed(ActionEvent e) { |
| 83 |
if (e.getActionCommand().equals("ok")) { |
| 84 |
for (int i = 0; i < useCheckBox.length; i++) { |
| 85 |
if (useCheckBox[i].isSelected()) { |
| 86 |
text[i] = new TagString[3]; |
| 87 |
for (int j = 0; j < textField[i].length; j++) { |
| 88 |
text[i][j] = new TagString(textField[i][j].getText()); |
| 89 |
} |
| 90 |
} else { |
| 91 |
text[i] = null; |
| 92 |
} |
| 93 |
} |
| 94 |
setVisible(false); |
| 95 |
} else if (e.getActionCommand().equals("cancel")) { |
| 96 |
for (int i = 0; i < useCheckBox.length; i++) { |
| 97 |
useCheckBox[i].setSelected(text[i] != null); |
| 98 |
for (int j = 0; j < textField[i].length; j++) { |
| 99 |
if (text[i] != null) { |
| 100 |
textField[i][j].setText(text[i][j].toString()); |
| 101 |
textField[i][j].setEnabled(true); |
| 102 |
} else { |
| 103 |
textField[i][j].setText(""); |
| 104 |
textField[i][j].setEnabled(false); |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
setVisible(false); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
public void configure(MultiPageDocument md) { |
| 113 |
if (text[0] != null) { |
| 114 |
md.setHeader(new Font("times", Font.PLAIN, 10), text[0][0], |
| 115 |
text[0][1], text[0][2], 1); |
| 116 |
} |
| 117 |
|
| 118 |
if (text[1] != null) { |
| 119 |
md.setFooter(new Font("times", Font.PLAIN, 10), text[1][0], |
| 120 |
text[1][1], text[1][2], 1); |
| 121 |
} |
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
public void itemStateChanged(ItemEvent e) { |
| 126 |
for (int i = 0; i < useCheckBox.length; i++) { |
| 127 |
if (e.getSource() == useCheckBox[i]) { |
| 128 |
for (int j = 0; j < textField[i].length; j++) { |
| 129 |
textField[i][j] |
| 130 |
.setEnabled(e.getStateChange() == ItemEvent.SELECTED); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
public static void main(String[] argv) { |
| 137 |
JDialog d = new HeadFootDialog(); |
| 138 |
d.setVisible(true); |
| 139 |
} |
| 140 |
|
| 141 |
} |