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 | 829 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 705 insertions(+), 124 deletions(-) diff --git a/ObjEditor.java b/ObjEditor.java index 422d126..cd7eaf9 100644 --- a/ObjEditor.java +++ b/ObjEditor.java @@ -4,6 +4,7 @@ import java.awt.*; import java.awt.event.*; +import java.awt.image.BufferedImage; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; @@ -13,6 +14,9 @@ import javax.swing.plaf.metal.MetalLookAndFeel; //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; @@ -35,6 +39,53 @@ GroupEditor callee; JFrame frame; + + static ObjEditor theFrame; + + cButton GetButton(String name, boolean border) + { + ImageIcon icon = GetIcon(name); + return new cButton(icon, border); + } + + cToggleButton GetToggleButton(String name, boolean 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 + { + 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 null; + } + } // SCRIPT @@ -145,7 +196,7 @@ objEditor.ctrlPanel.remove(namePanel); - if (!GroupEditor.allparams) + if (!allparams) return; // objEditor.ctrlPanel.remove(liveCB); @@ -168,7 +219,8 @@ // objEditor.ctrlPanel.remove(remarkButton); objEditor.ctrlPanel.remove(setupPanel); - objEditor.ctrlPanel.remove(commandsPanel); + objEditor.ctrlPanel.remove(setupPanel2); + objEditor.ctrlPanel.remove(objectCommandsPanel); objEditor.ctrlPanel.remove(pushPanel); //objEditor.ctrlPanel.remove(fillPanel); @@ -216,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); } @@ -229,6 +287,12 @@ client = inClient; copy = client; + if (copy.versions == null) + { + copy.versions = new byte[100][]; + copy.versionindex = -1; + } + SetupUI2(callee.GetEditor()); } @@ -243,6 +307,7 @@ //localCopy.parent = null; frame = new JFrame(); + frame.setUndecorated(false); objEditor = this; this.callee = callee; @@ -260,6 +325,12 @@ copy = localCopy; copy.editWindow = this; + if (copy.versions == null) + { +// copy.versions = new byte[100][]; +// copy.versionindex = -1; + } + SetupMenu(); //SetupName(objEditor); // new @@ -273,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("Load...")); + fileMenu.add(openItem = new MenuItem("Open...")); //oe.menuBar.add(menu = new Menu("Include")); Menu menu = new Menu("Import"); @@ -310,7 +386,7 @@ } newItem.addActionListener(this); - loadItem.addActionListener(this); + openItem.addActionListener(this); saveItem.addActionListener(this); saveAsItem.addActionListener(this); exportAsItem.addActionListener(this); @@ -319,28 +395,68 @@ closeItem.addActionListener(this); objectPanel = new JTabbedPane(); + + ChangeListener changeListener = new ChangeListener() + { + public void stateChanged(ChangeEvent changeEvent) + { +// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Material") && !materialFlushed) +// { +// if (latestObject != null) +// { +// refreshContents(true); +// SetMaterial(latestObject); +// } +// +// materialFlushed = true; +// } +// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Edit")) +// { +// if (listUI.size() == 0) +// EditSelection(false); +// } + + refreshContents(false); // To refresh Info tab + } + }; + objectPanel.addChangeListener(changeListener); + toolbarPanel = new JPanel(); toolbarPanel.setName("Toolbar"); + treePanel = new cGridBag(); treePanel.setName("Tree"); + + editPanel = new cGridBag().setVertical(true); + //editPanel.setName("Edit"); + ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout()); - ctrlPanel.setName("Edit"); + + editCommandsPanel = new cGridBag(); + editPanel.add(editCommandsPanel); + editPanel.add(ctrlPanel); + + toolboxPanel = new cGridBag().setVertical(false); + //toolboxPanel.setName("Toolbox"); + materialPanel = new cGridBag().setVertical(true); - materialPanel.setName("Material"); + //materialPanel.setName("Material"); + /*JTextPane*/ infoarea = createTextPane(); doc = infoarea.getStyledDocument(); 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()); @@ -351,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)); @@ -419,10 +542,10 @@ e.printStackTrace(); } - String selection = infoarea.getText(); - java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection); - java.awt.datatransfer.Clipboard clipboard = - Toolkit.getDefaultToolkit().getSystemClipboard(); +// String selection = infoarea.getText(); +// java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection); +// java.awt.datatransfer.Clipboard clipboard = +// Toolkit.getDefaultToolkit().getSystemClipboard(); //clipboard.setContents(data, data); } @@ -582,21 +705,144 @@ } } +//static GraphicsDevice device = GraphicsEnvironment +// .getLocalGraphicsEnvironment().getScreenDevices()[0]; + + Rectangle keeprect; + cRadio radio; + +cButton keepButton; + cButton twoButton; // Full 3D + cButton sixButton; + cButton threeButton; + cButton sevenButton; + cButton fourButton; // full panel + cButton oneButton; // full XYZ + //cButton currentLayout; + + boolean maximized; + + cButton fullscreenLayout; + + 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); + } + 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); +// 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) { - frame.getContentPane().remove(/*"Center",*/bigThree); - framePanel.add(bigThree); - frame.getContentPane().add(/*"Center",*/framePanel); + device.setFullScreenWindow(null); + frame.dispose(); + frame.setUndecorated(false); + frame.validate(); + frame.setVisible(true); + + //frame.setVisible(false); +// frame.removeNotify(); +// frame.setUndecorated(false); +// frame.addNotify(); + //frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height); + +// X frame.getContentPane().remove(/*"Center",*/bigThree); +// X framePanel.add(bigThree); +// X frame.getContentPane().add(/*"Center",*/framePanel); + framePanel.setDividerLocation(46); + + //frame.setVisible(true); + radio.layout = keepButton; + //theFrame = null; + keepButton = null; + radio.layout.doClick(); + } else { - frame.getContentPane().remove(/*"Center",*/framePanel); - framePanel.remove(bigThree); - frame.getContentPane().add(/*"Center",*/bigThree); + keepButton = radio.layout; + //keeprect = frame.getBounds(); +// 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(); +// X frame.getContentPane().remove(/*"Center",*/framePanel); +// X framePanel.remove(bigThree); +// X frame.getContentPane().add(/*"Center",*/bigThree); + framePanel.setDividerLocation(0); + + radio.layout = fullscreenLayout; + 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() { @@ -728,7 +974,7 @@ // NumberSlider vDivsField; // JCheckBox endcaps; JCheckBox liveCB; - JCheckBox selectCB; + JCheckBox selectableCB; JCheckBox hideCB; JCheckBox link2masterCB; JCheckBox markCB; @@ -736,7 +982,12 @@ JCheckBox speedupCB; JCheckBox rewindCB; JCheckBox flipVCB; + + cCheckBox toggleTextureCB; + cCheckBox toggleSwitchCB; + JComboBox texresMenu; + JButton resetButton; JButton stepButton; JButton stepAllButton; @@ -745,9 +996,13 @@ JButton fasterButton; JButton remarkButton; + cGridBag editPanel; + cGridBag editCommandsPanel; + cGridBag namePanel; cGridBag setupPanel; - cGridBag commandsPanel; + cGridBag setupPanel2; + cGridBag objectCommandsPanel; cGridBag pushPanel; cGridBag fillPanel; @@ -919,60 +1174,66 @@ 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"); - rewindCB = AddCheckBox(setupPanel, "Rewind", copy.rewind); + setupPanel2 = new cGridBag().setVertical(false); + + rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind); rewindCB.setToolTipText("Rewind animation"); - randomCB = AddCheckBox(setupPanel, "Random", copy.random); - randomCB.setToolTipText("Option for switch node"); + 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(setupPanel, "Support", copy.link2master); - link2masterCB.setToolTipText("Attach to support"); - speedupCB = AddCheckBox(setupPanel, "Speed", copy.speedup); + speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup); speedupCB.setToolTipText("Option motion capture"); } oe.ctrlPanel.add(setupPanel); oe.ctrlPanel.Return(); + oe.ctrlPanel.add(setupPanel2); + oe.ctrlPanel.Return(); - commandsPanel = new cGridBag().setVertical(false); + objectCommandsPanel = new cGridBag().setVertical(false); - resetButton = AddButton(commandsPanel, "Reset"); + resetButton = AddButton(objectCommandsPanel, "Reset"); resetButton.setToolTipText("Jump to frame zero"); - stepButton = AddButton(commandsPanel, "Step"); + stepButton = AddButton(objectCommandsPanel, "Step"); stepButton.setToolTipText("Step one frame"); // resetAllButton = AddButton(oe, "Reset All"); // stepAllButton = AddButton(oe, "Step All"); // Return(); - slowerButton = AddButton(commandsPanel, "Slow"); + slowerButton = AddButton(objectCommandsPanel, "Slow"); slowerButton.setToolTipText("Decrease animation speed"); - fasterButton = AddButton(commandsPanel, "Fast"); + fasterButton = AddButton(objectCommandsPanel, "Fast"); fasterButton.setToolTipText("Increase animation speed"); - remarkButton = AddButton(commandsPanel, "Remark"); + remarkButton = AddButton(objectCommandsPanel, "Remark"); remarkButton.setToolTipText("Set the current transform as the target"); - oe.ctrlPanel.add(commandsPanel); + oe.ctrlPanel.add(objectCommandsPanel); oe.ctrlPanel.Return(); pushPanel = AddSlider(oe.ctrlPanel, "Push", -1, 1, copy.NORMALPUSH, 1.1); // To have the buttons @@ -1178,8 +1439,11 @@ //worldPanel.setName("World"); centralPanel = new cGridBag(); centralPanel.preferredWidth = 20; - timelinePanel = new JPanel(new BorderLayout()); - timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel); + + if (Globals.ADVANCED) + { + timelinePanel = new JPanel(new BorderLayout()); + timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel); cameraPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, cameraView, timelinePanel); cameraPanel.setContinuousLayout(true); @@ -1188,7 +1452,10 @@ // cameraPanel.setDividerSize(9); cameraPanel.setResizeWeight(1.0); + } + centralPanel.add(cameraView); + centralPanel.setFocusable(true); //frame.setJMenuBar(timelineMenubar); //centralPanel.add(timelinePanel); @@ -1214,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()); @@ -1251,12 +1519,23 @@ //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //tmp.setName("Edit"); objectPanel.add(materialPanel); + 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(ctrlPanel); - objectPanel.add(infoPanel); + objectPanel.add(editPanel); + 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; @@ -1265,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, @@ -1277,14 +1556,12 @@ scrollpane.addMouseWheelListener(this); // Default not fast enough /*JTabbedPane*/ scenePanel = new cGridBag(); - scenePanel.preferredWidth = 6; + scenePanel.preferredWidth = 5; JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.add(scrollpane); - tabbedPane.add(FSPane = new cFileSystemPane(this)); - - optionsPanel = new cGridBag().setVertical(true); + optionsPanel = new cGridBag().setVertical(false); optionsPanel.setName("Options"); @@ -1292,6 +1569,8 @@ tabbedPane.add(optionsPanel); + tabbedPane.add(FSPane = new cFileSystemPane(this)); + scenePanel.add(tabbedPane); /* @@ -1353,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; @@ -1364,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"); @@ -1384,9 +1663,14 @@ // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc); frame.setSize(1280, 860); - 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() @@ -1473,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); @@ -1540,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()); @@ -1591,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()); @@ -1598,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); @@ -1733,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")) @@ -2072,19 +2357,19 @@ void LoadObjFile(String fullname) { - /* + System.out.println("Loading " + fullname); + /**/ //lastFilename = fullname; if(loadObjThread == null) { - loadObjThread = new LoadOBJThread(); - loadObjThread.start(); + loadObjThread = new LoadOBJThread(); + loadObjThread.start(); } loadObjThread.add(fullname); - */ + /**/ - System.out.println("Loading " + fullname); - makeSomething(new FileObject(fullname, true), true); + //makeSomething(new FileObject(fullname, true), true); } void LoadGFDFile(String fullname) @@ -2460,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) @@ -2643,6 +2929,7 @@ } } } + cFileSystemPane FSPane; void SetMaterial(cMaterial mat, Object3D.cVector2[] others) @@ -2696,11 +2983,14 @@ } } } + freezematerial = false; } void SetMaterial(Object3D object) { + latestObject = object; + cMaterial mat = object.material; if (mat == null) @@ -2812,12 +3102,17 @@ // } /**/ - if (deselect) + if (deselect || child == null) { //group.deselectAll(); //freeze = true; GetTree().clearSelection(); //freeze = false; + + if (child == null) + { + return; + } } //group.addSelectee(child); @@ -2886,7 +3181,7 @@ cameraView.ToggleDL(); cameraView.repaint(); return; - } else if (event.getSource() == toggleTextureItem) + } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB) { cameraView.ToggleTexture(); // june 2013 copy.HardTouch(); @@ -2925,9 +3220,9 @@ frame.validate(); return; - } else if (event.getSource() == toggleSwitchItem) + } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB) { - cameraView.ToggleRandom(); + cameraView.ToggleSwitch(); cameraView.repaint(); return; } else if (event.getSource() == toggleHandleItem) @@ -2956,7 +3251,7 @@ { copy.live ^= true; return; - } else if (event.getSource() == selectCB) + } else if (event.getSource() == selectableCB) { copy.dontselect ^= true; return; @@ -3141,9 +3436,9 @@ { Close(); //return true; - } else if (source == loadItem) + } else if (source == openItem) { - load(); + Open(); //return true; } else if (source == newItem) { @@ -3168,6 +3463,10 @@ { generatePOV(); //return true; + } else if (event.getSource() == archiveItem) + { + cTools.Archive(frame); + return; } else if (source == zBufferItem) { try @@ -3214,6 +3513,60 @@ objEditor.refreshContents(); } + static public byte[] Compress(Object3D o) + { + try + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); +// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos); + ObjectOutputStream out = new ObjectOutputStream(baos); //zstream); + + Object3D parent = o.parent; + o.parent = null; + + out.writeObject(o); + + o.parent = parent; + + out.flush(); + + baos //zstream + .close(); + out.close(); + + byte[] bytes = baos.toByteArray(); + + System.out.println("save #bytes = " + bytes.length); + return bytes; + } catch (Exception e) + { + System.err.println(e); + return null; + } + } + + static public Object Uncompress(byte[] bytes) + { + 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(bais); // istream); + Object obj = in.readObject(); + + bais //istream + .close(); + in.close(); + + return obj; + } catch (Exception e) + { + System.err.println(e); + return null; + } + } + static public Object clone(Object o) { try @@ -3222,12 +3575,19 @@ ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(o); + + out.flush(); + out.close(); + + byte[] bytes = baos.toByteArray(); + + System.out.println("clone = " + bytes.length); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream in = new ObjectInputStream(bais); Object obj = in.readObject(); in.close(); - out.close(); + return obj; } catch (Exception e) { @@ -3242,7 +3602,7 @@ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();) { ab = (cRadio)e.nextElement(); - if(ab.GetObject() == client) + if(ab.GetObject() == copy) { return ab; } @@ -3251,24 +3611,77 @@ return null; } + 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(); - //EditorFrame.m_MainFrame.requestFocusInWindow(); - tab.graphs[tab.undoindex++] = (Object3D)clone(copy); - - for (int i = tab.undoindex; i < tab.graphs.length; i++) + byte[] compress = CompressCopy(); + + 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])) { - tab.graphs[i] = null; + thesame = true; + } + + //EditorFrame.m_MainFrame.requestFocusInWindow(); + if (!thesame) + { + //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); @@ -3281,16 +3694,31 @@ e.printStackTrace(); } } + + return !thesame; } void CopyChanged(Object3D obj) { + SetUndoStates(); + + boolean temp = CameraPane.SWITCH; + CameraPane.SWITCH = false; + + copy.ExtractBigData(versiontable); + copy.clear(); for (int i=0; i<obj.Size(); i++) { copy.add(obj.get(i)); } + + copy.RestoreBigData(versiontable); + + CameraPane.SWITCH = temp; + + //assert(hashtable.isEmpty()); copy.Touch(); @@ -3313,40 +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(); - if (tab.undoindex == 0) + 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 (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(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(tab.graphs[tab.undoindex]); + CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex])); + + //if (!tab.user[tab.versionindex]) + // tab.graphs[tab.versionindex] = null; } void ImportGFD() @@ -3498,7 +4016,7 @@ assert false; } - void EditSelection() + void EditSelection(boolean newWindow) { } @@ -3642,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) { @@ -3993,7 +4527,8 @@ void makeSomething(Object3D thing, boolean resetmodel) // deselect) { - Save(); + if (Globals.REPLACEONMAKE) // && resetmodel) + Save(); //Tween.set(thing, 0).target(1).start(tweenManager); //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager); // if (thing instanceof GenericJointDemo) @@ -4080,6 +4615,12 @@ { ResetModel(); Select(thing.GetTreePath(), true, false); // unselect... false); + + if (thing.Size() == 0) + { + //EditSelection(false); + } + refreshContents(); } @@ -4217,6 +4758,7 @@ try { + // Try compressed version first. java.io.FileInputStream istream = new java.io.FileInputStream(fullname); java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream); java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream); @@ -4227,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); @@ -4286,6 +4830,12 @@ void LoadIt(Object obj) { + if (obj == null) + { + // Invalid file + return; + } + System.out.println("Loaded " + obj); //new Exception().printStackTrace(); Object3D readobj = (Object3D) obj; @@ -4295,6 +4845,8 @@ if (readobj != null) { + //if (Globals.SAVEONMAKE) // A new object cannot share meshes + // Save(); try { //readobj.deepCopySelf(copy); @@ -4339,6 +4891,7 @@ } } catch (ClassCastException e) { + e.printStackTrace(); assert (false); Composite c = (Composite) copy; c.children.clear(); @@ -4349,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) { @@ -4458,6 +5022,7 @@ //ps.print(buffer.toString()); } catch (IOException e) { + e.printStackTrace(); } } @@ -4472,6 +5037,8 @@ String filename = browser.getFile(); if (filename != null && filename.length() > 0) { + if (!filename.endsWith(".gfd")) + filename += ".gfd"; lastname = browser.getDirectory() + filename; save(); } @@ -4638,7 +5205,7 @@ MenuBar menuBar; Menu fileMenu; MenuItem newItem; - MenuItem loadItem; + MenuItem openItem; MenuItem saveItem; MenuItem saveAsItem; MenuItem exportAsItem; @@ -4661,22 +5228,36 @@ CheckboxMenuItem toggleSwitchItem; CheckboxMenuItem toggleRootItem; CheckboxMenuItem animationItem; + MenuItem archiveItem; CheckboxMenuItem toggleHandleItem; CheckboxMenuItem togglePaintItem; JSplitPane mainPanel; JScrollPane scrollpane; + JPanel toolbarPanel; + cGridBag treePanel; + JPanel radioPanel; ButtonGroup buttonGroup; - cGridBag ctrlPanel; + + cGridBag toolboxPanel; cGridBag materialPanel; + cGridBag ctrlPanel; + JScrollPane infoPanel; + cGridBag optionsPanel; + JTabbedPane objectPanel; + boolean materialFlushed; + Object3D latestObject; + cGridBag XYZPanel; + JSplitPane gridPanel; JSplitPane bigPanel; + cGridBag bigThree; cGridBag scenePanel; cGridBag centralPanel; @@ -4791,7 +5372,7 @@ cNumberSlider fogField; JLabel opacityPowerLabel; cNumberSlider opacityPowerField; - JTree jTree; + cTree jTree; //ObjectUI parent; cNumberSlider normalpushField; -- Gitblit v1.6.2