import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.util.*; /** * Toolboxes for manipulating data. File IO, zooming, edit/copy rows and columns, * slider groups, name groups with comments. */ public class OntoDataFrame extends JFrame implements ActionListener, ListSelectionListener, ChangeListener, ItemListener{ OntoApp oa; JTextArea ta=new JTextArea(); JButton b1=new JButton("Use data"); JButton bRead=new JButton("Read from file"); JButton bWrite=new JButton("Write to file"); // JButton bclose=new JButton("Close frame"); JTabbedPane jtp=new JTabbedPane(); JButton bzoomplus=new JButton("Zoom+"); JButton bzoomminus=new JButton("Zoom-"); JButton bzoomview=new JButton("Zoom to view"); JButton bznormalize=new JButton("Normalize coordinates"); JButton bzrotateright=new JButton("Rotate right"); JButton bzrotateleft=new JButton("Rotate left"); JButton bzgpscoordinates=new JButton("GPS coord"); JButton bzgpspeople=new JButton("GPS people calc"); JComboBox cmapnames=new JComboBox(); JComboBox ccalculatetype=new JComboBox(new Object[]{"Normal","GPSpeople"}); JCheckBox ccentrpeople=new JCheckBox("People in centre"); JCheckBox czoomview=new JCheckBox("Zoom to view while calculating", true); JButton bzl=new JButton("Left"); JButton bzr=new JButton("Right"); JButton bzu=new JButton("Up"); JButton bzd=new JButton("Down"); JCheckBox bzapptableview=new JCheckBox("View table", false); JCheckBox bzappslidersview=new JCheckBox("View sliders", true); JCheckBox bznameslidersview=new JCheckBox("Name sliders", true); JComboBox bzdrawtype=new JComboBox(new Object[]{"Words only", "Balls"}); JCheckBox bzresetview=new JCheckBox("View reset", true); JCheckBox bzmasterview=new JCheckBox("Master slider", false); JCheckBox bzuserslidersview; JButton brcut=new JButton("Cut"); JButton brcopy=new JButton("Copy"); JButton brpaste=new JButton("Paste"); JButton brinsert=new JButton("Insert"); JButton brdelete=new JButton("Delete"); OntoRowData rowclipboard; JButton brccut=new JButton("Cut"); JButton brccopy=new JButton("Copy"); JButton brcpaste=new JButton("Paste"); JButton brcinsert=new JButton("Insert"); JButton brcdelete=new JButton("Delete"); JTextField brparameter=new JTextField(""); OntoColumnData columnclipboard; JList brlist=new JList(); JButton brnormalize=new JButton("Normalize data"); JButton brlockall=new JButton("Lock all"); JButton brunlockall=new JButton("Unlock all"); JButton brlockbiggest=new JButton("Lock biggest"); JCheckBox brautomcalc=new JCheckBox("Automatic calculating", true); JList[] sgparameters; JSlider[] sgsliders; JButton[] sgadd; JButton[] sgremove; JTextField[] sggroupname; JButton sgnewgroup=new JButton("New group"); JButton sgremovelast=new JButton("Remove last"); JPanel sgpanel; //slider group panel JList gwordlist; JTextArea gcommentarea=new JTextArea(); JList gcommentlist=new JList(); JButton gdelcomm=new JButton("Delete comment"); JTextField gcommentfield=new JTextField(); JComboBox gnewcalctype=new JComboBox(new String[]{"Average", "Sum"}); JTextField gnewname=new JTextField(); JPanel p1=new JPanel(new BorderLayout()); JPanel p2=new JPanel(new BorderLayout()); JPanel p3=new JPanel(new BorderLayout()); JPanel p4=new JPanel(new BorderLayout()); JPanel p5=new JPanel(new BorderLayout()); public OntoDataFrame(OntoApp oa){ this.oa=oa; jtp.add("csv", p1); jtp.add("zoom", p2); jtp.add("data", p3); // jtp.add("slider", p4); jtp.add("group", p5); getContentPane().add(jtp, BorderLayout.CENTER); p1.add(new JScrollPane(ta), BorderLayout.CENTER); JPanel buttonPanel=new JPanel(new GridLayout()); buttonPanel.add(b1); if(oa.isStandalone){ buttonPanel.add(bRead); buttonPanel.add(bWrite); } // buttonPanel.add(bclose); p1.add(buttonPanel, BorderLayout.NORTH); b1.addActionListener(this); bRead.addActionListener(this); bWrite.addActionListener(this); // bclose.addActionListener(this); JPanel p2south=new JPanel(new GridLayout(1, 1)); // JPanel bzpanel=new JPanel(new GridLayout(1, 4)); JPanel bzpanel2=new JPanel(new GridLayout(4, 4)); bzpanel2.add(bzl); bzpanel2.add(bzr); bzpanel2.add(bzu); bzpanel2.add(bzd); bzl.addActionListener(this); bzr.addActionListener(this); bzu.addActionListener(this); bzd.addActionListener(this); // p2south.add(bzpanel); bzpanel2.add(bzoomplus); bzpanel2.add(bzoomminus); bzpanel2.add(bzoomview); bzpanel2.add(bznormalize); bzpanel2.add(bzrotateleft); bzpanel2.add(bzrotateright); bzpanel2.add(bzgpscoordinates); bzpanel2.add(bzgpspeople); bzpanel2.add(cmapnames); bzpanel2.add(ccalculatetype); bzpanel2.add(ccentrpeople); bzoomplus.addActionListener(this); bzoomminus.addActionListener(this); bzoomview.addActionListener(this); bznormalize.addActionListener(this); bzrotateright.addActionListener(this); bzrotateleft.addActionListener(this); bzgpscoordinates.addActionListener(this); bzgpspeople.addActionListener(this); cmapnames.addItemListener(this); // p2south.add(bzpanel); p2south.add(bzpanel2); p2.add(p2south, BorderLayout.SOUTH); p2.add(czoomview, BorderLayout.NORTH); czoomview.addActionListener(this); JPanel p2east=new JPanel(new BorderLayout()); JPanel p2east2=new JPanel(new GridLayout(4, 1)); p2east2.add(bzapptableview); p2east2.add(bzappslidersview); p2east2.add(bznameslidersview); p2east2.add(bzdrawtype); p2east2.add(bzresetview); p2east2.add(bzmasterview); // bzuserslidersview=new JCheckBox("Others parameters", !oa.isStandalone); bzuserslidersview=new JCheckBox("Others parameters", false); p2east2.add(bzuserslidersview); bzdrawtype.setToolTipText("Drawing type"); bzdrawtype.addItemListener(this); // bzdrawtype.setSelectedIndex(1); bzapptableview.addChangeListener(this); bzappslidersview.addChangeListener(this); bznameslidersview.addChangeListener(this); bzresetview.addChangeListener(this); bzmasterview.addChangeListener(this); bzuserslidersview.addChangeListener(this); p2east.add(p2east2, BorderLayout.NORTH); p2.add(p2east, BorderLayout.EAST); JPanel brpanel=new JPanel(new GridLayout(1, 6)); JLabel brrowlabel=new JLabel("Rows:"); brrowlabel.setToolTipText("Use table rows"); brpanel.add(brrowlabel); brpanel.add(brcut); brpanel.add(brcopy); brpanel.add(brpaste); brpanel.add(brinsert); brpanel.add(brdelete); brcut.addActionListener(this); brcopy.addActionListener(this); brpaste.addActionListener(this); brinsert.addActionListener(this); brdelete.addActionListener(this); p3.add(brpanel, BorderLayout.SOUTH); JPanel p3west=new JPanel(new BorderLayout()); p3west.add(new JScrollPane(brlist), BorderLayout.WEST); brlist.addListSelectionListener(this); p3west.add(brparameter, BorderLayout.SOUTH); brparameter.addActionListener(this); p3.add(p3west, BorderLayout.WEST); brlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JPanel brcpanel=new JPanel(new GridLayout(1, 6)); brcpanel.add(new JLabel("Columns:")); brcpanel.add(brccut); brcpanel.add(brccopy); brcpanel.add(brcpaste); brcpanel.add(brcinsert); brcpanel.add(brcdelete); brccut.addActionListener(this); brccopy.addActionListener(this); brcpaste.addActionListener(this); brcinsert.addActionListener(this); brcdelete.addActionListener(this); p3.add(brcpanel, BorderLayout.NORTH); JPanel p3east=new JPanel(new GridLayout(9, 1)); p3east.add(brnormalize); p3east.add(brlockall); p3east.add(brunlockall); p3east.add(brlockbiggest); // p3east.add(oa.b1); p3east.add(oa.btf1); p3east.add(oa.b2); p3east.add(oa.b3); p3east.add(brautomcalc); // p3east.add(oa.b1); // p3east.add(oa.btf1); brautomcalc.setToolTipText("Calculate after each change"); p3.add(p3east, BorderLayout.EAST); brnormalize.addActionListener(this); brlockall.addActionListener(this); brunlockall.addActionListener(this); brlockbiggest.addActionListener(this); sgnewgroup.addActionListener(this); sgremovelast.addActionListener(this); gwordlist=new JList(); JPanel p5west=new JPanel(new BorderLayout()); p5west.add(gdelcomm, BorderLayout.SOUTH); p5west.add(new JScrollPane(gwordlist), BorderLayout.CENTER); p5.add(p5west, BorderLayout.WEST); gdelcomm.addActionListener(this); // p5.add(new JScrollPane(gcommentarea), BorderLayout.CENTER); p5.add(new JScrollPane(gcommentlist), BorderLayout.CENTER); JPanel p5south=new JPanel(new BorderLayout()); p5south.add(new JLabel("Add comment:"), BorderLayout.WEST); p5south.add(gcommentfield, BorderLayout.CENTER); p5.add(p5south, BorderLayout.SOUTH); gcommentfield.addActionListener(this); gwordlist.addListSelectionListener(this); JPanel p5east=new JPanel(new GridLayout(5, 1)); p5east.add(new JLabel("Calculating type")); p5east.add(gnewcalctype); p5east.add(new JLabel("Object name")); p5east.add(gnewname); p5east.add(new JLabel("Add object")); gnewname.addActionListener(this); JPanel p5east1=new JPanel(new BorderLayout()); p5east1.add(p5east, BorderLayout.NORTH); p5.add(p5east1, BorderLayout.EAST); setSize(500, 300); setTitle("Data frame"); } public void actionPerformed(ActionEvent e){ try{ // if(e.getSource()==bclose){ // this.setVisible(false); // } if(e.getSource()==b1){ try{ oa.od.readDataFromText(ta.getText()); oa.od.normalizeData(); oa.os.initialize(); oa.addTable(); oa.addTree(); oa.repaint(); }catch(Exception ex2){ JOptionPane.showMessageDialog(null, ex2.toString(), "Problem", JOptionPane.ERROR_MESSAGE); } } if(e.getSource()==bRead){ JFileChooser jfc=new JFileChooser(new File(".")); if(jfc.showSaveDialog(this)==JFileChooser.APPROVE_OPTION){ File f=jfc.getSelectedFile(); BufferedReader br=new BufferedReader(new FileReader(f)); String s=br.readLine(); StringBuffer sb=new StringBuffer(); while(s!=null){ sb.append(s+"\n"); s=br.readLine(); } br.close(); ta.setText(sb.toString()); } } if(e.getSource()==bWrite){ JFileChooser jfc=new JFileChooser(new File(".")); if(jfc.showOpenDialog(this)==JFileChooser.APPROVE_OPTION){ File f=jfc.getSelectedFile(); PrintWriter pw=new PrintWriter(new FileWriter(f)); pw.print(ta.getText()); pw.close(); } } double stepkoef=0.25; if(e.getSource()==bzl){ oa.op.wcx-=stepkoef*oa.op.getWidth()/2/oa.op.koef; if(ccentrpeople.isSelected() && oa.od.gps!=null){ oa.od.coordinates[oa.od.gpsPeopleNr][0]=oa.op.wcx; oa.od.coordinates[oa.od.gpsPeopleNr][1]=oa.op.wcy; oa.od.positionToGpsPeople(); } } if(e.getSource()==bzr){ oa.op.wcx+=stepkoef*oa.op.getWidth()/2/oa.op.koef; if(ccentrpeople.isSelected() && oa.od.gps!=null){ oa.od.coordinates[oa.od.gpsPeopleNr][0]=oa.op.wcx; oa.od.coordinates[oa.od.gpsPeopleNr][1]=oa.op.wcy; oa.od.positionToGpsPeople(); } } if(e.getSource()==bzu){ oa.op.wcy+=stepkoef*oa.op.getHeight()/2/oa.op.koef; if(ccentrpeople.isSelected() && oa.od.gps!=null){ oa.od.coordinates[oa.od.gpsPeopleNr][0]=oa.op.wcx; oa.od.coordinates[oa.od.gpsPeopleNr][1]=oa.op.wcy; oa.od.positionToGpsPeople(); } } if(e.getSource()==bzd){ oa.op.wcy-=stepkoef*oa.op.getHeight()/2/oa.op.koef; if(ccentrpeople.isSelected() && oa.od.gps!=null){ oa.od.coordinates[oa.od.gpsPeopleNr][0]=oa.op.wcx; oa.od.coordinates[oa.od.gpsPeopleNr][1]=oa.op.wcy; oa.od.positionToGpsPeople(); } } if(e.getSource()==bzoomplus){ oa.op.koef*=1.5; } if(e.getSource()==bzoomminus){ oa.op.koef/=1.5; } if(e.getSource()==bzoomview){ oa.op.calculateKoef(); } if(e.getSource()==bznormalize){ oa.od.normalizeCoordinates(); oa.op.calculateKoef(); } if(e.getSource()==bzrotateright){ oa.od.rotateCoordinates(0.1); oa.op.calculateKoef(); } if(e.getSource()==bzrotateleft){ oa.od.rotateCoordinates(-0.1); oa.op.calculateKoef(); } if(e.getSource()==bzgpscoordinates){ oa.od.gpsCoordinates(); oa.op.calculateKoef(); } if(e.getSource()==bzgpspeople){ oa.od.positionToGpsPeople(); } if(e.getSource()==czoomview){ oa.op.zoomToBoundsWhileCalculating=czoomview.isSelected(); } int trow=oa.table.getSelectedRow(); boolean rowchanged=false; if(e.getSource()==brcut){ if(trow>-1 && trow-1 && trow-1 && trow-1 && tcol-1 && trow-1 && tcol-1){ oa.od.params[brlist.getSelectedIndex()].name=brparameter.getText(); colChanged=true; } } if(colChanged){ oa.addTable(); oa.addTree(); oa.os.initialize(); rowclipboard=null; String[] ps=new String[oa.od.params.length]; for(int k=0; kmaxdata){ maxdata=sum; maxid=j; } } oa.od.locked[maxid]=true; } /* for(int i=0; i0){ addNewGroupRow(); } } if(e.getSource()==gdelcomm){ int selected[]=gwordlist.getSelectedIndices(); Object selcomm[]=gcommentlist.getSelectedValues(); for(int j=0; j-1){ brparameter.setText(oa.od.params[brlist.getSelectedIndex()].name); } } if(e.getSource()==gwordlist){ // updateGCommentArea(); updateGCommentList(); } } public void itemStateChanged(ItemEvent e){ if(e.getSource()==bzdrawtype){ oa.repaint(); } if(e.getSource()==cmapnames){ String s=(String)cmapnames.getSelectedItem(); StringTokenizer stk=new StringTokenizer(s, "\t"); String mapname=stk.nextToken(); double mapx1=Double.parseDouble(stk.nextToken()); double mapy1=Double.parseDouble(stk.nextToken()); double mapx2=Double.parseDouble(stk.nextToken()); double mapy2=Double.parseDouble(stk.nextToken()); oa.op.loadGpsMap(mapname, mapx1, mapy1, mapx2, mapy2); oa.op.repaint(); } } /** * Returs array in each vector of parameter names ordered by group numbers. */ /* public Vector[] readParamGroups(){ Vector[] groups=new Vector[oa.od.paramgroupnames.length]; for(int j=0; j