Mercurial > hg > release > icedtea-web-1.7
changeset 1197:7f012876934e
ok/apply/cancel mechanism in itweb-settings fixed to work again. Added rest button for cache path.
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Fri, 10 Apr 2015 12:56:35 +0200 |
parents | 03e42ec1bc49 |
children | 8bddbbe7ee7a |
files | ChangeLog netx/net/sourceforge/jnlp/config/InfrastructureFileDescriptor.java netx/net/sourceforge/jnlp/controlpanel/CachePane.java netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java |
diffstat | 8 files changed, 265 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Apr 10 12:47:01 2015 +0200 +++ b/ChangeLog Fri Apr 10 12:56:35 2015 +0200 @@ -1,3 +1,20 @@ +2015-04-10 Jiri Vanek <jvanek@redhat.com> + + ok/apply/cancel mechanism in itweb-settings fixed to work again. Added rest button for cache path. + *netx/net/sourceforge/jnlp/config/InfrastructureFileDescriptor.java: added + setValue and getFullPaths overloads with DeploymentConfiguration param to + allow itweb-settings work with two copies of properties. + *netx/net/sourceforge/jnlp/controlpanel/CachePane.java: returned config. + Calls to PathsAndFiles made with this config. + *netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java: same + *netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java: same + *netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java: same + *netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java: Calls to + PathsAndFiles made with config. + *netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java: usableDiskSpace + removed, and replaced by dynamic getter to react on change of cache dir. + Added button resting cache to default. + 2015-04-10 Jiri Vanek <jvanek@redhat.com> Cache now uses PathsAndFiles instances instead of various duplications
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/config/InfrastructureFileDescriptor.java Fri Apr 10 12:56:35 2015 +0200 @@ -0,0 +1,191 @@ +/* + Copyright (C) 2012 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea 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 IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. +*/ + +package net.sourceforge.jnlp.config; + +import java.io.File; +import net.sourceforge.jnlp.runtime.JNLPRuntime; +import net.sourceforge.jnlp.runtime.Translator; + + +public class InfrastructureFileDescriptor { + private final String fileName; + private final String pathStub; + private final String systemPathStub; + private final String descriptionKey; + final PathsAndFiles.Target[] target; + + + //simple constructor to allow testing instances based on overrides + protected InfrastructureFileDescriptor() { + this("undef", "undef", "undef", "undef"); + } + + InfrastructureFileDescriptor(String fileName, String pathStub, String systemPathStub, String descriptionKey, PathsAndFiles.Target... target) { + this.fileName = fileName; + this.pathStub = pathStub; + this.systemPathStub = systemPathStub; + this.descriptionKey = descriptionKey; + this.target = target; + } + + /** setup-able files have to override this + * if they don't, they are read only, and set value will fail + * if it is desired to write value of property, then override and use known key. + * @return null by default. Should return key to configuration if overriden. + */ + protected String getPropertiesKey() { + return null; + } + + public File getFile() { + return new File(getFullPath()); + } + + public void setValue(String value) { + setValue(value, JNLPRuntime.getConfiguration()); + } + + public String getFullPath() { + return getFullPath(JNLPRuntime.getConfiguration()); + } + + /** + * overload version for control panel, which is saving to internal copy. + * @param value + * @param config + */ + public void setValue(String value, DeploymentConfiguration config) { + String key = getPropertiesKey(); + if (key == null) { + throw new IllegalStateException("This file is read only"); + } else { + config.setProperty(key, value); + } + } + + /** + * overload version for control panel, which is saving to internal copy. + * @param config + * @return + */ + public String getFullPath(DeploymentConfiguration config) { + String key = getPropertiesKey(); + if (key == null) { + return getDefaultFullPath(); + } else { + return config.getProperty(key); + } + } + + public File getDefaultFile() { + return new File(getDefaultFullPath()); + } + + public String getDefaultDir() { + return clean(systemPathStub + File.separator + pathStub); + } + + public String getDefaultFullPath() { + return clean(systemPathStub + File.separator + pathStub + File.separator + fileName); + } + + //returns path acronym for default location + protected String getSystemPathStubAcronym() { + return systemPathStub; + } + + protected String getFileName() { + return fileName; + } + + protected String getDescriptionKey() { + return descriptionKey; + } + + /** + * This remaining part of file declaration, when acronym is removed. + * See getDirViaAcronym. + * + * @return + */ + private String getStub() { + return clean(pathStub + File.separator + fileName); + } + + @Override + public String toString() { + return clean(getSystemPathStubAcronym() + File.separator + getStub()); + } + + /** + * For documentation purposes, the descriptor may be created as VARIABLE/custom/path. + * + * This is whole part, which is considered as setup-able. + * @return + */ + public String getDirViaAcronym() { + return clean(getSystemPathStubAcronym() + File.separator + pathStub); + } + + /** + * Remove garbage from paths. + * + * Currently this methods unify all multiple occurrences of separators + * to single one. Eg /path/to//file will become /path/to/file. + * + * Those artifacts maybe spread during various s=path+deparator+subdir+separator + * file=s+separator+filename + * + * @param s string to be cleaned + * @return cleaned string + */ + protected String clean(String s) { + while (s.contains(File.separator + File.separator)) { + s = s.replace(File.separator + File.separator, File.separator); + } + return s; + } + + /** + * @return the translated description + */ + public String getDescription() { + return Translator.R(descriptionKey); + } + +}
--- a/netx/net/sourceforge/jnlp/controlpanel/CachePane.java Fri Apr 10 12:47:01 2015 +0200 +++ b/netx/net/sourceforge/jnlp/controlpanel/CachePane.java Fri Apr 10 12:56:35 2015 +0200 @@ -60,6 +60,7 @@ import net.sourceforge.jnlp.cache.CacheDirectory; import net.sourceforge.jnlp.cache.CacheUtil; import net.sourceforge.jnlp.cache.DirectoryNode; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.config.PathsAndFiles; import net.sourceforge.jnlp.runtime.Translator; import net.sourceforge.jnlp.util.FileUtils; @@ -68,7 +69,8 @@ import net.sourceforge.jnlp.util.ui.NonEditableTableModel; public class CachePane extends JPanel { - JDialog parent; + final JDialog parent; + final DeploymentConfiguration config; private final String location; private JComponent defaultFocusComponent; DirectoryNode root; @@ -87,10 +89,11 @@ * * @param parent The parent dialog that uses this pane. */ - public CachePane(JDialog parent) { + public CachePane(JDialog parent, DeploymentConfiguration config) { super(new BorderLayout()); this.parent = parent; - location = PathsAndFiles.CACHE_DIR.getFullPath(); + this.config = config; + location = PathsAndFiles.CACHE_DIR.getFullPath(config); addComponents(); } @@ -268,7 +271,7 @@ public void run() { try { FileLock fl = null; - File netxRunningFile = PathsAndFiles.MAIN_LOCK.getFile(); + File netxRunningFile = new File(PathsAndFiles.MAIN_LOCK.getFullPath(config)); if (!netxRunningFile.exists()) { try { FileUtils.createParentDir(netxRunningFile); @@ -319,7 +322,7 @@ } private void updateRecentlyUsed(File f) { - File recentlyUsedFile = PathsAndFiles.getRecentlyUsedFile().getFile(); + File recentlyUsedFile = new File(PathsAndFiles.getRecentlyUsedFile().getFullPath(config)); PropertiesFile pf = new PropertiesFile(recentlyUsedFile); pf.load(); Enumeration<Object> en = pf.keys();
--- a/netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java Fri Apr 10 12:47:01 2015 +0200 +++ b/netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java Fri Apr 10 12:56:35 2015 +0200 @@ -18,7 +18,6 @@ package net.sourceforge.jnlp.controlpanel; import java.awt.Container; -import java.awt.Dimension; import java.awt.Frame; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -46,16 +45,21 @@ private boolean initialized = false; private static final String dialogTitle = Translator.R("CVCPDialogTitle"); + private final DeploymentConfiguration config; // Configuration file which contains all the settings. CachePane topPanel; /** * Creates a new instance of the cache viewer. - * + * + * @param config Deployment configuration file. */ - public CacheViewer() { + public CacheViewer(DeploymentConfiguration config) { super((Frame) null, dialogTitle, true); // Don't need a parent. + this.config = config; + if (config == null) { + throw new IllegalArgumentException("config: " + config); + } setIconImages(ImageResources.INSTANCE.getApplicationImages()); - /* Prepare for adding components to dialog box */ Container contentPane = getContentPane(); contentPane.setLayout(new GridBagLayout()); @@ -66,7 +70,7 @@ c.weighty = 1; c.gridx = 0; c.gridy = 0; - topPanel = new CachePane(this); + topPanel = new CachePane(this, this.config); contentPane.add(topPanel, c); pack(); @@ -119,9 +123,11 @@ /** * Display the cache viewer. + * + * @param config Configuration file. */ - public static void showCacheDialog() { - CacheViewer psd = new CacheViewer(); + public static void showCacheDialog(final DeploymentConfiguration config) { + CacheViewer psd = new CacheViewer(config); psd.setResizable(true); psd.centerDialog(); psd.setVisible(true);
--- a/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java Fri Apr 10 12:47:01 2015 +0200 +++ b/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java Fri Apr 10 12:56:35 2015 +0200 @@ -170,7 +170,7 @@ return JOptionPane.showConfirmDialog(ControlPanel.this, "<html>"+Translator.R("CPJVMNotokMessage1", s)+"<br/>" + validationResult.formattedText+"<br/>" - + Translator.R("CPJVMNotokMessage2", DeploymentConfiguration.KEY_JRE_DIR, PathsAndFiles.USER_DEPLOYMENT_FILE.getFullPath())+"</html>", + + Translator.R("CPJVMNotokMessage2", DeploymentConfiguration.KEY_JRE_DIR, PathsAndFiles.USER_DEPLOYMENT_FILE.getFullPath(config))+"</html>", Translator.R("CPJVMconfirmInvalidJdkTitle"),JOptionPane.OK_CANCEL_OPTION); } return JOptionPane.OK_OPTION; @@ -360,7 +360,7 @@ } private JPanel createPolicySettingsPanel() { - return new PolicyPanel(this); + return new PolicyPanel(this, this.config); } private JPanel createJVMSettingsPanel() {
--- a/netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java Fri Apr 10 12:47:01 2015 +0200 +++ b/netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java Fri Apr 10 12:56:35 2015 +0200 @@ -86,7 +86,7 @@ final JLabel debuggingDescription = new JLabel("<html>" + Translator.R("CPDebuggingDescription") + "<hr /><br /></html>"); final JLabel logsDestinationTitle = new JLabel(Translator.R("CPFilesLogsDestDir")+": "); - final JTextField logsDestination = new JTextField(PathsAndFiles.LOG_DIR.getFullPath()); + final JTextField logsDestination = new JTextField(PathsAndFiles.LOG_DIR.getFullPath(config)); logsDestination.getDocument().addDocumentListener(new DocumentListener() { @@ -107,7 +107,7 @@ } private void save() { - PathsAndFiles.LOG_DIR.setValue(logsDestination.getText()); + PathsAndFiles.LOG_DIR.setValue(logsDestination.getText(), config); } }); final JButton logsDestinationReset = new JButton(Translator.R("CPFilesLogsDestDirResert"));
--- a/netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java Fri Apr 10 12:47:01 2015 +0200 +++ b/netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java Fri Apr 10 12:56:35 2015 +0200 @@ -56,6 +56,7 @@ import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.SwingUtilities; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.config.PathsAndFiles; import net.sourceforge.jnlp.security.policyeditor.PolicyEditor; @@ -73,16 +74,18 @@ public class PolicyPanel extends NamedBorderPanel { private PolicyEditorWindow policyEditor = null; + private final DeploymentConfiguration config; - public PolicyPanel(final JFrame frame) { + public PolicyPanel(final JFrame frame, final DeploymentConfiguration config) { super(R("CPHeadPolicy"), new GridBagLayout()); + this.config = config; addComponents(frame); } private void addComponents(final JFrame frame) { JLabel aboutLabel = new JLabel("<html>" + R("CPPolicyDetail") + "</html>"); - final String fileUrlString = PathsAndFiles.JAVA_POLICY.getFullPath(); + final String fileUrlString = PathsAndFiles.JAVA_POLICY.getFullPath(config); final JButton simpleEditorButton = new JButton(R("CPButSimpleEditor")); simpleEditorButton.addActionListener(new LaunchSimplePolicyEditorAction(frame, fileUrlString));
--- a/netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java Fri Apr 10 12:47:01 2015 +0200 +++ b/netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java Fri Apr 10 12:56:35 2015 +0200 @@ -70,14 +70,13 @@ private final JSpinner cacheSizeSpinner; private static final long BYTES_TO_MEGABYTES = 1024l * 1024l; - private final File cacheDir; - final long usableDiskSpace; private final JCheckBox limitCacheSizeCheckBox; private final JLabel cacheSizeWarningLabel; private final DeploymentConfiguration config; private final JComboBox<ComboItem> cbCompression; private final JButton bLocation; + private final JButton resetLocation; private final JTextField location; private final JLabel locationDescription; private final JLabel lCompression; @@ -108,16 +107,14 @@ lCompression = new JLabel(Translator.R("TIFPCompressionLevel") + ":"); // Sets compression level for jar files. bLocation = new JButton(Translator.R("TIFPChange") + "..."); - location = new JTextField(PathsAndFiles.CACHE_DIR.getFullPath()); + resetLocation = new JButton(Translator.R("CPFilesLogsDestDirResert")); + location = new JTextField(PathsAndFiles.CACHE_DIR.getFullPath(config)); locationDescription = new JLabel(Translator.R("TIFPLocationLabel") + ":"); bViewFiles = new JButton(Translator.R("TIFPViewFiles")); diskSpacePanel = new JPanel(); diskSpacePanel.setLayout(new GridBagLayout()); - cacheDir = PathsAndFiles.CACHE_DIR.getFile(); - usableDiskSpace = cacheDir.getUsableSpace() / BYTES_TO_MEGABYTES; // getUsableSpace returns bytes - addComponents(); if (limitCacheSizeCheckBox.isSelected()) { showCacheSizeSpinnerGUIElements(true); @@ -187,7 +184,15 @@ c.gridx = 1; c.gridwidth = 2; diskSpacePanel.add(cbCompression, c); - + resetLocation.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + location.setText(PathsAndFiles.CACHE_DIR.getDefaultFullPath()); + //background engine is clever. Will reset for us if it will see default path here + PathsAndFiles.CACHE_DIR.setValue(PathsAndFiles.CACHE_DIR.getDefaultFullPath(), config); + showCacheSizeSpinnerGUIElements(limitCacheSizeCheckBox.isSelected()); + } + }); // This displays the option for changing location of cache // User can NOT edit the text field must do it through dialog. location.setEditable(false); // Can not c&p into the location field. @@ -217,7 +222,8 @@ if (canWrite) { location.setText(result); - PathsAndFiles.CACHE_DIR.setValue(result); + PathsAndFiles.CACHE_DIR.setValue(result, config); + showCacheSizeSpinnerGUIElements(limitCacheSizeCheckBox.isSelected()); } } } @@ -226,7 +232,7 @@ bViewFiles.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - CacheViewer.showCacheDialog(); + CacheViewer.showCacheDialog(config); } }); @@ -240,8 +246,11 @@ diskSpacePanel.add(location, c); c.gridx = 1; c.weightx = 0.5; + diskSpacePanel.add(resetLocation, c); + c.gridx = 2; + c.weightx = 0.5; diskSpacePanel.add(bLocation, c); - c.gridx = 2; + c.gridx = 3; diskSpacePanel.add(bViewFiles, c); JPanel panel = new JPanel(); @@ -259,6 +268,11 @@ } + private long getCurrentUsableSpace() { + long usableDiskSpace = new File(PathsAndFiles.CACHE_DIR.getFullPath(config)).getUsableSpace() / BYTES_TO_MEGABYTES; // getUsableSpace returns bytes + return usableDiskSpace; + } + private static class PowerOfSpinnerNumberModel extends SpinnerNumberModel { private final List<Long> powersOf; @@ -327,6 +341,7 @@ @Override public void stateChanged(final ChangeEvent e) { + final long usableDiskSpace = getCurrentUsableSpace(); final long cacheSizeSpinnerValue = (long) cacheSizeSpinner.getValue(); if (limitCacheSizeCheckBox.isSelected()) { @@ -374,6 +389,7 @@ private void showCompressionAndLocationGUIElements(boolean bool) { cbCompression.setEnabled(bool); lCompression.setEnabled(bool); + resetLocation.setEnabled(bool); bLocation.setEnabled(bool); location.setEnabled(bool); locationDescription.setEnabled(bool); @@ -384,7 +400,7 @@ lCacheSize.setEnabled(bool); cacheSizeSpinner.setEnabled(bool); cacheSizeWarningLabel.setEnabled(bool); - + long usableDiskSpace = getCurrentUsableSpace(); if(bool == false) { cacheSizeSpinner.setToolTipText(null); cacheSizeWarningLabel.setText(Translator.R("TIFPCacheSizeSpinnerLargeValueWarning", usableDiskSpace));