From 1af7d3700724834e40ad8636bc9a56cdc3b19b15 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Sat, 27 Jul 2019 11:52:38 -0400 Subject: [PATCH] New layout icons --- ObjEditor.java | 583 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 429 insertions(+), 154 deletions(-) diff --git a/ObjEditor.java b/ObjEditor.java index 7128e8d..cd7eaf9 100644 --- a/ObjEditor.java +++ b/ObjEditor.java @@ -15,6 +15,9 @@ //import javax.swing.plaf.ColorUIResource; //import javax.swing.plaf.metal.DefaultMetalTheme; +import javax.swing.plaf.basic.BasicSplitPaneDivider; +import javax.swing.plaf.basic.BasicSplitPaneUI; + //import javax.media.opengl.GLCanvas; import //weka.core. @@ -41,61 +44,47 @@ cButton GetButton(String name, boolean border) { - try - { - ImageIcon icon = GetIcon(name); - return new cButton(icon, border); - } - catch (Exception e) - { - return new cButton(name, border); - } + ImageIcon icon = GetIcon(name); + return new cButton(icon, border); } cToggleButton GetToggleButton(String name, boolean border) { - try - { - ImageIcon icon = GetIcon(name); - return new cToggleButton(icon, border); - } - catch (Exception e) - { - return new cToggleButton(name, border); - } + ImageIcon icon = GetIcon(name); + return new cToggleButton(icon, border); } cCheckBox GetCheckBox(String name, boolean border) { + ImageIcon icon = GetIcon(name); + return new cCheckBox(icon, border); + } + + private ImageIcon GetIcon(String name) + { try { - ImageIcon icon = GetIcon(name); - return new cCheckBox(icon, border); + BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name)); + + if (image.getWidth() != 24 && image.getHeight() != 24) + { + BufferedImage resized = new BufferedImage(24, 24, image.getType()); + Graphics2D g = resized.createGraphics(); + g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null); + g.dispose(); + + image = resized; + } + + javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image); + return icon; } catch (Exception e) { - return new cCheckBox(name, border); + return null; } - } - - private ImageIcon GetIcon(String name) throws IOException - { - BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name)); - - if (image.getWidth() != 24 && image.getHeight() != 24) - { - BufferedImage resized = new BufferedImage(24, 24, image.getType()); - Graphics2D g = resized.createGraphics(); - g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); - //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null); - g.dispose(); - - image = resized; - } - - javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image); - return icon; } // SCRIPT @@ -207,7 +196,7 @@ objEditor.ctrlPanel.remove(namePanel); - if (!GroupEditor.allparams) + if (!allparams) return; // objEditor.ctrlPanel.remove(liveCB); @@ -279,6 +268,12 @@ client = inClient; copy = client; + if (copy.versions == null) + { + copy.versions = new byte[100][]; + copy.versionindex = -1; + } + // "this" is not called: SetupUI2(objEditor); } @@ -292,6 +287,12 @@ client = inClient; copy = client; + if (copy.versions == null) + { + copy.versions = new byte[100][]; + copy.versionindex = -1; + } + SetupUI2(callee.GetEditor()); } @@ -306,7 +307,7 @@ //localCopy.parent = null; frame = new JFrame(); - frame.setUndecorated(true); + frame.setUndecorated(false); objEditor = this; this.callee = callee; @@ -324,6 +325,12 @@ copy = localCopy; copy.editWindow = this; + if (copy.versions == null) + { +// copy.versions = new byte[100][]; +// copy.versionindex = -1; + } + SetupMenu(); //SetupName(objEditor); // new @@ -337,12 +344,17 @@ return frame.action(event, obj); } + // Cannot work without static + static boolean allparams = true; + + static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>(); + void SetupMenu() { frame.setMenuBar(menuBar = new MenuBar()); menuBar.add(fileMenu = new Menu("File")); fileMenu.add(newItem = new MenuItem("New")); - fileMenu.add(loadItem = new MenuItem("Open...")); + fileMenu.add(openItem = new MenuItem("Open...")); //oe.menuBar.add(menu = new Menu("Include")); Menu menu = new Menu("Import"); @@ -374,7 +386,7 @@ } newItem.addActionListener(this); - loadItem.addActionListener(this); + openItem.addActionListener(this); saveItem.addActionListener(this); saveAsItem.addActionListener(this); exportAsItem.addActionListener(this); @@ -398,6 +410,11 @@ // // materialFlushed = true; // } +// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Edit")) +// { +// if (listUI.size() == 0) +// EditSelection(false); +// } refreshContents(false); // To refresh Info tab } @@ -406,11 +423,12 @@ toolbarPanel = new JPanel(); toolbarPanel.setName("Toolbar"); + treePanel = new cGridBag(); treePanel.setName("Tree"); editPanel = new cGridBag().setVertical(true); - editPanel.setName("Edit"); + //editPanel.setName("Edit"); ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout()); @@ -419,10 +437,10 @@ editPanel.add(ctrlPanel); toolboxPanel = new cGridBag().setVertical(false); - toolboxPanel.setName("Toolbox"); + //toolboxPanel.setName("Toolbox"); materialPanel = new cGridBag().setVertical(true); - materialPanel.setName("Material"); + //materialPanel.setName("Material"); /*JTextPane*/ infoarea = createTextPane(); @@ -430,14 +448,15 @@ infoarea.setEditable(true); SetText(); + // infoarea.setFont(infoarea.getFont().deriveFont(10, 14f)); // infoarea.setOpaque(false); // //infoarea.setForeground(textcolor); // TEXTAREA infoarea.setLineWrap(true); // TEXTAREA infoarea.setWrapStyleWord(true); infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED); - infoPanel.setPreferredSize(new Dimension(50, 200)); - infoPanel.setName("Info"); + infoPanel.setPreferredSize(new Dimension(1, 1)); + //infoPanel.setName("Info"); //infoPanel.setLayout(new BorderLayout()); //infoPanel.add(createTextPane()); @@ -448,7 +467,14 @@ mainPanel.setDividerSize(9); mainPanel.setDividerLocation(0.5); //1.0); mainPanel.setResizeWeight(0.5); - + +//mainPanel.setDividerSize((int) (mainPanel.getDividerSize() * 1.5)); + BasicSplitPaneDivider divider = ( (BasicSplitPaneUI) mainPanel.getUI()).getDivider(); + divider.setDividerSize(15); + divider.setBorder(BorderFactory.createTitledBorder(divider.getBorder(), "Custom border title -- gets rid of the one-touch arrows!")); + + mainPanel.setUI(new BasicSplitPaneUI()); + //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5)); //mainPanel.setLayout(new GridBagLayout()); toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); @@ -679,8 +705,8 @@ } } -static GraphicsDevice device = GraphicsEnvironment - .getLocalGraphicsEnvironment().getScreenDevices()[0]; +//static GraphicsDevice device = GraphicsEnvironment +// .getLocalGraphicsEnvironment().getScreenDevices()[0]; Rectangle keeprect; cRadio radio; @@ -701,10 +727,19 @@ void Minimize() { frame.setState(Frame.ICONIFIED); + frame.validate(); } +// artifactURI=null, type=0, property=${file.reference.jfxrt.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@6767876f, broken=false, additional={} +// artifactURI=null, type=0, property=${file.reference.mac-ui.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@16bdc817, broken=false, additional={} +// artifactURI=null, type=0, property=${file.reference.classes.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@9daa9c17, broken=false, additional={} void Maximize() { + if (CameraPane.FULLSCREEN) + { + ToggleFullScreen(); + } + if (maximized) { frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height); @@ -712,20 +747,36 @@ else { keeprect = frame.getBounds(); - Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); - Dimension rect2 = frame.getToolkit().getScreenSize(); - frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height); +// Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); +// Dimension rect2 = frame.getToolkit().getScreenSize(); +// frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height); // frame.setState(Frame.MAXIMIZED_BOTH); + frame.setBounds(frame.getGraphicsConfiguration().getBounds()); } maximized ^= true; + + frame.validate(); } + + cButton minButton; + cButton maxButton; + cButton fullButton; void ToggleFullScreen() { - if (CameraPane.FULLSCREEN) +GraphicsDevice device = frame.getGraphicsConfiguration().getDevice(); + + cameraView.ToggleFullScreen(); + + if (!CameraPane.FULLSCREEN) { device.setFullScreenWindow(null); + frame.dispose(); + frame.setUndecorated(false); + frame.validate(); + frame.setVisible(true); + //frame.setVisible(false); // frame.removeNotify(); // frame.setUndecorated(false); @@ -735,7 +786,7 @@ // X frame.getContentPane().remove(/*"Center",*/bigThree); // X framePanel.add(bigThree); // X frame.getContentPane().add(/*"Center",*/framePanel); - framePanel.setDividerLocation(1); + framePanel.setDividerLocation(46); //frame.setVisible(true); radio.layout = keepButton; @@ -750,7 +801,12 @@ // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width, // frame.getToolkit().getScreenSize().height); //frame.setVisible(false); + + frame.dispose(); + frame.setUndecorated(true); device.setFullScreenWindow(frame); + frame.validate(); + frame.setVisible(true); // frame.removeNotify(); // frame.setUndecorated(true); // frame.addNotify(); @@ -763,9 +819,30 @@ radio.layout.doClick(); //frame.setVisible(true); } - - cameraView.ToggleFullScreen(); + frame.validate(); } + + private byte[] CompressCopy() + { + boolean temp = CameraPane.SWITCH; + CameraPane.SWITCH = false; + + copy.ExtractBigData(versiontable); + // if (copy == client) + + byte[] versions[] = copy.versions; + copy.versions = null; + + byte[] compress = Compress(copy); + + copy.versions = versions; + + copy.RestoreBigData(versiontable); + + CameraPane.SWITCH = temp; + + return compress; + } private JTextPane createTextPane() { @@ -897,7 +974,7 @@ // NumberSlider vDivsField; // JCheckBox endcaps; JCheckBox liveCB; - JCheckBox selectCB; + JCheckBox selectableCB; JCheckBox hideCB; JCheckBox link2masterCB; JCheckBox markCB; @@ -1097,38 +1174,40 @@ namePanel = new cGridBag(); nameField = AddText(namePanel, copy.GetName()); - namePanel.add(nameField); + namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER)); oe.ctrlPanel.add(namePanel); oe.ctrlPanel.Return(); - if (!GroupEditor.allparams) + if (!allparams) return; setupPanel = new cGridBag().setVertical(false); liveCB = AddCheckBox(setupPanel, "Live", copy.live); liveCB.setToolTipText("Animate object"); - selectCB = AddCheckBox(setupPanel, "Select", !copy.dontselect); - selectCB.setToolTipText("Make object selectable"); + selectableCB = AddCheckBox(setupPanel, "Select", !copy.dontselect); + selectableCB.setToolTipText("Make object selectable"); // Return(); + hideCB = AddCheckBox(setupPanel, "Hide", copy.hide); hideCB.setToolTipText("Hide object"); markCB = AddCheckBox(setupPanel, "Mark", copy.marked); - markCB.setToolTipText("Set the animation target transform"); + markCB.setToolTipText("As animation target transform"); setupPanel2 = new cGridBag().setVertical(false); rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind); rewindCB.setToolTipText("Rewind animation"); - randomCB = AddCheckBox(setupPanel2, "Rand", copy.random); - randomCB.setToolTipText("Randomly Rewind or Go back and forth"); + randomCB = AddCheckBox(setupPanel2, "Random", copy.random); + randomCB.setToolTipText("Randomly Rewind (or Go back and forth)"); + link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master); + link2masterCB.setToolTipText("Attach to support"); + if (Globals.ADVANCED) { - link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master); - link2masterCB.setToolTipText("Attach to support"); speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup); speedupCB.setToolTipText("Option motion capture"); } @@ -1402,6 +1481,7 @@ XYZPanel.addComponent(/*BorderLayout.SOUTH,*/sideView); // Scroll); XYZPanel.addComponent(/*BorderLayout.CENTER,*/frontView); // Scroll); XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll); + //XYZPanel.setName("XYZ"); /* gridPanel = new JPanel(); //new BorderLayout()); @@ -1439,13 +1519,23 @@ //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //tmp.setName("Edit"); objectPanel.add(materialPanel); - objectPanel.add(toolboxPanel); + objectPanel.setIconAt(0, GetIcon("icons/material.png")); // JPanel north = new JPanel(new BorderLayout()); // north.setName("Edit"); // north.add(ctrlPanel, BorderLayout.NORTH); // objectPanel.add(north); objectPanel.add(editPanel); - objectPanel.add(infoPanel); + objectPanel.setIconAt(1, GetIcon("icons/write.png")); + + //if (Globals.ADVANCED) + objectPanel.add(infoPanel); + objectPanel.setIconAt(2, GetIcon("icons/info.png")); + + objectPanel.add(XYZPanel); + objectPanel.setIconAt(3, GetIcon("icons/XYZ.png")); + + objectPanel.add(toolboxPanel); + objectPanel.setIconAt(4, GetIcon("icons/primitives.png")); /* aConstraints.gridx = 0; @@ -1454,7 +1544,7 @@ aConstraints.gridy += 1; aConstraints.gridwidth = 1; mainPanel.add(objectPanel, aConstraints); - */ + */ scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS, VERTICAL_SCROLLBAR_AS_NEEDED, @@ -1466,7 +1556,7 @@ scrollpane.addMouseWheelListener(this); // Default not fast enough /*JTabbedPane*/ scenePanel = new cGridBag(); - scenePanel.preferredWidth = 6; + scenePanel.preferredWidth = 5; JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.add(scrollpane); @@ -1542,9 +1632,9 @@ /**/ bigThree = new cGridBag(); - bigThree.addComponent(scenePanel); bigThree.addComponent(centralPanel); - bigThree.addComponent(XYZPanel); + bigThree.addComponent(scenePanel); + //bigThree.addComponent(XYZPanel); // // SIDE EFFECT!!! // aConstraints.gridx = 0; @@ -1553,9 +1643,9 @@ // aConstraints.gridheight = 1; framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree); - framePanel.setContinuousLayout(true); - framePanel.setOneTouchExpandable(true); - framePanel.setDividerLocation(0.8); + framePanel.setContinuousLayout(false); + framePanel.setOneTouchExpandable(false); + //.setDividerLocation(0.8); //framePanel.setDividerSize(15); //framePanel.setResizeWeight(0.15); framePanel.setName("Frame"); @@ -1574,12 +1664,13 @@ frame.setSize(1280, 860); - frame.validate(); - frame.setVisible(true); - cameraView.requestFocusInWindow(); gridPanel.setDividerLocation(1.0); + + frame.validate(); + + frame.setVisible(true); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() @@ -1666,24 +1757,6 @@ texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints); colorSection.add(texture); - cGridBag anisoU = new cGridBag(); - anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints); - anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING); - anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints); - colorSection.add(anisoU); - - cGridBag anisoV = new cGridBag(); - anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints); - anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING); - anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints); - colorSection.add(anisoV); - - cGridBag shadowbias = new cGridBag(); - shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints); - shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING); - shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints); - colorSection.add(shadowbias); - panel.add(new JSeparator()); panel.add(colorSection); @@ -1733,6 +1806,12 @@ fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING); fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints); diffuseSection.add(fakedepth); + + cGridBag shadowbias = new cGridBag(); + shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints); + shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING); + shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints); + diffuseSection.add(shadowbias); panel.add(new JSeparator()); @@ -1784,6 +1863,18 @@ // aConstraints.gridy += 1; // aConstraints.gridwidth = 1; + cGridBag anisoU = new cGridBag(); + anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints); + anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING); + anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints); + specularSection.add(anisoU); + + cGridBag anisoV = new cGridBag(); + anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints); + anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING); + anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints); + specularSection.add(anisoV); + panel.add(new JSeparator()); @@ -1791,35 +1882,35 @@ //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints); - cGridBag globalSection = new cGridBag().setVertical(true); + //cGridBag globalSection = new cGridBag().setVertical(true); cGridBag camera = new cGridBag(); camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints); cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING); camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints); - globalSection.add(camera); + colorSection.add(camera); cGridBag ambient = new cGridBag(); ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints); ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING); ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints); - globalSection.add(ambient); + colorSection.add(ambient); cGridBag backlit = new cGridBag(); backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints); backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING); backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints); - globalSection.add(backlit); + colorSection.add(backlit); cGridBag opacity = new cGridBag(); opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints); opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING); opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints); - globalSection.add(opacity); + colorSection.add(opacity); - panel.add(new JSeparator()); + //panel.add(new JSeparator()); - panel.add(globalSection); + //panel.add(globalSection); //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints); @@ -1926,8 +2017,9 @@ // 3D models if (filename.endsWith(".3ds") || filename.endsWith(".3DS")) { - lastConverter = new com.jmex.model.converters.MaxToJme(); - LoadFile(filename, lastConverter); + //lastConverter = new com.jmex.model.converters.MaxToJme(); + //LoadFile(filename, lastConverter); + LoadObjFile(filename); // New 3ds loader continue; } if (filename.endsWith(".dae") || filename.endsWith(".DAE")) @@ -2653,6 +2745,7 @@ LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2); LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2); } + //cJME.count++; //cJME.count %= 12; if (gc) @@ -2836,6 +2929,7 @@ } } } + cFileSystemPane FSPane; void SetMaterial(cMaterial mat, Object3D.cVector2[] others) @@ -2889,6 +2983,7 @@ } } } + freezematerial = false; } @@ -3007,12 +3102,17 @@ // } /**/ - if (deselect) + if (deselect || child == null) { //group.deselectAll(); //freeze = true; GetTree().clearSelection(); //freeze = false; + + if (child == null) + { + return; + } } //group.addSelectee(child); @@ -3151,7 +3251,7 @@ { copy.live ^= true; return; - } else if (event.getSource() == selectCB) + } else if (event.getSource() == selectableCB) { copy.dontselect ^= true; return; @@ -3336,9 +3436,9 @@ { Close(); //return true; - } else if (source == loadItem) + } else if (source == openItem) { - load(); + Open(); //return true; } else if (source == newItem) { @@ -3363,6 +3463,10 @@ { generatePOV(); //return true; + } else if (event.getSource() == archiveItem) + { + cTools.Archive(frame); + return; } else if (source == zBufferItem) { try @@ -3414,8 +3518,8 @@ try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos); - ObjectOutputStream out = new ObjectOutputStream(zstream); +// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos); + ObjectOutputStream out = new ObjectOutputStream(baos); //zstream); Object3D parent = o.parent; o.parent = null; @@ -3426,10 +3530,14 @@ out.flush(); - zstream.close(); + baos //zstream + .close(); out.close(); - return baos.toByteArray(); + byte[] bytes = baos.toByteArray(); + + System.out.println("save #bytes = " + bytes.length); + return bytes; } catch (Exception e) { System.err.println(e); @@ -3439,13 +3547,16 @@ static public Object Uncompress(byte[] bytes) { - System.out.println("#bytes = " + bytes.length); + System.out.println("restore #bytes = " + bytes.length); try { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais); - ObjectInputStream in = new ObjectInputStream(istream); + //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais); + ObjectInputStream in = new ObjectInputStream(bais); // istream); Object obj = in.readObject(); + + bais //istream + .close(); in.close(); return obj; @@ -3500,39 +3611,77 @@ return null; } - java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>(); public void Save() + { + //Save(true); + Replace(); + } + + private boolean Equal(byte[] compress, byte[] name) + { + if (compress.length != name.length) + { + return false; + } + + for (int i=compress.length; --i>=0;) + { + if (compress[i] != name[i]) + return false; + } + + return true; + } + + java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>(); + + public boolean Save(boolean user) { System.err.println("Save"); cRadio tab = GetCurrentTab(); - boolean temp = CameraPane.SWITCH; - CameraPane.SWITCH = false; + byte[] compress = CompressCopy(); - copy.ExtractBigData(hashtable); + boolean thesame = false; + + // Quick heuristic using length. Works only when stream is compressed. + if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1])) + { + thesame = true; + } //EditorFrame.m_MainFrame.requestFocusInWindow(); - tab.graphs[tab.undoindex++] = Compress(copy); - - copy.RestoreBigData(hashtable); - - CameraPane.SWITCH = temp; - - //assert(hashtable.isEmpty()); - - for (int i = tab.undoindex; i < tab.graphs.length; i++) + if (!thesame) { - tab.graphs[i] = null; + //tab.user[tab.versionindex] = user; + //boolean increment = true; // tab.graphs[tab.versionindex] == null; + + copy.versions[++copy.versionindex] = compress; + + // if (increment) + // tab.versionindex++; } + //copy.RestoreBigData(versiontable); + + //assert(hashtable.isEmpty()); + + for (int i = copy.versionindex+1; i < copy.versions.length; i++) + { + //tab.user[i] = false; + copy.versions[i] = null; + } + + SetUndoStates(); + // test save if (false) { try { - FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex); + FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex); ObjectOutputStream p = new ObjectOutputStream(ostream); p.writeObject(copy); @@ -3545,14 +3694,18 @@ e.printStackTrace(); } } + + return !thesame; } void CopyChanged(Object3D obj) { + SetUndoStates(); + boolean temp = CameraPane.SWITCH; CameraPane.SWITCH = false; - copy.ExtractBigData(hashtable); + copy.ExtractBigData(versiontable); copy.clear(); @@ -3561,7 +3714,7 @@ copy.add(obj.get(i)); } - copy.RestoreBigData(hashtable); + copy.RestoreBigData(versiontable); CameraPane.SWITCH = temp; @@ -3588,42 +3741,130 @@ refreshContents(); } - public void Undo() + cButton undoButton; + cButton restoreButton; + cButton replaceButton; + cButton redoButton; + + boolean muteSlider; + + int VersionCount() { + int count = 0; + + for (int i = copy.versions.length; --i >= 0;) + { + if (copy.versions[i] != null) + count++; + } + + return count; + } + + void SetUndoStates() + { + cRadio tab = GetCurrentTab(); + + restoreButton.setEnabled(copy.versionindex != -1); + replaceButton.setEnabled(copy.versionindex != -1); + + undoButton.setEnabled(copy.versionindex > 0); + redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null); + + muteSlider = true; + versionSlider.setMaximum(VersionCount() - 1); + versionSlider.setInteger(copy.versionindex); + muteSlider = false; + } + + public boolean Undo() + { + // Option? + Replace(); + System.err.println("Undo"); cRadio tab = GetCurrentTab(); - if (tab.undoindex == 0) + if (copy.versionindex == 0) { java.awt.Toolkit.getDefaultToolkit().beep(); - return; + return false; } - if (tab.graphs[tab.undoindex] == null) +// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex]) +// { +// if (Save(false)) +// tab.versionindex -= 1; +// else +// { +// if (tab.versionindex <= 0) +// return false; +// else +// tab.versionindex -= 1; +// } +// } + + copy.versionindex -= 1; + + CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex])); + + return true; + } + + public boolean Restore() + { + System.err.println("Restore"); + + cRadio tab = GetCurrentTab(); + + if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null) { - Save(); - tab.undoindex -= 1; + java.awt.Toolkit.getDefaultToolkit().beep(); + return false; } - tab.undoindex -= 1; + CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex])); + + return true; + } - CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex])); + public boolean Replace() + { + System.err.println("Replace"); + + cRadio tab = GetCurrentTab(); + + if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null) + { + // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep(); + return false; + } + + copy.versions[copy.versionindex] = CompressCopy(); + + return true; } public void Redo() { + // Option? + Replace(); + cRadio tab = GetCurrentTab(); - if (tab.graphs[tab.undoindex + 1] == null) + if (copy.versions[copy.versionindex + 1] == null) { java.awt.Toolkit.getDefaultToolkit().beep(); return; } - tab.undoindex += 1; + copy.versionindex += 1; - CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex])); + CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex])); + + //if (!tab.user[tab.versionindex]) + // tab.graphs[tab.versionindex] = null; } void ImportGFD() @@ -3919,9 +4160,25 @@ //copy.Touch(); } + cNumberSlider versionSlider; + public void stateChanged(ChangeEvent e) { // assert(false); + if (e.getSource() == versionSlider) + { + if (muteSlider) + return; + + int version = versionSlider.getInteger(); + + if (copy.versions[version] != null) + { + CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version])); + } + + return; + } if (freezematerial) { @@ -4270,7 +4527,7 @@ void makeSomething(Object3D thing, boolean resetmodel) // deselect) { - if (Globals.SAVEONMAKE) // && resetmodel) + if (Globals.REPLACEONMAKE) // && resetmodel) Save(); //Tween.set(thing, 0).target(1).start(tweenManager); //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager); @@ -4512,7 +4769,9 @@ readobj.ResetDisplayList(); } catch (Exception e) { - //e.printStackTrace(); + if (!e.toString().contains("GZIP")) + e.printStackTrace(); + try { java.io.FileInputStream istream = new java.io.FileInputStream(fullname); @@ -4586,8 +4845,8 @@ if (readobj != null) { - if (Globals.SAVEONMAKE) - Save(); + //if (Globals.SAVEONMAKE) // A new object cannot share meshes + // Save(); try { //readobj.deepCopySelf(copy); @@ -4632,6 +4891,7 @@ } } catch (ClassCastException e) { + e.printStackTrace(); assert (false); Composite c = (Composite) copy; c.children.clear(); @@ -4642,13 +4902,24 @@ c.addChild(csg); } + copy.versions = readobj.versions; + copy.versionindex = readobj.versionindex; + + if (copy.versions == null) + { + copy.versions = new byte[100][]; + copy.versionindex = -1; + } + + //? SetUndoStates(); + ResetModel(); copy.HardTouch(); // recompile? refreshContents(); } } - void load() // throws ClassNotFoundException + void Open() // throws ClassNotFoundException { if (Grafreed.standAlone) { @@ -4751,6 +5022,7 @@ //ps.print(buffer.toString()); } catch (IOException e) { + e.printStackTrace(); } } @@ -4765,6 +5037,8 @@ String filename = browser.getFile(); if (filename != null && filename.length() > 0) { + if (!filename.endsWith(".gfd")) + filename += ".gfd"; lastname = browser.getDirectory() + filename; save(); } @@ -4931,7 +5205,7 @@ MenuBar menuBar; Menu fileMenu; MenuItem newItem; - MenuItem loadItem; + MenuItem openItem; MenuItem saveItem; MenuItem saveAsItem; MenuItem exportAsItem; @@ -4954,6 +5228,7 @@ CheckboxMenuItem toggleSwitchItem; CheckboxMenuItem toggleRootItem; CheckboxMenuItem animationItem; + MenuItem archiveItem; CheckboxMenuItem toggleHandleItem; CheckboxMenuItem togglePaintItem; JSplitPane mainPanel; -- Gitblit v1.6.2