|
From: <de...@us...> - 2015-11-24 23:15:50
|
Revision: 9199
http://sourceforge.net/p/fudaa/svn/9199
Author: deniger
Date: 2015-11-24 23:15:48 +0000 (Tue, 24 Nov 2015)
Log Message:
-----------
CRUE-667
Modified Paths:
--------------
trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGExportData.java
trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGLegendPanelManager.java
Modified: trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGExportData.java
===================================================================
--- trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGExportData.java 2015-11-24 23:15:41 UTC (rev 9198)
+++ trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGExportData.java 2015-11-24 23:15:48 UTC (rev 9199)
@@ -22,7 +22,6 @@
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCell;
-import org.apache.commons.lang.StringUtils;
import org.fudaa.ctulu.CtuluLib;
import org.fudaa.ctulu.CtuluLibArray;
import org.fudaa.ctulu.CtuluLibString;
Modified: trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGLegendPanelManager.java
===================================================================
--- trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGLegendPanelManager.java 2015-11-24 23:15:41 UTC (rev 9198)
+++ trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGLegendPanelManager.java 2015-11-24 23:15:48 UTC (rev 9199)
@@ -3,13 +3,21 @@
*/
package org.fudaa.ebli.courbe;
+import com.lowagie.text.Font;
+import com.memoire.bu.BuLib;
import com.memoire.bu.BuVerticalLayout;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import org.apache.commons.lang.StringUtils;
/**
*
@@ -17,6 +25,14 @@
*/
public class EGLegendPanelManager extends MouseAdapter implements EGGrapheModelListener {
+ private class LegendLine {
+
+ String txt;
+ String tooltip;
+ EGCourbe courbe;
+ int padding;
+ }
+
JPanel panel;
JPanel mainPanel;
EGGraphe graphe;
@@ -105,26 +121,104 @@
return mainPanel;
}
+ private String groupByLastSeparator;
+
+ public String getGroupByLastSeparator() {
+ return groupByLastSeparator;
+ }
+
+ /**
+ * Si non null, sera utilis\xE9 pour afficher les courbes par groupe. Par exemple les courbes C1 - Toto / 1, C2 - Toto / 1, ... seront affich\xE9es
+ * <pre>
+ * Toto / 1
+ * C1
+ * C2
+ * </pre>
+ *
+ * @param groupByLastSeparator si null, pas de groupement par suffixe
+ */
+ public void setGroupByLastSeparator(String groupByLastSeparator) {
+ this.groupByLastSeparator = groupByLastSeparator;
+ }
+
private void rebuild() {
panel.removeAll();
panel.setDoubleBuffered(false);
EGCourbe[] courbes = graphe.getModel().getCourbes();
+ List<LegendLine> lines = new ArrayList<LegendLine>();
for (EGCourbe courbe : courbes) {
if (!courbe.isVisible_) {
continue;
}
- JLabel label = new JLabel();
+ LegendLine line = new LegendLine();
+ line.courbe = courbe;
+ line.tooltip = courbe.getTitle();
+ line.txt = courbe.getTitle();
+ lines.add(line);
+ }
+ manageGroupByPrefix(lines);
+ for (LegendLine line : lines) {
+ addLabelToPanel(line);
+ }
+ panel.revalidate();
+ panel.repaint(0);
+ }
+
+ /**
+ * Si un groupement par pr\xE9fixe est demand\xE9, les lignes vont \xEAtre r\xE9agenc\xE9es pour cela.
+ *
+ * @param lines
+ */
+ private void manageGroupByPrefix(List<LegendLine> lines) {
+ if (lines.size() > 0 && StringUtils.isNotBlank(groupByLastSeparator)) {
+ //contiend les lines par prefixes
+ LinkedHashMap<String, List<LegendLine>> linesByPrefix = new LinkedHashMap<String, List<LegendLine>>();
+ for (LegendLine line : lines) {
+ String prefix = StringUtils.substringAfterLast(line.txt, groupByLastSeparator);
+ List<LegendLine> foundList = linesByPrefix.get(prefix);
+ if (foundList == null) {
+ foundList = new ArrayList<LegendLine>();
+ linesByPrefix.put(prefix, foundList);
+ }
+ foundList.add(line);
+ }
+ lines.clear();
+ for (Map.Entry<String, List<LegendLine>> entry : linesByPrefix.entrySet()) {
+ String key = entry.getKey();
+ List<LegendLine> linesByTitle = entry.getValue();
+ //s'il y a plusieurs courbes pour le pr\xE9fixe on fait un padding de 5 et on enl\xE8ve le padding
+ //si une seule line ou le pr\xE9fixe est vide on ne fait rien
+ if (StringUtils.isNotBlank(key) && linesByTitle.size() > 1) {
+ LegendLine titleLine = new LegendLine();
+ titleLine.tooltip = key;
+ titleLine.txt = key;
+ lines.add(titleLine);
+ for (LegendLine legendLine : linesByTitle) {
+ legendLine.txt = StringUtils.substringBeforeLast(legendLine.txt, groupByLastSeparator).trim();
+ legendLine.padding = 15;
+ }
+ }
+ lines.addAll(linesByTitle);
+ }
+ }
+ }
+
+ private void addLabelToPanel(LegendLine line) {
+ JLabel label = new JLabel();
+
+ label.setText(line.txt);
+ label.setToolTipText(line.tooltip);
+ if (line.courbe != null) {
EGIconForCourbe icon = new EGIconForCourbe();
- icon.updateFromCourbe(courbe);
label.setIcon(icon);
- label.setText(courbe.getTitle());
- label.setToolTipText(courbe.getTitle());
- label.putClientProperty("COURBE", courbe);
- label.setOpaque(false);
- panel.add(label);
+ icon.updateFromCourbe(line.courbe);
+ label.putClientProperty("COURBE", line.courbe);
label.addMouseListener(this);
+ } else {
+ label.setFont(BuLib.deriveFont(label.getFont(), Font.BOLD, 1));
}
- panel.revalidate();
- panel.repaint(0);
+ label.setOpaque(false);
+ label.setBorder(BorderFactory.createEmptyBorder(0, line.padding, 0, 0));
+ panel.add(label);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|