i want to save positions of my dockables in sql i tried to do somethink like that
File a = new File( “C:/a.txt”);
control.read(a);
but it doesnt works
java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at bibliothek.gui.dock.common.intern.DefaultCDockable.add(DefaultCDockable.java:238)
at EditorDockable.(EditorDockable.java:65)
at EditorFactory.read(EditorFactory.java:22)
at EditorFactory.read(EditorFactory.java:1)
at bibliothek.gui.dock.common.intern.CommonMultipleDockableFactory.layout(CommonMultipleDockableFactory.java:167)
at bibliothek.gui.dock.common.intern.CommonMultipleDockableFactory.layout(CommonMultipleDockableFactory.java:162)
at bibliothek.gui.dock.common.intern.CommonMultipleDockableFactory.layout(CommonMultipleDockableFactory.java:57)
at bibliothek.gui.dock.layout.DockSituation.convert(DockSituation.java:377)
at bibliothek.gui.dock.layout.DockSituation.convert(DockSituation.java:363)
at bibliothek.gui.dock.layout.DockSituation.convert(DockSituation.java:363)
at bibliothek.gui.dock.frontend.DefaultLayoutChangeStrategy.applyLayout(DefaultLayoutChangeStrategy.java:309)
at bibliothek.gui.dock.frontend.DefaultLayoutChangeStrategy.setLayout(DefaultLayoutChangeStrategy.java:97)
at bibliothek.gui.DockFrontend.setSetting(DockFrontend.java:1481)
at bibliothek.gui.dock.common.intern.CDockFrontend.access$001(CDockFrontend.java:48)
at bibliothek.gui.dock.common.intern.CDockFrontend$1.run(CDockFrontend.java:163)
at bibliothek.gui.dock.support.mode.ModeManager.runTransaction(ModeManager.java:512)
at bibliothek.gui.dock.facile.mode.LocationModeManager.runLayoutTransaction(LocationModeManager.java:474)
at bibliothek.gui.dock.common.intern.CDockFrontend.setSetting(CDockFrontend.java:161)
at bibliothek.gui.DockFrontend.read(DockFrontend.java:1841)
at bibliothek.gui.dock.common.CControl$8.read(CControl.java:809)
at bibliothek.gui.dock.support.util.ApplicationResourceManager.readStream(ApplicationResourceManager.java:144)
at bibliothek.gui.dock.support.util.ApplicationResourceManager.readFile(ApplicationResourceManager.java:204)
at bibliothek.gui.dock.common.CControl.read(CControl.java:2609)
there a my classes :
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JTextArea;
import bibliothek.gui.dock.common.DefaultMultipleCDockable;
import bibliothek.gui.dock.common.action.CAction;
import bibliothek.gui.dock.common.event.CDockableLocationEvent;
import bibliothek.gui.dock.common.event.CDockableLocationListener;
import bibliothek.gui.dock.common.event.CDockablePropertyListener;
import bibliothek.gui.dock.common.event.CDockableStateListener;
import bibliothek.gui.dock.common.intern.CDockable;
import bibliothek.gui.dock.common.mode.ExtendedMode;
class EditorDockable extends DefaultMultipleCDockable{
private EditorLayout itsLayout=null;
private DataRoom room=null;
private boolean mousePressed=false;
public EditorDockable( EditorFactory factory, final EditorLayout layout, DataRoom room ){
/* it is mandatory to set the factory, the EditorDockable cannot be created
* without it. */
super( factory );
this.itsLayout=layout;
this.setDataRoom(room);
/* and then we just set up the editor */
setTitleText( layout.getFileName() );
if(layout.getFileContent()!=null){
for(ImageComponent e: layout.getFileContent()){
e.setParentDockable(this);
add(e);
}
}
add(layout.getBackground());
//verbinde RaumPanel mit dem EditorDockable
if(layout.getBackground() instanceof RaumPanel){
((RaumPanel) layout.getBackground()).setEditor(this);
}
}
public EditorDockable( EditorFactory factory, final EditorLayout layout ){
/* it is mandatory to set the factory, the EditorDockable cannot be created
* without it. */
super( factory );
this.itsLayout=layout;
/* and then we just set up the editor */
setTitleText( layout.getFileName() );
if(layout.getFileContent()!=null){
for(ImageComponent e: layout.getFileContent()){
e.setParentDockable(this);
add(e);
}
}
add(layout.getBackground());
//verbinde RaumPanel mit dem EditorDockable
if(layout.getBackground() instanceof RaumPanel){
((RaumPanel) layout.getBackground()).setEditor(this);
}
}
/* This convenient method allows us to grab the entire content of this dockable
* in one step. */
public EditorLayout getLayout(){
return itsLayout;
}
public DataRoom getDataRoom() {
return room;
}
public void setDataRoom(DataRoom room) {
this.room = room;
}
}```
import bibliothek.gui.dock.common.MultipleCDockableFactory;
/* This factory builds a link between EditorDockable and EditorLayout */
class EditorFactory implements MultipleCDockableFactory<EditorDockable, EditorLayout>{
/* An empty layout is required to read a layout from an XML file or from a byte stream */
public EditorLayout create(){
return new EditorLayout();
}
/* An optional method allowing to reuse 'dockable' when loading a new layout */
public boolean match( EditorDockable dockable, EditorLayout layout ){
System.out.println("factory");
return dockable.getLayout().equals( layout );
}
/* Called when applying a stored layout */
public EditorDockable read( EditorLayout layout ){
System.out.println("factory");
return new EditorDockable( this, layout );
}
/* Called when storing the current layout */
public EditorLayout write( EditorDockable dockable ){
System.out.println("factory");
return dockable.getLayout();
}
}
import java.awt.Color;
import java.awt.Cursor;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.JPanel;
import bibliothek.gui.dock.common.MultipleCDockableLayout;
import bibliothek.util.xml.XElement;
class EditorLayout implements MultipleCDockableLayout {
private String fileName=null;
private JPanel background=null;
private ArrayList pc;
public EditorLayout(){
// nothing
}
public EditorLayout( String fileName, ArrayList <ImageComponent>pc, JPanel background ){
this.fileName = fileName;
this.pc=pc;
this.background=background;
}
public String getFileName(){
return fileName;
}
public ArrayList<ImageComponent> getFileContent(){
return pc;
}
public JPanel getBackground(){
return background;
}
@Override
public boolean equals( Object obj ){
if( this == obj ){
return true;
}
if( obj == null ){
return false;
}
if( getClass() != obj.getClass() ){
return false;
}
EditorLayout other = (EditorLayout) obj;
return equals( background, other.background ) &&
equals( fileName, other.fileName ); /*&&
/*equals( fileContent, other.fileContent );*/
}
private boolean equals( Object a, Object b ){
if( a == null ){
return b == null;
}
else{
return a.equals( b );
}
}
public void readStream( DataInputStream in ) throws IOException{
fileName = in.readUTF();
}
public void readXML( XElement element ){
fileName = element.getElement( "name" ).getString();
}
public void writeStream( DataOutputStream out ) throws IOException{
out.writeUTF( fileName );
}
public void writeXML( XElement element ){
element.addElement( "name" ).setString( fileName );
}
public EditorLayout clone(){
return this;
}
}
i dont understand what im doing wrong an who can i store the "layout"(dockable positions an state if they are open ore closed ) in the data base , it can u halp me please ?