コード例 #1
0
ファイル: IPToolKit.java プロジェクト: Teena/iptoolkit
  /** *********** Initialization of every component and variable being used ************* */
  IPToolKit() {

    cp = new Container();
    cp.setLayout(new BorderLayout());
    Main_pnl = new JPanel();
    jmb = new JMenuBar();
    m_File = new JMenu("File");
    m_Arith = new JMenu("Arithmetic");
    m_Filter = new JMenu("Filters");
    m_Open = new JMenuItem("Open");
    m_Save = new JMenuItem("Save");
    m_Exit = new JMenuItem("Exit");
    m_Add = new JMenu("Add");
    m_Sub = new JMenu("Subtract");
    m_Mul = new JMenu("Multiply");
    m_Div = new JMenu("Divide");
    edge = new JMenu("Edge Detection");
    mpre = new JMenu("Prewits");
    msob = new JMenu("Sobel");
    lbl_img = new JLabel("");
    lbl_gray = new JLabel("");
    lbl_res = new JLabel("");
    jfc = new JFileChooser();
    panel_image = new JPanel();
    panel_gray = new JPanel();
    panel_result = new JPanel();
    scrollPane = new JScrollPane();
    mAddConst = new JMenu("Constant");
    mSubConst = new JMenu("Constant");
    mMulConst = new JMenu("Constant");
    mDivConst = new JMenu("Constant");
    mAddSat = new JMenuItem("Saturation");
    mAddWrap = new JMenuItem("Wrap Around");
    mSubSat = new JMenuItem("Saturation");
    mSubWrap = new JMenuItem("Wrap Around");
    mMulSat = new JMenuItem("Saturation");
    mMulWrap = new JMenuItem("Wrap Around");
    mDivSat = new JMenuItem("Saturation");
    mDivWrap = new JMenuItem("Wrap Around");
    mAddImg = new JMenuItem("Image");
    mSubImg = new JMenuItem("Image");
    mMulImg = new JMenuItem("Image");
    mDivImg = new JMenuItem("Image");
    mlowPass = new JMenuItem("Low Pass");
    mhighPass = new JMenuItem("High Pass");
    mhighBoost = new JMenuItem("High Boost");
    median = new JMenuItem("Median");
    mBright = new JMenuItem("Brightness");
    mContrast = new JMenuItem("Contrast Stretch");
    mThreshold = new JMenuItem(" Threshold ");
    m_Enhance = new JMenu("Enhancement");
    mInvert = new JMenuItem("Negative");
    mpre_hor = new JMenuItem("Prewits Horizontal");
    mpre_ver = new JMenuItem("Prewits Vertical");
    mpre_both = new JMenuItem("Prewits Both");
    msob_hor = new JMenuItem("Sobel Horizontal");
    msob_ver = new JMenuItem("Sobel Vertical");
    msob_both = new JMenuItem("Sobel Both");
    ;
    mrob = new JMenuItem("Roberts");
    mean = new JMenuItem("Mean");
    mlap = new JMenuItem("Laplacian");
    other = new JMenu("Other");
    hist = new JMenuItem("Histogram Equalization");
    conect = new JMenuItem("Connected Component");
    mBlend = new JMenuItem("Blending");
    vsb = new JScrollBar(JScrollBar.VERTICAL);
    hsb = new JScrollBar(JScrollBar.HORIZONTAL);
    //	jsp = new JScrollPane();

    setJMenuBar(jmb);
    add(cp);

    //	setBackground(new Color(255,255,255));

    panel_image.setBackground(new Color(255, 0, 0));
    panel_gray.setBackground(new Color(0, 255, 0));
    panel_result.setBackground(new Color(0, 0, 255));

    jmb.add(m_File);
    jmb.add(m_Arith);
    jmb.add(m_Enhance);
    jmb.add(m_Filter);
    jmb.add(edge);
    jmb.add(other);

    cp.add(Main_pnl);

    Main_pnl.setLayout(new GridLayout(1, 3, 10, 10));

    Main_pnl.add(panel_image);
    Main_pnl.add(panel_gray);
    Main_pnl.add(panel_result);

    m_File.add(m_Open);
    m_File.add(m_Save);
    m_File.add(m_Exit);

    m_Arith.add(m_Add);
    m_Add.add(mAddImg);
    m_Add.add(mAddConst);
    mAddConst.add(mAddSat);
    mAddConst.add(mAddWrap);

    m_Arith.add(m_Sub);
    m_Sub.add(mSubImg);
    m_Sub.add(mSubConst);
    mSubConst.add(mSubSat);
    mSubConst.add(mSubWrap);

    m_Arith.add(m_Mul);
    m_Mul.add(mMulImg);
    m_Mul.add(mMulConst);
    mMulConst.add(mMulSat);
    mMulConst.add(mMulWrap);

    m_Arith.add(m_Div);
    m_Div.add(mDivImg);
    m_Div.add(mDivConst);
    mDivConst.add(mDivSat);
    mDivConst.add(mDivWrap);

    m_Filter.add(mlowPass);
    m_Filter.add(mhighPass);
    m_Filter.add(mhighBoost);
    m_Filter.add(median);
    m_Filter.add(mean);

    edge.add(mpre);
    edge.add(msob);
    mpre.add(mpre_hor);
    mpre.add(mpre_ver);
    mpre.add(mpre_both);
    msob.add(msob_hor);
    msob.add(msob_ver);
    msob.add(msob_both);
    edge.add(mrob);
    edge.add(mlap);

    m_Enhance.add(mBright);
    m_Enhance.add(mContrast);
    m_Enhance.add(mThreshold);
    m_Enhance.add(mInvert);
    m_Enhance.add(mBlend);

    other.add(hist);
    other.add(conect);

    m_Open.addActionListener(this);
    m_Save.addActionListener(this);
    m_Exit.addActionListener(this);

    mAddImg.addActionListener(this);
    mSubImg.addActionListener(this);
    mMulImg.addActionListener(this);
    mDivImg.addActionListener(this);

    mAddSat.addActionListener(this);
    mAddWrap.addActionListener(this);
    mSubSat.addActionListener(this);
    mSubWrap.addActionListener(this);
    mMulSat.addActionListener(this);
    mMulWrap.addActionListener(this);
    mDivSat.addActionListener(this);
    mDivWrap.addActionListener(this);

    mlowPass.addActionListener(this);
    mhighPass.addActionListener(this);
    mhighBoost.addActionListener(this);
    median.addActionListener(this);

    mBright.addActionListener(this);
    mContrast.addActionListener(this);
    mThreshold.addActionListener(this);
    mInvert.addActionListener(this);
    mBlend.addActionListener(this);

    mpre_hor.addActionListener(this);
    mpre_ver.addActionListener(this);
    mpre_both.addActionListener(this);
    msob_hor.addActionListener(this);
    msob_ver.addActionListener(this);
    msob_both.addActionListener(this);
    mrob.addActionListener(this);
    mean.addActionListener(this);
    mlap.addActionListener(this);

    hist.addActionListener(this);
    conect.addActionListener(this);

    lbl_gray.addMouseListener(this);

    panel_image.add(lbl_img);
    panel_gray.add(lbl_gray);
    panel_result.add(lbl_res);

    cp.add(vsb, BorderLayout.EAST);
    cp.add(hsb, BorderLayout.SOUTH);
    //	cp1 = getContentPane();

    cp = getContentPane();
    setSize(600, 400);
    setVisible(true);
  }
コード例 #2
0
ファイル: SampleApp.java プロジェクト: kdanninger/jac444a-3
  private void _displayImgInFrame() {

    final JFrame frame = new JFrame("Google Static Map");
    GUIUtils.setAppIcon(frame, "71.png");
    // frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    JLabel imgLbl = new JLabel(new ImageIcon(_img));
    imgLbl.setToolTipText(
        MessageFormat.format(
            "<html>Image downloaded from URI<br>size: w={0}, h={1}</html>",
            _img.getWidth(), _img.getHeight()));

    GUIUtils.centerOnScreen(frame);
    frame.setVisible(true);
    frame.setContentPane(imgLbl);
    frame.pack();
    frame.setResizable(false);

    imgLbl.addMouseListener(
        new MouseListener() {
          public void mouseClicked(MouseEvent e) {}

          public void mousePressed(MouseEvent e) {

            System.out.println("Mouse Listener:  Mouse Clicked!");
            mapIsUp = 1;
            sentX = 0.00;
            clickX = e.getX(); // Latitude
            clickY = e.getY(); // Longitude
            if ((clickX < (_img.getWidth() / 2))
                && (clickY < (_img.getHeight() / 2))) { // 1st quadrant positive values
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getWidth() / 2)) + clickX) * pixelX); // Add to latitude
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY); // Add to Longitude
              System.out.println("Top left");
            } else if ((clickX > (_img.getWidth() / 2))
                && (clickY > (_img.getHeight() / 2))) { // 2nd quadrant negative values
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getHeight() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Bottom Right");
            } else if ((clickX < (_img.getWidth() / 2))
                && (clickY > (_img.getHeight() / 2))) { // 3rd quadrant 1 positive 1 negative
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getWidth() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Bottom Left");
            } else { // 3rd quadrant 1 positive 1 negative
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getHeight() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Top Right");
            }

            BigDecimal toCoordsX = new BigDecimal(sentX);
            BigDecimal toCoordsY = new BigDecimal(sentY);

            sentX =
                (toCoordsX.setScale(6, BigDecimal.ROUND_HALF_UP))
                    .doubleValue(); // allows values of up to 6 decimal places
            sentY = (toCoordsY.setScale(6, BigDecimal.ROUND_HALF_UP)).doubleValue();
            getCoords = sentX + " " + sentY;
            ttfLati.setText(Double.toString(sentX));
            ttfLongi.setText(Double.toString(sentY));

            System.out.println("... saving Coordinates");
            saveLocation(
                getCoords); // pass getCoords through saveLocation. this string is appended to the
                            // savedLocations file.
            System.out.println("... savedCoordinates");

            // Update the Locations ComboBox with new additions
            ttfSave.removeAllItems(); // re-populate the ComboBox
            System.out.println("removed items");

            getSavedLocations(); // run through file to get all locations
            for (int i = 0; i < loc.size(); i++) ttfSave.addItem(loc.get(i));
            System.out.println("update combobox");
            mapIsUp = 0;
            frame.dispose(); // closes window
            startTaskAction(); // pops up a new window
          }

          public void saveLocation(String xy) {
            BufferedWriter f = null; // created a bufferedWriter object

            try {
              f =
                  new BufferedWriter(
                      new FileWriter(
                          "savedLocations.txt",
                          true)); // evaluated true if file has not been created yet
              f.write(xy); // append passed coordinates and append to file if exists
              f.newLine();
              f.flush();
            } catch (IOException ioe) {
              ioe.printStackTrace();
            } finally { // close the file
              if (f != null) {

                try {
                  f.close();
                } catch (IOException e) { // any error, catch exception
                  System.err.println("Error: " + e.getMessage());
                }
              }
            }
          }

          public void mouseReleased(MouseEvent e) {}

          public void mouseEntered(MouseEvent e) {}

          public void mouseExited(MouseEvent e) {}
        });
  }