예제 #1
1
  protected void resizeDesktop() {
    int x = 0;
    int y = 0;
    JScrollPane scrollPane = getScrollPane();
    Insets scrollInsets = getScrollPaneInsets();

    if (scrollPane != null) {
      JInternalFrame allFrames[] = desktop.getAllFrames();
      for (int i = 0; i < allFrames.length; i++) {
        if (allFrames[i].getX() + allFrames[i].getWidth() > x) {
          x = allFrames[i].getX() + allFrames[i].getWidth();
        }
        if (allFrames[i].getY() + allFrames[i].getHeight() > y) {
          y = allFrames[i].getY() + allFrames[i].getHeight();
        }
      }
      Dimension d = scrollPane.getVisibleRect().getSize();
      if (scrollPane.getBorder() != null) {
        d.setSize(
            d.getWidth() - scrollInsets.left - scrollInsets.right,
            d.getHeight() - scrollInsets.top - scrollInsets.bottom);
      }

      if (x <= d.getWidth()) {
        x = ((int) d.getWidth()) - 20;
      }
      if (y <= d.getHeight()) {
        y = ((int) d.getHeight()) - 20;
      }
      desktop.setAllSize(x, y);
      scrollPane.invalidate();
      scrollPane.validate();
    }
  }
예제 #2
0
  public PleaseWaitFrame() throws HeadlessException {

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int locationX = (int) (screenSize.getWidth() - FRAME_SIZE.getWidth()) / 2;
    int locationY = (int) (screenSize.getHeight() - FRAME_SIZE.getHeight()) / 2;
    this.setSize(FRAME_SIZE);
    this.setLocation(locationX, locationY);
    this.setUndecorated(true);
    this.setResizable(false);
    JPanel panel = new JPanel();

    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = new Insets(0, 0, 0, 0);
    gbc.fill = GridBagConstraints.CENTER;
    panel.setLayout(gbl);
    messageLabel = new JLabel(message);
    messageLabel.setFont(new Font(null, Font.BOLD, 25));
    panel.add(messageLabel, gbc);

    Border border = new LineBorder(Color.BLACK, 1);

    panel.setSize(FRAME_SIZE);

    panel.setBorder(border);

    this.setContentPane(panel);

    // super.setVisible(true);
    super.setVisible(false);
  }
예제 #3
0
  private void computeWorkersSizes(Dimension panelDimensions) {

    // check when the column of of workers start
    double startWorkerColumn = 8d * panelDimensions.getWidth() / 9d;

    double workerColumnWidth = panelDimensions.getWidth() - startWorkerColumn;
    workerXStart = startWorkerColumn + workerColumnWidth / 5d;
    workerXEnd = panelDimensions.getWidth() - workerColumnWidth / 5d;
    workerFirstY = panelDimensions.getHeight() / 9d;
    workerLastY = 8d * panelDimensions.getHeight() / 9d;
    workerHeight = (workerLastY - workerFirstY) / new Double(Market.numberOfWorkers);
    assert workerXStart > 0;
    assert workerXEnd > 0;
    assert workerFirstY > 0;
    assert workerLastY > 0;
    assert workerHeight > 0;

    int index = 0;
    for (Consumer x : SleepStoneTest.market.getLabor().workers) {
      Rectangle rectangle =
          new Rectangle(
              (int) workerXStart,
              (int) (workerFirstY + index * workerHeight),
              (int) (workerXEnd - workerXStart),
              (int) workerHeight);
      tradersPlace.put(x, new Point((int) rectangle.getCenterX(), (int) rectangle.getCenterY()));
      consumerPlace.put(x, rectangle);
      index++;
    }
  }
  private void setSizeAndDimensions(
      @NotNull JTable table,
      @NotNull JBPopup popup,
      @NotNull RelativePoint popupPosition,
      @NotNull List<UsageNode> data) {
    JComponent content = popup.getContent();
    Window window = SwingUtilities.windowForComponent(content);
    Dimension d = window.getSize();

    int width = calcMaxWidth(table);
    width = (int) Math.max(d.getWidth(), width);
    Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize();
    width = Math.max((int) headerSize.getWidth(), width);
    width = Math.max(myWidth, width);

    if (myWidth == -1) myWidth = width;
    int newWidth = Math.max(width, d.width + width - myWidth);

    myWidth = newWidth;

    int rowsToShow = Math.min(30, data.size());
    Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
    Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
    dimension = rectangle.getSize();
    Point location = window.getLocation();
    if (!location.equals(rectangle.getLocation())) {
      window.setLocation(rectangle.getLocation());
    }

    if (!data.isEmpty()) {
      TableScrollingUtil.ensureSelectionExists(table);
    }
    table.setSize(dimension);
    // table.setPreferredSize(dimension);
    // table.setMaximumSize(dimension);
    // table.setPreferredScrollableViewportSize(dimension);

    Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize();

    int newHeight =
        (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight())
            + 4 /* invisible borders, margins etc*/;
    Dimension newDim = new Dimension(dimension.width, newHeight);
    window.setSize(newDim);
    window.setMinimumSize(newDim);
    window.setMaximumSize(newDim);

    window.validate();
    window.repaint();
    table.revalidate();
    table.repaint();
  }
예제 #5
0
파일: Ladder.java 프로젝트: yblee/Ladder
  Ladder(String title) {
    super(title);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(170, 130);

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    frameSize = getSize();
    setLocation(
        (int) (screen.getWidth() / 2 - frameSize.getWidth() / 2),
        (int) (screen.getHeight() / 2 - frameSize.getHeight() / 2));

    con = getContentPane();
  }
예제 #6
0
  /** Creates new form RaceMenu1 */
  public RaceMenu() {
    RACENUM = 6;
    initComponents();
    OKButton.setEnabled(false);
    DescriptionContainer.setViewportView(DescriptionText);

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    if ((screenSize.getWidth() > getContentPane().getWidth())
        && (screenSize.getHeight() > getContentPane().getHeight())) {
      int intwidth =
          new Double(((screenSize.getWidth() - getContentPane().getWidth()) / 2)).intValue();
      int intheight =
          new Double(((screenSize.getHeight() - getContentPane().getHeight()) / 2)).intValue();
      setLocation(intwidth, intheight);
    } else {
      setLocation(0, 0);
    }

    menucreate = TLKFactory.getCreateMenu();
    menucreate.BlockWindow(true);
    TLKFAC = menucreate.getTLKFactory();
    RESFAC = menucreate.getResourceFactory();
    String imagestring = "";
    DescriptionText.setText(TLKFAC.getEntry(485));
    try {
      racialmap = RESFAC.getResourceAs2DA("racialtypes");
    } catch (IOException err) {
      JOptionPane.showMessageDialog(
          null,
          "Fatal Error - racialtypes.2da not found. Your data files might be corrupt.",
          "Error",
          0);
      System.exit(0);
    }
    for (int i = 0; i < racialmap.length; i++) {
      String tempispc = racialmap[i][racialtypes.PlayerRace];
      if (tempispc != null && tempispc.equalsIgnoreCase("1")) {
        RaceButton racebutton = new RaceButton();
        descstr = racialmap[i][racialtypes.Name];
        int descnum = ChkHex.ChkHex(descstr);
        racebutton.RaceButton.setText(TLKFAC.getEntry(descnum));
        racebutton.setSize(240, 52);
        racebutton.InfoNum.setText(Integer.toString(i));
        RaceButtonList.add(racebutton, -1);
      }
    }

    pack();
  }
예제 #7
0
  public VDialog() {
    setSize(250, 250);
    setUndecorated(true); // remove the window bar
    // the following lines of code calculate a random coordinate to position the dialog
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = (int) screenSize.getWidth();
    int height = (int) screenSize.getHeight();
    Random rn = new Random();
    int xPos = rn.nextInt(width - 250);
    int yPos = rn.nextInt(height - 250);
    this.setLocation(xPos, yPos);

    // set transparent background color
    Color c = new Color(0, 0, 0, 0);
    setBackground(c);

    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    addKeyListener(new MKeyListener());
    // put the image of the cow
    try {
      this.add(
          new JLabel(
              new ImageIcon(
                  ImageIO.read(getClass().getResourceAsStream("/resources/cow_rszd.png")))));
    } catch (IOException e) {
      e.printStackTrace();
    }
    pack();
    setVisible(true);
  }
예제 #8
0
  public void setImage(BufferedImage image, String format) {
    ImageDocument document = imageComponent.getDocument();
    BufferedImage previousImage = document.getValue();
    document.setValue(image);
    if (image == null) return;
    document.setFormat(format);
    ImageZoomModel zoomModel = getZoomModel();
    if (previousImage == null || !zoomModel.isZoomLevelChanged()) {
      // Set smart zooming behaviour on open
      Options options = OptionsManager.getInstance().getOptions();
      ZoomOptions zoomOptions = options.getEditorOptions().getZoomOptions();
      // Open as actual size
      zoomModel.setZoomFactor(1.0d);

      if (zoomOptions.isSmartZooming()) {
        Dimension prefferedSize = zoomOptions.getPrefferedSize();
        if (prefferedSize.width > image.getWidth() && prefferedSize.height > image.getHeight()) {
          // Resize to preffered size
          // Calculate zoom factor

          double factor =
              (prefferedSize.getWidth() / (double) image.getWidth()
                      + prefferedSize.getHeight() / (double) image.getHeight())
                  / 2.0d;
          zoomModel.setZoomFactor(Math.ceil(factor));
        }
      }
    }
  }
예제 #9
0
  private void show(int _current) {
    OpenDefinitionsDocument doc = _docs.get(_current);

    String text = getTextFor(doc);

    _label.setText(_displayManager.getName(doc));
    _label.setIcon(_displayManager.getIcon(doc));

    if (text.length() > 0) {
      // as wide as the text area wants, but only 200px high
      _textpane.setText(text);
      _scroller.setPreferredSize(_textpane.getPreferredScrollableViewportSize());
      if (_scroller.getPreferredSize().getHeight() > 200)
        _scroller.setPreferredSize(
            new Dimension((int) _scroller.getPreferredSize().getWidth(), 200));

      _scroller.setVisible(_showSource);
    } else _scroller.setVisible(false);

    Dimension d = _label.getMinimumSize();
    d.setSize(d.getWidth() + _padding * 2, d.getHeight() + _padding * 2);
    _label.setPreferredSize(d);
    _label.setHorizontalAlignment(SwingConstants.CENTER);
    _label.setVerticalAlignment(SwingConstants.CENTER);
    pack();
    centerH();
  }
예제 #10
0
  public SwingTest() {
    Container contentPane = getContentPane();

    pnTop.setBackground(Color.pink);
    pnCenter.setBackground(Color.YELLOW);
    pnBottom.setBackground(Color.BLUE);

    this.setLayout(new GridLayout(4, 1));

    pnTop.add(lbName);
    pnTop.setLayout(new FlowLayout());

    contentPane.add(pnTop);

    pnCenter.add(lbAge);
    contentPane.add(pnCenter);

    pnBottom.add(lbAddress);
    contentPane.add(pnBottom);

    pnResult.add(lbResult);
    contentPane.add(pnResult);

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    int nXpos = (int) (screen.getWidth() / 2 - super.getWidth() / 2);
    int nYpos = (int) (screen.getHeight() / 2 - super.getHeight() / 2);
    setSize(nXpos, nYpos);
    setVisible(true);
  }
예제 #11
0
  private void computeMarketsSize(Dimension panelDimensions) {

    double rowMaxLenght = 8d * panelDimensions.getWidth() / 9d;

    // check when the column of of workers start
    double halfheight = panelDimensions.getHeight() / 2d;
    marketYStart = 2d * halfheight / 5d + halfheight;
    marketYEnd = 3d * halfheight / 5d + halfheight;

    marketFirstX = rowMaxLenght / 9d;
    marketLastX = 8d * rowMaxLenght / 9d;
    double rowRealLenght = marketLastX - marketFirstX;
    marketRadius = (rowRealLenght * 3d) / (4d * new Double(GoodType.values().length));

    marketSpacing = marketRadius / 3d;
    int index = 0;
    for (GoodType x : GoodType.values()) {

      Point a =
          new Point(
              (int) Math.round(marketFirstX + index * (marketRadius + marketSpacing)),
              (int) Math.round((marketYStart + marketYEnd) / 2d));
      marketPlace.put(x, a);
      index++;
    }
  }
예제 #12
0
  private void computeFirmSizes(Dimension panelDimensions) {

    ArrayList<Firm> firms = SleepStoneTest.firms;

    double rowMaxLenght = 8d * panelDimensions.getWidth() / 9d;

    // check when the column of of workers start
    double halfheight = panelDimensions.getHeight() / 2d;
    firmYStart = halfheight / 3d;
    firmYEnd = 2d * halfheight / 3d;

    firmFirstX = rowMaxLenght / 11d;
    firmLastX = 10d * rowMaxLenght / 11d;
    double rowRealLenght = firmLastX - firmFirstX;
    firmLenght = (rowRealLenght * 3d) / (4d * new Double(firms.size()));
    firmSpacing = firmLenght / 3d;

    // compute the rectangles
    for (int i = 0; i < firms.size(); i++) {

      Rectangle location =
          new Rectangle(
              (int) Math.round(firmFirstX + i * (firmLenght + firmSpacing)),
              (int) Math.round(firmYStart),
              (int) Math.round(firmLenght),
              (int) Math.round(firmYEnd - firmYStart));
      System.out.println(location);
      firmsPlace.put(firms.get(i), location);
      tradersPlace.put(
          firms.get(i), new Point((int) location.getCenterX(), (int) location.getCenterY()));
    }
  }
예제 #13
0
  @Override
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension d = this.getSize();
    int width = (int) d.getWidth();
    int height = (int) d.getHeight();

    g2.clearRect(0, 0, width, height);
    AffineTransform at = null;

    if (cachedImage == null) {
      renderOffscreen();
    }
    if (getOrientation() == SwingConstants.VERTICAL) {
      at = AffineTransform.getScaleInstance((double) width / 10f, (double) height / DEFAULT_HEIGHT);
    }

    if (getOrientation() == SwingConstants.HORIZONTAL) {
      at =
          AffineTransform.getScaleInstance(
              (double) width / DEFAULT_WIDTH, (double) height / (double) 10);
    }

    drawBackground(g2);
    g2.drawRenderedImage(cachedImage, at);
  }
예제 #14
0
  public Dimension getPreferredSize(JComponent c) {
    Dimension preferredSize = super.getPreferredSize(c);
    if (c instanceof ProgressTooltip) {
      preferredSize.setSize(preferredSize.getWidth(), preferredSize.getHeight() + 6);
    }

    return preferredSize;
  }
 public void showGui() {
   pack();
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   int centerX = (int) screenSize.getWidth() / 2;
   int centerY = (int) screenSize.getHeight() / 2;
   setLocation(centerX - getWidth() / 2, centerY - getHeight() / 2);
   super.setVisible(true);
 }
예제 #16
0
  public void paint(Graphics g) {
    super.paint(g);

    Dimension size = getSize();
    double w = size.getWidth() - 50;
    double h = size.getHeight() + 20;

    try {
      readFile();
    } catch (IOException e) {
      System.err.println("IO issue");
    }

    barWidth = ((int) (w / numBars)) - 20;
    pos = 5;

    int xPos[] = {pos, pos, pos, pos};
    int yPos[] = {pos, pos, pos, pos};

    maxVal = maxValue(values);
    double barH, ratio;

    for (int i = 0; i < numBars - 1; i++) {
      Color col[] = new Color[numBars];
      for (int j = 0; j < numBars - 1; j++) {
        col[j] = new Color((int) (Math.random() * 0x1000000));
      }

      ratio = (double) values[i] / (double) maxVal;
      barH = ((h) * ratio) - 10;

      xPos[0] = pos;
      xPos[2] = pos + barWidth;
      xPos[1] = xPos[0];
      xPos[3] = xPos[2];
      yPos[0] = (int) h;
      yPos[1] = (int) barH;
      yPos[2] = yPos[1];
      yPos[3] = yPos[0];

      System.out.println(
          "xPos:" + xPos[1] + " yPos:" + yPos[0] + " h:" + h + " barH:" + barH + " ratio:" + ratio
              + " pos:" + pos);

      int stringPtsY[] = {
        ((i + 1) * 20) + 180, ((i + 1) * 20) + 200, ((i + 1) * 20) + 200, ((i + 1) * 20) + 180
      };
      int stringPtsX[] = {600, 600, 580, 580};

      g.setColor(col[i]);
      g.fillPolygon(xPos, yPos, xPos.length);

      g.fillPolygon(stringPtsX, stringPtsY, 4);
      g.setColor(Color.black);
      g.drawString(labels[i], 610, ((i + 1) * 20) + 195);
      pos = pos + barWidth + 10;
    }
  }
예제 #17
0
  /** Creates new form PortraitMenu1 */
  public PortraitMenu() {
    menucreate = TLKFactory.getCreateMenu();
    TLKFAC = menucreate.getTLKFactory();
    RESFAC = menucreate.getResourceFactory();
    Preferences prefs = Preferences.userRoot().node("/CharacterCreator");
    String NWNDir = prefs.get("GameDir", null);
    FileDelim = prefs.get("FileDelim", null);
    directory = NWNDir + "portraits" + FileDelim;
    menucreate.BlockWindow(true);
    initComponents();
    PortraitScrollPane.setViewportView(PortraitsWindow);
    OKButton.setEnabled(false);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    if ((screenSize.getWidth() > getContentPane().getWidth())
        && (screenSize.getHeight() > getContentPane().getHeight())) {
      int intwidth =
          new Double(((screenSize.getWidth() - getContentPane().getWidth()) / 2)).intValue();
      int intheight =
          new Double(((screenSize.getHeight() - getContentPane().getHeight()) / 2)).intValue();
      setLocation(intwidth, intheight);
    } else setLocation(0, 0);

    try {
      portraitmap = RESFAC.getResourceAs2DA("portraits");
    } catch (IOException err) {
      JOptionPane.showMessageDialog(
          null,
          "Fatal Error - portraits.2da not found. Your data files might be corrupt.",
          "Error",
          0);
      System.exit(0);
    }

    CURRENTPORTRAIT = "resource/portrait.jpg";
    java.net.URL targurl = getClass().getResource(CURRENTPORTRAIT);
    CurrentPortrait.setIcon(new ImageIcon(targurl));
    menucreate = TLKFactory.getCreateMenu();
    sexlock = true;
    racelock = true;

    RedoPortraits(-1);

    pack();
  }
예제 #18
0
  public void paint(Graphics g, JComponent c) {
    toolTip.getUI().paint(g, c);

    if (c instanceof ProgressTooltip) {
      ProgressTooltip tooltip = (ProgressTooltip) c;
      tooltip.getPercentage();

      Dimension d = getPreferredSize(c);

      int middlePoint = (int) ((d.getWidth() - 2) * tooltip.getPercentage());

      g.setColor(new Color(0x00B000));
      g.fillRect(4, (int) d.getHeight() - 6, middlePoint, 3);

      g.setColor(new Color(0xB00000));
      if (middlePoint < 4) middlePoint = 4;
      g.fillRect(middlePoint, (int) d.getHeight() - 6, (int) d.getWidth() - middlePoint - 4, 3);
    }
  }
예제 #19
0
  public void setNormalSize() {
    JScrollPane scrollPane = getScrollPane();
    int x = 0;
    int y = 0;
    Insets scrollInsets = getScrollPaneInsets();

    if (scrollPane != null) {
      Dimension d = scrollPane.getVisibleRect().getSize();
      if (scrollPane.getBorder() != null) {
        d.setSize(
            d.getWidth() - scrollInsets.left - scrollInsets.right,
            d.getHeight() - scrollInsets.top - scrollInsets.bottom);
      }

      d.setSize(d.getWidth() - 20, d.getHeight() - 20);
      desktop.setAllSize(x, y);
      scrollPane.invalidate();
      scrollPane.validate();
    }
  }
예제 #20
0
  public Container CreateContentPane() {
    // Create the content-pane-to-be.
    JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setOpaque(true);

    // the log panel
    log = new JTextPane();
    log.setEditable(false);
    log.setBackground(Color.BLACK);
    logPane = new JScrollPane(log);
    kit = new HTMLEditorKit();
    doc = new HTMLDocument();
    log.setEditorKit(kit);
    log.setDocument(doc);
    DefaultCaret c = (DefaultCaret) log.getCaret();
    c.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    ClearLog();

    // the preview panel
    previewPane = new DrawPanel();
    previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right);

    // status bar
    statusBar = new StatusBar();
    Font f = statusBar.getFont();
    statusBar.setFont(f.deriveFont(Font.BOLD, 15));
    Dimension d = statusBar.getMinimumSize();
    d.setSize(d.getWidth(), d.getHeight() + 30);
    statusBar.setMinimumSize(d);

    // layout
    Splitter split = new Splitter(JSplitPane.VERTICAL_SPLIT);
    split.add(previewPane);
    split.add(logPane);
    split.setDividerSize(8);

    contentPane.add(statusBar, BorderLayout.SOUTH);
    contentPane.add(split, BorderLayout.CENTER);

    // open the file
    if (recentFiles[0].length() > 0) {
      OpenFileOnDemand(recentFiles[0]);
    }

    // connect to the last port
    ListSerialPorts();
    if (Arrays.asList(portsDetected).contains(recentPort)) {
      OpenPort(recentPort);
    }

    return contentPane;
  }
  public Dimension getPreferredScrollableViewportSize() {
    Dimension defaultPreferredSize = super.getPreferredSize();

    Dimension preferredSize =
        new Dimension(
            (int) defaultPreferredSize.getWidth(),
            (int)
                Math.min(
                    defaultPreferredSize.getHeight(),
                    getFontMetrics(getFont()).getHeight() * MAX_ROW_HEIGHT));

    return preferredSize;
  }
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   sb.append((int) _dim.getWidth());
   sb.append(' ');
   sb.append((int) _dim.getHeight());
   sb.append(' ');
   sb.append(_loc.x);
   sb.append(' ');
   sb.append(_loc.y);
   sb.append(' ');
   sb.append(_currentStrategyIndex);
   return sb.toString();
 }
예제 #23
0
  /**
   * Centers the given component on the user's screen.
   *
   * @param component a component (usually a frame.)
   */
  public static void centerOnScreen(Component component) {
    Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();
    int screenWidth = (int) screenSize.getWidth();
    int screenHeight = (int) screenSize.getHeight();

    int componentWidth = component.getWidth();
    int componentHeight = component.getHeight();

    int top = (screenHeight - componentHeight) / 2;
    int left = (screenWidth - componentWidth) / 2;

    Utils.changeFrameLocation(component, left, top);
  }
예제 #24
0
 public static void main(String[] args) {
   JFrame frame = new JFrame("Clock by Volkman");
   frame.setContentPane(new Clock().getForm());
   frame.pack();
   Toolkit tk = Toolkit.getDefaultToolkit();
   Dimension dim = tk.getScreenSize();
   AWTUtilities.setWindowOpacity(frame, (float) 0.25);
   frame.setLocation((int) dim.getWidth() - 400, 20);
   frame.removeNotify();
   frame.setUndecorated(true);
   frame.setVisible(true);
   frame.setAlwaysOnTop(true);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
예제 #25
0
  public AppFrame() {
    super();
    GlobalData.oFrame = this;
    this.setSize(this.width, this.height);
    this.toolkit = Toolkit.getDefaultToolkit();

    Dimension w = toolkit.getScreenSize();
    int fx = (int) w.getWidth();
    int fy = (int) w.getHeight();

    int wx = (fx - this.width) / 2;
    int wy = (fy - this.getHeight()) / 2;

    setLocation(wx, wy);

    this.tracker = new MediaTracker(this);
    String sHost = "";
    try {

      localAddr = InetAddress.getLocalHost();
      if (localAddr.isLoopbackAddress()) {
        localAddr = LinuxInetAddress.getLocalHost();
      }
      sHost = localAddr.getHostAddress();
    } catch (UnknownHostException ex) {
      sHost = "你的IP地址错误";
    }
    //
    this.textLines[0] = "服务器正在运行.";
    this.textLines[1] = "";
    this.textLines[2] = "你的IP地址: " + sHost;
    this.textLines[3] = "";
    this.textLines[4] = "请打开你的手机客户端";
    this.textLines[5] = "";
    this.textLines[6] = "输入屏幕上显示的IP地址.";
    //
    try {
      URL fileURL = this.getClass().getProtectionDomain().getCodeSource().getLocation();
      String sBase = fileURL.toString();
      if ("jar".equals(sBase.substring(sBase.length() - 3, sBase.length()))) {
        jar = new JarFile(new File(fileURL.toURI()));

      } else {
        basePath = System.getProperty("user.dir") + "\\res\\";
      }
    } catch (Exception ex) {
      this.textLines[1] = "exception: " + ex.toString();
    }
  }
예제 #26
0
  public ArenaFrame(String title, Arena arena, String background, String battleBG, String cardBG) {
    setTitle(title);
    this.arena = arena;
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    width = (int) screenSize.getWidth();
    height = (int) screenSize.getHeight();
    posX = (width - Constant.BATTLEFIELD_WIDTH) / 2;
    posY = (height - Constant.BATTLEFIELD_HEIGHT - Constant.CARDPANEL_HEIGHT) / 2;
    skill_id = 0;
    addKeyListener(this);
    addMouseListener(this);
    addMouseMotionListener(this);

    setUndecorated(true);
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    c = getContentPane();
    c.setPreferredSize(new Dimension(width, height));
    c.setLayout(null);

    battle_field =
        new BattleFieldPanel(Constant.BATTLEFIELD_WIDTH, Constant.BATTLEFIELD_HEIGHT, arena);
    battle_field.setBounds(posX, posY, Constant.BATTLEFIELD_WIDTH, Constant.BATTLEFIELD_HEIGHT);
    battle_field.setOpaque(false);
    c.add(battle_field);

    card_panel = new CardPanel(Constant.CARDPANEL_WIDTH, Constant.CARDPANEL_HEIGHT, arena);
    card_panel.setBounds(
        posX,
        posY + Constant.BATTLEFIELD_HEIGHT,
        Constant.CARDPANEL_WIDTH,
        Constant.CARDPANEL_HEIGHT);
    card_panel.setOpaque(false);
    c.add(card_panel);

    setSize(width, height);

    setBackground(background);
    setBattleFieldBackground(battleBG);
    setCardPanelBackground(cardBG);

    setResizable(false);
    setLocationRelativeTo(null);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setVisible(true);
    setFocusable(true);
  }
예제 #27
0
  public static void createAndShowGUI() {
    // Create and set up window
    console frame = new console();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Add contents
    frame.addComponentsToPane();

    // Display
    frame.pack();
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((int) (dim.getWidth() - 600) / 2, (int) (dim.getHeight() - 300) / 2);
    frame.setSize(600, 200);
    frame.setVisible(true);
  }
예제 #28
0
    /**
     * Sets readable text describing the resolution if the selected value is null we return the
     * string "Auto".
     *
     * @param list
     * @param value
     * @param index
     * @param isSelected
     * @param cellHasFocus
     * @return Component
     */
    @Override
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      // call super to set backgrounds and fonts
      super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

      // now just change the text
      if (value == null) setText("Auto");
      else if (value instanceof Dimension) {
        Dimension d = (Dimension) value;

        setText(((int) d.getWidth()) + "x" + ((int) d.getHeight()));
      }
      return this;
    }
예제 #29
0
파일: Ladder.java 프로젝트: yblee/Ladder
  private void initLadder() {

    int width = (int) (frameSize.getWidth() / player);
    int height = (int) (frameSize.getHeight());

    for (int i = 0; i < ladderMap.length; i++)
      for (int j = 0; j < ladderMap[i].length - 1; j++) {
        if (Math.random() > 0.4 && ladderMap[i][j] != 2) {
          ladderMap[i][j] = 1;
          ladderMap[i][j + 1] = 2;
        }
      }

    drawLadder();
  }
예제 #30
0
    private void updateUIState(ParamChangeEvent event) {
      if (updatingUI.compareAndSet(false, true)) {
        try {
          if (event != null && canUseGeoCoordinates(product)) {
            final String parmName = event.getParameter().getName();
            if (parmName.startsWith("geo_")) {
              final GeoPos geoPos1 =
                  new GeoPos((Float) paramNorthLat1.getValue(), (Float) paramWestLon1.getValue());
              final GeoPos geoPos2 =
                  new GeoPos((Float) paramSouthLat2.getValue(), (Float) paramEastLon2.getValue());
              updateXYParams(geoPos1, geoPos2);
            } else if (parmName.startsWith("source_x") || parmName.startsWith("source_y")) {
              syncLatLonWithXYParams();
            }
          }
          int x1 = ((Number) paramX1.getValue()).intValue();
          int y1 = ((Number) paramY1.getValue()).intValue();
          int x2 = ((Number) paramX2.getValue()).intValue();
          int y2 = ((Number) paramY2.getValue()).intValue();

          int sx = ((Number) paramSX.getValue()).intValue();
          int sy = ((Number) paramSY.getValue()).intValue();

          updateSubsetDefRegion(x1, y1, x2, y2, sx, sy);

          Dimension s =
              productSubsetDef.getSceneRasterSize(
                  product.getSceneRasterWidth(), product.getSceneRasterHeight());
          subsetWidthLabel.setText(String.valueOf(s.getWidth()));
          subsetHeightLabel.setText(String.valueOf(s.getHeight()));

          int sliderBoxX1 = x1 / thumbNailSubSampling;
          int sliderBoxY1 = y1 / thumbNailSubSampling;
          int sliderBoxX2 = x2 / thumbNailSubSampling;
          int sliderBoxY2 = y2 / thumbNailSubSampling;
          int sliderBoxW = sliderBoxX2 - sliderBoxX1 + 1;
          int sliderBoxH = sliderBoxY2 - sliderBoxY1 + 1;
          Rectangle box =
              getScaledRectangle(new Rectangle(sliderBoxX1, sliderBoxY1, sliderBoxW, sliderBoxH));
          imageCanvas.setSliderBoxBounds(box);
        } finally {
          updatingUI.set(false);
        }
      }
    }