当前位置: 首页>>代码示例>>Java>>正文


Java SwingGUI类代码示例

本文整理汇总了Java中net.sf.freecol.client.gui.SwingGUI的典型用法代码示例。如果您正苦于以下问题:Java SwingGUI类的具体用法?Java SwingGUI怎么用?Java SwingGUI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SwingGUI类属于net.sf.freecol.client.gui包,在下文中一共展示了SwingGUI类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * Add a listener for button presses on this panel to show the BuildQueuePanel
 */
public void initialize() {
    if (colony != null) {
        // we are interested in changes to the build queue, as well as
        // changes to the warehouse and the colony's production bonus
        colony.addPropertyChangeListener(EVENT, this);
            
        if (openBuildQueue) {
            addMouseListener(new MouseAdapter() {
                    @Override
                    public void mousePressed(MouseEvent e) {
                        ((SwingGUI)freeColClient.getGUI()).showBuildQueuePanel(colony);
                    }
                });
        }
    }
    update();
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:21,代码来源:ConstructionPanel.java

示例2: actionPerformed

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent ae) {
    final String command = ae.getActionCommand();
    SwingGUI gui = (SwingGUI)freeColClient.getGUI();
    if (null != command) switch (command) {
        case FreeColPanel.OK:
            if (this.colorChooserPanel != null) {
                this.currentColor = this.colorChooserPanel.getColor();
                gui.removeFromCanvas(this.colorChooserPanel);
            }
            fireEditingStopped();
            break;
        case FreeColPanel.CANCEL:
            if (this.colorChooserPanel != null) {
                gui.removeFromCanvas(this.colorChooserPanel);
            }
            fireEditingCanceled();
            break;
        default:
            logger.warning("Bad event: " + command);
            break;
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:27,代码来源:ColorCellEditor.java

示例3: loadAnimation

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * Find the animation for a unit attack.
 *
 * @param unit The {@code Unit} to animate.
 * @param direction The {@code Direction} of the attack.
 * @return True if the animation is loaded.
 */
private boolean loadAnimation(Unit unit, Direction direction) {
    float scale = ((SwingGUI)getGUI()).getMapScale();
    String roleStr = (unit.hasDefaultRole()) ? ""
        : "." + unit.getRoleSuffix();
    String startStr = "animation.unit." + unit.getType().getId() + roleStr
                    + ".attack.";

    // Only check directions not covered by the EW mirroring.
    // Favour East and West animations.
    if (loadAnimation(startStr, scale, direction)) return true;
    switch (direction) {
    case N: case S:
        return loadAnimation(startStr, scale, direction.getNextDirection())
            || loadAnimation(startStr, scale, direction.rotate(2))
            || loadAnimation(startStr, scale, direction.rotate(3))
            || loadAnimation(startStr, scale, direction.rotate(-3));
    case NE: case SW:
        return loadAnimation(startStr, scale, direction.getNextDirection())
            || loadAnimation(startStr, scale, direction.getPreviousDirection())
            || loadAnimation(startStr, scale, direction.rotate(2))
            || loadAnimation(startStr, scale, direction.rotate(3));
    case NW: case SE:
        return loadAnimation(startStr, scale, direction.getPreviousDirection())
            || loadAnimation(startStr, scale, direction.getNextDirection())
            || loadAnimation(startStr, scale, direction.rotate(-2))
            || loadAnimation(startStr, scale, direction.rotate(-3));
    case E: case W:
        return loadAnimation(startStr, scale, direction.getNextDirection())
            || loadAnimation(startStr, scale, direction.getPreviousDirection())
            || loadAnimation(startStr, scale, direction.rotate(2))
            || loadAnimation(startStr, scale, direction.rotate(-2));
    default:
        break;
    }
    return false;           
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:44,代码来源:UnitAttackAnimation.java

示例4: ColorCellEditor

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * The constructor to use.
 *
 * @param freeColClient The top level component that holds all
 *     other components.
 */
public ColorCellEditor(FreeColClient freeColClient) {
    this.freeColClient = freeColClient;

    this.colorEditButton = new JButton();
    this.colorEditButton.addActionListener(ae ->
        this.colorChooserPanel = ((SwingGUI)freeColClient.getGUI())
            .showColorChooserPanel(this));
    this.colorEditButton.setBorderPainted(false);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:16,代码来源:ColorCellEditor.java

示例5: buildList

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * Builds the buttons for all the terrains.
 */
private void buildList() {
    final Specification spec = getSpecification();
    List<TileType> tileList = spec.getTileTypeList();
    Dimension terrainSize = ImageLibrary.scaleDimension(ImageLibrary.TILE_OVERLAY_SIZE, 0.5f);
    for (TileType type : tileList) {
        listPanel.add(buildButton(SwingGUI.createTileImageWithOverlayAndForest(type, terrainSize),
                                  Messages.getName(type),
                                  new TileTypeTransform(type)));
    }
    Dimension riverSize = ImageLibrary.scaleDimension(ImageLibrary.TILE_SIZE, 0.5f);
    listPanel.add(buildButton(ImageLibrary.getRiverImage("0101", riverSize),
                              Messages.message("mapEditorTransformPanel.minorRiver"),
                              new RiverTransform(TileImprovement.SMALL_RIVER)));
    listPanel.add(buildButton(ImageLibrary.getRiverImage("0202", riverSize),
                              Messages.message("mapEditorTransformPanel.majorRiver"),
                              new RiverTransform(TileImprovement.LARGE_RIVER)));
    listPanel.add(buildButton(ImageLibrary.getRiverImage("2022", riverSize),
                              Messages.message("mapEditorTransformPanel.changeRiverConnections"),
                              new RiverStyleTransform(RiverStyleTransform.CHANGE_CONNECTIONS)));
    listPanel.add(buildButton(ImageLibrary.getRiverImage("1022", riverSize),
                              Messages.message("mapEditorTransformPanel.setRiverStyle"),
                              new RiverStyleTransform(RiverStyleTransform.SET_STYLE)));
    listPanel.add(buildButton(ImageLibrary.getMiscImage("image.tileitem."
                + first(getSpecification().getResourceTypeList()).getId(), 0.75f),
        Messages.message("mapEditorTransformPanel.resource"),
        new ResourceTransform()));
    listPanel.add(buildButton(ImageLibrary.getMiscImage(ImageLibrary.LOST_CITY_RUMOUR, 0.5f),
                              Messages.getName(ModelMessage.MessageType.LOST_CITY_RUMOUR),
                              new LostCityRumourTransform()));
    SettlementType settlementType = nativeNation.getType().getCapitalType();
    settlementButton = buildButton(ImageLibrary.getSettlementImage(settlementType, 0.5f),
                                   Messages.message("settlement"),
                                   new SettlementTransform());
    listPanel.add(settlementButton);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:39,代码来源:MapEditorTransformPanel.java

示例6: UnitLabel

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * Creates a JLabel to display a unit.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param unit The {@code Unit} to display.
 * @param isSmall The image will be smaller if set to {@code true}.
 * @param ignoreLocation The image will not include production or state
 *            information if set to {@code true}.
 * @param useTileImageLibrary If false use ImageLibrary in GUI.
 *              If true use tileImageLibrary in SwingGUI.
 */
public UnitLabel(FreeColClient freeColClient, Unit unit,
                 boolean isSmall, boolean ignoreLocation,
                 boolean useTileImageLibrary) {
    this.freeColClient = freeColClient;
    this.gui = (SwingGUI)freeColClient.getGUI();
    this.unit = unit;

    selected = false;
    this.isSmall = isSmall;
    this.ignoreLocation = ignoreLocation;
    this.useTileImageLibrary = useTileImageLibrary;

    updateIcon();
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:26,代码来源:UnitLabel.java

示例7: animate

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * Do the animation.
 *
 * @return True if the required animations were found and executed,
 *     false on error.
 */
public boolean animate() {
    Direction direction = this.attackerTile.getDirection(this.defenderTile);
    if (direction == null) return false; // Fail fast

    final FreeColClient fcc = getFreeColClient();
    final SwingGUI gui = (SwingGUI)getGUI();
    boolean ret = true;

    if (fcc.getAnimationSpeed(this.attacker.getOwner()) > 0) {
        if (loadAnimation(this.attacker, direction)) {
            new UnitImageAnimation(gui, this.attacker, this.attackerTile,
                                   this.sza, this.mirror).animate();
        } else {
            ret = false;
        }
    }

    if (!success && fcc.getAnimationSpeed(this.defender.getOwner()) > 0) {
        if (loadAnimation(this.defender, direction.getReverseDirection())) {
            new UnitImageAnimation(gui, this.defender, this.defenderTile,
                                   this.sza, this.mirror).animate();
        } else {
            ret = false;
        }
    }
    return ret;
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:34,代码来源:UnitAttackAnimation.java

示例8: executeWithUnitOutForAnimation

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void executeWithUnitOutForAnimation(JLabel unitLabel) {
    final SwingGUI gui = (SwingGUI)getGUI();
    final float scale = gui.getMapScale();
    final int movementRatio = (int)(Math.pow(2, this.speed + 1) * scale);
    final Rectangle r1 = gui.getTileBounds(this.sourceTile);
    final Rectangle r2 = gui.getTileBounds(this.destinationTile);
    final Rectangle bounds = r1.union(r2);
    final double xratio = ImageLibrary.TILE_SIZE.width
        / (double)ImageLibrary.TILE_SIZE.height;

    // Tile positions should be valid at this point.
    final Point srcP = gui.getTilePosition(this.sourceTile);
    if (srcP == null) {
        logger.warning("Failed move animation for " + this.unit
            + " at source tile: " + this.sourceTile);
        return;
    }
    final Point dstP = gui.getTilePosition(this.destinationTile);
    if (dstP == null) {
        logger.warning("Failed move animation for " + this.unit
            + " at destination tile: " + this.destinationTile);
        return;
    }
        
    final int labelWidth = unitLabel.getWidth();
    final int labelHeight = unitLabel.getHeight();
    final Point srcPoint = gui.calculateUnitLabelPositionInTile(labelWidth,
        labelHeight, srcP);
    final Point dstPoint = gui.calculateUnitLabelPositionInTile(labelWidth,
        labelHeight, dstP);
    final int stepX = (srcPoint.getX() == dstPoint.getX()) ? 0
        : (srcPoint.getX() > dstPoint.getX()) ? -1 : 1;
    final int stepY = (srcPoint.getY() == dstPoint.getY()) ? 0
        : (srcPoint.getY() > dstPoint.getY()) ? -1 : 1;

    int dropFrames = 0;
    Point point = srcPoint;
    while (!point.equals(dstPoint)) {
        long time = System.currentTimeMillis();
        point.x += stepX * xratio * movementRatio;
        point.y += stepY * movementRatio;
        if ((stepX < 0 && point.x < dstPoint.x)
            || (stepX > 0 && point.x > dstPoint.x)) {
            point.x = dstPoint.x;
        }
        if ((stepY < 0 && point.y < dstPoint.y)
            || (stepY > 0 && point.y > dstPoint.y)) {
            point.y = dstPoint.y;
        }
        if (dropFrames <= 0) {
            unitLabel.setLocation(point);
            gui.paintImmediatelyCanvasIn(bounds);
            int timeTaken = (int)(System.currentTimeMillis()-time);
            final int waitTime = ANIMATION_DELAY - timeTaken;
            if (waitTime > 0) {
                Utils.delay(waitTime, "Animation interrupted.");
                dropFrames = 0;
            } else {
                dropFrames = timeTaken / ANIMATION_DELAY - 1;
            }
        } else {
            dropFrames--;
        }
    }
    gui.refresh();
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:71,代码来源:UnitMoveAnimation.java

示例9: actionPerformed

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent ae) {
    final ConnectController cc = getFreeColClient().getConnectController();
    final SwingGUI gui = getGUI();
    final String command = ae.getActionCommand();

    switch (Enum.valueOf(NewPanelAction.class, command)) {
    case OK:
        FreeCol.setName(getSelectedName());
        FreeCol.setAdvantages(getSelectedAdvantages());
        FreeCol.setTC(getSelectedTC().getId());

        NewPanelAction action = Enum.valueOf(NewPanelAction.class,
            buttonGroup.getSelection().getActionCommand());
        switch (action) {
        case SINGLE:
            this.specification.prepare(getSelectedAdvantages(),
                                       this.difficulty);
            if (cc.startSinglePlayerGame(this.specification)) return;
            break;
        case JOIN:
            int joinPort = getSelectedPort(this.joinPortField);
            if (joinPort < 0) break;
            if (cc.joinMultiplayerGame(this.joinNameField.getText(),
                                       joinPort)) return;
            break;
        case START:
            int serverPort = getSelectedPort(this.serverPortField);
            if (serverPort < 0) break;
            this.specification.prepare(getSelectedAdvantages(),
                                       this.difficulty);
            if (cc.startMultiplayerGame(this.specification,
                    this.publicServer.isSelected(), serverPort)) return;
            break;
        case META_SERVER:
            List<ServerInfo> servers = MetaServerUtils.getServerList();
            if (servers != null) gui.showServerListPanel(servers);
            break;
        default:
            break;
        }
        break;
    default:
        super.actionPerformed(ae);
        break;
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:51,代码来源:NewPanel.java

示例10: InformationPanel

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * Creates an information panel that shows the given
 * texts and images, and an "OK" button.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param texts The texts to be displayed in the panel.
 * @param fcos The source {@code FreeColObject}s for the text.
 * @param images The images to be displayed in the panel.
 *
 * @see #createLayout(FreeColClient) For the outer layout
 */
public InformationPanel(FreeColClient freeColClient, String[] texts,
                        FreeColObject[] fcos, ImageIcon[] images) {
    super(freeColClient, createLayout(freeColClient));

    final SwingGUI gui = getGUI();
    JPanel textPanel = new MigPanel();
    textPanel.setOpaque(false);
    textPanel.setLayout(new MigLayout("wrap 2", "", "top"));
    for (int i = 0; i < texts.length; i++) {
        if (images != null && images[i] != null) {
            textPanel.add(new JLabel(images[i]));
            textPanel.add(Utility.getDefaultTextArea(texts[i],
                new Dimension(BASE_WIDTH - images[i].getIconWidth(),
                              BASE_HEIGHT)));
        } else {
            textPanel.add(Utility.getDefaultTextArea(texts[i],
                new Dimension(BASE_WIDTH, BASE_HEIGHT)), "skip");
        }
        StringTemplate disp = displayLabel(fcos[i]);
        if (disp == null) continue;
        JButton button = Utility.localizedButton(StringTemplate
            .template("informationPanel.display")
            .addStringTemplate("%object%", disp));
        final FreeColObject fco = fcos[i];
        button.addActionListener((ActionEvent ae) -> {
                gui.displayObject(fco);
            });
        /*
        If there is another text to display, we need to add
            "gapbottom 25" into the .add(), which gives some
            cushion between each text block
        */
        if ((i + 1) < texts.length) {
            textPanel.add(button, "skip, gapbottom 25");
        } else {
            textPanel.add(button, "skip");
        }

    }

    JScrollPane scrollPane = new JScrollPane(textPanel,
        JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
        JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // correct way to make scroll pane opaque
    scrollPane.getViewport().setOpaque(false);
    scrollPane.setBorder(null);
    setBorder(null);

    add(scrollPane);
    add(okButton, "tag ok");
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:63,代码来源:InformationPanel.java

示例11: animate

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * Do the animation.
 *
 * @return False if there was an error.
 */
public boolean animate() {
    final int movementSpeed
        = getFreeColClient().getAnimationSpeed(unit.getOwner());
    if (movementSpeed <= 0) return true;
    
    final SwingGUI gui = (SwingGUI)getGUI();
    final Point srcP = gui.getTilePosition(sourceTile);
    final Point dstP = gui.getTilePosition(destinationTile);
    if (srcP == null || dstP == null) return false;

    float scale = gui.getMapScale();
    final int movementRatio = (int)(Math.pow(2, movementSpeed + 1) * scale);
    final Rectangle r1 = gui.getTileBounds(sourceTile);
    final Rectangle r2 = gui.getTileBounds(destinationTile);
    final Rectangle bounds = r1.union(r2);

    gui.executeWithUnitOutForAnimation(unit, sourceTile,
        (JLabel unitLabel) -> {
            final int labelWidth = unitLabel.getWidth();
            final int labelHeight = unitLabel.getHeight();
            final Point srcPoint = gui.calculateUnitLabelPositionInTile(labelWidth, labelHeight, srcP);
            final Point dstPoint = gui.calculateUnitLabelPositionInTile(labelWidth, labelHeight, dstP);
            final double xratio = ImageLibrary.TILE_SIZE.width
                / (double)ImageLibrary.TILE_SIZE.height;
            final int stepX = (srcPoint.getX() == dstPoint.getX()) ? 0
                : (srcPoint.getX() > dstPoint.getX()) ? -1 : 1;
            final int stepY = (srcPoint.getY() == dstPoint.getY()) ? 0
                : (srcPoint.getY() > dstPoint.getY()) ? -1 : 1;

            gui.requireFocus(sourceTile);
            // Painting the whole screen once to get rid of
            // disposed dialog-boxes.
            gui.paintImmediatelyCanvasInItsBounds();

            int dropFrames = 0;
            Point point = srcPoint;
            while (!point.equals(dstPoint)) {
                long time = System.currentTimeMillis();

                point.x += stepX * xratio * movementRatio;
                point.y += stepY * movementRatio;
                if ((stepX < 0 && point.x < dstPoint.x)
                    || (stepX > 0 && point.x > dstPoint.x)) {
                    point.x = dstPoint.x;
                }
                if ((stepY < 0 && point.y < dstPoint.y)
                    || (stepY > 0 && point.y > dstPoint.y)) {
                    point.y = dstPoint.y;
                }
                if (dropFrames <= 0) {
                    unitLabel.setLocation(point);
                    gui.paintImmediatelyCanvasIn(bounds);
                        
                    int timeTaken = (int)(System.currentTimeMillis() - time);
                    final int waitTime = ANIMATION_DELAY - timeTaken;
                    if (waitTime > 0) {
                        Utils.delay(waitTime, "Animation interrupted.");
                        dropFrames = 0;
                    } else {
                        dropFrames = timeTaken / ANIMATION_DELAY - 1;
                    }
                } else {
                    dropFrames--;
                }
            }
            gui.refresh();
        });
    return true;
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:75,代码来源:UnitMoveAnimation.java

示例12: UnitImageAnimation

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * Constructor
 *
 * @param gui The gui.
 * @param unit The {@code Unit} to be animated.
 * @param tile The {@code Tile} where the animation occurs.
 * @param animation The animation to show.
 * @param mirror Mirror image the base animation.
 */
public UnitImageAnimation(SwingGUI gui, Unit unit, Tile tile,
                          SimpleZippedAnimation animation, boolean mirror) {
    this.gui = gui;
    this.unit = unit;
    this.tile = tile;
    this.animation = animation;
    this.mirror = mirror;
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:18,代码来源:UnitImageAnimation.java

示例13: getGUI

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * Get the GUI.
 *
 * @return The {@code GUI}.
 */
protected SwingGUI getGUI() {
    return (SwingGUI)freeColClient.getGUI();
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:9,代码来源:FreeColDialog.java

示例14: getGUI

import net.sf.freecol.client.gui.SwingGUI; //导入依赖的package包/类
/**
 * Get the GUI.
 *
 * @return The current {@code GUI}.
 */
protected final SwingGUI getGUI() {
    return (SwingGUI)freeColClient.getGUI();
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:9,代码来源:FreeColPanel.java


注:本文中的net.sf.freecol.client.gui.SwingGUI类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。