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 class
Configuration.BoardsConfigurationHolder
Used to provide a fixed root for the Boards when serializing.static class
Configuration.MachineConfigurationHolder
Used to provide a fixed root for the Machine when serializing.static class
Configuration.PackagesConfigurationHolder
Used to provide a fixed root for the Packages when serializing.static class
Configuration.PanelsConfigurationHolder
Used to provide a fixed root for the Panels when serializing.static class
Configuration.PartsConfigurationHolder
Used to provide a fixed root for the Parts when serializing.static class
Configuration.TablesLinked
static class
Configuration.VisionSettingsConfigurationHolder
Used to provide a fixed root for the VisionSettings when serializing.
-
Field Summary
-
Fields inherited from class org.openpnp.model.AbstractModelObject
propertyChangeSupport
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBoard(java.io.File file)
Loads a Board definition into the configuration if it is not already loadedvoid
addBoard(Board board)
Adds the specified Board definition to the configurationvoid
addListener(ConfigurationListener listener)
void
addPackage(Package pkg)
void
addPanel(java.io.File file)
Loads a Panel definition into the configuration if it is not already loadedvoid
addPanel(Panel panel)
Adds the specified Panel definition to the configurationvoid
addPart(Part part)
void
addVisionSettings(AbstractVisionSettings visionSettings)
protected java.io.File
createBackedUpFile(java.lang.String fileName, java.time.LocalDateTime now)
static java.lang.String
createId(java.lang.String prefix)
java.io.File
createResourceFile(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.Serializer
createSerializer()
void
fireVisionSettingsChanged()
Signal that something about the vision settings has changed.static Configuration
get()
Board
getBoard(java.io.File file)
Returns the Board definition contained in the specified file.java.util.List<Board>
getBoards()
com.google.common.eventbus.EventBus
getBus()
java.io.File
getConfigurationDirectory()
ThemeSettingsPanel.FontSize
getFontSize()
java.lang.String
getImgurClientId()
java.lang.String
getLengthDisplayAlignedFormat()
java.lang.String
getLengthDisplayAlignedFormatWithUnits()
java.lang.String
getLengthDisplayFormat()
java.lang.String
getLengthDisplayFormatWithUnits()
java.util.Locale
getLocale()
Machine
getMachine()
Package
getPackage(java.lang.String id)
java.util.List<Package>
getPackages()
Panel
getPanel(java.io.File file)
Returns the Panel definition contained in the specified file.java.util.List<Panel>
getPanels()
Part
getPart(java.lang.String id)
java.util.List<Part>
getParts()
java.io.File
getResourceDirectory(java.lang.Class forClass)
Gets a File reference for the resources directory belonging to the given class.java.io.File
getResourceFile(java.lang.Class forClass, java.lang.String name)
Gets a File reference for the named file within the configuration directory.Scripting
getScripting()
LengthUnit
getSystemUnits()
Configuration.TablesLinked
getTablesLinked()
ThemeInfo
getThemeInfo()
int
getVerticalScrollUnitIncrement()
java.util.List<AbstractVisionSettings>
getVisionSettings()
AbstractVisionSettings
getVisionSettings(java.lang.String visionSettingsId)
static void
initialize()
Initializes a new temporary Configuration singleton storing configuration in memory only.static void
initialize(java.io.File configurationDirectory)
Initializes a new persistent Configuration singleton storing configuration files in configurationDirectory.java.lang.Boolean
isAlternateRows()
static boolean
isInstanceInitialized()
boolean
isInUse(PlacementsHolder<?> placementsHolder)
Checks to see if the specified PlacementsHolder is used by the current job or any of the currently loaded panelsvoid
load()
Job
loadJob(java.io.File file)
Returns the Job contained within the specified filevoid
removeBoard(Board board)
Removes the specified Board definition from the configuration.void
removeListener(ConfigurationListener listener)
void
removePackage(Package pkg)
void
removePanel(Panel panel)
Removes the specified Panel definition from the configuration.void
removePart(Part part)
void
removeVisionSettings(AbstractVisionSettings visionSettings)
void
resolveBoard(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 BoardLocationvoid
resolvePanel(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.void
save()
void
saveBoard(Board board)
Saves the specified Board into its filevoid
saveJob(Job job, java.io.File file)
Serializes the specified job and writes it to the specified filevoid
savePanel(Panel panel)
Saves the specified Panel into its filevoid
setAlternateRows(java.lang.Boolean alternateRows)
void
setFontSize(ThemeSettingsPanel.FontSize fontSize)
void
setLengthDisplayAlignedFormat(java.lang.String format)
void
setLengthDisplayAlignedFormatWithUnits(java.lang.String format)
void
setLengthDisplayFormat(java.lang.String format)
void
setLengthDisplayFormatWithUnits(java.lang.String format)
void
setLocale(java.util.Locale locale)
void
setMachine(Machine machine)
void
setSystemUnits(LengthUnit lengthUnit)
void
setTablesLinked(Configuration.TablesLinked tablesLinked)
void
setThemeInfo(ThemeInfo theme)
void
setVerticalScrollUnitIncrement(int verticalScrollUnitIncrement)
-
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)
-
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.IOException
Gets 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.IOException
Gets 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.IOException
Creates 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)
-
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.Exception
Loads 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.Exception
Loads 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)
-
-