org.jdesktop.swingx.painter.AbstractLayoutPainter.HorizontalAlignment Java Examples

The following examples show how to use org.jdesktop.swingx.painter.AbstractLayoutPainter.HorizontalAlignment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RelativePainterHighlighter.java    From BART with MIT License 6 votes vote down vote up
@Override 
protected void doPaint(Graphics2D g, T object, int width, int height) { 
    if (painter == null) 
        return; 
    // use epsilon 
    if (xFactor != 0.0) { 
        int oldWidth = width; 
        width = (int) (xFactor * width); 
        if (getHorizontalAlignment() == HorizontalAlignment.RIGHT) { 
            g.translate(oldWidth - width, 0); 
        } 
    } 
    if (yFactor != 0.0) { 
        int oldHeight = height; 
        height = (int) (yFactor * height); 
        if (getVerticalAlignment() == VerticalAlignment.BOTTOM) { 
            g.translate(0, oldHeight - height); 
        } 
    } 
  
    painter.paint(g, object, width, height); 
}
 
Example #2
Source File: TextLayer.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void enlargeCanvas(int north, int east, int south, int west) {
    VerticalAlignment verticalAlignment = painter.getVerticalAlignment();
    HorizontalAlignment horizontalAlignment = painter.getHorizontalAlignment();
    int newTx = translationX;
    int newTy = translationY;

    if (horizontalAlignment == LEFT) {
        newTx += west;
    } else if (horizontalAlignment == CENTER) {
        newTx += (west - east) / 2;
    } else { // RIGHT
        newTx -= east;
    }

    if (verticalAlignment == TOP) {
        newTy += north;
    } else if (verticalAlignment == VerticalAlignment.CENTER) {
        newTy += (north - south) / 2;
    } else { // BOTTOM
        newTy -= south;
    }

    setTranslation(newTx, newTy);
}
 
Example #3
Source File: SplashImageCreator.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
private static void addTextLayer(Composition comp, String text,
                                 Color textColor, Font font,
                                 int translationY, BlendingMode blendingMode,
                                 float opacity, boolean dropShadow) {
    TextLayer layer = addNewTextLayer(comp, text);

    AreaEffects effects = null;
    if (dropShadow) {
        effects = new AreaEffects();
        var dropShadowEffect = new ShadowPathEffect(0.6f);
        dropShadowEffect.setEffectWidth(3);
        dropShadowEffect.setOffset(Utils.offsetFromPolar(4, 0.7));
        effects.setDropShadow(dropShadowEffect);
    }

    var settings = new TextSettings(text, font, textColor, effects,
        HorizontalAlignment.CENTER,
        VerticalAlignment.CENTER, false, 0);

    layer.setSettings(settings);

    layer.startMovement();
    layer.moveWhileDragging(0, translationY);
    layer.endMovement();

    layer.setOpacity(opacity, true);
    layer.setBlendingMode(blendingMode, true);
}
 
Example #4
Source File: TextSettingsPanel.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
private JPanel createTextPanel(TextSettings settings) {
    JPanel textPanel = new JPanel();
    textPanel.setLayout(new GridBagLayout());

    var gbh = new GridBagHelper(textPanel);

    gbh.addLabel("Text:", 0, 0);
    createTextTF(settings);
    gbh.addLastControl(textTF);

    gbh.addLabel("Color:", 0, 1);
    color = new ColorParam("Color", settings.getColor(), USER_ONLY_TRANSPARENCY);
    gbh.addControl(new ColorParamGUI(color, false));
    color.setAdjustmentListener(this);

    gbh.addLabel("Rotation:", 2, 1);
    rotationParam = new AngleParam("", settings.getRotation());
    rotationParam.setAdjustmentListener(this);
    gbh.addControl(rotationParam.createGUI());

    hAlignmentCB = new JComboBox<>(HorizontalAlignment.values());
    hAlignmentCB.setSelectedItem(settings.getHorizontalAlignment());
    gbh.addLabel("Horizontal Alignment:", 0, 2);
    hAlignmentCB.addActionListener(this);
    gbh.addControl(hAlignmentCB);

    vAlignmentCB = new JComboBox<>(VerticalAlignment.values());
    vAlignmentCB.setSelectedItem(settings.getVerticalAlignment());
    gbh.addLabel("Vertical Alignment:", 0, 3);
    vAlignmentCB.addActionListener(this);
    gbh.addControl(vAlignmentCB);

    return textPanel;
}
 
Example #5
Source File: TextSettings.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
public TextSettings(String text, Font font, Color color,
                    AreaEffects areaEffects,
                    HorizontalAlignment horizontalAlignment,
                    VerticalAlignment verticalAlignment,
                    boolean watermark, double rotation) {
    this.areaEffects = areaEffects;
    this.color = color;
    this.font = font;
    this.horizontalAlignment = horizontalAlignment;
    this.text = text;
    this.verticalAlignment = verticalAlignment;
    this.watermark = watermark;
    this.rotation = rotation;
}
 
Example #6
Source File: TextSettings.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Default settings
 */
public TextSettings() {
    areaEffects = null;
    color = WHITE;
    font = calcDefaultFont();
    horizontalAlignment = HorizontalAlignment.CENTER;
    text = DEFAULT_TEXT;
    verticalAlignment = VerticalAlignment.CENTER;
    watermark = false;
    rotation = 0;
}
 
Example #7
Source File: TextSettings.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
public void randomize() {
    text = Rnd.createRandomString(10);
    font = Rnd.createRandomFont();
    areaEffects = Rnd.createRandomEffects();
    color = Rnd.createRandomColor();
    horizontalAlignment = Rnd.chooseFrom(HorizontalAlignment.values());
    verticalAlignment = Rnd.chooseFrom(VerticalAlignment.values());
    watermark = Rnd.nextBoolean();
    rotation = Rnd.nextDouble() * Math.PI * 2;
}
 
Example #8
Source File: DSWorkbenchDoItYourselfAttackPlaner.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
@Override
public void resetView() {
    AttackManager.getSingleton().addManagerListener(this);
    //setup renderer and general view
   // ((DoItYourselfAttackTableModel) jAttackTable.getModel()).clear();

    HighlightPredicate.ColumnHighlightPredicate colu = new HighlightPredicate.ColumnHighlightPredicate(0, 1, 2, 3, 6);
    jAttackTable.setRowHeight(24);
    jAttackTable.getTableHeader().setDefaultRenderer(new DefaultTableHeaderRenderer());
    jAttackTable.setHighlighters(new CompoundHighlighter(colu, HighlighterFactory.createAlternateStriping(Constants.DS_ROW_A, Constants.DS_ROW_B)));
    jAttackTable.setColumnControlVisible(true);
    jAttackTable.setDefaultEditor(UnitHolder.class, new UnitCellEditor());
    jAttackTable.setDefaultEditor(Village.class, new VillageCellEditor());
    jAttackTable.setDefaultRenderer(UnitHolder.class, new UnitCellRenderer());
    jAttackTable.setDefaultRenderer(Integer.class, new NoteIconCellRenderer(NoteIconCellRenderer.ICON_TYPE.NOTE));
    jAttackTable.setDefaultRenderer(Date.class, new ColoredDateCellRenderer());
    jAttackTable.setDefaultRenderer(Long.class, new ColoredCoutdownCellRenderer());
    jAttackTable.setDefaultEditor(Date.class, new DateSpinEditor());
    jAttackTable.setDefaultEditor(Integer.class, new NoteIconCellEditor(NoteIconCellEditor.ICON_TYPE.NOTE));
    BufferedImage back = ImageUtils.createCompatibleBufferedImage(5, 5, BufferedImage.BITMASK);
    Graphics2D g = back.createGraphics();
    GeneralPath p = new GeneralPath();
    p.moveTo(0, 0);
    p.lineTo(5, 0);
    p.lineTo(5, 5);
    p.closePath();
    g.setColor(Color.GREEN.darker());
    g.fill(p);
    g.dispose();
    jAttackTable.addHighlighter(new PainterHighlighter(HighlightPredicate.EDITABLE, new ImagePainter(back, HorizontalAlignment.RIGHT, VerticalAlignment.TOP)));

    DefaultComboBoxModel model = new DefaultComboBoxModel();
    DefaultComboBoxModel model2 = new DefaultComboBoxModel();
    for (UnitHolder unit : DataHolder.getSingleton().getUnits()) {
        model.addElement(unit);
        model2.addElement(unit);
    }
    jUnitBox.setModel(model);
    jUnitComboBox.setModel(model2);
    jUnitBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram"));
    jUnitComboBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram"));
    jUnitBox.setRenderer(new UnitListCellRenderer());
    jAttackTypeComboBox.setRenderer(new StandardAttackListCellRenderer());
    
    DefaultComboBoxModel typeModel = new DefaultComboBoxModel();

    for (ManageableType t : StandardAttackManager.getSingleton().getAllElements()) {
        StandardAttack a = (StandardAttack) t;
        typeModel.addElement(a);
    }
    jAttackTypeComboBox.setModel(typeModel);

    jUnitComboBox.setRenderer(new UnitListCellRenderer());

    jSourceVillage.setValue(new Point(500, 500));
    jTargetVillage.setValue(new Point(500, 500));
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            jSourceVillage.updateUI();
            jTargetVillage.updateUI();
        }
    });

}
 
Example #9
Source File: RelativePainterHighlighter.java    From BART with MIT License 4 votes vote down vote up
public void setHorizontalAlignment(HorizontalAlignment align) { 
    getPainter().setHorizontalAlignment(align); 
    fireStateChanged(); 
}
 
Example #10
Source File: RelativePainterHighlighter.java    From BART with MIT License 4 votes vote down vote up
public HorizontalAlignment getHorizontalAlignment() { 
    return getPainter().getHorizontalAlignment(); 
}
 
Example #11
Source File: TextSettings.java    From Pixelitor with GNU General Public License v3.0 4 votes vote down vote up
public HorizontalAlignment getHorizontalAlignment() {
    return horizontalAlignment;
}