public void startEditing(final PartType pt) { isEditing = true; isDeleting = false; setUpLeftPanel(); selectedImagePath = new String(pt.getImagePath()); leftTitle.setText("Editing Part " + pt.getName()); nameField.setText(pt.getName()); numField.setText(String.valueOf(pt.getPartNum())); descField.setText(pt.getDescription()); badChanceScroller.setValue((int) (pt.getBadChance() * 100)); imageClickablePanels.get(pt.getImagePath()).getHandler().mouseClicked(); submitButton.setText("Edit >"); removeAllActionListener(submitButton); submitButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO try and get rid of this hack float newChance = (float) badChanceScroller.getValue(); pt.setName(nameField.getText()); pt.setPartNum(Integer.parseInt(numField.getText())); pt.setDescription(descField.getText()); pt.setBadChance(newChance / 100); pt.setImagePath(selectedImagePath); manager.editPart(pt); restoreLeftPanel(); } }); }
public void startDeleting(final PartType pt) { isEditing = false; isDeleting = true; setUpLeftPanel(); leftTitle.setText("Deleting Part " + pt.getName()); nameField.setText(pt.getName()); nameField.setEnabled(false); numField.setText(String.valueOf(pt.getPartNum())); numField.setEnabled(false); descField.setText(pt.getDescription()); descField.setEnabled(false); badChanceScroller.setValue((int) (pt.getBadChance() * 100)); badChanceScroller.setEnabled(false); imageClickablePanels.get(pt.getImagePath()).getHandler().mouseClicked(); submitButton.setText("Confirm Delete >"); removeAllActionListener(submitButton); submitButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { manager.deletePart(pt); restoreLeftPanel(); } }); }
public void setUpLeftPanel() { leftPanel.removeAll(); leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS)); leftPanel.setAlignmentX(LEFT_ALIGNMENT); leftPanel.setBorder(Constants.PADDING); leftTitle = new WhiteLabel("Create a New Part"); leftTitle.setFont(new Font("Arial", Font.PLAIN, 20)); leftTitle.setLabelSize(300, 40); leftTitle.setAlignmentX(0); leftPanel.add(leftTitle); JPanel namePanel = new JPanel(); namePanel.setBorder(Constants.TOP_PADDING); namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.LINE_AXIS)); namePanel.setOpaque(false); namePanel.setVisible(true); namePanel.setAlignmentX(0); leftPanel.add(namePanel); WhiteLabel nameLabel = new WhiteLabel("Name"); nameLabel.setLabelSize(100, 25); namePanel.add(nameLabel); nameField = new JTextField("name"); nameField.setMaximumSize(new Dimension(200, 25)); nameField.setBorder(Constants.FIELD_PADDING); namePanel.add(nameField); JPanel numPanel = new JPanel(); numPanel.setBorder(Constants.TOP_PADDING); numPanel.setLayout(new BoxLayout(numPanel, BoxLayout.LINE_AXIS)); numPanel.setOpaque(false); numPanel.setVisible(true); numPanel.setAlignmentX(0); leftPanel.add(numPanel); WhiteLabel numLabel = new WhiteLabel("Part no."); numLabel.setLabelSize(100, 25); numPanel.add(numLabel); numField = new WhiteLabel("" + (rightPanel.getItemList().size() + 1)); numField.setMaximumSize(new Dimension(200, 25)); numField.setBorder(Constants.FIELD_PADDING); numPanel.add(numField); JPanel descPanel = new JPanel(); descPanel.setBorder(Constants.TOP_PADDING); descPanel.setLayout(new BoxLayout(descPanel, BoxLayout.LINE_AXIS)); descPanel.setOpaque(false); descPanel.setVisible(true); descPanel.setAlignmentX(0); leftPanel.add(descPanel); WhiteLabel descLabel = new WhiteLabel("Description"); descLabel.setLabelSize(100, 25); descPanel.add(descLabel); descField = new JTextArea("Description..."); descField.setMinimumSize(new Dimension(200, 70)); descField.setMaximumSize(new Dimension(200, 70)); descField.setPreferredSize(new Dimension(200, 70)); descField.setBorder(Constants.FIELD_PADDING); descPanel.add(descField); JPanel chancePanel = new JPanel(); chancePanel.setBorder(Constants.TOP_PADDING); chancePanel.setLayout(new BoxLayout(chancePanel, BoxLayout.LINE_AXIS)); chancePanel.setOpaque(false); chancePanel.setVisible(true); chancePanel.setAlignmentX(0); leftPanel.add(chancePanel); WhiteLabel chanceLabel = new WhiteLabel("Defect Chance"); chanceLabel.setLabelSize(100, 25); chancePanel.add(chanceLabel); badChanceScroller = new JSlider(JSlider.HORIZONTAL, CHANCE_MIN, CHANCE_MAX, CHANCE_INIT); badChanceScroller.setMajorTickSpacing(50); badChanceScroller.setMinorTickSpacing(5); badChanceScroller.setPaintTicks(true); badChanceScroller.setPaintLabels(true); badChanceScroller.setFont(new Font("Arial", Font.PLAIN, 14)); badChanceScroller.setForeground(Color.WHITE); badChanceScroller.setOpaque(false); chancePanel.add(badChanceScroller); imagePanel = new JPanel(); imagePanel.setBorder(Constants.TOP_PADDING); imagePanel.setLayout(new BoxLayout(imagePanel, BoxLayout.LINE_AXIS)); imagePanel.setOpaque(false); imagePanel.setAlignmentX(0); leftPanel.add(imagePanel); imageLabel = new WhiteLabel("Select Image "); imageLabel.setLabelSize(100, 60); imagePanel.add(imageLabel); imageSelectPanel = new JPanel(); imageSelectPanel.setBackground(new Color(0, 0, 0, 0)); // Iterate through the ArrayList of available images in constants to // populate JScrollPane for (String imagePath : Constants.DEFAULT_IMAGEPATHS) { ClickablePanel imageSelectClickable = new ClickablePanel(new ImageClickHandler(imagePath)); JLabel imageSelectLabel = new JLabel(new ImageIcon(Constants.PART_IMAGE_PATH + imagePath + ".png")); imageSelectLabel.setMinimumSize(new Dimension(50, 30)); imageSelectLabel.setPreferredSize(new Dimension(50, 30)); imageSelectLabel.setMaximumSize(new Dimension(50, 30)); imageSelectClickable.add(imageSelectLabel); imageSelectClickable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); imageSelectClickable.setMinimumSize(new Dimension(50, 30)); imageSelectClickable.setPreferredSize(new Dimension(50, 30)); imageSelectClickable.setMaximumSize(new Dimension(50, 30)); imageSelectPanel.add(imageSelectClickable); imageClickablePanels.put(imagePath, imageSelectClickable); imageSelectPanel.setOpaque(false); } imageSelect = new JScrollPane(imageSelectPanel); imageSelect.setMinimumSize(new Dimension(250, 60)); imageSelect.setPreferredSize(new Dimension(250, 60)); imageSelect.setMaximumSize(new Dimension(250, 60)); // imageSelect.setOpaque(false); imageSelect.setBorder(null); imageSelect.setOpaque(false); imageSelect.getViewport().setOpaque(false); imagePanel.add(imageSelect); JPanel buttonPanel = new JPanel(); buttonPanel.setBorder(Constants.TOP_PADDING); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); buttonPanel.setOpaque(false); buttonPanel.setVisible(true); buttonPanel.setAlignmentX(0); leftPanel.add(buttonPanel); if (isEditing || isDeleting) { JButton cancelButton = new JButton("Cancel"); cancelButton.setMinimumSize(new Dimension(100, 25)); cancelButton.setMaximumSize(new Dimension(100, 25)); cancelButton.setPreferredSize(new Dimension(100, 25)); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { restoreLeftPanel(); } }); buttonPanel.add(cancelButton); } else { WhiteLabel fakeLabel = new WhiteLabel(""); fakeLabel.setLabelSize(100, 25); buttonPanel.add(fakeLabel); } submitButton = new JButton("Submit >"); submitButton.setMinimumSize(new Dimension(200, 25)); submitButton.setMaximumSize(new Dimension(200, 25)); submitButton.setPreferredSize(new Dimension(200, 25)); submitButton.setAlignmentX(0); buttonPanel.add(submitButton); removeAllActionListener(submitButton); submitButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO try to remove this hack float chance = (float) badChanceScroller.getValue(); PartType newPart = new PartType( nameField.getText(), Integer.parseInt(numField.getText()), descField.getText(), chance / 100); newPart.setImagePath(selectedImagePath); manager.createPart(newPart); restoreLeftPanel(); } }); }