|
From: <fd...@us...> - 2007-03-18 23:57:38
|
Revision: 3143
http://jnode.svn.sourceforge.net/jnode/?rev=3143&view=rev
Author: fduminy
Date: 2007-03-18 12:35:21 -0700 (Sun, 18 Mar 2007)
Log Message:
-----------
JPartition (JNode disk partitionner) : alpha version
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/
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
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/controller/
trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/
trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/view/
trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsFrame.java
trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsUI.java
trunk/distr/src/apps/org/jnode/apps/jpartition/view/FileDeviceFrame.java
trunk/distr/src/apps/org/jnode/apps/jpartition/view/PartitionUI.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,35 @@
+/**
+ *
+ */
+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
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,86 @@
+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);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,32 @@
+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 {
+
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,60 @@
+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.naming.InitialNaming;
+import org.jnode.naming.NameSpace;
+import org.jnode.test.fs.driver.stubs.StubDeviceManager;
+
+public class JPartition {
+ private static final Logger log = Logger.getLogger(JPartition.class);
+
+ public static void main(String[] args) throws Exception {
+ initJNodeCore();
+
+ FileDeviceFrame frm = new FileDeviceFrame();
+ frm.setSize(300, 300);
+ frm.setVisible(true);
+ frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ 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);
+ }
+
+ 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);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,58 @@
+package org.jnode.apps.jpartition.controller;
+
+import javax.naming.NameNotFoundException;
+
+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.DevicePartitionsUI;
+import org.jnode.driver.Device;
+import org.jnode.driver.DeviceListener;
+import org.jnode.driver.DeviceUtils;
+
+public class DevicePartitionsController implements DeviceListener
+{
+ private static final Logger log = Logger.getLogger(DevicePartitionsController.class);
+
+ private DevicePartitionsList model;
+ private DevicePartitionsFrame view;
+
+ public DevicePartitionsController(DevicePartitionsList model,
+ DevicePartitionsFrame view)
+ {
+ this.model = model;
+ this.view = view;
+
+ try {
+ DeviceUtils.getDeviceManager().addListener(this);
+ } catch (NameNotFoundException e) {
+ log.error(e);
+ }
+ }
+
+ public void deviceStarted(Device device) {
+ System.err.println("deviceStarted...");
+ DevicePartitions devPart = new DevicePartitions(device);
+ model.add(devPart);
+ view.getDevPartsUI().deviceAdded(devPart);
+ }
+
+ public void deviceStop(Device device) {
+ System.err.println("deviceStop...");
+ DevicePartitions devPartsToRemove = null;
+ for(DevicePartitions devParts : model)
+ {
+ if(device.equals(devParts.getDevice()))
+ {
+ devPartsToRemove = devParts;
+ break;
+ }
+ }
+ if(devPartsToRemove != null)
+ {
+ model.remove(devPartsToRemove);
+ view.getDevPartsUI().deviceRemoved(devPartsToRemove);
+ }
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,73 @@
+package org.jnode.apps.jpartition.model;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jnode.driver.ApiNotFoundException;
+import org.jnode.driver.Device;
+import org.jnode.driver.block.PartitionableBlockDeviceAPI;
+import org.jnode.partitions.PartitionTableEntry;
+import org.jnode.partitions.ibm.IBMPartitionTableEntry;
+
+public class DevicePartitions
+{
+ private static final Logger log = Logger.getLogger(DevicePartitions.class);
+
+ private final Device device;
+ private final List<Partition> partitions = new ArrayList<Partition>();
+
+ public DevicePartitions(Device device)
+ {
+ this.device = device;
+ try {
+ addPartitions(device);
+ } catch (Exception e) {
+ log.error(e);
+ }
+ }
+
+ public List<Partition> getPartitions()
+ {
+ return partitions;
+ }
+
+ protected void addPartitions(Device device) throws Exception
+ {
+ System.err.println("addPartitions");
+ if(device.implementsAPI(PartitionableBlockDeviceAPI.class))
+ {
+ System.err.println("implementsAPI");
+ partitions.clear();
+ PartitionableBlockDeviceAPI<?> api = device.getAPI(PartitionableBlockDeviceAPI.class);
+ for(PartitionTableEntry e : api.getPartitionTable())
+ {
+ System.err.println("PartitionTableEntry");
+ addPartition(e);
+ }
+ }
+ }
+
+ public void addPartition(PartitionTableEntry e)
+ {
+ if(e instanceof IBMPartitionTableEntry)
+ {
+ IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
+ partitions.add(new Partition(pte));
+ }
+ else
+ {
+ log.warn("found non-IBMPartitionTableEntry");
+ }
+ }
+
+ public String toString()
+ {
+ return device.getId();
+ }
+
+ public Device getDevice() {
+ return device;
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,7 @@
+package org.jnode.apps.jpartition.model;
+
+import java.util.ArrayList;
+
+public class DevicePartitionsList extends ArrayList<DevicePartitions>
+{
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,40 @@
+package org.jnode.apps.jpartition.model;
+
+import org.jnode.driver.bus.ide.IDEConstants;
+import org.jnode.partitions.ibm.IBMPartitionTableEntry;
+import org.jnode.partitions.ibm.IBMPartitionTypes;
+
+public class Partition
+{
+ private final IBMPartitionTableEntry pte;
+
+ public Partition(IBMPartitionTableEntry pte)
+ {
+ this.pte = pte;
+ }
+
+ public boolean isEmpty()
+ {
+ return pte.isEmpty();
+ }
+
+ public boolean isBootable()
+ {
+ return pte.getBootIndicator();
+ }
+
+ public IBMPartitionTypes getType()
+ {
+ return pte.getSystemIndicator();
+ }
+
+ public long getStart()
+ {
+ return pte.getStartLba();
+ }
+
+ public long getSize()
+ {
+ return pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsFrame.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsFrame.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsFrame.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,28 @@
+package org.jnode.apps.jpartition.view;
+
+import javax.swing.JFrame;
+
+import org.jnode.apps.jpartition.controller.DevicePartitionsController;
+import org.jnode.apps.jpartition.model.DevicePartitionsList;
+
+public class DevicePartitionsFrame extends JFrame {
+ private DevicePartitionsUI devPartsUI;
+
+ private DevicePartitionsController controller;
+
+ public DevicePartitionsFrame(DevicePartitionsList devicePartitionsList)
+ {
+ setTitle("JPartition");
+
+ devPartsUI = new DevicePartitionsUI(devicePartitionsList);
+ add(devPartsUI);
+
+ controller = new DevicePartitionsController(devicePartitionsList, this);
+ }
+
+ public DevicePartitionsUI getDevPartsUI() {
+ return devPartsUI;
+ }
+
+
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsUI.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsUI.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsUI.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,67 @@
+package org.jnode.apps.jpartition.view;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
+import javax.swing.JPanel;
+
+import org.jnode.apps.jpartition.model.DevicePartitions;
+import org.jnode.apps.jpartition.model.DevicePartitionsList;
+import org.jnode.apps.jpartition.model.Partition;
+
+public class DevicePartitionsUI extends JPanel {
+ private DevicePartitionsList devicePartitions;
+
+ private DefaultComboBoxModel cboDevicesModel = new DefaultComboBoxModel();
+ private JComboBox cboDevices = new JComboBox(cboDevicesModel);
+ private JPanel partitionsPanel = new JPanel(new FlowLayout());
+
+ public DevicePartitionsUI(DevicePartitionsList devicePartitions)
+ {
+ super(new BorderLayout());
+ this.devicePartitions = devicePartitions;
+
+ add(cboDevices, BorderLayout.NORTH);
+ add(partitionsPanel, BorderLayout.CENTER);
+
+ for(DevicePartitions 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)
+ {
+ System.err.println("itemStateChanged");
+ DevicePartitions devParts = (DevicePartitions) event.getItem();
+ partitionsPanel.removeAll();
+
+ for(Partition partition : devParts.getPartitions())
+ {
+ partitionsPanel.add(new PartitionUI(partition));
+ }
+ }
+ }
+ });
+ }
+
+ public void deviceAdded(DevicePartitions devParts) {
+ System.err.println("deviceAdded");
+ cboDevicesModel.addElement(devParts);
+ }
+
+ public void deviceRemoved(DevicePartitions devParts) {
+ cboDevicesModel.removeElement(devParts);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/view/FileDeviceFrame.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/view/FileDeviceFrame.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/view/FileDeviceFrame.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,133 @@
+package org.jnode.apps.jpartition.view;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import javax.naming.NameNotFoundException;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
+import javax.swing.JList;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.FileIDEDevice;
+import org.jnode.driver.ApiNotFoundException;
+import org.jnode.driver.DeviceAlreadyRegisteredException;
+import org.jnode.driver.DeviceManager;
+import org.jnode.driver.DeviceNotFoundException;
+import org.jnode.driver.DeviceUtils;
+import org.jnode.driver.DriverException;
+import org.jnode.partitions.command.PartitionHelper;
+import org.jnode.partitions.ibm.IBMPartitionTypes;
+
+public class FileDeviceFrame extends JFrame
+{
+ private static final Logger log = Logger.getLogger(FileDeviceFrame.class);
+
+ private static final long DEFAULT_FILE_SIZE = 1000;
+
+ private DefaultListModel fileDevices = new DefaultListModel();
+
+ private JList devicesList = new JList(fileDevices);
+ private JPanel buttons = new JPanel();
+ private JButton addButton = new JButton("add device");
+ private JButton removeButton = new JButton("remove device");
+
+ public FileDeviceFrame() throws Exception
+ {
+ setTitle("File devices");
+ setLayout(new BorderLayout());
+ add(new JScrollPane(devicesList), BorderLayout.CENTER);
+ add(buttons, BorderLayout.SOUTH);
+
+ buttons.add(addButton);
+ buttons.add(removeButton);
+
+ addButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser jfc = new JFileChooser();
+ jfc.setDialogType(JFileChooser.SAVE_DIALOG);
+ int result = jfc.showSaveDialog(FileDeviceFrame.this);
+ if(result == JFileChooser.APPROVE_OPTION)
+ {
+ try
+ {
+ FileIDEDevice fd = createDevice(jfc.getSelectedFile());
+ if(addDevice(fd))
+ {
+ fileDevices.addElement(fd);
+ }
+ else
+ {
+ JOptionPane.showMessageDialog(FileDeviceFrame.this,
+ "failed to add device", "add device",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ } catch (Exception e) {
+ log.error(e);
+ }
+ }
+ }
+ });
+ removeButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event) {
+ if(devicesList.getSelectedIndex() >= 0)
+ {
+ //TODO
+ }
+ }
+ });
+ }
+
+ protected FileIDEDevice createDevice(File file) throws Exception
+ {
+ //return new FileDevice(file, "rw");
+ FileIDEDevice dev = new FileIDEDevice(file, DEFAULT_FILE_SIZE,
+ true, true);
+ return dev;
+ }
+
+ private boolean addDevice(FileIDEDevice device)
+ {
+ boolean success = false;
+ try
+ {
+ DeviceManager devMan = DeviceUtils.getDeviceManager();
+ devMan.register(device);
+ success = true;
+
+ PartitionHelper helper = new PartitionHelper(device.getId(), devMan);
+ helper.initMbr();
+ helper.write();
+ 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) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ApiNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return success;
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/view/PartitionUI.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/view/PartitionUI.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/view/PartitionUI.java 2007-03-18 19:35:21 UTC (rev 3143)
@@ -0,0 +1,57 @@
+package org.jnode.apps.jpartition.view;
+
+import java.awt.Color;
+
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import org.jnode.apps.jpartition.model.Partition;
+
+public class PartitionUI extends JPanel
+{
+ private Partition partition = null;
+
+ private JLabel lblInfos = new JLabel();
+
+ public PartitionUI(Partition partition)
+ {
+ setPartition(partition);
+
+
+ setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
+ lblInfos.setBackground(Color.CYAN);
+ add(lblInfos);
+ }
+
+ public Partition getPartition() {
+ return partition;
+ }
+
+ public void setPartition(Partition partition) {
+ if(this.partition != partition)
+ {
+ this.partition = partition;
+ refreshFromModel();
+ }
+ }
+
+ public void refreshFromModel()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ String name = partition.getType().getName();
+ if(name.length() > 10)
+ {
+ name = name.substring(0, 10);
+ }
+ String boot = partition.isBootable() ? "(B)" : "(-)";
+ sb.append(boot).append(name);
+ if(!partition.isEmpty())
+ {
+ sb.append("-").append(partition.getStart());
+ sb.append("-").append(partition.getSize());
+ }
+ lblInfos.setText(sb.toString());
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|