2016-10-04 06:33:25 +02:00
/ *
* Copyright ( C ) 2015 Laurent CLOUET
* Author Laurent CLOUET < laurent . clouet @nopnop.net >
*
2020-05-28 13:28:42 +02:00
* This program is free software ; you can redistribute it and / or
2016-10-04 06:33:25 +02:00
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; version 2
* of the License .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
* /
2015-01-15 23:20:17 +01:00
package com.sheepit.client.standalone.swing.activity ;
2020-06-06 02:04:29 +10:00
import java.awt.Graphics ;
2015-07-29 16:51:34 -06:00
import java.awt.GridBagConstraints ;
2016-10-12 00:34:51 +02:00
import java.awt.GridBagLayout ;
import java.awt.GridLayout ;
2015-01-15 23:20:17 +01:00
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
2015-04-03 19:39:52 +01:00
import java.awt.event.KeyEvent ;
import java.awt.event.KeyListener ;
2020-06-06 02:04:29 +10:00
import java.awt.image.BufferedImage ;
2015-01-15 23:20:17 +01:00
import java.io.File ;
2015-07-06 18:41:28 +01:00
import java.net.MalformedURLException ;
2017-03-29 22:13:04 +02:00
import java.util.Hashtable ;
2015-01-15 23:20:17 +01:00
import java.util.LinkedList ;
import java.util.List ;
2020-06-06 02:04:29 +10:00
import javax.imageio.ImageIO ;
2015-07-29 16:51:34 -06:00
import javax.swing.BorderFactory ;
2015-07-29 21:59:58 -06:00
import javax.swing.Box ;
import javax.swing.BoxLayout ;
2020-04-14 23:24:28 +10:00
import javax.swing.ButtonGroup ;
2015-01-15 23:20:17 +01:00
import javax.swing.ImageIcon ;
import javax.swing.JButton ;
import javax.swing.JCheckBox ;
import javax.swing.JFileChooser ;
import javax.swing.JLabel ;
2015-02-02 22:43:42 +00:00
import javax.swing.JOptionPane ;
2015-07-29 21:59:58 -06:00
import javax.swing.JPanel ;
2015-01-15 23:20:17 +01:00
import javax.swing.JPasswordField ;
2020-04-14 23:24:28 +10:00
import javax.swing.JRadioButton ;
2015-04-20 21:26:07 +01:00
import javax.swing.JSlider ;
2017-04-25 13:06:23 +02:00
import javax.swing.JSpinner ;
2015-01-15 23:20:17 +01:00
import javax.swing.JTextField ;
2020-04-14 23:24:28 +10:00
import javax.swing.UIManager ;
import javax.swing.UnsupportedLookAndFeelException ;
2017-04-25 13:06:23 +02:00
import javax.swing.SpinnerNumberModel ;
2021-06-02 14:47:28 +00:00
import javax.swing.event.ChangeListener ;
import javax.swing.event.ChangeEvent ;
2017-04-25 13:06:23 +02:00
2020-04-14 23:24:28 +10:00
import com.formdev.flatlaf.FlatLaf ;
import com.formdev.flatlaf.FlatLightLaf ;
import com.formdev.flatlaf.FlatDarkLaf ;
2015-01-15 23:20:17 +01:00
import com.sheepit.client.Configuration ;
import com.sheepit.client.Configuration.ComputeType ;
2015-04-20 21:26:07 +01:00
import com.sheepit.client.hardware.cpu.CPU ;
2015-01-15 23:20:17 +01:00
import com.sheepit.client.hardware.gpu.GPU ;
import com.sheepit.client.hardware.gpu.GPUDevice ;
2020-05-16 18:20:38 +10:00
import com.sheepit.client.hardware.gpu.GPULister ;
import com.sheepit.client.hardware.gpu.nvidia.Nvidia ;
import com.sheepit.client.hardware.gpu.opencl.OpenCL ;
2015-07-06 18:41:28 +01:00
import com.sheepit.client.network.Proxy ;
2017-03-19 18:14:33 +01:00
import com.sheepit.client.os.OS ;
2015-01-15 23:20:17 +01:00
import com.sheepit.client.standalone.GuiSwing ;
2021-05-03 20:36:51 +00:00
import com.sheepit.client.standalone.swing.SwingTooltips ;
2019-05-03 15:49:51 +02:00
import com.sheepit.client.standalone.swing.components.CollapsibleJPanel ;
2021-07-16 23:37:24 +00:00
import org.jetbrains.annotations.NotNull ;
2015-01-15 23:20:17 +01:00
2021-10-02 19:38:04 +00:00
2015-01-15 23:20:17 +01:00
public class Settings implements Activity {
private static final String DUMMY_CACHE_DIR = " Auto detected " ;
private GuiSwing parent ;
private JTextField login ;
private JPasswordField password ;
private JLabel cacheDirText ;
private File cacheDir ;
private JFileChooser cacheDirChooser ;
private JCheckBox useCPU ;
2015-01-24 17:49:27 +00:00
private List < JCheckBoxGPU > useGPUs ;
2020-06-09 14:47:39 +10:00
private JCheckBox useSysTray ;
2021-07-16 23:37:24 +00:00
private JCheckBox headlessCheckbox ;
2020-05-16 18:20:38 +10:00
private JLabel renderbucketSizeLabel ;
private JSlider renderbucketSize ;
2015-04-20 21:26:07 +01:00
private JSlider cpuCores ;
2017-03-29 22:13:04 +02:00
private JSlider ram ;
2017-04-25 13:06:23 +02:00
private JSpinner renderTime ;
2017-03-19 17:38:22 +01:00
private JSlider priority ;
2015-07-06 18:41:28 +01:00
private JTextField proxy ;
2017-05-08 01:35:08 +02:00
private JTextField hostname ;
2015-01-15 23:20:17 +01:00
2020-04-14 23:24:28 +10:00
private ButtonGroup themeOptionsGroup ;
private JRadioButton lightMode ;
private JRadioButton darkMode ;
2020-05-28 13:28:42 +02:00
2015-03-31 21:35:04 +01:00
private JCheckBox saveFile ;
2015-04-03 19:50:58 +01:00
private JCheckBox autoSignIn ;
2015-01-28 01:02:05 +00:00
JButton saveButton ;
2015-04-03 19:50:58 +01:00
private boolean haveAutoStarted ;
2020-06-09 14:47:39 +10:00
private boolean useSysTrayPrevState ;
2021-07-16 23:37:24 +00:00
private boolean isHeadlessPrevState ;
private boolean sessionStarted ; //indicates whether the settings activity gets shown on launch or mid-session.
// it should only be false when the settings activity gets shown right after launch
2015-01-15 23:20:17 +01:00
public Settings ( GuiSwing parent_ ) {
parent = parent_ ;
cacheDir = null ;
2015-01-24 17:49:27 +00:00
useGPUs = new LinkedList < JCheckBoxGPU > ( ) ;
2015-04-03 19:50:58 +01:00
haveAutoStarted = false ;
2021-07-16 23:37:24 +00:00
sessionStarted = false ;
2015-01-15 23:20:17 +01:00
}
2020-05-28 13:28:42 +02:00
@Override public void show ( ) {
2015-01-15 23:20:17 +01:00
Configuration config = parent . getConfiguration ( ) ;
2021-10-02 19:38:04 +00:00
parent . getSettingsLoader ( ) . merge ( config , false ) ;
2020-06-09 14:47:39 +10:00
useSysTrayPrevState = config . isUseSysTray ( ) ;
2021-07-16 23:37:24 +00:00
isHeadlessPrevState = config . isHeadless ( ) ;
2015-01-15 23:20:17 +01:00
2020-05-28 13:28:42 +02:00
applyTheme ( config . getTheme ( ) ) ; // apply the proper theme (light/dark)
2018-08-24 19:46:03 +02:00
List < GPUDevice > gpus = GPU . listDevices ( config ) ;
2020-05-16 18:20:38 +10:00
useGPUs . clear ( ) ; // Empty the auxiliary list (used in the list of checkboxes)
2015-07-29 16:51:34 -06:00
GridBagConstraints constraints = new GridBagConstraints ( ) ;
int currentRow = 0 ;
2020-06-06 02:04:29 +10:00
JLabel labelImage ;
try {
// Include the version of the app as a watermark in the SheepIt logo.
final BufferedImage watermark = ImageIO . read ( getClass ( ) . getResource ( " /sheepit-logo.png " ) ) ;
Graphics gph = watermark . getGraphics ( ) ;
gph . setFont ( gph . getFont ( ) . deriveFont ( 12f ) ) ;
gph . drawString ( " v " + config . getJarVersion ( ) , 335 , 120 ) ;
gph . dispose ( ) ;
labelImage = new JLabel ( new ImageIcon ( watermark ) ) ;
}
catch ( Exception e ) {
// If something fails, we just show the SheepIt logo (without any watermark)
ImageIcon image = new ImageIcon ( getClass ( ) . getResource ( " /sheepit-logo.png " ) ) ;
labelImage = new JLabel ( image ) ;
}
2016-10-12 00:34:51 +02:00
constraints . fill = GridBagConstraints . CENTER ;
constraints . gridwidth = 2 ;
constraints . gridx = 0 ;
2015-07-29 16:51:34 -06:00
constraints . gridy = currentRow ;
2021-06-22 15:41:56 +02:00
parent . getContentPanel ( ) . add ( labelImage , constraints ) ;
2015-01-15 23:20:17 +01:00
2015-07-29 16:51:34 -06:00
+ + currentRow ;
2015-01-15 23:20:17 +01:00
2020-04-14 23:24:28 +10:00
constraints . gridy = currentRow ;
2021-06-22 15:41:56 +02:00
parent . getContentPanel ( ) . add ( new JLabel ( " " ) , constraints ) ; // Add a separator between logo and first panel
2020-05-28 13:28:42 +02:00
2020-04-14 23:24:28 +10:00
currentRow + + ;
2020-05-28 13:28:42 +02:00
2016-10-12 00:34:51 +02:00
// authentication
2020-10-29 22:06:00 +11:00
CollapsibleJPanel authentication_panel = new CollapsibleJPanel ( new GridLayout ( 2 , 2 ) , this ) ;
2017-02-18 14:31:43 +01:00
authentication_panel . setBorder ( BorderFactory . createTitledBorder ( " Authentication " ) ) ;
2015-01-15 23:20:17 +01:00
2017-02-18 14:31:43 +01:00
JLabel loginLabel = new JLabel ( " Username: " ) ;
2015-01-15 23:20:17 +01:00
login = new JTextField ( ) ;
2019-08-07 22:17:59 +02:00
login . setText ( parent . getConfiguration ( ) . getLogin ( ) ) ;
2015-01-15 23:20:17 +01:00
login . setColumns ( 20 ) ;
2015-04-03 19:39:52 +01:00
login . addKeyListener ( new CheckCanStart ( ) ) ;
2017-02-18 14:31:43 +01:00
JLabel passwordLabel = new JLabel ( " Password: " ) ;
2015-01-15 23:20:17 +01:00
password = new JPasswordField ( ) ;
2019-08-07 22:17:59 +02:00
password . setText ( parent . getConfiguration ( ) . getPassword ( ) ) ;
2015-01-15 23:20:17 +01:00
password . setColumns ( 10 ) ;
2015-04-03 19:39:52 +01:00
password . addKeyListener ( new CheckCanStart ( ) ) ;
2015-01-15 23:20:17 +01:00
2017-02-18 14:31:43 +01:00
authentication_panel . add ( loginLabel ) ;
authentication_panel . add ( login ) ;
2015-01-15 23:20:17 +01:00
2017-02-18 14:31:43 +01:00
authentication_panel . add ( passwordLabel ) ;
authentication_panel . add ( password ) ;
2015-07-06 18:41:28 +01:00
2016-10-12 00:34:51 +02:00
constraints . gridx = 0 ;
2015-07-29 16:51:34 -06:00
constraints . gridy = currentRow ;
2016-10-12 00:34:51 +02:00
constraints . fill = GridBagConstraints . HORIZONTAL ;
2021-06-22 15:41:56 +02:00
parent . getContentPanel ( ) . add ( authentication_panel , constraints ) ;
2015-01-15 23:20:17 +01:00
2020-04-14 23:24:28 +10:00
// Theme selection panel
2020-10-29 22:06:00 +11:00
CollapsibleJPanel themePanel = new CollapsibleJPanel ( new GridLayout ( 1 , 3 ) , this ) ;
2020-04-14 23:24:28 +10:00
themePanel . setBorder ( BorderFactory . createTitledBorder ( " Theme " ) ) ;
2020-05-28 13:28:42 +02:00
2020-04-14 23:24:28 +10:00
themeOptionsGroup = new ButtonGroup ( ) ;
2020-05-28 13:28:42 +02:00
2020-04-14 23:24:28 +10:00
lightMode = new JRadioButton ( " Light " ) ;
lightMode . setActionCommand ( " light " ) ;
lightMode . setSelected ( config . getTheme ( ) . equals ( " light " ) ) ;
lightMode . addActionListener ( new ApplyThemeAction ( ) ) ;
2020-05-28 13:28:42 +02:00
2020-04-14 23:24:28 +10:00
darkMode = new JRadioButton ( " Dark " ) ;
darkMode . setActionCommand ( " dark " ) ;
darkMode . setSelected ( config . getTheme ( ) . equals ( " dark " ) ) ;
darkMode . addActionListener ( new ApplyThemeAction ( ) ) ;
2020-05-28 13:28:42 +02:00
2020-04-14 23:24:28 +10:00
themePanel . add ( lightMode ) ;
themePanel . add ( darkMode ) ;
2020-05-28 13:28:42 +02:00
2020-04-14 23:24:28 +10:00
// Group both radio buttons to allow only one selected
themeOptionsGroup . add ( lightMode ) ;
themeOptionsGroup . add ( darkMode ) ;
2020-05-28 13:28:42 +02:00
2020-04-14 23:24:28 +10:00
currentRow + + ;
constraints . gridx = 0 ;
constraints . gridy = currentRow ;
constraints . gridwidth = 2 ;
2020-05-28 13:28:42 +02:00
2021-06-22 15:41:56 +02:00
parent . getContentPanel ( ) . add ( themePanel , constraints ) ;
2020-05-28 13:28:42 +02:00
2016-10-12 00:34:51 +02:00
// directory
2020-10-29 22:06:00 +11:00
CollapsibleJPanel directory_panel = new CollapsibleJPanel ( new GridLayout ( 1 , 3 ) , this ) ;
2016-10-12 00:34:51 +02:00
directory_panel . setBorder ( BorderFactory . createTitledBorder ( " Cache " ) ) ;
2017-02-18 14:31:43 +01:00
JLabel cacheLabel = new JLabel ( " Working directory: " ) ;
2021-04-21 09:05:22 +02:00
cacheLabel . setToolTipText ( SwingTooltips . WORKING_DIRECTORY . getText ( ) ) ;
2016-10-12 00:34:51 +02:00
directory_panel . add ( cacheLabel ) ;
2015-01-15 23:20:17 +01:00
String destination = DUMMY_CACHE_DIR ;
2019-08-07 22:17:59 +02:00
if ( config . isUserHasSpecifiedACacheDir ( ) ) {
2018-08-18 02:03:51 +02:00
destination = config . getCacheDirForSettings ( ) . getName ( ) ;
2015-01-15 23:20:17 +01:00
}
2015-07-29 21:59:58 -06:00
JPanel cacheDirWrapper = new JPanel ( ) ;
cacheDirWrapper . setLayout ( new BoxLayout ( cacheDirWrapper , BoxLayout . LINE_AXIS ) ) ;
2015-01-15 23:20:17 +01:00
cacheDirText = new JLabel ( destination ) ;
2015-07-29 21:59:58 -06:00
cacheDirWrapper . add ( cacheDirText ) ;
cacheDirWrapper . add ( Box . createHorizontalGlue ( ) ) ;
2015-01-15 23:20:17 +01:00
cacheDirChooser = new JFileChooser ( ) ;
cacheDirChooser . setFileSelectionMode ( JFileChooser . DIRECTORIES_ONLY ) ;
JButton openButton = new JButton ( " ... " ) ;
openButton . addActionListener ( new ChooseFileAction ( ) ) ;
2015-07-29 21:59:58 -06:00
cacheDirWrapper . add ( openButton ) ;
2016-10-12 00:34:51 +02:00
directory_panel . add ( cacheDirWrapper ) ;
2015-01-15 23:20:17 +01:00
2016-10-12 00:34:51 +02:00
currentRow + + ;
constraints . gridx = 0 ;
2015-07-29 16:51:34 -06:00
constraints . gridy = currentRow ;
2016-10-12 00:34:51 +02:00
constraints . gridwidth = 2 ;
2021-06-22 15:41:56 +02:00
parent . getContentPanel ( ) . add ( directory_panel , constraints ) ;
2016-10-12 00:34:51 +02:00
// compute devices
GridBagLayout gridbag = new GridBagLayout ( ) ;
GridBagConstraints compute_devices_constraints = new GridBagConstraints ( ) ;
2020-10-29 22:06:00 +11:00
CollapsibleJPanel compute_devices_panel = new CollapsibleJPanel ( gridbag , this ) ;
2016-10-12 00:34:51 +02:00
compute_devices_panel . setBorder ( BorderFactory . createTitledBorder ( " Compute devices " ) ) ;
2021-04-21 09:05:22 +02:00
compute_devices_panel . setToolTipText ( SwingTooltips . COMPUTE_DEVICES . getText ( ) ) ;
2015-01-15 23:20:17 +01:00
ComputeType method = config . getComputeMethod ( ) ;
useCPU = new JCheckBox ( " CPU " ) ;
boolean gpuChecked = false ;
if ( method = = ComputeType . CPU_GPU ) {
useCPU . setSelected ( true ) ;
gpuChecked = true ;
}
2015-04-07 20:05:48 +01:00
else if ( method = = ComputeType . CPU ) {
2015-01-15 23:20:17 +01:00
useCPU . setSelected ( true ) ;
gpuChecked = false ;
}
2015-04-07 20:05:48 +01:00
else if ( method = = ComputeType . GPU ) {
2015-01-15 23:20:17 +01:00
useCPU . setSelected ( false ) ;
gpuChecked = true ;
}
2015-01-28 01:02:05 +00:00
useCPU . addActionListener ( new CpuChangeAction ( ) ) ;
2016-10-12 00:34:51 +02:00
compute_devices_constraints . gridx = 1 ;
compute_devices_constraints . gridy = 0 ;
compute_devices_constraints . fill = GridBagConstraints . BOTH ;
compute_devices_constraints . weightx = 1 . 0 ;
compute_devices_constraints . weighty = 1 . 0 ;
gridbag . setConstraints ( useCPU , compute_devices_constraints ) ;
compute_devices_panel . add ( useCPU ) ;
2020-05-16 18:20:38 +10:00
if ( gpus . size ( ) > 0 ) {
renderbucketSizeLabel = new JLabel ( " Renderbucket size: " ) ;
2020-05-28 13:28:42 +02:00
renderbucketSize = new JSlider ( ) ;
2020-05-16 18:20:38 +10:00
renderbucketSize . setMajorTickSpacing ( 1 ) ;
renderbucketSize . setMinorTickSpacing ( 1 ) ;
renderbucketSize . setPaintTicks ( true ) ;
2021-06-02 14:47:28 +00:00
renderbucketSize . setSnapToTicks ( true ) ;
2020-05-16 18:20:38 +10:00
renderbucketSize . setPaintLabels ( true ) ;
2021-04-21 09:05:22 +02:00
renderbucketSizeLabel . setToolTipText ( SwingTooltips . RENDERBUCKET_SIZE . getText ( ) ) ;
2020-05-16 18:20:38 +10:00
renderbucketSizeLabel . setVisible ( false ) ;
renderbucketSize . setVisible ( false ) ;
for ( GPUDevice gpu : gpus ) {
JCheckBoxGPU gpuCheckBox = new JCheckBoxGPU ( gpu ) ;
gpuCheckBox . setToolTipText ( gpu . getId ( ) ) ;
if ( gpuChecked ) {
GPUDevice config_gpu = config . getGPUDevice ( ) ;
if ( config_gpu ! = null & & config_gpu . getId ( ) . equals ( gpu . getId ( ) ) ) {
gpuCheckBox . setSelected ( gpuChecked ) ;
renderbucketSizeLabel . setVisible ( true ) ;
renderbucketSize . setVisible ( true ) ;
}
2015-01-29 14:30:53 +00:00
}
2020-05-16 18:20:38 +10:00
gpuCheckBox . addActionListener ( new GpuChangeAction ( ) ) ;
compute_devices_constraints . gridy + + ;
gridbag . setConstraints ( gpuCheckBox , compute_devices_constraints ) ;
compute_devices_panel . add ( gpuCheckBox ) ;
useGPUs . add ( gpuCheckBox ) ;
2015-01-15 23:20:17 +01:00
}
2016-10-12 00:34:51 +02:00
2020-05-16 18:20:38 +10:00
// Initialisation values will apply if we are not able to detect the proper GPU technology or
// because is a new one (different from CUDA and OPENCL). In that case, move into a safe position
// of 32x32 pixel render bucket and a maximum of 128x128 pixel for the "unknown GPU"
2020-05-28 13:28:42 +02:00
int maxRenderbucketSize = 128 ;
2020-06-21 19:21:23 +10:00
int recommendedBucketSize = GPU . MIN_RENDERBUCKET_SIZE ;
2020-05-16 18:20:38 +10:00
2021-02-23 20:25:56 +00:00
//When replacing gpus it can happen that the client can't find the one specified in the config anymore in which case config.getGPUDevice()
//returns null
if ( ( config . getComputeMethod ( ) = = ComputeType . GPU | | config . getComputeMethod ( ) = = ComputeType . CPU_GPU ) & & config . getGPUDevice ( ) ! = null ) {
2020-05-16 18:20:38 +10:00
GPULister gpu ;
if ( config . getGPUDevice ( ) . getType ( ) . equals ( " CUDA " ) ) {
gpu = new Nvidia ( ) ;
maxRenderbucketSize = gpu . getMaximumRenderBucketSize ( config . getGPUDevice ( ) . getMemory ( ) ) ;
recommendedBucketSize = gpu . getRecommendedRenderBucketSize ( config . getGPUDevice ( ) . getMemory ( ) ) ;
}
else if ( config . getGPUDevice ( ) . getType ( ) . equals ( " OPENCL " ) ) {
gpu = new OpenCL ( ) ;
maxRenderbucketSize = gpu . getMaximumRenderBucketSize ( config . getGPUDevice ( ) . getMemory ( ) ) ;
recommendedBucketSize = gpu . getRecommendedRenderBucketSize ( config . getGPUDevice ( ) . getMemory ( ) ) ;
}
}
2020-05-28 13:28:42 +02:00
2020-05-16 18:20:38 +10:00
buildRenderBucketSizeSlider ( maxRenderbucketSize , config . getRenderbucketSize ( ) ! = - 1 ?
( ( int ) ( Math . log ( config . getRenderbucketSize ( ) ) / Math . log ( 2 ) ) ) - 5 :
( ( int ) ( Math . log ( recommendedBucketSize ) / Math . log ( 2 ) ) ) - 5 ) ;
compute_devices_constraints . weightx = 1 . 0 / gpus . size ( ) ;
compute_devices_constraints . gridx = 0 ;
2016-10-12 00:34:51 +02:00
compute_devices_constraints . gridy + + ;
2020-05-16 18:20:38 +10:00
gridbag . setConstraints ( renderbucketSizeLabel , compute_devices_constraints ) ;
compute_devices_panel . add ( renderbucketSizeLabel ) ;
compute_devices_constraints . gridx = 1 ;
compute_devices_constraints . weightx = 1 . 0 ;
gridbag . setConstraints ( renderbucketSize , compute_devices_constraints ) ;
compute_devices_panel . add ( new JLabel ( " " ) , compute_devices_constraints ) ; // Add a space between lines
compute_devices_panel . add ( renderbucketSize ) ;
2015-01-15 23:20:17 +01:00
}
2015-04-20 21:26:07 +01:00
CPU cpu = new CPU ( ) ;
if ( cpu . cores ( ) > 1 ) { // if only one core is available, no need to show the choice
2017-07-02 17:43:17 +02:00
double step = 1 ;
2020-05-28 13:28:42 +02:00
double display = ( double ) cpu . cores ( ) / step ;
2017-07-02 17:43:17 +02:00
while ( display > 10 ) {
step + = 1 . 0 ;
2020-05-28 13:28:42 +02:00
display = ( double ) cpu . cores ( ) / step ;
2017-07-02 17:43:17 +02:00
}
2021-07-07 16:18:45 +00:00
cpuCores = new JSlider ( CPU . MIN_CORES , cpu . cores ( ) ) ;
2020-05-28 13:28:42 +02:00
cpuCores . setMajorTickSpacing ( ( int ) ( step ) ) ;
2015-04-20 21:26:07 +01:00
cpuCores . setMinorTickSpacing ( 1 ) ;
cpuCores . setPaintTicks ( true ) ;
2021-06-02 14:47:28 +00:00
cpuCores . setSnapToTicks ( true ) ;
cpuCores . addChangeListener ( new ChangeListener ( ) {
@Override public void stateChanged ( ChangeEvent e ) {
cpuCores . setToolTipText ( String . valueOf ( cpuCores . getValue ( ) ) ) ;
}
} ) ;
2015-04-20 21:26:07 +01:00
cpuCores . setPaintLabels ( true ) ;
2021-07-07 16:18:45 +00:00
cpuCores . setValue ( config . getNbCores ( ) ! = - 1 ? ( Math . max ( config . getNbCores ( ) , CPU . MIN_CORES ) ) : cpuCores . getMaximum ( ) ) ;
2015-04-20 21:26:07 +01:00
JLabel coreLabel = new JLabel ( " CPU cores: " ) ;
2021-04-21 09:05:22 +02:00
coreLabel . setToolTipText ( SwingTooltips . CPU_CORES . getText ( ) ) ;
2015-07-29 16:51:34 -06:00
2016-10-12 00:34:51 +02:00
compute_devices_constraints . weightx = 1 . 0 / gpus . size ( ) ;
compute_devices_constraints . gridx = 0 ;
compute_devices_constraints . gridy + + ;
gridbag . setConstraints ( coreLabel , compute_devices_constraints ) ;
compute_devices_panel . add ( coreLabel ) ;
compute_devices_constraints . gridx = 1 ;
compute_devices_constraints . weightx = 1 . 0 ;
gridbag . setConstraints ( cpuCores , compute_devices_constraints ) ;
2020-05-16 18:20:38 +10:00
compute_devices_panel . add ( new JLabel ( " " ) , compute_devices_constraints ) ; // Add a space between lines
2016-10-12 00:34:51 +02:00
compute_devices_panel . add ( cpuCores ) ;
2015-04-20 21:26:07 +01:00
}
2017-03-29 22:13:04 +02:00
// max ram allowed to render
2017-03-19 18:14:33 +01:00
OS os = OS . getOS ( ) ;
2019-02-20 13:46:53 +01:00
int all_ram = ( int ) os . getMemory ( ) ;
2017-03-29 22:13:04 +02:00
ram = new JSlider ( 0 , all_ram ) ;
int step = 1000000 ;
2020-05-28 13:28:42 +02:00
double display = ( double ) all_ram / ( double ) step ;
2017-07-02 17:43:17 +02:00
while ( display > 10 ) {
step + = 1000000 ;
2020-05-28 13:28:42 +02:00
display = ( double ) all_ram / ( double ) step ;
2017-07-02 17:43:17 +02:00
}
2017-03-29 22:13:04 +02:00
Hashtable < Integer , JLabel > labelTable = new Hashtable < Integer , JLabel > ( ) ;
for ( int g = 0 ; g < all_ram ; g + = step ) {
2017-07-02 17:43:17 +02:00
labelTable . put ( new Integer ( g ) , new JLabel ( " " + ( g / 1000000 ) ) ) ;
2017-03-29 22:13:04 +02:00
}
ram . setMajorTickSpacing ( step ) ;
ram . setLabelTable ( labelTable ) ;
ram . setPaintTicks ( true ) ;
2021-06-02 14:47:28 +00:00
ram . addChangeListener ( new ChangeListener ( ) {
@Override public void stateChanged ( ChangeEvent e ) {
ram . setToolTipText ( String . format ( " %,d MiB " , ( ram . getValue ( ) / 1024 ) ) ) ;
}
} ) ;
2017-03-29 22:13:04 +02:00
ram . setPaintLabels ( true ) ;
2020-05-28 13:28:42 +02:00
ram . setValue ( ( int ) ( config . getMaxMemory ( ) ! = - 1 ? config . getMaxMemory ( ) : os . getMemory ( ) ) ) ;
2017-03-29 22:13:04 +02:00
JLabel ramLabel = new JLabel ( " Memory: " ) ;
2021-04-21 09:05:22 +02:00
ramLabel . setToolTipText ( SwingTooltips . MEMORY . getText ( ) ) ;
2017-03-29 22:13:04 +02:00
compute_devices_constraints . weightx = 1 . 0 / gpus . size ( ) ;
compute_devices_constraints . gridx = 0 ;
compute_devices_constraints . gridy + + ;
gridbag . setConstraints ( ramLabel , compute_devices_constraints ) ;
compute_devices_panel . add ( ramLabel ) ;
compute_devices_constraints . gridx = 1 ;
compute_devices_constraints . weightx = 1 . 0 ;
gridbag . setConstraints ( ram , compute_devices_constraints ) ;
2020-05-16 18:20:38 +10:00
compute_devices_panel . add ( new JLabel ( " " ) , compute_devices_constraints ) ; // Add a space between lines
2017-03-29 22:13:04 +02:00
compute_devices_panel . add ( ram ) ;
2021-06-22 15:41:56 +02:00
parent . getContentPanel ( ) . add ( compute_devices_panel , constraints ) ;
2017-03-29 22:13:04 +02:00
// priority
2021-05-29 15:14:00 +00:00
// ui display low -> high but the actual values are reversed
// -19 is highest priority
2017-03-19 18:14:33 +01:00
boolean high_priority_support = os . getSupportHighPriority ( ) ;
priority = new JSlider ( high_priority_support ? - 19 : 0 , 19 ) ;
2021-05-29 15:14:00 +00:00
Hashtable < Integer , JLabel > labelTablePriority = new Hashtable < > ( ) ;
labelTablePriority . put ( high_priority_support ? - 19 : 0 , new JLabel ( " Low " ) ) ;
labelTablePriority . put ( 19 , new JLabel ( " High " ) ) ;
priority . setLabelTable ( labelTablePriority ) ;
2017-03-19 17:38:22 +01:00
priority . setMinorTickSpacing ( 1 ) ;
priority . setPaintTicks ( true ) ;
2021-06-02 14:47:28 +00:00
priority . setSnapToTicks ( true ) ;
priority . addChangeListener ( new ChangeListener ( ) {
@Override public void stateChanged ( ChangeEvent e ) {
priority . setToolTipText ( String . valueOf ( priority . getValue ( ) ) ) ;
}
} ) ;
2017-03-19 17:38:22 +01:00
priority . setPaintLabels ( true ) ;
2021-05-29 15:14:00 +00:00
if ( high_priority_support ) {
// inverse
priority . setValue ( - 1 * config . getPriority ( ) ) ;
}
else {
priority . setValue ( 19 - config . getPriority ( ) ) ;
}
JLabel priorityLabel = new JLabel ( " Priority " ) ;
2021-04-21 09:05:22 +02:00
priorityLabel . setToolTipText ( SwingTooltips . PRIORITY . getText ( ) ) ;
2017-03-19 17:38:22 +01:00
2020-05-28 23:05:52 +10:00
boolean showPrioritySlider = os . checkNiceAvailability ( ) ;
priority . setVisible ( showPrioritySlider ) ;
priorityLabel . setVisible ( showPrioritySlider ) ;
2017-03-19 17:38:22 +01:00
compute_devices_constraints . weightx = 1 . 0 / gpus . size ( ) ;
compute_devices_constraints . gridx = 0 ;
compute_devices_constraints . gridy + + ;
gridbag . setConstraints ( priorityLabel , compute_devices_constraints ) ;
compute_devices_panel . add ( priorityLabel ) ;
compute_devices_constraints . gridx = 1 ;
compute_devices_constraints . weightx = 1 . 0 ;
gridbag . setConstraints ( priority , compute_devices_constraints ) ;
compute_devices_panel . add ( priority ) ;
2016-10-12 00:34:51 +02:00
currentRow + + ;
constraints . gridx = 0 ;
2016-09-21 23:26:44 +02:00
constraints . gridy = currentRow ;
2016-10-12 00:34:51 +02:00
constraints . gridwidth = 2 ;
2021-06-22 15:41:56 +02:00
parent . getContentPanel ( ) . add ( compute_devices_panel , constraints ) ;
2016-09-21 23:26:44 +02:00
2016-10-12 00:34:51 +02:00
// other
2021-07-16 23:37:24 +00:00
CollapsibleJPanel advanced_panel = new CollapsibleJPanel ( new GridLayout ( 5 , 2 ) , this ) ;
2016-10-12 00:34:51 +02:00
advanced_panel . setBorder ( BorderFactory . createTitledBorder ( " Advanced options " ) ) ;
2016-09-21 23:26:44 +02:00
2020-06-09 14:47:39 +10:00
JLabel useSysTrayLabel = new JLabel ( " Minimize to SysTray " ) ;
2021-04-21 09:05:22 +02:00
useSysTrayLabel . setToolTipText ( SwingTooltips . MINIMIZE_TO_SYSTRAY . getText ( ) ) ;
2020-06-09 14:47:39 +10:00
useSysTray = new JCheckBox ( ) ;
useSysTray . setSelected ( config . isUseSysTray ( ) ) ;
advanced_panel . add ( useSysTrayLabel ) ;
advanced_panel . add ( useSysTray ) ;
2021-07-16 23:37:24 +00:00
JLabel headlessLabel = new JLabel ( " Block Eevee projects " ) ;
headlessCheckbox = new JCheckBox ( ) ;
headlessCheckbox . setSelected ( config . isHeadless ( ) ) ;
advanced_panel . add ( headlessLabel ) ;
advanced_panel . add ( headlessCheckbox ) ;
2017-02-18 14:31:43 +01:00
JLabel proxyLabel = new JLabel ( " Proxy: " ) ;
2021-04-21 09:05:22 +02:00
proxyLabel . setToolTipText ( " http://login:password@host:port \ n " + SwingTooltips . PROXY . getText ( ) ) ;
2016-10-12 00:34:51 +02:00
proxy = new JTextField ( ) ;
proxy . setToolTipText ( " http://login:password@host:port " ) ;
proxy . setText ( parent . getConfiguration ( ) . getProxy ( ) ) ;
proxy . addKeyListener ( new CheckCanStart ( ) ) ;
advanced_panel . add ( proxyLabel ) ;
advanced_panel . add ( proxy ) ;
2017-05-08 01:35:08 +02:00
JLabel hostnameLabel = new JLabel ( " Computer name: " ) ;
2021-04-21 09:05:22 +02:00
hostnameLabel . setToolTipText ( SwingTooltips . COMPUTER_NAME . getText ( ) ) ;
2017-05-08 01:35:08 +02:00
hostname = new JTextField ( ) ;
hostname . setText ( parent . getConfiguration ( ) . getHostname ( ) ) ;
advanced_panel . add ( hostnameLabel ) ;
advanced_panel . add ( hostname ) ;
2017-04-25 13:06:23 +02:00
JLabel renderTimeLabel = new JLabel ( " Max time per frame (in minute): " ) ;
2021-04-21 09:05:22 +02:00
renderTimeLabel . setToolTipText ( SwingTooltips . MAX_TIME_PER_FRAME . getText ( ) ) ;
2017-04-25 13:06:23 +02:00
int val = 0 ;
if ( parent . getConfiguration ( ) . getMaxRenderTime ( ) > 0 ) {
val = parent . getConfiguration ( ) . getMaxRenderTime ( ) / 60 ;
}
2020-05-28 13:28:42 +02:00
renderTime = new JSpinner ( new SpinnerNumberModel ( val , 0 , 1000 , 1 ) ) ;
2017-04-25 13:06:23 +02:00
advanced_panel . add ( renderTimeLabel ) ;
advanced_panel . add ( renderTime ) ;
2016-10-12 00:34:51 +02:00
currentRow + + ;
constraints . gridx = 0 ;
2015-07-29 16:51:34 -06:00
constraints . gridy = currentRow ;
2016-10-12 00:34:51 +02:00
constraints . gridwidth = 2 ;
2021-06-22 15:41:56 +02:00
parent . getContentPanel ( ) . add ( advanced_panel , constraints ) ;
2015-03-31 21:35:04 +01:00
2016-10-12 00:34:51 +02:00
// general settings
JPanel general_panel = new JPanel ( new GridLayout ( 1 , 2 ) ) ;
saveFile = new JCheckBox ( " Save settings " , true ) ;
general_panel . add ( saveFile ) ;
2015-04-03 19:50:58 +01:00
2019-08-07 22:17:59 +02:00
autoSignIn = new JCheckBox ( " Auto sign in " , config . isAutoSignIn ( ) ) ;
2015-04-03 19:50:58 +01:00
autoSignIn . addActionListener ( new AutoSignInChangeAction ( ) ) ;
2016-10-12 00:34:51 +02:00
general_panel . add ( autoSignIn ) ;
2015-04-03 19:50:58 +01:00
2016-10-12 00:34:51 +02:00
currentRow + + ;
constraints . gridx = 0 ;
constraints . gridy = currentRow ;
constraints . gridwidth = 2 ;
2021-06-22 15:41:56 +02:00
parent . getContentPanel ( ) . add ( general_panel , constraints ) ;
2015-03-31 21:35:04 +01:00
2020-04-14 23:24:28 +10:00
currentRow + + ;
constraints . gridy = currentRow ;
2021-06-22 15:41:56 +02:00
parent . getContentPanel ( ) . add ( new JLabel ( " " ) , constraints ) ; // Add a separator between last checkboxes and button
2020-05-28 13:28:42 +02:00
2020-04-14 23:24:28 +10:00
currentRow + + ;
2016-02-08 13:06:33 +01:00
String buttonText = " Start " ;
if ( parent . getClient ( ) ! = null ) {
if ( parent . getClient ( ) . isRunning ( ) ) {
buttonText = " Save " ;
}
}
saveButton = new JButton ( buttonText ) ;
2015-07-10 20:54:08 -06:00
checkDisplaySaveButton ( ) ;
2015-01-15 23:20:17 +01:00
saveButton . addActionListener ( new SaveAction ( ) ) ;
2016-10-12 00:34:51 +02:00
currentRow + + ;
constraints . gridwidth = 2 ;
constraints . gridx = 0 ;
2015-07-29 16:51:34 -06:00
constraints . gridy = currentRow ;
2021-06-22 15:41:56 +02:00
parent . getContentPanel ( ) . add ( saveButton , constraints ) ;
2020-06-09 14:47:39 +10:00
// Increase the size of the app Window to ensure it shows all the information with the Advanced Options panel opened.
parent . setSize ( 520 , 850 ) ;
2015-07-29 16:51:34 -06:00
2019-08-07 22:17:59 +02:00
if ( haveAutoStarted = = false & & config . isAutoSignIn ( ) & & checkDisplaySaveButton ( ) ) {
2015-04-03 19:50:58 +01:00
// auto start
haveAutoStarted = true ;
new SaveAction ( ) . actionPerformed ( null ) ;
}
2015-01-15 23:20:17 +01:00
}
2020-10-29 22:06:00 +11:00
public void resizeWindow ( ) { }
2020-05-16 18:20:38 +10:00
private void buildRenderBucketSizeSlider ( int maxRenderbucketSize , int selectedBucketSize ) {
Hashtable < Integer , JLabel > renderbucketSizeTable = new Hashtable < Integer , JLabel > ( ) ;
// We "take logs" to calculate the exponent to fill the slider. The logarithm, or log, of a number reflects
// what power you need to raise a certain base to in order to get that number. In this case, as we are
// offering increments of 2^n, the formula will be:
//
// log(tile size in px)
// exponent = --------------------
// log(2)
//
int steps = ( int ) ( Math . log ( maxRenderbucketSize ) / Math . log ( 2 ) ) ;
for ( int i = 5 ; i < = steps ; i + + ) {
renderbucketSizeTable . put ( ( i - 5 ) , new JLabel ( String . format ( " %.0f " , Math . pow ( 2 , i ) ) ) ) ;
}
renderbucketSize . setMinimum ( 0 ) ;
renderbucketSize . setMaximum ( renderbucketSizeTable . size ( ) - 1 ) ;
renderbucketSize . setLabelTable ( renderbucketSizeTable ) ;
renderbucketSize . setValue ( selectedBucketSize ) ;
}
2015-04-03 19:50:58 +01:00
public boolean checkDisplaySaveButton ( ) {
2015-01-28 01:02:05 +00:00
boolean selected = useCPU . isSelected ( ) ;
for ( JCheckBoxGPU box : useGPUs ) {
if ( box . isSelected ( ) ) {
selected = true ;
}
}
2015-07-06 18:41:28 +01:00
if ( login . getText ( ) . isEmpty ( ) | | password . getPassword ( ) . length = = 0 | | Proxy . isValidURL ( proxy . getText ( ) ) = = false ) {
2015-04-03 19:39:52 +01:00
selected = false ;
}
2020-05-28 13:28:42 +02:00
2015-01-28 01:02:05 +00:00
saveButton . setEnabled ( selected ) ;
2015-04-03 19:50:58 +01:00
return selected ;
2015-01-28 01:02:05 +00:00
}
2020-05-28 13:28:42 +02:00
2020-04-14 23:24:28 +10:00
private void applyTheme ( String theme_ ) {
try {
if ( theme_ . equals ( " light " ) ) {
UIManager . setLookAndFeel ( new FlatLightLaf ( ) ) ;
2020-05-28 13:28:42 +02:00
}
else if ( theme_ . equals ( " dark " ) ) {
2020-04-14 23:24:28 +10:00
UIManager . setLookAndFeel ( new FlatDarkLaf ( ) ) ;
}
2020-05-28 13:28:42 +02:00
2020-04-14 23:24:28 +10:00
// Apply the new theme
FlatLaf . updateUI ( ) ;
}
catch ( UnsupportedLookAndFeelException e1 ) {
e1 . printStackTrace ( ) ;
}
}
2015-01-28 01:02:05 +00:00
2015-01-15 23:20:17 +01:00
class ChooseFileAction implements ActionListener {
2020-05-28 13:28:42 +02:00
@Override public void actionPerformed ( ActionEvent arg0 ) {
JOptionPane . showMessageDialog ( parent . getContentPane ( ) ,
" <html>The working directory has to be dedicated directory. <br />Caution, everything not related to SheepIt-Renderfarm will be removed.<br />You should create a directory specifically for it.</html> " ,
" Warning: files will be removed! " , JOptionPane . WARNING_MESSAGE ) ;
2015-01-15 23:20:17 +01:00
int returnVal = cacheDirChooser . showOpenDialog ( parent . getContentPane ( ) ) ;
if ( returnVal = = JFileChooser . APPROVE_OPTION ) {
File file = cacheDirChooser . getSelectedFile ( ) ;
cacheDir = file ;
cacheDirText . setText ( cacheDir . getName ( ) ) ;
}
}
}
2015-01-28 01:02:05 +00:00
class CpuChangeAction implements ActionListener {
2020-05-28 13:28:42 +02:00
@Override public void actionPerformed ( ActionEvent e ) {
2015-01-28 01:02:05 +00:00
checkDisplaySaveButton ( ) ;
}
}
2015-01-15 23:20:17 +01:00
class GpuChangeAction implements ActionListener {
2020-05-28 13:28:42 +02:00
@Override public void actionPerformed ( ActionEvent e ) {
2020-05-16 18:20:38 +10:00
renderbucketSizeLabel . setVisible ( false ) ;
renderbucketSize . setVisible ( false ) ;
int counter = 0 ;
2015-01-15 23:20:17 +01:00
for ( JCheckBox box : useGPUs ) {
2020-05-16 18:20:38 +10:00
if ( ! box . isSelected ( ) ) {
box . setSelected ( false ) ;
}
else {
GPULister gpu ;
2020-05-28 13:28:42 +02:00
int maxRenderbucketSize = 128 ; // Max default render bucket size
2020-06-21 19:21:23 +10:00
int recommendedBucketSize = GPU . MIN_RENDERBUCKET_SIZE ; // Default recommended render bucket size
2020-05-16 18:20:38 +10:00
if ( useGPUs . get ( counter ) . getGPUDevice ( ) . getType ( ) . equals ( " CUDA " ) ) {
gpu = new Nvidia ( ) ;
maxRenderbucketSize = gpu . getMaximumRenderBucketSize ( useGPUs . get ( counter ) . getGPUDevice ( ) . getMemory ( ) ) ;
recommendedBucketSize = gpu . getRecommendedRenderBucketSize ( useGPUs . get ( counter ) . getGPUDevice ( ) . getMemory ( ) ) ;
}
else if ( useGPUs . get ( counter ) . getGPUDevice ( ) . getType ( ) . equals ( " OPENCL " ) ) {
gpu = new OpenCL ( ) ;
maxRenderbucketSize = gpu . getMaximumRenderBucketSize ( useGPUs . get ( counter ) . getGPUDevice ( ) . getMemory ( ) ) ;
recommendedBucketSize = gpu . getRecommendedRenderBucketSize ( useGPUs . get ( counter ) . getGPUDevice ( ) . getMemory ( ) ) ;
}
buildRenderBucketSizeSlider ( maxRenderbucketSize , ( ( int ) ( Math . log ( recommendedBucketSize ) / Math . log ( 2 ) ) ) - 5 ) ;
renderbucketSizeLabel . setVisible ( true ) ;
renderbucketSize . setVisible ( true ) ;
}
// Simulate a radio button behavior with check buttons while only 1 GPU
// can be selected at a time
2015-01-15 23:20:17 +01:00
if ( box . equals ( e . getSource ( ) ) = = false ) {
box . setSelected ( false ) ;
}
2020-05-16 18:20:38 +10:00
counter + + ;
2015-01-15 23:20:17 +01:00
}
2015-01-28 01:02:05 +00:00
checkDisplaySaveButton ( ) ;
2015-01-15 23:20:17 +01:00
}
}
2015-04-03 19:39:52 +01:00
class AutoSignInChangeAction implements ActionListener {
2020-05-28 13:28:42 +02:00
@Override public void actionPerformed ( ActionEvent e ) {
2015-04-03 19:39:52 +01:00
if ( autoSignIn . isSelected ( ) ) {
saveFile . setSelected ( true ) ;
}
}
}
2020-04-14 23:24:28 +10:00
class ApplyThemeAction implements ActionListener {
2020-05-28 13:28:42 +02:00
@Override public void actionPerformed ( ActionEvent e ) {
2020-04-14 23:24:28 +10:00
applyTheme ( themeOptionsGroup . getSelection ( ) . getActionCommand ( ) ) ;
}
}
2020-05-28 13:28:42 +02:00
2015-01-15 23:20:17 +01:00
class SaveAction implements ActionListener {
2020-05-28 13:28:42 +02:00
@Override public void actionPerformed ( ActionEvent e ) {
2015-01-15 23:20:17 +01:00
if ( parent = = null ) {
return ;
}
Configuration config = parent . getConfiguration ( ) ;
if ( config = = null ) {
return ;
}
2020-05-28 13:28:42 +02:00
2020-04-14 23:24:28 +10:00
if ( themeOptionsGroup . getSelection ( ) . getActionCommand ( ) ! = null )
config . setTheme ( themeOptionsGroup . getSelection ( ) . getActionCommand ( ) ) ;
2015-01-15 23:20:17 +01:00
if ( cacheDir ! = null ) {
File fromConfig = config . getStorageDir ( ) ;
if ( fromConfig ! = null & & fromConfig . getAbsolutePath ( ) . equals ( cacheDir . getAbsolutePath ( ) ) = = false ) {
config . setCacheDir ( cacheDir ) ;
}
else {
2016-01-06 20:26:46 +01:00
// do nothing because the directory is the same as before
2015-01-15 23:20:17 +01:00
}
}
2015-01-24 17:49:27 +00:00
GPUDevice selected_gpu = null ;
for ( JCheckBoxGPU box : useGPUs ) {
2015-01-15 23:20:17 +01:00
if ( box . isSelected ( ) ) {
2015-01-24 17:49:27 +00:00
selected_gpu = box . getGPUDevice ( ) ;
2015-01-15 23:20:17 +01:00
}
}
2021-07-16 23:37:24 +00:00
ComputeType method = getComputeType ( selected_gpu ) ;
2015-01-15 23:20:17 +01:00
config . setComputeMethod ( method ) ;
2015-01-24 17:49:27 +00:00
if ( selected_gpu ! = null ) {
2019-08-07 22:17:59 +02:00
config . setGPUDevice ( selected_gpu ) ;
2015-01-15 23:20:17 +01:00
}
2020-05-16 18:20:38 +10:00
int renderbucket_size = - 1 ;
if ( renderbucketSize ! = null ) {
renderbucket_size = ( int ) Math . pow ( 2 , ( renderbucketSize . getValue ( ) + 5 ) ) ;
}
2021-07-16 23:37:24 +00:00
config . setRenderbucketSize ( renderbucket_size ) ;
2020-05-16 18:20:38 +10:00
2015-04-20 21:26:07 +01:00
int cpu_cores = - 1 ;
2015-06-05 12:51:27 +00:00
if ( cpuCores ! = null ) {
2015-04-20 21:26:07 +01:00
cpu_cores = cpuCores . getValue ( ) ;
}
if ( cpu_cores > 0 ) {
2019-08-07 22:17:59 +02:00
config . setNbCores ( cpu_cores ) ;
2015-04-20 21:26:07 +01:00
}
2019-02-20 13:46:53 +01:00
long max_ram = - 1 ;
2017-03-29 22:13:04 +02:00
if ( ram ! = null ) {
max_ram = ram . getValue ( ) ;
}
if ( max_ram > 0 ) {
config . setMaxMemory ( max_ram ) ;
}
2017-04-25 13:06:23 +02:00
int max_rendertime = - 1 ;
if ( renderTime ! = null ) {
2020-05-28 13:28:42 +02:00
max_rendertime = ( Integer ) renderTime . getValue ( ) * 60 ;
2017-04-25 13:06:23 +02:00
config . setMaxRenderTime ( max_rendertime ) ;
}
2021-05-29 15:14:00 +00:00
// ui display low -> high but the actual values are reversed
// -19 is highest priority
OS os = OS . getOS ( ) ;
boolean high_priority_support = os . getSupportHighPriority ( ) ;
if ( high_priority_support ) {
// inverse
config . setUsePriority ( - 1 * priority . getValue ( ) ) ;
}
else {
config . setUsePriority ( 19 - priority . getValue ( ) ) ;
}
2017-03-19 17:38:22 +01:00
2021-07-16 23:37:24 +00:00
config . setHeadless ( headlessCheckbox . isSelected ( ) ) ;
2015-07-06 18:41:28 +01:00
String proxyText = null ;
if ( proxy ! = null ) {
try {
Proxy . set ( proxy . getText ( ) ) ;
proxyText = proxy . getText ( ) ;
}
catch ( MalformedURLException e1 ) {
System . err . println ( " Error: wrong url for proxy " ) ;
2017-01-12 20:50:44 +01:00
System . err . println ( e1 ) ;
2015-07-06 18:41:28 +01:00
System . exit ( 2 ) ;
}
}
2021-07-16 23:37:24 +00:00
config . setProxy ( proxyText ) ;
2015-07-06 18:41:28 +01:00
2015-01-15 23:20:17 +01:00
parent . setCredentials ( login . getText ( ) , new String ( password . getPassword ( ) ) ) ;
2015-03-31 00:29:58 +01:00
2018-04-07 21:13:39 +02:00
String hostnameText = hostname . getText ( ) ;
if ( hostnameText = = null | | hostnameText . isEmpty ( ) ) {
hostnameText = parent . getConfiguration ( ) . getHostname ( ) ;
2017-05-08 01:35:08 +02:00
}
2021-07-16 23:37:24 +00:00
config . setHostname ( hostnameText ) ;
config . setAutoSignIn ( autoSignIn . isSelected ( ) ) ;
config . setUseSysTray ( useSysTray . isSelected ( ) ) ;
// config.setUIType(GuiSwing.type);
2017-05-08 01:35:08 +02:00
2015-03-31 21:35:04 +01:00
if ( saveFile . isSelected ( ) ) {
2021-10-02 19:38:04 +00:00
parent . getSettingsLoader ( )
. setSettings ( config . getConfigFilePath ( ) , login . getText ( ) , new String ( password . getPassword ( ) ) , proxyText , hostnameText , method ,
selected_gpu , renderbucket_size , cpu_cores , max_ram , max_rendertime , getCachePath ( config ) , autoSignIn . isSelected ( ) , useSysTray . isSelected ( ) ,
headlessCheckbox . isSelected ( ) , GuiSwing . type , themeOptionsGroup . getSelection ( ) . getActionCommand ( ) , config . getPriority ( ) ) ;
2019-09-15 21:34:16 +02:00
// wait for successful authentication (to store the public key)
// or do we already have one?
if ( parent . getClient ( ) . getServer ( ) . getServerConfig ( ) ! = null & & parent . getClient ( ) . getServer ( ) . getServerConfig ( ) . getPublickey ( ) ! = null ) {
parent . getSettingsLoader ( ) . saveFile ( ) ;
2021-07-16 23:37:24 +00:00
sessionStarted = true ;
2019-09-15 21:34:16 +02:00
}
2021-07-16 23:37:24 +00:00
}
boolean sysTrayChanged = useSysTray . isSelected ( ) ! = useSysTrayPrevState ;
boolean headlessChanged = headlessCheckbox . isSelected ( ) ! = isHeadlessPrevState ;
boolean restartRequired = sysTrayChanged | | headlessChanged ;
if ( restartRequired ) {
String warning = " The following changes require a restart to take effect: %s " ;
List < String > changes = new LinkedList < > ( ) ;
2020-06-09 14:47:39 +10:00
2021-07-16 23:37:24 +00:00
if ( sysTrayChanged ) {
changes . add ( " Minimize to SysTray " ) ;
2020-06-09 14:47:39 +10:00
}
2021-07-16 23:37:24 +00:00
if ( headlessChanged & & sessionStarted ) { //only show this when the setting gets changed in the middle of a session, not on launch
changes . add ( " Block Eevee Projects " ) ;
}
if ( changes . size ( ) > 0 ) {
warning = String . format ( warning , String . join ( " , " , changes ) ) ;
JOptionPane . showMessageDialog ( null , warning ) ;
}
}
}
@NotNull private ComputeType getComputeType ( GPUDevice selected_gpu ) {
ComputeType method = ComputeType . CPU ;
if ( useCPU . isSelected ( ) & & selected_gpu = = null ) {
method = ComputeType . CPU ;
}
else if ( useCPU . isSelected ( ) = = false & & selected_gpu ! = null ) {
method = ComputeType . GPU ;
}
else if ( useCPU . isSelected ( ) & & selected_gpu ! = null ) {
method = ComputeType . CPU_GPU ;
}
return method ;
}
private String getCachePath ( Configuration config ) {
String cachePath = null ;
if ( config . isUserHasSpecifiedACacheDir ( ) & & config . getCacheDirForSettings ( ) ! = null ) {
cachePath = config . getCacheDirForSettings ( ) . getAbsolutePath ( ) ;
2015-04-02 20:31:16 +01:00
}
2021-07-16 23:37:24 +00:00
return cachePath ;
2015-01-15 23:20:17 +01:00
}
}
2015-01-24 17:49:27 +00:00
class JCheckBoxGPU extends JCheckBox {
private GPUDevice gpu ;
public JCheckBoxGPU ( GPUDevice gpu ) {
super ( gpu . getModel ( ) ) ;
this . gpu = gpu ;
}
public GPUDevice getGPUDevice ( ) {
return gpu ;
}
}
2015-04-03 19:39:52 +01:00
public class CheckCanStart implements KeyListener {
2020-05-28 13:28:42 +02:00
@Override public void keyPressed ( KeyEvent arg0 ) {
2015-04-03 19:39:52 +01:00
}
2020-05-28 13:28:42 +02:00
@Override public void keyReleased ( KeyEvent arg0 ) {
2015-07-10 20:54:08 -06:00
checkDisplaySaveButton ( ) ;
2015-04-03 19:39:52 +01:00
}
2020-05-28 13:28:42 +02:00
@Override public void keyTyped ( KeyEvent arg0 ) {
2015-04-03 19:39:52 +01:00
}
}
2015-01-15 23:20:17 +01:00
}