MAJ (coloration des nodes évalués)

This commit is contained in:
pablo rodriguez 2022-11-13 08:58:51 +01:00
parent 9e4475c2fd
commit 8858b05744
9 changed files with 216 additions and 54 deletions

View File

@ -14,6 +14,6 @@
<classpathentry kind="lib" path="C:/Users/pabr6/eclipse-workspace/zip4j-1.2.7.jar"/>
<classpathentry kind="lib" path="C:/Users/pabr6/git/analyseWriter/MEPTL/miglayout15-swing.jar"/>
<classpathentry kind="lib" path="jgoodies-forms-1.8.0.jar" sourcepath="jgoodies-forms-1.8.0-sources.jar"/>
<classpathentry kind="lib" path="C:/Users/pabr6/eclipse-workspace/cXML.jar" sourcepath="/cXML"/>
<classpathentry kind="lib" path="C:/Users/pabr6/eclipse-workspace/cXML.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

4
bin/.gitignore vendored
View File

@ -1,5 +1 @@
/MEPTL/
/calcul/
/evaluer/
/fenetres/
/list/

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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();
}
}

View File

@ -32,6 +32,7 @@ public class actEvalueTrue extends AbstractAction{
nod.addMenu(true);
}
fenetres.create.getTextNodeSelect().refreshAffichage(nod);
fenetres.create.getTree().repaint();
}
}

View File

@ -80,7 +80,7 @@ public class actNewFichierAnalyse extends AbstractAction{
fenetres.create.constructionTree();
fenetres.create.getTextNodeSelect().afficheChargementFichierAnalyse();
}else {
fenetres.create.getTextNodeSelect().setText("<h1>Le fichier n'est pas valise</h1>");
fenetres.create.getTextNodeSelect().setText("<h1>Le fichier n'est pas valide</h1>");
}
} catch (ParserConfigurationException | SAXException | IOException | CloneNotSupportedException e1) {