001: package org.objectweb.salome_tmf.ihm.filtre;
002:
003: import java.awt.Color;
004: import java.awt.GridLayout;
005: import java.awt.event.ActionEvent;
006: import java.awt.event.ActionListener;
007: import java.awt.event.KeyEvent;
008: import java.awt.event.KeyListener;
009:
010: import javax.swing.BorderFactory;
011: import javax.swing.JPanel;
012: import javax.swing.JRadioButton;
013: import javax.swing.JTextField;
014:
015: import org.objectweb.salome_tmf.data.DataConstants;
016: import org.objectweb.salome_tmf.ihm.languages.Language;
017: import org.objectweb.salome_tmf.ihm.models.TestTreeModel;
018:
019: public class CampagneTreeFiltrePanel extends JPanel implements
020: ActionListener {
021: JRadioButton bCampagne;
022: JTextField filtreStr;
023:
024: int filtre = -1;
025: StringSimpleDataFiltre m_dataFilter;
026: TestTreeModel m_FilterTreeModel;
027:
028: public CampagneTreeFiltrePanel(TestTreeModel pFilterTreeModel) {
029: super ();
030: m_FilterTreeModel = pFilterTreeModel;
031: m_dataFilter = new StringSimpleDataFiltre();
032: m_FilterTreeModel.setFilter(m_dataFilter);
033: initComponent();
034: }
035:
036: void initComponent() {
037: setLayout(new GridLayout(1, 4));
038: setBorder(BorderFactory.createTitledBorder(BorderFactory
039: .createLineBorder(Color.BLACK), "Filtre"));
040: filtreStr = new JTextField();
041: bCampagne = new JRadioButton(Language.getInstance().getText(
042: "Campagne"), true);
043:
044: bCampagne.setSelected(false);
045:
046: bCampagne.addActionListener(this );
047:
048: filtreStr.addKeyListener(new KeyListener() {
049: public void keyTyped(KeyEvent keyEvent) {
050:
051: }
052:
053: public void keyPressed(KeyEvent keyEvent) {
054: }
055:
056: public void keyReleased(KeyEvent keyEvent) {
057: reloadFilter();
058: }
059:
060: });
061:
062: add(filtreStr);
063: add(bCampagne);
064:
065: }
066:
067: public void actionPerformed(ActionEvent evt) {
068: if (evt.getSource().equals(bCampagne)) {
069: bCampagnePerformed();
070: }
071: }
072:
073: void bCampagnePerformed() {
074: filtre = -1;
075: if (bCampagne.isSelected()) {
076: filtre = DataConstants.CAMPAIGN;
077: }
078: applyFilter();
079: }
080:
081: void reloadFilter() {
082: if (filtre != -1) {
083: /*try {
084: Thread.sleep(100);
085: } catch (Exception e){
086: e.printStackTrace();
087: }*/
088: applyFilter();
089: }
090: }
091:
092: void applyFilter() {
093: //System.out.println("Filtre : " + filtreStr.getText() + ", type = " + filtre);
094: if (m_dataFilter != null) {
095: m_dataFilter.setFilterType(filtre);
096: m_dataFilter.setFilterStr(filtreStr.getText());
097: }
098: m_FilterTreeModel.setFiltered(true);
099: }
100:
101: public void reInit(boolean filter) {
102: bCampagne.setSelected(false);
103: filtre = -1;
104: if (filter) {
105: m_dataFilter.reInit();
106: }
107: m_FilterTreeModel.setFiltered(false);
108: }
109:
110: public boolean isActived() {
111: return (filtre != -1);
112: }
113: }
|