/** * Copyright 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ package com.jogamp.common.os; import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.concurrent.TimeUnit; import com.jogamp.common.util.JarUtil; import com.jogamp.common.util.ReflectionUtil; import com.jogamp.common.util.VersionNumber; import com.jogamp.common.util.cache.TempJarCache; import jogamp.common.Debug; import jogamp.common.jvm.JVMUtil; import jogamp.common.os.MachineDescriptionRuntime; import jogamp.common.os.PlatformPropsImpl; /** * Utility class for querying platform specific properties. *
* Some field declarations and it's static initialization has been delegated
* to it's super class {@link PlatformPropsImpl} to solve
* static initialization interdependencies w/ the GlueGen native library loading
* and it's derived information {@link #getMachineDescription()}, {@link #is32Bit()}, ..
* This mechanism is preferred in this case to avoid synchronization and locking
* and allow better performance accessing the mentioned fields/methods.
*
true
if AWT is available and not in headless mode, otherwise false
. */
public static final boolean AWT_AVAILABLE;
private static final URL platformClassJarURL;
static {
PlatformPropsImpl.initSingleton(); // just documenting the order of static initialization
{
URL _platformClassJarURL;
try {
_platformClassJarURL = JarUtil.getJarURL(Platform.class.getName(), Platform.class.getClassLoader());
} catch (Exception e) {
_platformClassJarURL = null;
}
platformClassJarURL = _platformClassJarURL;
}
USE_TEMP_JAR_CACHE = (OS_TYPE != OSType.ANDROID) && isRunningFromJarURL() &&
Debug.getBooleanProperty(useTempJarCachePropName, true, true);
AWT_AVAILABLE = AccessController.doPrivileged(new PrivilegedAction* Implies {@link #isJavaSE()}. *
** Note: We claim Android is compatible. *
*/ public static boolean isJava6() { return JAVA_6; } /** * Returns true if this machine is little endian, otherwise false. */ public static boolean isLittleEndian() { return LITTLE_ENDIAN; } /** * Returns the OS name. *In case of {@link OSType#ANDROID}, see {@link #getOSType()}, the OS name is Linux
*/ public static String getOSName() { return OS; } /** * Returns the OS version. */ public static String getOSVersion() { return OS_VERSION; } /** * Returns the OS version number. */ public static VersionNumber getOSVersionNumber() { return OS_VERSION_NUMBER; } /** * Returns the CPU architecture String. */ public static String getArchName() { return ARCH; } /** * Returns the OS type. *In case of {@link OSType#ANDROID} the OS name, see {@link #getOSName()}, is Linux
*/ public static OSType getOSType() { return OS_TYPE; } /** * Returns the CPU type. */ public static CPUFamily getCPUFamily() { return CPU_ARCH.getFamily(); } /** * Returns the CPU architecture. */ public static CPUType getCPUType() { return CPU_ARCH; } /** * Returns the (guessed) ABI. */ public static ABIType getABIType() { return ABI_TYPE; } /** * Returns the GlueGen common name for the currently running OSType and CPUType * as implemented in the build system in 'gluegen-cpptasks-base.xml'.Shortcut to {@link #getMachineDescription()}.{@link MachineDescription#is32Bit() is32Bit()}
*/ public static boolean is32Bit() { // return Platform.machineDescription.is32Bit(); return Platform.is32Bit; // used very often } /** * Returns true if this JVM/ARCH is 64bit. *Shortcut to {@link #getMachineDescription()}.{@link MachineDescription#is32Bit() is64Bit()}
*/ public static boolean is64Bit() { // return Platform.machineDescription.is64Bit(); return !Platform.is32Bit; // used very often } /** * Returns the MachineDescription of the running machine. */ public static MachineDescription getMachineDescription() { return machineDescription; } /** Returnstrue
if AWT is available and not in headless mode, otherwise false
. */
public static boolean isAWTAvailable() {
return AWT_AVAILABLE;
}
//
// time / jitter
//
/**
* Returns the estimated sleep jitter value in nanoseconds.
* * Includes a warm-up path, allowing hotspot to optimize the code. *
*/ public static synchronized long getCurrentSleepJitter() { getCurrentSleepJitterImpl(TimeUnit.MILLISECONDS.toNanos(10), 10); // warm-up return getCurrentSleepJitterImpl(TimeUnit.MILLISECONDS.toNanos(10), 10); } private static long getCurrentSleepJitterImpl(final long nsDuration, final int splitInLoops) { final long nsPeriod = nsDuration / splitInLoops; final long t0_ns = System.nanoTime(); for(int i=splitInLoops; i>0; i--) { try { TimeUnit.NANOSECONDS.sleep(nsPeriod); } catch (InterruptedException e) { } } return ( ( System.nanoTime() - t0_ns ) - nsDuration ) / splitInLoops; } } 02111-1307 USA */ package net.sourceforge.jnlp.controlpanel; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.ArrayList; import javax.swing.Box; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.PlainDocument; import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.Translator; /** * This is the pane used with creating a JDialog version. This allows changing * the network configuration: Proxy * * @author Andrew Su (asu@redhat.com, andrew.su@utoronto.ca) * */ @SuppressWarnings("serial") public class NetworkSettingsPanel extends JPanel implements ActionListener { private DeploymentConfiguration config; private JPanel description; private ArrayList<JPanel> proxyPanels = new ArrayList<JPanel>(); // The stuff with editable fields /** List of properties used by this panel */ public static String[] properties = { "deployment.proxy.type", "deployment.proxy.http.host", "deployment.proxy.http.port", "deployment.proxy.bypass.local", "deployment.proxy.auto.config.url", }; /** * Creates a new instance of the network settings panel. * * @param config * Loaded DeploymentConfiguration file. */ public NetworkSettingsPanel(DeploymentConfiguration config) { super(); this.config = config; setLayout(new BorderLayout()); addComponents(); } /** * This adds the components to the panel. */ protected void addComponents() { JPanel settingPanel = new NamedBorderPanel(Translator.R("CPHeadNetworkSettings")); settingPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.gridx = 0; JLabel networkDesc = new JLabel("<html>" + Translator.R("CPNetworkSettingsDescription") + "<hr /></html>"); JLabel[] description = { new JLabel("<html>" + Translator.R("NSDescription-1") + "</html>"), new JLabel("<html>" + Translator.R("NSDescription0") + "</html>"), new JLabel("<html>" + Translator.R("NSDescription1") + "</html>"), new JLabel("<html>" + Translator.R("NSDescription2") + "</html>"), new JLabel("<html>" + Translator.R("NSDescription3") + "</html>") }; this.description = new JPanel(new CardLayout()); for (int i = 0; i < description.length; i++) this.description.add(description[i], String.valueOf(i - 1)); // Settings for selecting Proxy Server JPanel proxyServerPanel = new JPanel(new GridLayout(0, 1)); JPanel proxyLocationPanel = new JPanel(new GridBagLayout()); JPanel proxyBypassPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); JLabel addressLabel = new JLabel(Translator.R("NSAddress") + ":"); JLabel portLabel = new JLabel(Translator.R("NSPort") + ":"); final JTextField addressField = new JTextField(config.getProperty(properties[1]), 10); addressField.getDocument().addDocumentListener(new DocumentAdapter(config, properties[1])); final JTextField portField = new JTextField(5); portField.setDocument(NetworkSettingsPanel.getPortNumberDocument()); portField.getDocument().addDocumentListener(new DocumentAdapter(config, properties[2])); portField.setText(config.getProperty(properties[2])); // Create the button which allows setting of other types of proxy. JButton advancedProxyButton = new JButton(Translator.R("NSAdvanced") + "..."); advancedProxyButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { AdvancedProxySettingsDialog.showAdvancedProxySettingsDialog(config); addressField.setText(config.getProperty(properties[1])); portField.setText(config.getProperty(properties[2])); } }); JCheckBox bypassCheckBox = new JCheckBox(Translator.R("NSBypassLocal"), Boolean.parseBoolean(config.getProperty(properties[3]))); bypassCheckBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { config.setProperty(properties[3], String.valueOf(e.getStateChange() == ItemEvent.SELECTED)); } }); c.gridy = 0; c.gridx = GridBagConstraints.RELATIVE; c.weightx = 0; proxyLocationPanel.add(Box.createHorizontalStrut(20), c); proxyLocationPanel.add(addressLabel, c); c.weightx = 1; proxyLocationPanel.add(addressField, c); c.weightx = 0; proxyLocationPanel.add(portLabel, c); c.weightx = 1; proxyLocationPanel.add(portField, c); c.weightx = 0; proxyLocationPanel.add(advancedProxyButton, c); proxyBypassPanel.add(Box.createHorizontalStrut(5)); proxyBypassPanel.add(bypassCheckBox); proxyServerPanel.add(proxyLocationPanel); proxyServerPanel.add(proxyBypassPanel); JRadioButton directConnection = new JRadioButton(Translator.R("NSDirectConnection"), config.getProperty(properties[0]).equals("0")); directConnection.setActionCommand("0"); directConnection.addActionListener(this); JRadioButton useProxyServer = new JRadioButton(Translator.R("NSManualProxy"), config.getProperty(properties[0]).equals("1")); useProxyServer.setActionCommand("1"); useProxyServer.addActionListener(this); JRadioButton useAutoProxyConfigScript = new JRadioButton(Translator.R("NSAutoProxy"), config.getProperty(properties[0]).equals("2")); useAutoProxyConfigScript.setActionCommand("2"); useAutoProxyConfigScript.addActionListener(this); JRadioButton useBrowserSettings = new JRadioButton(Translator.R("NSBrowserProxy"), config.getProperty(properties[0]).equals("3")); useBrowserSettings.setActionCommand("3"); useBrowserSettings.addActionListener(this); ButtonGroup modeSelect = new ButtonGroup(); modeSelect.add(useBrowserSettings); modeSelect.add(useProxyServer); modeSelect.add(useAutoProxyConfigScript); modeSelect.add(directConnection);