Beispiel #1
0
    @Override
    public void actionPerformed(ActionEvent e) {
      // TODO Auto-generated method stub

      Object source = e.getSource();
      if (source == ok) {
        response = APPLY_OPTION;
        this.setVisible(false);
      } else if (source == cancel) {
        response = CANCEL_OPTION;
        this.setVisible(false);
      } else if (source == sizeCombo) {
        // get the number from the source
        JComboBox number = (JComboBox) source;
        String numberItem = (String) number.getSelectedItem();
        Font temp = example.getFont();
        // then set the font
        int newSize = Integer.parseInt(numberItem);
        example.setFont(new Font(temp.getFamily(), temp.getStyle(), newSize));
      } else if (source == fontCombo) {
        JComboBox font = (JComboBox) source;
        String s = (String) font.getSelectedItem();
        Font tmp = example.getFont();
        example.setFont(new Font(s, tmp.getStyle(), tmp.getSize()));
      } else if (source == foreground) {
        Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground());
        MenuBar.shapeLBG.setBackground(tmp);
        if (tmp != null) example.setForeground(tmp);
      }
    }
  @Override
  public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    Object source = e.getSource();

    if (source == ok) {
      userResponse = APPLY_OPTION;
      this.setVisible(false);
    } else if (source == cancel) {
      userResponse = CANCEL_OPTION;
      this.setVisible(false);
    } else if (source == fontCombo) {
      @SuppressWarnings("unchecked")
      JComboBox<String> cb = (JComboBox<String>) source;
      String s = (String) cb.getSelectedItem();
      Font tmp = example.getFont();
      example.setFont(new Font(s, tmp.getStyle(), tmp.getSize()));
    } else if (source == sizeCombo) {
      @SuppressWarnings("unchecked")
      JComboBox<String> cb = (JComboBox<String>) source;
      String s = (String) cb.getSelectedItem();
      int newSize = Integer.parseInt(s);
      Font tmp = example.getFont();
      example.setFont(new Font(tmp.getFamily(), tmp.getStyle(), newSize));
    } else if (source == foreground) {
      Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground());
      if (tmp != null) example.setForeground(tmp);
    }
  }
 public void actionPerformed(ActionEvent e) {
   Color color =
       JColorChooser.showDialog(InnereKlassemitmainMethode.this, "Eine Farbe wählen", Color.red);
   if (color != null) {
     g.setColor(color);
     status.setText("Farbe mit JColorChooser abgeändert");
   }
 }
  public void mouseReleased(MouseEvent e) {
    if (mMouseOverButton && mPressedButton != -1) {
      boolean needsUpdate = false;
      if (mColorListMode == VisualizationColor.cColorListModeCategories) {
        Color newColor =
            JColorChooser.showDialog(
                mOwner, "Select category color", mCategoryColorList[mPressedButton]);
        if (newColor != null) {
          mCategoryColorList[mPressedButton] = newColor;
          needsUpdate = true;
        }
      } else {
        if (mPressedButton == cColorWedgeButton) {
          if (++mColorListMode > VisualizationColor.cColorListModeStraight)
            mColorListMode = VisualizationColor.cColorListModeHSBShort;
          updateColorList(-1);
          needsUpdate = true;
        } else {
          int index = mPressedButton * (mWedgeColorList.length - 1);
          Color newColor =
              JColorChooser.showDialog(
                  mOwner, "Select color for min/max value", mWedgeColorList[index]);
          if (newColor != null) {
            mWedgeColorList[index] = newColor;
            updateColorList(-1);
            needsUpdate = true;
          }
        }
      }

      mPressedButton = -1;
      mMouseOverButton = false;

      if (needsUpdate) {
        mListener.actionPerformed(
            new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "colorChanged"));
        repaint();
      }
    }
  }
Beispiel #5
0
  @Override
  public void mouseReleased(MouseEvent e) {
    debug("mouseReleased (" + e.getX() + "," + e.getY() + ")");

    color = JColorChooser.showDialog(this, "Choose a color", color);

    if (color == null) color = Color.lightGray;

    colorPicker.setBackground(color);

    if (assignedClass != null) assignedClass.setColor(color);

    updateDependends();
  }
Beispiel #6
0
  static boolean customThemeDialog(Component parent) {

    Color customColor =
        JColorChooser.showDialog(
            parent,
            Locale.explain("ui.chooseBase"), // $NON-NLS-1$
            ShadeConfig.theme.get().getBase());
    if (customColor != null) {
      CUSTOM.getLookAndFeel().setBase(customColor);
      return true;
    }

    return false;
  }
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == colorBorderButton) {
      Color chosenColor =
          JColorChooser.showDialog(
              colorBorderButton,
              messageBundle.getString("viewer.utilityPane.annotation.ink.colorBorderChooserTitle"),
              colorBorderButton.getBackground());
      if (chosenColor != null) {
        // change the colour of the button background
        colorBorderButton.setBackground(chosenColor);
        annotation.setColor(chosenColor);

        // save the action state back to the document structure.
        updateCurrentAnnotation();
        currentAnnotationComponent.resetAppearanceShapes();
        currentAnnotationComponent.repaint();
      }
    }
  }
 /** Methode appelee quand l'utilisateur appuie sur le bouton. */
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == button) {
     Color choosedColor =
         JColorChooser.showDialog(parent.dialog(), "Choose color", new Color(R, G, B));
     if (choosedColor != null) {
       this.R = choosedColor.getRed();
       this.G = choosedColor.getGreen();
       this.B = choosedColor.getBlue();
       parent.elementModified();
     }
     String tmp =
         new String(
             label
                 + Integer.toString(getRed())
                 + ", "
                 + Integer.toString(getGreen())
                 + ", "
                 + Integer.toString(getBlue()));
     while (tmp.length() < 38) {
       tmp = tmp + " ";
     }
     jlabel.setText(tmp);
   }
 }
Beispiel #9
0
 private void Font_Color_buttonActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_Font_Color_buttonActionPerformed
   Color initialcolor = Color.BLACK;
   font_color = JColorChooser.showDialog(this, "Select a color", initialcolor);
   DisplayArea_text.setForeground(font_color);
 } // GEN-LAST:event_Font_Color_buttonActionPerformed
Beispiel #10
0
 private void color_buttonActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_color_buttonActionPerformed
   Color initialcolor = Color.WHITE;
   bg_color = JColorChooser.showDialog(this, "Select a color", initialcolor);
   DisplayArea_text.setBackground(bg_color);
 } // GEN-LAST:event_color_buttonActionPerformed
    @Override
    public void actionPerformed(ActionEvent evt) {
      String command = evt.getActionCommand();
      switch (command) {
        case "New File":
          {
            OSC = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
            Graphics osg = OSC.getGraphics();
            osg.setColor(fillColor);
            osg.fillRect(0, 0, getWidth(), getHeight());
            osg.dispose();
            repaint();
            break;
          }
        case "Open":
          {
            JFileChooser chooser = new JFileChooser();
            FileNameExtensionFilter filter =
                new FileNameExtensionFilter("JPG or PNG Images", "jpg", "png");
            chooser.setFileFilter(filter);
            int returnVal = chooser.showOpenDialog(null);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
              try {

                OSC = ImageIO.read(chooser.getSelectedFile());
                Graphics2D g2 = (Graphics2D) OSC.getGraphics();

                g2.scale((double) 640 / OSC.getWidth(), (double) 480 / OSC.getHeight());
                g2.drawImage(OSC, 0, 0, OSC.getWidth(), OSC.getHeight(), null);
              } catch (Exception e) {
              }
            }
            repaint();
            break;
          }
        case "Save":
          {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setSelectedFile(new File("image.PNG"));
            fileDialog.setDialogTitle("Select File to be Saved");
            int option = fileDialog.showSaveDialog(null);
            if (option != JFileChooser.APPROVE_OPTION)
              return; // User canceled or clicked the dialog’s close box.

            File selectedFile = fileDialog.getSelectedFile();
            if (selectedFile.exists()) { // Ask the user whether to replace the file.
              int response =
                  JOptionPane.showConfirmDialog(
                      null,
                      "The file \""
                          + selectedFile.getName()
                          + "\" already exists.\nDo you want to replace it?",
                      "Confirm Save",
                      JOptionPane.YES_NO_OPTION,
                      JOptionPane.WARNING_MESSAGE);
              if (response != JOptionPane.YES_OPTION)
                return; // User does not want to replace the file.
            }
            try {
              boolean hasFormat = ImageIO.write(OSC, "PNG", selectedFile);
              if (!hasFormat) throw new Exception("PNG" + " format is not available.");
            } catch (Exception e) {
              JOptionPane.showMessageDialog(
                  null, "Sorry, an error occurred while trying to save image.");
              e.printStackTrace();
            }

            break;
          }
        case "Exit":
          {
            System.exit(0);
          }

        case "Select Drawing Color...":
          {
            Color newColor =
                JColorChooser.showDialog(AdvancedGUIEX1.this, "Select Drawing Color", currentColor);
            if (newColor != null) currentColor = newColor;
            break;
          }
        case "Fill With Color...":
          {
            Color newColor =
                JColorChooser.showDialog(AdvancedGUIEX1.this, "Select Fill Color", fillColor);
            if (newColor != null) {
              fillColor = newColor;
              Graphics osg = OSC.getGraphics();
              osg.setColor(fillColor);
              osg.fillRect(0, 0, OSC.getWidth(), OSC.getHeight());
              osg.dispose();
              AdvancedGUIEX1.this.repaint();
            }
            break;
          }
        case "Draw With Black":
          currentColor = Color.BLACK;
          break;
        case "Draw With White":
          currentColor = Color.WHITE;
          break;
        case "Draw With Red":
          currentColor = Color.RED;
          break;
        case "Draw With Green":
          currentColor = Color.GREEN;
          break;
        case "Draw With Blue":
          currentColor = Color.BLUE;
          break;
        case "Draw With Yellow":
          currentColor = Color.YELLOW;
          break;
        case "Curve":
          currentTool = Tool.CURVE;
          break;
        case "Line":
          currentTool = Tool.LINE;
          break;
        case "Rectangle":
          currentTool = Tool.RECT;
          break;
        case "Oval":
          currentTool = Tool.OVAL;
          break;
        case "Filled Rectangle":
          currentTool = Tool.FILLED_RECT;
          break;
        case "Filled Oval":
          currentTool = Tool.FILLED_OVAL;
          break;
        case "Smudge":
          currentTool = Tool.SMUDGE;
          break;
        case "Erase":
          currentTool = Tool.ERASE;
          break;
      }
    }
Beispiel #12
0
  public void actionPerformed(ActionEvent e) {
    System.out.println("actionPerformed");
    if (e.getSource() == pen) // 画笔
    {
      System.out.println("pen");
      toolFlag = 0;
    }

    if (e.getSource() == eraser) // 橡皮
    {
      System.out.println("eraser");
      toolFlag = 1;
    }

    if (e.getSource() == clear) // 清除
    {
      System.out.println("clear");
      toolFlag = 2;
      paintInfo.removeAllElements();
      repaint();
    }

    if (e.getSource() == drLine) // 画线
    {
      System.out.println("drLine");
      toolFlag = 3;
    }

    if (e.getSource() == drCircle) // 画圆
    {
      System.out.println("drCircle");
      toolFlag = 4;
    }

    if (e.getSource() == drRect) // 画矩形
    {
      System.out.println("drRect");
      toolFlag = 5;
    }

    if (e.getSource() == colchooser) // 调色板
    {
      System.out.println("colchooser");
      Color newColor = JColorChooser.showDialog(this, "我的调色板", c);
      c = newColor;
    }

    if (e.getSource() == openPic) // 打开图画
    {

      openPicture.setVisible(true);

      if (openPicture.getFile() != null) {
        int tempflag;
        tempflag = toolFlag;
        toolFlag = 2;
        repaint();

        try {
          paintInfo.removeAllElements();
          File filein = new File(openPicture.getDirectory(), openPicture.getFile());
          picIn = new FileInputStream(filein);
          VIn = new ObjectInputStream(picIn);
          paintInfo = (Vector) VIn.readObject();
          VIn.close();
          repaint();
          toolFlag = tempflag;

        } catch (ClassNotFoundException IOe2) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read object");
        } catch (IOException IOe) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read file");
        }
      }
    }

    if (e.getSource() == savePic) // 保存图画
    {
      savePicture.setVisible(true);
      try {
        File fileout = new File(savePicture.getDirectory(), savePicture.getFile());
        picOut = new FileOutputStream(fileout);
        VOut = new ObjectOutputStream(picOut);
        VOut.writeObject(paintInfo);
        VOut.close();
      } catch (IOException IOe) {
        System.out.println("can not write object");
      }
    }
  }