//This file is part of SECONDO. //Copyright (C) 2004, University in Hagen, Department of Computer Science, //Database Systems for New Applications. //SECONDO is free software; you can redistribute it and/or modify //it under the terms of the GNU General Public License as published by //the Free Software Foundation; either version 2 of the License, or //(at your option) any later version. //SECONDO is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU General Public License for more details. //You should have received a copy of the GNU General Public License //along with SECONDO; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package viewer; import viewer.viewer3d.graphic3d.*; import java.awt.event.*; import javax.swing.*; import gui.*; import java.awt.*; import sj.lang.ListExpr; import viewer.viewer3d.objects.*; import java.beans.*; import gui.idmanager.*; import viewer.fuzzy2d.*; import javax.swing.event.*; import tools.Reporter; /** this class provioded a viewer for fuzzy spatial objects * the objects are displayed with 2 dimensions * to show the membership value one can for each object the * color for the values 0 and 1. For membershipvalues in(0,1) * is a linear approximatiopn between the Colors used. * To display the 3the dimension is also used a ZBuffer. */ public class Fuzzy2D extends SecondoViewer implements ApplyListener{ /** creates the new Viewer */ public Fuzzy2D(){ Img = new FuzzyImage(pw,ph); ImgPanel = new JPanel(){ public void paint(Graphics G){ super.paint(G); G.drawImage(Img,0,0,null); } }; ImgPanel.setSize(pw,ph); Dimension D = new Dimension(pw,ph); ImgPanel.setMinimumSize(D); ImgPanel.setMaximumSize(D); ImgPanel.setPreferredSize(D); ScrollPane = new JScrollPane(ImgPanel); ComboBox = new JComboBox(); setLayout(new BorderLayout()); JPanel P= new JPanel(); P.add(ComboBox); P.add(CoordLabel); P.setLayout(new GridLayout(2,1)); add(P,BorderLayout.NORTH); add(ScrollPane,BorderLayout.CENTER); add(BBLabel,BorderLayout.SOUTH); ((Graphics2D)Img.getGraphics()).setBackground(new Color(255,255,255)); ImgPanel.repaint(); // build the MenuExtension JMenuItem MI_ShowSettings = ObjectMenu.add("settings"); MI_ShowSettings.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ showObjectSettings(); } }); JMenuItem MI_HideSelectedObject=ObjectMenu.add("hide"); MI_HideSelectedObject.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ hideSelectedObject(); } }); JMenuItem MI_ShowViewConfig = ViewMenu.add("settings"); MI_ShowViewConfig.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ showViewSettings(); } }); JMenuItem MI_AutoBB = ViewMenu.add("automatic bounding box"); MI_AutoBB.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ if(!AutoBoundingBox){ AutoBoundingBox=true; update(); } }}); MenuExtension.addMenu(ObjectMenu); MenuExtension.addMenu(ViewMenu); MouseInputListener MIL=new MouseInputAdapter(){ public void mouseMoved(MouseEvent evt){ double[] wc = Img.getWorld(evt.getX(),evt.getY()); // round to 3 positions after comma wc[0] = ((int)(wc[0]*1000))/1000.0; wc[1] = ((int)(wc[1]*1000))/1000.0; CoordLabel.setText("("+wc[0]+" , "+wc[1]+")"); } public void mousePressed(MouseEvent evt){ startX = evt.getX(); startY = evt.getY(); } public void mouseDragged(MouseEvent evt){ double[] wc = Img.getWorld(evt.getX(),evt.getY()); // round to 3 positions after comma wc[0] = ((int)(wc[0]*1000))/1000.0; wc[1] = ((int)(wc[1]*1000))/1000.0; CoordLabel.setText("("+wc[0]+" , "+wc[1]+")"); if(isPainting) drawRectangle(startX,startY,oldX,oldY); oldX = evt.getX(); oldY = evt.getY(); drawRectangle(startX,startY,oldX,oldY); isPainting=true; } public void mouseReleased(MouseEvent evt){ if(isPainting) drawRectangle(startX,startY,oldX,oldY); isPainting=false; // set the new BoundingBox AutoBoundingBox = false; double[] P1 = Img.getWorld(startX,startY); double[] P2 = Img.getWorld(oldX,oldY); BB2.setTo(P1[0],P1[1],P2[0],P2[1]); Img.setBoundingBox(BB2); BB2.equalize(Img.getBoundingBox()); update(); } public void mouseClicked(MouseEvent evt){ selectNextAt(evt.getX(),evt.getY()); } public void drawRectangle(int x1,int y1,int x2,int y2){ Graphics2D G = (Graphics2D) ImgPanel.getGraphics(); G.setColor(Color.green); G.setXORMode(Color.white); int x = Math.min(x1,x2); int w = Math.abs(x1-x2); int y = Math.min(y1,y2); int h= Math.abs(y1-y2); G.drawRect(x,y,w,h); } private int startX; private int startY; private int oldX; private int oldY; private boolean isPainting = false; }; ImgPanel.addMouseListener(MIL); ImgPanel.addMouseMotionListener(MIL); update(); } /* find the next Object3D which lays under (x,y) and selected it */ private void selectNextAt(int x, int y){ int count = ComboBox.getItemCount(); if(count<=0) return; double[] Pos = Img.getWorld(x,y); double exactness = Img.getWorldAccuracy(Math.max(Img.getPointSize()/2,2)); int index = ComboBox.getSelectedIndex(); if(index<0) index=0; else index++; // begin after selected object boolean found = false; int next=index; for(int i=0;i=0){ // object allready displayed ComboBox.setSelectedIndex(index); return true; } ListExpr LE = o.toListExpr(); if(LE.listLength()!=2) return false; ListExpr type = LE.first(); ListExpr value = LE.second(); if(! (type.isAtom() && type.atomType()==ListExpr.SYMBOL_ATOM)) return false; String TypeName = type.symbolValue(); if (TypeName.equals("fpoint")){ FPoint3D P3D = new FPoint3D(); if(!P3D.readFromSecondoObject(o)) return false; Point3DVector PV = P3D.getPoints(); if(PV!=null) for(int i=0;i=0) ComboBox.removeItemAt(index); Img.paint(); ImgPanel.repaint(); */ } /** remove all objects from this viewer */ public void removeAll(){ ComboBox.removeAllItems(); Img.removeAll(); myPoints.empty(); myLines.empty(); myTriangles.empty(); Img.paint(); ImgPanel.repaint(); } /** remove all graphical object with given ID */ private void removeGraphicalObjects(ID id){ int i=0; while (i=0; } /** select O in the ComboBox if displayed */ public boolean selectObject(SecondoObject O){ int index = getIndexOf(O); if (index<0) return false; else{ ComboBox.setSelectedIndex(index); return true; } } /** returns the menuextension for this viewer */ public MenuVector getMenuVector(){ return MenuExtension; } /** returns the index of SO in the ComboBox indicated by the ID * if the combobox not contains SO -1 is returned */ private int getIndexOf(SecondoObject SO){ int pos = -1; int count= ComboBox.getItemCount(); boolean found =false; ID id = SO.getID(); for(int i=0;i