package ui.view; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Dialog.ModalityType; import java.awt.Dimension; import java.awt.event.ItemEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.math.RoundingMode; import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.stream.Collectors; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.DefaultComboBoxModel; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFormattedTextField; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.JTree; import javax.swing.SwingUtilities; import javax.swing.border.EmptyBorder; import javax.swing.text.NumberFormatter; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import classes.AbstractCpsObject; import classes.Constrain; import classes.CpsUpperNode; import classes.Flexibility; import classes.HolonElement; import classes.HolonElement.Priority; import classes.HolonObject; import ui.controller.Control; import ui.controller.FlexManager; import ui.controller.FlexManager.FlexState; import ui.controller.FlexManager.FlexWrapper; import ui.model.Model; public class FlexWindow extends JFrame { private JPanel nothingSelectedPanel; private JPanel selectedPanel; private JTabbedPane contentPanel = new JTabbedPane(); private JScrollPane usageViewPanel; private Control controller; private Model model; public boolean isClosed = false; //Flexibility Intermediate private Flexibility intermediateFlex = new Flexibility(null); private boolean offered = true, onConstrain = true, offConstrain =false; //JTree private DefaultMutableTreeNode listOfAllSelectedHolonObjects; private JTree stateTree; private DefaultTreeModel treeModel; private FlexManager flexmanager; public FlexWindow(JFrame parentFrame, ui.controller.Control controller){ this.intermediateFlex.name = "name"; this.controller = controller; this.model = controller.getModel(); //InitWindow createMenuBar(); initWindowPanel(parentFrame); selectedCpsObjectsChanged(); this.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { isClosed = true; } }); //this.pack(); } private void initWindowPanel(JFrame parentFrame) { this.setBounds(0, 0, 400, parentFrame.getHeight()>20?parentFrame.getHeight()- 20:parentFrame.getHeight()); this.setIconImage(Util.loadImage("/Images/Holeg.png", 30, 30)); this.setTitle("Flexibility"); this.setLocationRelativeTo(parentFrame); this.setVisible(true); //this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); createNothingSelectedPanel(); createSelectedPanel(); createUsageViewPanel(); contentPanel.addTab("Settings", nothingSelectedPanel); contentPanel.addTab("Order", usageViewPanel); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); this.setContentPane(contentPanel); this.revalidate(); } private void createMenuBar(){ JMenuBar menuBar = new JMenuBar(); JMenu canvas = new JMenu("Canvas"); menuBar.add(canvas); JMenuItem selectAllMenuItem = new JMenuItem("Select All"); selectAllMenuItem.addActionListener(clicked -> selectAll()); canvas.add(selectAllMenuItem); JMenuItem updateMenuItem = new JMenuItem("Update"); updateMenuItem.addActionListener(clicked -> selectedCpsObjectsChanged()); canvas.add(updateMenuItem); JMenu flex = new JMenu("Flex"); menuBar.add(flex); JMenuItem addMenuItem = new JMenuItem("Add Flexibility"); addMenuItem.addActionListener(clicked -> createAddDialog()); flex.add(addMenuItem); JMenuItem deleteMenuItem = new JMenuItem("Delete Flexibility"); deleteMenuItem.addActionListener(clicked -> createDeleteDialog()); flex.add(deleteMenuItem); this.setJMenuBar(menuBar); } private void selectAll() { model.getSelectedCpsObjects().clear(); model.getSelectedCpsObjects().addAll(model.getObjectsOnCanvas()); selectedCpsObjectsChanged(); } private void createUsageViewPanel() { flexmanager = controller.getSimManager().getActualFlexManager(); //GridBagApprouch JPanel gridbagPanel = new JPanel(new GridBagLayout()); usageViewPanel = new JScrollPane(gridbagPanel); gridbagPanel.setBackground(Color.white); //5breit FlexState[] titles = FlexState.values(); for(int i = 0; i<5; i++){ List listOfFlexWithState = flexmanager.getAllFlexWrapperWithState(titles[i]); JLabel label = new JLabel(titles[i].toString() + "[" + listOfFlexWithState.size()+ "]"); GridBagConstraints labelC = new GridBagConstraints(); labelC.gridx = 1; labelC.gridy = i*2; labelC.anchor = GridBagConstraints.LINE_START; labelC.fill = GridBagConstraints.HORIZONTAL; labelC.weightx = 0.5; labelC.weighty = 0.0; gridbagPanel.add(label, labelC); JPanel listPanel = new JPanel(new GridBagLayout()); createFlexPanel(listPanel, listOfFlexWithState); GridBagConstraints panelC = new GridBagConstraints(); panelC.gridx = 0; panelC.gridwidth = 2; panelC.gridy = i*2 +1; panelC.fill = GridBagConstraints.BOTH; gridbagPanel.add(listPanel, panelC); JButton expandButton = new JButton("-"); GridBagConstraints buttonC = new GridBagConstraints(); buttonC.gridx = 0; buttonC.gridy = i*2; gridbagPanel.add(expandButton, buttonC); expandButton.addActionListener(clicked -> { listPanel.setVisible(!listPanel.isVisible()); expandButton.setText(listPanel.isVisible()?"-":"+"); }); } //Add Spacer JLabel spacer = new JLabel(); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 5*2; c.fill = GridBagConstraints.VERTICAL; c.weightx = 0.0; c.weighty = 1; gridbagPanel.add(spacer, c); } private void createFlexPanel(JPanel listPanel, List flexWrapperList) { listPanel.setBackground(Color.white); Insets insets = new Insets(2,2,2,2); //String[] flexesString = flexWrapperList.stream().map(flexWrapper -> flexWrapper.getFlex().name).toArray(String[]::new); for(int i = 0; i < flexWrapperList.size(); i++) { FlexWrapper actual = flexWrapperList.get(i); GridBagConstraints c = new GridBagConstraints(); c.gridx = Math.floorMod(i, 5); c.weightx = 0.0; c.insets = insets; JButton labelButton = new JButton(actual.getFlex().name); labelButton.setPreferredSize(new Dimension(70,70)); labelButton.setBorder(BorderFactory.createLineBorder(Color.black)); listPanel.add(labelButton, c); labelButton.addActionListener(clicked ->{ actual.order(); controller.calculateStateAndVisualForCurrentTimeStep(); controller.updateCanvas(); }); labelButton.setToolTipText(createToolTipp(actual)); } //AddSpacer JLabel spacer = new JLabel(); GridBagConstraints c = new GridBagConstraints(); c.gridx = 5; c.gridy = 0; c.fill = GridBagConstraints.VERTICAL; c.weightx = 1; c.weighty = 0; listPanel.add(spacer, c); } private String createToolTipp(FlexWrapper actual) { String tooltipString = "" + "" + actual.getFlex().name + "( " + actual.getFlex().getElement().getEleName() + " )
" + ((actual.remainingDuration() != 0)?"Remaining Duration:"+ actual.remainingDuration()+"
":"") + ((actual.remainingTimeTillActivation() != 0)?"Remaining TimeTillActivation:"+ actual.remainingTimeTillActivation()+"
":"") + "Duration: " + actual.getFlex().getDuration() + "
" + "Cooldown: " + actual.getFlex().getCooldown() + "
" //+ "Speed: " + actual.getFlex().speed + "
" + "Cost: " + actual.getFlex().cost + "
" + "BrigtMir: " + actual.getFlex().bringtmir() + "
" + "Constrains: " + actual.getFlex().constrainList.stream().map(constrain -> constrain.getName()).collect(Collectors.joining( "," )) + "
" + ""; return tooltipString; } public void updateFlexOrderMenu() { createUsageViewPanel(); contentPanel.setComponentAt(contentPanel.indexOfTab("Order"), usageViewPanel); contentPanel.revalidate(); } private void createSelectedPanel() { //Liste aller Flexibilities listOfAllSelectedHolonObjects = new DefaultMutableTreeNode("HolonObjects"); treeModel = new DefaultTreeModel(listOfAllSelectedHolonObjects); stateTree = new JTree(treeModel); stateTree.setComponentPopupMenu(new PopUpDemo(stateTree, treeModel)); selectedPanel = new JPanel(new BorderLayout()); selectedPanel.add(new JScrollPane(stateTree)); } private void createNothingSelectedPanel() { nothingSelectedPanel = new JPanel(); nothingSelectedPanel.setLayout(new BoxLayout(nothingSelectedPanel, BoxLayout.PAGE_AXIS)); JLabel nothingSelectedTextLabel = new JLabel("No HolonObject selected."); nothingSelectedTextLabel.setForeground(Color.gray); nothingSelectedTextLabel.setAlignmentX(Component.CENTER_ALIGNMENT); nothingSelectedPanel.add(Box.createVerticalGlue()); nothingSelectedPanel.add(nothingSelectedTextLabel); nothingSelectedPanel.add(Box.createVerticalGlue()); } public void selectedCpsObjectsChanged() { //TODO:Maybe wrong place updateFlexOrderMenu(); if(model.getSelectedCpsObjects().isEmpty()) { contentPanel.setComponentAt(contentPanel.indexOfTab("Settings"), nothingSelectedPanel); contentPanel.revalidate(); //this.revalidate(); return; } listOfAllSelectedHolonObjects.removeAllChildren(); //Init with HolonObjects for(AbstractCpsObject aCps: model.getSelectedCpsObjects()) { DefaultMutableTreeNode newObjectChild = new DefaultMutableTreeNode(aCps.getName() + " ID:" + aCps.getId()); if(aCps instanceof HolonObject) expandTreeHolonObject((HolonObject)aCps, newObjectChild); if(aCps instanceof CpsUpperNode)expandTreeUpperNode((CpsUpperNode)aCps, newObjectChild); listOfAllSelectedHolonObjects.add(newObjectChild); } treeModel.nodeStructureChanged(listOfAllSelectedHolonObjects); stateTree.revalidate(); // stateTree.addMouseListener(new MouseAdapter() { // // @Override // public void mousePressed(MouseEvent e) { // System.out.println("MouseEvent"); // if (!SwingUtilities.isRightMouseButton(e)) return; // // } // }); expandAll(stateTree); selectedPanel.revalidate(); contentPanel.setComponentAt(contentPanel.indexOfTab("Settings"), selectedPanel); contentPanel.revalidate(); this.revalidate(); } private void expandAll(JTree tree) { for(int i = 0; i< tree.getRowCount() ; i++) { tree.expandRow(i); } } private void expandTreeUpperNode(CpsUpperNode groupNode, DefaultMutableTreeNode root) { for(AbstractCpsObject aCps: groupNode.getNodes()) { DefaultMutableTreeNode newObjectChild = new DefaultMutableTreeNode(aCps.getName() + " ID:" + aCps.getId()); if(aCps instanceof HolonObject) expandTreeHolonObject((HolonObject)aCps, newObjectChild); if(aCps instanceof CpsUpperNode)expandTreeUpperNode((CpsUpperNode)aCps, newObjectChild); root.add(newObjectChild); } } private void expandTreeHolonObject(HolonObject hObject, DefaultMutableTreeNode root) { for(HolonElement hElement: hObject.getElements()) { DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(new ElementInfo(hElement)); expandTreeFlex(hElement, newChild); root.add(newChild); } } private void expandTreeFlex(HolonElement hElement, DefaultMutableTreeNode root) { for(Flexibility flex: hElement.flexList) { DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(""+"Flex: "+ "" + flex.name+ "" + ""); root.add(newChild); } } private void createDeleteDialog() { List list= createListOfHolonObjects(model.getObjectsOnCanvas()); //String test = list.stream().map(Object::toString).collect(Collectors.joining(",")); Object[] allFlexes = list.stream().flatMap(hObject -> hObject.getElements().stream()).flatMap(hElement -> hElement.flexList.stream()).toArray(size -> new Flexibility[size]); if(allFlexes.length == 0) { JOptionPane.showMessageDialog(this, "No Flexibility exist.", "Warning", JOptionPane.WARNING_MESSAGE); return; } Flexibility toDeleteFlex =(Flexibility) JOptionPane.showInputDialog(this, "Select to Delete Flexibility:", "Flexibility?", JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , allFlexes, ""); if(toDeleteFlex != null) { System.out.println("ToDelete:" + toDeleteFlex); toDeleteFlex.getElement().flexList.remove(toDeleteFlex); controller.getSimManager().calculateStateForTimeStep(model.getCurIteration(), true); selectedCpsObjectsChanged(); } } private List createListOfHolonObjects(List objectsOnCanvas) { List list = new ArrayList(); for(AbstractCpsObject aCps : objectsOnCanvas) { if(aCps instanceof HolonObject) list.add((HolonObject) aCps); else if (aCps instanceof CpsUpperNode) list.addAll(createListOfHolonObjects(((CpsUpperNode)aCps).getNodes())); } return list; } //Add Element private void createAddDialog(){ if(model.getObjectsOnCanvas().isEmpty()) { JOptionPane.showMessageDialog(this, "No HolonObject exist.", "Warning", JOptionPane.WARNING_MESSAGE); return; } JDialog addDialog = new JDialog(); addDialog.setTitle("Create Flexibility"); addDialog.setBounds(0, 0, 820, 400); addDialog.setDefaultCloseOperation(DISPOSE_ON_CLOSE); JPanel dialogPanel = new JPanel(new BorderLayout()); addDialog.setContentPane(dialogPanel); JPanel selectionPanel = new JPanel(null); dialogPanel.add(selectionPanel, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); dialogPanel.add(buttonPanel, BorderLayout.PAGE_END); addDialog.setModalityType(ModalityType.APPLICATION_MODAL); //Erstelle HolonObject AuswahlBox HolonObject[] holonObjects = createListOfHolonObjects(model.getObjectsOnCanvas()).stream().toArray(HolonObject[]::new); DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel( holonObjects ); JComboBox holonObjectSelector = new JComboBox(comboBoxModel); holonObjectSelector.setBounds(10,30, 800, 30); selectionPanel.add(holonObjectSelector); DefaultComboBoxModel comboBoxModelElements = new DefaultComboBoxModel( holonObjects[0].getElements().stream().toArray(size -> new HolonElement[size])); JComboBox holonElementSelector = new JComboBox(comboBoxModelElements); holonElementSelector.setBounds(10,80, 800, 30); selectionPanel.add(holonElementSelector); holonObjectSelector.addItemListener(aListener -> { if(aListener.getStateChange() == ItemEvent.SELECTED) { System.out.println("Selected"); DefaultComboBoxModel newComboBoxModelElements = new DefaultComboBoxModel( ((HolonObject) aListener.getItem()).getElements().stream().toArray(size -> new HolonElement[size])); holonElementSelector.setModel(newComboBoxModelElements); } }); JLabel selectObjectLabel = new JLabel("Select HolonObject:"); selectObjectLabel.setBounds(10, 10, 200, 20); selectionPanel.add(selectObjectLabel); JLabel selectElementLabel = new JLabel("Select HolonElement:"); selectElementLabel.setBounds(10, 60, 200, 20); selectionPanel.add(selectElementLabel); JPanel flexAttributesBorderPanel = new JPanel(null); flexAttributesBorderPanel.setBounds(10, 120, 800, 200); flexAttributesBorderPanel.setBorder(BorderFactory.createTitledBorder("Flexibility Attributes")); selectionPanel.add(flexAttributesBorderPanel); JLabel flexNameLabel = new JLabel("Name:"); flexNameLabel.setBounds(10,20, 50, 20); flexAttributesBorderPanel.add(flexNameLabel); JFormattedTextField nameTextField = new JFormattedTextField(intermediateFlex.name); nameTextField.addPropertyChangeListener(changed -> intermediateFlex.name = nameTextField.getText()); nameTextField.setBounds(80, 15, 200, 30); flexAttributesBorderPanel.add(nameTextField); JLabel flexSpeedLabel = new JLabel("Speed:"); flexSpeedLabel.setBounds(10,55, 50, 20); flexAttributesBorderPanel.add(flexSpeedLabel); //Integer formatter NumberFormat format = NumberFormat.getIntegerInstance(); format.setGroupingUsed(false); format.setParseIntegerOnly(true); NumberFormatter integerFormatter = new NumberFormatter(format); integerFormatter.setMinimum(0); integerFormatter.setCommitsOnValidEdit(true); JFormattedTextField speedTextField = new JFormattedTextField(integerFormatter); speedTextField.setValue(intermediateFlex.speed); speedTextField.setToolTipText("Only positive Integer."); speedTextField.addPropertyChangeListener(actionEvent -> intermediateFlex.speed = Integer.parseInt(speedTextField.getValue().toString())); speedTextField.setBounds(80, 50, 200, 30); flexAttributesBorderPanel.add(speedTextField); speedTextField.setEnabled(false); JLabel flexDurationLabel = new JLabel("Duration:"); flexDurationLabel.setBounds(10,90, 70, 20); flexAttributesBorderPanel.add(flexDurationLabel); NumberFormatter moreThenZeroIntegerFormater = new NumberFormatter(format); moreThenZeroIntegerFormater.setMinimum(1); moreThenZeroIntegerFormater.setCommitsOnValidEdit(true); JFormattedTextField durationTextField = new JFormattedTextField(moreThenZeroIntegerFormater); durationTextField.setValue(intermediateFlex.getDuration()); durationTextField.setToolTipText("Only positive Integer bigger then 0."); durationTextField.addPropertyChangeListener(actionEvent -> intermediateFlex.setDuration(Integer.parseInt(durationTextField.getValue().toString()))); durationTextField.setBounds(80, 85, 200, 30); flexAttributesBorderPanel.add(durationTextField); JLabel flexCostsLabel = new JLabel("Costs:"); flexCostsLabel.setBounds(10,125, 70, 20); flexAttributesBorderPanel.add(flexCostsLabel); //Double Format: NumberFormat doubleFormat = NumberFormat.getNumberInstance(Locale.US); doubleFormat.setMinimumFractionDigits(1); doubleFormat.setMaximumFractionDigits(2); doubleFormat.setRoundingMode(RoundingMode.HALF_UP); //CostFormatter: NumberFormatter costsFormatter = new NumberFormatter(doubleFormat); costsFormatter.setMinimum(0.0); JFormattedTextField costTextField = new JFormattedTextField(costsFormatter); costTextField.setValue(intermediateFlex.cost); costTextField.setToolTipText("Only non negative Double with DecimalSeperator Point('.')."); costTextField.addPropertyChangeListener(propertyChange -> intermediateFlex.cost = Float.parseFloat(costTextField.getValue().toString())); costTextField.setBounds(80, 120, 200, 30); flexAttributesBorderPanel.add(costTextField); JLabel flexCooldownLabel = new JLabel("Cooldown:"); flexCooldownLabel.setBounds(310,20, 70, 20); flexAttributesBorderPanel.add(flexCooldownLabel); JFormattedTextField cooldownTextField = new JFormattedTextField(moreThenZeroIntegerFormater); cooldownTextField.setValue(intermediateFlex.getCooldown()); cooldownTextField.setToolTipText("Only positive Integer."); cooldownTextField.addPropertyChangeListener(actionEvent -> intermediateFlex.setCooldown(Integer.parseInt(cooldownTextField.getValue().toString()))); cooldownTextField.setBounds(380, 15, 200, 30); flexAttributesBorderPanel.add(cooldownTextField); JCheckBox offeredCheckBox = new JCheckBox("Offered"); offeredCheckBox.setSelected(this.offered); offeredCheckBox.setBounds(310, 55, 200, 20); flexAttributesBorderPanel.add(offeredCheckBox); JCheckBox onConstrainCheckBox = new JCheckBox("On_Constrain"); onConstrainCheckBox.setSelected(this.onConstrain); onConstrainCheckBox.setBounds(310, 80, 200, 20); flexAttributesBorderPanel.add(onConstrainCheckBox); JCheckBox offConstrainCheckBox = new JCheckBox("Off_Constrain"); offConstrainCheckBox.setSelected(this.offConstrain); offConstrainCheckBox.setBounds(310, 105, 200, 20); flexAttributesBorderPanel.add(offConstrainCheckBox); //Both cant be true.... onConstrainCheckBox.addActionListener(clicked -> { if(onConstrainCheckBox.isSelected()) offConstrainCheckBox.setSelected(false); }); offConstrainCheckBox.addActionListener(clicked -> { if(offConstrainCheckBox.isSelected()) onConstrainCheckBox.setSelected(false); }); JButton createFlexButton = new JButton("Create"); createFlexButton.addActionListener(clicked -> { //createFlexButton.requestFocus(); //createFlexButton.grabFocus(); HolonElement ele = (HolonElement) holonElementSelector.getSelectedItem(); Flexibility toCreateFlex = new Flexibility(ele); toCreateFlex.name = intermediateFlex.name; toCreateFlex.speed = intermediateFlex.speed; toCreateFlex.setDuration(intermediateFlex.getDuration()); toCreateFlex.cost = intermediateFlex.cost; toCreateFlex.setCooldown(intermediateFlex.getCooldown()); toCreateFlex.offered=offeredCheckBox.isSelected(); if(onConstrainCheckBox.isSelected())toCreateFlex.constrainList.add(Constrain.createOnConstrain()); if(offConstrainCheckBox.isSelected())toCreateFlex.constrainList.add(Constrain.createOffConstrain()); ele.flexList.add(toCreateFlex); //save checkboxes this.offered=offeredCheckBox.isSelected(); this.onConstrain = onConstrainCheckBox.isSelected(); this.offConstrain = offConstrainCheckBox.isSelected(); if(!model.getSelectedCpsObjects().contains(holonObjectSelector.getSelectedItem()))model.getSelectedCpsObjects().add((AbstractCpsObject)holonObjectSelector.getSelectedItem()); controller.getSimManager().calculateStateForTimeStep(model.getCurIteration(), false); selectedCpsObjectsChanged(); addDialog.dispose(); }); buttonPanel.add(createFlexButton); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(clicked -> { addDialog.dispose(); }); buttonPanel.add(cancelButton); //last addDialog.setLocationRelativeTo(this); addDialog.setVisible(true); } class PopUpDemo extends JPopupMenu { JMenuItem anItem; public PopUpDemo(JTree jTree, DefaultTreeModel model) { anItem = new JMenuItem("EditPriorities"); anItem.addActionListener( clicked -> { TreePath[] paths = jTree.getSelectionPaths(); if(paths == null) { jTree.setSelectionInterval(0, jTree.getRowCount()); paths = jTree.getSelectionPaths(); } Priority prio = null; for (TreePath path : jTree.getSelectionPaths()) { Object treeNodeUserObject = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject(); if(treeNodeUserObject instanceof ElementInfo) { if(prio == null) prio = makePriorityDialog(); if(prio == null) break; ElementInfo eleInfo = (ElementInfo)treeNodeUserObject; eleInfo.ele.setPriority(prio); model.reload((DefaultMutableTreeNode)path.getLastPathComponent()); } } }); add(anItem); } private Priority makePriorityDialog() { return (Priority) JOptionPane.showInputDialog(this, "Select the Priority:", "Priority?", JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , Priority.values(), ""); } } class ElementInfo { HolonElement ele; public ElementInfo(HolonElement ele) { this.ele = ele; } @Override public String toString() { return ele.getEleName() + " Priority:" + ele.getPriority(); } } }