Package ch.rakudave.jnetmap.model.device.Device

Examples of ch.rakudave.jnetmap.model.device.Device.Type


    };
   
  }
 
  private static Icon getIcon(Device d, String flag) {
    Type type = d.getType();
    if (type != null) {
      if (type.equals(Type.Other)) {
        ImageIcon img = Icons.fromBase64(d.getOtherID());
        if (img != null) return img;
      } else {
        return Icons.getCisco(type.toString().toLowerCase() + flag);
      }
    }
    return Icons.getCisco("workstation" + flag);
  }
View Full Code Here


  public DeviceProperties(final Frame owner, Device device, final boolean isNew) {
    super(owner, Lang.getNoHTML("device.properties"), ModalityType.DOCUMENT_MODAL);
    d = device;
    setLayout(new BorderLayout(5, 5));
    setPreferredSize(new Dimension(350,500));
    final Type oldType = (d.getType() != null)?d.getType():Type.Workstation;
    JPanel iconPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
      final JLabel deviceIcon = new JLabel((Type.Other.equals(oldType))?Icons.fromBase64(d.getOtherID()):Icons.getCisco(oldType.toString().toLowerCase()));
      iconPanel.add(Box.createVerticalStrut(64));
      iconPanel.add(deviceIcon);
      iconPanel.add(Box.createVerticalStrut(64));
    JPanel centerWrapper = new JPanel(new BorderLayout());
      centerWrapper.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));
      JPanel propPanel = new JPanel(new GridLayout(0, 2, 5, 5));
        final JTextField otherID = new JTextField(d.getOtherID());
        final JComboBox typeCombo = new JComboBox(Device.Type.values());
          typeCombo.setSelectedItem(oldType);
          typeCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              if ("other".equals(typeCombo.getSelectedItem().toString().toLowerCase())) {
                File f = SwingHelper.openDialog(owner, new FileNameExtensionFilter("PNG Image", "png"));
                if (f != null) {
                  String base64 = Icons.getBase64(f);
                  otherID.setText(base64);
                  deviceIcon.setIcon(Icons.fromBase64(base64));
                } else {
                  deviceIcon.setIcon(Icons.getCisco(oldType.toString().toLowerCase()));
                  typeCombo.setSelectedItem(oldType);
                }
              } else {
                deviceIcon.setIcon(Icons.getCisco(typeCombo.getSelectedItem().toString().toLowerCase()));
                otherID.setText("");
              }
            }
          });
        final JTextField deviceName = new JTextField(d.getName());
        final JTextField deviceDesc = new JTextField(d.getDesctription());
        final JTextField deviceLocation = new JTextField(d.getLocation());
        final JTextField deviceVendor = new JTextField(d.getVendor());
        final JTextField deviceModel = new JTextField(d.getModel());
        propPanel.add(new JLabel(Lang.get("device.type"))); propPanel.add(typeCombo);
        propPanel.add(new JLabel(Lang.get("device.name"))); propPanel.add(deviceName);
        propPanel.add(new JLabel(Lang.get("device.description"))); propPanel.add(deviceDesc);
        propPanel.add(new JLabel(Lang.get("device.location"))); propPanel.add(deviceLocation);
        propPanel.add(new JLabel(Lang.get("device.vendor"))); propPanel.add(deviceVendor);
        propPanel.add(new JLabel(Lang.get("device.model"))); propPanel.add(deviceModel);
        propPanel.add(new JLabel(Lang.get("device.interfaces"))); propPanel.add(new JLabel());
      final JList interfaceList = new JList(d.getInterfaces().toArray());
        interfaceList.setCellRenderer(new IFListRenderer());
      JPanel interfaceManipulators = new JPanel();
        interfaceManipulators.setLayout(new BoxLayout(interfaceManipulators, BoxLayout.PAGE_AXIS));
        JButton removeInterface = new JButton(Lang.get("action.remove"), Icons.get("remove"));
          removeInterface.setPreferredSize(new Dimension(100, 30));
          removeInterface.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              if (interfaceList.getSelectedValue() == null) return;
              if (JOptionPane.showConfirmDialog(owner, Lang.get("message.confirm.delete")
                  .replaceAll("%name%", ((NetworkIF) interfaceList.getSelectedValue()).getName()),
                  Lang.getNoHTML("action.delete"), JOptionPane.YES_NO_OPTION) == 1) return;
              Controller.getCurrentMap().removeEdge(((NetworkIF) interfaceList.getSelectedValue()).getConnection());
              interfaceList.setListData(d.getInterfaces().toArray());
            }
          });
        JButton editInterface = new JButton(Lang.get("action.edit"), Icons.get("edit"));
          editInterface.setPreferredSize(new Dimension(100, 30));
          editInterface.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              if (interfaceList.getSelectedValue() == null) return;
              new InterfaceProperties(owner, ((NetworkIF) interfaceList.getSelectedValue()));
              interfaceList.setListData(d.getInterfaces().toArray());
            }
          });
        interfaceManipulators.add(removeInterface);
        interfaceManipulators.add(editInterface);
        interfaceManipulators.add(Box.createVerticalGlue());
      centerWrapper.add(propPanel, BorderLayout.NORTH);
      centerWrapper.add(new JScrollPane(interfaceList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
      centerWrapper.add(interfaceManipulators, BorderLayout.EAST);
    JPanel bottomRow = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
      final JDialog _this = this;
      JButton cancel = new JButton(Lang.get("action.cancel"), Icons.get("cancel"));
        cancel.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            _this.dispose();
          }
        });
      JButton ok = new JButton(Lang.get("action.ok"), Icons.get("ok"));
        ok.setPreferredSize(cancel.getPreferredSize());
        ok.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            final Type newType = (Type)typeCombo.getSelectedItem();
            final String oldName = d.getName(), newName = deviceName.getText(),
              oldID = d.getOtherID(), newID = otherID.getText(),
              oldDesc = d.getDesctription(), newDesc = deviceDesc.getText(),
              oldLocation = d.getLocation(), newLocation = deviceLocation.getText(),
              oldVendor = d.getVendor(), newVentor = deviceVendor.getText(),
View Full Code Here

TOP

Related Classes of ch.rakudave.jnetmap.model.device.Device.Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.