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 InitialMemoryHeap extends Editor {
034: private JTextField m_args = new JTextField();
035: private JComboBox m_units = new JComboBox();
036:
037: public InitialMemoryHeap() {
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.getInitialMemoryHeap(), m_args, m_units);
054: }
055:
056: public void updateModel() {
057: int value;
058:
059: // System.out.println("Parsing " + m_args.getText());
060:
061: try {
062: value = Integer.parseInt(m_args.getText());
063: } catch (Exception exc) {
064: // nothing here
065: m_model.setInitialMemoryHeap(-1);
066: return;
067: }
068: // System.out.println("sel index: " + m_units.getSelectedIndex() + " / " + value + " / " + (value*1024*1024));
069:
070: switch (m_units.getSelectedIndex()) {
071: case 0:
072: if (value > 2047)
073: value = 2047;
074: m_model.setInitialMemoryHeap(value * 1024 * 1024);
075: break;
076: case 1:
077: m_model.setInitialMemoryHeap(value * 1024);
078: break;
079: case 2:
080: m_model.setInitialMemoryHeap(value);
081: break;
082: }
083:
084: // System.out.println("Resulting initmem: " + m_model.getInitialMemoryHeap());
085: }
086:
087: public String getLabel() {
088: return "INITIALMEMORY_LABEL";
089: }
090:
091: public String getDescription() {
092: return "INITIALMEMORY_HELP";
093: }
094:
095: public void setValueCombo(int value, JTextField num, JComboBox box) {
096: if (value >= (1024 * 1024)) {
097: num.setText(new Integer(value / (1024 * 1024)).toString());
098: box.setSelectedIndex(0);
099: } else if (value >= 1024) {
100: num.setText(new Integer(value / 1024).toString());
101: box.setSelectedIndex(1);
102: } else if (value > 0) {
103: num.setText(new Integer(value).toString());
104: box.setSelectedIndex(2);
105: } else {
106: num.setText("");
107: box.setSelectedIndex(0);
108: }
109: }
110:
111: }
|