/* PseudoCode Interpreted Language (PCIL): Part of the algoviz@vt collection of algorithm visualizations. Copyright (C) 2008 Brandon Malone, Frank Hadlock This file is part of the PseudoCode Interpreted Language. PseudoCode Interpreted Language 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 3 of the License, or (at your option) any later version. PseudoCode Interpreted Language 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 PseudoCode Interpreted Language. If not, see . */ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package dynamicmvc; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.BorderFactory; import javax.swing.JPanel; /** * * @author bm542 */ public class ResizablePanel extends JPanel { public boolean mouseClicked; public int lastX; public int lastY; PrimitivePointer pp; public ResizablePanel(PrimitivePointer pp) { super(); mouseClicked = false; lastX = -1; lastY = -1; this.pp = pp; addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { mousePressedHandler(evt); } public void mouseReleased(java.awt.event.MouseEvent evt) { mouseReleasedHandler(evt); } }); addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { public void mouseDragged(java.awt.event.MouseEvent evt) { mouseDraggedHandler(evt); } }); } public void paint(Graphics g) { super.paint(g); // draw a white square in the bottom 10 x 10 int width = getWidth(); int height = getHeight(); g.setColor(Color.white); g.fillRect(width - 10, height - 10, 10, 10); } public void mousePressedHandler(java.awt.event.MouseEvent evt) { int width = this.getWidth(); int height = this.getHeight(); if (width - evt.getX() < 10 && height - evt.getY() < 10) { mouseClicked = true; lastX = -1; lastY = -1; } } public void mouseReleasedHandler(java.awt.event.MouseEvent evt) { mouseClicked = false; View.updateView(); } public void mouseDraggedHandler(java.awt.event.MouseEvent evt) { if (mouseClicked) { if (lastX != -1) { int thisX = evt.getX(); int thisY = evt.getY(); int deltaWidth = thisX - lastX; int deltaHeight = thisY - lastY; int width = this.getWidth(); int height = this.getHeight(); width += deltaWidth; height += deltaHeight; PrimitivePointer pWidth = PrimitiveFactory.create(PrimitiveInteger.pseudocodeTypeName(), "__width"); PrimitivePointer pHeight = PrimitiveFactory.create(PrimitiveInteger.pseudocodeTypeName(), "__height"); PrimitiveInteger pw = (PrimitiveInteger)pWidth.dereference(); PrimitiveInteger ph = (PrimitiveInteger)pHeight.dereference(); pw.setValue(width); ph.setValue(height); pp.set("__width", pWidth); pp.set("__height", pHeight); setSize(new Dimension(width, height)); this.invalidate(); } lastX = evt.getX(); lastY = evt.getY(); } } }