Exemple #1
0
  @Override
  public void renderBorder(Track track, RenderContext context, Rectangle arect) {

    Rectangle adjustedRect = calculateDrawingRect(arect);

    // Draw boundaries if there is room
    if (adjustedRect.getHeight() >= 10) {

      /// TrackProperties pros = track.getProperties();

      // midline

      DataRange axisDefinition = track.getDataRange();
      float maxValue = axisDefinition.getMaximum();
      float baseValue = axisDefinition.getBaseline();
      float minValue = axisDefinition.getMinimum();

      double maxX = adjustedRect.getMaxX();
      double x = adjustedRect.getX();
      double y = adjustedRect.getY();

      if ((baseValue > minValue) && (baseValue < maxValue)) {
        int baseY = computeYPixelValue(adjustedRect, axisDefinition, baseValue);

        getBaselineGraphics(context).drawLine((int) x, baseY, (int) maxX, baseY);
      }

      PreferenceManager prefs = PreferenceManager.getInstance();

      Color altColor = track.getAltColor();
      Color borderColor =
          (prefs.getAsBoolean(PreferenceManager.CHART_COLOR_BORDERS)
                  && altColor != null
                  && altColor.equals(track.getColor()))
              ? track.getColor()
              : Color.lightGray;
      Graphics2D borderGraphics = context.getGraphic2DForColor(borderColor);

      // Draw the baseline -- todo, this is a wig track option?
      double zeroValue = axisDefinition.getBaseline();
      int zeroY = computeYPixelValue(adjustedRect, axisDefinition, zeroValue);
      borderGraphics.drawLine(adjustedRect.x, zeroY, adjustedRect.x + adjustedRect.width, zeroY);

      // Optionally draw "Y" line  (UCSC track line option)
      if (track.isDrawYLine()) {
        Graphics2D yLineGraphics = context.getGraphic2DForColor(Color.gray);
        int yLine = computeYPixelValue(adjustedRect, axisDefinition, track.getYLine());
        GraphicUtils.drawDashedLine(
            borderGraphics, adjustedRect.x, yLine, adjustedRect.x + adjustedRect.width, yLine);
      }

      // If the chart has + and - numbers draw both borders or none. This
      // needs documented somewhere.
      boolean drawBorders = true;

      if (minValue * maxValue < 0) {
        drawBorders =
            prefs.getAsBoolean(PreferenceManager.CHART_DRAW_BOTTOM_BORDER)
                && prefs.getAsBoolean(PreferenceManager.CHART_DRAW_TOP_BORDER);
      }

      if (drawBorders && prefs.getAsBoolean(PreferenceManager.CHART_DRAW_TOP_BORDER)) {
        borderGraphics.drawLine(
            adjustedRect.x, adjustedRect.y, adjustedRect.x + adjustedRect.width, adjustedRect.y);
      }

      if (drawBorders && prefs.getAsBoolean(PreferenceManager.CHART_DRAW_BOTTOM_BORDER)) {
        borderGraphics.drawLine(
            adjustedRect.x,
            adjustedRect.y + adjustedRect.height,
            adjustedRect.x + adjustedRect.width,
            adjustedRect.y + adjustedRect.height);
      }
    }
    /*
    (CHART_DRAW_TOP_BORDER));
    prefs.setDrawBottomBorder(getBooleanPreference(CHART_DRAW_BOTTOM_BORDER));
    prefs.setColorBorders(getBooleanPreference(CHART_COLOR_BORDERS));
    prefs.setDrawAxis(getBooleanPreference(CHART_DRAW_Y_AXIS));
    prefs.setDrawTrackName(getBooleanPreference(CHART_DRAW_TRACK_NAME));
    prefs.setColorTrackName(getBooleanPreference(CHART_COLOR_TRACK_NAME));
    prefs.setAutoscale(getBooleanPreference(CHART_AUTOSCALE));
    prefs.setShowDataRange(getBooleanPreference(CHART_SHOW_DATA_RANGE));
     */
  }
Exemple #2
0
  /** Creates a new Launcher object. */
  public Launcher() {
    // Initialize the SystemTray now (to avoid a bug!)
    SystemTray tray = null;
    try {
      tray = SystemTray.getDefaultSystemTray();
    } catch (Throwable e) {
      // Log to System error instead of standard error log.
      System.err.println("Error loading system tray library, system tray support disabled.");
    }

    // Use the native look and feel.
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (System.getProperty("app.name") != null) {
      appName = System.getProperty("app.name");
    } else {
      appName = "Openfire";
    }

    binDir = new File("").getAbsoluteFile();
    // See if the appdir property is set. If so, use it to find the executable.
    if (System.getProperty("appdir") != null) {
      binDir = new File(System.getProperty("appdir"));
    }

    configFile = new File(new File(binDir.getParent(), "conf"), "openfire.xml");

    frame =
        new DroppableFrame() {
          @Override
          public void fileDropped(File file) {
            String fileName = file.getName();
            if (fileName.endsWith(".jar") || fileName.endsWith(".war")) {
              installPlugin(file);
            }
          }
        };

    frame.setTitle(appName);

    ImageIcon splash;
    JPanel mainPanel = new JPanel();
    JLabel splashLabel = null;

    cardPanel.setLayout(cardLayout);

    // Set the icon.
    try {
      splash = new ImageIcon(getClass().getClassLoader().getResource("splash.gif"));
      splashLabel = new JLabel("", splash, JLabel.CENTER);

      onIcon = new ImageIcon(getClass().getClassLoader().getResource("openfire_on-16x16.gif"));
      offIcon = new ImageIcon(getClass().getClassLoader().getResource("openfire_off-16x16.gif"));
      frame.setIconImage(offIcon.getImage());
    } catch (Exception e) {
      e.printStackTrace();
    }

    mainPanel.setLayout(new BorderLayout());
    cardPanel.setBackground(Color.white);

    // Add buttons
    final JButton startButton = new JButton("Start");
    startButton.setActionCommand("Start");

    final JButton stopButton = new JButton("Stop");
    stopButton.setActionCommand("Stop");

    final JButton browserButton = new JButton("Launch Admin");
    browserButton.setActionCommand("Launch Admin");

    final JButton quitButton = new JButton("Quit");
    quitButton.setActionCommand("Quit");

    toolbar.setLayout(new GridBagLayout());
    toolbar.add(
        startButton,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    toolbar.add(
        stopButton,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    toolbar.add(
        browserButton,
        new GridBagConstraints(
            2,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    toolbar.add(
        quitButton,
        new GridBagConstraints(
            3,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));

    mainPanel.add(cardPanel, BorderLayout.CENTER);
    mainPanel.add(toolbar, BorderLayout.SOUTH);

    // create the main menu of the system tray icon
    JPopupMenu menu = new JPopupMenu(appName + " Menu");

    final JMenuItem showMenuItem = new JMenuItem("Hide");
    showMenuItem.setActionCommand("Hide/Show");
    menu.add(showMenuItem);

    final JMenuItem startMenuItem = new JMenuItem("Start");
    startMenuItem.setActionCommand("Start");
    menu.add(startMenuItem);

    final JMenuItem stopMenuItem = new JMenuItem("Stop");
    stopMenuItem.setActionCommand("Stop");
    menu.add(stopMenuItem);

    final JMenuItem browserMenuItem = new JMenuItem("Launch Admin");
    browserMenuItem.setActionCommand("Launch Admin");
    menu.add(browserMenuItem);

    menu.addSeparator();

    final JMenuItem quitMenuItem = new JMenuItem("Quit");
    quitMenuItem.setActionCommand("Quit");
    menu.add(quitMenuItem);

    browserButton.setEnabled(false);
    stopButton.setEnabled(false);
    browserMenuItem.setEnabled(false);
    stopMenuItem.setEnabled(false);

    ActionListener actionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if ("Start".equals(e.getActionCommand())) {
              frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
              // Adjust button and menu items.
              startButton.setEnabled(false);
              stopButton.setEnabled(true);
              startMenuItem.setEnabled(false);
              stopMenuItem.setEnabled(true);

              // Startup Application
              startApplication();

              // Change to the "on" icon.
              frame.setIconImage(onIcon.getImage());
              trayIcon.setIcon(onIcon);

              // Start a thread to enable the admin button after 8 seconds.
              Thread thread =
                  new Thread() {
                    @Override
                    public void run() {
                      try {
                        sleep(8000);
                      } catch (InterruptedException ie) {
                        // Ignore.
                      }
                      // Enable the Launch Admin button/menu item only if the
                      // server has started.
                      if (stopButton.isEnabled()) {
                        browserButton.setEnabled(true);
                        browserMenuItem.setEnabled(true);
                        frame.setCursor(Cursor.getDefaultCursor());
                      }
                    }
                  };
              thread.start();
            } else if ("Stop".equals(e.getActionCommand())) {
              stopApplication();
              // Change to the "off" button.
              frame.setIconImage(offIcon.getImage());
              trayIcon.setIcon(offIcon);
              // Adjust buttons and menu items.
              frame.setCursor(Cursor.getDefaultCursor());
              browserButton.setEnabled(false);
              startButton.setEnabled(true);
              stopButton.setEnabled(false);
              browserMenuItem.setEnabled(false);
              startMenuItem.setEnabled(true);
              stopMenuItem.setEnabled(false);
            } else if ("Launch Admin".equals(e.getActionCommand())) {
              launchBrowser();
            } else if ("Quit".equals(e.getActionCommand())) {
              stopApplication();
              System.exit(0);
            } else if ("Hide/Show".equals(e.getActionCommand())
                || "PressAction".equals(e.getActionCommand())) {
              // Hide/Unhide the window if the user clicked in the system tray icon or
              // selected the menu option
              if (frame.isVisible()) {
                frame.setVisible(false);
                frame.setState(Frame.ICONIFIED);
                showMenuItem.setText("Show");
              } else {
                frame.setVisible(true);
                frame.setState(Frame.NORMAL);
                showMenuItem.setText("Hide");
              }
            }
          }
        };

    // Register a listener for the radio buttons.
    startButton.addActionListener(actionListener);
    stopButton.addActionListener(actionListener);
    browserButton.addActionListener(actionListener);
    quitButton.addActionListener(actionListener);

    // Register a listener for the menu items.
    quitMenuItem.addActionListener(actionListener);
    browserMenuItem.addActionListener(actionListener);
    stopMenuItem.addActionListener(actionListener);
    startMenuItem.addActionListener(actionListener);
    showMenuItem.addActionListener(actionListener);

    // Set the system tray icon with the menu
    trayIcon = new TrayIcon(offIcon, appName, menu);
    trayIcon.setIconAutoSize(true);
    trayIcon.addActionListener(actionListener);

    if (tray != null) {
      tray.addTrayIcon(trayIcon);
    }

    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            stopApplication();
            System.exit(0);
          }

          @Override
          public void windowIconified(WindowEvent e) {
            // Make the window disappear when minimized
            frame.setVisible(false);
            showMenuItem.setText("Show");
          }
        });

    cardPanel.add("main", splashLabel);
    frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
    frame.pack();

    frame.setSize(400, 300);
    frame.setResizable(true);

    GraphicUtils.centerWindowOnScreen(frame);

    frame.setVisible(true);

    // Setup command area
    final ImageIcon icon = new ImageIcon(getClass().getClassLoader().getResource("splash2.gif"));
    pane =
        new DroppableTextPane() {
          @Override
          public void paintComponent(Graphics g) {
            final Dimension size = pane.getSize();

            int x = (size.width - icon.getIconWidth()) / 2;
            int y = (size.height - icon.getIconHeight()) / 2;
            //  Approach 1: Dispaly image at at full size
            g.setColor(Color.white);
            g.fillRect(0, 0, size.width, size.height);
            g.drawImage(icon.getImage(), x, y, null);

            setOpaque(false);
            super.paintComponent(g);
          }

          @Override
          public void fileDropped(File file) {
            String fileName = file.getName();
            if (fileName.endsWith(".jar") || fileName.endsWith(".war")) {
              installPlugin(file);
            }
          }
        };

    pane.setEditable(false);

    final JPanel bevelPanel = new JPanel();
    bevelPanel.setBackground(Color.white);
    bevelPanel.setLayout(new BorderLayout());
    bevelPanel.setBorder(BorderFactory.createLoweredBevelBorder());
    bevelPanel.add(new JScrollPane(pane), BorderLayout.CENTER);
    cardPanel.add("running", bevelPanel);

    // Start the app.
    startButton.doClick();
  }
Exemple #3
0
  /**
   * Method description
   *
   * @param track
   * @param context
   * @param arect
   */
  @Override
  public void renderAxis(Track track, RenderContext context, Rectangle arect) {

    // For now disable axes for all chromosome view
    if (context.getChr().equals(Globals.CHR_ALL)) {
      return;
    }

    super.renderAxis(track, context, arect);

    Rectangle drawingRect = calculateDrawingRect(arect);

    PreferenceManager prefs = PreferenceManager.getInstance();

    Color labelColor =
        prefs.getAsBoolean(PreferenceManager.CHART_COLOR_TRACK_NAME)
            ? track.getColor()
            : Color.black;
    Graphics2D labelGraphics = context.getGraphic2DForColor(labelColor);

    labelGraphics.setFont(FontManager.getFont(8));

    if (prefs.getAsBoolean(PreferenceManager.CHART_DRAW_TRACK_NAME)) {

      // Only attempt if track height is > 25 pixels
      if (arect.getHeight() > 25) {
        Rectangle labelRect = new Rectangle(arect.x, arect.y + 10, arect.width, 10);
        labelGraphics.setFont(FontManager.getFont(10));
        GraphicUtils.drawCenteredText(track.getName(), labelRect, labelGraphics);
      }
    }

    if (prefs.getAsBoolean(PreferenceManager.CHART_DRAW_Y_AXIS)) {

      Rectangle axisRect = new Rectangle(arect.x, arect.y + 1, AXIS_AREA_WIDTH, arect.height);

      DataRange axisDefinition = track.getDataRange();
      float maxValue = axisDefinition.getMaximum();
      float baseValue = axisDefinition.getBaseline();
      float minValue = axisDefinition.getMinimum();

      // Bottom (minimum tick mark)
      int pY = computeYPixelValue(drawingRect, axisDefinition, minValue);

      labelGraphics.drawLine(
          axisRect.x + AXIS_AREA_WIDTH - 10, pY, axisRect.x + AXIS_AREA_WIDTH - 5, pY);
      GraphicUtils.drawRightJustifiedText(
          formatter.format(minValue), axisRect.x + AXIS_AREA_WIDTH - 15, pY, labelGraphics);

      // Top (maximum tick mark)
      int topPY = computeYPixelValue(drawingRect, axisDefinition, maxValue);

      labelGraphics.drawLine(
          axisRect.x + AXIS_AREA_WIDTH - 10, topPY, axisRect.x + AXIS_AREA_WIDTH - 5, topPY);
      GraphicUtils.drawRightJustifiedText(
          formatter.format(maxValue), axisRect.x + AXIS_AREA_WIDTH - 15, topPY + 4, labelGraphics);

      // Connect top and bottom
      labelGraphics.drawLine(
          axisRect.x + AXIS_AREA_WIDTH - 10, topPY, axisRect.x + AXIS_AREA_WIDTH - 10, pY);

      // Middle tick mark.  Draw only if room
      int midPY = computeYPixelValue(drawingRect, axisDefinition, baseValue);

      if ((midPY < pY - 15) && (midPY > topPY + 15)) {
        labelGraphics.drawLine(
            axisRect.x + AXIS_AREA_WIDTH - 10, midPY, axisRect.x + AXIS_AREA_WIDTH - 5, midPY);
        GraphicUtils.drawRightJustifiedText(
            formatter.format(baseValue),
            axisRect.x + AXIS_AREA_WIDTH - 15,
            midPY + 4,
            labelGraphics);
      }

    } else if (track.isShowDataRange() && arect.height > 20) {
      drawScale(track.getDataRange(), context, arect);
    }
  }