Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip
Binary file not shown.
Binary file modified sources/net.sf.j2s.core/dist/swingjs/net.sf.j2s.core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20181213165944
20181217223342
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip
Binary file not shown.
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/net.sf.j2s.core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20181213165944
20181217223342
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
4 changes: 3 additions & 1 deletion sources/net.sf.j2s.java.core/src/components/TableDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellRenderer;
Expand All @@ -65,7 +66,8 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
int row, int column) {
setOpaque(true);
setBackground(colors[row % 3]);
setText(" " + row);
setText("" + row);
setHorizontalAlignment(SwingConstants.CENTER);
setBorder(new LineBorder(Color.white, 3));
return this;
}
Expand Down
7 changes: 4 additions & 3 deletions sources/net.sf.j2s.java.core/src/javax/swing/JPopupMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,10 @@ public Component getInvoker() {
public void setInvoker(Component invoker) {
Component oldInvoker = this.invoker;
this.invoker = invoker;
if ((oldInvoker != this.invoker) && (ui != null)) {
((JSComponentUI) ui).reinstallUI(this, (JComponent) invoker);
}
// SwingJS does not do this
// if ((oldInvoker != this.invoker) && (ui != null)) {
// ((JSComponentUI) ui).reinstallUI(this, (JComponent) invoker);
// }
invalidate();
}

Expand Down
21 changes: 10 additions & 11 deletions sources/net.sf.j2s.java.core/src/javax/swing/SwingUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,6 @@ private static String layoutCompoundLabelImpl(
/* Initialize the icon bounds rectangle iconR.
*/

System.out.println("SwingUtil tiv0 " + text + "\n" + textR + "\n" + iconR + "\n" + viewR + "\n"
+ fm.getDescent() + " " + fm.getAscent() + " " + fm.getHeight() + " " + fm.getMaxAscent());

if (icon != null) {
iconR.width = icon.getIconWidth();
iconR.height = icon.getIconHeight();
Expand Down Expand Up @@ -1017,11 +1014,15 @@ private static String layoutCompoundLabelImpl(
(int) v.getPreferredSpan(View.X_AXIS));
textR.height = (int) v.getPreferredSpan(View.Y_AXIS);
} else {
Dimension d = ui.getHTMLSize(ui.textNode);
textR.width = d.width;
textR.height = d.height;
System.out.println("swingutil " + text + " " + d + " " + fm.getHeight());
// Take into account the left and right side bearings.
if (ui.textNode == null) {
textR.width = fm.stringWidth(text);
textR.height = fm.getHeight();
} else {
Dimension d = ui.getHTMLSize(ui.textNode);
textR.width = d.width;
textR.height = d.height;
}
// Take into account the left and right side bearings.
// This gives more space than it is actually needed,
// but there are two reasons:
// 1. If we set the width to the actual bounds,
Expand Down Expand Up @@ -1148,9 +1149,7 @@ else if (horizontalAlignment == RIGHT) {
// SwingJS, for JSGraphicsUtil setting preferred button size;
viewR.width = labelR_width;
viewR.height = labelR_height;
}

System.out.println("SwingUtil tiv " + text + "\n" + textR + "\n" + iconR + "\n" + viewR + "\n");
}
return text;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.Serializable;

import javax.accessibility.AccessibleContext;
import javax.swing.Icon;
Expand Down Expand Up @@ -76,7 +75,8 @@ public DefaultSwatchChooserPanel() {
setInheritsPopupMenu(true);
}

public String getDisplayName() {
@Override
public String getDisplayName() {
return "Swatches";//UIManager.getString("ColorChooser.swatchesNameText");
}

Expand All @@ -99,7 +99,8 @@ public String getDisplayName() {
* @see #getDisplayedMnemonicIndex
* @since 1.4
*/
public int getMnemonic() {
@Override
public int getMnemonic() {
return getInt("ColorChooser.swatchesMnemonic", -1);
}

Expand Down Expand Up @@ -127,27 +128,32 @@ public int getMnemonic() {
* @see #getMnemonic
* @since 1.4
*/
public int getDisplayedMnemonicIndex() {
@Override
public int getDisplayedMnemonicIndex() {
return getInt("ColorChooser.swatchesDisplayedMnemonicIndex", -1);
}

public Icon getSmallDisplayIcon() {
@Override
public Icon getSmallDisplayIcon() {
return null;
}

public Icon getLargeDisplayIcon() {
@Override
public Icon getLargeDisplayIcon() {
return null;
}

/**
* The background color, foreground color, and font are already set to the
* defaults from the defaults table before this method is called.
*/
public void installChooserPanel(JColorChooser enclosingChooser) {
@Override
public void installChooserPanel(JColorChooser enclosingChooser) {
super.installChooserPanel(enclosingChooser);
}

protected void buildChooser() {
@Override
protected void buildChooser() {

GridBagLayout gb = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
Expand Down Expand Up @@ -205,7 +211,8 @@ protected void buildChooser() {
add(superHolder);
}

public void uninstallChooserPanel(JColorChooser enclosingChooser) {
@Override
public void uninstallChooserPanel(JColorChooser enclosingChooser) {
super.uninstallChooserPanel(enclosingChooser);
swatchPanel.removeMouseListener(mainSwatchListener);
recentSwatchPanel.removeMouseListener(recentSwatchListener);
Expand All @@ -216,21 +223,24 @@ public void uninstallChooserPanel(JColorChooser enclosingChooser) {
removeAll(); // strip out all the sub-components
}

public void updateChooser() {
@Override
public void updateChooser() {

}


class RecentSwatchListener extends MouseAdapter implements Serializable {
public void mousePressed(MouseEvent e) {
class RecentSwatchListener extends MouseAdapter {
@Override
public void mousePressed(MouseEvent e) {
Color color = recentSwatchPanel.getColorForLocation(e.getX(), e.getY());
getColorSelectionModel().setSelectedColor(color);

}
}

class MainSwatchListener extends MouseAdapter implements Serializable {
public void mousePressed(MouseEvent e) {
class MainSwatchListener extends MouseAdapter {
@Override
public void mousePressed(MouseEvent e) {
Color color = swatchPanel.getColorForLocation(e.getX(), e.getY());
getColorSelectionModel().setSelectedColor(color);
recentSwatchPanel.setMostRecentColor(color);
Expand Down Expand Up @@ -259,15 +269,17 @@ public SwatchPanel() {
setInheritsPopupMenu(true);
}

public boolean isFocusTraversable() {
@Override
public boolean isFocusTraversable() {
return false;
}

protected void initValues() {

}

public void paintComponent(Graphics g) {
@Override
public void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRect(0,0,getWidth(), getHeight());
for (int row = 0; row < numSwatches.height; row++) {
Expand All @@ -290,7 +302,8 @@ public void paintComponent(Graphics g) {
}
}

public Dimension getPreferredSize() {
@Override
public Dimension getPreferredSize() {
int x = numSwatches.width * (swatchSize.width + gap.width) - 1;
int y = numSwatches.height * (swatchSize.height + gap.height) - 1;
return new Dimension( x, y );
Expand All @@ -301,7 +314,8 @@ protected void initColors() {

}

public String getToolTipText(MouseEvent e) {
@Override
public String getToolTipText(MouseEvent e) {
Color color = getColorForLocation(e.getX(), e.getY());
return color.getRed()+", "+ color.getGreen() + ", " + color.getBlue();
}
Expand All @@ -328,21 +342,30 @@ private Color getColorForCell( int column, int row) {
}

class RecentSwatchPanel extends SwatchPanel {
protected void initValues() {

static Color[] recentColors; // BH SwingJS adds static recentColors just for fun

@Override
protected void initValues() {
swatchSize = UIManager.getDimension("ColorChooser.swatchesRecentSwatchSize");
numSwatches = new Dimension( 5, 7 );
gap = new Dimension(1, 1);
}


protected void initColors() {
Color defaultRecentColor = UIManager.getColor("ColorChooser.swatchesDefaultRecentColor");
int numColors = numSwatches.width * numSwatches.height;

colors = new Color[numColors];
for (int i = 0; i < numColors ; i++) {
colors[i] = defaultRecentColor;
}
@Override
protected void initColors() {
if (recentColors == null) {
Color defaultRecentColor = UIManager.getColor("ColorChooser.swatchesDefaultRecentColor");
int numColors = numSwatches.width * numSwatches.height;
colors = new Color[numColors];
for (int i = 0; i < numColors ; i++) {
colors[i] = defaultRecentColor;
}
recentColors = colors;
} else {
colors = recentColors;
}
}

public void setMostRecentColor(Color c) {
Expand All @@ -357,13 +380,15 @@ public void setMostRecentColor(Color c) {
class MainSwatchPanel extends SwatchPanel {


protected void initValues() {
@Override
protected void initValues() {
swatchSize = UIManager.getDimension("ColorChooser.swatchesSwatchSize");
numSwatches = new Dimension( 31, 9 );
gap = new Dimension(1, 1);
}

protected void initColors() {
@Override
protected void initColors() {
int[] rawValues = initRawValues();
int numColors = rawValues.length / 3;

Expand Down
23 changes: 23 additions & 0 deletions sources/net.sf.j2s.java.core/src/swingjs/JSGraphics2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ public class JSGraphics2D // extends SunGraphics2D

// private Color currentColor;

private static float pixelRatio = /** @j2sNative
(function () {
var ctx = document.createElement("canvas").getContext("2d"),
dpr = window.devicePixelRatio || 1,
bsr = ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
ctx.oBackingStorePixelRatio ||
ctx.backingStorePixelRatio || 1;
return dpr / bsr;
})() || */1;
// this is 1.5 for Windows
// nice, but now how would be do raw pixel setting, say, from images?
// can.width = w * pixelRatio;
// can.height = h * pixelRatio;
// can.getContext("2d").setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);


public JSGraphics2D(Object canvas) { // this must be Object, because we are
// passing an actual HTML5 canvas
hints = new RenderingHints(new Hashtable());
Expand Down Expand Up @@ -546,6 +564,11 @@ private void drawDirect(int[] pixels, int x, int y, int width, int height, boole
buf8[pt++] = argb & 0xFF;
buf8[pt++] = (isRGB ? 0xFF : (argb >> 24) & 0xFF);
}
double[] m = HTML5CanvasContext2D.getMatrix(ctx, transform);
if (m[0] != 1 || m[1] != 0 || m[2] != 0 || m[3] != 1)
System.err.println("Unsupported transform");
x += m[4];
y += m[5];
HTML5CanvasContext2D.putImageData(ctx, imageData, x, y);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package swingjs.api.js;

import java.awt.geom.AffineTransform;

public abstract class HTML5CanvasContext2D {

public abstract void beginPath();
Expand Down Expand Up @@ -193,5 +195,18 @@ public static void setFillStyle(HTML5CanvasContext2D ctx, String s) {
{}
}

public static double[] getMatrix(HTML5CanvasContext2D ctx, AffineTransform transform) {
double[] m = /** @j2sNative ctx._m || */ null;
if (m == null) {
m = new double[6];
/**
* @j2sNative
* ctx._m = m;
*/
transform.getMatrix(m);
}
return m;
}


}
Loading