Logo Search packages:      
Sourcecode: latexdraw version File versions  Download package

boolean latexDraw::ui::LaTeXDrawFrame::open ( String  fileName,
boolean  withDialog 
) [inline]

Allows to load a saved project

Definition at line 3521 of file LaTeXDrawFrame.java.

References latexDraw::ui::dialog::PreferencesFrame::addRecentFile(), codePanel, currentFile, latexDraw::ui::DrawContainer::displayBorders(), displayCodePanel(), latexDraw::ui::DrawPanel::draw, drawPanel, fileChooserOpen, formerDividerLocation, formerIsInAutoUpdate, latexDraw::ui::components::LMenuBar::getAutoAdjustBorders(), latexDraw::ui::components::LToolbar::getButtonImageBorders(), latexDraw::ui::components::LMenuBar::getDisplayBorders(), latexDraw::ui::components::LMenuBar::getDisplayGrid(), latexDraw::ui::components::LMenuBar::getDisplayPersoGrid(), latexDraw::ui::components::LMenuBar::getDisplayXScale(), latexDraw::ui::components::LMenuBar::getDisplayYScale(), latexDraw::ui::DrawPanel::getDraw(), latexDraw::ui::DrawContainer::getFigures(), latexDraw::ui::components::LToolbar::getMagneticCB(), latexDraw::ui::components::LToolbar::getPersoGridGapField(), latexDraw::ui::DrawContainer::getPersonalGridGap(), latexDraw::ui::components::LToolbar::getSliderDelimitor(), isCodePanelDisplayed(), latexDraw::ui::DrawPanel::isGridDisplayed(), latexDraw::ui::DrawPanel::isGridMagnetic(), latexDraw::ui::DrawContainer::isSelection(), menuBar, latexDraw::ui::DrawContainer::open(), pathOpen, preferencesFrame, latexDraw::ui::DrawContainer::readObject(), reinitializeButtons(), latexDraw::ui::DrawContainer::setAutoAdjustement(), latexDraw::ui::CodePanel::setCaption(), latexDraw::ui::DrawContainer::setClassicGridDrawn(), latexDraw::ui::CodePanel::setComments(), latexDraw::ui::DrawPanel::setDraw(), setExportAsMenu(), latexDraw::util::UndoRedoManager::setFigures(), latexDraw::ui::components::progressbars::AbstractProgressBarManager::setFileToParse(), latexDraw::ui::DrawPanel::setGridIsMagnetic(), latexDraw::ui::DrawPanel::setIsGridDisplay(), latexDraw::ui::CodePanel::setIsInAutoUpdate(), setIsModified(), latexDraw::ui::CodePanel::setLabel(), latexDraw::ui::DrawContainer::setParentPanel(), latexDraw::ui::DrawContainer::setPersonalGridGap(), latexDraw::ui::CodePanel::setPositionHoriToken(), latexDraw::ui::CodePanel::setPositionVertToken(), setSelection(), setStatusBarText(), setTitle(), splitPane, latexDraw::ui::components::progressbars::AbstractProgressBarManager::startProgressBar(), toolbar, undoManager, latexDraw::ui::DrawPanel::updateDraw(), latexDraw::ui::components::LMenuBar::updateRecentFilesMenu(), updateUndoRedo(), and versionOfFile.

Referenced by LaTeXDrawFrame().

      {
            File file;
            
            if(fileName==null)
            {
                  if(fileChooserOpen==null)     
                  {
                        fileChooserOpen = new JFileChooser(pathOpen);
                        fileChooserOpen.setFileSelectionMode(JFileChooser.FILES_ONLY);
                        fileChooserOpen.addChoosableFileFilter(new LaTeXDrawFilter());
                        fileChooserOpen.addChoosableFileFilter(new SVGFilter());
                        fileChooserOpen.setMultiSelectionEnabled(false);
                        fileChooserOpen.setDialogTitle(LaTeXDrawLang.getStringLaTeXDrawFrame("LaTeXDrawFrame.200")); //$NON-NLS-1$
                  }
                  
                  int id = fileChooserOpen.showOpenDialog(this);
                  
                  if(id != JFileChooser.APPROVE_OPTION)
                        return false;
                  
                  file = fileChooserOpen.getSelectedFile();
                  
                  if(file==null) 
                        return false;
            }
            else
                  file = new File(fileName);
            
            setIsModified(false);
            newProject();
            currentFile = file;
            reinitializeButtons();
            setStatusBarText(LaTeXDrawLang.getStringLaTeXDrawFrame("LaTeXDrawFrame.201")); //$NON-NLS-1$
            projectName = file.getName();
            setExportAsMenu(true);
            
            String ext = projectName.endsWith(LaTeXDrawResources.PROJECT_EXTENSION) ? LaTeXDrawResources.PROJECT_EXTENSION : SVGFilter.SVG_EXTENSION;
            int id = projectName.toLowerCase().indexOf(ext.toLowerCase());
            
            if(id !=-1)             
                  projectName = projectName.substring(0, id);
          
          if(file.exists() && file.isFile() && file.canRead()) 
          {
            try 
            {
                  if(ext.equals(SVGFilter.SVG_EXTENSION))
                  {
                        if(progressbarSVG==null)
                              progressbarSVG = new SVGProgressBarManager(this);
                        
                        progressbarSVG.setFileToParse(file);
                        progressbarSVG.startProgressBar();
                  }
                  else
                  {
                              ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
                      DrawContainer draw;
                      
                              if(!LaTeXDrawResources.LABEL_APP.equals(in.readObject()))
                                    new LaTeXDrawException(LaTeXDrawException.NOT_TEXDRAW_FILE);
      
                              versionOfFile = (String)in.readObject();
                              boolean autoUpd = in.readBoolean();
                              formerIsInAutoUpdate = in.readBoolean();
                              boolean displayB = in.readBoolean();
                              menuBar.getAutoAdjustBorders().setSelected(in.readBoolean());
                              
                      if(LaTeXDrawFrame.getVersionOfFile().compareTo("1.9.3")>=0) //$NON-NLS-1$
                              {
                                    draw = new DrawContainer();
                                    draw.open(in);
                              }
                              else
                                    draw = (DrawContainer)in.readObject(); 
                      
                              drawPanel.setDraw(draw);
                              draw = drawPanel.getDraw();
                              draw.isSelection(false);
                              toolbar.getSliderDelimitor().setValue(Delimitor.getOpacity());
                              menuBar.getDisplayBorders().setSelected(displayB);
                              draw.setParentPanel(drawPanel);
                              draw.setAutoAdjustement(menuBar.getAutoAdjustBorders().isSelected());                     
                              draw.displayBorders(displayB);      
                              undoManager.setFigures(draw.getFigures());
                              setPreferredSize((Dimension)in.readObject());
                              Point location = (Point)in.readObject();
                              setLocation(new Point(Math.max(0, location.x), Math.max(0, location.y)));
                              splitPane.setDividerLocation(in.readInt());
                              displayCodePanel(in.readBoolean());
                              codePanel.setIsInAutoUpdate(autoUpd);
                              Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                              formerDividerLocation=(int)(dim.width*0.7);
                              formerIsInAutoUpdate = !isCodePanelDisplayed();
                              toolbar.getButtonImageBorders().setSelected(menuBar.getDisplayBorders().isSelected());
                              drawPanel.setIsGridDisplay(in.readBoolean());
                              menuBar.getDisplayXScale().setSelected(in.readBoolean());
                              menuBar.getDisplayYScale().setSelected(in.readBoolean());
                              codePanel.setComments((String) in.readObject());
                              
                              if(LaTeXDrawFrame.getVersionOfFile().compareTo("1.6")>=0) //$NON-NLS-1$
                              {
                                    codePanel.setLabel((String)in.readObject());
                                    codePanel.setCaption((String)in.readObject());
                                    codePanel.setPositionHoriToken((String)in.readObject());
                                    codePanel.setPositionVertToken((String)in.readObject());
                              }
                              
                              if(LaTeXDrawFrame.getVersionOfFile().compareTo("1.8")>=0) //$NON-NLS-1$
                              {
                                    drawPanel.setGridIsMagnetic(in.readBoolean());
                                    toolbar.getMagneticCB().setSelected(drawPanel.isGridMagnetic());
                                    boolean isClassicGrid = in.readBoolean();
                                    menuBar.getDisplayGrid().setSelected(isClassicGrid && drawPanel.isGridDisplayed());
                                    menuBar.getDisplayPersoGrid().setSelected(!isClassicGrid && drawPanel.isGridDisplayed());
                                    toolbar.getPersoGridGapField().setEnabled(menuBar.getDisplayPersoGrid().isSelected());
                                    drawPanel.draw.setClassicGridDrawn(isClassicGrid);
                                    drawPanel.draw.setPersonalGridGap(in.readInt());
                                    toolbar.getPersoGridGapField().setValue(drawPanel.draw.getPersonalGridGap());
                              }
                              else
                              {
                                    menuBar.getDisplayGrid().setSelected(drawPanel.isGridDisplayed());
                                    menuBar.getDisplayPersoGrid().setSelected(false);
                                    toolbar.getPersoGridGapField().setEnabled(false);
                              }
                              
                              if(LaTeXDrawFrame.getVersionOfFile().compareTo("1.9")>=0) //$NON-NLS-1$
                              {
                                    Delimitor.setOpacity(in.readInt());
                                    toolbar.getSliderDelimitor().setValue(Delimitor.getOpacity());
                              }
                              
                              currentFile = new File(currentFile.getPath().substring(0, 
                                          currentFile.getPath().length()-LaTeXDrawResources.PROJECT_EXTENSION.length())+SVGFilter.SVG_EXTENSION);
                              drawPanel.updateDraw(true);
                              in.close(); 
                              
                              setTitle();
                              undoManager = new UndoRedoManager(drawPanel.getDraw().getFigures(), drawPanel.getDraw(), this);
                              updateUndoRedo();
                              setSelection(false);
                              setIsModified(false);
                              preferencesFrame.addRecentFile(file.getAbsolutePath());
                              menuBar.updateRecentFilesMenu();
                              setStatusBarText(LaTeXDrawLang.getStringLaTeXDrawFrame("LaTeXDrawFrame.202")); //$NON-NLS-1$
                  }
                  }
            catch(InvalidClassException ex)
            {
                  currentFile = null;
                  setIsModified(false);
                  
                  if(withDialog)
                        JOptionPane.showMessageDialog(this, LaTeXDrawLang.getString1_9("LaTeXDrawFrame.12"),  //$NON-NLS-1$
                                        LaTeXDrawLang.getStringLaTeXDrawFrame("LaTeXDrawFrame.86"), JOptionPane.WARNING_MESSAGE);  //$NON-NLS-1$
                        return false;
            }
                  catch(Exception ex) 
                  {
                        setIsModified(false);
                        currentFile = null;
                        setStatusBarText(LaTeXDrawLang.getStringLaTeXDrawFrame("LaTeXDrawFrame.203")); //$NON-NLS-1$
                        ex.printStackTrace(); 
                        
                        if(withDialog)
                              JOptionPane.showMessageDialog(this, 
                                        LaTeXDrawLang.getStringLaTeXDrawFrame("LaTeXDrawFrame.204") + ex.toString(), //$NON-NLS-1$
                                        LaTeXDrawLang.getStringLaTeXDrawFrame("LaTeXDrawFrame.86"), JOptionPane.WARNING_MESSAGE);   //$NON-NLS-1$
                        return false;
                  }
          }
          else
          {
            setIsModified(false);
                  currentFile = null;
                  setStatusBarText(LaTeXDrawLang.getStringLaTeXDrawFrame("LaTeXDrawFrame.203")); //$NON-NLS-1$
                  
                  if(withDialog)
                        JOptionPane.showMessageDialog(this, LaTeXDrawLang.getStringLaTeXDrawFrame("LFrame2.18"), //$NON-NLS-1$
                                  LaTeXDrawLang.getStringLaTeXDrawFrame("LaTeXDrawFrame.86"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
                  return false;
          }

          return true;
      }


Generated by  Doxygen 1.6.0   Back to index