コード例 #1
0
  /** Creates the editor component of the property editor. */
  public void createComponent() {
    JCheckBox c = new JCheckBox();

    c.setEnabled(!readonly);
    c.addKeyListener(this);
    c.addChangeListener(this);
    c.addFocusListener(this);

    component = c;
  }
コード例 #2
0
ファイル: OptionsPane.java プロジェクト: fr1zle/FTBLaunch
  public OptionsPane() {
    this.setBorder(new EmptyBorder(5, 5, 5, 5));
    currentRam = new JLabel();
    currentRam.setBounds(427, 114, 85, 23);
    long ram = 0;
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    Method m;
    try {
      m = operatingSystemMXBean.getClass().getDeclaredMethod("getTotalPhysicalMemorySize");
      m.setAccessible(true);
      Object value = m.invoke(operatingSystemMXBean);
      if (value != null) {
        ram = Long.valueOf(value.toString()) / 1024 / 1024;
      } else {
        Logger.logWarn("Could not get RAM Value");
        ram = 8192;
      }
    } catch (Exception e) {
      Logger.logError(e.getMessage(), e);
    }

    ramMaximum = new JSlider();
    ramMaximum.setBounds(190, 114, 222, 23);
    ramMaximum.setSnapToTicks(true);
    ramMaximum.setMajorTickSpacing(256);
    ramMaximum.setMinorTickSpacing(256);
    ramMaximum.setMinimum(256);
    String vmType = System.getProperty("sun.arch.data.model");
    if (vmType != null) {
      if (vmType.equals("64")) {
        ramMaximum.setMaximum((int) ram);
      } else if (vmType.equals("32")) {
        if (ram < 1024) {
          ramMaximum.setMaximum((int) ram);
        } else {
          ramMaximum.setMaximum(1024);
        }
      }
    }
    int ramMax =
        (Integer.parseInt(Settings.getSettings().getRamMax()) > ramMaximum.getMaximum())
            ? ramMaximum.getMaximum()
            : Integer.parseInt(Settings.getSettings().getRamMax());
    ramMaximum.setValue(ramMax);
    currentRam.setText(getAmount());
    ramMaximum.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent arg0) {
            currentRam.setText(getAmount());
          }
        });
    ramMaximum.addFocusListener(settingsChangeListener);

    JButton installBrowseBtn = new JButton("...");
    installBrowseBtn.setBounds(786, 11, 49, 23);
    installBrowseBtn.addActionListener(new ChooseDir(this));
    setLayout(null);
    add(installBrowseBtn);

    lblInstallFolder = new JLabel(I18N.getLocaleString("INSTALL_FOLDER"));
    lblInstallFolder.setBounds(10, 11, 127, 23);
    add(lblInstallFolder);

    installFolderTextField = new JTextField();
    installFolderTextField.setBounds(147, 11, 629, 23);
    installFolderTextField.addFocusListener(settingsChangeListener);
    installFolderTextField.setColumns(10);
    installFolderTextField.setText(Settings.getSettings().getInstallPath());
    add(installFolderTextField);

    tglbtnForceUpdate = new JToggleButton(I18N.getLocaleString("FORCE_UPDATE"));
    tglbtnForceUpdate.setBounds(147, 45, 629, 29);
    tglbtnForceUpdate.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            tglbtnForceUpdate.setEnabled(false);
            saveSettingsInto(Settings.getSettings());
          }
        });
    tglbtnForceUpdate.getModel().setPressed(Settings.getSettings().getForceUpdate());
    add(tglbtnForceUpdate);

    lblRamMaximum = new JLabel(I18N.getLocaleString("RAM_MAX"));
    lblRamMaximum.setBounds(10, 114, 195, 23);
    add(lblRamMaximum);
    add(ramMaximum);
    add(currentRam);

    ArrayList<String> locales = new ArrayList<String>();
    for (Map.Entry<Integer, String> entry : I18N.localeIndices.entrySet()) {
      Logger.logInfo(
          "[i18n] Added "
              + entry.getKey().toString()
              + " "
              + entry.getValue()
              + " to options pane");
      locales.add(entry.getKey(), I18N.localeFiles.get(entry.getValue()));
    }

    locale = new JComboBox(locales.toArray());
    locale.setBounds(190, 148, 222, 23);
    locale.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            I18N.setLocale(I18N.localeIndices.get(locale.getSelectedIndex()));
            if (LaunchFrame.getInstance() != null) {
              LaunchFrame.getInstance().updateLocale();
            }
          }
        });
    locale.addFocusListener(settingsChangeListener);
    locale.setSelectedItem(I18N.localeFiles.get(Settings.getSettings().getLocale()));

    lblLocale = new JLabel(I18N.getLocaleString("LANGUAGE"));
    lblLocale.setBounds(10, 148, 195, 23);
    add(lblLocale);
    add(locale);

    minecraftSize = new JLabel("Size for Minecraft Window");
    minecraftSize.setBounds(10, 182, 195, 23);
    add(minecraftSize);

    minecraftX = new JTextField();
    minecraftX.setBounds(190, 182, 85, 22);
    minecraftX.setDocument(new documentFilter("\\D++"));
    minecraftX.setText(Settings.getSettings().getMinecraftX());
    minecraftX.addFocusListener(settingsChangeListener);
    add(minecraftX);

    lblX = new JLabel("x");
    lblX.setBounds(297, 182, 6, 20);
    add(lblX);

    minecraftY = new JTextField();
    minecraftY.setBounds(327, 182, 85, 23);
    minecraftY.setDocument(new documentFilter("\\D++"));
    minecraftY.setText(Settings.getSettings().getMinecraftY());
    minecraftY.addFocusListener(settingsChangeListener);
    add(minecraftY);
    minecraftY.setColumns(5);

    JLabel minecraftPos = new JLabel("Position of Minecraft Window");
    minecraftPos.setBounds(10, 216, 195, 23);
    add(minecraftPos);

    xPosField = new JTextField();
    xPosField.setBounds(190, 217, 85, 22);
    xPosField.setDocument(new documentFilter("\\D++"));
    xPosField.setText(Settings.getSettings().getMinecraftXPos());
    xPosField.addFocusListener(settingsChangeListener);
    add(xPosField);
    xPosField.setColumns(10);

    JLabel lblX_1 = new JLabel("x");
    lblX_1.setBounds(297, 216, 6, 23);
    add(lblX_1);

    yPosField = new JTextField();
    yPosField.setBounds(327, 216, 85, 23);
    yPosField.setDocument(new documentFilter("\\D++"));
    yPosField.setText(Settings.getSettings().getMinecraftYPos());
    yPosField.addFocusListener(settingsChangeListener);
    add(yPosField);
    yPosField.setColumns(10);

    tglbtnCenterScreen = new JToggleButton("Center Window on Screen");
    tglbtnCenterScreen.setBounds(190, 252, 222, 23);
    tglbtnCenterScreen.setSelected(Boolean.parseBoolean(Settings.getSettings().getCenterWindow()));
    tglbtnCenterScreen.addFocusListener(settingsChangeListener);
    add(tglbtnCenterScreen);

    downloadServers = new JComboBox(getDownloadServerNames());
    downloadServers.setBounds(613, 115, 222, 23);
    downloadServers.addFocusListener(settingsChangeListener);
    if (DownloadUtils.serversLoaded) {
      if (DownloadUtils.downloadServers.containsKey(Settings.getSettings().getDownloadServer())) {
        downloadServers.setSelectedItem(Settings.getSettings().getDownloadServer());
      }
    }
    add(downloadServers);

    JLabel downloadLocation = new JLabel("Download Location");
    downloadLocation.setBounds(490, 118, 110, 14);
    add(downloadLocation);

    chckbxShowConsole = new JCheckBox("Show Console?");
    chckbxShowConsole.addFocusListener(settingsChangeListener);
    chckbxShowConsole.setSelected(Boolean.parseBoolean(Settings.getSettings().getConsoleActive()));
    chckbxShowConsole.setBounds(613, 148, 183, 23);
    add(chckbxShowConsole);

    autoMaxCheck = new JCheckBox("Automatically Maximize?");
    autoMaxCheck.addFocusListener(settingsChangeListener);
    autoMaxCheck.setSelected(Boolean.parseBoolean(Settings.getSettings().getAutoMaximize()));
    autoMaxCheck.setBounds(613, 184, 183, 23);
    add(autoMaxCheck);

    JLabel javaLocLabel = new JLabel("Java Location");
    javaLocLabel.setBounds(490, 220, 110, 14);
    add(javaLocLabel);

    javaInstallDir = new JTextField();
    javaInstallDir.setEditable(false);
    String javaInstall = Settings.getSettings().getJavaInstall();
    javaInstallDir.setText(javaInstall);
    javaInstallDir.setToolTipText(javaInstall);
    javaInstallDir.setBounds(613, 220, 230, 23);
    add(javaInstallDir);

    JButton dirChooserButton = new JButton("Change");
    dirChooserButton.setBounds(763, 240, 80, 23);
    dirChooserButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(Settings.getSettings().getJavaInstall());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int option = chooser.showOpenDialog(OptionsPane.this);
            if (JFileChooser.APPROVE_OPTION == option) {
              File selectedDir = chooser.getSelectedFile();
              String javaExecutableName = "java";
              if (OS.WINDOWS.equals(OSUtils.getCurrentOS())) {
                javaExecutableName += ".exe";
              }
              File javaExecutable =
                  new File(
                      selectedDir
                          + System.getProperty("file.separator")
                          + "bin"
                          + System.getProperty("file.separator")
                          + javaExecutableName);
              if (javaExecutable.exists()) {
                javaInstallDir.setText(selectedDir.getAbsolutePath());
                saveSettingsInto(Settings.getSettings());
              } else {
                JOptionPane.showMessageDialog(
                    OptionsPane.this,
                    "The selected directoy is not a proper Java installation.",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
              }
            }
          }
        });
    add(dirChooserButton);
  }