|
From: <fd...@us...> - 2007-04-15 18:15:19
|
Revision: 3159
http://jnode.svn.sourceforge.net/jnode/?rev=3159&view=rev
Author: fduminy
Date: 2007-04-15 11:15:09 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
Removed Paths:
-------------
trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java
trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java
trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java 2007-04-15 18:10:57 UTC (rev 3158)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java 2007-04-15 18:15:09 UTC (rev 3159)
@@ -1,35 +0,0 @@
-/**
- *
- */
-package org.jnode.apps.jpartition;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.naming.NameAlreadyBoundException;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.jnode.naming.NameSpace;
-
-public final class BasicNameSpace implements NameSpace {
- protected final Map<Class<?>, Object> namespace = new HashMap<Class<?>, Object>();
-
- public <T> void bind(Class<T> name, T service)
- throws NamingException, NameAlreadyBoundException {
- namespace.put(name, service);
- }
-
- public <T> T lookup(Class<T> name) throws NameNotFoundException {
- return (T) namespace.get(name);
- }
-
- public Set<Class<?>> nameSet() {
- return namespace.keySet();
- }
-
- public void unbind(Class<?> name) {
- namespace.remove(name);
- }
-}
\ No newline at end of file
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java 2007-04-15 18:10:57 UTC (rev 3158)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java 2007-04-15 18:15:09 UTC (rev 3159)
@@ -1,86 +0,0 @@
-package org.jnode.apps.jpartition;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.ByteBuffer;
-
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.jnode.apps.vmware.disk.VMWareDisk;
-import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
-import org.jnode.driver.DeviceManager;
-import org.jnode.driver.DriverException;
-import org.jnode.driver.block.BlockDeviceAPIHelper;
-import org.jnode.driver.block.PartitionableBlockDeviceAPI;
-import org.jnode.driver.bus.ide.IDEConstants;
-import org.jnode.driver.bus.ide.IDEDevice;
-import org.jnode.driver.bus.ide.IDEDeviceFactory;
-import org.jnode.driver.bus.ide.IDEDriverUtils;
-import org.jnode.naming.InitialNaming;
-import org.jnode.partitions.PartitionTable;
-import org.jnode.partitions.ibm.IBMPartitionTable;
-import org.jnode.partitions.ibm.IBMPartitionTableType;
-
-public class FileIDEDevice extends IDEDevice implements PartitionableBlockDeviceAPI
-{
- private VMWareDisk vmwareDisk;
- private PartitionTable pt;
-
- public FileIDEDevice(File file, long fileSize,
- boolean primary, boolean master)
- throws IOException, DriverException, NameNotFoundException, UnsupportedFormatException
- {
- super(null, primary, master, file.getName(), null, null);
- registerAPI(PartitionableBlockDeviceAPI.class, this);
-
- vmwareDisk = new VMWareDisk(file);
-
- setDriver(new FileIDEDeviceDriver());
-
- pt = buildPartitionTable();
- }
-
- public void flush() throws IOException {
- vmwareDisk.flush();
- }
-
- public long getLength() throws IOException {
- return vmwareDisk.getLength();
- }
-
- public void read(long devOffset, ByteBuffer destBuf) throws IOException {
- BlockDeviceAPIHelper.checkBounds(this, devOffset, destBuf.remaining());
-
- vmwareDisk.read(devOffset, destBuf);
- }
-
- public void write(long devOffset, ByteBuffer srcBuf) throws IOException {
- BlockDeviceAPIHelper.checkBounds(this, devOffset, srcBuf.remaining());
-
- vmwareDisk.write(devOffset, srcBuf);
- }
-
- public String toString()
- {
- return getId();
- }
-
- public PartitionTable getPartitionTable() throws IOException {
- return pt;
- }
-
- public int getSectorSize() throws IOException {
- return IDEConstants.SECTOR_SIZE;
- }
-
- protected PartitionTable buildPartitionTable() throws DriverException, IOException, NameNotFoundException
- {
- // Read the bootsector
- final byte[] bs = new byte[IDEConstants.SECTOR_SIZE];
- read(0, ByteBuffer.wrap(bs));
-
- return new IBMPartitionTable(new IBMPartitionTableType(), bs, this);
- }
-}
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java 2007-04-15 18:10:57 UTC (rev 3158)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java 2007-04-15 18:15:09 UTC (rev 3159)
@@ -1,32 +0,0 @@
-package org.jnode.apps.jpartition;
-
-import org.jnode.driver.Driver;
-import org.jnode.driver.DriverException;
-import org.jnode.driver.DeviceAlreadyRegisteredException;
-import org.jnode.driver.bus.ide.IDEDevice;
-
-/**
- *
- * @author Fabien DUMINY (fduminy at jnode.org)
- *
- */
-public class FileIDEDeviceDriver extends Driver {
- /**
- * Start the device.
- *
- * @throws org.jnode.driver.DriverException
- *
- */
- protected void startDevice() throws DriverException {
- }
-
- /**
- * Stop the device.
- *
- * @throws org.jnode.driver.DriverException
- *
- */
- protected void stopDevice() throws DriverException {
-
- }
-}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2007-04-15 18:10:57 UTC (rev 3158)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2007-04-15 18:15:09 UTC (rev 3159)
@@ -1,60 +1,58 @@
package org.jnode.apps.jpartition;
-import java.util.Collection;
-
-import javax.naming.NameNotFoundException;
-import javax.swing.JFrame;
-import javax.swing.SwingUtilities;
-
import org.apache.log4j.Logger;
-import org.jnode.apps.jpartition.model.DevicePartitions;
-import org.jnode.apps.jpartition.model.DevicePartitionsList;
-import org.jnode.apps.jpartition.view.DevicePartitionsFrame;
-import org.jnode.apps.jpartition.view.FileDeviceFrame;
-import org.jnode.driver.Device;
-import org.jnode.driver.DeviceManager;
-import org.jnode.driver.block.PartitionableBlockDeviceAPI;
+import org.jnode.apps.jpartition.controller.MainController;
+import org.jnode.apps.jpartition.swingview.SwingViewFactory;
+import org.jnode.apps.jpartition.utils.BasicNameSpace;
import org.jnode.naming.InitialNaming;
import org.jnode.naming.NameSpace;
import org.jnode.test.fs.driver.stubs.StubDeviceManager;
+import org.jnode.test.gui.Emu;
+import org.jnode.util.OsUtils;
-public class JPartition {
+public class JPartition extends Emu
+{
private static final Logger log = Logger.getLogger(JPartition.class);
- public static void main(String[] args) throws Exception {
- initJNodeCore();
+ public static void main(String[] args) throws Throwable
+ {
+// testCharva();
- FileDeviceFrame frm = new FileDeviceFrame();
- frm.setSize(300, 300);
- frm.setVisible(true);
- frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ if(!OsUtils.isJNode())
+ {
+ initJNodeCore();
+ }
- DevicePartitionsFrame mainUI = new DevicePartitionsFrame(getDevicePartitions());
- mainUI.setSize(300, 300);
- mainUI.setVisible(true);
- mainUI.setLocation(frm.getX(), frm.getY() + frm.getHeight());
- mainUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ ViewFactory viewFactory = new SwingViewFactory();
+ MainController controller = new MainController(viewFactory);
}
- public static DevicePartitionsList getDevicePartitions()
- {
- DevicePartitionsList devParts = new DevicePartitionsList();
- try {
- DeviceManager devMan = InitialNaming.lookup(DeviceManager.NAME);
- Collection<Device> devices = devMan.getDevicesByAPI(PartitionableBlockDeviceAPI.class);
- for(Device device : devices)
- {
- devParts.add(new DevicePartitions(device));
- }
- } catch (NameNotFoundException e) {
- log.error(e);
- }
- return devParts;
- }
-
private static void initJNodeCore() throws Exception {
NameSpace namespace = new BasicNameSpace();
InitialNaming.setNameSpace(namespace);
namespace.bind(DeviceManager.NAME, StubDeviceManager.INSTANCE);
- }
+ }
+
+/*
+ private static void testCharva() throws Throwable
+ {
+ initEnv();
+ SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager();
+ TextConsole tc = (TextConsole) cm.createConsole("Console 1",
+ ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE);
+ cm.focus(tc);
+ CommandShell cs = new CommandShell(tc);
+ final ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
+ sm.registerShell(cs);
+ new Thread(cs).start();
+
+ charvax.swing.JFrame frm = new charvax.swing.JFrame("test");
+ JLabel label = new JLabel("test");
+ frm.add(label);
+ frm.setFocus(label);
+ frm.setSize(300, 300);
+ frm.setVisible(true);
+ frm.setDefaultCloseOperation(charvax.swing.JFrame.EXIT_ON_CLOSE);
+ }
+*/
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 18:18:00
|
Revision: 3160
http://jnode.svn.sourceforge.net/jnode/?rev=3160&view=rev
Author: fduminy
Date: 2007-04-15 11:17:56 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessorListener.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java 2007-04-15 18:17:56 UTC (rev 3160)
@@ -0,0 +1,12 @@
+package org.jnode.apps.jpartition;
+
+import org.jnode.apps.jpartition.controller.MainController;
+
+public interface ViewFactory {
+ Object createDeviceView(MainController controller, Object fileDeviceView,
+ Object cmdProcessorView) throws Exception;
+
+ Object createFileDeviceView(MainController controller) throws Exception;
+
+ Object createCommandProcessorView(MainController mainController);
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java 2007-04-15 18:17:56 UTC (rev 3160)
@@ -0,0 +1,23 @@
+package org.jnode.apps.jpartition.commands;
+
+import org.jnode.apps.jpartition.commands.framework.BaseCommand;
+import org.jnode.apps.jpartition.commands.framework.CommandException;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.command.FdiskCommand;
+
+abstract public class BaseDeviceCommand extends BaseCommand {
+ protected final IDEDevice device;
+
+ public BaseDeviceCommand(String name, IDEDevice device)
+ {
+ super(name);
+ this.device = device;
+ }
+
+ abstract protected void doExecute() throws CommandException;
+
+ @Override
+ public String toString() {
+ return super.toString() + " - " + device.getId();
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java 2007-04-15 18:17:56 UTC (rev 3160)
@@ -0,0 +1,23 @@
+package org.jnode.apps.jpartition.commands;
+
+import org.jnode.apps.jpartition.commands.framework.CommandException;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.command.PartitionHelper;
+
+public class InitMbrCommand extends BaseDeviceCommand {
+
+ public InitMbrCommand(IDEDevice device) {
+ super("init MBR", device);
+ }
+
+ @Override
+ protected void doExecute() throws CommandException {
+ PartitionHelper helper;
+ try {
+ helper = new PartitionHelper(device);
+ helper.initMbr();
+ } catch (Throwable t) {
+ throw new CommandException(t);
+ }
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessorListener.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessorListener.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessorListener.java 2007-04-15 18:17:56 UTC (rev 3160)
@@ -0,0 +1,8 @@
+package org.jnode.apps.jpartition.commands.framework;
+
+public interface CommandProcessorListener {
+ void commandAdded(CommandProcessor processor, Command command);
+ void commandRemoved(CommandProcessor processor, Command command);
+ void commandStarted(CommandProcessor processor, Command command);
+ void commandFinished(CommandProcessor processor, Command command);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 21:17:18
|
Revision: 3164
http://jnode.svn.sourceforge.net/jnode/?rev=3164&view=rev
Author: fduminy
Date: 2007-04-15 14:17:16 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,82 @@
+package org.jnode.apps.jpartition.swingview;
+
+import it.battlehorse.stamps.annotations.ModelDependent;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.controller.MainController;
+
+public class CommandProcessorView extends JPanel
+{
+ private static final Logger log = Logger.getLogger(CommandProcessorView.class);
+
+ private MainController controller;
+
+ private DefaultListModel commands = new DefaultListModel();
+ private JList commandsUI = new JList(commands);
+ private JButton btnApply = new JButton("Apply");
+
+ public CommandProcessorView(MainController controller)
+ {
+ this.controller = controller;
+
+ setBorder(BorderFactory.createTitledBorder("pending commands"));
+
+ JPanel btnPanel = new JPanel(new BorderLayout());
+ btnPanel.add(btnApply, BorderLayout.NORTH);
+
+ JPanel panel = new JPanel(new BorderLayout());
+ panel.add(btnPanel, BorderLayout.EAST);
+ panel.add(new JScrollPane(commandsUI), BorderLayout.CENTER);
+ add(panel);
+
+ btnApply.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent ae_) {
+ CommandProcessorView.this.setEnabled(false);
+ CommandProcessorView.this.controller.userProcessCommands();
+ }
+ });
+ }
+
+ @ModelDependent(modelKey ="CommandProcessorModel" , propertyKey = "commandsProcessed")
+ public void commandsProcessed(Object command) {
+ setEnabled(true);
+ }
+
+ @ModelDependent(modelKey ="CommandProcessorModel" , propertyKey = "commandAdded")
+ public void commandAdded(Object command) {
+ commands.addElement(command);
+ }
+
+ @ModelDependent(modelKey ="CommandProcessorModel" , propertyKey = "commandStarted")
+ public void commandStarted(Object command) {
+ refreshCommand(command);
+ }
+
+ @ModelDependent(modelKey ="CommandProcessorModel" , propertyKey = "commandFinished")
+ public void commandFinished(Object command) {
+ refreshCommand(command);
+ }
+
+ @ModelDependent(modelKey ="CommandProcessorModel" , propertyKey = "commandRemoved")
+ public void commandRemoved(Object command) {
+ commands.removeElement(command);
+ }
+
+ protected void refreshCommand(Object command)
+ {
+ int index = commands.indexOf(command);
+ commands.set(index, command);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,96 @@
+package org.jnode.apps.jpartition.swingview;
+
+import it.battlehorse.stamps.annotations.ModelDependent;
+
+import javax.swing.JPanel;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.controller.MainController;
+import org.jnode.apps.jpartition.model.DeviceModel;
+
+public class DeviceView extends JPanel
+{
+ private static final Logger log = Logger.getLogger(DeviceView.class);
+
+ final private MainController controller;
+
+ //final private Object device;
+
+ public DeviceView(MainController controller)
+ {
+ this.controller = controller;
+ }
+
+/*
+ private static final Logger log = Logger.getLogger(DevicePartitionsUI.class);
+
+ final private DevicePartitionsList devicePartitions;
+
+ final private DefaultComboBoxModel cboDevicesModel = new DefaultComboBoxModel();
+ final private JComboBox cboDevices = new JComboBox(cboDevicesModel);
+ final private JPanel partitionsPanel = new JPanel(new FlowLayout());
+ final private PartitionController controller;
+
+ public DevicePartitionsUI(DevicePartitionsList devicePartitions, PartitionController controller)
+ {
+ super(new BorderLayout());
+
+ setBorder(BorderFactory.createTitledBorder(""));
+
+ this.devicePartitions = devicePartitions;
+ this.controller = controller;
+
+ JPanel devPanel = new JPanel(new BorderLayout());
+ devPanel.add(new JLabel("device : "), BorderLayout.WEST);
+ devPanel.add(cboDevices, BorderLayout.CENTER);
+ add(devPanel, BorderLayout.NORTH);
+
+ add(partitionsPanel, BorderLayout.CENTER);
+
+ for(DeviceModel devParts : devicePartitions)
+ {
+ cboDevicesModel.addElement(devParts);
+ }
+
+ if(cboDevicesModel.getSize() > 0)
+ {
+ cboDevices.setSelectedIndex(0);
+ }
+
+ cboDevices.addItemListener(new ItemListener()
+ {
+ public void itemStateChanged(ItemEvent event) {
+ if(event.getStateChange() == ItemEvent.SELECTED)
+ {
+ log.debug("itemStateChanged");
+ DeviceModel devParts = (DeviceModel) event.getItem();
+ partitionsPanel.removeAll();
+
+ if(devParts.getPartitions().isEmpty())
+ {
+ DiskAreaUI disk = new DiskAreaUI(DevicePartitionsUI.this.controller.getCommandProcessor(), devParts.getDevice());
+ disk.setLabel("disk not partitioned");
+ partitionsPanel.add(disk);
+ }
+ else
+ {
+ for(PartitionModel partition : devParts.getPartitions())
+ {
+ partitionsPanel.add(new PartitionUI(DevicePartitionsUI.this.controller.getCommandProcessor(), devParts.getDevice(), partition));
+ }
+ }
+ }
+ }
+ });
+ }
+
+ public void deviceAdded(DeviceModel devParts) {
+ log.debug("deviceAdded");
+ cboDevicesModel.addElement(devParts);
+ }
+
+ public void deviceRemoved(DeviceModel devParts) {
+ cboDevicesModel.removeElement(devParts);
+ }
+*/
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,85 @@
+package org.jnode.apps.jpartition.swingview;
+
+import java.awt.Color;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import org.jnode.apps.jpartition.controller.MainController;
+
+public class DiskAreaView extends JPanel
+{
+ final protected MainController controller;
+
+ final protected JLabel lblInfos = new JLabel();
+
+ public DiskAreaView(MainController controller)
+ {
+ this.controller = controller;
+
+ setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
+ lblInfos.setBackground(Color.CYAN);
+ add(lblInfos);
+
+ addMouseListener(new MouseAdapter()
+ {
+ @Override
+ public void mousePressed(MouseEvent event) {
+ showMenu(event);
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent event) {
+ showMenu(event);
+ }
+ });
+ }
+/*
+ final private CommandProcessor commandProcessor;
+ final private Device device;
+
+ public DiskAreaView(CommandProcessor commandProcessor, Device device)
+ {
+ this.commandProcessor = commandProcessor;
+ this.device = device;
+
+ setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
+ lblInfos.setBackground(Color.CYAN);
+ add(lblInfos);
+
+ addMouseListener(new MouseAdapter()
+ {
+ @Override
+ public void mousePressed(MouseEvent event) {
+ showMenu(event);
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent event) {
+ showMenu(event);
+ }
+ });
+ }
+
+ public void setLabel(String label)
+ {
+ lblInfos.setText(label);
+ }
+*/
+
+ protected void showMenu(MouseEvent event)
+ {
+ //TODO add popup menu
+/*
+ if(event.isPopupTrigger())
+ {
+ JPopupMenu menu = new JPopupMenu("context menu");
+ menu.add(new JMenuItem(new InitMbrAction((IDEDevice) device, commandProcessor)));
+ menu.show(event.getComponent(), event.getX(), event.getY());
+ }
+*/
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,39 @@
+package org.jnode.apps.jpartition.swingview;
+
+import org.apache.log4j.Logger;
+
+import charva.awt.Component;
+import charvax.swing.JOptionPane;
+
+public class ErrorReporter {
+ public static void reportError(Logger log, Object source, Throwable t)
+ {
+ reportError(log, source, (Object) t);
+ }
+
+ public static void reportError(Logger log, Object source, String message)
+ {
+ reportError(log, source, (Object) message);
+ }
+
+ private static void reportError(Logger log, Object source, Object message)
+ {
+ Component parent = (source instanceof Component) ? (Component) source : null;
+ Throwable t = (message instanceof Throwable) ? (Throwable) message : null;
+
+ String msg = (t == null) ? String.valueOf(message) : t.getMessage();
+ JOptionPane.showMessageDialog(parent,
+ "an error happened : "+msg+"\nSee logs for details",
+ "error",
+ JOptionPane.ERROR_MESSAGE);
+
+ if(t != null)
+ {
+ log.error(msg, t);
+ }
+ else
+ {
+ log.error(msg);
+ }
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,81 @@
+package org.jnode.apps.jpartition.swingview;
+
+import it.battlehorse.stamps.annotations.ModelDependent;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.AbstractListModel;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.controller.MainController;
+
+public class FileDeviceView extends JFrame
+{
+ private static final Logger log = Logger.getLogger(FileDeviceView.class);
+
+ private JList devicesList = new JList(new DefaultListModel());
+ private JPanel buttons = new JPanel();
+ private JButton addVMWareDiskButton = new JButton("add VMWare disk");
+ private JButton addFakeDiskButton = new JButton("add fake disk");
+ private JButton removeButton = new JButton("remove device");
+ final private MainController controller;
+
+ public FileDeviceView(MainController controller) throws Exception
+ {
+ this.controller = controller;
+
+ setTitle("File devices");
+ setLayout(new BorderLayout());
+ add(new JScrollPane(devicesList), BorderLayout.CENTER);
+ add(buttons, BorderLayout.SOUTH);
+
+ buttons.add(addVMWareDiskButton);
+ buttons.add(addFakeDiskButton);
+ buttons.add(removeButton);
+
+ addFakeDiskButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event) {
+ FileDeviceView.this.controller.userAddFakeDisk();
+ }
+ });
+ addVMWareDiskButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event) {
+ FileDeviceView.this.controller.userAddVMWareDisk();
+ }
+ });
+ removeButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event) {
+ if(devicesList.getSelectedIndex() >= 0)
+ {
+ Object value = devicesList.getSelectedValue();
+ FileDeviceView.this.controller.userRemoveFileDevice(value);
+ }
+ }
+ });
+
+ setSize(600, 300);
+ setVisible(true);
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ }
+
+ @ModelDependent(modelKey ="FileDeviceModel" , propertyKey = "deviceAdded")
+ public void addDevice(Object device) {
+ ((DefaultListModel) devicesList.getModel()).addElement(device);
+ }
+
+ @ModelDependent(modelKey ="FileDeviceModel" , propertyKey = "deviceRemoved")
+ public void removeDevice(Object device) {
+ ((DefaultListModel) devicesList.getModel()).removeElement(device);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,76 @@
+package org.jnode.apps.jpartition.swingview;
+
+import it.battlehorse.stamps.annotations.ModelDependent;
+
+import java.awt.BorderLayout;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.controller.MainController;
+
+public class MainView extends JFrame {
+ private static final Logger log = Logger.getLogger(DeviceView.class);
+
+ final private MainController controller;
+ final private DefaultComboBoxModel devices;
+ final private DeviceView deviceView;
+
+ public MainView(MainController controller,
+ JFrame fileDeviceView,
+ JComponent cmdProcessorView) throws Exception
+ {
+ this.controller = controller;
+
+ setTitle("JPartition");
+ setLayout(new BorderLayout());
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ add(cmdProcessorView, BorderLayout.SOUTH);
+
+ deviceView = new DeviceView(controller);
+ add(deviceView, BorderLayout.CENTER);
+
+ devices = new DefaultComboBoxModel();
+ JComboBox cboDevices = new JComboBox(devices);
+ cboDevices.addItemListener(new ItemListener()
+ {
+ public void itemStateChanged(ItemEvent event) {
+ boolean selected = (event.getStateChange() == ItemEvent.SELECTED);
+ if(selected)
+ {
+ MainView.this.controller.userSelectDevice(event.getItem());
+ }
+ }
+ });
+ add(cboDevices, BorderLayout.NORTH);
+
+ setSize(600, 300);
+ setVisible(true);
+ setLocation(fileDeviceView.getX(), fileDeviceView.getY() + fileDeviceView.getHeight());
+ }
+
+ @ModelDependent(modelKey ="DeviceModel" , propertyKey = "deviceStarted")
+ public void deviceStarted(Object device) {
+ log.debug("deviceStarted");
+ devices.addElement(device);
+ }
+
+ @ModelDependent(modelKey ="DeviceModel" , propertyKey = "deviceStop")
+ public void deviceStop(Object device) {
+ log.debug("deviceStop");
+ devices.removeElement(device);
+ }
+
+ @ModelDependent(modelKey ="DeviceModel" , propertyKey = "deviceSelected")
+ public void deviceSelected(Object device) {
+ log.debug("deviceSelected");
+ //TODO
+ //deviceView.init(device);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,83 @@
+package org.jnode.apps.jpartition.swingview;
+
+import it.battlehorse.stamps.annotations.ModelDependent;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.controller.MainController;
+import org.jnode.partitions.ibm.IBMPartitionTypes;
+
+public class PartitionView extends DiskAreaView
+{
+ private static final Logger log = Logger.getLogger(PartitionView.class);
+
+ private DeviceView deviceView;
+
+ public PartitionView(MainController controller, DeviceView deviceView)
+ {
+ super(controller);
+
+ this.deviceView = deviceView;
+ }
+
+ @ModelDependent(modelKey = "partition", propertyKey = "empty")
+ public void setEmpty(boolean empty) {
+ lblInfos.setText(empty ? "empty" : "");
+ }
+
+ @ModelDependent(modelKey = "partition", propertyKey = "bootable")
+ public void setBootable(boolean bootable) {
+ lblInfos.setText(bootable ? "B" : "");
+ }
+
+ @ModelDependent(modelKey = "partition", propertyKey = "type")
+ public void setType(IBMPartitionTypes type) {
+ lblInfos.setText(type.getName());
+ }
+
+ @ModelDependent(modelKey = "partition", propertyKey = "start")
+ public void setStart(long start) {
+
+ }
+
+ @ModelDependent(modelKey = "partition", propertyKey = "size")
+ public void setSize(long size) {
+ }
+
+/*
+ public PartitionModel getPartition() {
+ return partition;
+ }
+
+ public void setPartition(PartitionModel partition) {
+ if(this.partition != partition)
+ {
+ this.partition = partition;
+ refreshFromModel();
+ }
+ }
+
+ public void refreshFromModel()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ String name = partition.getType().getName();
+ log.debug("refreshFromModel: name="+name);
+ if(name.length() > 10)
+ {
+ name = name.substring(0, 10);
+ }
+ String boot = partition.isBootable() ? "(B)" : "(-)";
+ log.debug("refreshFromModel: boot="+boot);
+
+ sb.append(boot).append(name);
+ if(!partition.isEmpty())
+ {
+ sb.append("-").append(partition.getStart());
+ sb.append("-").append(partition.getSize());
+ }
+ lblInfos.setText(sb.toString());
+
+ log.debug("refreshFromModel: description="+sb.toString());
+ }
+*/
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,24 @@
+package org.jnode.apps.jpartition.swingview;
+
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+
+import org.jnode.apps.jpartition.ViewFactory;
+import org.jnode.apps.jpartition.controller.MainController;
+
+public class SwingViewFactory implements ViewFactory {
+ public Object createDeviceView(MainController controller,
+ Object fileDeviceView, Object cmdProcessorView) throws Exception
+ {
+ return new MainView(controller, (JFrame)fileDeviceView, (JComponent)cmdProcessorView);
+ }
+
+ public Object createFileDeviceView(MainController controller) throws Exception
+ {
+ return new FileDeviceView(controller);
+ }
+
+ public Object createCommandProcessorView(MainController mainController) {
+ return new CommandProcessorView(mainController);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,54 @@
+package org.jnode.apps.jpartition.swingview.actions;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Icon;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.commands.BaseDeviceCommand;
+import org.jnode.apps.jpartition.commands.framework.Command;
+import org.jnode.apps.jpartition.commands.framework.CommandProcessor;
+import org.jnode.apps.jpartition.swingview.ErrorReporter;
+import org.jnode.driver.bus.ide.IDEDevice;
+
+abstract public class BaseDeviceAction extends AbstractAction
+{
+ private static final Logger log = Logger.getLogger(BaseDeviceAction.class);
+
+ final protected CommandProcessor processor;
+ final protected IDEDevice device;
+
+ public BaseDeviceAction(IDEDevice device, CommandProcessor processor) {
+ super();
+ this.processor = processor;
+ this.device = device;
+ }
+
+ public BaseDeviceAction(IDEDevice device, CommandProcessor processor, String name, Icon icon) {
+ super(name, icon);
+ this.processor = processor;
+ this.device = device;
+ }
+
+ public BaseDeviceAction(IDEDevice device, CommandProcessor processor, String name) {
+ super(name);
+ this.processor = processor;
+ this.device = device;
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ try
+ {
+ Command command = getCommand(device);
+ processor.addCommand(command);
+ }
+ catch(Throwable t)
+ {
+ ErrorReporter.reportError(log, this, t);
+ }
+ }
+
+ abstract protected BaseDeviceCommand getCommand(IDEDevice device);
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,18 @@
+package org.jnode.apps.jpartition.swingview.actions;
+
+import org.jnode.apps.jpartition.commands.BaseDeviceCommand;
+import org.jnode.apps.jpartition.commands.InitMbrCommand;
+import org.jnode.apps.jpartition.commands.framework.CommandProcessor;
+import org.jnode.driver.bus.ide.IDEDevice;
+
+public class InitMbrAction extends BaseDeviceAction
+{
+ public InitMbrAction(IDEDevice device, CommandProcessor processor) {
+ super(device, processor, "init MBR");
+ }
+
+ @Override
+ protected BaseDeviceCommand getCommand(IDEDevice device) {
+ return new InitMbrCommand(device);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 21:20:18
|
Revision: 3165
http://jnode.svn.sourceforge.net/jnode/?rev=3165&view=rev
Author: fduminy
Date: 2007-04-15 14:20:05 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDevice.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDeviceDriver.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,35 @@
+/**
+ *
+ */
+package org.jnode.apps.jpartition.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jnode.naming.NameSpace;
+
+public final class BasicNameSpace implements NameSpace {
+ protected final Map<Class<?>, Object> namespace = new HashMap<Class<?>, Object>();
+
+ public <T> void bind(Class<T> name, T service)
+ throws NamingException, NameAlreadyBoundException {
+ namespace.put(name, service);
+ }
+
+ public <T> T lookup(Class<T> name) throws NameNotFoundException {
+ return (T) namespace.get(name);
+ }
+
+ public Set<Class<?>> nameSet() {
+ return namespace.keySet();
+ }
+
+ public void unbind(Class<?> name) {
+ namespace.remove(name);
+ }
+}
\ No newline at end of file
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,49 @@
+package org.jnode.apps.jpartition.utils.device;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import javax.naming.NameNotFoundException;
+
+import org.jnode.driver.DriverException;
+import org.jnode.driver.block.PartitionableBlockDeviceAPI;
+import org.jnode.driver.bus.ide.IDEConstants;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.PartitionTable;
+import org.jnode.partitions.ibm.IBMPartitionTable;
+import org.jnode.partitions.ibm.IBMPartitionTableType;
+
+abstract public class AbstractIDEDevice extends IDEDevice
+ implements PartitionableBlockDeviceAPI
+{
+ protected PartitionTable pt;
+
+ public AbstractIDEDevice(String name,
+ boolean primary, boolean master)
+ {
+ super(null, primary, master, name, null, null);
+ }
+
+ public PartitionTable getPartitionTable() throws IOException {
+ return pt;
+ }
+
+ public int getSectorSize() throws IOException {
+ return IDEConstants.SECTOR_SIZE;
+ }
+
+ protected PartitionTable buildPartitionTable() throws DriverException,
+ IOException, NameNotFoundException
+ {
+ // Read the bootsector
+ final byte[] bs = new byte[IDEConstants.SECTOR_SIZE];
+ read(0, ByteBuffer.wrap(bs));
+
+ return new IBMPartitionTable(new IBMPartitionTableType(), bs, this);
+ }
+
+ public String toString()
+ {
+ return getId();
+ }
+}
\ No newline at end of file
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,154 @@
+package org.jnode.apps.jpartition.utils.device;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.naming.NameNotFoundException;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.swingview.ErrorReporter;
+import org.jnode.apps.jpartition.swingview.FileDeviceView;
+import org.jnode.apps.vmware.disk.VMWareDisk;
+import org.jnode.apps.vmware.disk.tools.DiskFactory;
+import org.jnode.driver.ApiNotFoundException;
+import org.jnode.driver.Device;
+import org.jnode.driver.DeviceAlreadyRegisteredException;
+import org.jnode.driver.DeviceManager;
+import org.jnode.driver.DeviceNotFoundException;
+import org.jnode.driver.DriverException;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.command.PartitionHelper;
+import org.jnode.partitions.ibm.IBMPartitionTypes;
+
+public class DeviceUtils {
+ private static final long DEFAULT_FILE_SIZE = 1000;
+ private static final Logger log = Logger.getLogger(FileDeviceView.class);
+
+ public static IDEDevice createFakeDevice()
+ {
+ IDEDevice device = null;
+ try
+ {
+ String name = findUnusedName("fake");
+ FakeIDEDevice fd = new FakeIDEDevice(name, true, true, 1024000);
+ if(addDevice(fd))
+ {
+ device = fd;
+ }
+ else
+ {
+ ErrorReporter.reportError(log, DeviceUtils.class.getName(), "failed to add device");
+ }
+ } catch (Exception e) {
+ log.error(e);
+ }
+
+ return device;
+ }
+
+ public static IDEDevice createVMWareDevice() {
+ IDEDevice device = null;
+
+ try
+ {
+ AbstractIDEDevice fd = createDevice();
+ if(addDevice(fd))
+ {
+ device = fd;
+ }
+ else
+ {
+ ErrorReporter.reportError(log, DeviceUtils.class.getName(), "failed to add device");
+ }
+ } catch (Exception e) {
+ log.error(e);
+ }
+
+ return device;
+ }
+
+ public static AbstractIDEDevice createDevice() throws Exception
+ {
+ File tmpFile = File.createTempFile("disk", "");
+ File directory = tmpFile.getParentFile();
+ String name = tmpFile.getName();
+
+ File mainFile = DiskFactory.createSparseDisk(directory, name, DEFAULT_FILE_SIZE);
+ VMWareDisk vmwareDisk = new VMWareDisk(mainFile);
+
+ AbstractIDEDevice dev = new FileIDEDevice(name,
+ true, true, vmwareDisk);
+ return dev;
+ }
+
+ public static void restart(Device device)
+ {
+ DeviceManager devMan;
+ try {
+ devMan = org.jnode.driver.DeviceUtils.getDeviceManager();
+
+ devMan.stop(device);
+ devMan.start(device);
+ } catch (NameNotFoundException e) {
+ log.error(e);
+ } catch (DeviceNotFoundException e) {
+ log.error(e);
+ } catch (DriverException e) {
+ log.error(e);
+ }
+ }
+
+ public static boolean addDevice(AbstractIDEDevice device)
+ {
+ boolean success = false;
+ try
+ {
+ DeviceManager devMan = org.jnode.driver.DeviceUtils.getDeviceManager();
+ devMan.register(device);
+ success = true;
+
+ PartitionHelper helper = new PartitionHelper(device);
+ helper.initMbr();
+ helper.write();
+ if(helper.hasValidMBR())
+ {
+ helper.modifyPartition(0, true, 0, DEFAULT_FILE_SIZE,
+ false, IBMPartitionTypes.PARTTYPE_WIN95_FAT32);
+ }
+ } catch (NameNotFoundException e) {
+ log.error(e);
+ } catch (DeviceAlreadyRegisteredException e) {
+ log.error(e);
+ } catch (DriverException e) {
+ log.error(e);
+ } catch (DeviceNotFoundException e) {
+ log.error(e);
+ } catch (ApiNotFoundException e) {
+ log.error(e);
+ } catch (IOException e) {
+ log.error(e);
+ }
+
+ return success;
+ }
+
+ public static String findUnusedName(String baseName) throws NameNotFoundException
+ {
+ DeviceManager devMan = org.jnode.driver.DeviceUtils.getDeviceManager();
+ String name = null;
+ int i = 0;
+ do
+ {
+ String newName = baseName + "-" + i;
+ try {
+ devMan.getDevice(newName);
+ i++;
+ } catch (DeviceNotFoundException e) {
+ name = newName;
+ }
+ }
+ while(name == null);
+
+ return name;
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,57 @@
+package org.jnode.apps.jpartition.utils.device;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jnode.apps.vmware.disk.VMWareDisk;
+import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
+import org.jnode.apps.vmware.disk.tools.DiskFactory;
+import org.jnode.driver.DeviceManager;
+import org.jnode.driver.DriverException;
+import org.jnode.driver.block.BlockDeviceAPIHelper;
+import org.jnode.driver.block.PartitionableBlockDeviceAPI;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.driver.bus.ide.IDEDeviceFactory;
+import org.jnode.driver.bus.ide.IDEDriverUtils;
+import org.jnode.naming.InitialNaming;
+
+public class FakeIDEDevice extends AbstractIDEDevice implements PartitionableBlockDeviceAPI
+{
+ private final long length;
+ public FakeIDEDevice(String name,
+ boolean primary, boolean master,
+ long length)
+ throws IOException, DriverException, NameNotFoundException, UnsupportedFormatException
+ {
+ super(name, primary, master);
+ this.length = length;
+
+ registerAPI(PartitionableBlockDeviceAPI.class, this);
+
+ setDriver(new FileIDEDeviceDriver());
+
+ pt = buildPartitionTable();
+ }
+
+ public void flush() throws IOException {
+ }
+
+ public long getLength() throws IOException {
+ return length;
+ }
+
+ public void read(long devOffset, ByteBuffer destBuf) throws IOException {
+ while(destBuf.remaining() > 0)
+ {
+ destBuf.put((byte) 0);
+ }
+ }
+
+ public void write(long devOffset, ByteBuffer srcBuf) throws IOException {
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDevice.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDevice.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDevice.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,61 @@
+package org.jnode.apps.jpartition.utils.device;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jnode.apps.vmware.disk.VMWareDisk;
+import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
+import org.jnode.apps.vmware.disk.tools.DiskFactory;
+import org.jnode.driver.DeviceManager;
+import org.jnode.driver.DriverException;
+import org.jnode.driver.block.BlockDeviceAPIHelper;
+import org.jnode.driver.block.PartitionableBlockDeviceAPI;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.driver.bus.ide.IDEDeviceFactory;
+import org.jnode.driver.bus.ide.IDEDriverUtils;
+import org.jnode.naming.InitialNaming;
+
+public class FileIDEDevice extends AbstractIDEDevice implements PartitionableBlockDeviceAPI
+{
+ private VMWareDisk vmwareDisk;
+
+ public FileIDEDevice(String name,
+ boolean primary, boolean master,
+ VMWareDisk vmwareDisk)
+ throws IOException, DriverException, NameNotFoundException, UnsupportedFormatException
+ {
+ super(name, primary, master);
+ registerAPI(PartitionableBlockDeviceAPI.class, this);
+
+ this.vmwareDisk = vmwareDisk;
+
+ setDriver(new FileIDEDeviceDriver());
+
+ pt = buildPartitionTable();
+ }
+
+ public void flush() throws IOException {
+ vmwareDisk.flush();
+ }
+
+ public long getLength() throws IOException {
+ return vmwareDisk.getLength();
+ }
+
+ public void read(long devOffset, ByteBuffer destBuf) throws IOException {
+ BlockDeviceAPIHelper.checkBounds(this, devOffset, destBuf.remaining());
+
+ vmwareDisk.read(devOffset, destBuf);
+ }
+
+ public void write(long devOffset, ByteBuffer srcBuf) throws IOException {
+ BlockDeviceAPIHelper.checkBounds(this, devOffset, srcBuf.remaining());
+
+ vmwareDisk.write(devOffset, srcBuf);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDeviceDriver.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDeviceDriver.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDeviceDriver.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,32 @@
+package org.jnode.apps.jpartition.utils.device;
+
+import org.jnode.driver.Driver;
+import org.jnode.driver.DriverException;
+import org.jnode.driver.DeviceAlreadyRegisteredException;
+import org.jnode.driver.bus.ide.IDEDevice;
+
+/**
+ *
+ * @author Fabien DUMINY (fduminy at jnode.org)
+ *
+ */
+public class FileIDEDeviceDriver extends Driver {
+ /**
+ * Start the device.
+ *
+ * @throws org.jnode.driver.DriverException
+ *
+ */
+ protected void startDevice() throws DriverException {
+ }
+
+ /**
+ * Stop the device.
+ *
+ * @throws org.jnode.driver.DriverException
+ *
+ */
+ protected void stopDevice() throws DriverException {
+
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2008-01-05 08:50:18
|
Revision: 3684
http://jnode.svn.sourceforge.net/jnode/?rev=3684&view=rev
Author: fduminy
Date: 2008-01-05 00:50:17 -0800 (Sat, 05 Jan 2008)
Log Message:
-----------
build fix
Removed Paths:
-------------
trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java 2008-01-04 17:38:02 UTC (rev 3683)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java 2008-01-05 08:50:17 UTC (rev 3684)
@@ -1,90 +0,0 @@
-package org.jnode.apps.jpartition.controller;
-
-import it.battlehorse.stamps.Dispatcher;
-import it.battlehorse.stamps.factories.DispatcherRegistry;
-import it.battlehorse.stamps.factories.TransformerRegistry;
-import org.jnode.apps.jpartition.ViewFactory;
-import org.jnode.apps.jpartition.model.CommandProcessorModel;
-import org.jnode.apps.jpartition.model.DeviceModel;
-import org.jnode.apps.jpartition.model.FileDeviceModel;
-
-public class MainController
-{
- final private DeviceModel deviceModel;
- final private FileDeviceModel fileDeviceModel;
- final private CommandProcessorModel cmdProcessorModel;
-
- public MainController(ViewFactory viewFactory) throws Exception
- {
- TransformerRegistry.getInstance().loadTransformers();
- Dispatcher dispatcher = DispatcherRegistry.getInstance().getBasicDispatcher();
-
- // FileDevice
- this.fileDeviceModel = new FileDeviceModel();
- Object fileDeviceView = viewFactory.createFileDeviceView(this);
-
- dispatcher.registerModel("FileDeviceModel",fileDeviceModel);
- dispatcher.registerView("FileDeviceModel",fileDeviceView,true);
-
- // CommandProcessor
- this.cmdProcessorModel = new CommandProcessorModel();
- Object cmdProcessorView = viewFactory.createCommandProcessorView(this);
-
- dispatcher.registerModel("CommandProcessorModel",cmdProcessorModel);
- dispatcher.registerView("CommandProcessorModel",cmdProcessorView,true);
-
- // Device
- this.deviceModel = new DeviceModel();
- Object deviceView = viewFactory.createDeviceView(this, fileDeviceView, cmdProcessorView);
-
- dispatcher.registerModel("DeviceModel",deviceModel);
- dispatcher.registerView("DeviceModel",deviceView,true);
- }
-
-/*
- final private DeviceModel model;
-
- public DeviceController(DeviceModel model)
- {
- this.model = model;
- }
-
-
- public static DeviceModel getDevicePartitions()
- {
- DeviceModel devParts = new DeviceModel();
- try {
- org.jnode.driver.DeviceManager devMan = org.jnode.driver.DeviceUtils.getDeviceManager();
- Collection<Device> devices = devMan.getDevicesByAPI(PartitionableBlockDeviceAPI.class);
- for(Device device : devices)
- {
- devParts.add(new DeviceModel((IDEDevice) device));
- }
- } catch (NameNotFoundException e) {
- log.error(e);
- }
- return devParts;
- }
-*/
-
-
- public void userAddFakeDisk() {
- fileDeviceModel.addFakeDisk();
- }
-
- public void userAddVMWareDisk() {
- fileDeviceModel.addVMWareDisk();
- }
-
- public void userRemoveFileDevice(Object device) {
- fileDeviceModel.removeFileDevice(device);
- }
-
- public void userProcessCommands() {
- cmdProcessorModel.processCommands();
- }
-
- public void userSelectDevice(Object device) {
- deviceModel.setDevice(device);
- }
-}
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java 2008-01-04 17:38:02 UTC (rev 3683)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java 2008-01-05 08:50:17 UTC (rev 3684)
@@ -1,93 +0,0 @@
-package org.jnode.apps.jpartition.swingview;
-
-import it.battlehorse.stamps.annotations.ModelDependent;
-import javax.swing.*;
-import org.apache.log4j.Logger;
-import org.jnode.apps.jpartition.controller.MainController;
-
-public class DeviceView extends JPanel
-{
- private static final Logger log = Logger.getLogger(DeviceView.class);
-
- final private MainController controller;
-
- //final private Object device;
-
- public DeviceView(MainController controller)
- {
- this.controller = controller;
- }
-
-/*
- private static final Logger log = Logger.getLogger(DevicePartitionsUI.class);
-
- final private DevicePartitionsList devicePartitions;
-
- final private DefaultComboBoxModel cboDevicesModel = new DefaultComboBoxModel();
- final private JComboBox cboDevices = new JComboBox(cboDevicesModel);
- final private JPanel partitionsPanel = new JPanel(new FlowLayout());
- final private PartitionController controller;
-
- public DevicePartitionsUI(DevicePartitionsList devicePartitions, PartitionController controller)
- {
- super(new BorderLayout());
-
- setBorder(BorderFactory.createTitledBorder(""));
-
- this.devicePartitions = devicePartitions;
- this.controller = controller;
-
- JPanel devPanel = new JPanel(new BorderLayout());
- devPanel.add(new JLabel("device : "), BorderLayout.WEST);
- devPanel.add(cboDevices, BorderLayout.CENTER);
- add(devPanel, BorderLayout.NORTH);
-
- add(partitionsPanel, BorderLayout.CENTER);
-
- for(DeviceModel devParts : devicePartitions)
- {
- cboDevicesModel.addElement(devParts);
- }
-
- if(cboDevicesModel.getSize() > 0)
- {
- cboDevices.setSelectedIndex(0);
- }
-
- cboDevices.addItemListener(new ItemListener()
- {
- public void itemStateChanged(ItemEvent event) {
- if(event.getStateChange() == ItemEvent.SELECTED)
- {
- log.debug("itemStateChanged");
- DeviceModel devParts = (DeviceModel) event.getItem();
- partitionsPanel.removeAll();
-
- if(devParts.getPartitions().isEmpty())
- {
- DiskAreaUI disk = new DiskAreaUI(DevicePartitionsUI.this.controller.getCommandProcessor(), devParts.getDevice());
- disk.setLabel("disk not partitioned");
- partitionsPanel.add(disk);
- }
- else
- {
- for(PartitionModel partition : devParts.getPartitions())
- {
- partitionsPanel.add(new PartitionUI(DevicePartitionsUI.this.controller.getCommandProcessor(), devParts.getDevice(), partition));
- }
- }
- }
- }
- });
- }
-
- public void deviceAdded(DeviceModel devParts) {
- log.debug("deviceAdded");
- cboDevicesModel.addElement(devParts);
- }
-
- public void deviceRemoved(DeviceModel devParts) {
- cboDevicesModel.removeElement(devParts);
- }
-*/
-}
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java 2008-01-04 17:38:02 UTC (rev 3683)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java 2008-01-05 08:50:17 UTC (rev 3684)
@@ -1,38 +0,0 @@
-package org.jnode.apps.jpartition.swingview;
-
-import charva.awt.Component;
-import charvax.swing.JOptionPane;
-import org.apache.log4j.Logger;
-
-public class ErrorReporter {
- public static void reportError(Logger log, Object source, Throwable t)
- {
- reportError(log, source, (Object) t);
- }
-
- public static void reportError(Logger log, Object source, String message)
- {
- reportError(log, source, (Object) message);
- }
-
- private static void reportError(Logger log, Object source, Object message)
- {
- Component parent = (source instanceof Component) ? (Component) source : null;
- Throwable t = (message instanceof Throwable) ? (Throwable) message : null;
-
- String msg = (t == null) ? String.valueOf(message) : t.getMessage();
- JOptionPane.showMessageDialog(parent,
- "an error happened : "+msg+"\nSee logs for details",
- "error",
- JOptionPane.ERROR_MESSAGE);
-
- if(t != null)
- {
- log.error(msg, t);
- }
- else
- {
- log.error(msg);
- }
- }
-}
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java 2008-01-04 17:38:02 UTC (rev 3683)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java 2008-01-05 08:50:17 UTC (rev 3684)
@@ -1,70 +0,0 @@
-package org.jnode.apps.jpartition.swingview;
-
-import it.battlehorse.stamps.annotations.ModelDependent;
-import java.awt.*;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import javax.swing.*;
-import org.apache.log4j.Logger;
-import org.jnode.apps.jpartition.controller.MainController;
-
-public class MainView extends JFrame {
- private static final Logger log = Logger.getLogger(DeviceView.class);
-
- final private MainController controller;
- final private DefaultComboBoxModel devices;
- final private DeviceView deviceView;
-
- public MainView(MainController controller,
- JFrame fileDeviceView,
- JComponent cmdProcessorView) throws Exception
- {
- this.controller = controller;
-
- setTitle("JPartition");
- setLayout(new BorderLayout());
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- add(cmdProcessorView, BorderLayout.SOUTH);
-
- deviceView = new DeviceView(controller);
- add(deviceView, BorderLayout.CENTER);
-
- devices = new DefaultComboBoxModel();
- JComboBox cboDevices = new JComboBox(devices);
- cboDevices.addItemListener(new ItemListener()
- {
- public void itemStateChanged(ItemEvent event) {
- boolean selected = (event.getStateChange() == ItemEvent.SELECTED);
- if(selected)
- {
- MainView.this.controller.userSelectDevice(event.getItem());
- }
- }
- });
- add(cboDevices, BorderLayout.NORTH);
-
- setSize(600, 300);
- setVisible(true);
- setLocation(fileDeviceView.getX(), fileDeviceView.getY() + fileDeviceView.getHeight());
- }
-
- @ModelDependent(modelKey ="DeviceModel" , propertyKey = "deviceStarted")
- public void deviceStarted(Object device) {
- log.debug("deviceStarted");
- devices.addElement(device);
- }
-
- @ModelDependent(modelKey ="DeviceModel" , propertyKey = "deviceStop")
- public void deviceStop(Object device) {
- log.debug("deviceStop");
- devices.removeElement(device);
- }
-
- @ModelDependent(modelKey ="DeviceModel" , propertyKey = "deviceSelected")
- public void deviceSelected(Object device) {
- log.debug("deviceSelected");
- //TODO
- //deviceView.init(device);
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2008-01-05 08:51:31
|
Revision: 3685
http://jnode.svn.sourceforge.net/jnode/?rev=3685&view=rev
Author: fduminy
Date: 2008-01-05 00:51:26 -0800 (Sat, 05 Jan 2008)
Log Message:
-----------
build fix
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java 2008-01-05 08:51:26 UTC (rev 3685)
@@ -0,0 +1,59 @@
+package org.jnode.apps.jpartition.controller;
+
+import org.jnode.apps.jpartition.ErrorReporter;
+import org.jnode.apps.jpartition.ViewFactory;
+
+public class MainController
+{
+ final private ErrorReporter errorReporter;
+
+ @SuppressWarnings("unchecked")
+ public MainController(ViewFactory viewFactory) throws Exception
+ {
+ errorReporter = viewFactory.createErrorReporter();
+
+ //support.addEventListener()
+ //dispatcher.registerModel("FileDeviceModel",fileDeviceModel);
+ //dispatcher.registerView("FileDeviceModel",fileDeviceView,true);
+
+ // CommandProcessor
+ Object cmdProcessorView = viewFactory.createCommandProcessorView();
+
+ // Device
+ Object deviceView = viewFactory.createDeviceView(cmdProcessorView);
+
+ //support.addEventListener()
+ //dispatcher.registerModel("DeviceModel",deviceModel);
+ //dispatcher.registerView("DeviceModel",deviceView,true);
+ }
+
+/*
+ final private DeviceModel model;
+
+ public DeviceController(DeviceModel model)
+ {
+ this.model = model;
+ }
+
+
+ public static DeviceModel getDevicePartitions()
+ {
+ DeviceModel devParts = new DeviceModel();
+ try {
+ org.jnode.driver.DeviceManager devMan = org.jnode.driver.DeviceUtils.getDeviceManager();
+ Collection<Device> devices = devMan.getDevicesByAPI(PartitionableBlockDeviceAPI.class);
+ for(Device device : devices)
+ {
+ devParts.add(new DeviceModel((IDEDevice) device));
+ }
+ } catch (NameNotFoundException e) {
+ log.error(e);
+ }
+ return devParts;
+ }
+*/
+
+// public void userProcessCommands() {
+// cmdProcessorModel.processCommands();
+// }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java 2008-01-05 08:51:26 UTC (rev 3685)
@@ -0,0 +1,76 @@
+package org.jnode.apps.jpartition.swingview;
+
+import java.awt.Color;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+
+import javax.swing.Action;
+import javax.swing.JLabel;
+
+import org.jnode.apps.jpartition.model.Device;
+import org.jnode.apps.jpartition.model.Partition;
+import org.jnode.apps.jpartition.model.UserFacade;
+
+public class DeviceView extends DiskAreaView
+{
+ public DeviceView()
+ {
+ super(Color.GREEN);
+ setLayout(null);
+ update();
+
+ addComponentListener(new ComponentListener(){
+
+ public void componentHidden(ComponentEvent e) {
+ update();
+ }
+
+ public void componentMoved(ComponentEvent e) {
+ update();
+ }
+
+ public void componentResized(ComponentEvent e) {
+ update();
+ }
+
+ public void componentShown(ComponentEvent e) {
+ update();
+ }});
+ }
+
+ public void update() {
+ removeAll();
+ Device device = UserFacade.getInstance().getSelectedDevice();
+ if(device == null)
+ {
+ add(new JLabel("no partition"));
+ }
+ else
+ {
+ final int space = 10;
+ double x = 0;
+ double pixelsPerByte = (double) getWidth() / (double) device.getSize();
+ for(Partition partition : device.getPartitions())
+ {
+ PartitionView p = new PartitionView(this, partition);
+ //JLabel p = new JLabel("test");
+
+ double size = pixelsPerByte * partition.getSize();
+ p.setBounds((int) x+space, 0+space, (int) size-2*space, getHeight()-2*space);
+ add(p);
+ p.update();
+
+ x += size;
+ }
+ repaint();
+ }
+ }
+
+ @Override
+ protected Action[] getActions() {
+ //return new Action[]{
+ // new AddPartitionAction()
+ // };
+ return null;
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java 2008-01-05 08:51:26 UTC (rev 3685)
@@ -0,0 +1,39 @@
+package org.jnode.apps.jpartition.swingview;
+
+import org.apache.log4j.Logger;
+
+import java.awt.Component;
+import javax.swing.JOptionPane;
+
+public class ErrorReporter implements org.jnode.apps.jpartition.ErrorReporter {
+ public void reportError(Logger log, Object source, Throwable t)
+ {
+ reportError(log, source, (Object) t);
+ }
+
+ public void reportError(Logger log, Object source, String message)
+ {
+ reportError(log, source, (Object) message);
+ }
+
+ private static void reportError(Logger log, Object source, Object message)
+ {
+ Component parent = (source instanceof Component) ? (Component) source : null;
+ Throwable t = (message instanceof Throwable) ? (Throwable) message : null;
+
+ String msg = (t == null) ? String.valueOf(message) : t.getMessage();
+ JOptionPane.showMessageDialog(parent,
+ "an error happened : "+msg+"\nSee logs for details",
+ "error",
+ JOptionPane.ERROR_MESSAGE);
+
+ if(t != null)
+ {
+ log.error(msg, t);
+ }
+ else
+ {
+ log.error(msg);
+ }
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java 2008-01-05 08:51:26 UTC (rev 3685)
@@ -0,0 +1,95 @@
+package org.jnode.apps.jpartition.swingview;
+
+import java.awt.BorderLayout;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.model.Device;
+import org.jnode.apps.jpartition.model.UserFacade;
+import org.jnode.apps.jpartition.model.UserListener;
+
+public class MainView extends JFrame {
+ private static final Logger log = Logger.getLogger(DeviceView.class);
+
+ final private DefaultComboBoxModel devices;
+ final private DeviceView deviceView;
+
+ public MainView(JComponent cmdProcessorView) throws Exception
+ {
+ setTitle("JPartition");
+ setLayout(new BorderLayout());
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ add(cmdProcessorView, BorderLayout.SOUTH);
+
+ deviceView = new DeviceView();
+ add(deviceView, BorderLayout.CENTER);
+
+ devices = new DefaultComboBoxModel(UserFacade.getInstance().getDevices());
+ final JComboBox cboDevices = new JComboBox(devices);
+ cboDevices.addItemListener(new ItemListener()
+ {
+ public void itemStateChanged(ItemEvent event) {
+ boolean selected = (event.getStateChange() == ItemEvent.SELECTED);
+ String item = selected ? String.valueOf(event.getItem()) : null;
+ UserFacade.getInstance().selectDevice(item);
+ deviceView.update();
+ }
+ });
+ add(cboDevices, BorderLayout.NORTH);
+
+ setSize(600, 300);
+ setVisible(true);
+ setLocation(300, 300);
+
+ UserFacade.getInstance().setUserListener(new UserListener(){
+ public void deviceAdded(String name) {
+ devices.addElement(name);
+ deviceView.update();
+ }
+
+ public void deviceRemoved(String name) {
+ devices.removeElement(name);
+ deviceView.update();
+ }
+
+ public void selectionChanged(Device selectedDevice) {
+ cboDevices.setSelectedItem(selectedDevice.getName());
+ deviceView.update();
+ }});
+ }
+
+// public void deviceStarted(Object device) {
+// log.debug("deviceStarted");
+// devices.addElement(device);
+// }
+//
+// public void deviceStop(Object device) {
+// log.debug("deviceStop");
+// devices.removeElement(device);
+// }
+//
+// public void deviceSelected(Object device) {
+// log.debug("deviceSelected");
+// deviceView.clearDevice();
+// //controller.userSelectDevice(device);
+// }
+//
+// public void partitionAdded(Object device) {
+// log.debug("partitionAdded");
+// deviceView.clearDevice();
+// //controller.userSelectDevice(device);
+// }
+//
+// public void partitionRemoved(Object device) {
+// log.debug("partitionRemoved");
+// deviceView.clearDevice();
+// //controller.userSelectDevice(device);
+// }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2008-01-24 16:29:00
|
Revision: 3723
http://jnode.svn.sourceforge.net/jnode/?rev=3723&view=rev
Author: fduminy
Date: 2008-01-24 08:28:57 -0800 (Thu, 24 Jan 2008)
Log Message:
-----------
jpartition : work in progress for console view
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -25,13 +25,16 @@
String msg = (t == null) ? String.valueOf(message) : t.getMessage();
displayError(source, msg);
- if(t != null)
+ if(log != null)
{
- log.error(msg, t);
+ if(t != null)
+ {
+ log.error(msg, t);
+ }
+ else
+ {
+ log.error(msg);
+ }
}
- else
- {
- log.error(msg);
- }
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -1,12 +1,14 @@
package org.jnode.apps.jpartition.commands;
+import java.io.IOException;
+
import org.jnode.apps.jpartition.commands.framework.BaseCommand;
import org.jnode.apps.jpartition.commands.framework.CommandException;
+import org.jnode.driver.ApiNotFoundException;
+import org.jnode.driver.DeviceNotFoundException;
import org.jnode.driver.bus.ide.IDEDevice;
-import org.jnode.partitions.command.FdiskCommand;
+import org.jnode.partitions.command.PartitionHelper;
-import sun.java2d.pipe.NullPipe;
-
abstract public class BaseDeviceCommand extends BaseCommand {
protected final IDEDevice device;
@@ -20,6 +22,19 @@
this.device = device;
}
+
+ final protected PartitionHelper createPartitionHelper() throws CommandException
+ {
+ try {
+ return new PartitionHelper(device);
+ } catch (DeviceNotFoundException e) {
+ throw new CommandException(e);
+ } catch (ApiNotFoundException e) {
+ throw new CommandException(e);
+ } catch (IOException e) {
+ throw new CommandException(e);
+ }
+ }
abstract protected void doExecute() throws CommandException;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -4,7 +4,7 @@
import org.jnode.driver.bus.ide.IDEDevice;
abstract public class BasePartitionCommand extends BaseDeviceCommand {
- private final int partitionNumber;
+ protected final int partitionNumber;
public BasePartitionCommand(String name, IDEDevice device, int partitionNumber)
{
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -1,17 +1,34 @@
package org.jnode.apps.jpartition.commands;
+import java.io.IOException;
+
import org.jnode.apps.jpartition.commands.framework.CommandException;
import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.command.PartitionHelper;
public class CreatePartitionCommand extends BasePartitionCommand {
-
- public CreatePartitionCommand(IDEDevice device, int partitionNumber) {
+ final private long start;
+ final private long size;
+
+ public CreatePartitionCommand(IDEDevice device, int partitionNumber, long start, long size) {
super("create partition", device, partitionNumber);
+ this.start = start;
+ this.size = size;
}
@Override
final protected void doExecute() throws CommandException {
- // TODO Auto-generated method stub
-
+// PartitionHelper helper = createPartitionHelper();
+// try {
+//
+// helper.write();
+// } catch (IOException e) {
+// throw new CommandException(e);
+// }
}
+
+ @Override
+ public String toString() {
+ return "create partition [" + start + ", " + (start+size-1) + "] on device " + device.getId();
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -2,16 +2,24 @@
import org.jnode.apps.jpartition.commands.framework.CommandException;
import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.fs.FileSystem;
+import org.jnode.fs.Formatter;
public class FormatPartitionCommand extends BasePartitionCommand {
-
- public FormatPartitionCommand(IDEDevice device, int partitionNumber) {
+ private final Formatter<? extends FileSystem> formatter;
+
+ public FormatPartitionCommand(IDEDevice device, int partitionNumber, Formatter<? extends FileSystem> formatter) {
super("format partition", device, partitionNumber);
+ this.formatter = formatter;
}
@Override
final protected void doExecute() throws CommandException {
// TODO Auto-generated method stub
-
}
+
+ @Override
+ public String toString() {
+ return "format partition " + partitionNumber + " on device " + device.getId() + " with " + formatter.getFileSystemType().getName();
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -12,6 +12,11 @@
@Override
final protected void doExecute() throws CommandException {
// TODO Auto-generated method stub
-
}
+
+ @Override
+ public String toString() {
+ return "remove partition " + partitionNumber + " on device" + device.getId();
+ }
+
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -23,8 +23,9 @@
this.errorReporter = errorReporter;
}
- public boolean hasChanges() {
- return !commands.isEmpty();
+ public List<Command> getPendingCommands()
+ {
+ return new ArrayList<Command>(commands);
}
public synchronized void process()
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -8,15 +8,14 @@
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.Context;
import org.jnode.apps.jpartition.ErrorReporter;
+import org.jnode.apps.jpartition.commands.framework.Command;
import org.jnode.apps.jpartition.consoleview.components.Component;
-import org.jnode.apps.jpartition.consoleview.components.Labelizer;
import org.jnode.apps.jpartition.consoleview.components.NumberField;
import org.jnode.apps.jpartition.consoleview.components.Options;
import org.jnode.apps.jpartition.consoleview.components.YesNo;
import org.jnode.apps.jpartition.model.Device;
import org.jnode.apps.jpartition.model.Partition;
import org.jnode.apps.jpartition.model.UserFacade;
-import org.jnode.util.NumberUtils;
class ConsoleView extends Component {
private static final Logger log = Logger.getLogger(ConsoleView.class);
@@ -36,8 +35,24 @@
}
println();
- print("selectedPartition="+PartitionLabelizer.INSTANCE.getLabel(selectedPartition));
- print(" on device "+DeviceLabelizer.INSTANCE.getLabel(UserFacade.getInstance().getSelectedDevice()));
+
+ if(selectedPartition == null)
+ {
+ print("selectedPartition=none");
+ }
+ else
+ {
+ print("selectedPartition="+PartitionLabelizer.INSTANCE.getLabel(selectedPartition));
+ }
+
+ if(UserFacade.getInstance().getSelectedDevice() == null)
+ {
+ println(" on no device");
+ }
+ else
+ {
+ println(" on device "+DeviceLabelizer.INSTANCE.getLabel(UserFacade.getInstance().getSelectedDevice()));
+ }
}
private void start() throws Exception
@@ -45,10 +60,18 @@
selectDevice();
selectPartition();
- if(UserFacade.getInstance().hasChanges())
+ List<Command> pendingCommands = UserFacade.getInstance().getPendingCommands();
+ if(!pendingCommands.isEmpty())
{
YesNo yesNo = new YesNo(context);
- boolean apply = yesNo.show("There is pending modifications. Would you like to apply them ?");
+ println();
+ println("The following modifications are pending :");
+ for(Command cmd : pendingCommands)
+ {
+ println("\t"+cmd);
+ }
+
+ boolean apply = yesNo.show("Would you like to apply them ?");
if(apply)
{
UserFacade.getInstance().applyChanges();
@@ -69,56 +92,92 @@
private void selectPartition() throws Exception
{
- selectedPartition = null;
- if(install)
+ List<Partition> partitions = UserFacade.getInstance().getPartitions();
+ if((partitions.size() == 1) && !partitions.get(0).isUsed())
{
- selectedPartition = selectPartitionForInstall();
+ YesNo yesNo = new YesNo(context);
+ boolean create = yesNo.show("There is no partition. Would you like to create one ?");
+ if(create)
+ {
+ selectedPartition = createPartition(partitions.get(0));
+ }
}
if(selectedPartition == null)
{
- selectedPartition = selectPartitionForDevice();
+ partitions = UserFacade.getInstance().getPartitions();
+
+ Options partitionsOpt = new Options(context);
+ int choice = (int) partitionsOpt.show("Select a partition", partitions, PartitionLabelizer.INSTANCE);
+
+ selectedPartition = partitions.get(choice - 1);
}
+
+ if(selectedPartition != null)
+ {
+ if(install)
+ {
+ formatPartition(selectedPartition);
+ }
+ else
+ {
+ modifyPartition(selectedPartition);
+ }
+ }
}
- private Partition selectPartitionForDevice() throws Exception {
- List<Partition> partitions = UserFacade.getInstance().getPartitions();
+ private Partition createPartition(Partition freePart) throws Exception {
+ long size = freePart.getSize();
+ NumberField sizeField = new NumberField(context);
+ size = sizeField.show("Size of the new partition ", size, 1, size);
- Options partitionsOpt = new Options(context);
- int choice = (int) partitionsOpt.show("Select a partition", partitions, PartitionLabelizer.INSTANCE);
-
- return partitions.get(choice - 1);
+ return UserFacade.getInstance().createPartition(freePart.getStart(), size);
}
-
- private Partition selectPartitionForInstall() throws Exception
- {
- List<Partition> partitions = UserFacade.getInstance().getPartitions();
- Partition partition = null;
- if((partitions.size() == 1) && !partitions.get(0).isUsed())
+
+ private void modifyPartition(Partition partition) throws Exception {
+ if(partition.isUsed())
{
- YesNo yesNo = new YesNo(context);
- boolean create = yesNo.show("There is no partition. Would you like to create one ?");
- if(create)
+ final String[] operations = new String[]{"format partition", "remove partition"};
+
+ Options partitionsOpt = new Options(context);
+ int choice = (int) partitionsOpt.show("Select an operation", operations);
+ switch(choice)
{
- partition = createPartition(partitions.get(0));
+ case 0: formatPartition(partition); break;
+ case 1: removePartition(partition); break;
}
}
-
- return partition;
+ else
+ {
+ final String[] operations = new String[]{"add partition"};
+
+ Options partitionsOpt = new Options(context);
+ int choice = (int) partitionsOpt.show("Select an operation", operations);
+ switch(choice)
+ {
+ case 0: createPartition(partition); break;
+ }
+ }
}
- private Partition createPartition(Partition freePart) throws Exception {
- long size = freePart.getSize();
- String space = NumberUtils.toBinaryByte(size);
+ private void removePartition(Partition partition) throws Exception {
YesNo yesNo = new YesNo(context);
- boolean allSpace = yesNo.show("Would you like to use all the free space ("+space+") ?");
+ boolean remove = yesNo.show("Would like you to remove the partition ?");
- if(!allSpace)
+ if(remove)
{
- NumberField sizeField = new NumberField(context);
- size = sizeField.show("Size of the new partition ");
+ UserFacade.getInstance().removePartition(partition.getStart() + 1);
}
+ }
+
+ private void formatPartition(Partition partition) throws Exception {
+ String[] formatters = UserFacade.getInstance().getFormatters();
+ Options partitionsOpt = new Options(context);
+ int choice = (int) partitionsOpt.show("Select a filesystem", formatters);
+ String formatter = formatters[choice];
- return UserFacade.getInstance().createPartition(freePart.getStart(), size);
- }
+ UserFacade.getInstance().selectFormatter(formatter);
+
+ UserFacade.getInstance().formatPartition(partition.getStart() + 1);
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -10,7 +10,13 @@
static final DeviceLabelizer INSTANCE = new DeviceLabelizer();
public String getLabel(Device device) {
+ if(device == null)
+ {
+ throw new NullPointerException("device is null");
+ }
+
StringBuilder sb = new StringBuilder();
+
sb.append(device.getName());
sb.append(" (").append(NumberUtils.toBinaryByte(device.getSize())).append(')');
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -9,7 +9,13 @@
static final PartitionLabelizer INSTANCE = new PartitionLabelizer();
public String getLabel(Partition partition) {
+ if(partition == null)
+ {
+ throw new NullPointerException("partition is null");
+ }
+
StringBuilder sb = new StringBuilder();
+
sb.append('[').append(partition.getStart()).append(',').append(partition.getEnd()).append(']');
sb.append(" (").append(NumberUtils.toBinaryByte(partition.getSize())).append(") ");
String format = partition.isUsed() ? partition.getFormat() : "unused";
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -2,12 +2,14 @@
import java.io.IOException;
import java.util.Collection;
-import java.util.List;
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.Context;
public class Component {
+ protected static final String TRUE_LONG_STRING = "yes";
+ protected static final String FALSE_LONG_STRING = "no";
+
protected final Context context;
protected Component(Context context) {
@@ -30,40 +32,115 @@
return context.getIn().read();
}
- final protected boolean readBoolean(boolean defaultValue) throws IOException {
+ final protected String getValueStr(boolean value)
+ {
+ return value ? TRUE_LONG_STRING : FALSE_LONG_STRING;
+ }
+
+ final protected Boolean readBoolean(Boolean defaultValue) throws IOException {
String line = context.getIn().readLine();
- boolean value = defaultValue;
- try
+ Boolean value;
+ if((line == null) || (line.trim().length() == 0))
{
- if(defaultValue)
+ value = defaultValue;
+ if(value != null)
{
- value = ("no".equals(line)) ? false : true;
+ print(String.valueOf(defaultValue));
}
- else
- {
- value = ("yes".equals(line)) ? true : false;
- }
}
- catch(Exception e)
+ else
{
- value = defaultValue;
+ try
+ {
+ line = line.trim();
+ if(defaultValue == null)
+ {
+ if(TRUE_LONG_STRING.equals(line))
+ {
+ value = true;
+ }
+ else if(FALSE_LONG_STRING.equals(line))
+ {
+ value = false;
+ }
+ else
+ {
+ value = null;
+ }
+ }
+ else if(defaultValue)
+ {
+ value = getValueStr(defaultValue).equals(line) ? false : true;
+ }
+ else
+ {
+ value = getValueStr(defaultValue).equals(line) ? true : false;
+ }
+ }
+ catch(Exception e)
+ {
+ value = defaultValue;
+ }
}
return value;
}
- final protected long readInt(long defaultValue) throws IOException {
+ final protected Long readInt() throws IOException {
+ return readInt(null, Long.MIN_VALUE, Long.MAX_VALUE);
+ }
+
+ final protected Long readInt(Long defaultValue) throws IOException {
+ return readInt(defaultValue, Long.MIN_VALUE, Long.MAX_VALUE);
+ }
+
+ final protected Long readInt(Long defaultValue, long min, long max) throws IOException {
+ checkInBounds("min", min, "max", max, "defaultValue", defaultValue);
+
String line = context.getIn().readLine();
- long value = defaultValue;
- try
+ Long value;
+ if((line == null) || (line.trim().length() == 0))
{
- value = Long.valueOf(line);
+ value = defaultValue;
+ if(value != null)
+ {
+ print(String.valueOf(defaultValue));
+ }
}
- catch(NumberFormatException e)
+ else
{
- value = defaultValue;
+ line = line.trim();
+ try
+ {
+ value = Long.decode(line);
+ }
+ catch(NumberFormatException e)
+ {
+ reportError("invalid value");
+ value = null;
+ }
+
+ if(value != null)
+ {
+ try {
+ checkInBounds("min", min, "max",
+ max, "value", value);
+ } catch (IllegalArgumentException e) {
+ if(min != max)
+ {
+ reportError("value must be between "+min+" and "+max);
+ }
+ else
+ {
+ reportError("value must be "+min);
+ }
+
+ value = null;
+ }
+ }
}
+
return value;
}
@@ -76,7 +153,12 @@
{
context.getErrorReporter().reportError(log, source, message);
}
-
+
+ final protected void reportError(String message)
+ {
+ context.getErrorReporter().reportError(null, null, message);
+ }
+
final protected void checkNonNull(String paramName, Object param)
{
if(param == null)
@@ -94,5 +176,23 @@
throw new IllegalArgumentException("parameter "+paramName+" can't be empty");
}
}
-
+
+ final protected void checkInBounds(String minName, long min, String maxName,
+ long max, String valueName, Long value) {
+ checkMinMax(minName, min, maxName, max);
+
+ if(value != null)
+ {
+ checkMinMax(minName, min, valueName, value);
+ checkMinMax(valueName, value, maxName, max);
+ }
+ }
+
+ final protected void checkMinMax(String minName, long min, String maxName, long max) {
+ if(min > max)
+ {
+ throw new IllegalArgumentException("parameter "+minName+" must be > parameter "+maxName);
+ }
+ }
+
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -15,19 +15,27 @@
}
public long show(String question) throws IOException {
- return show(question, Long.MIN_VALUE, Long.MAX_VALUE);
+ return show(question, Long.MIN_VALUE, Long.MIN_VALUE, Long.MAX_VALUE);
}
-
- public long show(String question, long min, long max) throws IOException {
+
+ public long show(String question, Long defaultValue) throws IOException {
+ return show(question, defaultValue, Long.MIN_VALUE, Long.MAX_VALUE);
+ }
+
+ public Long show(String question, Long defaultValue, long min, long max) throws IOException {
checkNonNull("question", question);
+ checkInBounds("min", min, "max", max, "defaultValue", defaultValue);
print(question);
+ if(defaultValue != null)
+ {
+ print(" ["+defaultValue+"]");
+ }
- long value = readInt(-1);
- while((value < min) || (value > max))
+ Long value = readInt(defaultValue, min, max);
+ while((value == null) || (value < min) || (value > max))
{
- reportError(log, null, "invalid choice");
- value = readInt(-1);
+ value = readInt(defaultValue);
}
return value;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -42,6 +42,6 @@
}
NumberField choice = new NumberField(context);
- return choice.show("Choice : ", 1, options.size());
+ return choice.show("Choice : ", null, 1, options.size());
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -15,11 +15,33 @@
}
public boolean show(String question) throws IOException {
+ return show(question, null);
+ }
+
+ public boolean show(String question, Boolean defaultValue) throws IOException {
checkNonNull("question", question);
println();
print(question);
- return readBoolean(false);
+ if(defaultValue != null)
+ {
+ String defaultValueStr = getValueStr(defaultValue);
+ print("["+defaultValueStr+"]");
+ }
+
+ Boolean value;
+ do
+ {
+ value = readBoolean(defaultValue);
+
+ if(value == null)
+ {
+ reportError("invalid value");
+ }
+ }
+ while(value == null);
+
+ return value;
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -1,13 +1,10 @@
package org.jnode.apps.jpartition.model;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import org.jnode.driver.ApiNotFoundException;
-import org.jnode.driver.bus.ide.IDEDeviceAPI;
import org.jnode.fs.FileSystem;
import org.jnode.fs.Formatter;
@@ -19,18 +16,14 @@
final private org.jnode.driver.Device device;
Device(String name, long size) {
- this(name, size, null);
+ this(name, size, null, new ArrayList<Partition>());
+ partitions.add(new Partition(0L, size, false));
}
- Device(org.jnode.driver.Device dev) throws ApiNotFoundException, IOException {
- this(dev.getId(), dev.getAPI(IDEDeviceAPI.class).getLength(), dev);
- }
-
- private Device(String name, long size, org.jnode.driver.Device device) {
+ Device(String name, long size, org.jnode.driver.Device device, List<Partition> partitions) {
this.name = name;
this.size = size;
- partitions = new ArrayList<Partition>();
- partitions.add(new Partition(0L, size, false));
+ this.partitions = partitions;
this.device = device;
}
@@ -106,8 +99,7 @@
partitions.add(index, newPart);
// after the new partition
- oldPart.setSize(oldPart.getSize() - size);
- oldPart.setStart(newPart.getEnd() + 1);
+ oldPart.setBounds(newPart.getEnd() + 1, oldPart.getSize() - size);
partitions.set(index + 1, oldPart);
}
else if(end == oldPart.getEnd())
@@ -147,6 +139,7 @@
Partition part = partitions.get(index);
long start = part.getStart();
long size = part.getSize();
+
if(index > 0)
{
Partition partBefore = partitions.get(index - 1);
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -90,29 +90,77 @@
private Device createDevice(org.jnode.driver.Device dev)
{
Device device = null;
- try {
- if(dev.implementsAPI(IDEDeviceAPI.class))
+ List<IBMPartitionTableEntry> partitions = getPartitions(dev);
+ if(partitions != null) // null if not supported
+ {
+ List<Partition> devPartitions = new ArrayList<Partition>(partitions.size());
+ Partition prevPartition = null;
+
+ for(IBMPartitionTableEntry e : partitions)
{
- Device tmpDevice = new Device(dev);
-
- if(dev.implementsAPI(PartitionableBlockDeviceAPI.class))
+ IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
+ long start = pte.getStartLba();
+ long size = pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
+
+ if(pte.isEmpty())
{
- PartitionableBlockDeviceAPI<?> api = dev.getAPI(PartitionableBlockDeviceAPI.class);
- for(PartitionTableEntry e : api.getPartitionTable())
+ if((prevPartition != null) && !prevPartition.isUsed())
{
- if(e instanceof IBMPartitionTableEntry)
- {
- IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
- if(!pte.isEmpty())
- {
- long size = pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
- tmpDevice.addPartition(pte.getStartLba(), size);
- }
+ // current and previous partitions are empty
+ prevPartition.mergeWithNextPartition(size);
+ }
+ else
+ {
+ // current partition is empty but not the previous one
+ devPartitions.add(new Partition(start, size, false));
+ }
+ }
+ else
+ {
+ // current partition is not empty
+ devPartitions.add(new Partition(start, size, true));
+ }
+ }
+
+ try {
+ long devSize = dev.getAPI(IDEDeviceAPI.class).getLength();
+ device = new Device(dev.getId(), devSize, dev, devPartitions);
+ } catch (ApiNotFoundException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+
+ return device;
+ }
+
+ private List<IBMPartitionTableEntry> getPartitions(org.jnode.driver.Device dev)
+ {
+ boolean supported = false;
+ List<IBMPartitionTableEntry> partitions = new ArrayList<IBMPartitionTableEntry>();
+
+ try {
+ if (dev.implementsAPI(IDEDeviceAPI.class)) {
+ if (dev.implementsAPI(PartitionableBlockDeviceAPI.class)) {
+ PartitionableBlockDeviceAPI<?> api = dev
+ .getAPI(PartitionableBlockDeviceAPI.class);
+ boolean supportedPartitions = true;
+
+ for (PartitionTableEntry e : api.getPartitionTable()) {
+ if (!(e instanceof IBMPartitionTableEntry)) {
+ // non IBM partition tables are not handled for now
+ supportedPartitions = false;
+ break;
}
+
+ partitions.add((IBMPartitionTableEntry) e);
}
+
+ support...
[truncated message content] |