Commit 5d77831d authored by Guillaume Chomat's avatar Guillaume Chomat
Browse files

corrected some problems with load and save

parent 7adc9445
/**
*
*$Id: FCGraphUI.java,v 1.9 2002-07-03 09:18:58 frederic Exp $
*$Id: FCGraphUI.java,v 1.10 2002-07-03 16:15:15 gchomat Exp $
*
* Transmorpher
*
......@@ -96,7 +96,7 @@ public class FCGraphUI extends BasicGraphUI{
"; "+graph+" was expected.");
Graphics2D g2 = (Graphics2D) g;
//System.out.println(g.getClipBounds()+"g.getClipBounds()");
//System.out.println(g.getClipBounds()+"g.getClipBounds()");
Rectangle paintBounds = new Rectangle(g.getClipBounds());
Rectangle real = graph.fromScreen(new Rectangle(paintBounds));
//System.out.println(real+"real");
......@@ -129,7 +129,7 @@ public class FCGraphUI extends BasicGraphUI{
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
g2.setTransform(at);
/* change with JGRAPH as port have views: draw ports two once
/* change with JGRAPH as port have views: draw ports two once
// Paint Foreground (Typically Ports)
// paintForeground(g);
......@@ -140,29 +140,29 @@ public class FCGraphUI extends BasicGraphUI{
// Empty out the renderer pane, allowing renderers to be gc'ed.
if (rendererPane != null)
rendererPane.removeAll(); */
}
public void paintCell(Graphics g, CellView view, Rectangle bounds,
boolean preview)
{
if (!view.isLeaf()) {
CellView[] children = view.getChildViews();
for (int i = 0; i < children.length; i++)
paintCell(g, children[i], children[i].getBounds(), preview);
}
boolean focus = graph.getSelectionModel().isChildrenSelected(view.getCell());
boolean sel = graph.isCellSelected(view.getCell());
//System.out.println(sel+"booleen de selection");
Component component = view.getRendererComponent(graph, sel, focus, preview);
rendererPane.paintComponent(g, component, graph, bounds.x, bounds.y,
bounds.width, bounds.height, true);
public void paintCell(Graphics g, CellView view, Rectangle bounds,
boolean preview)
{
if (!view.isLeaf()) {
CellView[] children = view.getChildViews();
for (int i = 0; i < children.length; i++)
paintCell(g, children[i], children[i].getBounds(), preview);
}
boolean focus = graph.getSelectionModel().isChildrenSelected(view.getCell());
boolean sel = graph.isCellSelected(view.getCell());
//System.out.println(sel+"booleen de selection");
Component component = view.getRendererComponent(graph, sel, focus, preview);
rendererPane.paintComponent(g, component, graph, bounds.x, bounds.y,
bounds.width, bounds.height, true);
}
/**
* TreeMouseListener is responsible for updating the selection
* based on mouse events.
......@@ -175,18 +175,18 @@ public class FCGraphUI extends BasicGraphUI{
public void mousePressed(MouseEvent e) {
// System.out.println("e "+e.getButton());
/*if(e.isPopupTrigger())
{
if (marquee!= null)
marquee.mousePressed(e);
super.mousePressed(e);
}*/
if(e.getButton() == MouseEvent.BUTTON3 ){
if(e.isPopupTrigger())
{
if (marquee!= null)
marquee.mousePressed(e);
super.mousePressed(e);
}
/*if(e.getButton() == MouseEvent.BUTTON3 ){
//System.out.println("marquee "+marquee);
if (marquee!= null)
marquee.mousePressed(e);
super.mousePressed(e);
}
}*/
else
super.mousePressed(e);
......
/**
* $Id: FCMarqueeHandler.java,v 1.42 2002-07-03 09:18:58 frederic Exp $
* $Id: FCMarqueeHandler.java,v 1.43 2002-07-03 16:15:15 gchomat Exp $
*
* Transmorpher
......@@ -156,17 +156,19 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
public void mousePressed(MouseEvent e) {
//System.out.println("MousePressed Start...");
/* if (e.isPopupTrigger()){
if (!e.isConsumed() && marquee.isSelected()) {
current = flowcomposer.getCurrentProcess().snap(e.getPoint());
flowcomposer.showPopup(e);
return;
}
}*/
if (e.getButton() == MouseEvent.BUTTON3) {
//current = flowcomposer.getCurrentProcess().snap(e.getPoint());
flowcomposer.showPopup(e);
if (e.isPopupTrigger()){
if (!e.isConsumed() && marquee.isSelected()) {
current = flowcomposer.getCurrentProcess().snap(e.getPoint());
flowcomposer.showPopup(e);
return;
}
}
/*if (e.getButton() == MouseEvent.BUTTON3) {
current = flowcomposer.getCurrentProcess().snap(e.getPoint());
flowcomposer.showPopup(e);
}*/
else{
if(flowcomposer.getCurrentProcess() != null){
if (!e.isConsumed() && !marquee.isSelected()) {
......
/**
*
*$Id: FlowComposer.java,v 1.62 2002-07-03 09:18:58 frederic Exp $
*$Id: FlowComposer.java,v 1.63 2002-07-03 16:15:15 gchomat Exp $
*
* Transmorpher
*
......@@ -79,13 +79,13 @@ public class FlowComposer extends JPanel implements GraphModelListener,
// a boolean which indicates if the drawing area is editing
protected boolean editing = false;
//Used only if FlowComposer is an applet
//private boolean inAnApplet = true;
//Process Factory allow to create new Process
protected FCProcessFactory processFactory;
//The Transmorpher Graph
protected Transmorpher transmorpher;
......@@ -127,7 +127,7 @@ public class FlowComposer extends JPanel implements GraphModelListener,
protected static FCWindowListener windowListener;
//File
protected File file;
protected File file = null;
//The current file name
protected String filename;
......@@ -135,6 +135,10 @@ public class FlowComposer extends JPanel implements GraphModelListener,
// Temporary filename
protected String temporaryFilename;
// temporatry file
protected File temporaryFile = null;
// Application Icon. From resource file.
public static ImageIcon appIcon;
......@@ -240,11 +244,10 @@ public class FlowComposer extends JPanel implements GraphModelListener,
this(null,null);
}
public FlowComposer(String filename, GraphModel model) {
public FlowComposer(File file, GraphModel model) {
super(true);
this.filename = filename;
setFile(file);
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
......@@ -264,7 +267,6 @@ public class FlowComposer extends JPanel implements GraphModelListener,
initMainProcess();
touchLayout = new Layout(currentProcess);
}
public static void init() {
......@@ -276,18 +278,28 @@ public class FlowComposer extends JPanel implements GraphModelListener,
processFactory = new FCProcessFactory(this);
if(filename != null)
if(file != null)
{
init_main = false;
ProcessParser parser = new ProcessParser(3,new Object[]{processFactory});
transmorpher = parser.Newparse(filename);
processFactory.createAllChannels();
processFactory.updateCellProcess();
loadXML();
this.editing = true;
File fileRDF = new File(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf('.'))+".rdf");
if(fileRDF.exists())
{
ParserRDF rdfParser = new ParserRDF(processFactory);
rdfParser.newParse(fileRDF.getAbsolutePath());
}
else
{
System.out.println("Basic Layout not yet implemented");
//apply the basic layout
}
}
else
{
temporaryFilename = "Untitled-"+ Integer.toString(instances.size()+1)+".xml";
temporaryFile = new File("Untitled-"+ Integer.toString(instances.size()+1)+".xml");
transmorpher = new Transmorpher(temporaryFilename,resource.getString("TRANSMORPHER_VERSION"),0,false);
//proccess Factory listen transmorpher modification.
transmorpher.addObserver(processFactory);
......@@ -295,7 +307,7 @@ public class FlowComposer extends JPanel implements GraphModelListener,
}
protected void initGUI(){
createStatusbar();
//updateLookAndFeel(windows);
......@@ -373,33 +385,41 @@ public class FlowComposer extends JPanel implements GraphModelListener,
newProcess("Main",MAIN);
}
protected void loadXML(){
ProcessParser parser = new ProcessParser(0,new Object[]{processFactory});
transmorpher = parser.Newparse(file.getAbsolutePath());
processFactory.createAllChannels();
processFactory.updateCellProcess();
}
/***************************************************************************************************
************************************** GUI Loading**************************************************
***************************************************************************************************/
/* Open a new editor frame. */
public static FlowComposer newEditor() {
return newEditor((String) null);
return newEditor((File) null);
}
/* Open a new editor frame. */
public static FlowComposer newEditor(String filename) {
return newEditor(filename, null);
public static FlowComposer newEditor(File file) {
return newEditor(file, null);
}
/* Open a new editor frame. */
public static FlowComposer newEditor(String filename, GraphModel model){
public static FlowComposer newEditor(File file, GraphModel model){
// Construct Frame
JFrame frame = new JFrame();
FlowComposer flowComposer = createInstance(filename,model);
FlowComposer flowComposer = createInstance(file,model);
instances.add(flowComposer);
frame.setContentPane(flowComposer);
flowComposer.setTitle((filename == null)? flowComposer.getTemporaryFilename() : filename);
frame.pack();
flowComposer.setTitle();
frame.addWindowListener(flowComposer.createCloser());
......@@ -430,10 +450,10 @@ public class FlowComposer extends JPanel implements GraphModelListener,
return flowcomposer;
}
public static FlowComposer createInstance(String filename, GraphModel model)
public static FlowComposer createInstance(File file, GraphModel model)
{
//return new FlowComposer("Untitled-"+ Integer.toString(instances.size()+1), model);
return new FlowComposer(filename, model);
return new FlowComposer(file, model);
}
public void setEditing( boolean editing){
......@@ -468,13 +488,53 @@ public class FlowComposer extends JPanel implements GraphModelListener,
}
}
return null;
}
/**
* Get the value of file.
* @return value of file.
*/
public File getFile() {return file;}
/**
* Set the value of file.
* @param v Value to assign to file.
*/
public void setFile(File v) {
this.file = v;
}
/**
* Get the value of temporaryFile.
* @return value of temporaryFile.
*/
public File getTemporaryFile() {return temporaryFile;}
/**
* Set the value of temporaryFile.
* @param v Value to assign to temporaryFile.
*/
public void setTemporaryFile(File v) {this.temporaryFile = v;}
public void setTitle(){
if(file != null)
setTitle(file.getAbsolutePath());
else if(temporaryFile != null)
setTitle(temporaryFile.getAbsolutePath());
}
public void setTitle(String file){
if(file != null)
getFrame().setTitle(title +" "+ version + " -- " + file);
}
/*
public void setTitle(File file){
if(file != null)
getFrame().setTitle(title +" "+ version + " -- " + file.getAbsolutePath());
}
*/
public String getTemporaryFilename(){
return temporaryFilename;
}
......@@ -994,41 +1054,41 @@ public class FlowComposer extends JPanel implements GraphModelListener,
protected Action[] actions = {
undoAction,
redoAction,
portRightAction,
portLeftAction,
new LoadAction(this),
zoomInAction,
new ZoomAction(this),
zoomOutAction,
new ImportAction(),
new ExportAction(),
new SaveAction(),
new SaveAsAction(),
new ExitAction(),
new SelectAction(),
new DeleteAction(),
new OptionAction(),
new NewTAction(),
new RunAction(),
new CompileAction(),
new DebugAction(),
new ExpandTAction(),
new PropertiesTAction(),
new NewPAction(),
new PropertiesPAction(),
new NewCAction(),
new ExpandCAction(),
propertiesCAction,
new NewCHAction(),
new PropertiesCHAction(),
new RedrawAction(),
new RotateAction(),
new InverseAction(),
new LoadLAction(),
new UnloadAction(),
new HelpAction()
undoAction,
redoAction,
portRightAction,
portLeftAction,
new LoadAction(this),
zoomInAction,
new ZoomAction(this),
zoomOutAction,
new ImportAction(),
new ExportAction(),
new SaveAction(),
new SaveAsAction(),
new ExitAction(),
new SelectAction(),
new DeleteAction(),
new OptionAction(),
new NewTAction(),
new RunAction(),
new CompileAction(),
new DebugAction(),
new ExpandTAction(),
new PropertiesTAction(),
new NewPAction(),
new PropertiesPAction(),
new NewCAction(),
new ExpandCAction(),
propertiesCAction,
new NewCHAction(),
new PropertiesCHAction(),
new RedrawAction(),
new RotateAction(),
new InverseAction(),
new LoadLAction(),
new UnloadAction(),
new HelpAction()
};
......@@ -1105,12 +1165,12 @@ public class FlowComposer extends JPanel implements GraphModelListener,
public void componentMoved(ComponentEvent e) { }
public void componentResized(ComponentEvent e) {
viewPortRect = sp.getViewport().getBounds();
List processList = processFactory.getAllProcess();
java.util.Iterator it = processList.iterator();
while (it.hasNext()) {
ProcessGraph process = (ProcessGraph)it.next();
resizeComponent(process);
......@@ -1121,7 +1181,7 @@ public class FlowComposer extends JPanel implements GraphModelListener,
componentResized(e);
}
public void resizeComponent(ProcessGraph process) {
viewPortRect = sp.getViewport().getBounds();
Dimension processRect = process.getPreferredSize();
......@@ -1147,7 +1207,7 @@ public class FlowComposer extends JPanel implements GraphModelListener,
}
}
/* This will change the source of the actionevent to graph. */
protected class EventRedirector implements ActionListener {
......@@ -1771,31 +1831,46 @@ public class FlowComposer extends JPanel implements GraphModelListener,
int returnVal=fc.showOpenDialog(flow);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
if (editing)
if(file.exists())
{
newEditor(file.getAbsolutePath());
}
else
{
ProcessParser processParser = new ProcessParser(3,new Object[]{processFactory});
transmorpher = processParser.Newparse(file.getAbsolutePath());
processFactory.createAllChannels();
filename = file.getAbsolutePath();
setTitle(filename);
if (editing)
{
newEditor(file);
}
else
{
setFile(file);
loadXML();
setTitle();
File fileRDF = new File(file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf('.'))+".rdf");
if(fileRDF.exists())
{
ParserRDF rdfParser = new ParserRDF(processFactory);
rdfParser.newParse(fileRDF.getAbsolutePath());
}
else
{
System.out.println("Basic Layout not yet implemented");
//apply the basic layout
}
}
editing = true;
}
ParserRDF rdfParser = new ParserRDF(processFactory);
rdfParser.newParse(filename.substring(0,filename.lastIndexOf('.'))+".rdf");
editing = true;
}
else {
//System.out.println("ta maere");
}
}
else{
Alert.show(null,"file is not found","WARNING",JOptionPane.WARNING_MESSAGE);
}
}
}
}
class PortRightAction extends AbstractAction {
private FlowComposer flow;
......@@ -1891,11 +1966,11 @@ public class FlowComposer extends JPanel implements GraphModelListener,
currentProcess.setScale(1.0);
Dimension dim = currentProcess.getPreferredSize();
int scale = currentProcess.getZoomCurrent();
System.out.println(scale+"scale");
//System.out.println(scale+"scale");
currentProcess.setZoomCurrent(2);
if (scale>2) {
for (int i=scale;i>2;i--){
System.out.println(i+"i");
//System.out.println(i+"i");
currentProcess.setPreferredSize(new Dimension((int)(dim.width/zoomSizes[i]),(int)(dim.height/zoomSizes[i])));
dim = currentProcess.getPreferredSize();
resizeComponent(currentProcess);
......@@ -1903,7 +1978,7 @@ public class FlowComposer extends JPanel implements GraphModelListener,
}
else if (scale<2) {
for (int i=scale;i<2;i++){
System.out.println(i+"i");
//System.out.println(i+"i");
currentProcess.setPreferredSize(new Dimension((int)(dim.width/zoomSizes[i]),(int)(dim.height/zoomSizes[i])));
dim = currentProcess.getPreferredSize();
resizeComponent(currentProcess);
......@@ -2020,27 +2095,27 @@ public class FlowComposer extends JPanel implements GraphModelListener,
public void actionPerformed(ActionEvent e) {
if(filename == null)
if(file == null)
{
filename = saveDialog();
if(filename == null)
setFile(new File(saveDialog()));
String filename = file.getAbsolutePath();
if(filename.equals(""))
return;
String name = filename.substring(filename.lastIndexOf(File.separatorChar)+1,filename.indexOf('.'));
transmorpher.setName(name);
setTitle(filename);
}
PrintStream out = System.out;
String directory = new File(filename).getParentFile().getAbsolutePath();
String directory = file.getParentFile().getAbsolutePath();
try{
out = new PrintStream(new BufferedOutputStream(new FileOutputStream(filename)));
out = new PrintStream(new BufferedOutputStream(new FileOutputStream(file.getAbsolutePath())));
}
catch(FileNotFoundException ex)
{
System.out.println("file not found "+ filename);
return;
Alert.show(null,"file " +file.getAbsolutePath()+"is not found","WARNING",JOptionPane.WARNING_MESSAGE);
return;
}
System.setOut(out