CPD Results

The following document contains the results of PMD's CPD 3.7.

Duplications

FileLine
org\fosstrak\hal\impl\sim\GraphicSimulator.java524
org\fosstrak\hal\impl\sim\multi\GraphicSimulatorServer.java451
		for(int i = 0; i < 4 - new Integer(tags.size()).toString().length(); i++) {
			id += "0";
		}
		id += tags.size();
		if(tagIdField == null) {
			tagIdField = new JTextField();
		}
		tagIdField.setText(id);
		
		// create tag dialog if it does not already exists
		if(newTagDialog == null) {
			newTagDialog = new JDialog(this, guiTextConfig.getString("AddNewTagDialogTitle"), true);
			newTagDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight"));
			newTagDialog.setLayout(new BorderLayout());
			
			// input fields panel
			JLabel epcLabel = new JLabel(guiTextConfig.getString("TagIdLabel") + ": ");
			JPanel inputFields = new JPanel();
			inputFields.setLayout(new GridLayout(2, 2));
			inputFields.add(epcLabel);
			inputFields.add(tagIdField);
			
			// cancel button
			JButton cancelButton = new JButton(guiTextConfig.getString("CancelButton"));
			cancelButton.addMouseListener(new MouseAdapter() {
				public void mouseReleased(MouseEvent e) {
					newTagDialog.setVisible(false);
				}
			});
			
			// add button
			JButton addButton = new JButton(guiTextConfig.getString("AddButton"));
			addButton.addMouseListener(new MouseAdapter() {
				public void mouseReleased(MouseEvent e) {
					newTagDialog.setVisible(false);
					createNewTag(tagIdField.getText());
				}
			});
			
			// buttons panel
			JPanel buttons = new JPanel();
			buttons.add(addButton);
			buttons.add(cancelButton);
			
			// compose all together
			newTagDialog.add(inputFields, BorderLayout.CENTER);
			newTagDialog.add(buttons, BorderLayout.SOUTH);
			newTagDialog.getRootPane().setDefaultButton(addButton);
		}
		newTagDialog.setLocation(pos);
		newTagDialog.setVisible(true);
	}

	/**
	 * updates the GUI with new reader information 
	 */
	private void updateGUI() {

FileLine
org\fosstrak\hal\impl\sim\GraphicSimulator.java331
org\fosstrak\hal\impl\sim\multi\GraphicSimulatorServer.java311
				JDialog aboutDialog = new JDialog(GraphicSimulatorServer.this, guiTextConfig.getString("AboutDialogTitle"), true);
				Point pos = new Point();
				pos.x = jLayeredPane.getLocationOnScreen().x + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2;
				pos.y = jLayeredPane.getLocationOnScreen().y + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2;
				aboutDialog.setLocation(pos);
				aboutDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight"));
				aboutDialog.setTitle(guiTextConfig.getString("AboutDialogTitle"));
				JLabel text = new JLabel(guiTextConfig.getString("AboutDialogContent"));
				text.setHorizontalAlignment(JLabel.CENTER);
				aboutDialog.add(text);
				aboutDialog.setVisible(true);
			}
		});
		helpMenu.add(aboutMenuItem);
		return helpMenu;
	}
	
	/**
	 * creates the layered pane if it does not already exists
	 * 
	 * @return layered pane
	 */
	private JLayeredPane getJLayeredPane() {
		if (jLayeredPane == null) {
			jLayeredPane = new JLayeredPane();
			jLayeredPane.setLayout(null);
			jLayeredPane.setOpaque(true);
			jLayeredPane.setBackground(Color.WHITE);

FileLine
org\fosstrak\hal\impl\sim\GraphicSimulator.java621
org\fosstrak\hal\impl\sim\multi\GraphicSimulatorServer.java618
	}

	/**
	 * removes the tag from the layered pane
	 * 
	 * @param tag which will be removed
	 */
	public void removeTag(Tag tag) {
		tags.remove(tag);
		jLayeredPane.remove(tag);
		jLayeredPane.repaint();
	}
	
	/**
	 * creates a new tag and adds it to the layered pane
	 * 
	 * @param name of the new tag
	 * @param epc of the new tag
	 */
	private void createNewTag(String id) {
		Point pos = new Point(getProperty("FramePadding"), tags.size() * (getProperty("TagHeight") + getProperty("InterTagPadding")) + getProperty("FramePadding"));
		createNewTag(id, pos);
	}
	
	/**
	 * creates a new tag and adds it to the layered pane
	 * 
	 * @param name of the new tag
	 * @param epc of the new tag
	 * @param pos position on the pane of the new tag
	 */
	private void createNewTag(String id, Point pos) {
		if(!"".equals(id)) {
			Tag newTag = new Tag(id, pos, this);
			tags.add(newTag);
			jLayeredPane.add(newTag, new Integer(1));
			jLayeredPane.repaint();
		}
	}

	/**
	 * returns the translation listener
	 * 
	 * @return translation listener
	 */
	public TranslationListener getTranslationListener() {
		return translationListener;
	}
	
	/**
	 * returns the gui text resource bundle
	 *
	 * @return gui text resource bundle
	 */
	public XMLConfiguration getGuiText() {
		return guiTextConfig;
	}

	/**
	 * returns the simulator properties
	 * 
	 * @return properties
	 */
	public XMLConfiguration getProperties() {
		return propsConfig;
	}
	
	/**
	 * adds an enter event to the simulator controller
	 * 
	 * @param antennaId 
	 * @param epc of the tag
	 */
	public void enterEvent(String readerId, String antennaId, String epc) {

FileLine
org\fosstrak\hal\impl\sim\GraphicSimulator.java384
org\fosstrak\hal\impl\sim\multi\GraphicSimulatorServer.java359
						contextMenu.setVisible(false);
						if(e.getButton() == MouseEvent.BUTTON1) {
							selection.select(tags);
						}
					}
				}
				
				// selection
				public void mousePressed(final MouseEvent e) {
					hideActiveContextMenuAndSelection();
					if(e.getButton() == MouseEvent.BUTTON1) {
						selection.setBounds(0, 0, getProperty("WindowWidth"), getProperty("WindowHeight"));
						selection.setStartPoint(e.getPoint());
						jLayeredPane.add(selection, new Integer(2));
					}
				}
			});
			
			// add drag listener
			jLayeredPane.addMouseMotionListener(new MouseMotionAdapter() {
				public void mouseDragged(MouseEvent e) {
					if(selection.isActive()) {
						selection.setCurrentPoint(e.getPoint());
					}
				}
			});
		}
		return jLayeredPane;
	}

	/**
	 * update the layered pane with new reader information
	 * 
	 * @return layered pane
	 */
	private void updateJLayeredPane() {

FileLine
org\fosstrak\hal\impl\sim\GraphicSimulator.java296
org\fosstrak\hal\impl\sim\multi\GraphicSimulatorServer.java275
	}
	
	/**
	 * creates the tag menu item
	 * 
	 * @return tag menu
	 */
	private JMenu getTagMenu() {
		JMenu tagMenu = new JMenu(guiTextConfig.getString("TagMenuItem"));
		
		// new tag
		JMenuItem newTagMenuItem = new JMenuItem();
		newTagMenuItem.setText(guiTextConfig.getString("AddNewTagMenuItem"));
		newTagMenuItem.addMouseListener(new MouseAdapter() {
			public void mouseReleased(MouseEvent e) {
				showAddTagDialog();
			}
		});
		tagMenu.add(newTagMenuItem);
		return tagMenu;
	}

	
	/**
	 * creates the help menu item
	 * 
	 * @return help menu
	 */
	private JMenu getHelpMenu() {
		JMenu helpMenu = new JMenu(guiTextConfig.getString("HelpMenuItem"));

		// about
		JMenuItem aboutMenuItem = new JMenuItem();
		aboutMenuItem.setText(guiTextConfig.getString("AboutMenuItem"));
		aboutMenuItem.addMouseListener(new MouseAdapter() {
			public void mouseReleased(MouseEvent e) {
				JDialog aboutDialog = new JDialog(GraphicSimulatorServer.this, guiTextConfig.getString("AboutDialogTitle"), true);

FileLine
org\fosstrak\hal\impl\sim\GraphicSimulator.java728
org\fosstrak\hal\impl\sim\multi\GraphicSimulatorServer.java741
	}
	
	/**
	 * gets a property value as integer
	 * 
	 * @param key of the property
	 * @return property as integer value
	 */
	public int getProperty(String key) {
      String error;
      if(!propsConfig.containsKey(key)) {
         error =  "Value '" + key + "' not found in properties !";
      } else {
         try {
            return propsConfig.getInt(key);
         } catch (Exception e) {
            error = "Value '" + key + "' is not an integer !";
         }
      }
      throw new NumberFormatException(error);
	}

	/**
	 * sets active context menu
	 * 
	 * @param contextMenu which is active
	 */
	public void setActiveContextMenu(JPopupMenu contextMenu) {
		activeContextMenu = contextMenu;
	}
	
	/**
	 * hide active context menu
	 */
	public void hideActiveContextMenu() {
		if(activeContextMenu != null) {
			activeContextMenu.setVisible(false);
			activeContextMenu = null;
		}
	}
	
	/**
	 * hide active context menu and hide selection
	 */
	public void hideActiveContextMenuAndSelection() {
		hideActiveContextMenu();
		selection.unselect(tags);
	}