📄 infojpanel.java
字号:
/*
* Created on 1-dec-2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package gui;
import graph.Properties;
import graph.EdgeProperties;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.GraphConstants;
import javax.swing.JPanel;
//import javax.swing.JList;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JComboBox;
//import javax.swing.JComponent;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.Dimension;
import java.awt.Color;
import java.util.Iterator;
/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class InfoJPanel extends JPanel implements ActionListener,KeyListener
{
public InfoJPanel(){
//super();
//setResizable(false);
//getContentPane().
//setLayout(new GridLayout(10,2));
//setLayout(new BorderLayout());
// almostRealContent zorg ervoor dat het altijd bovenaan staat,
// en dat niets verticaal wordt uitgerokken
// realContent zorgt ervoor dat niets horizontaal wordt uitgerokken.
//JPanel almostRealContent = new JPanel(new BorderLayout());
//add(almostRealContent, BorderLayout.NORTH);
//add(new JPanel(), BorderLayout.CENTER);
//realContent = new JPanel(new GridLayout(0, 1));
//realContent = new JPanel();
//realContent.setLayout(null);
//almostRealContent.add(realContent, BorderLayout.WEST);
//almostRealContent.add(new JPanel(), BorderLayout.CENTER);
setLayout(null);
constructPanel();
}
/**
*Publieke Methodes
*/
public void updateInformation(DefaultGraphCell dgc)
{
previousGraphCell = dgc;
informationTypes.removeActionListener(this);
if (dgc != null)
{
preferredType = (String) informationTypes.getSelectedItem();
}
//System.out.println("Preferred-type: " + preferredType);
// verwijder oude informatie
this.informationTypes.removeAllItems();
if (currentComponent != null)
{
remove(currentComponent);
repaint();
}
if (dgc != null && GraphConstants.getValue(dgc.getAttributes()) != null)
{
//System.out.println(GraphConstants.getValue(dgc.getAttributes()));
Properties p = (Properties) GraphConstants.getValue(dgc.getAttributes());
Iterator i = p.getInformationTypes();
// Overloop alle property-types, en steek ze in combo-box
while(i.hasNext())
{
this.informationTypes.addItem((String)i.next());
}
// selecteer het vorige, als er een vorige was, en als het erin zat, zoniet, neem het eerste
boolean changed = true;
for (int k = 0; k < informationTypes.getItemCount(); k++)
{
if ( preferredType != null && ( (String)(informationTypes.getItemAt(k))).compareTo(preferredType) == 0)
{ // Zoek of de string die geselecteerd was nu nog steeds in de combobox zit.
informationTypes.setSelectedIndex(k);
//System.out.println("Preferred found at position " + k);
changed=false;
}
}
if (! changed)
{
//System.out.println("Item van vorige keer geselecteerd, zelfde preferred: " + preferredType);
}
else
{
preferredType = (String)informationTypes.getItemAt(0);
//System.out.println("Item komt niet meer voor, nieuwe preferred: " + preferredType);
}
// Update name en color-label
nameLabel.setText(p.getName());
colorLabel.setBackground(p.getColor());
if (dgc instanceof DefaultEdge)
{
// toon de labels, en vul de capaciteit in.
capacityLabelText.setText("Capacity:");
capacityLabel.setText("" + ((EdgeProperties) GraphConstants.getValue(dgc.getAttributes())).getCapacity());
}
else
{
capacityLabelText.setText("");
capacityLabel.setText("");
}
// Update PropertyComponent
if (((String)informationTypes.getSelectedItem()) != null)
{
//System.out.println(((String)informationTypes.getSelectedItem()));
currentComponent = GUIEventManager.getComponentManager().getComponent(preferredType);
if (currentComponent != null)
{
//System.out.println("update currentComponent");
currentComponent.updateInformation(p);
currentComponent.setBounds(25, 120, 250, 400);
add(currentComponent);
currentComponent.repaint();
}
}
}
else
{
nameLabel.setText("");
colorLabel.setBackground(Color.WHITE);
capacityLabelText.setText("");
capacityLabel.setText("");
}
informationTypes.addActionListener(this);
}
/**
*Vangt de verschillende key-actions op
*In dit geval kan er enkel op enter worden geklikt.Dan wordt het levelnummer opgeslaan.
*/
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e)
{
if (e.getKeyChar() == '\n')
{
//dispose();
}
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource() instanceof JComboBox)
{
//System.out.println("JComboBox changed");
GUIEventManager.getReference().eventUpdateInfoJPanel(previousGraphCell);
}
}
private void constructPanel()
{
for (int i=0; i<5; i++)
{
textLabel[i] = new JLabel();
}
textLabel[0].setText("Name:");
textLabel[0].setOpaque(true);
size = textLabel[0].getPreferredSize();
textLabel[0].setBounds(10, 10, 55, 18);
add(textLabel[0]);
nameLabel = new JLabel("");
nameLabel.setForeground(Color.DARK_GRAY);
nameLabel.setBounds(65, 10, 100, 18);
add(nameLabel);
textLabel[1].setText("Color:");
size = textLabel[1].getPreferredSize();
textLabel[1].setBounds(10, 30, 55, 18);
add(textLabel[1]);
colorLabel = new JLabel("");
colorLabel.setOpaque(true);
colorLabel.setBounds(65, 31, 16, 16);
colorLabel.setBackground(Color.white);
add(colorLabel);
capacityLabelText = new JLabel("");
capacityLabelText.setText("");
size = capacityLabelText.getPreferredSize();
capacityLabelText.setBounds(10, 50, 55, 18);
add(capacityLabelText);
capacityLabel = new JLabel("");
capacityLabel.setForeground(Color.DARK_GRAY);
capacityLabel.setOpaque(true);
capacityLabel.setBounds(65, 50, 30, 18);
add(capacityLabel);
textLabel[3].setText("Properties:");
size = textLabel[3].getPreferredSize();
textLabel[3].setBounds(10, 85, size.width, 18);
add(textLabel[3]);
String[] data = {};
informationTypes = new JComboBox(data);
informationTypes.addActionListener(this);
informationTypes.setActionCommand("changedInformationType");
informationTypes.setBounds(80, 81, 110, 24);
add(informationTypes);
}
private PropertyComponent currentComponent;
private String preferredType;
private DefaultGraphCell previousGraphCell;
private JLabel textLabel[] = new JLabel[5];
private JComboBox informationTypes;
private JButton okButton;
private JLabel nameLabel;
private JLabel colorLabel;
private JLabel capacityLabel;
private JLabel capacityLabelText;
//private JPanel realContent;
private Dimension size;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -