1 /* 2 * Copyright (c) 2016 Helmut Neemann 3 * Use of this source code is governed by the GPL v3 license 4 * that can be found in the LICENSE file. 5 */ 6 package de.neemann.digital.gui; 7 8 import de.neemann.digital.core.element.ElementAttributes; 9 import de.neemann.digital.core.element.Key; 10 import de.neemann.digital.core.element.Keys; 11 import de.neemann.digital.draw.graphics.ColorScheme; 12 13 import java.util.ArrayList; 14 import java.util.Collections; 15 import java.util.List; 16 17 /** 18 * The Settings of Digital 19 * <p> 20 * Created by Helmut.Neemann on 11.05.2016. 21 */ 22 public final class Settings extends SettingsBase { 23 24 private static final class SettingsHolder { 25 static final Settings INSTANCE = new Settings(); 26 } 27 28 /** 29 * Returns the settings instance 30 * 31 * @return the Settings 32 */ getInstance()33 public static Settings getInstance() { 34 return SettingsHolder.INSTANCE; 35 } 36 Settings()37 private Settings() { 38 super(createKeyList(), ".digital.cfg"); 39 } 40 createKeyList()41 private static List<Key> createKeyList() { 42 List<Key> intList = new ArrayList<>(); 43 intList.add(Keys.SETTINGS_IEEE_SHAPES); 44 intList.add(Keys.SETTINGS_LANGUAGE); 45 intList.add(Keys.SETTINGS_EXPRESSION_FORMAT); 46 intList.add(ColorScheme.COLOR_SCHEME); 47 intList.add(ColorScheme.CUSTOM_COLOR_SCHEME); 48 intList.add(Keys.SETTINGS_DEFAULT_TREESELECT); 49 intList.add(Keys.SETTINGS_GRID); 50 intList.add(Keys.SETTINGS_SHOW_WIRE_BITS); 51 intList.add(Keys.SETTINGS_NOTOOLTIPS); 52 intList.add(Keys.SETTINGS_WIRETOOLTIP); 53 intList.add(Keys.SETTINGS_LIBRARY_PATH); 54 intList.add(Keys.SETTINGS_JAR_PATH); 55 intList.add(Keys.SETTINGS_ATF1502_FITTER); 56 intList.add(Keys.SETTINGS_ATMISP); 57 intList.add(Keys.SETTINGS_GHDL_PATH); 58 intList.add(Keys.SETTINGS_IVERILOG_PATH); 59 intList.add(Keys.SETTINGS_TOOLCHAIN_CONFIG); 60 intList.add(Keys.SETTINGS_FONT_SCALING); 61 intList.add(Keys.SETTINGS_MAC_MOUSE); 62 intList.add(Keys.SETTINGS_USE_EQUALS_KEY); 63 intList.add(Keys.SETTINGS_SHOW_TUNNEL_RENAME_DIALOG); 64 65 return Collections.unmodifiableList(intList); 66 } 67 68 /** 69 * Returns true if the given modification requires a restart. 70 * 71 * @param modified the modified settings 72 * @return true if the modification requires a restart 73 */ requiresRestart(ElementAttributes modified)74 public boolean requiresRestart(ElementAttributes modified) { 75 for (Key<?> key : getKeys()) 76 if (key.getRequiresRestart() && !getAttributes().equalsKey(key, modified)) 77 return true; 78 79 return false; 80 } 81 82 /** 83 * Returns true if the given modification requires a repaint. 84 * 85 * @param modified the modified settings 86 * @return true if the modification requires a repaint 87 */ requiresRepaint(ElementAttributes modified)88 public boolean requiresRepaint(ElementAttributes modified) { 89 for (Key<?> key : getKeys()) 90 if (key.getRequiresRepaint() && !getAttributes().equalsKey(key, modified)) 91 return true; 92 93 return false; 94 } 95 96 } 97