Java Code Examples for javax.swing.JPanel.getHeight()

The following are Jave code examples for showing how to use getHeight() of the javax.swing.JPanel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AgentWorkbench   File: DynForm.java   View Source Code Vote up 6 votes
@Override
protected void removeMultiple(DefaultMutableTreeNode node){
	
	// --- Remind all needed informations -------------------------------------------
	DefaultMutableTreeNode previousNode = node.getPreviousNode();
	DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
	
	DynType dt = (DynType) node.getUserObject();
	JPanel deletePanel = dt.getPanel();
	JPanel parentPanel = (JPanel) deletePanel.getParent();
	
	int movement = (deletePanel.getHeight() + 2) * (-1);
	
	// --- Remove node from the parent node and panel -------------------------------
	DynType dyntype = (DynType) node.getUserObject();
	node.setUserObject(null);
	parentNode.remove(node);
	this.getTreeNodesByDynType().remove(dyntype);
	
	// --- remove the panel from the parent -----------------------------------------
	parentPanel.remove(deletePanel);
	parentPanel.validate();
	this.setPanelBounds(parentPanel);
	
	// --- Now move the rest of the elements on the form ----------------------------
	this.moveAfterAddOrRemove(movement, previousNode);

	// --- refresh the GUI ----------------------------------------------------------
	this.adjustPreferredSize();
	
}
 
Example 2
Project: AgentWorkbench   File: DynForm.java   View Source Code Vote up 5 votes
/**
 * This method creates a so called dead end. This means that originally a class
 * should be displayed which was already displayed on a higher level in direction
 * to the root node. This was realized to prevent the form generation to be run
 * in an endless loop.
 *
 * @param oscsd the oscsd
 * @param className the class name
 * @param depth the depth
 * @param pan the pan
 * @param node the node
 */
private void createOuterDeadEnd(OntologySingleClassSlotDescription oscsd, String className, int depth, JPanel pan, DefaultMutableTreeNode node){
	
	// --- this outer element has no parents which are inner classes
	// --- so its added to the mainPanel
	final JPanel dataPanel = new JPanel();
	dataPanel.setLayout(null);
	dataPanel.setToolTipText(oscsd.getSlotName() + "-Panel");
	
	// --- add a JLabel to display the field's name
	JLabel valueFieldText = new JLabel();
	valueFieldText.setText("<html>" + oscsd.getSlotName() + " ["+oscsd.getSlotVarType()+"] - <b>" + Language.translate("Zyklisch !") + "</b></html>");
	valueFieldText.setBounds(new Rectangle(0, 4, 330, 16));
	
	// --- add both GUI elements to the panel
	dataPanel.add(valueFieldText, null);
	this.setPanelBounds(dataPanel);
	
	DynType dynType = new DynType(oscsd, DynType.typeCyclic, className, dataPanel, oscsd.getSlotName(), null);
	node.add(new DefaultMutableTreeNode(dynType));
	
	// --- set the new position (increment the height) for the parent panel of the 
	// --- newly created panel
	Rectangle pos = dataPanel.getBounds();
	pos.x = 10;//tiefe * einrueckungProUntereEbene;
	pos.y = pan.getHeight();
	dataPanel.setBounds(pos);

	pan.add(dataPanel);
	this.setPanelBounds(pan);
	
}
 
Example 3
Project: SE2017-Team1   File: TestUtil.java   View Source Code Vote up 5 votes
public static void exportToImage(String format, JPanel dPanel, String fileName) {
  BufferedImage bImg = new BufferedImage(dPanel.getWidth(), dPanel.getHeight(), BufferedImage.TYPE_INT_RGB);
  Graphics2D cg = bImg.createGraphics();
  dPanel.paintAll(cg);
  try {
          if (ImageIO.write(bImg, "jpg", new File("./" + fileName + "." + format)))
          {
              System.out.println("image saved succesfully");
          }
  } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
  }
}
 
Example 4
Project: SE2017-Team1   File: TestUtil.java   View Source Code Vote up 5 votes
public static void exportToImage(String format, JPanel dPanel, String fileName) {
  BufferedImage bImg = new BufferedImage(dPanel.getWidth(), dPanel.getHeight(), BufferedImage.TYPE_INT_RGB);
  Graphics2D cg = bImg.createGraphics();
  dPanel.paintAll(cg);
  try {
          if (ImageIO.write(bImg, "jpg", new File("./" + fileName + "." + format)))
          {
              System.out.println("image saved succesfully");
          }
  } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
  }
}
 
Example 5
Project: AgentWorkbench   File: DynForm.java   View Source Code Vote up 4 votes
@Override
protected DefaultMutableTreeNode addSingleMultipleNode(DefaultMutableTreeNode node, boolean isInnerClass){
	
	// --- Get all needed information about the node, which has to be copied --------
	DynType dt = (DynType) node.getUserObject();
	String clazz = dt.getClassName();
	OntologySingleClassSlotDescription oscsd = dt.getOntologySingleClassSlotDescription();
	
	JPanel oldPanel = dt.getPanel();
	JPanel parentPanel = (JPanel) oldPanel.getParent();

	// --- Get parent node ----------------------------------------------------------
	DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); 
	int depth2WorkOn = parentNode.getLevel()-1;
	
	// --- Create the panel/node as needed as a copy of the current node ------------
	JPanel blindPanel = new JPanel();
	blindPanel.setLayout(null);
	DefaultMutableTreeNode newNode = null;
	
	if (isInnerClass==true) {
		newNode = this.createInnerElements(oscsd, clazz, depth2WorkOn+1, blindPanel, parentNode, true);
		if (oldPanel.isVisible()==false) {
			// --- Case special class: set invisible and small ------------ 
			this.setJPanelInvisibleAndSmall(newNode);
		}
		
	} else {
		newNode = this.createOuterElements(oscsd, depth2WorkOn, blindPanel, parentNode, true);
	}
	
	// --- Place the node at the right position in the tree -------------------------
	newNode.removeFromParent();
	int nodeIndexPos = parentNode.getIndex(node)+1;
	objectTree.insertNodeInto(newNode, parentNode, nodeIndexPos);
	
	// --- Set the size of the new Panel --------------------------------------------
	DynType dtNew = (DynType) newNode.getUserObject();
	JPanel newPanel = dtNew.getPanel();
	
	// --- Layout the new panel -----------------------------------------------------
	if (oldPanel.isVisible()==true) {
		// ----------------------------------------------------------------
		// --- The normal case for visible classes ------------------------
		// ----------------------------------------------------------------			
		this.setPanelBounds(newPanel);
		newPanel.setPreferredSize(newPanel.getSize());

		// --- Now place the new sub panel on the right super panel -------
		int movement = oldPanel.getHeight() + 2;
		int xPos = oldPanel.getX();
		int yPos = oldPanel.getY() + movement;
		newPanel.setBounds(xPos, yPos, newPanel.getWidth(), newPanel.getHeight());
		
		// --- Add to parent panel ----------------------------------------
		parentPanel.add(newPanel);
		parentPanel.validate();
		this.setPanelBounds(parentPanel);
		
		// --- Now move the rest of the elements on the form ----------------------------
		this.moveAfterAddOrRemove(movement, newNode);
		
	} else {
		// ----------------------------------------------------------------
		// --- The case for special classes, that have to be invisible ----
		// ----------------------------------------------------------------
		newPanel.setVisible(false);
		newPanel.setBounds(oldPanel.getBounds());
		
	}
	
	// --- refresh the GUI ----------------------------------------------------------
	this.adjustPreferredSize();
	
	return newNode;
}
 
Example 6
Project: jaer   File: Head6DOF_GUI.java   View Source Code Vote up 4 votes
private Point gaze2pix(JPanel pan, Point2D.Float gaze) {
    int h=pan.getHeight(), w=pan.getWidth();
    // (g+1)/2 ranges 0:1
    p2.setLocation((gaze.x + 1) / 2 * w, h-((gaze.y + 1) / 2 * h)); // y starts from top in AWT, so flip y here
    return p2;
}