Example #1
0
 // Skapar de grafiska komponenterna för menyn
 public void createLabels() {
   // Skapar textfält för nick och intellegens och lägger till dem i en lista
   for (int i = 0; i < 4; i++) {
     textfields.add(new JTextField(20));
     intfields.add(new JTextField(20));
   }
   // Skapar checkboxes för att bestämma om spelaren är ett AI och lägger till den i en lista
   for (int i = 0; i < 4; i++) {
     boxes.add(new JCheckBox());
     boxes.get(i).addActionListener(this);
   }
   // Lägger till labels med förbestämd text i panelen
   for (int i = 0; i < 4; i++) {
     panel.add(new JLabel(labeltext[i]));
   }
   // Lägger till textfields och checkboxes i panelen
   for (int i = 4; i < 8; i++) {
     panel.add(new JLabel(labeltext[i]));
     panel.add(textfields.get(i - 4));
     panel.add(boxes.get(i - 4));
     panel.add(intfields.get(i - 4));
     intfields.get(i - 4).setVisible(false);
   }
   // Lägger till några tomma labels i panelen för att skapa mellanrum och symetri
   for (int i = 0; i < 5; i++) {
     panel.add(new JLabel(" "));
   }
   // Lägger till knapparna och lägger actionlisteners på dem
   panel.add(go);
   go.addActionListener(this);
   panel.add(help);
   help.addActionListener(this);
 }
Example #2
0
 // Metoden makeBoard - Skapar de grafiska komponenterna för spelplanen
 public void makeBoard() {
   int k = 0;
   // Laddar in bilderna för kortens baksida till programmet
   for (int j = 1; j < 33; j++) {
     for (int i = 0; i < 2; i++) {
       bilder.add(new ImageIcon("Memorypics/" + j + ".gif"));
     }
   }
   // Skapar korten med bilder och id, blandar sedan korten
   for (int i = 0; i < 64; i++) {
     cards.add(new Card(bilder.get(i), k));
     if (i % 2 == 1) {
       k++;
     }
     Collections.shuffle(cards);
   }
   // Lägger ut korten på spelplanen
   for (int i = 0; i < 64; i++) {
     panel.add(cards.get(i));
     cards.get(i).addActionListener(this);
     cards.get(i).setBorder(new LineBorder(Color.WHITE, 1));
     cards.get(i).pos = i;
   }
   // Lägger till labels för nick och poängställning
   for (int i = 0; i < players.size(); i++) {
     playerlabels.add(new JLabel(players.get(i).nick + ": "));
     scorelabels.add(new JLabel(players.get(i).score + ""));
     panel.add(playerlabels.get(i));
     panel.add(scorelabels.get(i));
   }
 }
Example #3
0
  /** @return the list of the data flavors */
  public Collection<DataFlavor> getColorDataFlavors() {

    LinkedList<DataFlavor> dataFlavors = new LinkedList<DataFlavor>();

    dataFlavors.add(colorFlavor);
    dataFlavors.add(w3cSVGColorFlavor);

    return dataFlavors;
  }
Example #4
0
  void createBend(int bendx, int bendy) {
    Bend bn = null;
    int index = 0;
    if (bends == null) {
      if (driver.nearpln(bendx, bendy, fromX, fromY, toX, toY)) {
        bends = new LinkedList<Bend>();
        bn = new Bend(bendx, bendy);
        if (fromX == toX) // if line vertical
        bn.x = fromX;
        if (fromY == toY) // if line horizontal
        bn.y = fromY;
        bends.add(bn);
        bn.marked = true;
        driver.bendForDragging = bn;
        return;
      }
    } else {
      int x = fromX;
      int y = fromY;
      Object[] oa = bends.toArray();
      for (Object o : oa) {
        Bend b = (Bend) o;
        if (sameBend(bendx, bendy, b)) {
          bn = b;
          bn.marked = true;
          driver.bendForDragging = bn;
          return;
        }
        if (driver.nearpln(bendx, bendy, x, y, b.x, b.y)) {
          bn = new Bend(bendx, bendy);
          if (x == b.x) // if line vertical
          bn.x = x;
          if (y == b.y) // if line horizontal
          bn.y = y;
          bends.add(index, bn);
          bn.marked = true;
          driver.bendForDragging = bn;
          return;
        }
        x = b.x;
        y = b.y;
        index++;
      }

      if (driver.nearpln(bendx, bendy, x, y, toX, toY)) {
        bn = new Bend(bendx, bendy);
        if (x == toX) // if line vertical
        bn.x = x;
        if (y == toY) // if line horizontal
        bn.y = y;
        bends.add(bn);
        bn.marked = true;
        driver.bendForDragging = bn;
      }
    }
  }
Example #5
0
    void add(Target t) {
      SocketChannel sc = null;
      try {

        sc = SocketChannel.open();
        sc.configureBlocking(false);

        boolean connected = sc.connect(t.address);

        t.channel = sc;
        t.connectStart = System.currentTimeMillis();

        if (connected) {
          t.connectFinish = t.connectStart;
          sc.close();
          printer.add(t);
        } else {
          synchronized (pending) {
            pending.add(t);
          }

          sel.wakeup();
        }
      } catch (IOException x) {
        if (sc != null) {
          try {
            sc.close();
          } catch (IOException xx) {
          }
        }
        t.failure = x;
        printer.add(t);
      }
    }
Example #6
0
  // Method that aids collectSatanSpawn(), recursively walks through tree and populates a linked
  // list
  private void getPointsForRebuilding(TreeNode t, LinkedList<Point> points) {
    if (t == null) return;

    points.add(t.p);
    getPointsForRebuilding(t.left, points);
    getPointsForRebuilding(t.right, points);
  }
Example #7
0
  public String get_item_ids() {

    String jsonarry;

    try {

      krypton_database_get_my_tokens getxt = new krypton_database_get_my_tokens();

      String token_array[] = new String[network.listing_size];
      token_array = getxt.get_tokens(network.base58_id);

      LinkedList<String> list = new LinkedList<String>();
      for (int loop = 0; loop < token_array.length; loop++) { // ************

        if (!token_array[loop].contains("-")) {
          list.add(token_array[loop]);
        }
      } // *****************************************************************

      jsonarry = JSONValue.toJSONString(list);

    } catch (Exception e) {

      statex = "0";
      jsonarry = "Error";
    } // *****************

    return jsonarry;
  } // *************************************
Example #8
0
 public ButtonBar addButtonBar(JInternalFrame iaf) {
   ButtonBar bb = new ButtonBar(this, iaf, iaf.getTitle());
   bar.add(bb);
   bBar.add(bb);
   activeButton(bb);
   return bb;
 }
Example #9
0
  public ShowComp() throws InterruptedException, IOException {
    super("CONNECTED COMPUTERS");
    int x = 0, d = 20;
    mb = new JMenuBar();
    File = new JMenu("File");
    mb.add(File);
    exit = new JMenuItem("Exit");
    exit.addActionListener(this);
    File.add(exit);
    ta = new JTextArea();
    ta.setBounds(20, 30, 315, 470);
    ta.setEditable(false);
    add(ta);

    setJMenuBar(mb);

    sel = new JLabel("The connected computers are..");
    sel.setBounds(15, 5, 300, 30);
    add(sel);
    b1 = new JButton("<< BACK");
    b1.setBounds(140, 510, 100, 30);
    b1.setToolTipText("Back to main page");
    b1.addActionListener(this);
    add(b1);
    setLayout(null);
    while (x < 360) {
      x = x + d;
      setBounds(675, 50, x, 600);
      this.show();
    }
    // setVisible(true);
    String s = "192.168.0.", temp = null;
    Printer printer = new Printer();
    printer.start();
    Connector connector = new Connector(printer);
    connector.start();

    LinkedList targets = new LinkedList();
    for (int i = 1; i <= 255; i++) {
      temp = s + Integer.toString(i);
      Target t = new Target(temp);
      targets.add(t);
      connector.add(t);
    }
    Thread.sleep(2000);
    connector.shutdown();
    connector.join();

    for (Iterator i = targets.iterator(); i.hasNext(); ) {
      Target t = (Target) i.next();
      if (!t.shown) t.show();
    }

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  }
Example #10
0
    @Override
    public void run() {
      // System.out.println("update map now");
      LinkedList<EdgeOp> backlist = new LinkedList<>();
      PublicData pd = PublicData.getData();
      int i;
      PosOp tmpPosOp;
      EdgeOp tmpEdgeOp;
      Pos tmpPos;
      for (i = 0; i < pd.posTask.size(); i++) {
        tmpPosOp = pd.posTask.get(i);
        if (tmpPosOp.op == 0) { // op==0 add a pos
          MapViewer.this.g.addVertex(new Integer(tmpPosOp.pos));
          tmpPos = pd.agentsPos.get(tmpPosOp.pos);
          MapViewer.this.layout.setLocation(tmpPosOp.pos, tmpPos.getX(), tmpPos.getY());
        } else {
          MapViewer.this.g.removeVertex(tmpPosOp.pos);
        }
      }
      for (i = 0; i < pd.edgeTask.size(); i++) {
        tmpEdgeOp = pd.edgeTask.get(i);
        if (tmpEdgeOp.op == 0) { // add a edge
          // int edgeNum=g.getEdgeCount();
          MapViewer.this.g.addEdge(edgeCnt, tmpEdgeOp.start, tmpEdgeOp.end);
          backlist.add(new EdgeOp(1, edgeCnt, 0, pd.displayCnt));
          edgeCnt++;
        } else { // remove

          if (tmpEdgeOp.delay <= 0) {
            g.removeEdge(tmpEdgeOp.start);
          } else {
            tmpEdgeOp.delay--;
            backlist.add(tmpEdgeOp);
          }
        }
      }
      pd.resetTask();
      pd.edgeTask = backlist;
      vv.repaint();
      // throw new UnsupportedOperationException("Not supported yet."); //To change body of
      // generated methods, choose Tools | Templates.
    }
Example #11
0
 @Override
 public Collection<Handle> createHandles(int detailLevel) {
   LinkedList<Handle> handles = new LinkedList<Handle>();
   switch (detailLevel % 2) {
     case -1: // Mouse hover handles
       handles.add(new BezierOutlineHandle(this, true));
       break;
     case 0:
       handles.add(new BezierOutlineHandle(this));
       for (int i = 0, n = path.size(); i < n; i++) {
         handles.add(new BezierNodeHandle(this, i));
       }
       break;
     case 1:
       TransformHandleKit.addTransformHandles(this, handles);
       handles.add(new BezierScaleHandle(this));
       break;
   }
   return handles;
 }
 public Collection<Handle> createHandles(SVGPathFigure pathFigure, int detailLevel) {
   LinkedList<Handle> handles = new LinkedList<Handle>();
   switch (detailLevel % 2) {
     case 0:
       for (int i = 0, n = path.size(); i < n; i++) {
         handles.add(new BezierNodeHandle(this, i, pathFigure));
       }
       break;
     case 1:
       TransformHandleKit.addTransformHandles(this, handles);
       break;
     default:
       break;
   }
   return handles;
 }
  public Object addNode(String id, String label, String description, Image image, String tooltip) {
    if (id == null || label == null) return null;

    HashMap map = new HashMap();
    map.put("Address", id);

    if (description.indexOf(id) > -1) description = description.substring(id.length());
    map.put("Label", label);
    map.put("Description", description);
    map.put("Tooltip", tooltip);
    map.put("Image", image);
    map.put(" ", tooltip);
    map.put("Pivot", "");
    map.put("Active", Boolean.FALSE);
    rows.add(map);
    return map;
  }
  @Override
  public Collection<Action> getActions(Point2D.Double p) {
    LinkedList<Action> actions = new LinkedList<Action>();
    if (get(TRANSFORM) != null) {
      ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.samples.odg.Labels");
      actions.add(
          new AbstractAction(labels.getString("edit.removeTransform.text")) {
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent evt) {
              willChange();
              fireUndoableEditHappened(TRANSFORM.setUndoable(ODGAttributedFigure.this, null));
              changed();
            }
          });
    }
    return actions;
  }
Example #15
0
 private Drawing createDrawing() {
   DefaultDrawing drawing = new DefaultDrawing();
   LinkedList<InputFormat> inputFormats = new LinkedList<InputFormat>();
   inputFormats.add(new SVGInputFormat());
   inputFormats.add(new SVGZInputFormat());
   inputFormats.add(new ImageInputFormat(new SVGImageFigure()));
   inputFormats.add(new TextInputFormat(new SVGTextFigure()));
   LinkedList<OutputFormat> outputFormats = new LinkedList<OutputFormat>();
   outputFormats.add(new SVGOutputFormat());
   outputFormats.add(new ImageOutputFormat());
   drawing.setInputFormats(inputFormats);
   drawing.setOutputFormats(outputFormats);
   return drawing;
 }
Example #16
0
 // Metoden sortPlayers - Sorterar spelarlistan, bubblesort används då det är en liten lista
 public LinkedList<Player> sortPlayers(LinkedList<Player> tosort) {
   boolean isSorted = false;
   Player replace;
   // Kär så länge listan inte är färdigsorterad
   while (isSorted == false) {
     for (int i = 1; i < players.size(); i++) {
       if (tosort.get(i - 1).score < tosort.get(i).score) {
         replace = tosort.get(i);
         tosort.remove(i);
         tosort.add(i - 1, replace);
       }
     }
     // Kollar om listan är sorterad
     for (int i = 1; i < players.size(); i++) {
       if (tosort.get(i - 1).score < tosort.get(i).score) {
         isSorted = false;
         break;
       } else {
         isSorted = true;
       }
     }
   }
   return tosort;
 }
Example #17
0
 public Collection<Handle> createHandles(int detailLevel) {
   LinkedList<Handle> handles = new LinkedList<Handle>();
   switch (detailLevel % 2) {
     case -1: // Mouse hover handles
       handles.add(new BoundsOutlineHandle(this, false, true));
       break;
     case 0:
       handles.add(new BoundsOutlineHandle(this));
       handles.add(new MoveHandle(this, RelativeLocator.northWest()));
       handles.add(new MoveHandle(this, RelativeLocator.northEast()));
       handles.add(new MoveHandle(this, RelativeLocator.southWest()));
       handles.add(new MoveHandle(this, RelativeLocator.southEast()));
       handles.add(new FontSizeHandle(this));
       handles.add(new LinkHandle(this));
       break;
     case 1:
       TransformHandleKit.addTransformHandles(this, handles);
       break;
   }
   return handles;
 }
Example #18
0
 public void sendString(String text) {
   synchronized (listeners) {
     commands.add(text);
   }
 }
Example #19
0
 public void addSessionListener(ConsoleCallback l) {
   listeners.add(l);
 }
Example #20
0
 // Action - vad som händer om man klickar på de olika knapparna
 public void actionPerformed(ActionEvent e) {
   // Om man trycker på startknappen
   if (e.getSource() == go) {
     for (int i = 0; i < 4; i++) {
       // Skapar spelare och AI, beroende på om textfälten och checkboxarna är ifyllda
       if (textfields.get(i).getText().length() > 0) {
         // Om checkboxen är itryckt, skapa ett AI
         if (boxes.get(i).isSelected()) {
           try {
             if (Integer.parseInt(intfields.get(i).getText()) >= 0) {
               players.add(
                   new AI(
                       textfields.get(i).getText(), Integer.parseInt(intfields.get(i).getText())));
             }
             // Om intellegensen är angivet negativt använder vi ett minne av storleken 0.
             else {
               players.add(new AI(textfields.get(i).getText(), 0));
             }
           }
           // Om intellegensen inte är angiven i siffror, använd standardintellegensen på 20 korts
           // minne
           catch (NumberFormatException ex) {
             players.add(new AI(textfields.get(i).getText(), 20));
           }
         }
         // Om spelaren inte är ett AI, lägg till en vanlig spelare
         else {
           players.add(new Player(textfields.get(i).getText()));
         }
       }
     }
     // Stänger ner menyn och startar spelet, skickar med spelarinfon
     if (players.size() >= 1) {
       this.dispose();
       f.dispose();
       new Memory(players);
     }
   }
   // Om man trycker på hjälpknappen visas en ruta med lite instruktioner
   if (e.getSource() == help) {
     f.setVisible(true);
     f.setBounds(300, 200, 500, 200);
     f.setResizable(false);
     String text =
         "<html>Om inställningar:<br>Skriv in spelarnas namn för att lägga till dem.<br>"
             + "Om AI önskas: Klicka i rutan och ange intellegens. (Antal kort AIn kommer ihåg.)<br>"
             + "Tryck på 'Starta' för att starta spelet.<br><br>"
             + "Hur man spelar:<br>Spelaren vars tur det är får sitt namn markerat med grön färg längst ner.<br>"
             + "För att göra ditt drag, tryck på korten. Du kan inte välja samma kort två gånger<br><br>"
             + "Det är ett vanligt memory, lets go!</html>";
     f.add(new JLabel(text), BorderLayout.NORTH);
   }
   for (int i = 0; i < boxes.size(); i++) {
     // Om checkboxarna är ikryssade lägger den till ett eget namn för AIn som ska skapas och visar
     // rutan för intellegensbestämning
     if (boxes.get(i).isSelected()) {
       textfields.get(i).setText("AI " + (i + 1));
       textfields.get(i).setEnabled(false);
       intfields.get(i).setText("" + 20);
       intfields.get(i).setVisible(true);
     }
     // Om checkboxarna blir urklickade igen, nollställ textfälten, och ta bort rutan för
     // intellegensbestämning
     else if (!boxes.get(i).isSelected()) {
       if (textfields.get(i).getText().indexOf("AI") != -1) {
         textfields.get(i).setText("");
         intfields.get(i).setVisible(false);
       }
       textfields.get(i).setEnabled(true);
     }
   }
 }
Example #21
0
  /** Initialize the common user interface components. */
  private void initUI() {
    /* initialize fields */
    {
      pFileSeqPanels = new TreeMap<FileSeq, JFileSeqPanel>();
    }

    /* initialize the popup menus */
    {
      initBasicMenus(true, false);
      updateMenuToolTips();
    }

    /* initialize the panel components */
    {
      setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

      /* header */
      {
        pApplyToolTipText = "Replace the working area files with the selected checked-in files.";
        pUnApplyToolTipText = "There are no unsaved changes to Apply at this time.";

        JPanel panel = initHeader(true);
        add(panel);
      }

      add(Box.createRigidArea(new Dimension(0, 4)));

      /* full node name */
      {
        LinkedList<Component> extra = new LinkedList<Component>();
        extra.add(Box.createRigidArea(new Dimension(4, 0)));
        {
          JButton btn = new JButton();
          pSeqLayoutButton = btn;
          btn.setName(pIsListLayout ? "ListLayoutButton" : "TabbedLayoutButton");

          Dimension size = new Dimension(19, 19);
          btn.setMinimumSize(size);
          btn.setMaximumSize(size);
          btn.setPreferredSize(size);

          btn.setActionCommand("seq-layout-changed");
          btn.addActionListener(this);

          extra.add(btn);
        }

        initNameField(this, extra);

        pNodeNameField.setFocusable(true);
        pNodeNameField.addKeyListener(this);
        pNodeNameField.addMouseListener(this);
      }

      add(Box.createRigidArea(new Dimension(0, 4)));

      {
        JTabbedPane tab = new JTabbedPane();
        pFileSeqsTab = tab;
        tab.setVisible(!pIsListLayout);
        add(tab);
      }

      {
        Box vbox = new Box(BoxLayout.Y_AXIS);
        pFileSeqsBox = vbox;

        {
          JScrollPane scroll = UIFactory.createVertScrollPane(vbox);
          pFileSeqsScroll = scroll;
          scroll.setVisible(!pIsListLayout);

          add(scroll);
        }
      }

      Dimension size = new Dimension(sSize + 22, 120);
      setMinimumSize(size);
      setPreferredSize(size);

      setFocusable(true);
      addKeyListener(this);
      addMouseListener(this);
    }

    updateNodeStatus(null, null, null);
  }
Example #22
0
 void add(Target t) {
   synchronized (pending) {
     pending.add(t);
     pending.notify();
   }
 }