first stab at adding support for a user-specific fixed window width
This commit is contained in:
parent
a30d5ea135
commit
24df5f0f1a
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ public class Settings {
|
|||
public static final Property<Compare> compareMethod = new Property<>( "compareMethod" );
|
||||
public static final Property<Accuracy> accuracy = new Property<>( "accuracy" );
|
||||
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 */
|
||||
|
||||
|
@ -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" ) );
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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("<", "<")
|
||||
|
|
Reference in a new issue