X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2FSetLineWidth.java;h=feb49c24958855a1f40c253703cf9f0827e07de0;hp=5ac64ae3e3a78a2f009f98078249f9d5e2b7880c;hb=a6197ddcaac11c0b943183da7d46169742d024af;hpb=88f2c3647ed9e055090484f01a959d4581f85e7d diff --git a/tim/prune/function/SetLineWidth.java b/tim/prune/function/SetLineWidth.java index 5ac64ae..feb49c2 100644 --- a/tim/prune/function/SetLineWidth.java +++ b/tim/prune/function/SetLineWidth.java @@ -1,15 +1,14 @@ package tim.prune.function; -import javax.swing.JOptionPane; - import tim.prune.App; import tim.prune.DataSubscriber; -import tim.prune.GenericFunction; -import tim.prune.I18nManager; import tim.prune.UpdateMessageBroker; import tim.prune.config.Config; -public class SetLineWidth extends GenericFunction +/** + * Function to set the width with which lines are drawn + */ +public class SetLineWidth extends SingleNumericParameterFunction { /** @@ -17,7 +16,7 @@ public class SetLineWidth extends GenericFunction * @param inApp App object */ public SetLineWidth(App inApp) { - super(inApp); + super(inApp, 1, 4); } /** @return name key */ @@ -25,32 +24,35 @@ public class SetLineWidth extends GenericFunction return "function.setlinewidth"; } + /** @return description key */ + public String getDescriptionKey() { + return "dialog.setlinewidth.text"; + } + + /** @return the current value to display */ + public int getCurrentParamValue() { + return Config.getConfigInt(Config.KEY_LINE_WIDTH); + } /** * Run function */ public void begin() { - int currLineWidth = Config.getConfigInt(Config.KEY_LINE_WIDTH); - if (currLineWidth < 1 || currLineWidth > 4) { - currLineWidth = 2; - } - Object lineWidthStr = JOptionPane.showInputDialog(_app.getFrame(), - I18nManager.getText("dialog.setlinewidth.text"), - I18nManager.getText(getNameKey()), - JOptionPane.QUESTION_MESSAGE, null, null, "" + currLineWidth); - if (lineWidthStr != null) + // Not required, because this function is started from a ChooseSingleParameter function + // and goes directly to the completeFunction method. + } + + /** + * Complete the function using the given line width parameter + */ + public void completeFunction(int inLineWidth) + { + final int currLineWidth = Config.getConfigInt(Config.KEY_LINE_WIDTH); + if (inLineWidth >= 1 && inLineWidth <= 4 && inLineWidth != currLineWidth) { - int lineWidth = 2; - try { - lineWidth = Integer.parseInt(lineWidthStr.toString()); - if (lineWidth >= 1 && lineWidth <= 4 && lineWidth != currLineWidth) - { - Config.setConfigInt(Config.KEY_LINE_WIDTH, lineWidth); - UpdateMessageBroker.informSubscribers(DataSubscriber.SELECTION_CHANGED); - } - } - catch (NumberFormatException nfe) {}; + Config.setConfigInt(Config.KEY_LINE_WIDTH, inLineWidth); + UpdateMessageBroker.informSubscribers(DataSubscriber.SELECTION_CHANGED); } } }