import javax.swing.JButton; import java.awt.*; import java.awt.event.*; import java.awt.Color; import java.awt.Graphics; import java.util.HashMap; import javax.swing.JFrame; import javax.swing.JOptionPane; import com.mxgraph.view.mxGraph; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JTextField; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.view.mxGraph; import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.JOptionPane; import java.util.HashMap; public class Acoes extends JFrame implements MouseListener, MouseMotionListener { protected static mxGraph graph = new mxGraph(); protected static HashMap m = new HashMap(); private int prevX; private int prevY; private static int x,y; private String name ; private Container mainContainer; private String fileName; private boolean dragging; private mxGraphComponent GraphComponent; private JTextField text; private JButton buttAdd; private JButton butAddJiton; private JButton buttAddPlac; private JButton buttDel; private JButton buttLin; private Object cell ; private JMenuBar mainBar; JMenu fileMenu, editMenu, setColorMenuItem, aboutMenu; JMenuItem newMenuItem, openMenuItem, closeMenuItem, saveMenuItem, saveAsMenuItem, exitMenuItem, undoMenuItem, redoMenuItem, foreGroundMenuItem, backGroundMenuItem, authorMenuItem; public mxGraph getGraph (){ return graph; } public static HashMap getM(){ return m; } public Acoes (){ super("Jpetri - Mos38-kiso"); initGUI(); mainBar = new JMenuBar(); setJMenuBar(mainBar); /*----------------------------------------------------------------------------*/ fileMenu = new JMenu("File"); fileMenu.setMnemonic('F'); newMenuItem = new JMenuItem("New"); openMenuItem = new JMenuItem("Open"); closeMenuItem = new JMenuItem("Close"); saveMenuItem = new JMenuItem("Save"); saveAsMenuItem = new JMenuItem("Save As"); exitMenuItem = new JMenuItem("Exit"); newMenuItem.addActionListener(null ); openMenuItem.addActionListener(null ); saveMenuItem.addActionListener(null); saveAsMenuItem.addActionListener( null); closeMenuItem.addActionListener(null ); exitMenuItem.addActionListener(null); fileMenu.add(newMenuItem); fileMenu.add(openMenuItem); fileMenu.add(closeMenuItem); fileMenu.addSeparator(); fileMenu.add(saveMenuItem); fileMenu.add(saveAsMenuItem); fileMenu.addSeparator(); fileMenu.add(exitMenuItem); /*----------------------------------------------------------------------------*/ editMenu = new JMenu("Edit"); editMenu.setMnemonic('E'); undoMenuItem = new JMenuItem("Undo"); redoMenuItem = new JMenuItem("Redo"); setColorMenuItem = new JMenu("Set Color"); foreGroundMenuItem = new JMenuItem("Set ForeGround"); backGroundMenuItem = new JMenuItem("Set BackGround"); setColorMenuItem.add(foreGroundMenuItem); setColorMenuItem.add(backGroundMenuItem); editMenu.add(undoMenuItem); editMenu.add(redoMenuItem); editMenu.addSeparator(); editMenu.add(setColorMenuItem); /*----------------------------------------------------------------------------*/ aboutMenu = new JMenu("About"); aboutMenu.setMnemonic('A'); authorMenuItem = new JMenuItem("Author"); aboutMenu.add(authorMenuItem); /*----------------------------------------------------------------------------*/ mainBar.add(fileMenu); mainBar.add(editMenu); mainBar.add(aboutMenu); /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ } private void initGUI() { setSize(900, 600); setLocationRelativeTo(null); GraphComponent = new mxGraphComponent(graph); GraphComponent.setPreferredSize(new Dimension(870,480)); getContentPane().add(GraphComponent); // this.addMouseListener(this); this.addMouseMotionListener(this); // text = new JTextField(); getContentPane().add(text); text.setPreferredSize(new Dimension(520, 21)); setLayout(new FlowLayout(FlowLayout.LEFT)); buttAddPlac = new JButton("AddPlac"); getContentPane().add(buttAddPlac); buttAddPlac.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ AddPlac add = new AddPlac(text.getText()); } }); butAddJiton = new JButton("AddJito"); getContentPane().add(butAddJiton); butAddJiton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ AddJito add = new AddJito(text.getText()); } }); buttAdd = new JButton("add trans"); getContentPane().add(buttAdd); class MousePressListener implements MouseListener { public void mouseDragged(MouseEvent evt) { if(!dragging) return; int x = evt.getX(); int y = evt.getY(); if(x < 3) x = 3; if(x > getWidth() - 57) x = getWidth() - 57; if(y < 3) y = 3; if(y > getHeight() - 4) y = getHeight() - 4; //graphicsForDrawing.drawLine(prevX, prevY, x, y); prevX = x; prevY = y; AddGraph add = new AddGraph(text.getText()); } public void mouseClicked (MouseEvent evt){ x = evt.getX(); y = evt.getY(); AddGraph add = new AddGraph(text.getText()); } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent evt) { // TODO Auto-generated method stub int x = evt.getX(); int y = evt.getY(); int width = getWidth(); int height = getHeight(); if(dragging) return; if(x > width - 53) { if(y > height - 53) repaint(); } else if(x > 3 && x < width - 56 && y > 3 && y < height - 3) { prevX = x; prevY = y; dragging = true; AddGraph add = new AddGraph(text.getText()); } } @Override public void mouseReleased(MouseEvent evt) { // TODO Auto-generated method stub if(!dragging) { return; } else { dragging = false; AddGraph add = new AddGraph( null); return; } } }; buttAdd.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ dragging = true;; } }); buttDel = new JButton("delt"); getContentPane().add(buttDel); buttDel.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0){ graph.getModel().remove(cell); } }); buttLin = new JButton("Arc"); getContentPane().add(buttLin); buttLin.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ AddLin line = new AddLin(); } }); GraphComponent.getGraphControl().addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { cell = GraphComponent.getCellAt(e.getX(), e.getY()); } }); } @Override public void mouseDragged(MouseEvent evt) { // TODO Auto-generated method stub if(!dragging) return; int x = evt.getX(); int y = evt.getY(); if(x < 3) x = 3; if(x > getWidth() - 57) x = getWidth() - 57; if(y < 3) y = 3; if(y > getHeight() - 4) y = getHeight() - 4; //graphicsForDrawing.drawLine(prevX, prevY, x, y); prevX = x; prevY = y; AddGraph add = new AddGraph(text.getText()); } @Override public void mouseMoved(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseClicked(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } }