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 TestTreeFiltrePanel extends JPanel implements
020: ActionListener {
021:
022: JRadioButton bFamille;
023: JRadioButton bSuite;
024: JRadioButton bTest;
025: JTextField filtreStr;
026:
027: int filtre = -1;
028: StringSimpleDataFiltre m_dataFilter;
029: TestTreeModel m_FilterTreeModel;
030:
031: public TestTreeFiltrePanel(TestTreeModel pFilterTreeModel) {
032: super ();
033: m_FilterTreeModel = pFilterTreeModel;
034: m_dataFilter = new StringSimpleDataFiltre();
035: m_FilterTreeModel.setFilter(m_dataFilter);
036: initComponent();
037: }
038:
039: public ISimpleDataFilter getFilter() {
040: return m_dataFilter;
041: }
042:
043: void initComponent() {
044: setLayout(new GridLayout(1, 4));
045: setBorder(BorderFactory.createTitledBorder(BorderFactory
046: .createLineBorder(Color.BLACK), "Filtre"));
047: filtreStr = new JTextField();
048: bFamille = new JRadioButton(Language.getInstance().getText(
049: "Famille"), true);
050: bSuite = new JRadioButton(Language.getInstance().getText(
051: "Suite"), true);
052: bTest = new JRadioButton(
053: Language.getInstance().getText("Test"), true);
054:
055: bFamille.setSelected(false);
056: bSuite.setSelected(false);
057: bTest.setSelected(false);
058:
059: bFamille.addActionListener(this );
060: bSuite.addActionListener(this );
061: bTest.addActionListener(this );
062:
063: filtreStr.addKeyListener(new KeyListener() {
064: public void keyTyped(KeyEvent keyEvent) {
065:
066: }
067:
068: public void keyPressed(KeyEvent keyEvent) {
069: }
070:
071: public void keyReleased(KeyEvent keyEvent) {
072: reloadFilter();
073: }
074:
075: });
076:
077: add(filtreStr);
078: add(bFamille);
079: add(bSuite);
080: add(bTest);
081: }
082:
083: public void actionPerformed(ActionEvent evt) {
084: if (evt.getSource().equals(bFamille)) {
085: bFamillePerformed();
086: } else if (evt.getSource().equals(bSuite)) {
087: bSuitePerformed();
088: } else if (evt.getSource().equals(bTest)) {
089: bTestPerformed();
090: }
091: }
092:
093: void bFamillePerformed() {
094: filtre = -1;
095: if (bFamille.isSelected()) {
096: bSuite.setSelected(false);
097: bTest.setSelected(false);
098: filtre = DataConstants.FAMILY;
099: }
100: applyFilter();
101: }
102:
103: void bSuitePerformed() {
104: filtre = -1;
105: if (bSuite.isSelected()) {
106: bFamille.setSelected(false);
107: bTest.setSelected(false);
108: filtre = DataConstants.TESTLIST;
109: }
110:
111: applyFilter();
112: }
113:
114: void bTestPerformed() {
115: filtre = -1;
116: if (bTest.isSelected()) {
117: bFamille.setSelected(false);
118: bSuite.setSelected(false);
119: filtre = DataConstants.TEST;
120: }
121: applyFilter();
122: }
123:
124: void reloadFilter() {
125: if (filtre != -1) {
126: /*try {
127: Thread.sleep(100);
128: } catch (Exception e){
129: e.printStackTrace();
130: }*/
131: applyFilter();
132: }
133: }
134:
135: void applyFilter() {
136: //System.out.println("Filtre : " + filtreStr.getText() + ", type = " + filtre);
137: if (m_dataFilter != null) {
138: m_dataFilter.setFilterType(filtre);
139: m_dataFilter.setFilterStr(filtreStr.getText());
140: }
141: m_FilterTreeModel.setFiltered(true);
142: }
143:
144: public int getFiltreType() {
145: return filtre;
146: }
147:
148: public void reInit(boolean filter) {
149: bFamille.setSelected(false);
150: bSuite.setSelected(false);
151: bTest.setSelected(false);
152: if (filter) {
153: m_dataFilter.reInit();
154: }
155: }
156: }
|