001: package salomeTMF_plug.requirements.ihm;
002:
003: import java.awt.Color;
004: import java.awt.Cursor;
005: import java.awt.GridLayout;
006: import java.awt.event.ActionEvent;
007: import java.awt.event.ActionListener;
008: import java.util.Observer;
009:
010: import javax.swing.JPanel;
011: import javax.swing.JRadioButton;
012: import javax.swing.tree.TreePath;
013:
014: import org.objectweb.salome_tmf.ihm.languages.Language;
015: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
016:
017: import salomeTMF_plug.requirements.data.IReqFilter;
018: import salomeTMF_plug.requirements.data.ReqFilter;
019:
020: public class FiltrePanel extends JPanel implements ActionListener {
021:
022: JRadioButton bHigh;
023: JRadioButton bMedium;
024: JRadioButton bLow;
025: JRadioButton bNone;
026: int filtre = ReqFilter.P_FILTRE;
027: IReqFilter m_ReqFilter;
028: FilterReqTreeModel m_FilterReqTreeModel;
029: Observer pObserver = null;
030:
031: public FiltrePanel(FilterReqTreeModel pFilterReqTreeModel) {
032: super ();
033: m_FilterReqTreeModel = pFilterReqTreeModel;
034: if (m_FilterReqTreeModel != null) {
035: m_ReqFilter = pFilterReqTreeModel.getFilter();
036: }
037: initComponent();
038: }
039:
040: public FiltrePanel(FilterReqTreeModel pFilterReqTreeModel,
041: Observer _pObserver) {
042: super ();
043: m_FilterReqTreeModel = pFilterReqTreeModel;
044: if (m_FilterReqTreeModel != null) {
045: m_ReqFilter = pFilterReqTreeModel.getFilter();
046: }
047: initComponent();
048: pObserver = _pObserver;
049: }
050:
051: void initComponent() {
052: setLayout(new GridLayout(1, 4));
053: bHigh = new JRadioButton(Language.getInstance().getText(
054: "Filtre_Exigence_Haute"), true);
055: bHigh.setForeground(Color.red);
056:
057: bMedium = new JRadioButton(Language.getInstance().getText(
058: "Filtre_Exigence_Moyenne"), true);
059: bMedium.setForeground(Color.blue);
060:
061: bLow = new JRadioButton(Language.getInstance().getText(
062: "Filtre_Exigence_Faible"), true);
063: bLow.setForeground(Color.BLACK);
064:
065: bNone = new JRadioButton(Language.getInstance().getText(
066: "Filtre_Exigence_Option"), true);
067: bNone.setForeground(Color.gray);
068:
069: bHigh.addActionListener(this );
070: bMedium.addActionListener(this );
071: bLow.addActionListener(this );
072: bNone.addActionListener(this );
073: add(bHigh);
074: add(bMedium);
075: add(bLow);
076: add(bNone);
077: }
078:
079: public void actionPerformed(ActionEvent evt) {
080: if (evt.getSource().equals(bHigh)) {
081: bHighPerformed();
082: } else if (evt.getSource().equals(bMedium)) {
083: bMediumPerformed();
084: } else if (evt.getSource().equals(bLow)) {
085: bLowPerformed();
086: } else if (evt.getSource().equals(bNone)) {
087: bNonePerformed();
088: }
089: }
090:
091: int getMaxSelected() {
092: if (bHigh.isSelected()) {
093: return ReqFilter.P_HIGHT;
094: }
095: if (bMedium.isSelected()) {
096: return ReqFilter.P_MEDIUM;
097: }
098: if (bLow.isSelected()) {
099: return ReqFilter.P_LOW;
100: }
101: if (bNone.isSelected()) {
102: return ReqFilter.P_NONE;
103: }
104: return ReqFilter.P_HIGHT;
105: }
106:
107: /****************** Actions *************/
108: void bHighPerformed() {
109: filtre = getFiltre();
110: applyFilter();
111: }
112:
113: void bMediumPerformed() {
114: filtre = getFiltre();
115: applyFilter();
116: }
117:
118: void bLowPerformed() {
119: filtre = getFiltre();
120: applyFilter();
121: }
122:
123: void bNonePerformed() {
124: filtre = getFiltre();
125: applyFilter();
126: }
127:
128: int getFiltre() {
129: int f = 0;
130: if (bHigh.isSelected()) {
131: f = f | ReqFilter.P_HIGHT;
132: }
133: if (bMedium.isSelected()) {
134: f = f | ReqFilter.P_MEDIUM;
135: }
136: if (bLow.isSelected()) {
137: f = f | ReqFilter.P_LOW;
138: }
139: if (bNone.isSelected()) {
140: f = f | ReqFilter.P_NONE;
141: }
142: return f;
143: }
144:
145: IReqFilter getFilter() {
146: return m_ReqFilter;
147: }
148:
149: void reInit(boolean filter) {
150: bHigh.setSelected(true);
151: bMedium.setSelected(true);
152: bLow.setSelected(true);
153: bNone.setSelected(true);
154: if (filter) {
155: m_ReqFilter.reInit();
156: }
157: }
158:
159: void applyFilter() {
160: SalomeTMFContext.getInstance().getSalomeFrame().setCursor(
161: new Cursor(Cursor.WAIT_CURSOR));
162: if (m_ReqFilter != null) {
163: m_ReqFilter.setFilter(filtre);
164: m_FilterReqTreeModel.setFiltered(true);
165: }
166: if (pObserver != null) {
167: pObserver.update(null, new ReqEvent(
168: ReqEvent.FILTRE_REQ_CHANGE, null));
169: }
170: SalomeTMFContext.getInstance().getSalomeFrame().setCursor(
171: new Cursor(Cursor.DEFAULT_CURSOR));
172: }
173: }
|