Example usage for java.awt.event KeyAdapter KeyAdapter

List of usage examples for java.awt.event KeyAdapter KeyAdapter

Introduction

In this page you can find the example usage for java.awt.event KeyAdapter KeyAdapter.

Prototype

KeyAdapter

Source Link

Usage

From source file:edu.ku.brc.specify.plugins.ipadexporter.InstitutionConfigDlg.java

/**
 * @return//w  ww. j  av a2  s . c om
 */
private JPanel createCuratorPanel() {
    AppPreferences remotePrefs = AppPreferences.getRemote();

    String curatorName = remotePrefs.get(curatorPref, "");
    String colMgrName = remotePrefs.get(colMgrPref, "");

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,4px,p"));

    crTextFld = UIHelper.createTextField(curatorName);
    cmTextFld = UIHelper.createTextField(colMgrName);

    pb.add(UIHelper.createI18NFormLabel("Curator"), cc.xy(1, 1));
    pb.add(crTextFld, cc.xy(3, 1));

    pb.add(UIHelper.createI18NFormLabel("COLMGR"), cc.xy(1, 3));
    pb.add(cmTextFld, cc.xy(3, 3));

    KeyAdapter ka = new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            updateOKBtn();
        }
    };
    crTextFld.addKeyListener(ka);
    cmTextFld.addKeyListener(ka);
    return pb.getPanel();
}

From source file:view.QuestionLab.java

/**
 * Creates new form QuestionLab//from  www .  j a  va 2 s  . c  o  m
 */
public QuestionLab(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    try {

        initComponents();
        submitButton.setVisible(false);
        jCheckBox1.setEnabled(false);
        jCheckBox3.setEnabled(false);
        jCheckBox4.setEnabled(false);
        jCheckBox5.setEnabled(false);
        jCheckBox7.setEnabled(false);
        jCheckBox8.setEnabled(false);
        jCheckBox9.setEnabled(false);
        jCheckBox10.setEnabled(false);
        submitButton.setEnabled(false);
        backButton.setEnabled(false);

        controller = ServerConnector.getServerConnector().getStudentController();
        studentObserverImpl = new StudentObserverImpl(this);
        controller.addObserve(studentObserverImpl);
        //controller.onlineNow();
        //displayMessage(Integer.toString(onlineNow));
        muteButton.setEnabled(false);
        setSize(Toolkit.getDefaultToolkit().getScreenSize());
        UIManager.setLookAndFeel(new GraphiteLookAndFeel());

        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        date = new Date();
        System.out.println(dateFormat.format(date));
        newDate = dateFormat.format(date);
        JButton buttonArrayListOne[][] = { { jButton1, jButton2, jButton3, jButton4, jButton5 },
                { jButton6, jButton7, jButton8, jButton9, jButton10 },
                { jButton11, jButton12, jButton13, jButton14, jButton15 },
                { jButton16, jButton17, jButton18, jButton19, jButton20 },
                { jButton21, jButton22, jButton23, jButton24, jButton25 },
                { jButton26, jButton27, jButton28, jButton29, jButton30 },
                { jButton31, jButton32, jButton33, jButton34, jButton35 },
                { jButton36, jButton37, jButton38, jButton39, jButton40 },
                { jButton41, jButton42, jButton43, jButton44, jButton45 },
                { jButton46, jButton47, jButton48, jButton49, jButton50 },
                { jButton51, jButton52, jButton53, jButton54, jButton55 },
                { jButton56, jButton57, jButton58, jButton59, jButton60 }

        };

        this.buttonArrayList = buttonArrayListOne;
        System.out.println("MyNIc" + PracticeExamLogIn.studentNic);
        new Timer(1000, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int hour = secondsLeft / 3600;
                int min = secondsLeft / 60 - hour * 60;
                int second = secondsLeft % 60;

                if (hour == 0) {
                    int seconds = secondsLeft % 60;

                    jLabel7.setText(Integer.toString(seconds));

                    jLabel8.setText("Minutes");
                    //   jLabel5.setText("Seconds");
                    jLabel6.setText(Integer.toString(min));

                } else {
                    jLabel6.setText(Integer.toString(hour));
                    jLabel7.setText(Integer.toString(min));
                    jLabel8.setText(Integer.toString(second));

                }
                secondsLeft--;
                if ("0".equals(jLabel6.getText()) && "0".equals(jLabel7.getText())) {
                    //check(); 
                    System.out.println("true");
                }

            }
        }).start();

        submitTextField.addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
                char c = e.getKeyChar();
                if (!((c >= 'a') && (c <= 'g') || (c == KeyEvent.VK_SPACE) || (c == KeyEvent.VK_TAB)
                        || (c == KeyEvent.VK_SPACE))) {
                    getToolkit().beep();
                    e.consume();
                }
            }
        });

        try {

            try {
                Exam exam = new Exam(PracticeExamLogIn.studentNic, date, anxCount);
                //    ExamController examController = ServerConnector.getServerConnector().getExamController();
                try {
                    boolean addMarks = ServerConnector.getServerConnector().getExamController().addMarks(exam);
                    // Exam exam = examController.addMarks(PracticeExamLogIn.studentNic, newDate, anxCount);
                    // if (addMarks) {
                    //   JOptionPane.showMessageDialog(QuestionLab.this, "Student Registered successfully !!");
                    //   this.dispose();
                    //    new LogIn(null, true).setVisible(true);

                    //                    } else {
                    //                        JOptionPane.showMessageDialog(QuestionLab.this, "Student Registered failed !!");
                    //                    }
                } catch (ClassNotFoundException | SQLException ex) {
                    Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (NotBoundException | MalformedURLException ex) {
                Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (RemoteException ex) {
            Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex);
        }

    } catch (UnsupportedLookAndFeelException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NotBoundException | MalformedURLException | RemoteException ex) {
        Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.mgmtp.jfunk.core.ui.JFunkFrame.java

private void buildTree() {
    tree = new JTree(new ScriptsTreeModel(roots));
    tree.setCellRenderer(new ScriptsTreeCellRenderer());
    tree.setRootVisible(false);//from   w  ww .j av  a 2s . c om
    tree.setShowsRootHandles(true);
    tree.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(final KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                runScripts();
            }
        }
    });
    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (!e.isPopupTrigger() && e.getClickCount() == 2) {
                if (tree.getModel().isLeaf(tree.getSelectionPath().getLastPathComponent())) {
                    runScripts();
                }
            }
        }

        @Override
        public void mousePressed(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
                TreePath[] paths = tree.getSelectionPaths();
                boolean newPath = true;
                for (TreePath path : paths) {
                    if (selPath.equals(path)) {
                        newPath = false;
                        break;
                    }
                }
                if (newPath) {
                    tree.setSelectionPath(selPath);
                }
                popup.show((Component) e.getSource(), e.getX(), e.getY());
            }
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
                TreePath[] paths = tree.getSelectionPaths();
                boolean newPath = true;
                for (TreePath path : paths) {
                    if (selPath.equals(path)) {
                        newPath = false;
                        break;
                    }
                }
                if (newPath) {
                    tree.setSelectionPath(selPath);
                }
                popup.show((Component) e.getSource(), e.getX(), e.getY());
            }
        }
    });
}

From source file:savant.view.swing.FrameCommandBar.java

/**
 * Create display menu for commandBar//from w  ww. j a  v  a 2s. c  o m
 */
private JMenu createDisplayModeMenu() {
    JMenu menu = new JMenu("Display Mode");

    //display modes
    DrawingMode[] validModes = mainTrack.getValidDrawingModes();
    modeItems = new JCheckBoxMenuItem[validModes.length];
    for (int i = 0; i < validModes.length; i++) {
        JCheckBoxMenuItem item = new JCheckBoxMenuItem(validModes[i].getDescription());
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JCheckBoxMenuItem item = (JCheckBoxMenuItem) e.getSource();
                if (item.getState()) {
                    DrawingMode[] validModes = mainTrack.getValidDrawingModes();
                    for (int j = 0; j < modeItems.length; j++) {
                        if (item.getText().equals(validModes[j].getDescription())) {
                            for (TrackAdapter t : frame.getTracks()) {

                                AnalyticsAgent.log(new NameValuePair[] {
                                        new NameValuePair("track-event", "DisplayModeChanged"),
                                        new NameValuePair("track-type", t.getClass().getSimpleName()),
                                        new NameValuePair("target-mode", validModes[j].getDescription()) });

                                t.setDrawingMode(validModes[j]);
                            }
                            drawModePosition = j;
                        } else {
                            modeItems[j].setState(false);
                        }
                    }
                } else {
                    item.setState(true);
                }
            }
        });
        if (validModes[i] == mainTrack.getDrawingMode()) {
            item.setState(true);
        }
        modeItems[i] = item;
        menu.add(item);
    }

    // Determine position of current draw mode.
    DrawingMode currentMode = mainTrack.getDrawingMode();
    for (int i = 0; i < validModes.length; i++) {
        if (validModes[i].equals(currentMode)) {
            drawModePosition = i;
            break;
        }
    }

    // Allow cycling through display modes.
    graphPane.addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            //check for: Mac + Command + 'm' OR !Mac + Ctrl + 'm'
            if ((MiscUtils.MAC && e.getModifiersEx() == 256 && e.getKeyChar() == 'm')
                    || (!MiscUtils.MAC && e.getKeyChar() == '\n' && e.isControlDown())) {
                cycleDisplayMode();
            }
        }
    });
    return menu;
}

From source file:com.all.browser.impl.MozillaBrowser.java

private void registerListeners() {
    mozillaPanel.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
        @Override/*from   ww  w.jav  a2 s.co m*/
        public void ancestorResized(HierarchyEvent e) {
            Container changedParent = e.getChangedParent();
            if (changedParent != null) {
                mozillaPanel.setBounds(changedParent.getBounds());
            }
        }
    });

    mozillaPanel.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_SPACE) {
                e.consume();
            }
        }
    });
}

From source file:org.openconcerto.erp.core.finance.accounting.element.AnalytiqueSQLElement.java

private void actionModifierAxe(MouseEvent e, final int index) {

    if (index == -1)
        return;//from w  w  w  . j av  a2 s . co m

    Component comp = (Component) e.getSource();
    JFrame frame = (JFrame) SwingUtilities.getRoot(comp);

    this.windowChangeNom = new JWindow(frame);
    Container container = this.windowChangeNom.getContentPane();
    container.setLayout(new GridBagLayout());

    final GridBagConstraints c = new DefaultGridBagConstraints();
    c.insets = new Insets(0, 0, 0, 0);
    c.weightx = 1;

    this.editedAxeIndex = index;
    this.text = new JTextField(" " + this.tabAxes.getTitleAt(index) + " ");
    this.text.setEditable(true);
    container.add(this.text, c);
    this.text.setBorder(null);
    // text.setBackground(this.tabAxes.getBackground());
    this.text.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {

            if (event.getKeyCode() == KeyEvent.VK_ENTER) {
                validAxeText();
            }
        }

    });

    this.windowChangeNom.pack();

    int ecartY = this.tabAxes.getBoundsAt(index).height - this.text.getBounds().height + 2;
    int ecartX = this.tabAxes.getBoundsAt(index).width - this.text.getBounds().width;

    this.windowChangeNom.setLocation(
            comp.getLocationOnScreen().x + this.tabAxes.getBoundsAt(index).getLocation().x + ecartX / 2,
            comp.getLocationOnScreen().y + this.tabAxes.getBoundsAt(index).getLocation().y + ecartY / 2);

    this.windowChangeNom.setVisible(true);
}

From source file:org.webcat.plugintester.ui.MainFrameBuilder.java

/**
 * Creates and lays out the Swing components for the window.
 *
 * @param frame the JFrame instance that will contain the components
 *//* w w w . j  a v a  2 s  .  c o  m*/
private void constructFrame(JFrame frame) {
    GridBagConstraints gridBagConstraints;

    fileChooser = new JFileChooser();
    bottomPanel = new JPanel();
    runButton = new JButton();
    mainPanel = new JPanel();
    JLabel webCatHomeLabel = new JLabel();
    webCatHomeField = new JTextField();
    webCatHomeBrowseButton = new JButton();
    JSeparator jSeparator0 = new JSeparator();
    JLabel submissionLabel = new JLabel();
    submissionField = new JTextField();
    submissionBrowseButton = new JButton();
    JSeparator jSeparator1 = new JSeparator();
    JLabel pluginsLabel = new JLabel();
    JPanel pluginsPanel = new JPanel();
    JScrollPane pluginsScrollPane = new JScrollPane();
    pluginsTable = new JTable();
    pluginAddButton = new JButton();
    pluginRemoveButton = new JButton();
    JSeparator jSeparator2 = new JSeparator();
    JTabbedPane tabPane = new JTabbedPane();
    propertiesPanel = new JPanel();
    JScrollPane propertiesScrollPane = new JScrollPane();
    propertiesEditor = new JEditorPane();
    documentationPanel = new JPanel();
    JScrollPane documentationScrollPane = new JScrollPane();
    documentationEditor = new JEditorPane();

    // File chooser
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    // Bottom panel
    bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 4));

    // Run button
    runButton.setText("Run Plug-ins");
    runButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            runButtonActionPerformed(evt);
        }
    });
    bottomPanel.add(runButton);

    frame.getContentPane().add(bottomPanel, BorderLayout.PAGE_END);

    // Main panel
    mainPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
    mainPanel.setLayout(new GridBagLayout());

    // Web-CAT Home field
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = GridBagConstraints.RELATIVE;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    webCatHomeLabel.setText("Web-CAT Home:");
    mainPanel.add(webCatHomeLabel, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    webCatHomeField.setTransferHandler(new WebCATHomeTransferHandler());
    mainPanel.add(webCatHomeField, gridBagConstraints);

    // Web-CAT Home browse button
    webCatHomeBrowseButton.setText("Browse...");
    webCatHomeBrowseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            webCatHomeBrowseButtonActionPerformed(evt);
        }
    });
    mainPanel.add(webCatHomeBrowseButton, new GridBagConstraints());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator0, gridBagConstraints);

    // Submission field
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = GridBagConstraints.RELATIVE;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    submissionLabel.setText("Submission:");
    mainPanel.add(submissionLabel, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    submissionField.setTransferHandler(new SubmissionTransferHandler());
    mainPanel.add(submissionField, gridBagConstraints);

    // Submission browse button
    submissionBrowseButton.setText("Browse...");
    submissionBrowseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            submissionBrowseButtonActionPerformed(evt);
        }
    });
    mainPanel.add(submissionBrowseButton, new GridBagConstraints());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator1, gridBagConstraints);

    // Plug-ins area
    pluginsLabel.setText("Plug-ins to run:");
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(pluginsLabel, gridBagConstraints);

    pluginsPanel.setPreferredSize(new Dimension(400, 80));
    pluginsPanel.setLayout(new GridBagLayout());

    pluginsModel = new PluginsTableModel();
    pluginsTable.setModel(pluginsModel);
    pluginsTable.setColumnSelectionAllowed(true);
    pluginsTable.getTableHeader().setReorderingAllowed(false);
    pluginsScrollPane.setViewportView(pluginsTable);
    pluginsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    pluginsTable.getColumnModel().getColumn(0).setResizable(false);
    pluginsScrollPane.setTransferHandler(new PluginsTransferHandler());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    pluginsPanel.add(pluginsScrollPane, gridBagConstraints);

    pluginAddButton.setText("Add...");
    pluginAddButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pluginAddButtonActionPerformed(evt);
        }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.PAGE_START;
    pluginsPanel.add(pluginAddButton, gridBagConstraints);

    pluginRemoveButton.setText("Remove");

    pluginRemoveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pluginRemoveButtonActionPerformed(evt);
        }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.PAGE_START;
    pluginsPanel.add(pluginRemoveButton, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 0.25;
    mainPanel.add(pluginsPanel, gridBagConstraints);
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator2, gridBagConstraints);

    tabPane.setPreferredSize(new Dimension(466, 150));

    propertiesPanel.setLayout(new GridBagLayout());

    propertiesEditor.addKeyListener(new KeyAdapter() {
        public void keyTyped(KeyEvent e) {
            propertiesTimer.restart();
        }
    });

    propertiesTimer = new Timer(1000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateGradingProperties();
        }
    });

    propertiesScrollPane.setViewportView(propertiesEditor);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    propertiesPanel.add(propertiesScrollPane, gridBagConstraints);

    tabPane.addTab("Properties", propertiesPanel);

    documentationPanel.setLayout(new GridBagLayout());

    documentationEditor.setContentType("text/html");
    documentationEditor.setEditable(false);
    documentationScrollPane.setViewportView(documentationEditor);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    documentationPanel.add(documentationScrollPane, gridBagConstraints);

    tabPane.addTab("Documentation", documentationPanel);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.gridheight = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weighty = 1.0;
    mainPanel.add(tabPane, gridBagConstraints);

    frame.getContentPane().add(mainPanel, BorderLayout.CENTER);

    frame.pack();
}

From source file:com.raddle.tools.MergeMain.java

private void initGUI() {
    try {//from  w  ww  .j a v a 2  s.c o m
        {
            this.setBounds(0, 0, 1050, 600);
            getContentPane().setLayout(null);
            this.setTitle("\u5c5e\u6027\u6587\u4ef6\u6bd4\u8f83");
            {
                sourceTxt = new JTextField();
                getContentPane().add(sourceTxt);
                sourceTxt.setBounds(12, 12, 373, 22);
            }
            {
                sourceBtn = new JButton();
                getContentPane().add(sourceBtn);
                sourceBtn.setText("\u6253\u5f00");
                sourceBtn.setBounds(406, 12, 74, 22);
                sourceBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        JFileChooser fileChooser = new JFileChooser(); // 
                        fileChooser.addChoosableFileFilter(
                                new FileNameExtensionFilter("", "properties"));
                        File curFile = new File(sourceTxt.getText());
                        if (curFile.exists()) {
                            fileChooser.setCurrentDirectory(curFile.getParentFile());
                        }
                        int result = fileChooser.showOpenDialog(MergeMain.this);
                        if (result == JFileChooser.APPROVE_OPTION) {
                            File selected = fileChooser.getSelectedFile();
                            source = new PropertyHolder(selected, "utf-8");
                            sourceTxt.setText(selected.getAbsolutePath());
                            properties.setProperty("left.file", selected.getAbsolutePath());
                            savePropMergeFile();
                            compare();
                        }
                    }
                });
            }
            {
                targetTxt = new JTextField();
                getContentPane().add(targetTxt);
                targetTxt.setBounds(496, 12, 419, 22);
            }
            {
                targetBtn = new JButton();
                getContentPane().add(targetBtn);
                targetBtn.setText("\u6253\u5f00");
                targetBtn.setBounds(935, 12, 81, 22);
                targetBtn.setSize(74, 22);
                targetBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        JFileChooser fileChooser = new JFileChooser(); // 
                        fileChooser.addChoosableFileFilter(
                                new FileNameExtensionFilter("", "properties"));
                        File curFile = new File(targetTxt.getText());
                        if (curFile.exists()) {
                            fileChooser.setCurrentDirectory(curFile.getParentFile());
                        }
                        int result = fileChooser.showOpenDialog(MergeMain.this);
                        if (result == JFileChooser.APPROVE_OPTION) {
                            File selected = fileChooser.getSelectedFile();
                            target = new PropertyHolder(selected, "utf-8");
                            targetTxt.setText(selected.getAbsolutePath());
                            properties.setProperty("right.file", selected.getAbsolutePath());
                            savePropMergeFile();
                            compare();
                        }
                    }
                });
            }
            {
                jScrollPane1 = new JScrollPane();
                getContentPane().add(jScrollPane1);
                jScrollPane1.setBounds(12, 127, 373, 413);
                {
                    ListModel sourceListModel = new DefaultComboBoxModel(new String[] {});
                    sourceList = new JList();
                    jScrollPane1.setViewportView(sourceList);
                    sourceList.setAutoscrolls(true);
                    sourceList.setModel(sourceListModel);
                    sourceList.addKeyListener(new KeyAdapter() {
                        @Override
                        public void keyPressed(KeyEvent evt) {
                            if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
                                PropertyLine v = (PropertyLine) sourceList.getSelectedValue();
                                if (v != null) {
                                    int ret = JOptionPane.showConfirmDialog(MergeMain.this,
                                            "?" + v.getKey() + "?");
                                    if (ret == JOptionPane.YES_OPTION) {
                                        v.setState(LineState.deleted);
                                        compare();
                                        sourceList.setSelectedValue(v, true);
                                    }
                                }
                            }
                        }
                    });
                    sourceList.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseClicked(MouseEvent evt) {
                            if (evt.getClickCount() == 2) {
                                Object v = sourceList.getSelectedValue();
                                updatePropertyLine((PropertyLine) v);
                                sourceList.setSelectedValue(v, true);
                            }
                        }
                    });
                    sourceList.addListSelectionListener(new ListSelectionListener() {

                        @Override
                        public void valueChanged(ListSelectionEvent evt) {
                            if (sourceList.getSelectedValue() != null) {
                                PropertyLine pl = (PropertyLine) sourceList.getSelectedValue();
                                if (target != null) {
                                    PropertyLine p = target.getLine(pl.getKey());
                                    if (p != null) {
                                        TextDiffResult rt = TextdiffUtil.getDifferResult(p.toString(),
                                                pl.toString());
                                        diffResultPane.setText("" + rt.getTargetHtml() + "<br/>?"
                                                + rt.getSrcHtml());
                                        selectLine(targetList, p);
                                        return;
                                    }
                                }
                                TextDiffResult rt = TextdiffUtil.getDifferResult("", pl.toString());
                                diffResultPane.setText(
                                        "" + rt.getTargetHtml() + "<br/>?" + rt.getSrcHtml());

                            }
                        }
                    });
                }
            }
            {
                jScrollPane2 = new JScrollPane();
                getContentPane().add(jScrollPane2);
                jScrollPane2.setBounds(496, 127, 419, 413);
                {
                    ListModel targetListModel = new DefaultComboBoxModel(new String[] {});
                    targetList = new JList();
                    jScrollPane2.setViewportView(targetList);
                    targetList.setAutoscrolls(true);
                    targetList.setModel(targetListModel);
                    targetList.addKeyListener(new KeyAdapter() {
                        @Override
                        public void keyPressed(KeyEvent evt) {
                            if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
                                PropertyLine v = (PropertyLine) targetList.getSelectedValue();
                                if (v != null) {
                                    int ret = JOptionPane.showConfirmDialog(MergeMain.this,
                                            "?" + v.getKey() + "?");
                                    if (ret == JOptionPane.YES_OPTION) {
                                        v.setState(LineState.deleted);
                                        compare();
                                        targetList.setSelectedValue(v, true);
                                    }
                                }
                            }
                        }
                    });
                    targetList.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseClicked(MouseEvent evt) {
                            if (evt.getClickCount() == 2) {
                                Object v = targetList.getSelectedValue();
                                updatePropertyLine((PropertyLine) v);
                                targetList.setSelectedValue(v, true);
                            }
                        }
                    });
                    targetList.addListSelectionListener(new ListSelectionListener() {

                        @Override
                        public void valueChanged(ListSelectionEvent evt) {
                            if (targetList.getSelectedValue() != null) {
                                PropertyLine pl = (PropertyLine) targetList.getSelectedValue();
                                if (source != null) {
                                    PropertyLine s = source.getLine(pl.getKey());
                                    if (s != null) {
                                        TextDiffResult rt = TextdiffUtil.getDifferResult(pl.toString(),
                                                s.toString());
                                        diffResultPane.setText("" + rt.getTargetHtml() + "<br/>?"
                                                + rt.getSrcHtml());
                                        selectLine(sourceList, s);
                                        return;
                                    }
                                }
                                TextDiffResult rt = TextdiffUtil.getDifferResult(pl.toString(), "");
                                diffResultPane.setText(
                                        "" + rt.getTargetHtml() + "<br/>?" + rt.getSrcHtml());
                            }
                        }
                    });
                }
            }
            {
                sourceSaveBtn = new JButton();
                getContentPane().add(sourceSaveBtn);
                sourceSaveBtn.setText("\u4fdd\u5b58");
                sourceSaveBtn.setBounds(406, 45, 74, 22);
                sourceSaveBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        int result = JOptionPane.showConfirmDialog(MergeMain.this,
                                "???\n"
                                        + source.getPropertyFile().getAbsolutePath());
                        if (result == JOptionPane.YES_OPTION) {
                            source.saveFile();
                            JOptionPane.showMessageDialog(MergeMain.this, "??");
                            clearState(source);
                            compare();
                        }
                    }
                });
            }
            {
                targetSaveBtn = new JButton();
                getContentPane().add(targetSaveBtn);
                targetSaveBtn.setText("\u4fdd\u5b58");
                targetSaveBtn.setBounds(935, 45, 81, 22);
                targetSaveBtn.setSize(74, 22);
                targetSaveBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        int result = JOptionPane.showConfirmDialog(MergeMain.this,
                                "????\n"
                                        + target.getPropertyFile().getAbsolutePath());
                        if (result == JOptionPane.YES_OPTION) {
                            target.saveFile();
                            JOptionPane.showMessageDialog(MergeMain.this, "??");
                            clearState(target);
                            compare();
                        }
                    }
                });
            }
            {
                toTargetBtn = new JButton();
                getContentPane().add(toTargetBtn);
                toTargetBtn.setText("->");
                toTargetBtn.setBounds(406, 221, 74, 22);
                toTargetBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        Object[] oo = sourceList.getSelectedValues();
                        for (Object selected : oo) {
                            PropertyLine s = (PropertyLine) selected;
                            if (s != null && target != null) {
                                PropertyLine t = target.getLine(s.getKey());
                                if (t == null) {
                                    PropertyLine n = s.clone();
                                    n.setState(LineState.added);
                                    target.addPropertyLineAtSuitedPosition(n);
                                } else if (!t.getValue().equals(s.getValue())) {
                                    t.setState(LineState.updated);
                                    t.setValue(s.getValue());
                                } else if (t.getState() == LineState.deleted) {
                                    if (t.getValue().equals(t.getOriginalValue())) {
                                        t.setState(LineState.original);
                                    } else {
                                        t.setState(LineState.updated);
                                    }
                                }
                                compare();
                            }
                        }
                    }
                });
            }
            {
                toSourceBtn = new JButton();
                getContentPane().add(toSourceBtn);
                toSourceBtn.setText("<-");
                toSourceBtn.setBounds(406, 255, 74, 22);
                toSourceBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        Object[] oo = targetList.getSelectedValues();
                        for (Object selected : oo) {
                            PropertyLine t = (PropertyLine) selected;
                            if (t != null && source != null) {
                                PropertyLine s = source.getLine(t.getKey());
                                if (s == null) {
                                    PropertyLine n = t.clone();
                                    n.setState(LineState.added);
                                    source.addPropertyLineAtSuitedPosition(n);
                                } else if (!s.getValue().equals(t.getValue())) {
                                    s.setState(LineState.updated);
                                    s.setValue(t.getValue());
                                } else if (s.getState() == LineState.deleted) {
                                    if (s.getValue().equals(s.getOriginalValue())) {
                                        s.setState(LineState.original);
                                    } else {
                                        s.setState(LineState.updated);
                                    }
                                }
                                compare();
                            }
                        }
                    }
                });
            }
            {
                jScrollPane3 = new JScrollPane();
                getContentPane().add(jScrollPane3);
                jScrollPane3.setBounds(12, 73, 903, 42);
                {
                    diffResultPane = new JTextPane();
                    jScrollPane3.setViewportView(diffResultPane);
                    diffResultPane.setBounds(12, 439, 903, 63);
                    diffResultPane.setContentType("text/html");
                    diffResultPane.setPreferredSize(new java.awt.Dimension(901, 42));
                }
            }
            {
                compareBtn = new JButton();
                getContentPane().add(compareBtn);
                compareBtn.setText("\u6bd4\u8f83");
                compareBtn.setBounds(406, 139, 74, 22);
                compareBtn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        compare();
                    }
                });
            }
            {
                sourceReloadBtn = new JButton();
                getContentPane().add(sourceReloadBtn);
                sourceReloadBtn.setText("\u91cd\u65b0\u8f7d\u5165");
                sourceReloadBtn.setBounds(12, 40, 64, 29);
                sourceReloadBtn.setSize(90, 22);
                sourceReloadBtn.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        if (sourceTxt.getText().length() > 0) {
                            File curFile = new File(sourceTxt.getText().trim());
                            if (curFile.exists()) {
                                source = new PropertyHolder(curFile, "utf-8");
                                sourceTxt.setText(curFile.getAbsolutePath());
                                properties.setProperty("left.file", curFile.getAbsolutePath());
                                savePropMergeFile();
                                compare();
                            } else {
                                JOptionPane.showMessageDialog(MergeMain.this,
                                        "" + curFile.getAbsolutePath() + "?");
                            }
                        }
                    }
                });
            }
            {
                targetReloadBtn = new JButton();
                getContentPane().add(targetReloadBtn);
                targetReloadBtn.setText("\u91cd\u65b0\u8f7d\u5165");
                targetReloadBtn.setBounds(839, 45, 90, 22);
                targetReloadBtn.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        if (targetTxt.getText().length() > 0) {
                            File curFile = new File(targetTxt.getText().trim());
                            if (curFile.exists()) {
                                target = new PropertyHolder(curFile, "utf-8");
                                targetTxt.setText(curFile.getAbsolutePath());
                                properties.setProperty("right.file", curFile.getAbsolutePath());
                                savePropMergeFile();
                                compare();
                            } else {
                                JOptionPane.showMessageDialog(MergeMain.this,
                                        "" + curFile.getAbsolutePath() + "?");
                            }
                        }
                    }
                });
            }
            {
                helpBtn = new JButton();
                getContentPane().add(helpBtn);
                helpBtn.setText("\u5e2e\u52a9");
                helpBtn.setBounds(405, 338, 38, 29);
                helpBtn.setSize(74, 22);
                helpBtn.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        StringBuilder sb = new StringBuilder();
                        sb.append("?").append("\n");
                        sb.append("del").append("\n");
                        sb.append("??").append("\n");
                        sb.append(": /.prop-merge/prop-merge.properties").append("\n");
                        JOptionPane.showMessageDialog(MergeMain.this, sb.toString());
                    }
                });
            }
            {
                sourceEditBtn = new JButton();
                getContentPane().add(sourceEditBtn);
                sourceEditBtn.setText("\u7f16\u8f91\u6587\u4ef6");
                sourceEditBtn.setBounds(108, 40, 90, 22);
                sourceEditBtn.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        if (sourceTxt.getText().length() > 0) {
                            File curFile = new File(sourceTxt.getText());
                            editFile(curFile);
                        }
                    }
                });
            }
            {
                targetEditBtn = new JButton();
                getContentPane().add(targetEditBtn);
                targetEditBtn.setText("\u7f16\u8f91\u6587\u4ef6");
                targetEditBtn.setBounds(743, 45, 90, 22);
                targetEditBtn.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        if (targetTxt.getText().length() > 0) {
                            File curFile = new File(targetTxt.getText());
                            editFile(curFile);
                        }
                    }
                });
            }
        }
        pack();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com._17od.upm.gui.MainWindow.java

private void addComponentsToPane() {

    // Ensure the layout manager is a BorderLayout
    if (!(getContentPane().getLayout() instanceof GridBagLayout)) {
        getContentPane().setLayout(new GridBagLayout());
    }//w w  w . j  av  a2  s.co  m

    // Create the menubar
    setJMenuBar(createMenuBar());

    GridBagConstraints c = new GridBagConstraints();

    // The toolbar Row
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.insets = new Insets(0, 0, 0, 0);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.HORIZONTAL;
    Component toolbar = createToolBar();
    getContentPane().add(toolbar, c);

    // Keep the frame background color consistent
    getContentPane().setBackground(toolbar.getBackground());

    // The seperator Row
    c.gridx = 0;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.HORIZONTAL;
    getContentPane().add(new JSeparator(), c);

    // The search field row
    searchIcon = new JLabel(Util.loadImage("search.gif"));
    searchIcon.setDisabledIcon(Util.loadImage("search_d.gif"));
    searchIcon.setEnabled(false);
    c.gridx = 0;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(5, 1, 5, 1);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    getContentPane().add(searchIcon, c);

    searchField = new JTextField(15);
    searchField.setEnabled(false);
    searchField.setMinimumSize(searchField.getPreferredSize());
    searchField.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            // This method never seems to be called
        }

        public void insertUpdate(DocumentEvent e) {
            dbActions.filter();
        }

        public void removeUpdate(DocumentEvent e) {
            dbActions.filter();
        }
    });
    searchField.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                dbActions.resetSearch();
            } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                // If the user hits the enter key in the search field and
                // there's only one item
                // in the listview then open that item (this code assumes
                // that the one item in
                // the listview has already been selected. this is done
                // automatically in the
                // DatabaseActions.filter() method)
                if (accountsListview.getModel().getSize() == 1) {
                    viewAccountMenuItem.doClick();
                }
            }
        }
    });
    c.gridx = 1;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(5, 1, 5, 1);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    getContentPane().add(searchField, c);

    resetSearchButton = new JButton(Util.loadImage("stop.gif"));
    resetSearchButton.setDisabledIcon(Util.loadImage("stop_d.gif"));
    resetSearchButton.setEnabled(false);
    resetSearchButton.setToolTipText(Translator.translate(RESET_SEARCH_TXT));
    resetSearchButton.setActionCommand(RESET_SEARCH_TXT);
    resetSearchButton.addActionListener(this);
    resetSearchButton.setBorder(BorderFactory.createEmptyBorder());
    resetSearchButton.setFocusable(false);
    c.gridx = 2;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(5, 1, 5, 1);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    getContentPane().add(resetSearchButton, c);

    // The accounts listview row
    accountsListview = new JList();
    accountsListview.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    accountsListview.setSelectedIndex(0);
    accountsListview.setVisibleRowCount(10);
    accountsListview.setModel(new SortedListModel());
    JScrollPane accountsScrollList = new JScrollPane(accountsListview, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    accountsListview.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            // If the listview gets focus, there is one ore more items in
            // the listview and there is nothing
            // already selected, then select the first item in the list
            if (accountsListview.getModel().getSize() > 0 && accountsListview.getSelectedIndex() == -1) {
                accountsListview.setSelectionInterval(0, 0);
            }
        }
    });
    accountsListview.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            dbActions.setButtonState();
        }
    });
    accountsListview.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                viewAccountMenuItem.doClick();
            }
        }
    });
    accountsListview.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                viewAccountMenuItem.doClick();
            }
        }
    });
    // Create a shortcut to delete account functionality with DEL(delete)
    // key

    accountsListview.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {

                try {
                    dbActions.reloadDatabaseBefore(new DeleteAccountAction());
                } catch (InvalidPasswordException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (ProblemReadingDatabaseFile e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

            }
        }
    });

    c.gridx = 0;
    c.gridy = 3;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 1, 1, 1);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.BOTH;
    getContentPane().add(accountsScrollList, c);

    // The "File Changed" panel
    c.gridx = 0;
    c.gridy = 4;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 1, 0, 1);
    c.ipadx = 3;
    c.ipady = 3;
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.BOTH;
    databaseFileChangedPanel = new JPanel();
    databaseFileChangedPanel.setLayout(new BoxLayout(databaseFileChangedPanel, BoxLayout.X_AXIS));
    databaseFileChangedPanel.setBackground(new Color(249, 172, 60));
    databaseFileChangedPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    JLabel fileChangedLabel = new JLabel("Database file changed");
    fileChangedLabel.setAlignmentX(LEFT_ALIGNMENT);
    databaseFileChangedPanel.add(fileChangedLabel);
    databaseFileChangedPanel.add(Box.createHorizontalGlue());
    JButton reloadButton = new JButton("Reload");
    reloadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                dbActions.reloadDatabaseFromDisk();
            } catch (Exception ex) {
                dbActions.errorHandler(ex);
            }
        }
    });
    databaseFileChangedPanel.add(reloadButton);
    databaseFileChangedPanel.setVisible(false);
    getContentPane().add(databaseFileChangedPanel, c);

    // Add the statusbar
    c.gridx = 0;
    c.gridy = 5;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 1, 1, 1);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.HORIZONTAL;
    getContentPane().add(statusBar, c);

}

From source file:org.nuclos.client.relation.EntityRelationshipModelEditPanel.java

protected void init() {
    final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate();
    mainPanel = new JPanel();

    double sizeHeader[][] = { { TableLayout.PREFERRED, 5, TableLayout.PREFERRED, 10 }, { 10, 25, 10 } };
    panelHeader = new JPanel();
    panelHeader.setLayout(new TableLayout(sizeHeader));
    clcttfName.setLabelText(localeDelegate.getMessage("nuclos.entityfield.entityrelation.name.label", "Name"));
    clcttfName.setToolTipText(//from  w w w  .ja  v a2  s .co m
            localeDelegate.getMessage("nuclos.entityfield.entityrelation.name.description", "Name"));
    clcttfName.setColumns(20);
    panelHeader.add(this.clcttfName.getJComponent(), "0,1");
    clcttfDescription.setLabelText(
            localeDelegate.getMessage("nuclos.entityfield.entityrelation.description.label", "Beschreibung"));
    clcttfDescription.setToolTipText(localeDelegate
            .getMessage("nuclos.entityfield.entityrelation.description.description", "Beschreibung"));
    clcttfDescription.setColumns(20);
    panelHeader.add(this.clcttfDescription.getJComponent(), "2,1");

    double size[][] = { { 5, TableLayout.FILL, 5 }, { 35, 5, TableLayout.FILL, 5 } };

    TableLayout layout = new TableLayout(size);
    layout.setVGap(3);
    layout.setHGap(5);
    mainPanel.setLayout(layout);

    mainPanel.add(panelHeader, "1,0");
    MyGraphModel model = new MyGraphModel(graphComponent, this, mf);

    mxGraph myGraph = new MyGraph(model);

    mxCodecRegistry.register(new mxModelCodec(model));
    mxCodecRegistry.register(new mxModelCodec(new java.sql.Date(System.currentTimeMillis())));
    mxCodecRegistry.register(new mxModelCodec(new Integer(0)));

    addEventListener(myGraph);

    graphComponent = new mxGraphComponent(myGraph);
    graphComponent.setGridVisible(true);
    graphComponent.getViewport().setOpaque(false);
    graphComponent.setBackground(Color.WHITE);
    graphComponent.setToolTips(true);

    graphComponent.setCellEditor(new MyCellEditor(graphComponent));

    model.setGraphComponent(graphComponent);

    graphComponent.addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_DELETE) {
                mxCell cell = (mxCell) graphComponent.getGraph().getSelectionModel().getCell();
                if (cell.getValue() instanceof EntityMetaDataVO) {
                    int iEdge = cell.getEdgeCount();
                    for (int i = 0; i < iEdge; i++) {
                        mxCell cellRelation = (mxCell) cell.getEdgeAt(i);
                        getGraphModel().remove(cellRelation);
                    }
                    getGraphModel().remove(cell);
                    fireChangeListenEvent();
                } else if (cell.getValue() instanceof EntityFieldMetaDataVO) {
                    int opt = JOptionPane.showConfirmDialog(mainPanel,
                            localeDelegate.getMessage("nuclos.entityrelation.editor.7",
                                    "M\u00f6chten Sie die Verbindung wirklich l\u00f6sen?"));
                    if (opt != 0) {
                        return;
                    }
                    mxCell cellSource = (mxCell) cell.getSource();
                    if (cellSource != null && cellSource.getValue() instanceof EntityMetaDataVO) {
                        EntityMetaDataVO metaSource = (EntityMetaDataVO) cellSource.getValue();
                        if (cell.getValue() instanceof EntityFieldMetaDataVO) {
                            EntityFieldMetaDataVO voField = (EntityFieldMetaDataVO) cell.getValue();
                            voField.flagRemove();

                            List<EntityFieldMetaDataTO> toList = new ArrayList<EntityFieldMetaDataTO>();
                            EntityFieldMetaDataTO toField = new EntityFieldMetaDataTO();
                            toField.setEntityFieldMeta(voField);
                            toList.add(toField);

                            MetaDataDelegate.getInstance().modifyEntityMetaData(metaSource, toList);

                            if (mpRemoveRelation.containsKey(metaSource)) {
                                mpRemoveRelation.get(metaSource).add(voField);
                            } else {
                                Set<EntityFieldMetaDataVO> s = new HashSet<EntityFieldMetaDataVO>();
                                s.add(voField);
                                mpRemoveRelation.put(metaSource, s);
                            }

                        }
                    }

                    mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel();
                    model.remove(cell);
                    EntityRelationshipModelEditPanel.this.fireChangeListenEvent();
                } else if (cell.getValue() != null && cell.getValue() instanceof String) {
                    String sValue = (String) cell.getValue();
                    if (sValue.length() == 0) {
                        getGraphModel().remove(cell);
                        EntityRelationshipModelEditPanel.this.fireChangeListenEvent();
                    }
                }
            }
        }

    });

    createMouseWheelListener();

    createMouseListener();

    //mainPanel.add(graphComponent, "1,2, 4,4");
    mainPanel.add(graphComponent, "1,2");

    this.add(mainPanel);

}