From 8858b05744b41f8deac9ef46a7dcf7e35b94b2eb Mon Sep 17 00:00:00 2001
From: pablo rodriguez <58742538+1-pablo-rodriguez@users.noreply.github.com>
Date: Sun, 13 Nov 2022 08:58:51 +0100
Subject: [PATCH] =?UTF-8?q?MAJ=20(coloration=20des=20nodes=20=C3=A9valu?=
=?UTF-8?q?=C3=A9s)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.classpath | 2 +-
bin/.gitignore | 4 -
src/fenetres/MyCellRenderer.java | 66 +++++++++++++++
src/fenetres/MyTreeCellEditor.java | 68 +++++++++++++++
src/fenetres/MyTreeCellRenderer.java | 43 +++++++---
src/fenetres/create.java | 83 ++++++++++---------
src/fenetres/create_act/actEvalueFalse.java | 1 +
src/fenetres/create_act/actEvalueTrue.java | 1 +
.../create_act/actNewFichierAnalyse.java | 2 +-
9 files changed, 216 insertions(+), 54 deletions(-)
create mode 100644 src/fenetres/MyCellRenderer.java
create mode 100644 src/fenetres/MyTreeCellEditor.java
diff --git a/.classpath b/.classpath
index 7242b9c..ea03344 100644
--- a/.classpath
+++ b/.classpath
@@ -14,6 +14,6 @@
-
+
diff --git a/bin/.gitignore b/bin/.gitignore
index 78b40c7..75cdcb7 100644
--- a/bin/.gitignore
+++ b/bin/.gitignore
@@ -1,5 +1 @@
-/MEPTL/
-/calcul/
-/evaluer/
/fenetres/
-/list/
diff --git a/src/fenetres/MyCellRenderer.java b/src/fenetres/MyCellRenderer.java
new file mode 100644
index 0000000..2bebfa2
--- /dev/null
+++ b/src/fenetres/MyCellRenderer.java
@@ -0,0 +1,66 @@
+package fenetres;
+
+import java.awt.Color;
+import java.awt.Component;
+
+import javax.swing.ImageIcon;
+import javax.swing.JComponent;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+
+import cXML.node;
+
+public class MyCellRenderer extends DefaultTreeCellRenderer{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Component getTreeCellRendererComponent(JTree tree, Object value,
+ boolean isSelected, boolean expanded, boolean leaf, int row,
+ boolean hasFocus) {
+
+ JComponent c = (JComponent) super.getTreeCellRendererComponent(tree, value, isSelected, expanded, leaf, row, hasFocus);
+
+
+ DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
+
+
+ cellRenderer.setOpenIcon(new ImageIcon(create.class.getResource("/resources/treeOpen.png")));
+ cellRenderer.setClosedIcon(new ImageIcon(create.class.getResource("/resources/treeClose.png")));
+ cellRenderer.setLeafIcon(new ImageIcon(create.class.getResource("/resources/treeLeaf.png")));
+
+ cellRenderer.setBackgroundNonSelectionColor(new Color(255, 255, 221));
+ cellRenderer.setBackgroundSelectionColor(new Color(0, 0, 128));
+ cellRenderer.setBorderSelectionColor(Color.black);
+ cellRenderer.setTextSelectionColor(Color.white);
+ cellRenderer.setTextNonSelectionColor(Color.blue);
+
+
+ node data = null;
+ if (value instanceof DefaultMutableTreeNode) {
+ final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) value;
+ final Object userObject = node1.getUserObject();
+ if (userObject instanceof node) {
+ data = (node) userObject;
+ }
+ }
+
+
+
+ if(data!=null) if(data.isEvaluate()) {
+ c.setForeground(Color.blue);
+ c.setBackground(Color.green);
+ c.setOpaque(true);
+ }
+
+
+
+
+ return c;
+ }
+ }
diff --git a/src/fenetres/MyTreeCellEditor.java b/src/fenetres/MyTreeCellEditor.java
new file mode 100644
index 0000000..2697abd
--- /dev/null
+++ b/src/fenetres/MyTreeCellEditor.java
@@ -0,0 +1,68 @@
+package fenetres;
+
+import java.awt.Component;
+import java.awt.event.ComponentListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.AbstractCellEditor;
+import javax.swing.JPanel;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreeCellEditor;
+
+import cXML.node;
+
+
+
+
+public class MyTreeCellEditor extends AbstractCellEditor implements TreeCellEditor{
+
+
+ private final JTree theTree;
+
+ public MyTreeCellEditor(final JTree tree) {
+ theTree = tree;
+ }
+
+ @Override
+ public Object getCellEditorValue() {
+ // TODO Auto-generated method stub
+// DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) theTree.getSelectionPath().getLastPathComponent();
+//
+// final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) selectNode;
+// final Object userObject = node1.getUserObject();
+//
+// final node nod = renderer.getPanel();
+// final CheckBoxNodeData checkBoxNode =
+// new CheckBoxNodeData(panel.label.getText(), panel.check.isSelected());
+// return checkBoxNode;
+ return null;
+ }
+
+ @Override
+ public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded,
+ boolean leaf, int row) {
+ final Component editor = tree.getCellRenderer().getTreeCellRendererComponent(tree, value, isSelected, expanded, leaf, row, leaf);
+//
+//
+// // editor always selected / focused
+// final ItemListener itemListener = new ItemListener() {
+//
+// @Override
+// public void itemStateChanged(final ItemEvent itemEvent) {
+// if (stopCellEditing()) {
+// fireEditingStopped();
+// }
+// }
+// };
+//
+// if (editor instanceof JPanel) {
+// final JPanel panel = (JPanel) editor;
+// panel.ItemListener((ItemListener) itemListener);
+// }
+
+ return editor;
+ }
+
+}
diff --git a/src/fenetres/MyTreeCellRenderer.java b/src/fenetres/MyTreeCellRenderer.java
index 7204966..a28f21e 100644
--- a/src/fenetres/MyTreeCellRenderer.java
+++ b/src/fenetres/MyTreeCellRenderer.java
@@ -2,7 +2,9 @@ package fenetres;
import java.awt.Color;
import java.awt.Component;
+import java.awt.Font;
+import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
@@ -21,19 +23,40 @@ public class MyTreeCellRenderer extends DefaultTreeCellRenderer {
boolean sel, boolean exp, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, exp, leaf, row, hasFocus);
- // Assuming you have a tree of Strings
- node nod = (node) ((DefaultMutableTreeNode) value).getUserObject();
- // If the node is a leaf and ends with "xxx"
-// if (leaf && nod.endsWith("xxx")) {
-// // Paint the node in blue
-// setForeground(new Color(13, 57 ,115));
-// }
+ DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
+
+
+ cellRenderer.setOpenIcon(new ImageIcon(create.class.getResource("/resources/treeOpen.png")));
+ cellRenderer.setClosedIcon(new ImageIcon(create.class.getResource("/resources/treeClose.png")));
+ cellRenderer.setLeafIcon(new ImageIcon(create.class.getResource("/resources/treeLeaf.png")));
+
+ cellRenderer.setBackgroundNonSelectionColor(new Color(255, 255, 221));
+ cellRenderer.setBackgroundSelectionColor(new Color(160, 160, 230));
+ cellRenderer.setBorderSelectionColor(Color.black);
+ cellRenderer.setTextSelectionColor(Color.white);
+ cellRenderer.setTextNonSelectionColor(Color.blue);
+
+ node data = null;
+ if (value instanceof DefaultMutableTreeNode) {
+ final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) value;
+ final Object userObject = node1.getUserObject();
+ if (userObject instanceof node) {
+ data = (node) userObject;
+ }
+ }
- if(nod.getAttributs().get("evaluer")!=null) {
- if(nod.getAttributs().get("evaluer").equals("true")) setForeground(new Color(0, 240 ,50));
+ if(data!=null) {
+ if(data.isEvaluate()) {
+ setForeground(new Color(120, 30 ,30));
+ setFont(new Font("Tahoma", Font.BOLD, 14));
+ }else {
+ setForeground(new Color(0, 0 ,0));
+ setFont(new Font("Tahoma", Font.PLAIN, 12));
+ }
}
-
+
+
return this;
}
}
diff --git a/src/fenetres/create.java b/src/fenetres/create.java
index 2ba8d6b..655396c 100644
--- a/src/fenetres/create.java
+++ b/src/fenetres/create.java
@@ -1,7 +1,6 @@
package fenetres;
import java.awt.BorderLayout;
-import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
@@ -26,10 +25,10 @@ import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.tree.DefaultMutableTreeNode;
-import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
+
import MEPTL.commandes;
import MEPTL.ecritureSujet;
import cXML.Run;
@@ -111,6 +110,7 @@ import list.listeEvalNameNode;
import list.listeRechercheParAnchorPageNumber;
import javax.swing.JToggleButton;
import java.awt.GridLayout;
+import java.awt.event.ActionListener;
@@ -245,8 +245,9 @@ public final class create extends JFrame {
if(tree.getSelectionPath()!=null) {
selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
node nod = (node) selectNode.getUserObject();
- createPopupMenuTree(nod);
- textNodeSelect.refreshAffichage(nod);
+ createPopupMenuTree(nod); //création du menu contextuel du node
+ textNodeSelect.refreshAffichage(nod); //affiche des informations sur le node
+ refreshTree();
}
}
});
@@ -265,22 +266,13 @@ public final class create extends JFrame {
});
-// chckbxtoolBarRecherche.addChangeListener(new ChangeListener() {
-// public void stateChanged(ChangeEvent e) {
-// if(chckbxtoolBarRecherche.isSelected()) {
-//// panelPrincipal.add(bRecherche);
-// panelPrincipal.add(bRecherche, "cell 0 1,alignx left,aligny top");
-// bRecherche.setVisible(true);
-// bRecherche.setEnabled(true);
-// }else {
-// bRecherche.setVisible(false);
-// bRecherche.setEnabled(false);
-// panelPrincipal.remove(bRecherche);
-// }
-// }
-// });
-
-
+ }
+
+ /**
+ *
+ */
+ private void refreshTree() {
+ tree.repaint();
}
@@ -697,21 +689,41 @@ public final class create extends JFrame {
toolBarPrincipal.addSeparator();
JButton btnEvaluerTrue = toolBarPrincipal.add( new actEvalueTrue() );
+ btnEvaluerTrue.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ refreshTree();
+ }
+ });
btnEvaluerTrue.setIcon(new ImageIcon(create.class.getResource("/resources/evaluertrue.png")));
btnEvaluerTrue.setHideActionText(true);
toolBarPrincipal.add(btnEvaluerTrue);
JButton btnEvaluerFalse = toolBarPrincipal.add(new actEvalueFalse() );
+ btnEvaluerFalse.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ refreshTree();
+ }
+ });
btnEvaluerFalse.setIcon(new ImageIcon(create.class.getResource("/resources/evaluerfalse.png")));
btnEvaluerFalse.setHideActionText(true);
toolBarPrincipal.add(btnEvaluerFalse);
JButton btnEvaluerTouteLaBrancheEtLesEnfantTrue = toolBarPrincipal.add( new actEvaluerTousEnfantsTrue() );
+ btnEvaluerTouteLaBrancheEtLesEnfantTrue.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ refreshTree();
+ }
+ });
btnEvaluerTouteLaBrancheEtLesEnfantTrue.setIcon(new ImageIcon(create.class.getResource("/resources/evaluertouslesenfants.png")));
btnEvaluerTouteLaBrancheEtLesEnfantTrue.setHideActionText(true);
toolBarPrincipal.add(btnEvaluerTouteLaBrancheEtLesEnfantTrue);
JButton btnEvaluerTouteLaBrancheEtLesEnfantFalse = toolBarPrincipal.add( new actEvaluerTousEnfantsFalse() );
+ btnEvaluerTouteLaBrancheEtLesEnfantFalse.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ refreshTree();
+ }
+ });
btnEvaluerTouteLaBrancheEtLesEnfantFalse.setIcon(new ImageIcon(create.class.getResource("/resources/evaluertouslesenfantsfaux.png")));
btnEvaluerTouteLaBrancheEtLesEnfantTrue.setHideActionText(true);
toolBarPrincipal.add(btnEvaluerTouteLaBrancheEtLesEnfantFalse);
@@ -878,33 +890,23 @@ public final class create extends JFrame {
tree.setExpandsSelectedPaths(true);
tree.setInvokesStopCellEditing(true);
-
+
//Construction si c'est un fichier d'analyse
if(commandes.sujet.getNomElt().equals("fichier")) {
+
root = new DefaultMutableTreeNode(commandes.sujet,true);
+
root = addNodeMutable(commandes.sujet, root);
-
+
+
commandes.tree = new JTree(root);
- DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) commandes.tree.getCellRenderer();
-
- cellRenderer.setOpenIcon(new ImageIcon(create.class.getResource("/resources/treeOpen.png")));
- cellRenderer.setClosedIcon(new ImageIcon(create.class.getResource("/resources/treeClose.png")));
- cellRenderer.setLeafIcon(new ImageIcon(create.class.getResource("/resources/treeLeaf.png")));
-
- cellRenderer.setBackgroundNonSelectionColor(new Color(255, 255, 221));
- cellRenderer.setBackgroundSelectionColor(new Color(0, 0, 128));
- cellRenderer.setBorderSelectionColor(Color.black);
- cellRenderer.setTextSelectionColor(Color.white);
- cellRenderer.setTextNonSelectionColor(Color.blue);
-
-
- tree.setCellRenderer(cellRenderer);
-
-// tree.setCellRenderer(new MyTreeCellRenderer());
+ tree.setCellRenderer(new MyTreeCellRenderer());
+// tree.setCellRenderer(new MyCellRenderer());
tree.setModel(commandes.tree.getModel()) ;
+
}
}
@@ -918,11 +920,16 @@ public final class create extends JFrame {
private static DefaultMutableTreeNode addNodeMutable(node nod, DefaultMutableTreeNode parent) {
if(nod!=null) {
DefaultMutableTreeNode node1 = null;
+
for(int i = 0 ; i < nod.getNodes().size(); i++) {
+ // Le node setting ne doit pas s'afficher dans le JTree
if(!nod.getNodes().get(i).getNomElt().equals("setting")) {
+
node1 = new DefaultMutableTreeNode(nod.getNodes().get(i));
addNodeMutable(nod.getNodes().get(i), node1);
parent.add(node1);
+
+
}
}
}
diff --git a/src/fenetres/create_act/actEvalueFalse.java b/src/fenetres/create_act/actEvalueFalse.java
index 410d0c3..bb9ef15 100644
--- a/src/fenetres/create_act/actEvalueFalse.java
+++ b/src/fenetres/create_act/actEvalueFalse.java
@@ -28,6 +28,7 @@ public class actEvalueFalse extends AbstractAction{
node nod = (node) fenetres.create.getSelectNode().getUserObject();
nod.evaluerFalse();
fenetres.create.getTextNodeSelect().refreshAffichage(nod);
+ fenetres.create.getTree().repaint();
}
}
diff --git a/src/fenetres/create_act/actEvalueTrue.java b/src/fenetres/create_act/actEvalueTrue.java
index c49a241..9c676cf 100644
--- a/src/fenetres/create_act/actEvalueTrue.java
+++ b/src/fenetres/create_act/actEvalueTrue.java
@@ -32,6 +32,7 @@ public class actEvalueTrue extends AbstractAction{
nod.addMenu(true);
}
fenetres.create.getTextNodeSelect().refreshAffichage(nod);
+ fenetres.create.getTree().repaint();
}
}
diff --git a/src/fenetres/create_act/actNewFichierAnalyse.java b/src/fenetres/create_act/actNewFichierAnalyse.java
index b4b0289..619253d 100644
--- a/src/fenetres/create_act/actNewFichierAnalyse.java
+++ b/src/fenetres/create_act/actNewFichierAnalyse.java
@@ -80,7 +80,7 @@ public class actNewFichierAnalyse extends AbstractAction{
fenetres.create.constructionTree();
fenetres.create.getTextNodeSelect().afficheChargementFichierAnalyse();
}else {
- fenetres.create.getTextNodeSelect().setText("
Le fichier n'est pas valise
");
+ fenetres.create.getTextNodeSelect().setText("Le fichier n'est pas valide
");
}
} catch (ParserConfigurationException | SAXException | IOException | CloneNotSupportedException e1) {