Example usage for java.awt.event KeyEvent getKeyCode

List of usage examples for java.awt.event KeyEvent getKeyCode

Introduction

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

Prototype

public int getKeyCode() 

Source Link

Document

Returns the integer keyCode associated with the key in this event.

Usage

From source file:corelyzer.ui.CorelyzerGLCanvas.java

public void keyPressed(final KeyEvent event) {
    canvasLock.lock();//from ww w.  j a va 2 s .  c  om

    char key = event.getKeyChar();
    if (key == '+' || key == '=' || key == '-') { // Zoom
        float dS = 1.33f;
        float scale = 1.0f;
        float[] cp = { 0.0f, 0.0f };
        float[] sc = { 0.0f, 0.0f };

        Point mousePos = canvas.getMousePosition();

        this.convertMousePointToSceneSpace(mousePos, cp);
        sc[0] = SceneGraph.getSceneCenterX();
        sc[1] = SceneGraph.getSceneCenterY();

        switch (key) {
        case '+':
        case '=':
            scale = 1 / dS;
            break;

        case '-':
            scale = dS;
            break;
        }

        SceneGraph.scaleScene(scale);

        float ncp[] = { 0.0f, 0.0f };
        this.convertMousePointToSceneSpace(mousePos, ncp);

        ncp[0] = ncp[0] - cp[0];
        ncp[1] = ncp[1] - cp[1];

        SceneGraph.panScene(-ncp[0], -ncp[1]);
    } else if (key == 'j' || key == 'J') {
        CorelyzerApp app = CorelyzerApp.getApp();
        app.getMainFrame().setAlwaysOnTop(false);

        String inputValue = JOptionPane.showInputDialog(getPopupParent(),
                "Please input the depth to jump to in meters: ");

        app.getMainFrame().setAlwaysOnTop(true);

        if (inputValue == null) {
            return;
        }

        try {
            float depthValue = Float.parseFloat(inputValue);
            float dpix = SceneGraph.getCanvasDPIX(this.canvasId);
            float dpiy = SceneGraph.getCanvasDPIY(this.canvasId);

            float px, py;
            if (SceneGraph.getDepthOrientation()) {
                px = depthValue * 100.0f / 2.54f * dpix;
                py = 0;
            } else {
                px = 0;
                py = depthValue * 100.0f / 2.54f * dpiy;
            }

            SceneGraph.lock();
            {
                SceneGraph.positionScene(px, py);
            }
            SceneGraph.unlock();
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(getPopupParent(), "Please type in a number", "Alert",
                    JOptionPane.ERROR_MESSAGE);
        }
    } else if (key == KeyEvent.VK_OPEN_BRACKET || key == KeyEvent.VK_CLOSE_BRACKET || key == '9'
            || key == '0') {
        // graph scaling
        float dS = 1.00f;

        if (key == KeyEvent.VK_OPEN_BRACKET || key == '9') {
            dS = 1.0f / 1.33f;
        } else if (key == KeyEvent.VK_CLOSE_BRACKET || key == '0') {
            dS = 1.33f;
        }

        SceneGraph.setGraphScale(dS);
        // SceneGraph.setMarkerScale(dS);
    } else if (key == 'D') { // Show onscreen debug information in
        // scenegraph
        boolean b = SceneGraph.getDebug();
        SceneGraph.setDebug(!b);
    } else if (key == 'Q' || key == 'W' || key == 'E' || key == 'R') {
        int keyId = 0;
        if (key == 'Q')
            keyId = 1; // scaling
        if (key == 'W')
            keyId = 2; // labels
        if (key == 'E')
            keyId = 3; // border
        else if (key == 'R')
            keyId = 4; // scissoring
        SceneGraph.debugKey(keyId);
    } else { // pan
        float movX = 0.0f;
        float movY = 0.0f;

        int dX = 10;
        int dY = 10;

        float sx, sy;
        float w, h;

        w = SceneGraph.getCanvasWidth(canvasId);
        h = SceneGraph.getCanvasHeight(canvasId);

        sx = w / canvas.getWidth();
        sy = h / canvas.getHeight();

        switch (event.getKeyCode()) {
        case KeyEvent.VK_UP:
            movX = 0.0f;
            movY = -dY * sy;
            break;

        case KeyEvent.VK_DOWN:
            movX = 0.0f;
            movY = dY * sy;
            break;

        case KeyEvent.VK_LEFT:
            movX = -dX * sx;
            movY = 0.0f;
            break;

        case KeyEvent.VK_RIGHT:
            movX = dX * sx;
            movY = 0.0f;
            break;
        }

        SceneGraph.panScene(movX, movY);
    }

    canvasLock.unlock();
    CorelyzerApp.getApp().updateGLWindows();
}

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

private void treeServicesKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_treeServicesKeyReleased
        if (evt.getKeyCode() == 114) {
            textFieldSearchServiceKeyReleased(evt);
        }//from ww w . j  ava  2s . com
    }

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

private void textFieldSearchServiceKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldSearchServiceKeyReleased
        TreeNode node = null;/*from   w  w w.  j ava2 s .  c o m*/
        boolean flag = evt.getKeyCode() != 114;
        final QService ser = (QService) treeServices.getLastSelectedPathComponent();
        for (Object object : ((ATreeModel) treeServices.getModel()).getNodes()) {
            final QService service = (QService) object;
            if (flag) {
                if (service.toString().toLowerCase()
                        .contains(textFieldSearchService.getText().trim().toLowerCase())) {
                    node = (TreeNode) object;
                    break;
                }
            } else {
                if (!flag && (ser == null || service.getId().equals(ser.getId()))) {
                    flag = true;
                }
            }
        }

        if (node != null) {
            TreeNode[] nodes = ((DefaultTreeModel) treeServices.getModel()).getPathToRoot(node);
            TreePath path = new TreePath(nodes);
            treeServices.setSelectionPath(path);
            treeServices.setExpandsSelectedPaths(true);
            treeServices.scrollPathToVisible(path);

        } else {
            Toolkit.getDefaultToolkit().beep();
        }
    }

From source file:base.BasePlayer.Main.java

@Override

public void keyPressed(KeyEvent e) {
    keyCode = e.getKeyCode();

    if (!Main.shift && (e.getModifiers() & KeyEvent.SHIFT_MASK) != 0) {

        Main.shift = true;/*from  www .ja v  a2 s.  c  o  m*/
    } else if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
        Main.drawCanvas.ctrlpressed = 100;

        if (keyCode == KeyEvent.VK_S) {

            if (drawCanvas.drawVariables.projectName.equals("Untitled")) {
                saveProjectAs.doClick();
            } else {
                Serializer ser = new Serializer();
                ser.serialize(drawCanvas.drawVariables.projectFile);
            }
        }
        if (keyCode == KeyEvent.VK_W) {

            //   System.out.println("\n----\n");

            /*
               int[][] array = new int[Main.varsamples][VariantHandler.callSlider.getUpperValue()+1];
                       
                  for(int i = 0; i<array.length; i++) {
                     for(int j = 0; j<array[i].length; j++) {
             array[i][j] = 0;
                     }
                  }
                  /*VarNode node = FileRead.head.getNext();
                  int counter = 0;
                  while(node != null) {
                     if(!drawCanvas.hideNode(node)) {               
             counter++;
             for(int i = 0; i<node.vars.size(); i++) {
                if(!drawCanvas.hideNodeVar(node, node.vars.get(i))) {
                   for(int j = 0;j<node.vars.get(i).getValue().size(); j++) {
                      if(!drawCanvas.hideVar(node.vars.get(i).getValue().get(j), false)) {
                         array[node.vars.get(i).getValue().get(j).getSample().getIndex()][(int)(MethodLibrary.round(node.vars.get(i).getValue().get(j).getAlleleFraction()*100,2))]++;
                      }
                              
                   }
                           
                           
                }                  
             }
                     }
                       
                     node = node.getNext();
                  }*/
            /*   int width = Main.drawCanvas.getWidth()-Main.sidebarWidth;
                    
               JPopupMenu menu = new JPopupMenu();
            Plotter plotter = new Plotter(width);         
            plotter.setPreferredSize(new Dimension(width,400));
            menu.add(plotter);
            menu.pack();
            menu.show(Main.drawCanvas,Main.sidebarWidth, drawScroll.getVerticalScrollBar().getValue());
            */
        }
        if (keyCode == KeyEvent.VK_PLUS || keyCode == 107) {

            //      defaultFontSize++;

            //      setFonts();
        }
        if (keyCode == KeyEvent.VK_M || keyCode == KeyEvent.VK_MINUS || keyCode == 109) {

            //      defaultFontSize--;

            //      setFonts();
        }
        /*   else if(keyCode == KeyEvent.VK_M) {
              VarNode current = FileRead.head.getNext();
               while(current != null) {
                          
                  if(current.getNext() != null && current.getNext().getPosition()-current.getPosition() > 100000) {
        System.out.println(current.getPosition() +" " +(current.getNext().getPosition()-current.getPosition()));
                  }
                  current = current.getNext();
               }
               current = null;
           }
           */
    } else if (keyCode == KeyEvent.VK_DELETE) {
        if (Main.drawCanvas.selectedSample != null) {
            Main.drawCanvas.removeSample(Main.drawCanvas.selectedSample);
        }
    }
    /*   else if(keyCode == KeyEvent.VK_7) {
                  
                  
       }*/
    else if (keyCode == KeyEvent.VK_O && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
        /*   clearData();
                   
           try {
              FileInputStream fin = new FileInputStream("C:/HY-Data/RKATAINE/test.ses");
              ObjectInputStream ois = new ObjectInputStream(fin);
              drawCanvas.sampleList = (ArrayList<Sample>) ois.readObject();
              Main.samples = (short)drawCanvas.sampleList.size();
                      
              drawCanvas.splits = (ArrayList<SplitClass>) ois.readObject();
              for(int i = 0; i<drawCanvas.splits.size(); i++) {
                 drawCanvas.splits.get(i).resetSplits();
              }
              drawCanvas.drawVariables = (DrawVariables)ois.readObject();
                      
              ois.close();
              drawCanvas.resizeCanvas(Main.drawCanvas.getWidth(), Main.drawCanvas.getHeight());
                      
              Draw.setScrollbar(drawCanvas.drawVariables.scrollbarpos);
                      
              for(int i= 0; i<drawCanvas.splits.size(); i++) {
                 drawCanvas.splits.get(i).setCytoImage(null);
                 chromDraw.drawCyto(drawCanvas.splits.get(i));
                 chromDraw.updateExons = true;
                 FileRead.search = true;
                 drawCanvas.gotoPos(drawCanvas.splits.get(i).chrom, drawCanvas.splits.get(i).start, drawCanvas.splits.get(i).end);
                 chromDraw.repaint();
              }
              for(int i = 0 ;i<drawCanvas.sampleList.size(); i++) {
                 for(int r = 0 ;r<drawCanvas.sampleList.size(); r++) {
                    if(drawCanvas.sampleList.get(i).getreadHash().size() > 0) {
          drawCanvas.sampleList.get(i).resetreadHash();
                    }
                 }
              }
                   
           }
           catch(Exception ex) {
              ex.printStackTrace();
           }
           */
    }

    else if (keyCode == KeyEvent.VK_F9) {

        FileRead.head.putNext(null);
        drawCanvas.variantsStart = 0;
        drawCanvas.variantsEnd = 1;
        Draw.updatevars = true;
        Main.drawCanvas.repaint();

    } else if (keyCode == KeyEvent.VK_F11) {

        /*   try {
              BBFileReader reader = new BBFileReader( Main.bedCanvas.bedTrack.get(0).file.getCanonicalPath(),  Main.bedCanvas.bedTrack.get(0));
              int zoomlevel = 1;
              for(int i =2;i<reader.getZoomLevels().getZoomHeaderCount();i++) {
                 if(reader.getZoomLevels().getZoomLevelHeader(i).getReductionLevel() < (Main.drawCanvas.splits.get(0).viewLength/(Main.drawCanvas.splits.get(0).pixel*Main.drawCanvas.splits.get(0).viewLength))) {
                    zoomlevel = i;
                 }
                 else {
                    break;
                 }
              }
                      
                
                         
           }
           catch(Exception ex) {
              ex.printStackTrace();
           }*/
    } else if (keyCode == KeyEvent.VK_F12) {
        /*VarNode next = Main.drawCanvas.current.getNext();
                
        MethodLibrary.makeMultiAlt("2",next.getPosition(), "G", next);
                
           next = null;
        */
        /*   try {
              URL urli = new URL("ftp://ftp.ensembl.org/pub/grch37/update/gff3/homo_sapiens/Homo_sapiens.GRCh37.87.gff3.gz");
              System.out.println(urli.getProtocol() +" " +urli.getHost() +" " +urli.getPath().substring(0,urli.getPath().lastIndexOf("/")+1));
           }
           catch(Exception ex) {
              ex.printStackTrace();
           }*/
    } else if (keyCode == KeyEvent.VK_F8) {

        File file = new File(searchField.getText().replaceAll(" ", ""));
        if (!file.exists()) {
            if (Main.drawCanvas.splits.get(0).viewLength < 1000) {

                Main.getConsSeq();
            }
        } else {
            try {
                /*
                JFileChooser chooser = new JFileChooser(file.getPath());
                chooser.setAcceptAllFileFilterUsed(true);                       
                        
                chooser.setDialogTitle("Save FASTA file as...");
                int returnVal = chooser.showSaveDialog((Component)this.getParent());                   
                        
                if(returnVal == JFileChooser.APPROVE_OPTION) {  
                  String suffix = "";
                  if(!chooser.getSelectedFile().getName().endsWith(".fa") && !chooser.getSelectedFile().getName().endsWith(".fasta")) {
                     suffix = ".fa";
                  }
                          
                   File outfile = new File(chooser.getSelectedFile().getCanonicalPath() +suffix);   
                 //  File outfile = new File("test.fa");   
                   Main.nothread = true;
                  Main.noreadthread = true;
                  FileRead.search = true;   
                  Draw.variantcalculator = true;
                        
                  Seqfetcher fetcher = new Seqfetcher(file, outfile);
                  fetcher.execute();
                           
                }*/
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        }

    } else if (keyCode == KeyEvent.VK_ENTER) {

        if (e.getSource() == searchField) {
            search(searchField.getText());

        }

    }

}

From source file:app.RunApp.java

/**
 * Action when key pressed on textChoose
 * //from w w w. j  a v  a 2  s  . c o m
 * @param evt Event
 */
private void textChooseFileKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textChooseFileKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        String arffFilename = textChooseFile.getText();
        xmlFilename = DataIOUtils.getXMLString(arffFilename);
        xmlFilename = DataIOUtils.getFilePath(xmlFilename);
        loadDataset(arffFilename, xmlFilename);
    }
}

From source file:ECallCenter21.java

private void logPanelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_logPanelKeyPressed
    if (evt.getKeyCode() == 9) {
        logPanel.getNextFocusableComponent().requestFocusInWindow();
    }/*from   w  ww  .ja v  a 2 s . c o m*/
}

From source file:ECallCenter21.java

private void graphPanelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_graphPanelKeyPressed
    if (evt.getKeyCode() == 9) {
        graphPanel.getNextFocusableComponent().requestFocusInWindow();
    }// w  w w.java2 s. com
}

From source file:ECallCenter21.java

private void aboutPanelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_aboutPanelKeyPressed
    if (evt.getKeyCode() == 9) {
        aboutPanel.getNextFocusableComponent().requestFocusInWindow();
    }/* w  w  w . j  a  v  a 2 s  .  c o m*/
}

From source file:ECallCenter21.java

private void netConfigPanelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_netConfigPanelKeyPressed
    if (evt.getKeyCode() == 9) {
        netConfigPanel.getNextFocusableComponent().requestFocusInWindow();
    }/*  www . j  a  v  a  2 s.c  o  m*/
}

From source file:ECallCenter21.java

private void callCenterPanelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_callCenterPanelKeyPressed
    if (evt.getKeyCode() == 9) {
        callCenterPanel.getNextFocusableComponent().requestFocusInWindow();
    }//  ww w.j a  va2  s  .  c o  m
}