001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: package net.charabia.jsmoothgen.application.gui.editors;
022:
023: import net.charabia.jsmoothgen.skeleton.*;
024: import net.charabia.jsmoothgen.application.*;
025: import net.charabia.jsmoothgen.application.gui.*;
026: import net.charabia.jsmoothgen.application.gui.util.*;
027: import javax.swing.*;
028: import java.awt.*;
029: import java.util.*;
030: import java.io.File;
031: import java.util.jar.*;
032:
033: public class MaxMemoryHeap extends Editor {
034: private JTextField m_args = new JTextField();
035: private JComboBox m_units = new JComboBox();
036:
037: public MaxMemoryHeap() {
038: setLayout(new BorderLayout());
039: add(BorderLayout.CENTER, m_args);
040: m_args.setDocument(new RegExDocument("[0-9]+"));
041: m_args.setHorizontalAlignment(JTextField.RIGHT);
042:
043: Vector u = new Vector();
044: u.add(Main.local("UNIT_MB"));
045: u.add(Main.local("UNIT_KB"));
046: u.add(Main.local("UNIT_BYTE"));
047: DefaultComboBoxModel mod = new DefaultComboBoxModel(u);
048: m_units.setModel(mod);
049: add(BorderLayout.EAST, m_units);
050: }
051:
052: public void dataChanged() {
053: setValueCombo(m_model.getMaximumMemoryHeap(), m_args, m_units);
054: }
055:
056: public void updateModel() {
057: int value;
058:
059: try {
060: value = Integer.parseInt(m_args.getText());
061: } catch (Exception exc) {
062: // nothing here
063: m_model.setInitialMemoryHeap(-1);
064: return;
065: }
066:
067: switch (m_units.getSelectedIndex()) {
068: case 0:
069: if (value > 2047)
070: value = 2047;
071: m_model.setMaximumMemoryHeap(value * 1024 * 1024);
072: break;
073: case 1:
074: m_model.setMaximumMemoryHeap(value * 1024);
075: break;
076: case 2:
077: m_model.setMaximumMemoryHeap(value);
078: break;
079: }
080: }
081:
082: public String getLabel() {
083: return "MAXMEMORY_LABEL";
084: }
085:
086: public String getDescription() {
087: return "MAXMEMORY_HELP";
088: }
089:
090: public void setValueCombo(int value, JTextField num, JComboBox box) {
091: if (value >= (1024 * 1024)) {
092: num.setText(new Integer(value / (1024 * 1024)).toString());
093: box.setSelectedIndex(0);
094: } else if (value >= 1024) {
095: num.setText(new Integer(value / 1024).toString());
096: box.setSelectedIndex(1);
097: } else if (value > 0) {
098: num.setText(new Integer(value).toString());
099: box.setSelectedIndex(2);
100: } else {
101: num.setText("");
102: box.setSelectedIndex(0);
103: }
104: }
105:
106: }
|