add support for multiline run titles. resolves #7

This commit is contained in:
Gered 2016-01-03 16:23:41 -05:00
parent 016ecd8acd
commit fd84ef242f
2 changed files with 23 additions and 21 deletions

View file

@ -49,7 +49,7 @@ implements ActionListener, ListSelectionListener {
/**
* Zone dédition du titre de la course.
*/
private JTextField runTitle;
private JTextArea runTitle;
/**
* Étiquette du {@link runTitle}.
@ -126,7 +126,7 @@ implements ActionListener, ListSelectionListener {
String delayedStartString = new Time(run.getDelayedStart()).toString(Accuracy.HUNDREDTH);
runTitle = new JTextField(run.getName(), 61);
runTitle = new JTextArea(run.getName(), 2, 61);
runTitleLabel = new JLabel(Language.RUN_TITLE.get());
runSubTitle = new JTextField(run.getSubTitle(), 61);
runDelayedStart = new JTextField(delayedStartString, 5);

View file

@ -1,26 +1,18 @@
package org.fenix.llanfair.gui;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagLayout;
import org.fenix.llanfair.Run;
import org.fenix.llanfair.Run.State;
import org.fenix.llanfair.config.Settings;
import org.fenix.utils.gui.GBC;
import org.fenix.utils.locale.LocaleEvent;
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.event.TableModelEvent;
import org.fenix.llanfair.Language;
import org.fenix.llanfair.Run;
import org.fenix.llanfair.Segment;
import org.fenix.llanfair.config.Settings;
import org.fenix.llanfair.Run.State;
import org.fenix.llanfair.Time;
import org.fenix.utils.gui.GBC;
import org.fenix.utils.locale.LocaleEvent;
/**
* A panel representing informations on a given run. This panel uses numerous
* sub-component to given different kind of informations like a graph or a
@ -154,6 +146,9 @@ public class RunPane extends JPanel {
footer = new Footer(run);
separators = new ArrayList<JLabel>();
title.setHorizontalAlignment(SwingConstants.CENTER);
subTitle.setHorizontalAlignment(SwingConstants.CENTER);
placeComponents();
setRun(run);
@ -291,7 +286,7 @@ public class RunPane extends JPanel {
* Places the sub-components within this component.
*/
private void placeComponents() {
add(title, GBC.grid(0, 0).insets(3, 0, 1, 0));
add(title, GBC.grid(0, 0).insets(3, 0, 1, 0).fill(GBC.B));
add(subTitle, GBC.grid(0, 1).insets(3, 0, 0, 0));
add(attemptCounter, GBC.grid(0, 2).insets(1, 0, 1, 3).anchor(GBC.LE));
add(createSeparator(), GBC.grid(0, 3).insets(3, 0).fill(GBC.H));
@ -310,7 +305,7 @@ public class RunPane extends JPanel {
*/
private void updateValues(int identifier) {
if ((identifier & TITLE) == TITLE) {
title.setText("" + run.getName());
title.setText("<html><div style='text-align: center;'>" + sanitizeTitleString(run.getName()) + "</div></html>");
subTitle.setText(run.getSubTitle());
}
if ((identifier & ATTEMPTS) == ATTEMPTS) {
@ -423,4 +418,11 @@ public class RunPane extends JPanel {
repaint();
}
private String sanitizeTitleString(String title) {
return title
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\n", "<br/>");
}
}