cbxformat.addItem(resources.getString("PrintfFormat"));
cbxformat.addItem(resources.getString("UseDataSourceFormat"));
cbxformat.setEditable(false);
// CARD PANEL
cards = new JPanel();
cards.setLayout(new CardLayout());
// JSYnoptic formater
lformatdigits = new JLabel(resources.getString("DecimalDigits:"));
nfformat = new NumberField(0, 3);
nfformat.setColumns(10);
nfformat.setHorizontalAlignment(SwingConstants.RIGHT);
GridBagPanel digitsPanel = new GridBagPanel();
digitsPanel.addOnCurrentRow(lformatdigits);
digitsPanel.addOnCurrentRow(nfformat);
digitsPanel.carriageReturn();
cards.add(digitsPanel, "jsynopticFormat");
// Printf Formater
GridBagPanel printfPanel = new GridBagPanel();
lPrintfFormat = new JLabel(resources.getString("PrintfFormat"));
tfPrintfFormat = new JTextField(10);
printfPanel.addOnCurrentRow(lPrintfFormat);
printfPanel.addOnCurrentRow(tfPrintfFormat);
printfPanel.carriageReturn();
cards.add(printfPanel, "printfFormat");
cards.add(new GridBagPanel(), "noAttributes");
// Mapper
cbxmapper = new JComboBox();
cbxmapper.addItem(resources.getString("=======NONE======="));
int idx = 0;
if (TextMapper.textMappers != null) {
for (int i = 0; i < TextMapper.textMappers.size(); ++i) {
TextMapper tm = (TextMapper) TextMapper.textMappers.get(i);
if (tm.equals(mapper)) {
idx = i + 1;
}
cbxmapper.addItem(tm);
}
}
cbxmapper.setEditable(false);
cbxmapper.setSelectedIndex(idx);
beditmapper = new JButton(resources.getString("Edit"));
bnewmapper = new JButton(resources.getString("New"));
bdelmapper = new JButton(resources.getString("Delete"));
bduplicateMapper = new JButton(resources.getString("Duplicate"));
if (idx == 0) {
beditmapper.setEnabled(false);
bdelmapper.setEnabled(false);
bduplicateMapper.setEnabled(false);
}
cbxmapper.setRenderer(new ListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
String s = value.toString();
if (s.length() > 18) {
s = s.substring(0, 15) + "...";
}
return new JLabel(s);
}
});
beditmapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mapper == null) {
return;
}
mapper.editDialog(TextPropertiesPanel.this.getOwner());
cbxmapper.repaint(); // in case of name change
}
});
bnewmapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mapper = TextMapper.createTextMapperDialog(TextPropertiesPanel.this.getOwner());
if (TextMapper.textMappers == null) {
TextMapper.textMappers = new Vector();
}
TextMapper.textMappers.add(mapper);
cbxmapper.addItem(mapper);
cbxmapper.setSelectedItem(mapper);
cards.revalidate();
}
});
bdelmapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mapper == null) {
return;
}
if (TextMapper.textMappers != null) {
TextMapper.textMappers.remove(mapper);
}
cbxmapper.removeItem(mapper);
cbxmapper.setSelectedIndex(0);
mapper = null;
bdelmapper.setEnabled(false);
bduplicateMapper.setEnabled(false);
beditmapper.setEnabled(false);
}
});
bduplicateMapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (mapper == null) {
return;
}
try {
TextMapper tm = (TextMapper)((TextMapper)mapper).clone();
if (TextMapper.textMappers != null) {
TextMapper.textMappers.add(tm);
}
mapper = tm;
cbxmapper.addItem(mapper);
cbxmapper.setSelectedItem(mapper);
}catch (CloneNotSupportedException cnse){
}
}
});
cbxmapper.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int idx = cbxmapper.getSelectedIndex();
if (idx == 0) {
beditmapper.setEnabled(false);
bdelmapper.setEnabled(false);
bduplicateMapper.setEnabled(false);
mapper = null;
} else {
mapper = (TextMapper) cbxmapper.getItemAt(idx);
beditmapper.setEnabled(true);
bdelmapper.setEnabled(true);
bduplicateMapper.setEnabled(true);
}
}
});
GridBagPanel mapperPanel = new GridBagPanel();
mapperPanel.addOnCurrentRow(cbxmapper, 2);
mapperPanel.addOnCurrentRow(beditmapper);
mapperPanel.addOnCurrentRow(bnewmapper);
mapperPanel.addOnCurrentRow(bdelmapper);
mapperPanel.addOnCurrentRow(bduplicateMapper);
mapperPanel.carriageReturn();
cards.add(mapperPanel, "mapper");
CardLayout cl = (CardLayout) (cards.getLayout());
if (cbxformat.getSelectedIndex() == TextShape.FORMAT_MAPPER) {
cl.show(cards, "mapper");
} else {
cl.show(cards, "bounds");
}
tfText.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
updateName();
}
public void removeUpdate(DocumentEvent e) {
updateName();
}
public void changedUpdate(DocumentEvent e) {
updateName();
}
private void updateName() {
TextPropertiesPanel.this.setName(tfText.getText());
}
});
setName(tfText.getText());
cbxformat.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ((cbxformat.getSelectedIndex() == TextShape.FORMAT_DECIMAL)
|| (cbxformat.getSelectedIndex() == TextShape.FORMAT_SCIENTIFIC)) {
nfformat.setEnabled(true);
lformatdigits.setEnabled(true);
} else {
nfformat.setEnabled(false);
lformatdigits.setEnabled(false);
}
if (cbxformat.getSelectedIndex() == TextShape.FORMAT_USE_DATA_SOURCE) {
if (DataInfo.getPrintfFormat(source) != null) {
tfPrintfFormat.setText(DataInfo.getPrintfFormat(source));
} else {
tfPrintfFormat.setText("");
if (JSynoptic.gui != null) {
JSynoptic.gui.setStatus(resources.getString("NoDataSourceFormat"));
} else {
System.err.println(resources.getString("NoDataSourceFormat"));
}
}
tfPrintfFormat.setEditable(false);
} else if (cbxformat.getSelectedIndex() == TextShape.FORMAT_PRINTF) {
tfPrintfFormat.setEditable(true);
}
CardLayout cl = (CardLayout) (cards.getLayout());
if (cbxformat.getSelectedIndex() == TextShape.FORMAT_MAPPER) {
cl.show(cards, "mapper");
} else if ((cbxformat.getSelectedIndex() == TextShape.FORMAT_DATE)
|| (cbxformat.getSelectedIndex() == TextShape.FORMAT_TIME)
|| (cbxformat.getSelectedIndex() == TextShape.FORMAT_DATE_TIME)) {
cl.show(cards, "noAttributes");
} else if ((cbxformat.getSelectedIndex() == TextShape.FORMAT_USE_DATA_SOURCE)
|| (cbxformat.getSelectedIndex() == TextShape.FORMAT_PRINTF)
|| (cbxformat.getSelectedIndex() == TextShape.FORMAT_DATE_TIME)) {
cl.show(cards, "printfFormat");
} else {
cl.show(cards, "jsynopticFormat");
}
}
});
dstree.getSourceTree().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {