first stab at adding support for a user-specific fixed window width

This commit is contained in:
Gered 2016-01-16 12:17:07 -05:00
parent a30d5ea135
commit 24df5f0f1a
8 changed files with 133 additions and 26 deletions

View file

@ -35,7 +35,7 @@ import java.util.logging.Logger;
*/ */
public class Llanfair extends BorderlessFrame implements TableModelListener, public class Llanfair extends BorderlessFrame implements TableModelListener,
LocaleListener, MouseWheelListener, ActionListener, NativeKeyListener, LocaleListener, MouseWheelListener, ActionListener, NativeKeyListener,
PropertyChangeListener, WindowListener { PropertyChangeListener, WindowListener, ComponentListener {
private static Resources RESOURCES = null; private static Resources RESOURCES = null;
@ -74,6 +74,7 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
RESOURCES = new Resources(); RESOURCES = new Resources();
registerFonts(); registerFonts();
setLookAndFeel(); setLookAndFeel();
addComponentListener(this);
run = new Run(); run = new Run();
runPane = null; runPane = null;
@ -349,9 +350,10 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
|| Settings.footerShowDeltaLabels.equals(property) || Settings.footerShowDeltaLabels.equals(property)
|| Settings.footerVerbose.equals(property) || Settings.footerVerbose.equals(property)
|| Settings.footerMultiline.equals(property) || Settings.footerMultiline.equals(property)
|| Settings.windowAutoSize.equals(property)
|| Settings.windowWidth.equals(property)
|| Run.NAME_PROPERTY.equals(property)) { || Run.NAME_PROPERTY.equals(property)) {
setPreferredSize(null); forceResize();
pack();
} }
} }
@ -425,6 +427,20 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
@Override public void windowDeiconified(WindowEvent event) {} @Override public void windowDeiconified(WindowEvent event) {}
@Override
public void componentResized(ComponentEvent e) {
// we may have to override the width, but allow the height to grow as needed
// don't have to change anything if autosizing
if (!Settings.windowAutoSize.get())
setSize(new Dimension(Settings.windowWidth.get(), getHeight()));
}
@Override public void componentMoved(ComponentEvent e) {}
@Override public void componentShown(ComponentEvent e) {}
@Override public void componentHidden(ComponentEvent e) {}
/** /**
* Action events are fired by clicking on the entries of the context menu. * Action events are fired by clicking on the entries of the context menu.
*/ */
@ -499,4 +515,15 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
} }
} }
private void forceResize() {
Dimension newSize = new Dimension();
newSize.height = getHeight();
if (Settings.windowAutoSize.get())
newSize.width = getWidth();
else
newSize.width = Settings.windowWidth.get();
setSize(newSize);
pack();
}
} }

View file

@ -37,6 +37,8 @@ public class Settings {
public static final Property<Compare> compareMethod = new Property<>( "compareMethod" ); public static final Property<Compare> compareMethod = new Property<>( "compareMethod" );
public static final Property<Accuracy> accuracy = new Property<>( "accuracy" ); public static final Property<Accuracy> accuracy = new Property<>( "accuracy" );
public static final Property<Boolean> warnOnReset = new Property<>( "warnOnReset" ); public static final Property<Boolean> warnOnReset = new Property<>( "warnOnReset" );
public static final Property<Boolean> windowAutoSize = new Property<>( "windowAutoSize" );
public static final Property<Integer> windowWidth = new Property<>( "windowWidth" );
/* COLOR properties */ /* COLOR properties */
@ -211,6 +213,8 @@ public class Settings {
global.put( compareMethod.key, Compare.BEST_OVERALL_RUN ); global.put( compareMethod.key, Compare.BEST_OVERALL_RUN );
global.put( accuracy.key, Accuracy.TENTH ); global.put( accuracy.key, Accuracy.TENTH );
global.put( warnOnReset.key, true ); global.put( warnOnReset.key, true );
global.put( windowAutoSize.key, true );
global.put( windowWidth.key, null );
global.put( colorBackground.key, Color.decode("0x000000") ); global.put( colorBackground.key, Color.decode("0x000000") );
global.put( colorForeground.key, Color.decode( "0xc0c0c0" ) ); global.put( colorForeground.key, Color.decode( "0xc0c0c0" ) );

View file

@ -40,6 +40,14 @@ public class TabGeneral extends SettingsTab implements ActionListener {
private JCheckBox warnOnReset; private JCheckBox warnOnReset;
private JLabel windowSizeLabel;
private JCheckBox windowAutoSize;
private JTextField windowSize;
private JLabel windowSizeUnitsText;
// ----------------------------------------------------------- CONSTRUCTORS // ----------------------------------------------------------- CONSTRUCTORS
TabGeneral() { TabGeneral() {
@ -75,6 +83,21 @@ public class TabGeneral extends SettingsTab implements ActionListener {
warnOnReset.setSelected(Settings.warnOnReset.get()); warnOnReset.setSelected(Settings.warnOnReset.get());
warnOnReset.addActionListener(this); warnOnReset.addActionListener(this);
windowSizeLabel = new JLabel("Window Width");
windowAutoSize = new JCheckBox("Autosize");
windowAutoSize.setSelected(Settings.windowAutoSize.get());
windowAutoSize.addActionListener(this);
String windowWidthText = "";
if (Settings.windowWidth.get() != null)
windowWidthText = "" + Settings.windowWidth.get();
windowSize = new JTextField(windowWidthText, 4);
windowSize.setEnabled(!windowAutoSize.isSelected());
windowSize.addActionListener(this);
windowSizeUnitsText = new JLabel("pixels");
languageText = new JLabel("" + Language.setting_language); languageText = new JLabel("" + Language.setting_language);
alwaysOnTopText = new JLabel("" + Language.APPLICATION); alwaysOnTopText = new JLabel("" + Language.APPLICATION);
compareText = new JLabel("" + Language.COMPARE_METHOD); compareText = new JLabel("" + Language.COMPARE_METHOD);
@ -100,13 +123,29 @@ public class TabGeneral extends SettingsTab implements ActionListener {
} }
} else if (source.equals(warnOnReset)) { } else if (source.equals(warnOnReset)) {
Settings.warnOnReset.set(warnOnReset.isSelected()); Settings.warnOnReset.set(warnOnReset.isSelected());
} else if (source.equals(windowAutoSize)) {
windowSize.setEnabled(!windowAutoSize.isSelected());
} }
} }
// -------------------------------------------------------------- INHERITED // -------------------------------------------------------------- INHERITED
void doDelayedSettingChange() { void doDelayedSettingChange() throws InvalidSettingException {
Settings.alwaysOnTop.set(alwaysOnTop.isSelected()); Settings.alwaysOnTop.set(alwaysOnTop.isSelected());
Settings.windowAutoSize.set(windowAutoSize.isSelected());
if (!windowAutoSize.isSelected()) {
int windowWidth;
try {
windowWidth = Integer.parseInt(windowSize.getText().trim());
}
catch (Exception ex) {
throw new InvalidSettingException(this, windowSize, "Window Width must be a positive integer.");
}
Settings.windowWidth.set(windowWidth);
}
} }
/** /**
@ -150,6 +189,17 @@ public class TabGeneral extends SettingsTab implements ActionListener {
} }
add(accuracyText, GBC.grid(0, 4).anchor(GBC.FLE).insets(14, 10)); add(accuracyText, GBC.grid(0, 4).anchor(GBC.FLE).insets(14, 10));
add(accuracyPanel, GBC.grid(1, 4).fill(GBC.H).insets(10, 0)); add(accuracyPanel, GBC.grid(1, 4).fill(GBC.H).insets(10, 0));
add(windowSizeLabel, GBC.grid(0, 5).anchor(GBC.LE).insets(5, 10));
add(windowAutoSize, GBC.grid(1, 5).anchor(GBC.LS));
JPanel windowSizeContainer = new JPanel();
windowSizeContainer.add(windowSize);
windowSizeContainer.add(windowSizeUnitsText);
add(windowSizeContainer, GBC.grid(1, 6).anchor(GBC.LS));
}
private void validateWindowWidthText() {
System.out.println("windowWidth: " + windowSize.getText());
} }
// --------------------------------------------------------- INTERNAL TYPES // --------------------------------------------------------- INTERNAL TYPES

View file

@ -198,8 +198,7 @@ class Core extends JPanel implements ActionListener {
updateValues(ALL); updateValues(ALL);
updateVisibility(ALL); updateVisibility(ALL);
updateColors(ALL); updateColors(ALL);
resize = true; forceResize();
revalidate();
} }
/** /**
@ -381,49 +380,46 @@ class Core extends JPanel implements ActionListener {
} else if (Settings.compareMethod.equals(property)) { } else if (Settings.compareMethod.equals(property)) {
updateValues(TIME); updateValues(TIME);
updateColors(TIMER); updateColors(TIMER);
resize = true; forceResize();
revalidate();
} else if (Settings.accuracy.equals(property)) { } else if (Settings.accuracy.equals(property)) {
updateValues(TIME | TIMER); updateValues(TIME | TIMER);
resize = true; forceResize();
revalidate();
} else if (Settings.coreShowBestTime.equals(property) } else if (Settings.coreShowBestTime.equals(property)
|| Settings.coreShowSegmentTime.equals(property) || Settings.coreShowSegmentTime.equals(property)
|| Settings.coreShowSplitTime.equals(property)) { || Settings.coreShowSplitTime.equals(property)) {
updateVisibility(TIME); updateVisibility(TIME);
resize = true; forceResize();
revalidate();
} else if (Settings.coreShowSegmentName.equals(property)) { } else if (Settings.coreShowSegmentName.equals(property)) {
updateVisibility(NAME); updateVisibility(NAME);
resize = true; forceResize();
revalidate();
} else if (Settings.coreIconSize.equals(property)) { } else if (Settings.coreIconSize.equals(property)) {
resize = true; forceResize();
revalidate();
} else if (Settings.coreTimerFont.equals(property) } else if (Settings.coreTimerFont.equals(property)
|| Settings.coreSegmentTimerFont.equals(property)) { || Settings.coreSegmentTimerFont.equals(property)) {
updateFonts(TIMER); updateFonts(TIMER);
resize = true; forceResize();
revalidate();
} else if (Settings.coreShowSegmentTimer.equals(property)) { } else if (Settings.coreShowSegmentTimer.equals(property)) {
updateVisibility(TIMER); updateVisibility(TIMER);
resize = true; forceResize();
revalidate();
} else if (Settings.coreShowIcons.equals(property)) { } else if (Settings.coreShowIcons.equals(property)) {
updateVisibility(ICON); updateVisibility(ICON);
resize = true; forceResize();
revalidate();
} else if (Settings.coreFont.equals(property)) { } else if (Settings.coreFont.equals(property)) {
updateFonts(NAME); updateFonts(NAME);
resize = true; forceResize();
revalidate();
} else if (Settings.coreOtherTimeFont.equals(property)) { } else if (Settings.coreOtherTimeFont.equals(property)) {
updateFonts(TIME); updateFonts(TIME);
resize = true; forceResize();
revalidate(); } else if (Settings.windowAutoSize.equals(property) || Settings.windowWidth.equals(property)) {
updateSize();
forceResize();
} }
} }
private void forceResize() {
resize = true;
revalidate();
}
/** /**
* Callback invoked by the parent when the run table of segments is * Callback invoked by the parent when the run table of segments is
* updated. * updated.
@ -638,6 +634,9 @@ class Core extends JPanel implements ActionListener {
} }
} }
private void updateSize() {
}
private boolean isShowingNegativeTime() { private boolean isShowingNegativeTime() {
if (run != null) { if (run != null) {
Time time = run.getTime(Segment.LIVE); Time time = run.getTime(Segment.LIVE);

View file

@ -224,6 +224,9 @@ class Footer extends JPanel {
} else if (Settings.coreOtherTimeFont.equals(property)) { } else if (Settings.coreOtherTimeFont.equals(property)) {
updateFonts(TIME | DELTA); updateFonts(TIME | DELTA);
forceResize(); forceResize();
} else if (Settings.windowAutoSize.equals(property) || Settings.windowWidth.equals(property)) {
updateSize();
forceResize();
} }
} }
@ -521,4 +524,7 @@ class Footer extends JPanel {
labelDeltaBest.setText("" + Language.LB_FT_DELTA_BEST); labelDeltaBest.setText("" + Language.LB_FT_DELTA_BEST);
} }
} }
private void updateSize() {
}
} }

View file

@ -172,9 +172,16 @@ class Graph extends JPanel {
} }
} else if (Settings.coreFont.equals(property)) { } else if (Settings.coreFont.equals(property)) {
updateFonts(ALL); updateFonts(ALL);
} else if (Settings.windowAutoSize.equals(property) || Settings.windowWidth.equals(property)) {
updateSize();
forceResize();
} }
} }
private void forceResize() {
revalidate();
}
/** /**
* Callback invoked by the parent when the run table of segments is * Callback invoked by the parent when the run table of segments is
* updated. * updated.
@ -285,6 +292,9 @@ class Graph extends JPanel {
} }
} }
private void updateSize() {
}
// ---------------------------------------------------------- INTERNAL TYPE // ---------------------------------------------------------- INTERNAL TYPE
/** /**

View file

@ -281,6 +281,9 @@ public class History extends JPanel {
updateValues(TIME | LIVE); updateValues(TIME | LIVE);
updateColors(TIME); updateColors(TIME);
forceResize(); forceResize();
} else if (Settings.windowAutoSize.equals(property) || Settings.windowWidth.equals(property)) {
updateSize();
forceResize();
} }
} }
@ -446,6 +449,9 @@ public class History extends JPanel {
updateFonts(identifier, 0, run.getRowCount() - 1); updateFonts(identifier, 0, run.getRowCount() - 1);
} }
private void updateSize() {
}
// --------------------------------------------------------- INTERNAL TYPES // --------------------------------------------------------- INTERNAL TYPES
private class SegmentRow extends JPanel { private class SegmentRow extends JPanel {

View file

@ -248,6 +248,8 @@ public class RunPane extends JPanel {
updateFonts(TITLE); updateFonts(TITLE);
} else if (Settings.coreFont.equals(property)) { } else if (Settings.coreFont.equals(property)) {
updateFonts(ALL & ~TITLE); updateFonts(ALL & ~TITLE);
} else if (Settings.windowAutoSize.equals(property) || Settings.windowWidth.equals(property)) {
updateSize();
} }
} }
@ -418,6 +420,9 @@ public class RunPane extends JPanel {
repaint(); repaint();
} }
private void updateSize() {
}
private String sanitizeTitleString(String title) { private String sanitizeTitleString(String title) {
return title return title
.replace("<", "&lt;") .replace("<", "&lt;")