Beispiel #1
0
  void initComponents() {
    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    Color bgColor = Color.getHSBColor(0.58f, 0.17f, 0.95f);
    buttonPanel.setBackground(bgColor);
    Border empty = BorderFactory.createEmptyBorder(5, 5, 5, 5);
    buttonPanel.setBorder(empty);

    textField = new JTextField(75);
    buttonPanel.add(textField);

    buttonPanel.add(Box.createHorizontalStrut(10));
    searchPHI = new JButton("Search PHI");
    searchPHI.addActionListener(this);
    buttonPanel.add(searchPHI);

    buttonPanel.add(Box.createHorizontalStrut(10));
    searchTrial = new JButton("Search Trial IDs");
    searchTrial.addActionListener(this);
    buttonPanel.add(searchTrial);

    buttonPanel.add(Box.createHorizontalStrut(20));
    buttonPanel.add(Box.createHorizontalGlue());
    saveAs = new JCheckBox("Save As...");
    saveAs.setBackground(bgColor);
    buttonPanel.add(saveAs);

    mainPanel.add(buttonPanel, BorderLayout.NORTH);

    JScrollPane scrollPane = new JScrollPane();
    textPane = new ColorPane();
    // textPane.setEditable(false);
    scrollPane.setViewportView(textPane);
    mainPanel.add(scrollPane, BorderLayout.CENTER);

    JPanel footerPanel = new JPanel();
    footerPanel.setLayout(new BoxLayout(footerPanel, BoxLayout.X_AXIS));
    footerPanel.setBackground(bgColor);
    message = new JLabel("Ready...");
    footerPanel.add(message);
    mainPanel.add(footerPanel, BorderLayout.SOUTH);

    setTitle(windowTitle);
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent evt) {
            System.exit(0);
          }
        });
    getContentPane().add(mainPanel, BorderLayout.CENTER);
    pack();
    centerFrame();
  }
Beispiel #2
0
 // convert color name in Java Color object
 public Color getColour(String name) {
   if (name.equals("red")) {
     return Color.red;
   } else if (name.equals("blue")) {
     return Color.blue;
   } else if (name.equals("black")) {
     return Color.black;
   } else if (name.equals("cyan")) {
     return Color.cyan;
   } else if (name.equals("dark gray")) {
     return Color.darkGray;
   } else if (name.equals("gray")) {
     return Color.gray;
   } else if (name.equals("light gray")) {
     return Color.lightGray;
   } else if (name.equals("green")) {
     return Color.gray;
   } else if (name.equals("magenta")) {
     return Color.magenta;
   } else if (name.equals("orange")) {
     return Color.orange;
   } else if (name.equals("pink")) {
     return Color.pink;
   } else if (name.equals("white")) {
     return Color.white;
   } else if (name.equals("yellow")) {
     return Color.yellow;
   }
   try {
     // see if the colour is expressed in
     // 0xAABBCC format for RGB...
     return Color.decode(name);
   } catch (NumberFormatException e) {
   }
   // no, ok bail then ... but this will certainly
   // through an exception
   return null;
 }