public MapperDividersController(Mapper mapper, JPanel leftDivider, JPanel rightDivider) {
    this.mapper = mapper;
    this.leftDivider = leftDivider;
    this.rightDivider = rightDivider;

    leftDivider.addMouseListener(this);
    leftDivider.addMouseMotionListener(this);

    rightDivider.addMouseListener(this);
    rightDivider.addMouseMotionListener(this);
  }
  /** @param presentationModel A presentation model with panel's logic. */
  public ImageRenderingPanel(ImagePresentationModel presentationModel) {
    if (presentationModel == null)
      throw new IllegalArgumentException("presentationModel cannot be null.");

    mUIModel = presentationModel;
    mUIModel.addListener(
        new Listener() {
          @Override
          public void onVisibleImageContentUpdate() {
            SwingUtilities.invokeLater(() -> repaint());
          }

          @Override
          public void onImageChange() {
            SwingUtilities.invokeLater(() -> repaint());
          }
        });

    MouseHandler handler = new MouseHandler();

    super.addMouseListener(handler);
    super.addMouseMotionListener(handler);
    super.addMouseWheelListener(handler);
    super.addComponentListener(new ResizeHandler());
  }
Example #3
0
  public static void main(String[] args) {
    JFrame jf = new JFrame("Òƶ¯µÄÎÄ×Ö");
    final JPanel jp =
        new JPanel() {
          public void paint(Graphics g) {
            Graphics2D g2 = (Graphics2D) g;
            g2.setColor(Color.white);
            g2.fillRect(0, 0, 500, 400);
            g2.setColor(Color.black);
            g2.drawString("helloWorld", x, y);
          }
        };
    jp.addMouseMotionListener(
        new MouseMotionListener() {

          @Override
          public void mouseMoved(MouseEvent e) {}

          @Override
          public void mouseDragged(MouseEvent e) {
            // TODO Auto-generated method stub
            x = e.getX();
            y = e.getY();
            jp.repaint();
          }
        });
    jf.add(jp);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setSize(500, 400);
    jf.setVisible(true);
  }
Example #4
0
  /*
     El uso de este método estático es para inicializar el Canvas, su panel y
     otros componentes.
  */
  public static void initializeCanvas() {
    pastelements = null;
    futureelements = null;
    seleccionado = null;
    elements = new ArrayList<>();

    panel =
        new JPanel() {
          @Override
          public void paint(Graphics g) {
            super.paint(g);
            g.clearRect(0, 0, WIDTH, HEIGHT);
            for (int i = 0; i < elements.size(); i++) elements.get(i).paint(g);
          }
        };

    MouseAdapter ma =
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent me) {
            Canvas.mouseClicked(me);
          }

          @Override
          public void mouseMoved(MouseEvent me) {
            Canvas.mouseMoved(me);
          }
        };

    panel.addMouseListener(ma);
    panel.addMouseMotionListener(ma);
  }
Example #5
0
 /**
  * Kicseréli a rajzterület egér-eseménykezelőjét.
  *
  * @param newListener Az új egér-eseménykezelő.
  */
 public static void replaceGameAreaMouseListener(MouseInputListener newListener) {
   gameArea.removeMouseListener(gameAreaMouseListener);
   gameArea.removeMouseMotionListener(gameAreaMouseListener);
   gameAreaMouseListener = newListener;
   gameArea.addMouseListener(newListener);
   gameArea.addMouseMotionListener(newListener);
 }
Example #6
0
  /**
   * Sets up the event handler mechanics, including invoking the initGUIHandlers method, which would
   * be provided by the game developer using this framework, and would presumably be different for
   * each game.
   */
  private void initHandlers() {
    // SETUP THE LOW-LEVEL HANDLER WHO WILL
    // RELAY EVERYTHING
    MiniGameEventRelayer mger = new MiniGameEventRelayer(this);
    canvas.addMouseListener(mger);
    canvas.addMouseMotionListener(mger);
    window.setFocusable(true);
    window.addKeyListener(mger);
    canvas.addKeyListener(mger);

    // AND NOW LET THE GAME DEVELOPER PROVIDE
    // CUSTOM HANDLERS
    initGUIHandlers();
  }
Example #7
0
  public Exemplu2() {
    setTitle("Paint");
    setSize(500, 500);
    setLocationRelativeTo(null);

    panou = new JPanel();
    mb = new JMenuBar();
    menu = new JMenu("Color");
    mi1 = new JRadioButtonMenuItem("RED");
    mi2 = new JRadioButtonMenuItem("BLUE");
    mi3 = new JRadioButtonMenuItem("GREEN");
    bg = new ButtonGroup();

    setJMenuBar(mb);
    mb.add(menu);
    menu.add(mi1);
    menu.add(mi2);
    menu.add(mi3);

    bg.add(mi1);
    bg.add(mi2);
    bg.add(mi3);

    add(panou);

    panou.addMouseMotionListener(
        new MouseAdapter() {
          public void mouseDragged(MouseEvent ev) {
            int x = ev.getX();
            int y = ev.getY();

            Graphics g = panou.getGraphics();

            if (mi1.isSelected()) {
              g.setColor(Color.RED);
            }

            if (mi2.isSelected()) {
              g.setColor(Color.BLUE);
            }

            if (mi3.isSelected()) {
              g.setColor(Color.GREEN);
            }

            g.fillOval(x - 5, y - 5, 10, 10);
          }
        });
    setVisible(true);
  }
  // MouseTrackerFrame constructor sets up GUI and
  // registers mouse event handlers
  public MouseTrackerFrame() {
    super("Demonstrating Mouse Events");

    mousePanel = new JPanel(); // create panel
    mousePanel.setBackground(Color.WHITE); // set background color
    add(mousePanel, BorderLayout.CENTER); // add panel to JFrame

    statusBar = new JLabel("Mouse outside JPanel");
    add(statusBar, BorderLayout.SOUTH); // add label to JFrame

    // create and register listener for mouse and mouse motion events
    MouseHandler handler = new MouseHandler();
    mousePanel.addMouseListener(handler);
    mousePanel.addMouseMotionListener(handler);
  } // end MouseTrackerFrame constructor
Example #9
0
  public void init(Object parent) {

    glass = new BlurGlass();
    glass.setLayout(null);

    this.setLayout(null);

    setOpaque(false);
    // getContentPane().setOpaque(false);
    this.getLayeredPane().setOpaque(false);
    this.getRootPane().setOpaque(false);
    // putClientProperty("Synthetica.opaque", Boolean.FALSE);

    JParent = parent;
    glass.setOpaque(false);

    MouseInputAdapter adapter = new MouseInputAdapter() {};
    glass.addMouseListener(adapter);
    glass.addMouseMotionListener(adapter);

    try {
      if (parent instanceof JFrame) {
        layer = ((JFrame) parent).getLayeredPane();
      } else if (parent instanceof JInternalFrame) {
        layer = ((JInternalFrame) parent).getLayeredPane();
      }
      glass.setBounds(layer.getBounds());

    } catch (NullPointerException err) {
      Dialogos.error("Error interno en Dialogo interno modal", err);
    }

    try {
      glass.add(this);
      layer.add(glass, JLayeredPane.DEFAULT_LAYER);
    } catch (NullPointerException err) {
      Dialogos.error("Error interno en dialogo modal interno", err);
    }
  }
Example #10
0
  private void initZoomer(ImageIcon imgIcon) {

    _fullSizeImgIcon = imgIcon;

    this.setTitle(
        _titleBarStartTxt
            + ": Initial Size ("
            + imgIcon.getIconWidth()
            + "x"
            + imgIcon.getIconHeight()
            + "). Full size: "
            + imgIcon.getImage().getWidth(null)
            + "x"
            + imgIcon.getImage().getHeight(null)
            + ".");

    _panel = new JPanel();
    _panel.setBackground(Color.BLACK);
    _panel.setLayout(new BorderLayout());

    _label = new JLabel(_fullSizeImgIcon);
    _panel.add(_label, BorderLayout.CENTER);
    _mouseHandler = new ZoomMouseClickAndWheelListener();
    _panel.addMouseWheelListener(_mouseHandler);
    _panel.addMouseListener(_mouseHandler);
    _panel.addMouseMotionListener(_mouseHandler);

    // _panel.setSize(...

    // Make sure resources are deallocated
    // when window is closed:
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    _scrollPane = new JScrollPane(_panel);
    _scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    _scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    this.add(_scrollPane);

    ZoomAction zoomUpAction = new ZoomUpAction();
    ZoomAction zoomDownAction = new ZoomDownAction();
    WindowCloseAction winCloseAction = new Misc().new WindowCloseAction(this);

    Misc.bindKey(_panel, "control PLUS", zoomUpAction);
    Misc.bindKey(_panel, "control EQUALS", zoomUpAction);
    Misc.bindKey(_panel, "control shift EQUALS", zoomUpAction);

    Misc.bindKey(_panel, "control MINUS", zoomDownAction);
    Misc.bindKey(_panel, "control shift MINUS", zoomDownAction);

    Misc.bindKey(this, "control W", winCloseAction);
    Misc.bindKey(
        this,
        "F1",
        new ShowHelpAction("To do in Zoomer Window", "HelpFiles/zoomerHelp.html", this));

    // Center the window on the screen.
    this.setLocationRelativeTo(null);

    this.setVisible(true);
    pack();
    addWindowListener(new ZoomWindowListener());
    requestFocus();
  }
Example #11
0
  private void setBottomPanel() {

    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(new JSeparator(), BorderLayout.NORTH);

    boolean focusable = getFocusableWindowState();
    if (focusable) {
      SizeGrip sg = new SizeGrip();
      sg.applyComponentOrientation(sg.getComponentOrientation()); // Workaround
      panel.add(sg, BorderLayout.LINE_END);
      MouseInputAdapter adapter =
          new MouseInputAdapter() {
            private Point lastPoint;

            @Override
            public void mouseDragged(MouseEvent e) {
              Point p = e.getPoint();
              SwingUtilities.convertPointToScreen(p, panel);
              if (lastPoint == null) {
                lastPoint = p;
              } else {
                int dx = p.x - lastPoint.x;
                int dy = p.y - lastPoint.y;
                setLocation(getX() + dx, getY() + dy);
                lastPoint = p;
              }
            }

            @Override
            public void mousePressed(MouseEvent e) {
              lastPoint = e.getPoint();
              SwingUtilities.convertPointToScreen(lastPoint, panel);
            }
          };
      panel.addMouseListener(adapter);
      panel.addMouseMotionListener(adapter);
      // Don't add tipListener to the panel or SizeGrip
    } else {
      panel.setOpaque(false);
      JLabel label = new JLabel(FocusableTip.getString("FocusHotkey"));
      Color fg = UIManager.getColor("Label.disabledForeground");
      Font font = textArea.getFont();
      font = font.deriveFont(font.getSize2D() - 1.0f);
      label.setFont(font);
      if (fg == null) { // Non BasicLookAndFeel-derived Looks
        fg = Color.GRAY;
      }
      label.setOpaque(true);
      Color bg = TipUtil.getToolTipBackground();
      label.setBackground(bg);
      label.setForeground(fg);
      label.setHorizontalAlignment(SwingConstants.TRAILING);
      label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
      panel.add(label);
      panel.addMouseListener(tipListener);
    }

    // Replace the previous SOUTH Component with the new one.
    Container cp = getContentPane();
    if (cp.getComponentCount() == 2) { // Skip first time through
      Component comp = cp.getComponent(0);
      cp.remove(0);
      JScrollPane sp = new JScrollPane(comp);
      Border emptyBorder = BorderFactory.createEmptyBorder();
      sp.setBorder(emptyBorder);
      sp.setViewportBorder(emptyBorder);
      sp.setBackground(textArea.getBackground());
      sp.getViewport().setBackground(textArea.getBackground());
      cp.add(sp);
      // What was component 1 is now 0.
      cp.getComponent(0).removeMouseListener(tipListener);
      cp.remove(0);
    }

    cp.add(panel, BorderLayout.SOUTH);
  }
Example #12
0
  static void buildGUI() {
    // Need this size to balance axes.
    frame.setSize(520, 690);
    frame.setTitle("DrawTool");
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    Container cPane = frame.getContentPane();

    // Status label on top. Unused for now.
    statusLabel.setOpaque(true);
    statusLabel.setBackground(Color.white);
    cPane.add(statusLabel, BorderLayout.NORTH);

    // Build the input/output elements at the bottom.
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createLineBorder(Color.black));
    panel.setBackground(inputPanelColor);
    panel.setLayout(new GridLayout(2, 1));
    panel.add(outputLabel);
    JPanel bottomPanel = new JPanel();
    bottomPanel.setBackground(inputPanelColor);
    bottomPanel.add(inputField);
    bottomPanel.add(new JLabel("   "));
    JButton enterButton = new JButton("Enter");
    enterButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent a) {
            hasEntered = true;
          }
        });
    bottomPanel.add(enterButton);
    panel.add(bottomPanel);
    if (!sequencingOn) {
      cPane.add(panel, BorderLayout.SOUTH);
    }

    // Drawing in the center.
    drawArea = new DrawTool();
    if (sequencingOn) {
      frame.addKeyListener(
          new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
              handleKeyTyped(e);
            }
          });
    }
    cPane.add(drawArea, BorderLayout.CENTER);

    drawArea.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            handleMouseClick(e);
          }

          public void mouseReleased(MouseEvent e) {
            handleMouseReleased(e);
          }
        });

    drawArea.addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseDragged(MouseEvent e) {
            handleMouseDragged(e);
          }
        });
  }
  public void PostConstructor() {
    removeAll();
    setMinimumSize(new Dimension(60, 40));
    // setMaximumSize(new Dimension(Short.MAX_VALUE,
    //        Short.MAX_VALUE));
    setLocation(x, y);
    //        setFocusable(true);
    Titlebar = new JPanel();
    Titlebar.setLayout(new BoxLayout(Titlebar, BoxLayout.LINE_AXIS));
    Titlebar.setBackground(Color.getHSBColor(0.f, 0.0f, 0.6f));
    Titlebar.setMinimumSize(TitleBarMinimumSize);
    Titlebar.setMaximumSize(TitleBarMaximumSize);
    setBorder(BorderFactory.createLineBorder(Color.WHITE));
    setOpaque(true);
    resolveType();
    setVisible(true);
    //        revalidate();

    popup = new PopupMenu();

    ml =
        new MouseListener() {
          @Override
          public void mouseClicked(MouseEvent me) {
            if (patch != null) {
              if (me.getClickCount() == 1) {
                if (me.isShiftDown()) {
                  SetSelected(!GetSelected());
                  ((PatchGUI) patch).repaint();
                } else if (Selected == false) {
                  ((PatchGUI) patch).SelectNone();
                  SetSelected(true);
                  ((PatchGUI) patch).repaint();
                }
              }
              if (me.getClickCount() == 2) {
                ((PatchGUI) patch)
                    .ShowClassSelector(
                        AxoObjectInstanceAbstract.this.getLocation(),
                        AxoObjectInstanceAbstract.this,
                        null);
              }
            }
          }
          /*
          ClassSelector cs = ((PatchGUI)patch).cs;
          cs.setText(getType().id);
          //                        getParent().add(cs, 0);
          cs.setLocation(getLocation());
          //                        newObjTF.setSize(400,300);
          cs.setVisible(true);
          cs.requestFocus();
          * /
          }
          } else {
          for (AxoObjectInstanceAbstract o : patch.objectinstances) {
          o.SetSelected(false);
          }
          SetSelected(true);
          }
          //patch.invalidate();
          }*/

          @Override
          public void mousePressed(MouseEvent me) {
            if (me.isPopupTrigger()) {

            } else if (!IsLocked()) {
              dX = me.getXOnScreen() - getX();
              dY = me.getYOnScreen() - getY();
              dragging = true;
              if (IsSelected()) {
                for (AxoObjectInstanceAbstract o : patch.objectinstances) {
                  if (o.IsSelected()) {
                    o.dX = me.getXOnScreen() - o.getX();
                    o.dY = me.getYOnScreen() - o.getY();
                    o.dragging = true;
                  }
                }
              }
            }
          }

          @Override
          public void mouseReleased(MouseEvent me) {
            if (dragging) {
              dragging = false;
              if (patch != null) {
                for (AxoObjectInstanceAbstract o : patch.objectinstances) {
                  o.dragging = false;
                }
                patch.AdjustSize();
              }
            }
          }

          @Override
          public void mouseEntered(MouseEvent me) {}

          @Override
          public void mouseExited(MouseEvent me) {}
        };

    Titlebar.addMouseListener(ml);
    addMouseListener(ml);

    mml =
        new MouseMotionListener() {
          @Override
          public void mouseDragged(MouseEvent me) {
            if (patch != null) {
              if (dragging) {
                  /*
                  x = me.getLocationOnScreen().x - dX;
                  y = me.getLocationOnScreen().y - dY;
                  setLocation(x, y);
                  dX = me.getLocationOnScreen().x - getX();
                  dY = me.getLocationOnScreen().y - getY();*/

                for (AxoObjectInstanceAbstract o : patch.objectinstances) {
                  if (o.dragging) {
                    o.x = me.getLocationOnScreen().x - o.dX;
                    o.y = me.getLocationOnScreen().y - o.dY;
                    o.dX = me.getLocationOnScreen().x - o.getX();
                    o.dY = me.getLocationOnScreen().y - o.getY();
                    if (!me.isShiftDown()) {
                      o.x = ((o.x + (Constants.xgrid / 2)) / Constants.xgrid) * Constants.xgrid;
                      o.y = ((o.y + (Constants.ygrid / 2)) / Constants.ygrid) * Constants.ygrid;
                    }
                    o.setLocation(o.x, o.y);
                  }
                }
                // patch.invalidate();
                patch.repaint();
              }
            }
          }

          @Override
          public void mouseMoved(MouseEvent me) {}
        };

    Titlebar.addMouseMotionListener(mml);
    addMouseMotionListener(mml);
  }
  /** Builds the GUI. */
  private void buildGUI() {
    // We initialize our layout
    JPanel contentPane = (JPanel) getContentPane();
    layout = new GridBagLayout();
    contentPane.setLayout(layout);
    gbConstraints = new GridBagConstraints();
    gbConstraints.insets = new Insets(5, 5, 5, 5);

    // We prepare our action handler
    ActionsHandler handler = new ActionsHandler();

    // Prepares the glass pane to block gui interaction when needed
    JPanel glassPane = (JPanel) getGlassPane();
    glassPane.addMouseListener(new MouseAdapter() {});
    glassPane.addMouseMotionListener(new MouseMotionAdapter() {});
    glassPane.addKeyListener(new KeyAdapter() {});

    // We set-up the buttons factory
    ButtonFactory.useButtonIcons();
    ButtonFactory.useHighlightButtons();

    // We put our components

    warningLabel =
        new JLabel(
            langpack.getString("uninstaller.warning"),
            icons.getImageIcon("warning"),
            JLabel.TRAILING);
    buildConstraints(gbConstraints, 0, 0, 2, 1, 1.0, 0.0);
    gbConstraints.anchor = GridBagConstraints.WEST;
    gbConstraints.fill = GridBagConstraints.NONE;
    layout.addLayoutComponent(warningLabel, gbConstraints);
    contentPane.add(warningLabel);

    targetDestroyCheckbox =
        new JCheckBox(langpack.getString("uninstaller.destroytarget") + installPath, false);
    buildConstraints(gbConstraints, 0, 1, 2, 1, 1.0, 0.0);
    layout.addLayoutComponent(targetDestroyCheckbox, gbConstraints);
    contentPane.add(targetDestroyCheckbox);
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;

    progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    progressBar.setString(langpack.getString("InstallPanel.begin"));
    buildConstraints(gbConstraints, 0, 2, 2, 1, 1.0, 0.0);
    layout.addLayoutComponent(progressBar, gbConstraints);
    contentPane.add(progressBar);

    destroyButton =
        ButtonFactory.createButton(
            langpack.getString("uninstaller.uninstall"),
            icons.getImageIcon("delete"),
            buttonsHColor);
    destroyButton.addActionListener(handler);
    buildConstraints(gbConstraints, 0, 3, 1, 1, 0.5, 0.0);
    gbConstraints.fill = GridBagConstraints.NONE;
    gbConstraints.anchor = GridBagConstraints.WEST;
    layout.addLayoutComponent(destroyButton, gbConstraints);
    contentPane.add(destroyButton);

    quitButton =
        ButtonFactory.createButton(
            langpack.getString("installer.quit"), icons.getImageIcon("stop"), buttonsHColor);
    quitButton.addActionListener(handler);
    buildConstraints(gbConstraints, 1, 3, 1, 1, 0.5, 0.0);
    gbConstraints.anchor = GridBagConstraints.EAST;
    layout.addLayoutComponent(quitButton, gbConstraints);
    contentPane.add(quitButton);
  }
Example #15
0
  private void jbInit() throws Exception {
    int dw = Aut.getAut().getNumber(frmParam.getParam("sisfun", "datumHoriz"));
    int dh = Aut.getAut().getNumber(frmParam.getParam("sisfun", "datumVert"));
    br = new Rectangle();
    jp = new JPanel();
    month = new MonthPanel[12];
    setYear(-1);
    columns = Math.max(1, Math.min(4, dw));
    dh = Math.max(1, Math.min(4, dh));
    if (columns == 4 && dh == 4) dh = 3;

    jp.setPreferredSize(
        new Dimension(
            month[0].getPreferredSize().width + 10,
            (month[0].getPreferredSize().height + 5) * jp.getComponentCount() + 5));

    v =
        new JraScrollPane(
            JraScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JraScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    v.getViewport()
        .setMinimumSize(
            new Dimension(
                month[0].getPreferredSize().width + 10, month[0].getPreferredSize().height + 10));
    v.getViewport().setPreferredSize(v.getViewport().getMinimumSize());
    v.setViewportView(jp);

    Dimension ps = v.getViewport().getMinimumSize();
    Dimension ns = new Dimension(columns * (ps.width - 5) + 5, dh * (ps.height - 5) + 5);

    setPreferredPanelSize();
    v.getViewport().setPreferredSize(ns);

    v.addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            ensureProperViewSize();
          }
        });

    jp.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            // System.out.println("mouseclick "+e);
            if ((e.getModifiers() & e.BUTTON1_MASK) != 0) mouseClick(e);
          }

          public void mousePressed(MouseEvent e) {
            // System.out.println("mousepress "+e);
            if ((e.getModifiers() & e.BUTTON1_MASK) != 0) mousePress(e);
            if (e.getModifiers() == e.BUTTON3_MASK) {
              if (scroll) {
                scroll = false;
                scroller.stop();
              }
              setSelection(null, null);
              jp.repaint();
            }
          }

          public void mouseReleased(MouseEvent e) {
            if ((e.getModifiers() & e.BUTTON1_MASK) != 0) {
              if (scroll) {
                scroll = false;
                scroller.stop();
              }
              if (first != null && last != null) setResultRange();
            }
          }
        });
    jp.addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseDragged(MouseEvent e) {
            if ((e.getModifiers() & e.BUTTON1_MASK) != 0) mouseDrag(e);
          }
        });
    scroller =
        new javax.swing.Timer(
            30,
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                if (scroll && speed != 0) scrollView();
              }
            });
  }
  public JavaMouse(JPanel panel) {
    panel.addMouseListener(
        new java.awt.event.MouseAdapter() {
          @Override
          public void mousePressed(java.awt.event.MouseEvent e) {
            buttons[e.getButton() - 1] = true;
            MouseEvent event = createEvent(e, true);
            for (MouseListener listener : listeners) {
              listener.mouseButtonPressed(event);
            }
          }

          @Override
          public void mouseReleased(java.awt.event.MouseEvent e) {
            buttons[e.getButton() - 1] = false;
            MouseEvent event = createEvent(e, false);
            for (MouseListener listener : listeners) {
              listener.mouseButtonReleased(event);
            }
          }

          @Override
          public void mouseClicked(java.awt.event.MouseEvent e) {
            MouseEvent event = createEvent(e, false);
            for (MouseListener listener : listeners) {
              listener.mouseButtonClicked(event);
            }
          }
        });
    panel.addMouseMotionListener(
        new MouseMotionListener() {
          @Override
          public void mouseMoved(java.awt.event.MouseEvent e) {
            x = e.getX();
            y = e.getY();
            MouseEvent event = createEvent(e, false);
            for (MouseListener listener : listeners) {
              listener.mouseMoved(event);
            }
          }

          @Override
          public void mouseDragged(java.awt.event.MouseEvent e) {
            x = e.getX();
            y = e.getY();
            MouseEvent event = createEvent(e, true);
            for (MouseListener listener : listeners) {
              listener.mouseDragged(event);
            }
          }
        });
    panel.addMouseWheelListener(
        new MouseWheelListener() {
          @Override
          public void mouseWheelMoved(java.awt.event.MouseWheelEvent e) {
            scroll += e.getPreciseWheelRotation();
            MouseWheelEvent event =
                new MouseWheelEvent(
                    e.getPreciseWheelRotation(), e.getX(), e.getY(), JavaUtil.getEventMods(e));
            for (MouseListener listener : listeners) {
              listener.mouseScrolled(event);
            }
          }
        });
  }
Example #17
0
  public OheEditor(OheDialogPanel oheDialogPanel) {
    dialog = oheDialogPanel;

    // the MainPanel for showing the TimeRects
    contentPanel =
        new JPanel() {
          @Override
          public void setSize(Dimension d) {
            super.setSize(d);
            repositionTimeRects();
          }

          @Override
          public void paintComponent(Graphics g) {
            if (OheEditor.this.isEnabled()) {
              g.setColor(Color.WHITE);
              g.fillRect(0, 0, getWidth(), getHeight());

              // draw the time from 12PM to 00AM in a different color
              if (dialog.getHourMode() == ClockSystem.TWELVE_HOURS) {
                g.setColor(new Color(255, 255, 218));
                g.fillRect(
                    0,
                    getMinutePosition(12 * 60),
                    getWidth(),
                    getHeight() - getMinutePosition(12 * 60));
              }

              // horizontal Lines
              for (int i = 0; i <= 24; ++i) {
                if (i % 3 == 0) {
                  g.setColor(Color.BLACK);
                } else {
                  g.setColor(Color.LIGHT_GRAY);
                }

                g.drawLine(0, getMinutePosition(i * 60), getWidth(), getMinutePosition(i * 60));
              }

              // vertical Lines
              g.setColor(Color.BLACK);
              for (int i = 0; i <= 7; ++i) {
                g.drawLine(getDayPosition(i), 0, getDayPosition(i), getHeight());
              }

              // if a new Rect is dragged draw it
              if (day0 >= 0) {
                Graphics2D g2D = (Graphics2D) g;

                int day2 = Math.min(day0, day1);
                int day3 = Math.max(day0, day1);
                int minute2 = Math.min(minute0, minute1);
                int minute3 = Math.max(minute0, minute1);
                Rectangle bounds = getPanelBoundsForTimeinterval(day2, day3 + 1, minute2, minute3);

                TimeRect.drawTimeRect(g2D, bounds, minute2 == minute3, false);
              }
            } else {
              g.setColor(Color.LIGHT_GRAY);
              g.fillRect(0, 0, getWidth(), getHeight());
            }
          }
        };
    contentPanel.addMouseListener(this);
    contentPanel.addMouseMotionListener(this);
    contentPanel.setLayout(null);
    contentPanel.setPreferredSize(new Dimension(180, 384));

    initTimeRects();

    scrollPane =
        new JScrollPane(
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setViewportView(contentPanel);

    // the upper Panel for showing Weekdays
    scrollPane.setColumnHeaderView(
        new JPanel() {
          @Override
          public Dimension getPreferredSize() {
            return new Dimension(contentPanel.getWidth(), dayAxisHeight);
          }

          @Override
          public void paintComponent(Graphics g) {
            g.setColor(Color.WHITE);
            g.fillRect(0, 0, getWidth(), getHeight());

            g.setColor(Color.BLACK);
            for (int i = 0; i < 7; ++i) {
              if (i > 0) {
                g.drawLine(getDayPosition(i), 0, getDayPosition(i), getHeight());
              }

              String text = OpeningTimeCompiler.WEEKDAYS[i];
              g.drawString(
                  text,
                  (int) (getDayPosition(i + 0.5) - g.getFontMetrics().stringWidth(text) * 0.5),
                  (int) (dayAxisHeight * 0.5 + g.getFontMetrics().getHeight() * 0.35));
            }
          }
        });

    // the left Panel for showing the hours
    scrollPane.setRowHeaderView(
        new JPanel() {
          @Override
          public Dimension getPreferredSize() {
            return new Dimension(timeAxisWidth, contentPanel.getHeight());
          }

          @Override
          public void paintComponent(Graphics g) {
            g.setColor(Color.WHITE);
            g.fillRect(0, 0, getWidth(), getHeight());

            // draw the time from 12PM to 00AM in a different color
            if (dialog.getHourMode() == ClockSystem.TWELVE_HOURS) {
              g.setColor(new Color(255, 255, 218));
              g.fillRect(
                  0,
                  getMinutePosition(12 * 60),
                  getWidth(),
                  getHeight() - getMinutePosition(12 * 60));
            }

            for (int i = 0; i <= 24; ++i) {
              if (i % 3 == 0) {
                g.setColor(Color.BLACK);
                if (i % 24 != 0) {
                  String text = OpeningTimeUtils.timeString(i * 60, dialog.getHourMode(), false);
                  g.drawString(
                      text,
                      (timeAxisWidth - g.getFontMetrics().stringWidth(text)) / 2,
                      getMinutePosition(i * 60) + (int) (g.getFontMetrics().getHeight() * 0.35));
                }
              } else {
                g.setColor(Color.LIGHT_GRAY);
              }

              g.drawLine(
                  getWidth() - 4, getMinutePosition(i * 60), getWidth(), getMinutePosition(i * 60));
            }

            g.setColor(Color.BLACK);
            String text = OpeningTimeUtils.timeString(0, dialog.getHourMode(), false);
            g.drawString(
                text,
                (timeAxisWidth - g.getFontMetrics().stringWidth(text)) / 2,
                getMinutePosition(0) + (int) (g.getFontMetrics().getHeight() * 1.0));
            if (dialog.getHourMode() == ClockSystem.TWELVE_HOURS) {
              text = "AM";
              g.drawString(
                  text,
                  (timeAxisWidth - g.getFontMetrics().stringWidth(text)) / 2,
                  getMinutePosition(0) + (int) (g.getFontMetrics().getHeight() * 1.85));
              text = "PM";
              g.drawString(
                  text,
                  (timeAxisWidth - g.getFontMetrics().stringWidth(text)) / 2,
                  getMinutePosition(12 * 60) + (int) (g.getFontMetrics().getHeight() * 1.2));
            }
          }
        });

    setLayout(new BorderLayout());
    add(scrollPane, BorderLayout.CENTER);
  }
Example #18
0
  /**
   * Constructor PlacementPicker(java.lang.String)
   *
   * <p>Setus up all GUI components, initializes variables with default or needed values, and
   * prepares the map for user commands.
   *
   * @param java .lang.String mapName name of map file
   */
  public PlacementPicker(final String mapName) {
    super("Placement Picker");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    if (!placeDimensionsSet) {
      try {
        File file = null;
        if (s_mapFolderLocation != null && s_mapFolderLocation.exists())
          file = new File(s_mapFolderLocation, "map.properties");
        if (file == null || !file.exists())
          file = new File(new File(mapName).getParent() + File.separator + "map.properties");
        if (file.exists()) {
          double scale = unit_zoom_percent;
          int width = unit_width;
          int height = unit_height;
          boolean found = false;
          final String scaleProperty = MapData.PROPERTY_UNITS_SCALE + "=";
          final String widthProperty = MapData.PROPERTY_UNITS_WIDTH + "=";
          final String heightProperty = MapData.PROPERTY_UNITS_HEIGHT + "=";

          final FileReader reader = new FileReader(file);
          final LineNumberReader reader2 = new LineNumberReader(reader);
          int i = 0;
          while (true) {
            reader2.setLineNumber(i);
            final String line = reader2.readLine();
            if (line == null) break;
            if (line.contains(scaleProperty)) {
              try {
                scale =
                    Double.parseDouble(
                        line.substring(line.indexOf(scaleProperty) + scaleProperty.length())
                            .trim());
                found = true;
              } catch (final NumberFormatException ex) {
              }
            }
            if (line.contains(widthProperty)) {
              try {
                width =
                    Integer.parseInt(
                        line.substring(line.indexOf(widthProperty) + widthProperty.length())
                            .trim());
                found = true;
              } catch (final NumberFormatException ex) {
              }
            }
            if (line.contains(heightProperty)) {
              try {
                height =
                    Integer.parseInt(
                        line.substring(line.indexOf(heightProperty) + heightProperty.length())
                            .trim());
                found = true;
              } catch (final NumberFormatException ex) {
              }
            }
          }
          reader2.close();
          i++;
          if (found) {
            final int result =
                JOptionPane.showConfirmDialog(
                    new JPanel(),
                    "A map.properties file was found in the map's folder, "
                        + "\r\n do you want to use the file to supply the info for the placement box size? "
                        + "\r\n Zoom = "
                        + scale
                        + ",  Width = "
                        + width
                        + ",  Height = "
                        + height
                        + ",    Result = ("
                        + ((int) (scale * width))
                        + "x"
                        + ((int) (scale * height))
                        + ")",
                    "File Suggestion",
                    1);
            // if (result == 2)
            // return;
            if (result == 0) {
              unit_zoom_percent = scale;
              PLACEWIDTH = (int) (unit_zoom_percent * width);
              PLACEHEIGHT = (int) (unit_zoom_percent * height);
              placeDimensionsSet = true;
            }
          }
        }
      } catch (final Exception ex) {
      }
    }
    if (!placeDimensionsSet
        || JOptionPane.showConfirmDialog(
                new JPanel(),
                "Placement Box Size already set ("
                    + PLACEWIDTH
                    + "x"
                    + PLACEHEIGHT
                    + "), "
                    + "do you wish to continue with this?\r\nSelect Yes to continue, Select No to override and change the size.",
                "Placement Box Size",
                JOptionPane.YES_NO_OPTION)
            == 1) {
      try {
        final String result = getUnitsScale();
        try {
          unit_zoom_percent = Double.parseDouble(result.toLowerCase());
        } catch (final NumberFormatException ex) {
        }
        final String width =
            JOptionPane.showInputDialog(
                null,
                "Enter the unit's image width in pixels (unscaled / without zoom).\r\n(e.g. 48)");
        if (width != null) {
          try {
            PLACEWIDTH = (int) (unit_zoom_percent * Integer.parseInt(width));
          } catch (final NumberFormatException ex) {
          }
        }
        final String height =
            JOptionPane.showInputDialog(
                null,
                "Enter the unit's image height in pixels (unscaled / without zoom).\r\n(e.g. 48)");
        if (height != null) {
          try {
            PLACEHEIGHT = (int) (unit_zoom_percent * Integer.parseInt(height));
          } catch (final NumberFormatException ex) {
          }
        }
        placeDimensionsSet = true;
      } catch (final Exception ex) {
      }
    }

    File file = null;
    if (s_mapFolderLocation != null && s_mapFolderLocation.exists())
      file = new File(s_mapFolderLocation, "polygons.txt");
    if (file == null || !file.exists())
      file = new File(new File(mapName).getParent() + File.separator + "polygons.txt");
    if (file.exists()
        && JOptionPane.showConfirmDialog(
                new JPanel(),
                "A polygons.txt file was found in the map's folder, do you want to use the file to supply the territories?",
                "File Suggestion",
                1)
            == 0) {
      try {
        System.out.println("Polygons : " + file.getPath());
        m_polygons =
            PointFileReaderWriter.readOneToManyPolygons(new FileInputStream(file.getPath()));
      } catch (final IOException ex1) {
        ex1.printStackTrace();
      }
    } else {
      try {
        System.out.println("Select the Polygons file");
        final String polyPath =
            new FileOpen("Select A Polygon File", s_mapFolderLocation, ".txt").getPathString();
        if (polyPath != null) {
          System.out.println("Polygons : " + polyPath);
          m_polygons = PointFileReaderWriter.readOneToManyPolygons(new FileInputStream(polyPath));
        } else {
          System.out.println("Polygons file not given. Will run regardless");
        }
      } catch (final IOException ex1) {
        ex1.printStackTrace();
      }
    }
    createImage(mapName);
    final JPanel imagePanel = createMainPanel();
    /*
    Add a mouse listener to show
    X : Y coordinates on the lower
    left corner of the screen.
    */
    imagePanel.addMouseMotionListener(
        new MouseMotionAdapter() {
          @Override
          public void mouseMoved(final MouseEvent e) {
            m_location.setText("x:" + e.getX() + " y:" + e.getY());
            m_currentSquare = new Point(e.getPoint());
            repaint();
          }
        });
    /*
       Add a mouse listener to monitor
    for right mouse button being
    clicked.
    */
    imagePanel.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(final MouseEvent e) {
            mouseEvent(
                e.getPoint(),
                e.isControlDown() || e.isShiftDown(),
                SwingUtilities.isRightMouseButton(e));
          }
        });
    // set up the image panel size dimensions ...etc
    imagePanel.setMinimumSize(new Dimension(m_image.getWidth(this), m_image.getHeight(this)));
    imagePanel.setPreferredSize(new Dimension(m_image.getWidth(this), m_image.getHeight(this)));
    imagePanel.setMaximumSize(new Dimension(m_image.getWidth(this), m_image.getHeight(this)));
    // set up the layout manager
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(new JScrollPane(imagePanel), BorderLayout.CENTER);
    this.getContentPane().add(m_location, BorderLayout.SOUTH);
    // set up the actions
    final Action openAction =
        new AbstractAction("Load Placements") {
          private static final long serialVersionUID = -2894085191455411106L;

          public void actionPerformed(final ActionEvent event) {
            loadPlacements();
          }
        };
    openAction.putValue(Action.SHORT_DESCRIPTION, "Load An Existing Placement File");
    final Action saveAction =
        new AbstractAction("Save Placements") {
          private static final long serialVersionUID = -3341738809601318716L;

          public void actionPerformed(final ActionEvent event) {
            savePlacements();
          }
        };
    saveAction.putValue(Action.SHORT_DESCRIPTION, "Save The Placements To File");
    final Action exitAction =
        new AbstractAction("Exit") {
          private static final long serialVersionUID = -9093426903644867897L;

          public void actionPerformed(final ActionEvent event) {
            System.exit(0);
          }
        };
    exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit The Program");
    // set up the menu items
    final JMenuItem openItem = new JMenuItem(openAction);
    openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
    final JMenuItem saveItem = new JMenuItem(saveAction);
    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
    final JMenuItem exitItem = new JMenuItem(exitAction);
    // set up the menu bar
    final JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    final JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic('F');
    fileMenu.add(openItem);
    fileMenu.add(saveItem);
    fileMenu.addSeparator();
    fileMenu.add(exitItem);
    s_showAllMode = false;
    s_showOverflowMode = false;
    s_showIncompleteMode = false;
    s_incompleteNum = 1;
    showAllModeItem = new JCheckBoxMenuItem("Show All Placements Mode", false);
    showAllModeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent event) {
            s_showAllMode = showAllModeItem.getState();
            repaint();
          }
        });
    showOverflowModeItem = new JCheckBoxMenuItem("Show Overflow Mode", false);
    showOverflowModeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent event) {
            s_showOverflowMode = showOverflowModeItem.getState();
            repaint();
          }
        });
    showIncompleteModeItem = new JCheckBoxMenuItem("Show Incomplete Placements Mode", false);
    showIncompleteModeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent event) {
            if (showIncompleteModeItem.getState()) {
              final String num =
                  JOptionPane.showInputDialog(
                      null,
                      "Enter the minimum number of placements each territory must have.\r\n(examples: 1, 4, etc.)");
              try {
                s_incompleteNum = Math.max(1, Math.min(50, Integer.parseInt(num)));
              } catch (final Exception ex) {
                s_incompleteNum = 1;
              }
            }
            s_showIncompleteMode = showIncompleteModeItem.getState();
            repaint();
          }
        });
    final JMenu editMenu = new JMenu("Edit");
    editMenu.setMnemonic('E');
    editMenu.add(showAllModeItem);
    editMenu.add(showOverflowModeItem);
    editMenu.add(showIncompleteModeItem);
    menuBar.add(fileMenu);
    menuBar.add(editMenu);
  } // end constructor
Example #19
0
  /**
   * Constructor CenterPicker(java.lang.String) Setus up all GUI components, initializes variables
   * with default or needed values, and prepares the map for user commands.
   *
   * @param java .lang.String mapName name of map file
   */
  public CenterPicker(final String mapName) {
    super("Center Picker");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    File file = null;
    if (s_mapFolderLocation != null && s_mapFolderLocation.exists()) {
      file = new File(s_mapFolderLocation, "polygons.txt");
    }
    if (file == null || !file.exists()) {
      file = new File(new File(mapName).getParent() + File.separator + "polygons.txt");
    }
    if (file.exists()
        && JOptionPane.showConfirmDialog(
                new JPanel(),
                "A polygons.txt file was found in the map's folder, do you want to use the file to supply the territories names?",
                "File Suggestion",
                1)
            == 0) {
      try {
        m_polygons =
            PointFileReaderWriter.readOneToManyPolygons(new FileInputStream(file.getPath()));
      } catch (final IOException ex1) {
        System.out.println("Something wrong with your Polygons file: " + ex1);
        ex1.printStackTrace();
      }
    } else {
      try {
        final String polyPath =
            new FileOpen("Select A Polygon File", s_mapFolderLocation, ".txt").getPathString();
        if (polyPath != null) {
          m_polygons = PointFileReaderWriter.readOneToManyPolygons(new FileInputStream(polyPath));
        }
      } catch (final IOException ex1) {
        System.out.println("Something wrong with your Polygons file: " + ex1);
        ex1.printStackTrace();
      }
    }
    createImage(mapName);
    final JPanel imagePanel = createMainPanel();
    /*
     * Add a mouse listener to show
     * X : Y coordinates on the lower
     * left corner of the screen.
     */
    imagePanel.addMouseMotionListener(
        new MouseMotionAdapter() {
          @Override
          public void mouseMoved(final MouseEvent e) {
            m_location.setText("x:" + e.getX() + " y:" + e.getY());
          }
        });
    // Add a mouse listener to monitor for right mouse button being clicked.
    imagePanel.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(final MouseEvent e) {
            mouseEvent(e.getPoint(), SwingUtilities.isRightMouseButton(e));
          }
        });
    // set up the image panel size dimensions ...etc
    imagePanel.setMinimumSize(new Dimension(m_image.getWidth(this), m_image.getHeight(this)));
    imagePanel.setPreferredSize(new Dimension(m_image.getWidth(this), m_image.getHeight(this)));
    imagePanel.setMaximumSize(new Dimension(m_image.getWidth(this), m_image.getHeight(this)));
    // set up the layout manager
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(new JScrollPane(imagePanel), BorderLayout.CENTER);
    this.getContentPane().add(m_location, BorderLayout.SOUTH);
    // set up the actions
    final Action openAction =
        new AbstractAction("Load Centers") {
          private static final long serialVersionUID = 2712234474452114083L;

          @Override
          public void actionPerformed(final ActionEvent event) {
            loadCenters();
          }
        };
    openAction.putValue(Action.SHORT_DESCRIPTION, "Load An Existing Center Points File");
    final Action saveAction =
        new AbstractAction("Save Centers") {
          private static final long serialVersionUID = -4519036149978621171L;

          @Override
          public void actionPerformed(final ActionEvent event) {
            saveCenters();
          }
        };
    saveAction.putValue(Action.SHORT_DESCRIPTION, "Save The Center Points To File");
    final Action exitAction =
        new AbstractAction("Exit") {
          private static final long serialVersionUID = -5631457890653630218L;

          @Override
          public void actionPerformed(final ActionEvent event) {
            System.exit(0);
          }
        };
    exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit The Program");
    // set up the menu items
    final JMenuItem openItem = new JMenuItem(openAction);
    openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
    final JMenuItem saveItem = new JMenuItem(saveAction);
    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
    final JMenuItem exitItem = new JMenuItem(exitAction);
    // set up the menu bar
    final JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    final JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic('F');
    fileMenu.add(openItem);
    fileMenu.add(saveItem);
    fileMenu.addSeparator();
    fileMenu.add(exitItem);
    menuBar.add(fileMenu);
  } // end constructor
Example #20
0
  public void makeFrame() throws IOException {

    panel =
        new JPanel() {
          public void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D) g;
            g2.setColor(Color.RED);
            if (bufImage == null) {
              int w = this.getWidth();
              int h = this.getHeight();
              bufImage = new BufferedImage(800, 500, BufferedImage.TRANSLUCENT);
              Graphics2D gc = bufImage.createGraphics();
            }

            g2.drawImage(bufImage, null, 0, 0);
            if (state == State.DRAGGING) {
              g2.drawLine(start.x, start.y, end.x, end.y);
            }
          }

          public Dimension getPreferredSize() {
            return new Dimension(1300, 800);
          }
        };

    panel.addMouseListener(
        new MouseListener() {
          @Override
          public void mouseClicked(MouseEvent e) {

            x = e.getX();
            y = e.getY();
            label = new JLabel();

            String name = JOptionPane.showInputDialog("Enter the name of City");

            if (name.equals("Jodhpur")) {
              ImageIcon img = new ImageIcon("jodhpur.jpg");
              label.setIcon(img);
            } else if (name.equals("Pali")) {
              ImageIcon img = new ImageIcon("pali.jpg");
              label.setIcon(img);

            } else if (name.equals("Mahendipur Balajee")) {
              ImageIcon img = new ImageIcon("Mahendipur Balijee.jpg");
              label.setIcon(img);

            } else if (name.equals("Nadoti")) {
              ImageIcon img = new ImageIcon("Nadoti.jpg");
              label.setIcon(img);
            } else if (name.equals("Jaipur")) {
              ImageIcon img = new ImageIcon("jaipur.jpg");
              label.setIcon(img);
            } else if (name.equals("Ratanada Headoffice")) {
              ImageIcon img = new ImageIcon("Ratanada.jpg");
              label.setIcon(img);
            } else {
              ImageIcon img = new ImageIcon("Other.jpg");
              label.setIcon(img);
            }

            label.setLayout(new BorderLayout());
            panel.add(label);

            label.setBounds(x, y, 65, 60);
            label.setToolTipText(name);
          }

          @Override
          public void mousePressed(MouseEvent me) {}

          @Override
          public void mouseReleased(MouseEvent me) {

            state = State.IDLE;
          }

          @Override
          public void mouseEntered(MouseEvent me) {}

          @Override
          public void mouseExited(MouseEvent me) {}
        });

    panel.addMouseMotionListener(
        new MouseMotionListener() {

          @Override
          public void mouseDragged(MouseEvent me) {
            state = State.DRAGGING;
            end = me.getPoint();
            if (state == State.DRAGGING) {
              Graphics2D g2 = bufImage.createGraphics();
              g2.setColor(Color.red);
              g2.setStroke(new BasicStroke(2));
              g2.drawLine(start.x, start.y, end.x, end.y);
              panel.repaint();
            }
            start = end;
          }

          @Override
          public void mouseMoved(MouseEvent me) {

            start = me.getPoint();
          }
        });

    panel.setOpaque(true);
    // ^ out.close();
  }
Example #21
0
  /**
   * Constructor for setting up the status area
   *
   * @param mainFrame reference to the mainframe
   */
  public StatusArea(MainFrame mainFrame) {

    // Setup location
    this.setLocation(10 + moveHandlerHeight, 80 + mainFrame.getToolbar().getHeight());
    this.setVisible(true);
    this.setResizable(false);

    // Strip off window looks
    setRootPaneCheckingEnabled(false);
    ((javax.swing.plaf.basic.BasicInternalFrameUI) this.getUI()).setNorthPane(null);
    this.setBorder(null);

    // Create the top movehandler (for dragging)
    moveHandler = new JPanel(new BorderLayout());
    moveHandler.add(new JLabel("Status", SwingConstants.CENTER), BorderLayout.CENTER);

    moveHandler.setForeground(new Color(200, 200, 200));
    moveHandler.setOpaque(true);
    moveHandler.setBackground(Color.DARK_GRAY);
    moveHandler.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(30, 30, 30)));
    moveHandler.setFont(new Font("Arial", Font.BOLD, 9));
    moveHandler.setPreferredSize(new Dimension(statusItemWidth, moveHandlerHeight));
    ToolbarMoveMouseListener mml = new ToolbarMoveMouseListener(this, mainFrame);
    moveHandler.addMouseListener(mml);
    moveHandler.addMouseMotionListener(mml);

    JLabel close = new JLabel(EPDShore.res().getCachedImageIcon("images/window/close.png"));
    close.addMouseListener(
        new MouseAdapter() {
          public void mouseReleased(MouseEvent e) {
            setVisible(false);
          }
        });
    close.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    moveHandler.add(close, BorderLayout.EAST);

    // Create the grid for the status items
    statusPanel = new JPanel();
    statusPanel.setLayout(new GridLayout(0, 1));
    statusPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 0));
    statusPanel.setBackground(new Color(83, 83, 83));

    // Add status items here
    // Status: X coordinate
    statusItems.put("LAT", new JLabel(" LAT: N/A"));

    // Status: Y coordinate
    statusItems.put("LON", new JLabel(" LON: N/A"));

    // Create the grid for the highlighted ship info area
    highlightPanel = new JPanel();
    highlightPanel.setLayout(new GridLayout(0, 1));
    highlightPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 0));
    highlightPanel.setBackground(new Color(83, 83, 83));

    // Create the masterpanel for aligning
    masterPanel = new JPanel(new BorderLayout());
    masterPanel.add(moveHandler, BorderLayout.NORTH);
    masterPanel.add(statusPanel, BorderLayout.CENTER);
    masterPanel.add(highlightPanel, BorderLayout.SOUTH);
    masterPanel.setBorder(
        BorderFactory.createEtchedBorder(
            EtchedBorder.LOWERED, new Color(30, 30, 30), new Color(45, 45, 45)));
    this.getContentPane().add(masterPanel);

    // And finally refresh the status bar
    repaintToolbar();
  }