Skip to content

Commit

Permalink
Line title can be amended now
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Dec 18, 2024
1 parent a8bf385 commit 9ca6e70
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/studio/ui/chart/ChartConfigPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion src/studio/ui/chart/LegendListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions src/studio/ui/chart/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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() {
Expand Down
16 changes: 16 additions & 0 deletions src/studio/ui/chart/LineInfoFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
});



Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 9ca6e70

Please sign in to comment.