Esempio n. 1
0
  private MainPanel() {
    super(new BorderLayout());

    JTextPane textPane = new JTextPane();
    textPane.setEditable(false);
    textPane.setMargin(new Insets(0, 10, 0, 0));
    insertQuestion(textPane, "111 / 37 = ");
    insertQuestion(textPane, "222 / 37 = ");
    insertQuestion(textPane, "333 / 37 = ");
    insertQuestion(textPane, "444 / 37 = ");
    insertQuestion(textPane, "555 / 37 = ");
    insertQuestion(textPane, "666 / 37 = ");
    insertQuestion(textPane, "777 / 37 = ");
    insertQuestion(textPane, "888 / 37 = ");
    insertQuestion(textPane, "999 / 37 = ");

    add(new JScrollPane(textPane));
    setPreferredSize(new Dimension(320, 240));
  }
 public GithubLoginPanel(final GithubLoginDialog dialog) {
   DocumentListener listener =
       new DocumentAdapter() {
         @Override
         protected void textChanged(DocumentEvent e) {
           dialog.clearErrors();
         }
       };
   myLoginTextField.getDocument().addDocumentListener(listener);
   myPasswordField.getDocument().addDocumentListener(listener);
   mySignupTextField.setText(
       "<html>Do not have an account at github.com? <a href=\"https://github.com\">Sign up</a>.</html>");
   mySignupTextField.setMargin(new Insets(5, 0, 0, 0));
   mySignupTextField.addHyperlinkListener(
       new HyperlinkAdapter() {
         @Override
         protected void hyperlinkActivated(final HyperlinkEvent e) {
           BrowserUtil.browse(e.getURL());
         }
       });
   mySignupTextField.setBackground(UIUtil.TRANSPARENT_COLOR);
   mySignupTextField.setCursor(new Cursor(Cursor.HAND_CURSOR));
 }
  /** Creates the viewer content component. */
  private JTextPane createContent(AlgorithmData algData) {

    String algName = algData.getParams().getString("name");
    int numOfDesiredClusters = algData.getParams().getInt("desired-cluster-count");
    String[] div = algData.getStringArray("diversity-value-array");
    String[] pop = algData.getStringArray("cluster-population-array");
    int popLimit = algData.getParams().getInt("minimum-cluster-size");

    JTextPane area = new JTextPane();
    area.setContentType("text/html");
    area.setEditable(false);
    area.setMargin(new Insets(0, 10, 0, 0));

    String text;

    int population;

    if (algName.equals("Diversity Ranking Cluster Selection")) {
      boolean useCentroid = algData.getParams().getBoolean("use-centroid-based-variability");

      text = "<html><body bgcolor='#FFFFFF'><font face='serif' size='5'>";
      text += "<br>Number of Desired Clusters: " + numOfDesiredClusters + "<br>";
      text += "Minimum Cluster Size (population): " + popLimit + "<br>";
      if (useCentroid)
        text += "Diversity Measurement: Centroid Based Diversity (mean gene-to-centroid dist.)<br>";
      else
        text += "Diversity Measurement: Intra-gene Based Diversity (mean gene-to-gene dist.)<br>";

      text +=
          "<br><br>Note: Clusters are sorted by diversity.  Selected clusters are in <b>bold</b> type.<br>";

      text +=
          "<table cellpadding=10><th><u>Div. Rank</u></th><th><u>Diversity</u></th><th><u>Population</u></td>";
      int clusterCount = 0;
      for (int i = 0; i < div.length; i++) {
        population = Integer.parseInt(pop[i]);
        if (population >= popLimit && clusterCount < numOfDesiredClusters) {
          text +=
              "<tr align=center><td><b>"
                  + (i + 1)
                  + "</b></td><td><b>"
                  + div[i]
                  + "</b></td><td><b>"
                  + pop[i]
                  + "</b></td></tr>";
          clusterCount++;
        } else
          text +=
              "<tr align=center><td>"
                  + (i + 1)
                  + "</td><td>"
                  + div[i]
                  + "</td><td>"
                  + pop[i]
                  + "</td></tr>";
      }
      text += "</table></body></html>";
    } else {
      boolean useVariance = algData.getParams().getBoolean("use-centroid-variance");

      text = "<html><body bgcolor='#FFFFFF'><font face='serif' size='5'>";
      text += "<br>Number of Desired Clusters: " + numOfDesiredClusters + "<br>";
      text += "Minimum Cluster Size (population): " + popLimit + "<br>";
      if (useVariance) {
        text += "Selection Criteria: Centroid Variance<br>";
        text +=
            "<br><br>Note: Clusters are sorted by decreasing variance.  Selected clusters are in <b>bold</b> type.<br>";
        text +=
            "<table cellpadding=10><th><u>Var. Rank</u></th><th><u>Variance</u></th><th><u>Population</u></td>";
      } else {
        text += "Selection Criteria: Centroid Entropy<br>";
        text +=
            "<br><br>Note: Clusters are sorted by decreasing entropy.  Selected clusters are in <b>bold</b> type.<br>";
        text +=
            "<table cellpadding=10><th><u>Entropy Rank</u></th><th><u>Entropy</u></th><th><u>Population</u></td>";
      }

      int clusterCount = 0;
      for (int i = 0; i < div.length; i++) {
        population = Integer.parseInt(pop[i]);
        if (population >= popLimit && clusterCount < numOfDesiredClusters) {
          text +=
              "<tr align=center><td><b>"
                  + (i + 1)
                  + "</b></td><td><b>"
                  + div[i]
                  + "</b></td><td><b>"
                  + pop[i]
                  + "</b></td></tr>";
          clusterCount++;
        } else
          text +=
              "<tr align=center><td>"
                  + (i + 1)
                  + "</td><td>"
                  + div[i]
                  + "</td><td>"
                  + pop[i]
                  + "</td></tr>";
      }
      text += "</table></body></html>";
    }

    area.setText(text);
    area.setCaretPosition(0);
    return area;
  }
Esempio n. 4
0
  public Scripter() {
    setTitle("Runedev Script Editor");
    setVisible(true);
    setBackground(new Color(245, 245, 245));
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(final WindowEvent e) {
            // BotGUI.scripter = null;
          }
        });
    setResizable(false);
    final File icon = new File(GlobalConfiguration.Paths.getIconDirectory() + "/edit.png");
    setIconImage(GlobalConfiguration.getImageFile(icon));

    document = new HighLightedDocument();
    jSeparator1 = new JPopupMenu.Separator();

    textPane = new JTextPane(document);
    textPane.setCaretPosition(0);
    textPane.setMargin(new Insets(5, 5, 5, 5));
    textPane.setPreferredSize(new Dimension(minSize));
    final JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setPreferredSize(new Dimension(minSize));

    final JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.add(scrollPane, BorderLayout.CENTER);
    setContentPane(contentPane);

    final JMenuBar menuBar = new JMenuBar();

    final JMenu fileMenu = new JMenu("File");
    final JMenuItem newScript = new JMenuItem("New");
    newScript.setAccelerator(
        KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
    newScript.setIcon(new ImageIcon(GlobalConfiguration.Paths.getIconDirectory() + "/pencil.png"));
    fileMenu.add(newScript);

    final JMenuItem openScript = new JMenuItem("Open");
    openScript.setAccelerator(
        KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
    final Image Open =
        (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.Paths.Resources.PLAY));
    openScript.setIcon(new ImageIcon(Open));
    fileMenu.add(openScript);

    final JMenuItem saveScript = new JMenuItem("Save");
    saveScript.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
    final Image Save =
        (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.Paths.Resources.SAVE));
    saveScript.setIcon(new ImageIcon(Save));
    fileMenu.add(saveScript);
    menuBar.add(fileMenu);

    final JMenu editMenu = new JMenu("Edit");
    final JMenuItem cut = new JMenuItem("Cut");
    cut.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
    final Image Cut =
        (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.Paths.Resources.CUT));
    cut.setIcon(new javax.swing.ImageIcon(Cut));
    editMenu.add(cut);

    final JMenuItem copy = new JMenuItem("Copy");
    copy.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
    final Image Copy =
        (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.Paths.Resources.COPY));
    copy.setIcon(new javax.swing.ImageIcon(Copy));
    editMenu.add(copy);

    final JMenuItem paste = new JMenuItem("Paste");
    paste.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
    final Image Paste =
        (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.Paths.Resources.PASTE));
    paste.setIcon(new javax.swing.ImageIcon(Paste));
    editMenu.add(paste);
    editMenu.add(jSeparator1);

    final JMenuItem selectAll = new JMenuItem("Select All");
    selectAll.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
    editMenu.add(selectAll);
    menuBar.add(editMenu);

    final JMenu infoMenu = new JMenu("Info");
    final JMenuItem troubleshooting = new JMenuItem("Troubleshooting");
    troubleshooting.setIcon(
        new ImageIcon(GlobalConfiguration.Paths.getIconDirectory() + "/web.png"));
    infoMenu.add(troubleshooting);

    final JMenuItem about = new JMenuItem("about");
    about.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_F1, java.awt.event.InputEvent.CTRL_MASK));
    about.setIcon(new ImageIcon(GlobalConfiguration.Paths.getIconDirectory() + "/gui.png"));
    infoMenu.add(about);
    menuBar.add(infoMenu);

    class newClick implements ActionListener {

      public void actionPerformed(final ActionEvent e) {
        if (JOptionPane.showConfirmDialog(
                contentPane,
                "You really want to start a new script? \n"
                    + "All un-saved work on this script will be lost.")
            == 0) {
          try {
            document.remove(0, document.getLength());
            document.insertString(document.getLength(), defaultLayout, getStyle("text"));
          } catch (final BadLocationException e1) {
          }
        }
      }
    }

    class openClick implements ActionListener {

      public void actionPerformed(final ActionEvent e) {
        final JFileChooser fc = new JFileChooser(file);
        fc.setCurrentDirectory(new File("./scripts/"));
        fc.addChoosableFileFilter(new JavaFilter());
        if (fc.showOpenDialog(contentPane) == JFileChooser.APPROVE_OPTION) {
          file = fc.getSelectedFile();
          try {
            document.remove(0, document.getLength());
            final BufferedReader in = new BufferedReader(new FileReader(file));
            String line = null;
            while ((line = in.readLine()) != null) {
              if (document.getLength() != 0) {
                document.insertString(document.getLength(), "\n", getStyle("text"));
              }
              document.insertString(document.getLength(), line, getStyle("text"));
            }
          } catch (final Exception ee) {
          }
        }
      }
    }

    class saveClick implements ActionListener {

      public void actionPerformed(final ActionEvent e) {
        final JFileChooser fc = new JFileChooser(file);
        fc.setCurrentDirectory(new File("./scripts/"));
        fc.addChoosableFileFilter(new JavaFilter());
        if (fc.showSaveDialog(contentPane) == JFileChooser.APPROVE_OPTION) {
          try {
            file = fc.getSelectedFile();
            final BufferedWriter out = new BufferedWriter(new FileWriter(file));
            out.write(document.getText(0, document.getLength()));

            out.close();
          } catch (final Exception ee) {
          }
        }
      }
    }

    class Cut implements ActionListener {

      public void actionPerformed(final ActionEvent e) {
        textPane.cut();
      }
    }

    class Copy implements ActionListener {

      public void actionPerformed(final ActionEvent e) {
        textPane.copy();
      }
    }

    class Paste implements ActionListener {

      public void actionPerformed(final ActionEvent e) {
        textPane.paste();
      }
    }

    class SelectAll implements ActionListener {

      public void actionPerformed(final ActionEvent e) {
        textPane.selectAll();
      }
    }

    class tsClick implements ActionListener {

      public void actionPerformed(final ActionEvent e) {
        openURL("http://forum.runedev.info/viewtopic.php?f=40&t=2629");
      }

      public void openURL(final String url) {
        final OperatingSystem os = GlobalConfiguration.getCurrentOperatingSystem();
        try {
          if (os == OperatingSystem.MAC) {
            final Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
            final Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
            openURL.invoke(null, url);
          } else if (os == OperatingSystem.WINDOWS) {
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
          } else {
              /* assume Unix or Linux */
            final String[] browsers = {
              "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"
            };
            String browser = null;
            for (int count = 0; (count < browsers.length) && (browser == null); count++) {
              if (Runtime.getRuntime().exec(new String[] {"which", browsers[count]}).waitFor()
                  == 0) {
                browser = browsers[count];
              }
            }
            if (browser == null) {
              throw new Exception("Could not find web browser");
            } else {
              Runtime.getRuntime().exec(new String[] {browser, url});
            }
          }
        } catch (final Exception e) {
        }
      }
    }

    class aboutClick implements ActionListener {

      public void actionPerformed(final ActionEvent e) {
        JOptionPane.showMessageDialog(
            contentPane,
            new String[] {
              "A Script Editor Made for RuneDev.",
              "\nThis Editor was designed by Sorcermus\n"
                  + "for the RuneDev gaming client\n"
                  + "For more information, \nvisit; "
                  + GlobalConfiguration.Paths.URLs.SITE
            },
            "\n" + "About this editor, and the game client",
            JOptionPane.INFORMATION_MESSAGE);
      }
    }

    newScript.addActionListener(new newClick());
    openScript.addActionListener(new openClick());
    saveScript.addActionListener(new saveClick());
    cut.addActionListener(new Cut());
    copy.addActionListener(new Copy());
    paste.addActionListener(new Paste());
    selectAll.addActionListener(new SelectAll());
    troubleshooting.addActionListener(new tsClick());
    about.addActionListener(new aboutClick());

    setJMenuBar(menuBar);

    final JTextArea lines = new JTextArea("");
    lines.setSelectionEnd(document.getLength());
    lines.setFont(new Font("Monospaced", Font.PLAIN, 12));
    lines.setBackground(new Color(210, 210, 210));
    lines.setEditable(false);
    lines.setMargin(new Insets(5, 2, 5, 2));

    document.addDocumentListener(
        new DocumentListener() {

          public void changedUpdate(final DocumentEvent de) {
            lines.setText(getText());
          }

          public String getText() {
            final int caretPosition = document.getEndPosition().getOffset();
            final Element root = document.getDefaultRootElement();
            String text = "1" + System.getProperty("line.separator");
            for (int i = 2; i < root.getElementIndex(caretPosition) + 2; i++) {
              text += i + System.getProperty("line.separator");
            }
            return text;
          }

          public void insertUpdate(final DocumentEvent de) {
            lines.setText(getText());
          }

          public void removeUpdate(final DocumentEvent de) {
            lines.setText(getText());
          }
        });

    scrollPane.setRowHeaderView(lines);

    colorer = new Colorer();
    colorer.start();

    initStyles(12);

    documentReader = new DocumentReader(document);

    initDocument();

    pack();
    setVisible(true);
  }
Esempio n. 5
0
  /** Initialize the contents of the frame. */
  private void initialize() {
    frame = new JFrame();
    frame.getContentPane().setBackground(Color.WHITE);
    frame.setBounds(100, 100, 1024, 768);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    txtUsername = new JTextField();
    txtUsername.setText("username");
    txtUsername.setBounds(716, 11, 86, 20);
    frame.getContentPane().add(txtUsername);
    txtUsername.setColumns(10);

    txtPassword = new JTextField();
    txtPassword.setText("password");
    txtPassword.setBounds(812, 11, 86, 20);
    frame.getContentPane().add(txtPassword);
    txtPassword.setColumns(10);

    JButton btnNewButton = new JButton("Login");
    btnNewButton.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            PrivateDashboard privateDashboard = new PrivateDashboard();
            privateDashboard.getFrame().setVisible(true);
          }
        });
    btnNewButton.setBounds(908, 10, 89, 23);
    frame.getContentPane().add(btnNewButton);

    JLabel lblForgotPassword = new JLabel("Forgot Password");
    lblForgotPassword.setForeground(Color.BLUE);
    lblForgotPassword.setBounds(895, 44, 102, 14);
    frame.getContentPane().add(lblForgotPassword);

    JPanel panel_MainChartPanel = new JPanel();
    panel_MainChartPanel.setBorder(new LineBorder(new Color(0, 0, 0)));
    panel_MainChartPanel.setBackground(Color.WHITE);
    panel_MainChartPanel.setBounds(194, 69, 517, 436);
    frame.getContentPane().add(panel_MainChartPanel);
    panel_MainChartPanel.setLayout(null);

    //		JLabel label = new JLabel("");
    //		label.setBounds(0, 0, 67, 57);
    //		label.setIcon(new
    // ImageIcon(PublicDashboard.class.getResource("/ubc/cpsc544/3DBuildingView.png")));
    //		panel_MainChartPanel.add(label);

    BarChart barChart = new BarChart();
    ChartPanel chartPanel = barChart.getChartPanel();
    chartPanel.setVisible(true);
    chartPanel.setBounds(0, 0, 517, 436);
    panel_MainChartPanel.add(chartPanel);

    JPanel panel_Units = new JPanel();
    FlowLayout fl_panel_Units = (FlowLayout) panel_Units.getLayout();
    fl_panel_Units.setAlignment(FlowLayout.LEFT);
    panel_Units.setBorder(new LineBorder(new Color(0, 0, 0)));
    panel_Units.setBackground(Color.WHITE);
    panel_Units.setBounds(10, 364, 174, 141);
    frame.getContentPane().add(panel_Units);

    JLabel lblUnits = new JLabel("Units");
    lblUnits.setFont(new Font("Tahoma", Font.BOLD, 14));
    panel_Units.add(lblUnits);

    JRadioButton radioButton = new JRadioButton("Kilo-Watt Hour kWH");
    radioButton.setFont(new Font("Tahoma", Font.PLAIN, 14));
    radioButton.setBackground(Color.WHITE);
    radioButton.setSelected(true);
    panel_Units.add(radioButton);

    JRadioButton radioButton_1 = new JRadioButton("Ibs of CO2");
    radioButton_1.setEnabled(false);
    radioButton_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
    radioButton_1.setBackground(Color.WHITE);
    panel_Units.add(radioButton_1);

    JRadioButton radioButton_2 = new JRadioButton("Dollar Value");
    radioButton_2.setEnabled(false);
    radioButton_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
    radioButton_2.setBackground(Color.WHITE);
    panel_Units.add(radioButton_2);

    JPanel panel_4 = new JPanel();
    FlowLayout flowLayout_1 = (FlowLayout) panel_4.getLayout();
    flowLayout_1.setAlignment(FlowLayout.LEFT);
    panel_4.setBorder(new LineBorder(new Color(0, 0, 0)));
    panel_4.setBackground(Color.WHITE);
    panel_4.setBounds(10, 521, 701, 185);
    frame.getContentPane().add(panel_4);
    panel_4.setLayout(null);

    JTextPane txtpnFloors = new JTextPane();
    txtpnFloors.setFont(new Font("Tahoma", Font.PLAIN, 14));
    txtpnFloors.setText(
        "St. John\u2019s College is UBC\u2019s international graduate college. A magnet for international and multicultural exchange, the College offers an academic setting that encourages discussion, debate and cultural expression, all enlivened by the participation of resident graduate students who come from diverse cultural backgrounds.");
    txtpnFloors.setBounds(12, 60, 666, 80);
    panel_4.add(txtpnFloors);

    JTextPane txtpnNoFloors = new JTextPane();
    txtpnNoFloors.setFont(new Font("Helvetica", Font.PLAIN, 15));
    txtpnNoFloors.setText(
        "NO. FLOORS  \t-  05\nOCCUPANTS  \t-  120\n\nSt. John\u2019s College is UBC\u2019s international graduate college. A magnet for international\n and multicultural exchange, the College offers an academic setting that encourages \ndiscussion, debate and cultural expression, all enlivened by the participation of \nresident graduate students who come from diverse cultural backgrounds.");
    panel_4.add(txtpnNoFloors);

    JTextPane txtpnFloorsOccupants = new JTextPane();
    txtpnFloorsOccupants.setFont(new Font("Dialog", Font.PLAIN, 15));
    txtpnFloorsOccupants.setText("Floors:  05\r\nOccupants:  120\r");
    txtpnFloorsOccupants.setBounds(12, 12, 280, 51);
    panel_4.add(txtpnFloorsOccupants);

    JPanel panel_5 = new JPanel();
    panel_5.setBorder(new LineBorder(new Color(0, 0, 0)));
    panel_5.setBackground(Color.WHITE);
    panel_5.setBounds(721, 521, 276, 185);
    frame.getContentPane().add(panel_5);

    JLabel label_1 = new JLabel("");
    label_1.setIcon(new ImageIcon(PublicDashboard.class.getResource("/ubc/cpsc544/weather.png")));
    panel_5.add(label_1);

    JLabel lblBulbIcon = new JLabel("");
    lblBulbIcon.setIcon(new ImageIcon(PublicDashboard.class.getResource("/ubc/cpsc544/bulb.png")));
    lblBulbIcon.setBounds(12, 11, 35, 33);
    frame.getContentPane().add(lblBulbIcon);

    JLabel lblUbcEnergyDashboard = new JLabel("UBC Energy Dashboard");
    lblUbcEnergyDashboard.setForeground(new Color(0, 128, 0));
    lblUbcEnergyDashboard.setFont(new Font("Tahoma", Font.BOLD, 18));
    lblUbcEnergyDashboard.setBorder(null);
    lblUbcEnergyDashboard.setBounds(49, 15, 229, 29);
    frame.getContentPane().add(lblUbcEnergyDashboard);

    JPanel panel = new JPanel();
    panel.setBounds(10, 69, 174, 284);
    frame.getContentPane().add(panel);
    panel.setBackground(Color.WHITE);
    panel.setBorder(new LineBorder(new Color(0, 0, 0)));
    panel.setLayout(null);

    JLabel lblCumulative = new JLabel("Cumulative");
    lblCumulative.setBounds(10, 5, 89, 26);
    lblCumulative.setFont(new Font("Tahoma", Font.BOLD, 14));
    lblCumulative.setBorder(null);
    panel.add(lblCumulative);

    JLabel lblK = new JLabel("176,000 kWH");
    lblK.setIcon(new ImageIcon(PublicDashboard.class.getResource("/ubc/cpsc544/Electricity.jpg")));
    lblK.setFont(new Font("Tahoma", Font.BOLD, 17));
    lblK.setBorder(null);
    lblK.setBounds(10, 32, 144, 31);
    panel.add(lblK);

    JLabel lblCo = new JLabel("20,735 CO2");
    lblCo.setIcon(new ImageIcon(PublicDashboard.class.getResource("/ubc/cpsc544/COs.jpg")));
    lblCo.setFont(new Font("Tahoma", Font.PLAIN, 14));
    lblCo.setBorder(null);
    lblCo.setBounds(10, 67, 144, 31);
    panel.add(lblCo);

    JLabel label_2 = new JLabel("3,601.25");
    label_2.setIcon(
        new ImageIcon(PublicDashboard.class.getResource("/ubc/cpsc544/Dollar_Symbol.gif")));
    label_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
    label_2.setBorder(null);
    label_2.setBounds(10, 97, 144, 31);
    panel.add(label_2);

    JLabel lblLastMonth = new JLabel("Last month");
    lblLastMonth.setFont(new Font("Tahoma", Font.PLAIN, 14));
    lblLastMonth.setBorder(null);
    lblLastMonth.setBounds(10, 139, 89, 26);
    panel.add(lblLastMonth);

    JLabel lblKwh = new JLabel("166,500 kWH");
    lblKwh.setIcon(
        new ImageIcon(PublicDashboard.class.getResource("/ubc/cpsc544/Electricity.jpg")));
    lblKwh.setFont(new Font("Tahoma", Font.BOLD, 17));
    lblKwh.setBorder(null);
    lblKwh.setBounds(10, 176, 144, 31);
    panel.add(lblKwh);

    JLabel label_4 = new JLabel("5.4%");
    label_4.setForeground(new Color(0, 204, 0));
    label_4.setIcon(new ImageIcon(PublicDashboard.class.getResource("/ubc/cpsc544/DownArrow.png")));
    label_4.setFont(new Font("Tahoma", Font.BOLD, 21));
    label_4.setBorder(null);
    label_4.setBounds(10, 224, 144, 31);
    panel.add(label_4);

    JSeparator separator = new JSeparator();
    separator.setBounds(10, 133, 152, 2);
    panel.add(separator);

    JPanel panel_2 = new JPanel();
    panel_2.setBorder(new LineBorder(new Color(0, 0, 0)));
    panel_2.setBackground(Color.WHITE);
    panel_2.setBounds(723, 71, 274, 434);
    frame.getContentPane().add(panel_2);
    panel_2.setLayout(null);

    JTextPane txtpnIdeas = new JTextPane();
    txtpnIdeas.setBounds(12, 55, 259, 339);
    panel_2.add(txtpnIdeas);
    txtpnIdeas.setEditable(false);
    txtpnIdeas.setFont(new Font("Tahoma", Font.PLAIN, 15));
    txtpnIdeas.setBorder(null);
    txtpnIdeas.setMargin(new Insets(30, 30, 30, 30));
    txtpnIdeas.setText(
        "1. Lower your thermostat by 4 - 5 degrees Celsius (7 - 9 degrees Fahrenheit) while you're sleeping at night and when no one is at home. \n\n "
            + "2. Switch to cold when doing your laundry. 85 – 90% of the energy used to wash your clothes is used to heat the water. \n\n "
            + "3. Try setting your dishwasher to start after 7:00 p.m. when off-peak prices begin. ");

    JLabel lblTopIdeas = new JLabel("Top Ideas");
    lblTopIdeas.setBounds(12, 13, 112, 29);
    panel_2.add(lblTopIdeas);
    lblTopIdeas.setFont(new Font("Tahoma", Font.BOLD, 14));
    lblTopIdeas.setBorder(null);

    JLabel lblSt = new JLabel("St. John's College, UBC");
    lblSt.setFont(new Font("Dialog", Font.BOLD, 16));
    lblSt.setBounds(519, 40, 192, 22);
    frame.getContentPane().add(lblSt);
  }
Esempio n. 6
0
    public DocumentPanel() {
      super(new BorderLayout());

      JLabel lblDocument = new JLabel("Document: " + document.getTitle());
      lblDocument.setBorder(new EtchedBorder());

      textPane = new JTextPane(document);
      textPane.setEditable(false);
      textPane.setMargin(new Insets(5, 20, 5, 5));
      textPane.setMaximumSize(new Dimension(364, 1000000000));
      textPane.setPreferredSize(new Dimension(364, 400));
      textPane.setMinimumSize(new Dimension(364, 10));
      textPane.addCaretListener(
          new CaretListener() {
            public void caretUpdate(CaretEvent e) {
              int length = document.getLength();
              int offset = e.getDot();

              if (e.getDot() == e.getMark()) textPane.getCaret().moveDot(offset + 1);

              Paragraph p = lockManager.getParFromOffset(offset);
              int pOffset = p.getOffset();

              lblCursor.setText(
                  "Document Length="
                      + String.valueOf(length)
                      + ", CaretOffset="
                      + String.valueOf(offset)
                      + ", Paragraph="
                      + p.toString()
                      + ", Offset in Paragraph="
                      + String.valueOf(offset - p.getOffset()));
            }
          });
      Box box = new Box(BoxLayout.X_AXIS);
      box.add(textPane);
      box.add(Box.createGlue());
      box.setBackground(Color.WHITE);
      box.setOpaque(true);
      box.setPreferredSize(new Dimension(600, 10000));

      lblCursor = new JLabel("Cursor");
      lblCursor.setBorder(new EtchedBorder());

      JPanel boxText = new JPanel(new BorderLayout());
      boxText.setBorder(new EmptyBorder(5, 5, 5, 5));
      boxText.add(lblDocument, BorderLayout.NORTH);
      boxText.add(new JScrollPane(box), BorderLayout.CENTER);
      boxText.add(lblCursor, BorderLayout.SOUTH);

      JLabel lblPars = new JLabel("Paragraphs: ");
      lblPars.setBorder(new EtchedBorder());

      parList = new JList();
      parList.setPreferredSize(new Dimension(100, 300));
      parList.setEnabled(false);

      JPanel boxPars = new JPanel(new BorderLayout());
      boxPars.setBorder(new EmptyBorder(5, 5, 5, 5));
      boxPars.add(lblPars, BorderLayout.NORTH);
      boxPars.add(new JScrollPane(parList), BorderLayout.CENTER);

      add(boxText, BorderLayout.CENTER);
      add(boxPars, BorderLayout.EAST);
    }
Esempio n. 7
0
  private void initGui() {
    srsComboBoxLabel = new JLabel();
    sridLabel = new JLabel();

    DecimalFormat tileFormat = new DecimalFormat("##########");
    tileFormat.setMaximumIntegerDigits(10);
    tileFormat.setMinimumIntegerDigits(1);
    sridText = new JFormattedTextField(tileFormat);

    srsNameLabel = new JLabel();
    gmlSrsNameText = new JTextField();
    descriptionLabel = new JLabel();
    descriptionText = new JTextField();
    newButton = new JButton();
    applyButton = new JButton();
    deleteButton = new JButton();
    checkButton = new JButton();
    checkButton.setEnabled(false);
    copyButton = new JButton();

    fileLabel = new JLabel();
    fileText = new JTextField();
    browseFileButton = new JButton();
    addFileButton = new JButton();
    replaceWithFileButton = new JButton();
    saveFileButton = new JButton();

    dbSrsTypeLabel = new JLabel();
    dbSrsTypeText = new JTextPane();
    dbSrsNameLabel = new JLabel();
    dbSrsNameText = new JTextPane();

    srsComboBoxFactory = SrsComboBoxFactory.getInstance(config);
    srsComboBox = srsComboBoxFactory.createSrsComboBox(false);

    PopupMenuDecorator.getInstance()
        .decorate(
            sridText, gmlSrsNameText, descriptionText, fileText, dbSrsTypeText, dbSrsNameText);

    sridText.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            if (sridText.getValue() != null) {
              if (((Number) sridText.getValue()).intValue() < 0) sridText.setValue(0);
              else if (((Number) sridText.getValue()).intValue() > Integer.MAX_VALUE)
                sridText.setValue(Integer.MAX_VALUE);
            }
          }
        });

    setLayout(new GridBagLayout());

    contentsPanel = new JPanel();
    contentsPanel.setBorder(BorderFactory.createTitledBorder(""));
    contentsPanel.setLayout(new GridBagLayout());
    add(contentsPanel, GuiUtil.setConstraints(0, 0, 1.0, 0.0, GridBagConstraints.BOTH, 5, 0, 5, 0));
    {
      JPanel srsPanel = new JPanel();
      srsPanel.setLayout(new GridBagLayout());

      gmlSrsNameText.setPreferredSize(gmlSrsNameText.getPreferredSize());
      descriptionText.setPreferredSize(gmlSrsNameText.getPreferredSize());
      srsComboBox.setPreferredSize(gmlSrsNameText.getPreferredSize());

      srsPanel.add(
          sridLabel,
          GuiUtil.setConstraints(
              0, 0, 0, 0, GridBagConstraints.BOTH, 0, BORDER_THICKNESS, 0, BORDER_THICKNESS));
      srsPanel.add(
          sridText,
          GuiUtil.setConstraints(
              1, 0, 1, 0, GridBagConstraints.HORIZONTAL, 0, BORDER_THICKNESS, 0, BORDER_THICKNESS));
      srsPanel.add(
          checkButton,
          GuiUtil.setConstraints(
              2, 0, 0, 0, GridBagConstraints.HORIZONTAL, 0, BORDER_THICKNESS, 0, BORDER_THICKNESS));

      srsPanel.add(
          srsNameLabel,
          GuiUtil.setConstraints(
              0,
              1,
              0,
              0,
              GridBagConstraints.BOTH,
              BORDER_THICKNESS,
              BORDER_THICKNESS,
              0,
              BORDER_THICKNESS));
      srsPanel.add(
          gmlSrsNameText,
          GuiUtil.setConstraints(
              1,
              1,
              2,
              1,
              1,
              0,
              GridBagConstraints.HORIZONTAL,
              BORDER_THICKNESS,
              BORDER_THICKNESS,
              0,
              BORDER_THICKNESS));

      srsPanel.add(
          descriptionLabel,
          GuiUtil.setConstraints(
              0,
              2,
              0,
              0,
              GridBagConstraints.BOTH,
              BORDER_THICKNESS,
              BORDER_THICKNESS,
              0,
              BORDER_THICKNESS));
      srsPanel.add(
          descriptionText,
          GuiUtil.setConstraints(
              1,
              2,
              2,
              1,
              1,
              0,
              GridBagConstraints.HORIZONTAL,
              BORDER_THICKNESS,
              BORDER_THICKNESS,
              0,
              BORDER_THICKNESS));

      dbSrsTypeText.setEditable(false);
      dbSrsTypeText.setBorder(sridText.getBorder());
      dbSrsTypeText.setBackground(srsPanel.getBackground());
      dbSrsTypeText.setMargin(sridText.getMargin());

      dbSrsNameText.setEditable(false);
      dbSrsNameText.setBorder(sridText.getBorder());
      dbSrsNameText.setBackground(srsPanel.getBackground());
      dbSrsNameText.setMargin(sridText.getMargin());

      srsPanel.add(
          dbSrsNameLabel,
          GuiUtil.setConstraints(
              0,
              3,
              0,
              0,
              GridBagConstraints.HORIZONTAL,
              BORDER_THICKNESS,
              BORDER_THICKNESS,
              0,
              BORDER_THICKNESS));
      srsPanel.add(
          dbSrsNameText,
          GuiUtil.setConstraints(
              1,
              3,
              2,
              1,
              1,
              0,
              GridBagConstraints.BOTH,
              BORDER_THICKNESS,
              BORDER_THICKNESS,
              0,
              BORDER_THICKNESS));
      srsPanel.add(
          dbSrsTypeLabel,
          GuiUtil.setConstraints(
              0,
              4,
              0,
              0,
              GridBagConstraints.HORIZONTAL,
              BORDER_THICKNESS,
              BORDER_THICKNESS,
              BORDER_THICKNESS,
              BORDER_THICKNESS));
      srsPanel.add(
          dbSrsTypeText,
          GuiUtil.setConstraints(
              1,
              4,
              2,
              1,
              1,
              0,
              GridBagConstraints.BOTH,
              BORDER_THICKNESS,
              BORDER_THICKNESS,
              BORDER_THICKNESS,
              BORDER_THICKNESS));

      Box buttonsPanel = Box.createHorizontalBox();
      buttonsPanel.add(applyButton);
      buttonsPanel.add(Box.createRigidArea(new Dimension(2 * BORDER_THICKNESS, 0)));
      buttonsPanel.add(newButton);
      buttonsPanel.add(Box.createRigidArea(new Dimension(2 * BORDER_THICKNESS, 0)));
      buttonsPanel.add(copyButton);
      buttonsPanel.add(Box.createRigidArea(new Dimension(2 * BORDER_THICKNESS, 0)));
      buttonsPanel.add(deleteButton);
      buttonsPanel.add(Box.createRigidArea(new Dimension(2 * BORDER_THICKNESS, 0)));

      GridBagConstraints c =
          GuiUtil.setConstraints(
              0,
              5,
              3,
              1,
              1,
              0,
              GridBagConstraints.NONE,
              BORDER_THICKNESS * 2,
              BORDER_THICKNESS,
              BORDER_THICKNESS,
              BORDER_THICKNESS);
      c.anchor = GridBagConstraints.CENTER;
      srsPanel.add(buttonsPanel, c);

      JPanel currentlySupportedContent = new JPanel();
      currentlySupportedContent.setBorder(BorderFactory.createEmptyBorder());
      currentlySupportedContent.setLayout(new GridBagLayout());
      currentlySupportedContent.add(
          srsComboBoxLabel,
          GuiUtil.setConstraints(0, 0, 0.0, 1.0, GridBagConstraints.BOTH, 0, 5, 0, 5));
      currentlySupportedContent.add(
          srsComboBox, GuiUtil.setConstraints(1, 0, 1.0, 1.0, GridBagConstraints.BOTH, 0, 5, 0, 5));

      contentsPanel.add(
          currentlySupportedContent,
          GuiUtil.setConstraints(0, 0, 1.0, 0.0, GridBagConstraints.BOTH, 0, 0, 5, 0));
      contentsPanel.add(
          srsPanel, GuiUtil.setConstraints(0, 1, 1.0, 0.0, GridBagConstraints.BOTH, 20, 0, 5, 0));
    }

    impExpPanel = new JPanel();
    impExpPanel.setBorder(BorderFactory.createTitledBorder(""));
    impExpPanel.setLayout(new GridBagLayout());
    add(impExpPanel, GuiUtil.setConstraints(0, 1, 1.0, 0.0, GridBagConstraints.BOTH, 5, 0, 5, 0));
    {
      JPanel browse = new JPanel();
      JPanel button = new JPanel();

      impExpPanel.add(
          browse, GuiUtil.setConstraints(0, 0, 1.0, 1.0, GridBagConstraints.BOTH, 0, 0, 0, 0));
      impExpPanel.add(
          button, GuiUtil.setConstraints(0, 1, 0.0, 1.0, GridBagConstraints.BOTH, 5, 0, 5, 0));
      fileText.setPreferredSize(fileText.getPreferredSize());

      browse.setLayout(new GridBagLayout());
      {
        browse.add(
            fileLabel,
            GuiUtil.setConstraints(0, 0, 1.0, 0.0, GridBagConstraints.HORIZONTAL, 5, 5, 0, 5));
        browse.add(
            fileText,
            GuiUtil.setConstraints(0, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL, 0, 5, 5, 5));
        browse.add(
            browseFileButton,
            GuiUtil.setConstraints(1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 5, 5, 5));
      }

      button.setLayout(new GridBagLayout());
      {
        button.add(
            addFileButton, GuiUtil.setConstraints(0, 0, 0, 0, GridBagConstraints.NONE, 5, 5, 5, 5));
        button.add(
            replaceWithFileButton,
            GuiUtil.setConstraints(1, 0, 0, 0, GridBagConstraints.NONE, 5, 5, 5, 5));
        button.add(
            saveFileButton,
            GuiUtil.setConstraints(2, 0, 0, 0, GridBagConstraints.NONE, 5, 20, 5, 5));
      }
    }

    // influence focus policy
    checkButton.setFocusCycleRoot(false);

    srsComboBoxListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            displaySelectedValues();
          }
        };

    DropTarget dropTarget = new DropTarget(fileText, this);
    fileText.setDropTarget(dropTarget);
    impExpPanel.setDropTarget(dropTarget);

    srsComboBox.addActionListener(srsComboBoxListener);

    newButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (requestChange()) {
              DatabaseSrs refSys = DatabaseSrs.createDefaultSrs();
              refSys.setDescription(getNewRefSysDescription());
              refSys.setSupported(!dbPool.isConnected());

              config.getProject().getDatabase().addReferenceSystem(refSys);
              updateSrsComboBoxes(false);
              srsComboBox.setSelectedItem(refSys);

              displaySelectedValues();
            }
          }
        });

    copyButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (requestChange()) {
              DatabaseSrs orig = srsComboBox.getSelectedItem();
              DatabaseSrs copy = new DatabaseSrs(orig);
              copy.setDescription(getCopyOfDescription(orig));

              config.getProject().getDatabase().addReferenceSystem(copy);
              updateSrsComboBoxes(false);
              srsComboBox.setSelectedItem(copy);

              displaySelectedValues();
            }
          }
        });

    applyButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setSettings();
            LOG.info("Settings successfully applied.");
          }
        });

    deleteButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            DatabaseSrs refSys = srsComboBox.getSelectedItem();
            int index = srsComboBox.getSelectedIndex();

            String text = Language.I18N.getString("pref.db.srs.dialog.delete.msg");
            Object[] args = new Object[] {refSys.getDescription()};
            String formattedMsg = MessageFormat.format(text, args);

            if (JOptionPane.showConfirmDialog(
                    getTopLevelAncestor(),
                    formattedMsg,
                    Language.I18N.getString("pref.db.srs.dialog.delete.title"),
                    JOptionPane.YES_NO_OPTION)
                == JOptionPane.YES_OPTION) {
              config.getProject().getDatabase().getReferenceSystems().remove(refSys);
              updateSrsComboBoxes(false);
              srsComboBox.setSelectedIndex(index < srsComboBox.getItemCount() ? index : index - 1);
              displaySelectedValues();
            }
          }
        });

    checkButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int srid = 0;

            try {
              srid = Integer.parseInt(sridText.getText().trim());
            } catch (NumberFormatException nfe) {
              //
            }

            try {
              DatabaseSrs tmp = DatabaseSrs.createDefaultSrs();
              tmp.setSrid(srid);
              dbPool.getActiveDatabaseAdapter().getUtil().getSrsInfo(tmp);
              if (tmp.isSupported()) {
                LOG.all(LogLevel.INFO, "SRID " + srid + " is supported.");
                LOG.all(LogLevel.INFO, "Database name: " + tmp.getDatabaseSrsName());
                LOG.all(LogLevel.INFO, "SRS type: " + tmp.getType());
              } else LOG.all(LogLevel.WARN, "SRID " + srid + " is NOT supported.");
            } catch (SQLException sqlEx) {
              LOG.error("Error while checking user-defined SRSs: " + sqlEx.getMessage().trim());
            }
          }
        });

    browseFileButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            browseReferenceSystemFile(Language.I18N.getString("pref.db.srs.label.file"));
          }
        });

    addFileButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            importReferenceSystems(false);
          }
        });

    replaceWithFileButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            importReferenceSystems(true);
          }
        });

    saveFileButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            exportReferenceSystems();
          }
        });
  }