diff --git a/src/main/java/org/fenix/llanfair/Llanfair.java b/src/main/java/org/fenix/llanfair/Llanfair.java index 3d219f0..97b78d4 100644 --- a/src/main/java/org/fenix/llanfair/Llanfair.java +++ b/src/main/java/org/fenix/llanfair/Llanfair.java @@ -35,7 +35,7 @@ import java.util.logging.Logger; */ public class Llanfair extends BorderlessFrame implements TableModelListener, LocaleListener, MouseWheelListener, ActionListener, NativeKeyListener, - PropertyChangeListener, WindowListener { + PropertyChangeListener, WindowListener, ComponentListener { private static Resources RESOURCES = null; @@ -74,6 +74,7 @@ public class Llanfair extends BorderlessFrame implements TableModelListener, RESOURCES = new Resources(); registerFonts(); setLookAndFeel(); + addComponentListener(this); run = new Run(); runPane = null; @@ -349,9 +350,10 @@ public class Llanfair extends BorderlessFrame implements TableModelListener, || Settings.footerShowDeltaLabels.equals(property) || Settings.footerVerbose.equals(property) || Settings.footerMultiline.equals(property) + || Settings.windowAutoSize.equals(property) + || Settings.windowWidth.equals(property) || Run.NAME_PROPERTY.equals(property)) { - setPreferredSize(null); - pack(); + forceResize(); } } @@ -425,6 +427,20 @@ public class Llanfair extends BorderlessFrame implements TableModelListener, @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. */ @@ -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(); + } + } diff --git a/src/main/java/org/fenix/llanfair/config/Settings.java b/src/main/java/org/fenix/llanfair/config/Settings.java index b2831fe..bcd8cb2 100644 --- a/src/main/java/org/fenix/llanfair/config/Settings.java +++ b/src/main/java/org/fenix/llanfair/config/Settings.java @@ -37,6 +37,8 @@ public class Settings { public static final Property compareMethod = new Property<>( "compareMethod" ); public static final Property accuracy = new Property<>( "accuracy" ); public static final Property warnOnReset = new Property<>( "warnOnReset" ); + public static final Property windowAutoSize = new Property<>( "windowAutoSize" ); + public static final Property windowWidth = new Property<>( "windowWidth" ); /* COLOR properties */ @@ -211,6 +213,8 @@ public class Settings { global.put( compareMethod.key, Compare.BEST_OVERALL_RUN ); global.put( accuracy.key, Accuracy.TENTH ); global.put( warnOnReset.key, true ); + global.put( windowAutoSize.key, true ); + global.put( windowWidth.key, null ); global.put( colorBackground.key, Color.decode("0x000000") ); global.put( colorForeground.key, Color.decode( "0xc0c0c0" ) ); diff --git a/src/main/java/org/fenix/llanfair/dialog/TabGeneral.java b/src/main/java/org/fenix/llanfair/dialog/TabGeneral.java index ae73655..8d2e274 100644 --- a/src/main/java/org/fenix/llanfair/dialog/TabGeneral.java +++ b/src/main/java/org/fenix/llanfair/dialog/TabGeneral.java @@ -40,6 +40,14 @@ public class TabGeneral extends SettingsTab implements ActionListener { private JCheckBox warnOnReset; + private JLabel windowSizeLabel; + + private JCheckBox windowAutoSize; + + private JTextField windowSize; + + private JLabel windowSizeUnitsText; + // ----------------------------------------------------------- CONSTRUCTORS TabGeneral() { @@ -75,6 +83,21 @@ public class TabGeneral extends SettingsTab implements ActionListener { warnOnReset.setSelected(Settings.warnOnReset.get()); 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); alwaysOnTopText = new JLabel("" + Language.APPLICATION); compareText = new JLabel("" + Language.COMPARE_METHOD); @@ -100,13 +123,29 @@ public class TabGeneral extends SettingsTab implements ActionListener { } } else if (source.equals(warnOnReset)) { Settings.warnOnReset.set(warnOnReset.isSelected()); + } else if (source.equals(windowAutoSize)) { + windowSize.setEnabled(!windowAutoSize.isSelected()); } } // -------------------------------------------------------------- INHERITED - void doDelayedSettingChange() { + void doDelayedSettingChange() throws InvalidSettingException { 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(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 diff --git a/src/main/java/org/fenix/llanfair/gui/Core.java b/src/main/java/org/fenix/llanfair/gui/Core.java index b4df794..23a6793 100644 --- a/src/main/java/org/fenix/llanfair/gui/Core.java +++ b/src/main/java/org/fenix/llanfair/gui/Core.java @@ -198,8 +198,7 @@ class Core extends JPanel implements ActionListener { updateValues(ALL); updateVisibility(ALL); updateColors(ALL); - resize = true; - revalidate(); + forceResize(); } /** @@ -381,49 +380,46 @@ class Core extends JPanel implements ActionListener { } else if (Settings.compareMethod.equals(property)) { updateValues(TIME); updateColors(TIMER); - resize = true; - revalidate(); + forceResize(); } else if (Settings.accuracy.equals(property)) { updateValues(TIME | TIMER); - resize = true; - revalidate(); + forceResize(); } else if (Settings.coreShowBestTime.equals(property) || Settings.coreShowSegmentTime.equals(property) || Settings.coreShowSplitTime.equals(property)) { updateVisibility(TIME); - resize = true; - revalidate(); + forceResize(); } else if (Settings.coreShowSegmentName.equals(property)) { updateVisibility(NAME); - resize = true; - revalidate(); + forceResize(); } else if (Settings.coreIconSize.equals(property)) { - resize = true; - revalidate(); + forceResize(); } else if (Settings.coreTimerFont.equals(property) || Settings.coreSegmentTimerFont.equals(property)) { updateFonts(TIMER); - resize = true; - revalidate(); + forceResize(); } else if (Settings.coreShowSegmentTimer.equals(property)) { updateVisibility(TIMER); - resize = true; - revalidate(); + forceResize(); } else if (Settings.coreShowIcons.equals(property)) { updateVisibility(ICON); - resize = true; - revalidate(); + forceResize(); } else if (Settings.coreFont.equals(property)) { updateFonts(NAME); - resize = true; - revalidate(); + forceResize(); } else if (Settings.coreOtherTimeFont.equals(property)) { updateFonts(TIME); - resize = true; - revalidate(); + forceResize(); + } 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 * updated. @@ -638,6 +634,9 @@ class Core extends JPanel implements ActionListener { } } + private void updateSize() { + } + private boolean isShowingNegativeTime() { if (run != null) { Time time = run.getTime(Segment.LIVE); diff --git a/src/main/java/org/fenix/llanfair/gui/Footer.java b/src/main/java/org/fenix/llanfair/gui/Footer.java index d96b71a..278ca3d 100644 --- a/src/main/java/org/fenix/llanfair/gui/Footer.java +++ b/src/main/java/org/fenix/llanfair/gui/Footer.java @@ -224,6 +224,9 @@ class Footer extends JPanel { } else if (Settings.coreOtherTimeFont.equals(property)) { updateFonts(TIME | DELTA); 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); } } + + private void updateSize() { + } } diff --git a/src/main/java/org/fenix/llanfair/gui/Graph.java b/src/main/java/org/fenix/llanfair/gui/Graph.java index ba50f08..8af9387 100644 --- a/src/main/java/org/fenix/llanfair/gui/Graph.java +++ b/src/main/java/org/fenix/llanfair/gui/Graph.java @@ -172,9 +172,16 @@ class Graph extends JPanel { } } else if (Settings.coreFont.equals(property)) { 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 * updated. @@ -285,6 +292,9 @@ class Graph extends JPanel { } } + private void updateSize() { + } + // ---------------------------------------------------------- INTERNAL TYPE /** diff --git a/src/main/java/org/fenix/llanfair/gui/History.java b/src/main/java/org/fenix/llanfair/gui/History.java index 125f2f9..00ec7a5 100644 --- a/src/main/java/org/fenix/llanfair/gui/History.java +++ b/src/main/java/org/fenix/llanfair/gui/History.java @@ -281,6 +281,9 @@ public class History extends JPanel { updateValues(TIME | LIVE); updateColors(TIME); 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); } + private void updateSize() { + } + // --------------------------------------------------------- INTERNAL TYPES private class SegmentRow extends JPanel { diff --git a/src/main/java/org/fenix/llanfair/gui/RunPane.java b/src/main/java/org/fenix/llanfair/gui/RunPane.java index 50c3c6e..2abb9cc 100644 --- a/src/main/java/org/fenix/llanfair/gui/RunPane.java +++ b/src/main/java/org/fenix/llanfair/gui/RunPane.java @@ -248,6 +248,8 @@ public class RunPane extends JPanel { updateFonts(TITLE); } else if (Settings.coreFont.equals(property)) { updateFonts(ALL & ~TITLE); + } else if (Settings.windowAutoSize.equals(property) || Settings.windowWidth.equals(property)) { + updateSize(); } } @@ -418,6 +420,9 @@ public class RunPane extends JPanel { repaint(); } + private void updateSize() { + } + private String sanitizeTitleString(String title) { return title .replace("<", "<")