diff --git a/src/studio/ui/chart/ChartConfigPanel.java b/src/studio/ui/chart/ChartConfigPanel.java index c43a6ce..96b2dcb 100644 --- a/src/studio/ui/chart/ChartConfigPanel.java +++ b/src/studio/ui/chart/ChartConfigPanel.java @@ -109,7 +109,10 @@ public void addLine(Line line) { String title = "Line " + (1+ listLines.getListSize()); line.setTitle(title); lines.add(line); - listLines.add(title, line.getIcon(), detailsAction); + int index = listLines.add(title, line.getIcon(), detailsAction); + line.addChangeListener(e -> { + listLines.updateTitle(index, line.getTitle()); + }); } private void showDetails(Line line) { diff --git a/src/studio/ui/chart/LegendListPanel.java b/src/studio/ui/chart/LegendListPanel.java index b7db751..d551bdc 100644 --- a/src/studio/ui/chart/LegendListPanel.java +++ b/src/studio/ui/chart/LegendListPanel.java @@ -54,7 +54,7 @@ public void add(String title, LegendIcon icon) { add(title, icon, null); } - public void add(String title, LegendIcon icon, Action ... additionalActions) { + public int add(String title, LegendIcon icon, Action ... additionalActions) { JCheckBox checkBox = new JCheckBox(title, true); checkBox.addActionListener(e -> notifyListeners() ); LegendButton button = new LegendButton(icon, line, shape, bar); @@ -66,6 +66,11 @@ public void add(String title, LegendIcon icon, Action ... additionalActions) { checkBoxes.add(checkBox); buttons.add(button); updateLayout(); + return checkBoxes.size()-1; + } + + public void updateTitle(int index, String title) { + checkBoxes.get(index).setText(title); } public int getListSize() { diff --git a/src/studio/ui/chart/Line.java b/src/studio/ui/chart/Line.java index 6c6af3a..a9d83b7 100644 --- a/src/studio/ui/chart/Line.java +++ b/src/studio/ui/chart/Line.java @@ -13,6 +13,7 @@ import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class Line extends AbstractAnnotation implements XYAnnotation { @@ -150,7 +151,10 @@ public String getTitle() { } public void setTitle(String title) { + if (Objects.equals(this.title, title)) return; + this.title = title; + fireAnnotationChanged(); } public LegendIcon getIcon() { diff --git a/src/studio/ui/chart/LineInfoFrame.java b/src/studio/ui/chart/LineInfoFrame.java index 337566b..3f7940c 100644 --- a/src/studio/ui/chart/LineInfoFrame.java +++ b/src/studio/ui/chart/LineInfoFrame.java @@ -6,6 +6,8 @@ import javax.swing.*; import java.awt.*; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.function.DoubleConsumer; @@ -72,11 +74,22 @@ private Editor withAction(Editor editor, DoubleConsumer action) { return editor; } + private void updateTitle() { + line.setTitle(txtTitle.getText()); + } + private void initComponents() { setTitle(getTitle()); setDefaultCloseOperation(DISPOSE_ON_CLOSE); JLabel lblTitle = new JLabel("Title"); + txtTitle.addActionListener(e -> updateTitle()); + txtTitle.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + updateTitle(); + } + }); @@ -154,6 +167,9 @@ private void updateY(double newY) { } private void refresh() { + if (! super.getTitle().equals(getTitle())) { + setTitle(getTitle()); + } if (lockDX) dy = line.getDY(dx); else dx = line.getDX(dy);