Created
March 7, 2013 08:50
-
-
Save PShuvaev/5106544 to your computer and use it in GitHub Desktop.
foo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.pshuvaev.oop.graphview; | |
import javax.swing.*; | |
import javax.swing.plaf.DimensionUIResource; | |
import java.awt.*; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import java.awt.event.MouseListener; | |
/** | |
* Author: PShuvaev | |
*/ | |
public class GraphPanel extends JPanel implements MouseListener{ | |
public GraphPanel(){ | |
super(); | |
setLayout(null); | |
setBackground( new Color(255, 219, 190) ); | |
addMouseListener( this ); | |
} | |
public void addVertex( String title, Point p ){ | |
ViewVertex v = new ViewVertex(); | |
Dimension d = v.getSize(); | |
v.setLocation((int) (p.getX() - d.getWidth() / 2), (int) (p.getY() - d.getHeight() / 2)); | |
add(v); | |
System.out.println("addVertex"); | |
v.addMouseListener( new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
ViewVertex vertex = (ViewVertex) e.getSource(); | |
if( vertex.isSelected() ) { | |
vertex.setSelected( false ); | |
} else { | |
vertex.setSelected( true ); | |
} | |
System.out.println("vertexclicked"); | |
} | |
} ); | |
} | |
public static void main(String args[]){ | |
JFrame frame = new JFrame("Course editor"); | |
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); | |
frame.setPreferredSize(new Dimension(400, 300)); | |
frame.setLocation( 400, 200 ); | |
GraphPanel panel = new GraphPanel(); | |
frame.setContentPane(panel); | |
frame.pack(); | |
frame.setVisible(true); | |
} | |
@Override | |
public void mouseClicked(MouseEvent e) {} | |
@Override | |
public void mousePressed(MouseEvent e) { | |
addVertex("new", e.getPoint()); | |
repaint(); | |
} | |
@Override | |
public void mouseReleased(MouseEvent e) {} | |
@Override | |
public void mouseEntered(MouseEvent e) { | |
} | |
@Override | |
public void mouseExited(MouseEvent e) { | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment