Package org.openpnp.model
Class Configuration
- java.lang.Object
-
- org.openpnp.model.AbstractModelObject
-
- org.openpnp.model.Configuration
-
public class Configuration extends AbstractModelObject
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConfiguration.BoardsConfigurationHolderUsed to provide a fixed root for the Boards when serializing.static classConfiguration.MachineConfigurationHolderUsed to provide a fixed root for the Machine when serializing.static classConfiguration.PackagesConfigurationHolderUsed to provide a fixed root for the Packages when serializing.static classConfiguration.PanelsConfigurationHolderUsed to provide a fixed root for the Panels when serializing.static classConfiguration.PartsConfigurationHolderUsed to provide a fixed root for the Parts when serializing.static classConfiguration.ScriptStateConfigurationHolderstatic classConfiguration.TablesLinkedstatic classConfiguration.VisionSettingsConfigurationHolderUsed to provide a fixed root for the VisionSettings when serializing.
-
Field Summary
Fields Modifier and Type Field Description java.util.TreeMap<java.lang.String,java.lang.String>scriptState-
Fields inherited from class org.openpnp.model.AbstractModelObject
propertyChangeSupport
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBoard(java.io.File file)Loads a Board definition into the configuration if it is not already loadedvoidaddBoard(Board board)Adds the specified Board definition to the configurationvoidaddListener(ConfigurationListener listener)voidaddPackage(Package pkg)voidaddPanel(java.io.File file)Loads a Panel definition into the configuration if it is not already loadedvoidaddPanel(Panel panel)Adds the specified Panel definition to the configurationvoidaddPart(Part part)voidaddVisionSettings(AbstractVisionSettings visionSettings)protected java.io.FilecreateBackedUpFile(java.lang.String fileName, java.time.LocalDateTime now)static java.lang.StringcreateId(java.lang.String prefix)java.io.FilecreateResourceFile(java.lang.Class forClass, java.lang.String prefix, java.lang.String suffix)Creates a new file with a unique name within the configuration directory.static org.simpleframework.xml.SerializercreateSerializer()voidfireVisionSettingsChanged()Signal that something about the vision settings has changed.static Configurationget()BoardgetBoard(java.io.File file)Returns the Board definition contained in the specified file.java.util.List<Board>getBoards()com.google.common.eventbus.EventBusgetBus()java.io.FilegetConfigurationDirectory()intgetDistance()ThemeSettingsPanel.FontSizegetFontSize()java.lang.StringgetImgurClientId()java.lang.StringgetLengthDisplayAlignedFormat()java.lang.StringgetLengthDisplayAlignedFormatWithUnits()java.lang.StringgetLengthDisplayFormat()java.lang.StringgetLengthDisplayFormatWithUnits()java.util.LocalegetLocale()MachinegetMachine()PackagegetPackage(java.lang.String id)java.util.List<Package>getPackages()PanelgetPanel(java.io.File file)Returns the Panel definition contained in the specified file.java.util.List<Panel>getPanels()PartgetPart(java.lang.String id)java.util.List<Part>getParts()java.io.FilegetResourceDirectory(java.lang.Class forClass)Gets a File reference for the resources directory belonging to the given class.java.io.FilegetResourceFile(java.lang.Class forClass, java.lang.String name)Gets a File reference for the named file within the configuration directory.ScriptinggetScripting()LengthUnitgetSystemUnits()Configuration.TablesLinkedgetTablesLinked()ThemeInfogetThemeInfo()intgetVerticalScrollUnitIncrement()java.util.List<AbstractVisionSettings>getVisionSettings()AbstractVisionSettingsgetVisionSettings(java.lang.String visionSettingsId)static voidinitialize()Initializes a new temporary Configuration singleton storing configuration in memory only.static voidinitialize(java.io.File configurationDirectory)Initializes a new persistent Configuration singleton storing configuration files in configurationDirectory.java.lang.BooleanisAlternateRows()static booleanisInstanceInitialized()booleanisInUse(PlacementsHolder<?> placementsHolder)Checks to see if the specified PlacementsHolder is used by the current job or any of the currently loaded panelsvoidload()JobloadJob(java.io.File file)Returns the Job contained within the specified filevoidlockListeners()voidremoveBoard(Board board)Removes the specified Board definition from the configuration.voidremoveListener(ConfigurationListener listener)voidremovePackage(Package pkg)voidremovePanel(Panel panel)Removes the specified Panel definition from the configuration.voidremovePart(Part part)voidremoveVisionSettings(AbstractVisionSettings visionSettings)voidresolveBoard(Job job, BoardLocation boardLocation)Attempts to find the Board definition associated with the given BoardLocation, create a copy of it, and then assign the copy to the given BoardLocationvoidresolvePanel(Job job, PanelLocation panelLocation)Attempts to find the Panel definition associated with the given PanelLocation, create a copy of it, and assign the copy to the PanelLocation.voidsave()voidsaveBoard(Board board)Saves the specified Board into its filevoidsaveJob(Job job, java.io.File file)Serializes the specified job and writes it to the specified filevoidsavePanel(Panel panel)Saves the specified Panel into its filevoidsetAlternateRows(java.lang.Boolean alternateRows)voidsetDistance(int distance)voidsetFontSize(ThemeSettingsPanel.FontSize fontSize)voidsetLengthDisplayAlignedFormat(java.lang.String format)voidsetLengthDisplayAlignedFormatWithUnits(java.lang.String format)voidsetLengthDisplayFormat(java.lang.String format)voidsetLengthDisplayFormatWithUnits(java.lang.String format)voidsetLocale(java.util.Locale locale)voidsetMachine(Machine machine)voidsetSystemUnits(LengthUnit lengthUnit)voidsetTablesLinked(Configuration.TablesLinked tablesLinked)voidsetThemeInfo(ThemeInfo theme)voidsetVerticalScrollUnitIncrement(int verticalScrollUnitIncrement)voidunlockListeners()-
Methods inherited from class org.openpnp.model.AbstractModelObject
addPropertyChangeListener, addPropertyChangeListener, dispose, dumpListeners, fireIndexedPropertyChange, firePropertyChange, isListener, isListener, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Method Detail
-
isInstanceInitialized
public static boolean isInstanceInitialized()
-
get
public static Configuration get()
-
initialize
public static void initialize(java.io.File configurationDirectory)
Initializes a new persistent Configuration singleton storing configuration files in configurationDirectory.- Parameters:
configurationDirectory-
-
initialize
public static void initialize()
Initializes a new temporary Configuration singleton storing configuration in memory only.- Parameters:
configurationDirectory-
-
setMachine
public void setMachine(Machine machine)
-
getScripting
public Scripting getScripting()
-
getBus
public com.google.common.eventbus.EventBus getBus()
-
getConfigurationDirectory
public java.io.File getConfigurationDirectory()
-
getSystemUnits
public LengthUnit getSystemUnits()
-
setSystemUnits
public void setSystemUnits(LengthUnit lengthUnit)
-
setDistance
public void setDistance(int distance)
-
getDistance
public int getDistance()
-
getTablesLinked
public Configuration.TablesLinked getTablesLinked()
-
setTablesLinked
public void setTablesLinked(Configuration.TablesLinked tablesLinked)
-
getLocale
public java.util.Locale getLocale()
-
setLocale
public void setLocale(java.util.Locale locale)
-
getThemeInfo
public ThemeInfo getThemeInfo()
-
setThemeInfo
public void setThemeInfo(ThemeInfo theme)
-
getFontSize
public ThemeSettingsPanel.FontSize getFontSize()
-
setFontSize
public void setFontSize(ThemeSettingsPanel.FontSize fontSize)
-
isAlternateRows
public java.lang.Boolean isAlternateRows()
-
setAlternateRows
public void setAlternateRows(java.lang.Boolean alternateRows)
-
getLengthDisplayFormat
public java.lang.String getLengthDisplayFormat()
-
setLengthDisplayFormat
public void setLengthDisplayFormat(java.lang.String format)
-
getLengthDisplayAlignedFormat
public java.lang.String getLengthDisplayAlignedFormat()
-
setLengthDisplayAlignedFormat
public void setLengthDisplayAlignedFormat(java.lang.String format)
-
getLengthDisplayFormatWithUnits
public java.lang.String getLengthDisplayFormatWithUnits()
-
setLengthDisplayFormatWithUnits
public void setLengthDisplayFormatWithUnits(java.lang.String format)
-
getLengthDisplayAlignedFormatWithUnits
public java.lang.String getLengthDisplayAlignedFormatWithUnits()
-
setLengthDisplayAlignedFormatWithUnits
public void setLengthDisplayAlignedFormatWithUnits(java.lang.String format)
-
getVerticalScrollUnitIncrement
public int getVerticalScrollUnitIncrement()
-
setVerticalScrollUnitIncrement
public void setVerticalScrollUnitIncrement(int verticalScrollUnitIncrement)
-
getResourceDirectory
public java.io.File getResourceDirectory(java.lang.Class forClass) throws java.io.IOExceptionGets a File reference for the resources directory belonging to the given class. The directory is guaranteed to exist.- Parameters:
forClass-- Returns:
- Throws:
java.io.IOException
-
getResourceFile
public java.io.File getResourceFile(java.lang.Class forClass, java.lang.String name) throws java.io.IOExceptionGets a File reference for the named file within the configuration directory. forClass is used to uniquely identify the file and keep it separate from other classes' files.- Parameters:
forClass-name-- Returns:
- Throws:
java.io.IOException
-
createResourceFile
public java.io.File createResourceFile(java.lang.Class forClass, java.lang.String prefix, java.lang.String suffix) throws java.io.IOExceptionCreates a new file with a unique name within the configuration directory. forClass is used to uniquely identify the file within the application and a unique name is generated within that namespace. suffix is appended to the unique part of the filename. The result of calling File.getName() on the returned file can be used to load the same file in the future by calling getResourceFile(). This method uses NanosecondTime.get() so the files names will be unique and ordered.- Parameters:
forClass-suffix-- Returns:
- Throws:
java.io.IOException
-
addListener
public void addListener(ConfigurationListener listener)
-
lockListeners
public void lockListeners()
-
unlockListeners
public void unlockListeners()
-
removeListener
public void removeListener(ConfigurationListener listener)
-
load
public void load() throws java.lang.Exception- Throws:
java.lang.Exception
-
save
public void save() throws java.lang.Exception- Throws:
java.lang.Exception
-
createBackedUpFile
protected java.io.File createBackedUpFile(java.lang.String fileName, java.time.LocalDateTime now) throws java.lang.Exception- Throws:
java.lang.Exception
-
getPackage
public Package getPackage(java.lang.String id)
-
getPackages
public java.util.List<Package> getPackages()
-
addPackage
public void addPackage(Package pkg)
-
removePackage
public void removePackage(Package pkg)
-
getPart
public Part getPart(java.lang.String id)
-
getParts
public java.util.List<Part> getParts()
-
addPart
public void addPart(Part part)
-
removePart
public void removePart(Part part)
-
addVisionSettings
public void addVisionSettings(AbstractVisionSettings visionSettings)
-
getVisionSettings
public java.util.List<AbstractVisionSettings> getVisionSettings()
-
getVisionSettings
public AbstractVisionSettings getVisionSettings(java.lang.String visionSettingsId)
-
removeVisionSettings
public void removeVisionSettings(AbstractVisionSettings visionSettings)
-
getBoards
public java.util.List<Board> getBoards()
- Returns:
- an unmodifiable list of Boards loaded in the configuration
-
getPanels
public java.util.List<Panel> getPanels()
- Returns:
- an unmodifiable list of Panels loaded in the configuration
-
fireVisionSettingsChanged
public void fireVisionSettingsChanged()
Signal that something about the vision settings has changed. Inheritance makes it hard to track how changes affect single properties, therefore this is simply fired globally.
-
getMachine
public Machine getMachine()
-
addPanel
public void addPanel(Panel panel)
Adds the specified Panel definition to the configuration- Parameters:
panel- - the Panel definition to be added
-
addPanel
public void addPanel(java.io.File file) throws java.lang.ExceptionLoads a Panel definition into the configuration if it is not already loaded- Parameters:
file- - the file containing the Panel definition- Throws:
java.lang.Exception- if the specified file does not exist or does not contain a valid Panel
-
removePanel
public void removePanel(Panel panel)
Removes the specified Panel definition from the configuration. If the Panel definition has been flagged as being modified, a dialog is presented to confirm if the operator desires to save the Panel definition to the file system before it is removed.- Parameters:
panel- - the Panel definition to remove
-
getPanel
public Panel getPanel(java.io.File file) throws java.lang.Exception
Returns the Panel definition contained in the specified file. If the Panel definition is already loaded in the configuration, it is found and returned. If it is not already loaded into the configuration, the specified file is read and loaded into the configuration. If the specified file does not exist, a new empty Panel definition is created and saved into the specified file and then is loaded into the configuration.- Parameters:
file- - the file containing the Panel definition- Throws:
java.lang.Exception- if the specified file exists but does not contain a valid Panel
-
addBoard
public void addBoard(Board board)
Adds the specified Board definition to the configuration- Parameters:
board- - the Board definition to be added
-
addBoard
public void addBoard(java.io.File file) throws java.lang.ExceptionLoads a Board definition into the configuration if it is not already loaded- Parameters:
file- - the file containing the Board definition- Throws:
java.lang.Exception- if the specified file does not exist or does not contain a valid Board
-
removeBoard
public void removeBoard(Board board)
Removes the specified Board definition from the configuration. If the Board definition has been flagged as being modified, a dialog is presented to confirm if the operator desires to save the Board definition to the file system before it is removed.- Parameters:
board- - the Board to remove
-
getBoard
public Board getBoard(java.io.File file) throws java.lang.Exception
Returns the Board definition contained in the specified file. If the Board definition is already loaded in the configuration, it is found and returned. If it is not already loaded, the specified file is read and loaded into the configuration. If the specified file does not exist, a new empty Board definition is created and saved into the specified file and then is loaded into the configuration.- Parameters:
file- - the file containing the Board definition- Returns:
- the Board definition
- Throws:
java.lang.Exception- if the specified file exists but does not contain a valid Board definition
-
loadJob
public Job loadJob(java.io.File file) throws java.lang.Exception
Returns the Job contained within the specified file- Parameters:
file- - the file containing the Job- Returns:
- the Job
- Throws:
java.lang.Exception- - if the file can't be read successfully
-
resolveBoard
public void resolveBoard(Job job, BoardLocation boardLocation) throws java.lang.Exception
Attempts to find the Board definition associated with the given BoardLocation, create a copy of it, and then assign the copy to the given BoardLocation- Parameters:
job- - the JobboardLocation- - the BoardLocation- Throws:
java.lang.Exception- if the Board definition associated with the BoardLocation can't be loaded successfully
-
resolvePanel
public void resolvePanel(Job job, PanelLocation panelLocation) throws java.lang.Exception
Attempts to find the Panel definition associated with the given PanelLocation, create a copy of it, and assign the copy to the PanelLocation. Recursively resolves the Panel's children.- Parameters:
job- - the JobpanelLocation- - the PanelLocation- Throws:
java.lang.Exception- if the Panel and all of its descendants can't be loaded successfully
-
isInUse
public boolean isInUse(PlacementsHolder<?> placementsHolder)
Checks to see if the specified PlacementsHolder is used by the current job or any of the currently loaded panels- Parameters:
placementsHolder- - the PlacementsHolder to check- Returns:
- true if the PlacementsHolder is in use
-
saveJob
public void saveJob(Job job, java.io.File file) throws java.lang.Exception
Serializes the specified job and writes it to the specified file- Parameters:
job- - the job to savefile- - the file into which the job is to be saved- Throws:
java.lang.Exception- if the file can't be written successfully
-
getImgurClientId
public java.lang.String getImgurClientId()
-
savePanel
public void savePanel(Panel panel) throws java.lang.Exception
Saves the specified Panel into its file- Parameters:
panel- - the Panel to save- Throws:
java.lang.Exception- if the file can't be written successfully
-
saveBoard
public void saveBoard(Board board) throws java.lang.Exception
Saves the specified Board into its file- Parameters:
panel- - the Board to save- Throws:
java.lang.Exception- if the file can't be written successfully
-
createSerializer
public static org.simpleframework.xml.Serializer createSerializer()
-
createId
public static java.lang.String createId(java.lang.String prefix)
-
-