Search in sources :

Example 1 with ListDownLayout

use of org.twak.utils.ui.ListDownLayout in project chordatlas by twak.

the class PanoGen method selected.

public void selected(Pano p) {
    ui.removeAll();
    ui.setLayout(new ListDownLayout());
    selectedPano = p;
    JTextArea name = new JTextArea(p.orig.getName());
    name.setLineWrap(true);
    name.setPreferredSize(new Dimension(600, 100));
    JButton recalc = new JButton("reset");
    recalc.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            tweed.enqueue(new Runnable() {

                @Override
                public void run() {
                    p.set(p.oa1, p.oa2, p.oa3);
                    calculate();
                }
            });
        }
    });
    JButton depth = new JButton("depth");
    depth.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Point3d worldPos = new Point3d();
            Vector3d worldNormal = new Vector3d();
            BufferedImage im = p.getRenderPano();
            List<float[]> cubes = new ArrayList();
            for (double a = 0; a < 2 * Math.PI; a += 0.02) for (double b = -Math.PI / 2; b < Math.PI / 2; b += 0.02) {
                Point3d pt = new Point3d(Math.cos(b) * Math.cos(a), Math.sin(b), Math.cos(b) * Math.sin(a));
                pt.scale(10);
                pt.add(p.location);
                Color c = new Color(p.castTo(new float[] { (float) pt.x, (float) pt.y, (float) pt.z }, im, worldPos, worldNormal));
                if (!Double.isNaN(worldPos.x))
                    cubes.add(new float[] { (float) worldPos.x, (float) worldPos.y, (float) worldPos.z, c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f });
            }
            addCubes(cubes);
        }
    });
    // JButton render = new JButton("render");
    // render.addActionListener(new ActionListener() {
    // 
    // @Override
    // public void actionPerformed(ActionEvent e) {
    // TexGen tg = (TexGen) children.get(0);
    // if (tg != null) {
    // tg.renderTexture( new File(p.orig.getPath()+".projected.png"));
    // }
    // }
    // });
    JButton view = new JButton("view");
    view.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            tweed.enqueue(new Runnable() {

                @Override
                public void run() {
                    tweed.getCamera().setLocation(p.geom.getWorldTranslation());
                    tweed.gainFocus();
                }
            });
        }
    });
    JButton background = new JButton("set background");
    background.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            tweed.enqueue(new Runnable() {

                @Override
                public void run() {
                    System.out.println("rendering from " + p.orig.getPath());
                    int wS = tweed.getCamera().getWidth(), hS = tweed.getCamera().getHeight(), wC = 1024, // 
                    hC = 1024;
                    BufferedImage target = new BufferedImage(wC, hC, BufferedImage.TYPE_3BYTE_BGR);
                    p.ensurePano();
                    for (int x = 0; x < wC; x++) for (int y = 0; y < hC; y++) {
                        com.jme3.math.Vector3f loc = tweed.getCamera().getWorldCoordinates(new Vector2f(x * wS / wC, y * hS / hC), 1);
                        target.setRGB(x, hC - y - 1, p.castTo(new float[] { loc.x, loc.y, loc.z }, p.panoMedium, null, null));
                    }
                    // Graphics2D g2 = (Graphics2D) target.getGraphics();
                    // g2.setColor (Color.blue);
                    // g2.drawLine( target.getWidth()/2, 0, target.getWidth()/2, target.getHeight() );
                    // g2.dispose();
                    tweed.setBackground(target);
                }
            });
        }
    });
    ui.add(name);
    ui.add(view);
    // ui.add(recalc);
    ui.add(background);
    // ui.add(depth);
    tweed.frame.setGenUI(ui);
    ui.revalidate();
    ui.repaint();
}
Also used : ListDownLayout(org.twak.utils.ui.ListDownLayout) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) Dimension(java.awt.Dimension) BufferedImage(java.awt.image.BufferedImage) ActionListener(java.awt.event.ActionListener) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with ListDownLayout

use of org.twak.utils.ui.ListDownLayout in project chordatlas by twak.

the class SkelGen method getUI.

@Override
public JComponent getUI() {
    JPanel ui = new JPanel(new ListDownLayout());
    ui.add(new JLabel("To edit: use select tool, right click on buildings"));
    JButton compare = new JButton("compare to mesh");
    compare.addActionListener(l -> new CompareGens(this, blockGen));
    ui.add(compare);
    JButton pf = new JButton("all procedural facades");
    pf.addActionListener(l -> cgaAll());
    ui.add(pf);
    JButton proc = new JButton("CGA facades");
    return ui;
}
Also used : JPanel(javax.swing.JPanel) ListDownLayout(org.twak.utils.ui.ListDownLayout) CompareGens(org.twak.tweed.CompareGens) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel)

Example 3 with ListDownLayout

use of org.twak.utils.ui.ListDownLayout in project chordatlas by twak.

the class SkelGen method selected.

private void selected(PlanSkeleton skel, Node house, SuperFace sf, SuperEdge se) {
    JPanel ui = new JPanel();
    ui.setLayout(new ListDownLayout());
    JButton fac = new JButton("edit facade");
    fac.addActionListener(e -> editFacade(skel, sf, se, false));
    ui.add(fac);
    // JButton tex = new JButton( "texture facade" );
    // tex.addActionListener( e -> editFacade( skel, sf, se, true ) );
    // ui.add( tex );
    JButton proc = new JButton("procedural facade");
    proc.addActionListener(e -> cgaFacade(skel, sf, se));
    ui.add(proc);
    JButton camp = new JButton("procedural extrusions");
    camp.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            closeSitePlan();
            siteplan = new Siteplan(skel.plan, false) {

                SuperFace workon = sf;

                public void show(Output output, Skeleton threadKey) {
                    super.show(output, threadKey);
                    Plot.closeLast();
                    tweed.enqueue(new Runnable() {

                        @Override
                        public void run() {
                            removeGeometryFor(workon);
                            // current selection is invalid
                            tweed.frame.setGenUI(null);
                            setSkel((PlanSkeleton) threadKey, output, workon);
                        }
                    });
                }
            };
            siteplan.setVisible(true);
            siteplan.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        }
    });
    ui.add(camp);
    JButton mini = new JButton("street-view");
    mini.addActionListener(e -> new MiniViewer(se));
    if (sf != null)
        ui.add(mini);
    JButton prof = new JButton("profiles");
    prof.addActionListener(e -> new ProfileAssignmentViewer(sf, skelFootprint == null ? null : skelFootprint.globalProfs));
    ui.add(prof);
    ui.add(new JLabel("height " + sf.heights.size()));
    JButton plan = new JButton("plan");
    plan.addActionListener(e -> new Plot(toRender, footprint));
    ui.add(plan);
    JButton remove = new JButton("remove");
    remove.addActionListener(e -> {
        visible = false;
        calculateOnJmeThread();
        tweed.frame.removeGen(SkelGen.this);
    });
    ui.add(plan);
    JButton b = new JButton("view clean profiles");
    b.addActionListener(e -> SkelFootprint.debugFindCleanProfiles(footprint, this, new ProgressMonitor(null, "", "", 0, 100), tweed));
    ui.add(b);
    JButton c = new JButton("compare profiles");
    c.addActionListener(e -> skelFootprint.debugCompareProfs(skelFootprint.globalProfs));
    ui.add(c);
    tweed.frame.setGenUI(ui);
}
Also used : JPanel(javax.swing.JPanel) ListDownLayout(org.twak.utils.ui.ListDownLayout) PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton) ActionEvent(java.awt.event.ActionEvent) Plot(org.twak.utils.ui.Plot) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) SuperFace(org.twak.tweed.gen.SuperFace) ProgressMonitor(javax.swing.ProgressMonitor) ActionListener(java.awt.event.ActionListener) Siteplan(org.twak.siteplan.campskeleton.Siteplan) Output(org.twak.camp.Output) MiniViewer(org.twak.tweed.gen.MiniViewer) PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton) Skeleton(org.twak.camp.Skeleton) ProfileAssignmentViewer(org.twak.tweed.gen.ProfileAssignmentViewer)

Example 4 with ListDownLayout

use of org.twak.utils.ui.ListDownLayout in project chordatlas by twak.

the class AlignTool method getUI.

@Override
public void getUI(JPanel p) {
    p.setLayout(new ListDownLayout());
    JButton w = new JButton("save alignment");
    w.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            toAlign.save();
        }
    });
    JButton swap = new JButton("swap");
    swap.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Vector3f tmp = alignMarkers[0];
            alignMarkers[0] = alignMarkers[1];
            alignMarkers[1] = tmp;
            tweed.enqueue(new Runnable() {

                @Override
                public void run() {
                    doAlign();
                }
            });
        }
    });
    JFormattedTextField tf = new JFormattedTextField(new NumberFormatter());
    tf.setValue(vOffset);
    tf.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            vOffset = ((Number) tf.getValue()).doubleValue();
            doAlign();
        }
    });
    p.add(w);
    p.add(swap);
    p.add(new JLabel("height offset:"));
    p.add(tf);
}
Also used : ListDownLayout(org.twak.utils.ui.ListDownLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Vector3f(com.jme3.math.Vector3f) JButton(javax.swing.JButton) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) NumberFormatter(javax.swing.text.NumberFormatter)

Example 5 with ListDownLayout

use of org.twak.utils.ui.ListDownLayout in project chordatlas by twak.

the class ImagePlaneGen method getUI.

@Override
public JComponent getUI() {
    JPanel out = new JPanel(new ListDownLayout());
    JButton render = new JButton("render");
    render.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int c = 0;
            for (Pano pg : nearby) render(new File(Tweed.DATA + "facades/0/" + (c++)), FacadeTool.pixelsPerMeter, pg, null, FeatureCache.RENDERED_IMAGE);
        }
    });
    out.add(render);
    JButton load = new JButton("load");
    load.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser(lastLocation == null ? new File((System.getProperty("user.home") + "/Desktop")) : lastLocation);
            fileChooser.setFileFilter(new FileFilter() {

                @Override
                public String getDescription() {
                    return "csv";
                }

                @Override
                public boolean accept(File f) {
                    return f.isDirectory() || f.getName().toLowerCase().endsWith(".csv");
                }
            });
            if (fileChooser.showOpenDialog(out) == JFileChooser.APPROVE_OPTION) {
                windows.clear();
                File csv = fileChooser.getSelectedFile();
                lastLocation = csv.getParentFile();
                try (Stream<String> stream = Files.lines(csv.toPath())) {
                    stream.forEach(new Consumer<String>() {

                        @Override
                        public void accept(String line) {
                            if (line.startsWith("top"))
                                return;
                            String[] vals = line.split(",");
                            try {
                                windows.add(new Window(30 - Double.parseDouble(vals[0]) / FacadeTool.pixelsPerMeter, Double.parseDouble(vals[1]) / FacadeTool.pixelsPerMeter, 30 - Double.parseDouble(vals[2]) / FacadeTool.pixelsPerMeter, Double.parseDouble(vals[3]) / FacadeTool.pixelsPerMeter));
                            } catch (Throwable th) {
                                System.err.println("while parsing " + line + " :");
                                th.printStackTrace();
                            }
                        }
                    });
                } catch (Throwable th) {
                    th.printStackTrace();
                }
            }
            calculateOnJmeThread();
        }
    });
    out.add(load);
    return out;
}
Also used : JPanel(javax.swing.JPanel) ListDownLayout(org.twak.utils.ui.ListDownLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) Consumer(java.util.function.Consumer) Stream(java.util.stream.Stream) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Aggregations

ListDownLayout (org.twak.utils.ui.ListDownLayout)15 JButton (javax.swing.JButton)12 ActionEvent (java.awt.event.ActionEvent)11 ActionListener (java.awt.event.ActionListener)10 JPanel (javax.swing.JPanel)10 JLabel (javax.swing.JLabel)7 File (java.io.File)4 JSlider (javax.swing.JSlider)4 ChangeEvent (javax.swing.event.ChangeEvent)4 ChangeListener (javax.swing.event.ChangeListener)4 Dimension (java.awt.Dimension)3 JCheckBox (javax.swing.JCheckBox)3 Vector3f (com.jme3.math.Vector3f)2 Node (com.jme3.scene.Node)2 BorderLayout (java.awt.BorderLayout)2 Color (java.awt.Color)2 WindowAdapter (java.awt.event.WindowAdapter)2 WindowEvent (java.awt.event.WindowEvent)2 BufferedImage (java.awt.image.BufferedImage)2 ArrayList (java.util.ArrayList)2