001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.wizard;
019:
020: import java.awt.BorderLayout;
021: import java.awt.Color;
022:
023: import javax.swing.ButtonGroup;
024: import javax.swing.JLabel;
025: import javax.swing.JPanel;
026: import javax.swing.JRadioButton;
027: import javax.swing.JTextField;
028: import javax.swing.border.LineBorder;
029: import javax.swing.event.ChangeEvent;
030: import javax.swing.event.ChangeListener;
031:
032: import de.finix.contelligent.client.base.ContelligentComponent;
033: import de.finix.contelligent.client.i18n.Resources;
034: import de.finix.contelligent.client.util.TableLayout;
035: import de.finix.contelligent.client.util.dnd.ComponentDropEvent;
036: import de.finix.contelligent.client.util.dnd.ComponentDropListener;
037: import de.finix.contelligent.client.util.dnd.JPanelDND;
038: import de.finix.contelligent.client.util.list.NameValueComboBox;
039: import de.finix.contelligent.client.util.list.NameValueListModel;
040:
041: public class IconPane extends JPanel implements ChangeListener,
042: ComponentDropListener {
043: private String iconIdentifier;
044:
045: private JRadioButton systemIcon = new JRadioButton(Resources
046: .getLocalString("system_icon"));
047:
048: private NameValueComboBox systemIcons = new NameValueComboBox(
049: new NameValueListModel(NameValueListModel
050: .buildNameValuePairs(
051: (String[]) Resources.getIcons().keySet()
052: .toArray(new String[0]), Resources
053: .getIcons().values().toArray())));
054:
055: private JRadioButton customIcon = new JRadioButton(Resources
056: .getLocalString("custom_icon"));
057:
058: private JTextField customIconPath = new JTextField();
059:
060: private JPanelDND dropPanel;
061:
062: public IconPane(String iconIdentifier, String environment) {
063: super (new TableLayout(
064: new double[][] {
065: { TableLayout.FILL },
066: { TableLayout.PREFERRED, TableLayout.PREFERRED,
067: 5, TableLayout.PREFERRED,
068: TableLayout.PREFERRED } }));
069: this .iconIdentifier = iconIdentifier;
070: dropPanel = new JPanelDND(new BorderLayout(), environment);
071: ButtonGroup group = new ButtonGroup();
072: group.add(systemIcon);
073: group.add(customIcon);
074: systemIcon.addChangeListener(this );
075: customIcon.addChangeListener(this );
076: if (Resources.isSystemIcon(iconIdentifier)) {
077: systemIcon.setSelected(true);
078: } else {
079: customIcon.setSelected(true);
080: }
081: add(systemIcon, "0,0");
082: systemIcons.setSelectedItemByValue(iconIdentifier);
083: add(systemIcons, "0,1");
084: add(customIcon, "0,3");
085: add(customIconPath, "0,4");
086: JLabel dropLabel = new JLabel(Resources
087: .getLocalString("drop_icon"), JLabel.CENTER);
088: dropLabel.setBorder(new LineBorder(Color.gray, 1, true));
089: dropPanel.add(dropLabel, BorderLayout.CENTER);
090: dropPanel.addComponentDropListener(this );
091: // add(dropPanel, "0,6");
092: }
093:
094: public void stateChanged(ChangeEvent event) {
095: if (systemIcon.isSelected()) {
096: systemIcons.setEnabled(true);
097: customIconPath.setEnabled(false);
098: dropPanel.setDropEnabled(false);
099: } else {
100: customIconPath.setText(iconIdentifier);
101: systemIcons.setEnabled(false);
102: customIconPath.setEnabled(true);
103: dropPanel.setDropEnabled(true);
104: }
105: }
106:
107: public String getIconIdentifier() {
108: if (systemIcon.isSelected()) {
109: return (String) systemIcons.getSelectedItemValue();
110: } else {
111: return customIconPath.getText();
112: }
113: }
114:
115: public void componentDropped(ComponentDropEvent e) {
116: ContelligentComponent draggedComponent = e
117: .getDraggedComponent();
118: customIconPath.setText(draggedComponent.getPath());
119: }
120: }
|